What changed, and why it matters
This commit only adds a new unit test for an existing feature called 'txgraph staging' in Bitcoin Core. It does not change any production code, so it cannot introduce a security vulnerability or fix one. It is purely a test addition.
No security action needed. This is a test-only change and can be reviewed as normal code quality/test coverage.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a single BOOST_AUTO_TEST_CASE named txgraph_staging to src/test/txgraph_tests.cpp. The test exercises the existing TxGraph staging API (StartStaging, CommitStaging, HaveStaging, AddTransaction, AddDependency, RemoveTransaction, and level queries) to verify that staged changes are isolated from the MAIN level until committed. No production code is modified.
Changed components
src/test/txgraph_tests.cppInspect captured patch +53 / −0
diff --git a/src/test/txgraph_tests.cpp b/src/test/txgraph_tests.cpp
index e87c1c5e..26cf2b3a 100644
--- a/src/test/txgraph_tests.cpp
+++ b/src/test/txgraph_tests.cpp
@@ -368,4 +368,57 @@ BOOST_AUTO_TEST_CASE(txgraph_chunk_chain)
block_builder_checker({{&refs[0]}});
}
+BOOST_AUTO_TEST_CASE(txgraph_staging)
+{
+ /* Create a new graph for the test.
+ * The parameters are max_cluster_count, max_cluster_size, acceptable_iters
+ */
+ auto graph = MakeTxGraph(10, 1000, NUM_ACCEPTABLE_ITERS);
+
+ std::vector<TxGraph::Ref> refs;
+ refs.reserve(2);
+
+ FeePerWeight feerateA{2, 10};
+ FeePerWeight feerateB{1, 10};
+
+ // everytime adding a transaction, test the chunk status
+ // [A]
+ refs.push_back(graph->AddTransaction(feerateA));
+ BOOST_CHECK_EQUAL(graph->HaveStaging(), false);
+ BOOST_CHECK_EQUAL(graph->GetTransactionCount(TxGraph::Level::TOP), 1);
+
+ graph->StartStaging();
+ BOOST_CHECK_EQUAL(graph->HaveStaging(), true);
+ BOOST_CHECK_EQUAL(graph->GetTransactionCount(TxGraph::Level::TOP), 1);
+
+ // [A, B]
+ refs.push_back(graph->AddTransaction(feerateB));
+ BOOST_CHECK_EQUAL(graph->GetTransactionCount(TxGraph::Level::MAIN), 1);
+ BOOST_CHECK_EQUAL(graph->GetTransactionCount(TxGraph::Level::TOP), 2);
+ BOOST_CHECK_EQUAL(graph->Exists(refs[0], TxGraph::Level::TOP), true);
+ BOOST_CHECK_EQUAL(graph->Exists(refs[1], TxGraph::Level::TOP), true);
+
+ graph->AddDependency(/*parent=*/refs[0], /*child=*/refs[1]);
+ BOOST_CHECK_EQUAL(graph->GetTransactionCount(TxGraph::Level::MAIN), 1);
+ BOOST_CHECK_EQUAL(graph->GetTransactionCount(TxGraph::Level::TOP), 2);
+
+ graph->CommitStaging();
+ BOOST_CHECK_EQUAL(graph->HaveStaging(), false);
+
+ BOOST_CHECK_EQUAL(graph->GetTransactionCount(TxGraph::Level::MAIN), 2);
+
+ graph->StartStaging();
+
+ // [A]
+ graph->RemoveTransaction(refs[1]);
+ BOOST_CHECK_EQUAL(graph->GetTransactionCount(TxGraph::Level::MAIN), 2);
+ BOOST_CHECK_EQUAL(graph->GetTransactionCount(TxGraph::Level::TOP), 1);
+
+ graph->CommitStaging();
+
+ BOOST_CHECK_EQUAL(graph->GetTransactionCount(TxGraph::Level::MAIN), 1);
+
+ graph->SanityCheck();
+}
+
BOOST_AUTO_TEST_SUITE_END()
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.