| 409 | } |
| 410 | |
| 411 | static void replay_block(struct bitcoind *bitcoind, |
| 412 | u32 height, |
| 413 | struct bitcoin_blkid *blkid, |
| 414 | struct bitcoin_block *blk, |
| 415 | struct channel *channel) |
| 416 | { |
| 417 | struct replay_tx *rtx; |
| 418 | struct replay_tx_hash_iter rit; |
| 419 | |
| 420 | /* If we're shutting down, this can happen! */ |
| 421 | if (!channel->owner) |
| 422 | return; |
| 423 | |
| 424 | /* There's no such block: the chain got shorter than the tip we were |
| 425 | * replaying towards (a reorg while we replay). We've seen everything |
| 426 | * there is, so go live. */ |
| 427 | if (!blk) { |
| 428 | log_debug(channel->log, |
| 429 | "Replay reached end of chain at block %u", height); |
| 430 | convert_replay_txs(channel); |
| 431 | return; |
| 432 | } |
| 433 | |
| 434 | /* Tell onchaind that all existing txs have reached a new depth */ |
| 435 | replay_tx_hash_lock(channel->onchaind_replay_watches); |
| 436 | for (rtx = replay_tx_hash_first(channel->onchaind_replay_watches, &rit); |
| 437 | rtx; |
| 438 | rtx = replay_tx_hash_next(channel->onchaind_replay_watches, &rit)) { |
| 439 | /* Note: if you're in this block, that's depth 1! */ |
| 440 | onchain_tx_depth(channel, &rtx->txid, height - rtx->blockheight + 1); |
| 441 | } |
| 442 | replay_tx_hash_unlock(channel->onchaind_replay_watches); |
| 443 | |
| 444 | /* See if we add any new txs which spend a watched one */ |
| 445 | for (size_t i = 0; i < tal_count(blk->tx); i++) { |
| 446 | for (size_t j = 0; j < blk->tx[i]->wtx->num_inputs; j++) { |
| 447 | struct bitcoin_txid spent; |
| 448 | bitcoin_tx_input_get_txid(blk->tx[i], j, &spent); |
| 449 | rtx = replay_tx_hash_get(channel->onchaind_replay_watches, &spent); |
| 450 | if (rtx) { |
| 451 | /* Note: for efficiency, blk->tx's don't have |
| 452 | * PSBTs, so add one now */ |
| 453 | if (!blk->tx[i]->psbt) |
| 454 | blk->tx[i]->psbt = new_psbt(blk->tx[i], blk->tx[i]->wtx); |
| 455 | onchain_txo_spent(channel, blk->tx[i], j, height); |
| 456 | /* Watch this and all the children too. */ |
| 457 | replay_watch_tx(channel, height, blk->tx[i]); |
| 458 | } |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | /* Replay finished? Now we'll get fed real blocks */ |
| 463 | if (height == get_block_height(bitcoind->ld->topology)) { |
| 464 | convert_replay_txs(channel); |
| 465 | return; |
| 466 | } |
| 467 | |
| 468 | /* Ready for next block */ |
nothing calls this directly
no test coverage detected