From f2d8f37f1f7b30862c9d25dd8c099423dcaf6b36 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 21 Sep 2023 15:06:27 +0930 Subject: [PATCH] channeld: remove #if DEVELOPER in favor of runtime flag. Signed-off-by: Rusty Russell --- channeld/channeld.c | 57 +++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 31 deletions(-) diff --git a/channeld/channeld.c b/channeld/channeld.c index 261b445b5..d552e80cd 100644 --- a/channeld/channeld.c +++ b/channeld/channeld.c @@ -68,6 +68,9 @@ struct peer { bool channel_ready[NUM_SIDES]; u64 next_index[NUM_SIDES]; + /* --developer? */ + bool developer; + /* Features peer supports. */ u8 *their_features; @@ -171,13 +174,12 @@ struct peer { struct splice_state *splice_state; struct splicing *splicing; -#if DEVELOPER /* If set, don't fire commit counter when this hits 0 */ u32 *dev_disable_commit; /* If set, send channel_announcement after 1 second, not 30 */ bool dev_fast_gossip; -#endif + /* Information used for reestablishment. */ bool last_was_revoke; struct changed_htlc *last_sent_commit; @@ -1537,13 +1539,11 @@ static u8 *send_commit_part(struct peer *peer, } else pbase = NULL; -#if DEVELOPER if (peer->dev_disable_commit) { (*peer->dev_disable_commit)--; if (*peer->dev_disable_commit == 0) status_unusual("dev-disable-commit-after: disabling"); } -#endif if (notify_master) { status_debug("Telling master we're about to commit..."); @@ -1583,12 +1583,11 @@ static void send_commit(struct peer *peer) u32 feerate_target; u8 **msgs = tal_arr(tmpctx, u8*, 1); u8 *msg; -#if DEVELOPER + if (peer->dev_disable_commit && !*peer->dev_disable_commit) { peer->commit_timer = NULL; return; } -#endif /* FIXME: Document this requirement in BOLT 2! */ /* We can't send two commits in a row. */ @@ -5566,7 +5565,6 @@ static void handle_send_error(struct peer *peer, const u8 *msg) exit(0); } -#if DEVELOPER static void handle_dev_reenable_commit(struct peer *peer) { peer->dev_disable_commit = tal_free(peer->dev_disable_commit); @@ -5606,7 +5604,6 @@ static void handle_dev_quiesce(struct peer *peer, const u8 *msg) peer->stfu_initiator = LOCAL; maybe_send_stfu(peer); } -#endif /* DEVELOPER */ static void req_in(struct peer *peer, const u8 *msg) { @@ -5672,21 +5669,24 @@ static void req_in(struct peer *peer, const u8 *msg) case WIRE_CHANNELD_SPLICE_FEERATE_ERROR: case WIRE_CHANNELD_SPLICE_FUNDING_ERROR: break; -#if DEVELOPER - case WIRE_CHANNELD_DEV_REENABLE_COMMIT: - handle_dev_reenable_commit(peer); - return; + case WIRE_CHANNELD_DEV_REENABLE_COMMIT: + if (peer->developer) { + handle_dev_reenable_commit(peer); + return; + } + break; case WIRE_CHANNELD_DEV_MEMLEAK: - handle_dev_memleak(peer, msg); - return; + if (peer->developer) { + handle_dev_memleak(peer, msg); + return; + } + break; case WIRE_CHANNELD_DEV_QUIESCE: - handle_dev_quiesce(peer, msg); - return; -#else - case WIRE_CHANNELD_DEV_REENABLE_COMMIT: - case WIRE_CHANNELD_DEV_MEMLEAK: - case WIRE_CHANNELD_DEV_QUIESCE: -#endif /* DEVELOPER */ + if (peer->developer) { + handle_dev_quiesce(peer, msg); + return; + } + break; case WIRE_CHANNELD_INIT: case WIRE_CHANNELD_OFFER_HTLC_REPLY: case WIRE_CHANNELD_SENDING_COMMITSIG: @@ -5744,8 +5744,6 @@ static void init_channel(struct peer *peer) struct penalty_base *pbases; bool reestablish_only; struct channel_type *channel_type; - u32 *dev_disable_commit; /* Always NULL */ - bool dev_fast_gossip; assert(!(fcntl(MASTER_FD, F_GETFL) & O_NONBLOCK)); @@ -5807,8 +5805,8 @@ static void init_channel(struct peer *peer) &remote_ann_node_sig, &remote_ann_bitcoin_sig, &channel_type, - &dev_fast_gossip, - &dev_disable_commit, + &peer->dev_fast_gossip, + &peer->dev_disable_commit, &pbases, &reestablish_only, &peer->channel_update, @@ -5823,11 +5821,6 @@ static void init_channel(struct peer *peer) peer->splice_state->revoked_count = tal_count(peer->splice_state->inflights); peer->splice_state->count = tal_count(peer->splice_state->inflights); -#if DEVELOPER - peer->dev_disable_commit = dev_disable_commit; - peer->dev_fast_gossip = dev_fast_gossip; -#endif - status_debug("option_static_remotekey = %u," " option_anchor_outputs = %u" " option_anchors_zero_fee_htlc_tx = %u", @@ -5948,12 +5941,14 @@ int main(int argc, char *argv[]) int i, nfds; fd_set fds_in, fds_out; struct peer *peer; + bool developer; - subdaemon_setup(argc, argv); + developer = subdaemon_setup(argc, argv); status_setup_sync(MASTER_FD); peer = tal(NULL, struct peer); + peer->developer = developer; timers_init(&peer->timers, time_mono()); peer->commit_timer = NULL; peer->have_sigs[LOCAL] = peer->have_sigs[REMOTE] = false;