Skip to content

Commit 167767d

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 <rusty@rustcorp.com.au>
1 parent 6b77c95 commit 167767d

16 files changed

+45
-53
lines changed

lightningd/chaintopology.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -822,7 +822,7 @@ static void updates_complete(struct chain_topology *topo)
822822
{
823823
if (!bitcoin_blkid_eq(&topo->tip->blkid, &topo->prev_tip)) {
824824
/* Tell lightningd about new block. */
825-
notify_new_block(topo->bitcoind->ld, topo->tip->height);
825+
notify_new_block(topo->bitcoind->ld);
826826

827827
/* Tell watch code to re-evaluate all txs. */
828828
watch_topology_changed(topo);
@@ -838,7 +838,7 @@ static void updates_complete(struct chain_topology *topo)
838838

839839
/* Send out an account balance snapshot */
840840
if (!first_update_complete) {
841-
send_account_balance_snapshot(topo->ld, topo->tip->height);
841+
send_account_balance_snapshot(topo->ld);
842842
first_update_complete = true;
843843
}
844844
}

lightningd/channel_control.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ static void try_update_feerates(struct lightningd *ld, struct channel *channel)
117117
}
118118

119119
static void try_update_blockheight(struct lightningd *ld,
120-
struct channel *channel,
121-
u32 blockheight)
120+
struct channel *channel)
122121
{
122+
u32 blockheight = get_block_height(ld->topology);
123123
u8 *msg;
124124

125125
/* We don't update the blockheight for non-leased chans */
@@ -1030,7 +1030,7 @@ void lockin_has_completed(struct channel *channel, bool record_push)
10301030
* so update now. */
10311031
try_update_feerates(ld, channel);
10321032

1033-
try_update_blockheight(ld, channel, get_block_height(ld->topology));
1033+
try_update_blockheight(ld, channel);
10341034

10351035
/* Emit an event for the channel open (or channel proposal if blockheight
10361036
* is zero) */
@@ -1899,8 +1899,7 @@ bool peer_start_channeld(struct channel *channel,
18991899
* might not be what we expect: adjust now. */
19001900
if (channel->opener == LOCAL) {
19011901
try_update_feerates(ld, channel);
1902-
try_update_blockheight(ld, channel,
1903-
get_block_height(ld->topology));
1902+
try_update_blockheight(ld, channel);
19041903
}
19051904

19061905
/* "Reestablished" if we've just opened. */
@@ -1946,9 +1945,9 @@ void channeld_tell_depth(struct channel *channel,
19461945
* If so, we should forget the channel. */
19471946
static bool
19481947
is_fundee_should_forget(struct lightningd *ld,
1949-
struct channel *channel,
1950-
u32 block_height)
1948+
struct channel *channel)
19511949
{
1950+
u32 block_height = get_block_height(ld->topology);
19521951
/* 2016 by default */
19531952
u32 max_funding_unconfirmed = ld->dev_max_funding_unconfirmed;
19541953

@@ -1992,8 +1991,7 @@ static int cmp_channel_start(struct channel *const *a, struct channel *const *b,
19921991
}
19931992

19941993
/* Notify all channels of new blocks. */
1995-
void channel_notify_new_block(struct lightningd *ld,
1996-
u32 block_height)
1994+
void channel_notify_new_block(struct lightningd *ld)
19971995
{
19981996
struct peer *peer;
19991997
struct channel *channel;
@@ -2024,12 +2022,12 @@ void channel_notify_new_block(struct lightningd *ld,
20242022
list_for_each(&peer->channels, channel, list) {
20252023
if (channel_state_uncommitted(channel->state))
20262024
continue;
2027-
if (is_fundee_should_forget(ld, channel, block_height))
2025+
if (is_fundee_should_forget(ld, channel))
20282026
tal_arr_expand(&to_forget, channel);
20292027

20302028
/* Let channels know about new blocks,
20312029
* required for lease updates */
2032-
try_update_blockheight(ld, channel, block_height);
2030+
try_update_blockheight(ld, channel);
20332031
}
20342032
}
20352033

@@ -2055,7 +2053,7 @@ void channel_notify_new_block(struct lightningd *ld,
20552053
"confirmed. "
20562054
"We are fundee and can forget channel without "
20572055
"loss of funds.",
2058-
block_height - channel->first_blocknum,
2056+
get_block_height(ld->topology) - channel->first_blocknum,
20592057
fmt_bitcoin_txid(tmpctx, &channel->funding.txid));
20602058
/* FIXME: Send an error packet for this case! */
20612059
/* And forget it. COMPLETELY. */

lightningd/channel_control.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ void channeld_tell_depth(struct channel *channel,
2222
u32 depth);
2323

2424
/* Notify channels of new blocks. */
25-
void channel_notify_new_block(struct lightningd *ld,
26-
u32 block_height);
25+
void channel_notify_new_block(struct lightningd *ld);
2726

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

lightningd/channel_gossip.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -755,8 +755,7 @@ void channel_gossip_scid_changed(struct channel *channel)
755755

756756
/* Block height changed */
757757
static void new_blockheight(struct lightningd *ld,
758-
struct channel *channel,
759-
u32 block_height)
758+
struct channel *channel)
760759
{
761760
switch (channel->channel_gossip->state) {
762761
case CGOSSIP_PRIVATE:
@@ -765,7 +764,7 @@ static void new_blockheight(struct lightningd *ld,
765764
case CGOSSIP_NOT_USABLE:
766765
return;
767766
case CGOSSIP_NOT_DEEP_ENOUGH:
768-
if (!channel_announceable(channel, block_height)) {
767+
if (!channel_announceable(channel, get_block_height(ld->topology))) {
769768
check_channel_gossip(channel);
770769
return;
771770
}
@@ -776,8 +775,7 @@ static void new_blockheight(struct lightningd *ld,
776775
fatal("Bad channel_gossip_state %u", channel->channel_gossip->state);
777776
}
778777

779-
void channel_gossip_notify_new_block(struct lightningd *ld,
780-
u32 block_height)
778+
void channel_gossip_notify_new_block(struct lightningd *ld)
781779
{
782780
struct peer *peer;
783781
struct channel *channel;
@@ -791,7 +789,7 @@ void channel_gossip_notify_new_block(struct lightningd *ld,
791789
if (!channel->channel_gossip)
792790
continue;
793791

794-
new_blockheight(ld, channel, block_height);
792+
new_blockheight(ld, channel);
795793
check_channel_gossip(channel);
796794
}
797795
}

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
@@ -254,8 +254,10 @@ static void gossipd_new_blockheight_reply(struct subd *gossipd,
254254
gossipd->ld->gossip_blockheight);
255255
}
256256

257-
void gossip_notify_new_block(struct lightningd *ld, u32 blockheight)
257+
void gossip_notify_new_block(struct lightningd *ld)
258258
{
259+
u32 blockheight = get_block_height(ld->topology);
260+
259261
/* Only notify gossipd once we're synced. */
260262
if (!topology_synced(ld->topology))
261263
return;
@@ -268,7 +270,7 @@ void gossip_notify_new_block(struct lightningd *ld, u32 blockheight)
268270
static void gossip_topology_synced(struct chain_topology *topo, void *unused)
269271
{
270272
/* Now we start telling gossipd about blocks. */
271-
gossip_notify_new_block(topo->ld, get_block_height(topo));
273+
gossip_notify_new_block(topo->ld);
272274
}
273275

274276
/* 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
@@ -775,14 +775,14 @@ static int io_poll_lightningd(struct pollfd *fds, nfds_t nfds, int timeout)
775775
* like this, and it's always better to have compile-time calls than runtime,
776776
* as it makes the code more explicit. But pasting in direct calls is also an
777777
* abstraction violation, so we use this middleman function. */
778-
void notify_new_block(struct lightningd *ld, u32 block_height)
778+
void notify_new_block(struct lightningd *ld)
779779
{
780780
/* Inform our subcomponents individually. */
781-
htlcs_notify_new_block(ld, block_height);
782-
channel_notify_new_block(ld, block_height);
783-
channel_gossip_notify_new_block(ld, block_height);
784-
gossip_notify_new_block(ld, block_height);
785-
waitblockheight_notify_new_block(ld, block_height);
781+
htlcs_notify_new_block(ld);
782+
channel_notify_new_block(ld);
783+
channel_gossip_notify_new_block(ld);
784+
gossip_notify_new_block(ld);
785+
waitblockheight_notify_new_block(ld);
786786
}
787787

788788
static void on_sigint(int _ UNUSED)

0 commit comments

Comments
 (0)