Skip to content

Commit

Permalink
openingd: make sure our their reserve isn't our dust, and vice versa.
Browse files Browse the repository at this point in the history
This quotes from the BOLT proposal at lightning/bolts#389

Don't try to fund channels which would do this, and don't allow others
to fund channels which would do this.

Signed-off-by: Rusty Russell <[email protected]>
rustyrussell authored and cdecker committed Apr 5, 2018
1 parent 0c2447e commit 83f83f7
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions openingd/opening.c
Original file line number Diff line number Diff line change
@@ -346,6 +346,34 @@ static u8 *funder_channel(struct state *state,
negotiation_failed(state,
"minimum_depth %u larger than %u",
minimum_depth, max_minimum_depth);

/* BOLT #2:
*
* The receiver:
*...
* - if `channel_reserve_satoshis` is less than `dust_limit_satoshis`
* within the `open_channel` message:
* - MUST reject the channel.
*
* - if `channel_reserve_satoshis` from the `open_channel` message is
* less than `dust_limit_satoshis`:
* - MUST reject the channel.
*/
if (state->remoteconf->channel_reserve_satoshis
< state->localconf.dust_limit_satoshis)
negotiation_failed(state,
"Their channel reserve %"PRIu64
" would be below our dust %"PRIu64,
state->remoteconf->channel_reserve_satoshis,
state->localconf.dust_limit_satoshis);
if (state->localconf.channel_reserve_satoshis
< state->remoteconf->dust_limit_satoshis)
negotiation_failed(state,
"Their dust limit %"PRIu64
" would be above our reserve %"PRIu64,
state->remoteconf->dust_limit_satoshis,
state->localconf.channel_reserve_satoshis);

check_config_bounds(state, state->remoteconf);

/* Now, ask create funding transaction to pay those two addresses. */
@@ -585,6 +613,31 @@ static u8 *fundee_channel(struct state *state,
state->feerate_per_kw, max_feerate);

set_reserve(state);

/* BOLT #2:
*
* The sender:
*...
* - MUST set `channel_reserve_satoshis` greater than or equal to
* `dust_limit_satoshis` from the `open_channel` message.
* - MUST set `dust_limit_satoshis` less than
* `channel_reserve_satoshis` from the `open_channel` message.
*/
if (state->localconf.channel_reserve_satoshis
< state->remoteconf->dust_limit_satoshis)
negotiation_failed(state,
"Our channel reserve %"PRIu64
" would be below their dust %"PRIu64,
state->localconf.channel_reserve_satoshis,
state->remoteconf->dust_limit_satoshis);
if (state->localconf.dust_limit_satoshis
>= state->remoteconf->channel_reserve_satoshis)
negotiation_failed(state,
"Our dust limit %"PRIu64
" would be above their reserve %"PRIu64,
state->localconf.dust_limit_satoshis,
state->remoteconf->channel_reserve_satoshis);

check_config_bounds(state, state->remoteconf);

msg = towire_accept_channel(state, &state->channel_id,

0 comments on commit 83f83f7

Please sign in to comment.