feat(chain)!: make IndexedTxGraph::apply_block_relevant more efficient

Previously, `apply_block_relevant` used `batch_insert_relevant` which
allows inserting non-topologically-ordered transactions. However,
transactions from blocks are always ordered, so we can avoid looping
through block transactions twice (as done in `batch_insert_relevant`).

Additionally, `apply_block_relevant` now takes in a reference to a
`Block` instead of consuming the `Block`. This makes sense as typically
very few of the transactions in the block are inserted.
This commit is contained in:
志宇
2024-01-02 17:31:34 +08:00
parent e0512acf94
commit a7d01dc39a
3 changed files with 18 additions and 12 deletions

View File

@@ -298,7 +298,7 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
tip: emission.checkpoint,
introduce_older_blocks: false,
})?;
let indexed_additions = indexed_tx_graph.apply_block_relevant(emission.block, height);
let indexed_additions = indexed_tx_graph.apply_block_relevant(&emission.block, height);
assert!(indexed_additions.is_empty());
}
@@ -362,7 +362,7 @@ fn test_into_tx_graph() -> anyhow::Result<()> {
tip: emission.checkpoint,
introduce_older_blocks: false,
})?;
let indexed_additions = indexed_tx_graph.apply_block_relevant(emission.block, height);
let indexed_additions = indexed_tx_graph.apply_block_relevant(&emission.block, height);
assert!(indexed_additions.graph.txs.is_empty());
assert!(indexed_additions.graph.txouts.is_empty());
assert_eq!(indexed_additions.graph.anchors, exp_anchors);