MCPcopy Create free account
hub / github.com/ElementsProject/lightning / replay_block

Function replay_block

lightningd/onchain_control.c:398–452  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

396}
397
398static void replay_block(struct bitcoind *bitcoind,
399 u32 height,
400 struct bitcoin_blkid *blkid,
401 struct bitcoin_block *blk,
402 struct channel *channel)
403{
404 struct replay_tx *rtx;
405 struct replay_tx_hash_iter rit;
406
407 /* If we're shutting down, this can happen! */
408 if (!channel->owner)
409 return;
410
411 /* Tell onchaind that all existing txs have reached a new depth */
412 replay_tx_hash_lock(channel->onchaind_replay_watches);
413 for (rtx = replay_tx_hash_first(channel->onchaind_replay_watches, &rit);
414 rtx;
415 rtx = replay_tx_hash_next(channel->onchaind_replay_watches, &rit)) {
416 /* Note: if you're in this block, that's depth 1! */
417 onchain_tx_depth(channel, &rtx->txid, height - rtx->blockheight + 1);
418 }
419 replay_tx_hash_unlock(channel->onchaind_replay_watches);
420
421 /* See if we add any new txs which spend a watched one */
422 for (size_t i = 0; i < tal_count(blk->tx); i++) {
423 for (size_t j = 0; j < blk->tx[i]->wtx->num_inputs; j++) {
424 struct bitcoin_txid spent;
425 bitcoin_tx_input_get_txid(blk->tx[i], j, &spent);
426 rtx = replay_tx_hash_get(channel->onchaind_replay_watches, &spent);
427 if (rtx) {
428 /* Note: for efficiency, blk->tx's don't have
429 * PSBTs, so add one now */
430 if (!blk->tx[i]->psbt)
431 blk->tx[i]->psbt = new_psbt(blk->tx[i], blk->tx[i]->wtx);
432 onchain_txo_spent(channel, blk->tx[i], j, height);
433 /* Watch this and all the children too. */
434 replay_watch_tx(channel, height, blk->tx[i]);
435 }
436 }
437 }
438
439 /* Replay finished? Now we'll get fed real blocks */
440 if (height == get_block_height(bitcoind->ld->topology)) {
441 convert_replay_txs(channel);
442 return;
443 }
444
445 /* Ready for next block */
446 channel->onchaind_replay_height = height + 1;
447
448 /* Otherwise, wait for those to be resolved (in case onchaind is slow,
449 * e.g. waiting for HSM). */
450 if (channel->num_onchain_spent_calls == 0)
451 onchaind_replay(channel);
452}
453
454static void onchaind_replay(struct channel *channel)
455{

Callers

nothing calls this directly

Calls 8

onchain_tx_depthFunction · 0.85
new_psbtFunction · 0.85
onchain_txo_spentFunction · 0.85
replay_watch_txFunction · 0.85
convert_replay_txsFunction · 0.85
onchaind_replayFunction · 0.85
get_block_heightFunction · 0.70

Tested by

no test coverage detected