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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 11 additions & 12 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 4 additions & 6 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 6 additions & 6 deletions
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)

0 commit comments

Comments
 (0)