mirror of
https://github.com/aljazceru/lightning.git
synced 2026-02-22 22:44:25 +01:00
chaintopology: Use the DB to locate transactions and rebroadcast txs
Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
@@ -93,39 +93,6 @@ static void filter_block_txs(struct chain_topology *topo, struct block *b)
|
||||
b->full_txs = tal_free(b->full_txs);
|
||||
}
|
||||
|
||||
static const struct bitcoin_tx *tx_in_block(const struct block *b,
|
||||
const struct bitcoin_txid *txid)
|
||||
{
|
||||
size_t i, n = tal_count(b->txs);
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
struct bitcoin_txid this_txid;
|
||||
bitcoin_txid(b->txs[i], &this_txid);
|
||||
if (structeq(&this_txid, txid))
|
||||
return b->txs[i];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* FIXME: Use hash table. */
|
||||
static struct block *block_for_tx(const struct chain_topology *topo,
|
||||
const struct bitcoin_txid *txid,
|
||||
const struct bitcoin_tx **tx)
|
||||
{
|
||||
struct block *b;
|
||||
const struct bitcoin_tx *dummy_tx;
|
||||
|
||||
if (!tx)
|
||||
tx = &dummy_tx;
|
||||
|
||||
for (b = topo->tip; b; b = b->prev) {
|
||||
*tx = tx_in_block(b, txid);
|
||||
if (*tx)
|
||||
return b;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t get_tx_depth(const struct chain_topology *topo,
|
||||
const struct bitcoin_txid *txid)
|
||||
{
|
||||
@@ -189,7 +156,7 @@ static void rebroadcast_txs(struct chain_topology *topo, struct command *cmd)
|
||||
/* Put any txs we want to broadcast in ->txs. */
|
||||
txs->txs = tal_arr(txs, const char *, 0);
|
||||
list_for_each(&topo->outgoing_txs, otx, list) {
|
||||
if (block_for_tx(topo, &otx->txid, NULL))
|
||||
if (wallet_transaction_height(topo->wallet, &otx->txid))
|
||||
continue;
|
||||
|
||||
tal_resize(&txs->txs, num_txs+1);
|
||||
@@ -625,28 +592,6 @@ u32 get_feerate(const struct chain_topology *topo, enum feerate feerate)
|
||||
return topo->feerate[feerate];
|
||||
}
|
||||
|
||||
struct txlocator *locate_tx(const void *ctx, const struct chain_topology *topo,
|
||||
const struct bitcoin_txid *txid)
|
||||
{
|
||||
struct block *block = block_for_tx(topo, txid, NULL);
|
||||
if (block == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct txlocator *loc = talz(ctx, struct txlocator);
|
||||
loc->blkheight = block->height;
|
||||
size_t i, n = tal_count(block->txs);
|
||||
for (i = 0; i < n; i++) {
|
||||
struct bitcoin_txid this_txid;
|
||||
bitcoin_txid(block->txs[i], &this_txid);
|
||||
if (structeq(&this_txid, txid)){
|
||||
loc->index = block->txnums[i];
|
||||
return loc;
|
||||
}
|
||||
}
|
||||
return tal_free(loc);
|
||||
}
|
||||
|
||||
#if DEVELOPER
|
||||
static void json_dev_blockheight(struct command *cmd,
|
||||
const char *buffer UNUSED, const jsmntok_t *params UNUSED)
|
||||
|
||||
@@ -516,7 +516,7 @@ static enum watch_result funding_lockin_cb(struct channel *channel,
|
||||
if (depth < channel->minimum_depth)
|
||||
return KEEP_WATCHING;
|
||||
|
||||
loc = locate_tx(channel, ld->topology, txid);
|
||||
loc = wallet_transaction_locate(channel, ld->wallet, txid);
|
||||
|
||||
/* If we restart, we could already have peer->scid from database */
|
||||
if (!channel->scid) {
|
||||
|
||||
Reference in New Issue
Block a user