| 496 | } |
| 497 | |
| 498 | static void replay_block(struct bitcoind *bitcoind, |
| 499 | u32 height, |
| 500 | struct bitcoin_blkid *blkid, |
| 501 | struct bitcoin_block *blk, |
| 502 | struct channel *channel) |
| 503 | { |
| 504 | struct replay_tx *rtx; |
| 505 | struct replay_tx_hash_iter rit; |
| 506 | |
| 507 | /* If we're shutting down, this can happen! */ |
| 508 | if (!channel->owner) |
| 509 | return; |
| 510 | |
| 511 | /* There's no such block: the chain got shorter than the tip we were |
| 512 | * replaying towards (a reorg while we replay). We've seen everything |
| 513 | * there is, so go live. */ |
| 514 | if (!blk) { |
| 515 | log_debug(channel->log, |
| 516 | "Replay reached end of chain at block %u", height); |
| 517 | convert_replay_txs(channel); |
| 518 | return; |
| 519 | } |
| 520 | |
| 521 | /* Tell onchaind that all existing txs have reached a new depth */ |
| 522 | replay_tx_hash_lock(channel->onchaind_replay_watches); |
| 523 | for (rtx = replay_tx_hash_first(channel->onchaind_replay_watches, &rit); |
| 524 | rtx; |
| 525 | rtx = replay_tx_hash_next(channel->onchaind_replay_watches, &rit)) { |
| 526 | /* Note: if you're in this block, that's depth 1! */ |
| 527 | onchain_tx_depth(channel, &rtx->txid, height - rtx->blockheight + 1); |
| 528 | } |
| 529 | replay_tx_hash_unlock(channel->onchaind_replay_watches); |
| 530 | |
| 531 | /* See if we add any new txs which spend a watched one */ |
| 532 | for (size_t i = 0; i < tal_count(blk->tx); i++) { |
| 533 | for (size_t j = 0; j < blk->tx[i]->wtx->num_inputs; j++) { |
| 534 | struct bitcoin_txid spent; |
| 535 | bitcoin_tx_input_get_txid(blk->tx[i], j, &spent); |
| 536 | rtx = replay_tx_hash_get(channel->onchaind_replay_watches, &spent); |
| 537 | if (rtx) { |
| 538 | /* Note: for efficiency, blk->tx's don't have |
| 539 | * PSBTs, so add one now */ |
| 540 | if (!blk->tx[i]->psbt) |
| 541 | blk->tx[i]->psbt = new_psbt(blk->tx[i], blk->tx[i]->wtx); |
| 542 | onchain_txo_spent(channel, blk->tx[i], j, height); |
| 543 | /* Watch this and all the children too. */ |
| 544 | replay_watch_tx(channel, height, blk->tx[i]); |
| 545 | } |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | /* Replay finished? Now we'll get fed real blocks */ |
| 550 | if (height == get_block_height(bitcoind->ld->topology)) { |
| 551 | convert_replay_txs(channel); |
| 552 | return; |
| 553 | } |
| 554 | |
| 555 | /* Ready for next block */ |
nothing calls this directly
no test coverage detected