From c3e9cb7a47a1497a32c0c0fdc49209674d1155de Mon Sep 17 00:00:00 2001 From: Christian Decker Date: Thu, 9 Jun 2022 17:04:43 +0200 Subject: [PATCH] openingd: Add zeroconf-no-really-zero mode This is incompatible with the spec as it removes the enforcement for reserves being above dust, but from what I can see from other implementations it seems that others have allowed this as well. This commit just guards the necessary changes with compilation guards, so we can decide either way quickly. This part of the PR is not intended to be final, just as a discussion basis. --- Makefile | 3 +++ openingd/common.c | 2 ++ openingd/openingd.c | 9 +++++++++ 3 files changed, 14 insertions(+) diff --git a/Makefile b/Makefile index 2bbfe8894..71c3c8daa 100644 --- a/Makefile +++ b/Makefile @@ -257,6 +257,9 @@ endif CPPFLAGS += -DBINTOPKGLIBEXECDIR="\"$(shell sh tools/rel.sh $(bindir) $(pkglibexecdir))\"" CFLAGS = $(CPPFLAGS) $(CWARNFLAGS) $(CDEBUGFLAGS) $(COPTFLAGS) -I $(CCANDIR) $(EXTERNAL_INCLUDE_FLAGS) -I . -I$(CPATH) $(SQLITE3_CFLAGS) $(POSTGRES_INCLUDE) $(FEATURES) $(COVFLAGS) $(DEV_CFLAGS) -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS $(PIE_CFLAGS) $(COMPAT_CFLAGS) -DBUILD_ELEMENTS=1 + +CFLAGS += -DZERORESERVE=1 + # If CFLAGS is already set in the environment of make (to whatever value, it # does not matter) then it would export it to subprocesses with the above value # we set, including CWARNFLAGS which by default contains -Wall -Werror. This diff --git a/openingd/common.c b/openingd/common.c index 150b8faa5..493ee4472 100644 --- a/openingd/common.c +++ b/openingd/common.c @@ -180,6 +180,7 @@ bool check_config_bounds(const tal_t *ctx, return false; } +#ifndef ZERORESERVE /* BOLT #2: * * The receiving node MUST fail the channel if: @@ -197,6 +198,7 @@ bool check_config_bounds(const tal_t *ctx, &remoteconf->channel_reserve)); return false; } +#endif return true; } diff --git a/openingd/openingd.c b/openingd/openingd.c index 60237f09f..fa1af8678 100644 --- a/openingd/openingd.c +++ b/openingd/openingd.c @@ -144,6 +144,9 @@ static void set_reserve_absolute(struct state * state, const struct amount_sat d { status_debug("Setting their reserve to %s", type_to_string(tmpctx, struct amount_sat, &reserve_sat)); +#ifdef ZERORESERVE + state->localconf.channel_reserve = reserve_sat; +#else /* BOLT #2: * * The sending node: @@ -161,6 +164,7 @@ static void set_reserve_absolute(struct state * state, const struct amount_sat d } else { state->localconf.channel_reserve = reserve_sat; } +#endif } /* We always set channel_reserve_satoshis to 1%, rounded down. */ @@ -458,6 +462,7 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags) type_to_string(msg, struct channel_id, &state->channel_id)); +#ifndef ZERORESERVE if (amount_sat_greater(state->remoteconf.dust_limit, state->localconf.channel_reserve)) { negotiation_failed(state, @@ -469,6 +474,7 @@ static u8 *funder_channel_start(struct state *state, u8 channel_flags) &state->localconf.channel_reserve)); return NULL; } +#endif if (!check_config_bounds(tmpctx, state->funding_sats, state->feerate_per_kw, @@ -954,6 +960,8 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) /* This reserves 1% of the channel (rounded up) */ set_reserve(state, state->remoteconf.dust_limit); +#ifndef ZERORESERVE + /* Pending proposal to remove these limits. */ /* BOLT #2: * * The sender: @@ -985,6 +993,7 @@ static u8 *fundee_channel(struct state *state, const u8 *open_channel_msg) &state->remoteconf.channel_reserve)); return NULL; } +#endif /* These checks are the same whether we're opener or accepter... */ if (!check_config_bounds(tmpctx, state->funding_sats,