Skip to content

Commit ff7ded7

Browse files
committed
lightningd: don't hand redundant block_height to block notifications.
They can all call get_block_height(); the extra argument confused me and I thought they were called before the block height was actually updated. Signed-off-by: Rusty Russell <[email protected]>
1 parent 0719e0f commit ff7ded7

18 files changed

+46
-61
lines changed

lightningd/chaintopology.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -824,7 +824,7 @@ static void updates_complete(struct chain_topology *topo)
824824
{
825825
if (!bitcoin_blkid_eq(&topo->tip->blkid, &topo->prev_tip)) {
826826
/* Tell lightningd about new block. */
827-
notify_new_block(topo->bitcoind->ld, topo->tip->height);
827+
notify_new_block(topo->bitcoind->ld);
828828

829829
/* Tell watch code to re-evaluate all txs. */
830830
watch_topology_changed(topo);
@@ -840,7 +840,7 @@ static void updates_complete(struct chain_topology *topo)
840840

841841
/* Send out an account balance snapshot */
842842
if (!first_update_complete) {
843-
send_account_balance_snapshot(topo->ld, topo->tip->height);
843+
send_account_balance_snapshot(topo->ld);
844844
first_update_complete = true;
845845
}
846846
}

lightningd/channel_control.c

+11-12
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ static void try_update_feerates(struct lightningd *ld, struct channel *channel)
114114
}
115115

