Skip to content

Commit 52e4530

Browse files
committed
blockchaintest: Only check state root for 5 first/last blocks
This is blockchain tests execution optimization: only check state root hash of first 5 blocks (to detect early problems) and last 5 blocks (to do the final check of the chain of blocks). The current implementation of the MPT hash of the state builds the trie from scratch (no updates to the trie of the previous block). For the tests will a long chain of blocks the performance degrades significantly with 99% time spent in the keccak hash function. This improves testing of EIP-2935 implemented in #953.
1 parent 85ded61 commit 52e4530

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

test/blockchaintest/blockchaintest_runner.cpp

+13-3
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,9 @@ void run_blockchain_tests(std::span<const BlockchainTest> tests, evmc::VM& vm)
141141
std::unordered_map<int64_t, hash256> known_block_hashes{
142142
{c.genesis_block_header.block_number, c.genesis_block_header.hash}};
143143

144-
for (const auto& test_block : c.test_blocks)
144+
for (size_t i = 0; i != c.test_blocks.size(); ++i)
145145
{
146+
const auto& test_block = c.test_blocks[i];
146147
auto bi = test_block.block_info;
147148
bi.known_block_hashes = known_block_hashes;
148149

@@ -157,8 +158,17 @@ void run_blockchain_tests(std::span<const BlockchainTest> tests, evmc::VM& vm)
157158
SCOPED_TRACE(std::string{evmc::to_string(rev)} + '/' + std::to_string(case_index) +
158159
'/' + c.name + '/' + std::to_string(test_block.block_info.number));
159160

160-
EXPECT_EQ(
161-
state::mpt_hash(TestState{state}), test_block.expected_block_header.state_root);
161+
static constexpr size_t STATE_HASH_CHECK_MARGIN = 5;
162+
if (i < STATE_HASH_CHECK_MARGIN || i >= c.test_blocks.size() - STATE_HASH_CHECK_MARGIN)
163+
{
164+
// Only check state hashes for first (early problems)
165+
// and last (final check of the chain) blocks.
166+
// Otherwise, for very long blockchain test we spend a lot of time in MPT hashing
167+
// because the implementation of it is very simplistic: the trie is not updated
168+
// along the state changes but a new trie is build from scratch for every block.
169+
EXPECT_EQ(
170+
state::mpt_hash(TestState{state}), test_block.expected_block_header.state_root);
171+
}
162172

163173
if (rev >= EVMC_SHANGHAI)
164174
{

0 commit comments

Comments
 (0)