Browse Source

lightningd: correctly store our own channel_reserve_satoshis

openingd calculates our reserve based on the channel amount (even if
we're funding, to keep the calculation in one place), but it wasn't
reporting it back to the master daemon.  We initialized it to 0 so that
valgrind wouldn't get upset, as it's part of a structure we send over
the wire.

Have openingd report back, and also initialize it to an impossible value
as extra assurance.  And remove a stray (harmless but weird) semicolon.

Reported-by: Gálli Zoltán
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
ppa-0.6.1
Rusty Russell 7 years ago
committed by Christian Decker
parent
commit
8f38a46584
  1. 10
      lightningd/opening_control.c
  2. 6
      openingd/opening.c
  3. 2
      openingd/opening_wire.csv
  4. 5
      tests/test_lightningd.py

10
lightningd/opening_control.c

@ -314,7 +314,8 @@ static void opening_funder_finished(struct subd *openingd, const u8 *resp,
&fc->uc->minimum_depth,
&channel_info.remote_fundingkey,
&expected_txid,
&feerate)) {
&feerate,
&fc->uc->our_config.channel_reserve_satoshis)) {
log_broken(fc->uc->log,
"bad OPENING_FUNDER_REPLY %s",
tal_hex(resp, resp));
@ -502,7 +503,8 @@ static void opening_fundee_finished(struct subd *openingd,
&push_msat,
&channel_flags,
&feerate,
&funding_signed)) {
&funding_signed,
&uc->our_config.channel_reserve_satoshis)) {
log_broken(uc->log, "bad OPENING_FUNDEE_REPLY %s",
tal_hex(reply, reply));
tal_free(uc);
@ -674,8 +676,8 @@ static void channel_config(struct lightningd *ld,
ours->max_accepted_htlcs = 483;
/* This is filled in by lightning_openingd, for consistency. */
ours->channel_reserve_satoshis = 0;
};
ours->channel_reserve_satoshis = -1;
}
/* Peer has spontaneously exited from connectd due to open msg. Return
* NULL if we took over, otherwise hand back to connectd with this

6
openingd/opening.c

@ -544,7 +544,8 @@ static u8 *funder_channel(struct state *state,
minimum_depth,
&their_funding_pubkey,
&state->funding_txid,
state->feerate_per_kw);
state->feerate_per_kw,
state->localconf.channel_reserve_satoshis);
}
/* This is handed the message the peer sent which caused gossip to stop:
@ -819,7 +820,8 @@ static u8 *fundee_channel(struct state *state,
state->push_msat,
channel_flags,
state->feerate_per_kw,
msg);
msg,
state->localconf.channel_reserve_satoshis);
}
#ifndef TESTING

2
openingd/opening_wire.csv

@ -44,6 +44,7 @@ opening_funder_reply,,minimum_depth,u32
opening_funder_reply,,remote_fundingkey,struct pubkey
opening_funder_reply,,funding_txid,struct bitcoin_txid
opening_funder_reply,,feerate_per_kw,u32
opening_funder_reply,,our_channel_reserve_satoshis,u64
# This means they offer the open (contains their offer packet)
opening_fundee,6003
@ -74,3 +75,4 @@ opening_fundee_reply,,feerate_per_kw,u32
# The (encrypted) funding signed message: send this and we're committed.
opening_fundee_reply,,msglen,u16
opening_fundee_reply,,funding_signed_msg,msglen*u8
opening_fundee_reply,,our_channel_reserve_satoshis,u64

Can't render this file because it has a wrong number of fields in line 5.

5
tests/test_lightningd.py

@ -7,7 +7,6 @@ from utils import wait_for
import copy
import json
import logging
import pytest
import queue
import os
import random
@ -5114,7 +5113,6 @@ class LightningDTests(BaseLightningDTests):
# fundee will also forget and disconnect from peer.
assert len(l2.rpc.listpeers(l1.info['id'])['peers']) == 0
@pytest.mark.xfail(strict=True)
def test_reserve_enforcement(self):
"""Channeld should disallow you spending into your reserve"""
l1, l2 = self.connect(may_reconnect=True)
@ -5125,6 +5123,9 @@ class LightningDTests(BaseLightningDTests):
l2.stop()
# They should both aim for 1%.
assert l2.db_query('SELECT channel_reserve_satoshis FROM channel_configs') == [{'channel_reserve_satoshis': 10**6 // 100}, {'channel_reserve_satoshis': 10**6 // 100}]
# Edit db to reduce reserve to 0 so it will try to violate it.
l2.db_query('UPDATE channel_configs SET channel_reserve_satoshis=0',
use_copy=False)

Loading…
Cancel
Save