Skip to content

Commit

Permalink
openingd: Add method to set abs]olute reserve
Browse files Browse the repository at this point in the history
  • Loading branch information
cdecker committed Jun 9, 2022
1 parent 2749121 commit f7d0827
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions openingd/openingd.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,23 +139,34 @@ static void NORETURN negotiation_failed(struct state *state,
negotiation_aborted(state, errmsg);
}

/* We always set channel_reserve_satoshis to 1%, rounded down. */
static void set_reserve(struct state *state, const struct amount_sat dust_limit)
static void set_reserve_absolute(struct state * state, const struct amount_sat dust_limit, struct amount_sat reserve_sat)
{
state->localconf.channel_reserve
= amount_sat_div(state->funding_sats, 100);

status_debug("Setting their reserve to %s",
type_to_string(tmpctx, struct amount_sat, &reserve_sat));
/* BOLT #2:
*
* The sending node:
*...
* - MUST set `channel_reserve_satoshis` greater than or equal to
* `dust_limit_satoshis` from the `open_channel` message.
*/
if (amount_sat_greater(dust_limit,
state->localconf.channel_reserve))
if (amount_sat_greater(dust_limit, reserve_sat)) {
status_debug(
"Their reserve is too small, bumping to dust_limit: %s < %s",
type_to_string(tmpctx, struct amount_sat, &reserve_sat),
type_to_string(tmpctx, struct amount_sat, &dust_limit));
state->localconf.channel_reserve
= dust_limit;
} else {
state->localconf.channel_reserve = reserve_sat;
}
}

/* We always set channel_reserve_satoshis to 1%, rounded down. */
static void set_reserve(struct state *state, const struct amount_sat dust_limit)
{
set_reserve_absolute(state, dust_limit,
amount_sat_div(state->funding_sats, 100));
}

/*~ Handle random messages we might get during opening negotiation, (eg. gossip)
Expand Down

0 comments on commit f7d0827

Please sign in to comment.