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

Function remove_tip

lightningd/chaintopology.c:1045–1088  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1043}
1044
1045static void remove_tip(struct chain_topology *topo)
1046{
1047 struct block *b = topo->tip;
1048 struct bitcoin_txid *txs;
1049 size_t n;
1050 const struct short_channel_id *removed_scids;
1051
1052 log_debug(topo->log, "Removing stale block %u: %s",
1053 topo->tip->height,
1054 fmt_bitcoin_blkid(tmpctx, &b->blkid));
1055
1056 /* Move tip back one. */
1057 topo->tip = b->prev;
1058
1059 if (!topo->tip)
1060 fatal("Initial block %u (%s) reorganized out!",
1061 b->height,
1062 fmt_bitcoin_blkid(tmpctx, &b->blkid));
1063
1064 txs = wallet_transactions_by_height(b, topo->ld->wallet, b->height);
1065 n = tal_count(txs);
1066
1067 /* Notify that txs are kicked out (their height will be set NULL in db) */
1068 for (size_t i = 0; i < n; i++)
1069 txwatch_fire(topo, &txs[i], 0);
1070
1071 /* Grab these before we delete block from db */
1072 removed_scids = wallet_utxoset_get_created(tmpctx, topo->ld->wallet,
1073 b->height);
1074 wallet_block_remove(topo->ld->wallet, b);
1075
1076 /* This may have unconfirmed txs: reconfirm as we add blocks. */
1077 watch_for_utxo_reconfirmation(topo, topo->ld->wallet);
1078
1079 /* Anyone watching for block removes */
1080 watch_check_block_removed(topo, b->height);
1081
1082 block_map_del(topo->block_map, b);
1083
1084 /* These no longer exist, so gossipd drops any reference to them just
1085 * as if they were spent. */
1086 gossipd_notify_spends(topo->bitcoind->ld, b->height, removed_scids);
1087 tal_free(b);
1088}
1089
1090static void get_new_block(struct bitcoind *bitcoind,
1091 u32 height,

Callers 1

get_new_blockFunction · 0.85

Calls 10

fmt_bitcoin_blkidFunction · 0.85
txwatch_fireFunction · 0.85
wallet_block_removeFunction · 0.85
gossipd_notify_spendsFunction · 0.85
tal_freeFunction · 0.85
fatalFunction · 0.70

Tested by

no test coverage detected