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

Function remove_tip

lightningd/chaintopology.c:757–796  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

755}
756
757static void remove_tip(struct chain_topology *topo)
758{
759 struct block *b = topo->tip;
760 struct bitcoin_txid *txs;
761 size_t n;
762 const struct short_channel_id *removed_scids;
763
764 log_debug(topo->log, "Removing stale block %u: %s",
765 topo->tip->height,
766 type_to_string(tmpctx, struct bitcoin_blkid, &b->blkid));
767
768 /* Move tip back one. */
769 topo->tip = b->prev;
770
771 if (!topo->tip)
772 fatal("Initial block %u (%s) reorganized out!",
773 b->height,
774 type_to_string(tmpctx, struct bitcoin_blkid, &b->blkid));
775
776 txs = wallet_transactions_by_height(b, topo->ld->wallet, b->height);
777 n = tal_count(txs);
778
779 /* Notify that txs are kicked out (their height will be set NULL in db) */
780 for (size_t i = 0; i < n; i++)
781 txwatch_fire(topo, &txs[i], 0);
782
783 /* Grab these before we delete block from db */
784 removed_scids = wallet_utxoset_get_created(tmpctx, topo->ld->wallet,
785 b->height);
786 wallet_block_remove(topo->ld->wallet, b);
787
788 /* This may have unconfirmed txs: reconfirm as we add blocks. */
789 watch_for_utxo_reconfirmation(topo, topo->ld->wallet);
790 block_map_del(&topo->block_map, b);
791
792 /* These no longer exist, so gossipd drops any reference to them just
793 * as if they were spent. */
794 gossipd_notify_spends(topo->bitcoind->ld, b->height, removed_scids);
795 tal_free(b);
796}
797
798static void get_new_block(struct bitcoind *bitcoind,
799 struct bitcoin_blkid *blkid,

Callers 1

get_new_blockFunction · 0.85

Calls 9

txwatch_fireFunction · 0.85
wallet_block_removeFunction · 0.85
gossipd_notify_spendsFunction · 0.85
tal_freeFunction · 0.85
fatalFunction · 0.70
type_to_stringClass · 0.50

Tested by

no test coverage detected