Skip to content

Commit 2af94f1

Browse files
committed
chaintopology: remove redundant wallet pointer.
We already have access via the ld object, and we initialized this one twice anyway. Signed-off-by: Rusty Russell <[email protected]>
1 parent c3ec5fc commit 2af94f1

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

lightningd/chaintopology.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b)
7676

7777
txo = txowatch_hash_get(&topo->txowatches, &out);
7878
if (txo) {
79-
wallet_transaction_add(topo->wallet, tx, b->height, i);
79+
wallet_transaction_add(topo->ld->wallet,
80+
tx, b->height, i);
8081
txowatch_fire(txo, tx, j, b);
8182
}
8283
}
@@ -92,7 +93,8 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b)
9293
bitcoin_txid(tx, &txid);
9394
if (watching_txid(topo, &txid) || we_broadcast(topo, &txid) ||
9495
satoshi_owned != 0) {
95-
wallet_transaction_add(topo->wallet, tx, b->height, i);
96+
wallet_transaction_add(topo->ld->wallet,
97+
tx, b->height, i);
9698
}
9799
}
98100
b->full_txs = tal_free(b->full_txs);
@@ -101,7 +103,7 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b)
101103
size_t get_tx_depth(const struct chain_topology *topo,
102104
const struct bitcoin_txid *txid)
103105
{
104-
u32 blockheight = wallet_transaction_height(topo->wallet, txid);
106+
u32 blockheight = wallet_transaction_height(topo->ld->wallet, txid);
105107

106108
if (blockheight == 0)
107109
return 0;
@@ -161,7 +163,7 @@ static void rebroadcast_txs(struct chain_topology *topo, struct command *cmd)
161163
/* Put any txs we want to broadcast in ->txs. */
162164
txs->txs = tal_arr(txs, const char *, 0);
163165
list_for_each(&topo->outgoing_txs, otx, list) {
164-
if (wallet_transaction_height(topo->wallet, &otx->txid))
166+
if (wallet_transaction_height(topo->ld->wallet, &otx->txid))
165167
continue;
166168

167169
tal_resize(&txs->txs, num_txs+1);
@@ -229,7 +231,7 @@ void broadcast_tx(struct chain_topology *topo,
229231
log_add(topo->log, " (tx %s)",
230232
type_to_string(tmpctx, struct bitcoin_txid, &otx->txid));
231233

232-
wallet_transaction_add(topo->wallet, tx, 0, 0);
234+
wallet_transaction_add(topo->ld->wallet, tx, 0, 0);
233235
bitcoind_sendrawtx(topo->bitcoind, otx->hextx, broadcast_done, otx);
234236
}
235237

@@ -566,7 +568,7 @@ static void topo_update_spends(struct chain_topology *topo, struct block *b)
566568
const struct bitcoin_tx *tx = b->full_txs[i];
567569
for (size_t j = 0; j < tal_count(tx->input); j++) {
568570
const struct bitcoin_tx_input *input = &tx->input[j];
569-
scid = wallet_outpoint_spend(topo->wallet, tmpctx,
571+
scid = wallet_outpoint_spend(topo->ld->wallet, tmpctx,
570572
b->height, &input->txid,
571573
input->index);
572574
if (scid) {
@@ -584,7 +586,7 @@ static void topo_add_utxos(struct chain_topology *topo, struct block *b)
584586
for (size_t j = 0; j < tal_count(tx->output); j++) {
585587
const struct bitcoin_tx_output *output = &tx->output[j];
586588
if (is_p2wsh(output->script, NULL)) {
587-
wallet_utxoset_add(topo->wallet, tx, j,
589+
wallet_utxoset_add(topo->ld->wallet, tx, j,
588590
b->height, i, output->script,
589591
output->amount);
590592
}
@@ -599,7 +601,7 @@ static void add_tip(struct chain_topology *topo, struct block *b)
599601
b->prev = topo->tip;
600602
topo->tip->next = b;
601603
topo->tip = b;
602-
wallet_block_add(topo->wallet, b);
604+
wallet_block_add(topo->ld->wallet, b);
603605

604606
topo_add_utxos(topo, b);
605607
topo_update_spends(topo, b);
@@ -648,16 +650,16 @@ static void remove_tip(struct chain_topology *topo)
648650
b->height,
649651
type_to_string(tmpctx, struct bitcoin_blkid, &b->blkid));
650652

651-
txs = wallet_transactions_by_height(b, topo->wallet, b->height);
653+
txs = wallet_transactions_by_height(b, topo->ld->wallet, b->height);
652654
n = tal_count(txs);
653655

654656
/* Notify that txs are kicked out. */
655657
for (i = 0; i < n; i++)
656658
txwatch_fire(topo, &txs[i], 0);
657659

658-
wallet_block_remove(topo->wallet, b);
660+
wallet_block_remove(topo->ld->wallet, b);
659661
/* This may have unconfirmed txs: reconfirm as we add blocks. */
660-
watch_for_utxo_reconfirmation(topo, topo->wallet);
662+
watch_for_utxo_reconfirmation(topo, topo->ld->wallet);
661663
block_map_del(&topo->block_map, b);
662664
tal_free(b);
663665
}
@@ -744,9 +746,9 @@ static void get_init_blockhash(struct bitcoind *bitcoind, u32 blockcount,
744746

745747
/* Rollback to the given blockheight, so we start track
746748
* correctly again */
747-
wallet_blocks_rollback(topo->wallet, topo->max_blockheight);
749+
wallet_blocks_rollback(topo->ld->wallet, topo->max_blockheight);
748750
/* This may have unconfirmed txs: reconfirm as we add blocks. */
749-
watch_for_utxo_reconfirmation(topo, topo->wallet);
751+
watch_for_utxo_reconfirmation(topo, topo->ld->wallet);
750752

751753
/* Get up to speed with topology. */
752754
bitcoind_getblockhash(bitcoind, topo->max_blockheight,
@@ -843,14 +845,14 @@ struct chain_topology *new_topology(struct lightningd *ld, struct log *log)
843845
{
844846
struct chain_topology *topo = tal(ld, struct chain_topology);
845847

848+
topo->ld = ld;
846849
block_map_init(&topo->block_map);
847850
list_head_init(&topo->outgoing_txs);
848851
txwatch_hash_init(&topo->txwatches);
849852
txowatch_hash_init(&topo->txowatches);
850853
topo->log = log;
851854
memset(topo->feerate, 0, sizeof(topo->feerate));
852855
topo->bitcoind = new_bitcoind(topo, ld, log);
853-
topo->wallet = ld->wallet;
854856
topo->poll_seconds = 30;
855857
topo->feerate_uninitialized = true;
856858
topo->root = NULL;

lightningd/chaintopology.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,14 @@ static inline bool block_eq(const struct block *b, const struct bitcoin_blkid *k
8383
HTABLE_DEFINE_TYPE(struct block, keyof_block_map, hash_sha, block_eq, block_map);
8484

8585
struct chain_topology {
86+
struct lightningd *ld;
8687
struct block *root;
8788
struct block *prev_tip, *tip;
8889
struct block_map block_map;
8990
u32 feerate[NUM_FEERATES];
9091
bool feerate_uninitialized;
9192
u32 feehistory[NUM_FEERATES][FEE_HISTORY_NUM];
9293

93-
/* Where to store blockchain info. */
94-
struct wallet *wallet;
95-
9694
/* Where to log things. */
9795
struct log *log;
9896

lightningd/lightningd.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,6 @@ int main(int argc, char *argv[])
336336
/* Initialize wallet, now that we are in the correct directory */
337337
ld->wallet = wallet_new(ld, ld->log, &ld->timers);
338338
ld->owned_txfilter = txfilter_new(ld);
339-
ld->topology->wallet = ld->wallet;
340339

341340
/* We do extra checks in io_loop. */
342341
io_poll_debug = io_poll_override(io_poll_lightningd);

0 commit comments

Comments
 (0)