Skip to content

Commit efce1fa

Browse files
committed
lightningd: pass height back from getrawblockbyheight.
Several callers stash this, but we have it, so make it explicit: here's the block you asked for. Signed-off-by: Rusty Russell <[email protected]>
1 parent f67db3c commit efce1fa

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

lightningd/bitcoind.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,9 @@ void bitcoind_sendrawtx_(const tal_t *ctx,
455455

456456
struct getrawblockbyheight_call {
457457
struct bitcoind *bitcoind;
458+
u32 height;
458459
void (*cb)(struct bitcoind *bitcoind,
460+
u32 height,
459461
struct bitcoin_blkid *blkid,
460462
struct bitcoin_block *block,
461463
void *);
@@ -477,7 +479,7 @@ getrawblockbyheight_callback(const char *buf, const jsmntok_t *toks,
477479
* with NULL values. */
478480
err = json_scan(tmpctx, buf, toks, "{result:{blockhash:null}}");
479481
if (!err) {
480-
call->cb(call->bitcoind, NULL, NULL, call->cb_arg);
482+
call->cb(call->bitcoind, call->height, NULL, NULL, call->cb_arg);
481483
goto clean;
482484
}
483485

@@ -496,7 +498,7 @@ getrawblockbyheight_callback(const char *buf, const jsmntok_t *toks,
496498
"getrawblockbyheight",
497499
"bad block");
498500

499-
call->cb(call->bitcoind, &blkid, blk, call->cb_arg);
501+
call->cb(call->bitcoind, call->height, &blkid, blk, call->cb_arg);
500502

501503
clean:
502504
tal_free(call);
@@ -505,6 +507,7 @@ getrawblockbyheight_callback(const char *buf, const jsmntok_t *toks,
505507
void bitcoind_getrawblockbyheight_(struct bitcoind *bitcoind,
506508
u32 height,
507509
void (*cb)(struct bitcoind *bitcoind,
510+
u32 blockheight,
508511
struct bitcoin_blkid *blkid,
509512
struct bitcoin_block *blk,
510513
void *arg),
@@ -517,6 +520,7 @@ void bitcoind_getrawblockbyheight_(struct bitcoind *bitcoind,
517520
call->bitcoind = bitcoind;
518521
call->cb = cb;
519522
call->cb_arg = cb_arg;
523+
call->height = height;
520524

521525
trace_span_start("plugin/bitcoind", call);
522526
trace_span_tag(call, "method", "getrawblockbyheight");
@@ -724,6 +728,7 @@ process_getfilteredblock_step2(struct bitcoind *bitcoind,
724728
}
725729

726730
static void process_getfilteredblock_step1(struct bitcoind *bitcoind,
731+
u32 height,
727732
struct bitcoin_blkid *blkid,
728733
struct bitcoin_block *block,
729734
struct filteredblock_call *call)

lightningd/bitcoind.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ void bitcoind_getchaininfo_(struct bitcoind *bitcoind,
117117
void bitcoind_getrawblockbyheight_(struct bitcoind *bitcoind,
118118
u32 height,
119119
void (*cb)(struct bitcoind *bitcoind,
120+
u32 height,
120121
struct bitcoin_blkid *blkid,
121122
struct bitcoin_block *blk,
122123
void *arg),
@@ -126,6 +127,7 @@ void bitcoind_getrawblockbyheight_(struct bitcoind *bitcoind,
126127
typesafe_cb_preargs(void, void *, \
127128
(cb), (arg), \
128129
struct bitcoind *, \
130+
u32, \
129131
struct bitcoin_blkid *, \
130132
struct bitcoin_block *),\
131133
(arg))

lightningd/chaintopology.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@ static void remove_tip(struct chain_topology *topo)
10551055
}
10561056

10571057
static void get_new_block(struct bitcoind *bitcoind,
1058+
u32 height,
10581059
struct bitcoin_blkid *blkid,
10591060
struct bitcoin_block *blk,
10601061
struct chain_topology *topo)
@@ -1075,7 +1076,7 @@ static void get_new_block(struct bitcoind *bitcoind,
10751076
if (!bitcoin_blkid_eq(&topo->tip->blkid, &blk->hdr.prev_hash))
10761077
remove_tip(topo);
10771078
else {
1078-
add_tip(topo, new_block(topo, blk, topo->tip->height + 1));
1079+
add_tip(topo, new_block(topo, blk, height));
10791080

10801081
/* tell plugins a new block was processed */
10811082
notify_block_added(topo->ld, topo->tip);
@@ -1097,6 +1098,7 @@ static void try_extend_tip(struct chain_topology *topo)
10971098
}
10981099

10991100
static void init_topo(struct bitcoind *bitcoind UNUSED,
1101+
u32 height UNUSED,
11001102
struct bitcoin_blkid *blkid UNUSED,
11011103
struct bitcoin_block *blk,
11021104
struct chain_topology *topo)

0 commit comments

Comments
 (0)