Changeset View
Changeset View
Standalone View
Standalone View
src/bench/chained_tx.cpp
Show First 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | while (true) { | ||||
} | } | ||||
queue.emplace(txref); | queue.emplace(txref); | ||||
} | } | ||||
assert(chain.size() == txs); | assert(chain.size() == txs); | ||||
return chain; | return chain; | ||||
} | } | ||||
/// Run benchmark on AcceptToMemoryPool | /// Run benchmark on AcceptToMemoryPool | ||||
static void benchATMP(const Config &config, node::NodeContext &node, | static void benchATMP(node::NodeContext &node, benchmark::Bench &bench, | ||||
benchmark::Bench &bench, | |||||
const std::vector<CTransactionRef> chainedTxs) { | const std::vector<CTransactionRef> chainedTxs) { | ||||
auto chainman = Assert(node.chainman.get()); | auto chainman = Assert(node.chainman.get()); | ||||
Chainstate &activeChainState = chainman->ActiveChainstate(); | Chainstate &activeChainState = chainman->ActiveChainstate(); | ||||
CTxMemPool &mempool{*Assert(activeChainState.GetMempool())}; | CTxMemPool &mempool{*Assert(activeChainState.GetMempool())}; | ||||
assert(mempool.size() == 0); | assert(mempool.size() == 0); | ||||
bench.run([&] { | bench.run([&] { | ||||
LOCK(::cs_main); | LOCK(::cs_main); | ||||
for (const auto &tx : chainedTxs) { | for (const auto &tx : chainedTxs) { | ||||
MempoolAcceptResult result = | MempoolAcceptResult result = | ||||
AcceptToMemoryPool(config, activeChainState, tx, GetTime(), | AcceptToMemoryPool(activeChainState, tx, GetTime(), | ||||
/*bypass_limits=*/false); | /*bypass_limits=*/false); | ||||
assert(result.m_result_type == | assert(result.m_result_type == | ||||
MempoolAcceptResult::ResultType::VALID); | MempoolAcceptResult::ResultType::VALID); | ||||
} | } | ||||
mempool.clear(); | mempool.clear(); | ||||
}); | }); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | static void benchReorg(const Config &config, node::NodeContext &node, | ||||
bench.run([&] { | bench.run([&] { | ||||
BlockValidationState state; | BlockValidationState state; | ||||
// Disconnect blocks with long transaction chains | // Disconnect blocks with long transaction chains | ||||
activeChainState.InvalidateBlock(config, state, blockToInvalidate); | activeChainState.InvalidateBlock(config, state, blockToInvalidate); | ||||
assert(state.IsValid()); | assert(state.IsValid()); | ||||
activeChainState.ActivateBestChain(config, state); | activeChainState.ActivateBestChain(state); | ||||
assert(state.IsValid()); | assert(state.IsValid()); | ||||
assert(activeChainState.m_chain.Tip() == tipBeforeInvalidate); | assert(activeChainState.m_chain.Tip() == tipBeforeInvalidate); | ||||
// Transactions should be stuffed back into the mempool. | // Transactions should be stuffed back into the mempool. | ||||
assert(mempool.size() == reorgDepth * chainSizePerBlock); | assert(mempool.size() == reorgDepth * chainSizePerBlock); | ||||
if (!includeMempoolTxRemoval) { | if (!includeMempoolTxRemoval) { | ||||
// As of writing this test, removing transactions from mempool | // As of writing this test, removing transactions from mempool | ||||
// during re-connect takes significant amount of time, so we allow | // during re-connect takes significant amount of time, so we allow | ||||
// to test both with and without this process. | // to test both with and without this process. | ||||
mempool.clear(); | mempool.clear(); | ||||
} | } | ||||
// Reconnect block | // Reconnect block | ||||
{ | { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
activeChainState.ResetBlockFailureFlags(blockToInvalidate); | activeChainState.ResetBlockFailureFlags(blockToInvalidate); | ||||
} | } | ||||
activeChainState.ActivateBestChain(config, state); | activeChainState.ActivateBestChain(state); | ||||
assert(state.IsValid()); | assert(state.IsValid()); | ||||
assert(activeChainState.m_chain.Tip() == mostWorkTip); | assert(activeChainState.m_chain.Tip() == mostWorkTip); | ||||
assert(mempool.size() == 0); | assert(mempool.size() == 0); | ||||
}); | }); | ||||
} | } | ||||
static void | static void | ||||
benchGenerateNewBlock(const Config &config, node::NodeContext &node, | benchGenerateNewBlock(const Config &config, node::NodeContext &node, | ||||
▲ Show 20 Lines • Show All 87 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
/// Tests a chain of 50 1-input-1-output transactions. | /// Tests a chain of 50 1-input-1-output transactions. | ||||
static void MempoolAcceptance50ChainedTxs(benchmark::Bench &bench) { | static void MempoolAcceptance50ChainedTxs(benchmark::Bench &bench) { | ||||
RegTestingSetup test_setup{}; | RegTestingSetup test_setup{}; | ||||
const Config &config = GetConfig(); | const Config &config = GetConfig(); | ||||
const std::vector<CTransactionRef> chainedTxs = oneInOneOutChain( | const std::vector<CTransactionRef> chainedTxs = oneInOneOutChain( | ||||
config, createUTXOs(config, 1, test_setup.m_node).back(), 50); | config, createUTXOs(config, 1, test_setup.m_node).back(), 50); | ||||
benchATMP(config, test_setup.m_node, bench, chainedTxs); | benchATMP(test_setup.m_node, bench, chainedTxs); | ||||
} | } | ||||
/// Tests a chain of 500 1-input-1-output transactions. | /// Tests a chain of 500 1-input-1-output transactions. | ||||
static void MempoolAcceptance500ChainedTxs(benchmark::Bench &bench) { | static void MempoolAcceptance500ChainedTxs(benchmark::Bench &bench) { | ||||
RegTestingSetup test_setup{}; | RegTestingSetup test_setup{}; | ||||
const Config &config = GetConfig(); | const Config &config = GetConfig(); | ||||
const std::vector<CTransactionRef> chainedTxs = oneInOneOutChain( | const std::vector<CTransactionRef> chainedTxs = oneInOneOutChain( | ||||
config, createUTXOs(config, 1, test_setup.m_node).back(), 500); | config, createUTXOs(config, 1, test_setup.m_node).back(), 500); | ||||
benchATMP(config, test_setup.m_node, bench, chainedTxs); | benchATMP(test_setup.m_node, bench, chainedTxs); | ||||
} | } | ||||
/// Test a tree of 63 2-inputs-1-output transactions | /// Test a tree of 63 2-inputs-1-output transactions | ||||
static void MempoolAcceptance63TxTree(benchmark::Bench &bench) { | static void MempoolAcceptance63TxTree(benchmark::Bench &bench) { | ||||
RegTestingSetup test_setup{}; | RegTestingSetup test_setup{}; | ||||
const Config &config = GetConfig(); | const Config &config = GetConfig(); | ||||
const std::vector<CTransactionRef> chainedTxs = | const std::vector<CTransactionRef> chainedTxs = | ||||
twoInOneOutTree(config, test_setup.m_node, 5); | twoInOneOutTree(config, test_setup.m_node, 5); | ||||
assert(chainedTxs.size() == 63); | assert(chainedTxs.size() == 63); | ||||
benchATMP(config, test_setup.m_node, bench, chainedTxs); | benchATMP(test_setup.m_node, bench, chainedTxs); | ||||
} | } | ||||
/// Test a tree of 511 2-inputs-1-output transactions | /// Test a tree of 511 2-inputs-1-output transactions | ||||
static void MempoolAcceptance511TxTree(benchmark::Bench &bench) { | static void MempoolAcceptance511TxTree(benchmark::Bench &bench) { | ||||
RegTestingSetup test_setup{}; | RegTestingSetup test_setup{}; | ||||
const Config &config = GetConfig(); | const Config &config = GetConfig(); | ||||
const std::vector<CTransactionRef> chainedTxs = | const std::vector<CTransactionRef> chainedTxs = | ||||
twoInOneOutTree(config, test_setup.m_node, 8); | twoInOneOutTree(config, test_setup.m_node, 8); | ||||
assert(chainedTxs.size() == 511); | assert(chainedTxs.size() == 511); | ||||
benchATMP(config, test_setup.m_node, bench, chainedTxs); | benchATMP(test_setup.m_node, bench, chainedTxs); | ||||
} | } | ||||
/// Try to reorg a chain of depth 10 where each block has a 50 tx | /// Try to reorg a chain of depth 10 where each block has a 50 tx | ||||
/// 1-input-1-output chain. | /// 1-input-1-output chain. | ||||
static void Reorg10BlocksWith50TxChain(benchmark::Bench &bench) { | static void Reorg10BlocksWith50TxChain(benchmark::Bench &bench) { | ||||
RegTestingSetup test_setup{}; | RegTestingSetup test_setup{}; | ||||
const Config &config = GetConfig(); | const Config &config = GetConfig(); | ||||
benchReorg(config, test_setup.m_node, bench, 10, 50, true); | benchReorg(config, test_setup.m_node, bench, 10, 50, true); | ||||
▲ Show 20 Lines • Show All 91 Lines • Show Last 20 Lines |