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

Function remove_tip

lightningd/chaintopology.c:1060–1103  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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