116116
static void try_update_blockheight(struct lightningd *ld,
117-
struct channel *channel,
118-
u32 blockheight)
117+
struct channel *channel)
119118
{
119+
u32 blockheight = get_block_height(ld->topology);
120120
u8 *msg;
121121

122122
/* We don't update the blockheight for non-leased chans */
@@ -1005,7 +1005,7 @@ void lockin_has_completed(struct channel *channel, bool record_push)
10051005
* so update now. */
10061006
try_update_feerates(ld, channel);
10071007

1008-
try_update_blockheight(ld, channel, get_block_height(ld->topology));
1008+
try_update_blockheight(ld, channel);
10091009

10101010
/* Emit an event for the channel open (or channel proposal if blockheight
10111011
* is zero) */
@@ -1878,8 +1878,7 @@ bool peer_start_channeld(struct channel *channel,
18781878
* might not be what we expect: adjust now. */
18791879
if (channel->opener == LOCAL) {
18801880
try_update_feerates(ld, channel);
1881-
try_update_blockheight(ld, channel,
1882-
get_block_height(ld->topology));
1881+
try_update_blockheight(ld, channel);
18831882
}
18841883

18851884
/* "Reestablished" if we've just opened. */
@@ -1925,9 +1924,10 @@ void channeld_tell_depth(struct channel *channel,
19251924
* If so, we should forget the channel. */
19261925
static bool
19271926
is_fundee_should_forget(struct lightningd *ld,
1928-
struct channel *channel,
1929-
u32 block_height)
1927+
struct channel *channel)
19301928
{
1929+
u32 block_height = get_block_height(ld->topology);
1930+
19311931
/* BOLT #2:
19321932
*
19331933
* A non-funding node (fundee):
@@ -1967,9 +1967,9 @@ is_fundee_should_forget(struct lightningd *ld,
19671967
}
19681968

19691969
/* Notify all channels of new blocks. */
1970-
void channel_notify_new_block(struct lightningd *ld,
1971-
u32 block_height)
1970+
void channel_notify_new_block(struct lightningd *ld)
19721971
{
1972+
u32 block_height = get_block_height(ld->topology);
19731973
struct peer *peer;
19741974
struct channel *channel;
19751975
struct channel **to_forget = tal_arr(NULL, struct channel *, 0);
@@ -1983,13 +1983,12 @@ void channel_notify_new_block(struct lightningd *ld,
19831983
list_for_each(&peer->channels, channel, list) {
19841984
if (channel_state_uncommitted(channel->state))
19851985
continue;
1986-
if (is_fundee_should_forget(ld, channel, block_height)) {
1986+
if (is_fundee_should_forget(ld, channel)) {
19871987
tal_arr_expand(&to_forget, channel);
19881988
} else
19891989
/* Let channels know about new blocks,
19901990
* required for lease updates */
1991-
try_update_blockheight(ld, channel,
1992-
block_height);
1991+
try_update_blockheight(ld, channel);
19931992
}
19941993
}
19951994

lightningd/channel_control.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ void channeld_tell_depth(struct channel *channel,
2323
u32 depth);
2424

2525
/* Notify channels of new blocks. */
26-
void channel_notify_new_block(struct lightningd *ld,
27-
u32 block_height);
26+
void channel_notify_new_block(struct lightningd *ld);
2827

2928
/* Cancel the channel after `fundchannel_complete` succeeds
3029
* but before funding broadcasts. */

lightningd/channel_gossip.c

+4-6
Original file line numberDiff line numberDiff line change
@@ -752,8 +752,7 @@ void channel_gossip_scid_changed(struct channel *channel)
752752

753753
/* Block height changed */
754754
static void new_blockheight(struct lightningd *ld,
755-
struct channel *channel,
756-
u32 block_height)
755+
struct channel *channel)
757756
{
758757
switch (channel->channel_gossip->state) {
759758
case CGOSSIP_PRIVATE:
@@ -762,7 +761,7 @@ static void new_blockheight(struct lightningd *ld,
762761
case CGOSSIP_NOT_USABLE:
763762
return;
764763
case CGOSSIP_NOT_DEEP_ENOUGH:
765-
if (!channel_announceable(channel, block_height)) {
764+
if (!channel_announceable(channel, get_block_height(ld->topology))) {
766765
check_channel_gossip(channel);
767766
return;
768767
}
@@ -773,8 +772,7 @@ static void new_blockheight(struct lightningd *ld,
773772
fatal("Bad channel_gossip_state %u", channel->channel_gossip->state);
774773
}
775774

776-
void channel_gossip_notify_new_block(struct lightningd *ld,
777-
u32 block_height)
775+
void channel_gossip_notify_new_block(struct lightningd *ld)
778776
{
779777
struct peer *peer;
780778
struct channel *channel;
@@ -788,7 +786,7 @@ void channel_gossip_notify_new_block(struct lightningd *ld,
788786
if (!channel->channel_gossip)
789787
continue;
790788

791-
new_blockheight(ld, channel, block_height);
789+
new_blockheight(ld, channel);
792790
check_channel_gossip(channel);
793791
}
794792
}

lightningd/channel_gossip.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ void channel_gossip_update(struct channel *channel);
2323
void channel_gossip_scid_changed(struct channel *channel);
2424

2525
/* Block height changed */
26-
void channel_gossip_notify_new_block(struct lightningd *ld,
27-
u32 block_height);
26+
void channel_gossip_notify_new_block(struct lightningd *ld);
2827

2928
/* Got announcement_signatures from peer */
3029
void channel_gossip_got_announcement_sigs(struct channel *channel,

lightningd/coin_mvts.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static bool report_chan_balance(const struct channel *chan)
103103
abort();
104104
}
105105

106-
void send_account_balance_snapshot(struct lightningd *ld, u32 blockheight)
106+
void send_account_balance_snapshot(struct lightningd *ld)
107107
{
108108
struct balance_snapshot *snap = tal(NULL, struct balance_snapshot);
109109
struct account_balance *bal;
@@ -112,7 +112,7 @@ void send_account_balance_snapshot(struct lightningd *ld, u32 blockheight)
112112
struct peer *p;
113113
struct peer_node_id_map_iter it;
114114

115-
snap->blockheight = blockheight;
115+
snap->blockheight = get_block_height(ld->topology);
116116
snap->timestamp = time_now().ts.tv_sec;
117117
snap->node_id = &ld->our_nodeid;
118118

lightningd/coin_mvts.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ struct channel_coin_mvt *new_channel_mvt_routed_hout(const tal_t *ctx,
3636
struct htlc_out *hout,
3737
struct channel *channel);
3838

39-
void send_account_balance_snapshot(struct lightningd *ld, u32 blockheight);
39+
void send_account_balance_snapshot(struct lightningd *ld);
4040
#endif /* LIGHTNING_LIGHTNINGD_COIN_MVTS_H */

lightningd/gossip_control.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,10 @@ static void gossipd_new_blockheight_reply(struct subd *gossipd,
255255
gossipd->ld->gossip_blockheight);
256256
}
257257

258-
void gossip_notify_new_block(struct lightningd *ld, u32 blockheight)
258+
void gossip_notify_new_block(struct lightningd *ld)
259259
{
260+
u32 blockheight = get_block_height(ld->topology);
261+
260262
/* Only notify gossipd once we're synced. */
261263
if (!topology_synced(ld->topology))
262264
return;
@@ -269,7 +271,7 @@ void gossip_notify_new_block(struct lightningd *ld, u32 blockheight)
269271
static void gossip_topology_synced(struct chain_topology *topo, void *unused)
270272
{
271273
/* Now we start telling gossipd about blocks. */
272-
gossip_notify_new_block(topo->ld, get_block_height(topo));
274+
gossip_notify_new_block(topo->ld);
273275
}
274276

275277
/* We make sure gossipd is started before plugins (which may want gossip_map) */

lightningd/gossip_control.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ void gossipd_notify_spends(struct lightningd *ld,
1414
u32 blockheight,
1515
const struct short_channel_id *scids);
1616

17-
void gossip_notify_new_block(struct lightningd *ld, u32 blockheight);
17+
void gossip_notify_new_block(struct lightningd *ld);
1818

1919
#endif /* LIGHTNING_LIGHTNINGD_GOSSIP_CONTROL_H */

lightningd/lightningd.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -768,14 +768,14 @@ static int io_poll_lightningd(struct pollfd *fds, nfds_t nfds, int timeout)
768768
* like this, and it's always better to have compile-time calls than runtime,
769769
* as it makes the code more explicit. But pasting in direct calls is also an
770770
* abstraction violation, so we use this middleman function. */
771-
void notify_new_block(struct lightningd *ld, u32 block_height)
771+
void notify_new_block(struct lightningd *ld)
772772
{
773773
/* Inform our subcomponents individually. */
774-
htlcs_notify_new_block(ld, block_height);
775-
channel_notify_new_block(ld, block_height);
776-
channel_gossip_notify_new_block(ld, block_height);
777-
gossip_notify_new_block(ld, block_height);
778-
waitblockheight_notify_new_block(ld, block_height);
774+
htlcs_notify_new_block(ld);
775+
channel_notify_new_block(ld);
776+
channel_gossip_notify_new_block(ld);
777+
gossip_notify_new_block(ld);
778+
waitblockheight_notify_new_block(ld);
779779
}
780780

781781
static void on_sigint(int _ UNUSED)

lightningd/lightningd.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ const char *subdaemon_path(const tal_t *ctx, const struct lightningd *ld, const
439439
void test_subdaemons(const struct lightningd *ld);
440440

441441
/* Notify lightningd about new blocks. */
442-
void notify_new_block(struct lightningd *ld, u32 block_height);
442+
void notify_new_block(struct lightningd *ld);
443443

444444
/* Signal a clean exit from lightningd.
445445
* NOTE! This function **returns**.

lightningd/peer_control.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -2912,9 +2912,9 @@ timeout_waitblockheight_waiter(struct waitblockheight_waiter *w)
29122912
"Timed out."));
29132913
}
29142914
/* Called by lightningd at each new block. */
2915-
void waitblockheight_notify_new_block(struct lightningd *ld,
2916-
u32 block_height)
2915+
void waitblockheight_notify_new_block(struct lightningd *ld)
29172916
{
2917+
u32 block_height = get_block_height(ld->topology);
29182918
struct waitblockheight_waiter *w, *n;
29192919
char *to_delete = tal(NULL, char);
29202920

@@ -2929,8 +2929,7 @@ void waitblockheight_notify_new_block(struct lightningd *ld,
29292929
list_del(&w->list);
29302930
w->removed = true;
29312931
tal_steal(to_delete, w);
2932-
was_pending(waitblockheight_complete(w->cmd,
2933-
block_height));
2932+
was_pending(waitblockheight_complete(w->cmd, block_height));
29342933
}
29352934
tal_free(to_delete);
29362935
}

lightningd/peer_control.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,7 @@ struct leak_detect;
154154
void peer_dev_memleak(struct lightningd *ld, struct leak_detect *leaks);
155155

156156
/* Triggered at each new block. */
157-
void waitblockheight_notify_new_block(struct lightningd *ld,
158-
u32 block_height);
157+
void waitblockheight_notify_new_block(struct lightningd *ld);
159158

160159

161160
/* JSON parameter by channel_id or scid (caller must check state!) */

lightningd/peer_htlcs.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -2791,9 +2791,10 @@ static void consider_failing_incoming(struct lightningd *ld,
27912791
local_fail_in_htlc(hout->in, take(towire_permanent_channel_failure(NULL)));
27922792
}
27932793

2794-
void htlcs_notify_new_block(struct lightningd *ld, u32 height)
2794+
void htlcs_notify_new_block(struct lightningd *ld)
27952795
{
27962796
bool removed;
2797+
u32 height = get_block_height(ld->topology);
27972798

27982799
/* BOLT #2:
27992800
*

lightningd/peer_htlcs.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void onchain_failed_our_htlc(const struct channel *channel,
4646
void onchain_fulfilled_htlc(struct channel *channel,
4747
const struct preimage *preimage);
4848

49-
void htlcs_notify_new_block(struct lightningd *ld, u32 height);
49+
void htlcs_notify_new_block(struct lightningd *ld);
5050

5151
/* Only defined if COMPAT_V061 */
5252
void fixup_htlcs_out(struct lightningd *ld);

lightningd/test/run-find_my_abspath.c

+5-8
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ int unused_main(int argc, char *argv[]);
1111
void begin_topology(struct chain_topology *topo UNNEEDED)
1212
{ fprintf(stderr, "begin_topology called!\n"); abort(); }
1313
/* Generated stub for channel_gossip_notify_new_block */
14-
void channel_gossip_notify_new_block(struct lightningd *ld UNNEEDED,
15-
u32 block_height UNNEEDED)
14+
void channel_gossip_notify_new_block(struct lightningd *ld UNNEEDED)
1615
{ fprintf(stderr, "channel_gossip_notify_new_block called!\n"); abort(); }
1716
/* Generated stub for channel_notify_new_block */
18-
void channel_notify_new_block(struct lightningd *ld UNNEEDED,
19-
u32 block_height UNNEEDED)
17+
void channel_notify_new_block(struct lightningd *ld UNNEEDED)
2018
{ fprintf(stderr, "channel_notify_new_block called!\n"); abort(); }
2119
/* Generated stub for connectd_activate */
2220
void connectd_activate(struct lightningd *ld UNNEEDED)
@@ -112,7 +110,7 @@ bool fromwire_status_version(const tal_t *ctx UNNEEDED, const void *p UNNEEDED,
112110
void gossip_init(struct lightningd *ld UNNEEDED, int connectd_fd UNNEEDED)
113111
{ fprintf(stderr, "gossip_init called!\n"); abort(); }
114112
/* Generated stub for gossip_notify_new_block */
115-
void gossip_notify_new_block(struct lightningd *ld UNNEEDED, u32 blockheight UNNEEDED)
113+
void gossip_notify_new_block(struct lightningd *ld UNNEEDED)
116114
{ fprintf(stderr, "gossip_notify_new_block called!\n"); abort(); }
117115
/* Generated stub for handle_early_opts */
118116
void handle_early_opts(struct lightningd *ld UNNEEDED, int argc UNNEEDED, char *argv[])
@@ -127,7 +125,7 @@ size_t hash_htlc_key(const struct htlc_key *htlc_key UNNEEDED)
127125
struct ext_key *hsm_init(struct lightningd *ld UNNEEDED)
128126
{ fprintf(stderr, "hsm_init called!\n"); abort(); }
129127
/* Generated stub for htlcs_notify_new_block */
130-
void htlcs_notify_new_block(struct lightningd *ld UNNEEDED, u32 height UNNEEDED)
128+
void htlcs_notify_new_block(struct lightningd *ld UNNEEDED)
131129
{ fprintf(stderr, "htlcs_notify_new_block called!\n"); abort(); }
132130
/* Generated stub for htlcs_resubmit */
133131
void htlcs_resubmit(struct lightningd *ld UNNEEDED,
@@ -283,8 +281,7 @@ struct txfilter *txfilter_new(const tal_t *ctx UNNEEDED)
283281
const char *version(void)
284282
{ fprintf(stderr, "version called!\n"); abort(); }
285283
/* Generated stub for waitblockheight_notify_new_block */
286-
void waitblockheight_notify_new_block(struct lightningd *ld UNNEEDED,
287-
u32 block_height UNNEEDED)
284+
void waitblockheight_notify_new_block(struct lightningd *ld UNNEEDED)
288285
{ fprintf(stderr, "waitblockheight_notify_new_block called!\n"); abort(); }
289286
/* Generated stub for wallet_new */
290287
struct wallet *wallet_new(struct lightningd *ld UNNEEDED, struct timers *timers UNNEEDED)

lightningd/test/run-invoice-select-inchan.c

-4
Original file line numberDiff line numberDiff line change
@@ -907,10 +907,6 @@ bool peer_start_channeld(struct channel *channel UNNEEDED,
907907
bool reconnected UNNEEDED,
908908
bool reestablish_only UNNEEDED)
909909
{ fprintf(stderr, "peer_start_channeld called!\n"); abort(); }
910-
/* Generated stub for peer_start_closingd */
911-
void peer_start_closingd(struct channel *channel UNNEEDED,
912-
struct peer_fd *peer_fd UNNEEDED)
913-
{ fprintf(stderr, "peer_start_closingd called!\n"); abort(); }
914910
/* Generated stub for peer_start_dualopend */
915911
bool peer_start_dualopend(struct peer *peer UNNEEDED, struct peer_fd *peer_fd UNNEEDED,
916912
struct channel *channel UNNEEDED)

wallet/test/run-wallet.c

-4
Original file line numberDiff line numberDiff line change
@@ -929,10 +929,6 @@ bool peer_start_channeld(struct channel *channel UNNEEDED,
929929
bool reconnected UNNEEDED,
930930
bool reestablish_only UNNEEDED)
931931
{ fprintf(stderr, "peer_start_channeld called!\n"); abort(); }
932-
/* Generated stub for peer_start_closingd */
933-
void peer_start_closingd(struct channel *channel UNNEEDED,
934-
struct peer_fd *peer_fd UNNEEDED)
935-
{ fprintf(stderr, "peer_start_closingd called!\n"); abort(); }
936932
/* Generated stub for peer_start_dualopend */
937933
bool peer_start_dualopend(struct peer *peer UNNEEDED, struct peer_fd *peer_fd UNNEEDED,
938934
struct channel *channel UNNEEDED)

0 commit comments

Comments
 (0)