From 6bc4f567d267869cfc7cd54f5e65baa4aaf1f4ee Mon Sep 17 00:00:00 2001 From: Andrea Date: Tue, 10 Dec 2024 21:23:29 +0100 Subject: [PATCH] fix: quick workaround for flat storage memtrie comparison (#12592) Quick fix to allow state comparison between flat storage and memtries only when the view over key value pairs is at the same height, for both of them. --- .../src/test_loop/tests/resharding_v3.rs | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/integration-tests/src/test_loop/tests/resharding_v3.rs b/integration-tests/src/test_loop/tests/resharding_v3.rs index e0d87a6c243..89ce9df3d1f 100644 --- a/integration-tests/src/test_loop/tests/resharding_v3.rs +++ b/integration-tests/src/test_loop/tests/resharding_v3.rs @@ -37,6 +37,7 @@ use near_primitives::test_utils::create_user_test_signer; use near_primitives::transaction::SignedTransaction; use near_primitives::trie_key::TrieKey; use near_primitives::views::FinalExecutionStatus; +use near_store::flat::FlatStorageStatus; use std::cell::Cell; use std::u64; @@ -661,11 +662,25 @@ fn assert_state_sanity( trie.lock_for_iter().iter().unwrap().collect::, _>>().unwrap(); assert_state_equal(&memtrie_state, &trie_state, shard_uid, "memtrie and trie"); - let Some(flat_store_chunk_view) = client - .chain - .runtime_adapter - .get_flat_storage_manager() - .chunk_view(shard_uid, final_head.last_block_hash) + let flat_storage_manager = client.chain.runtime_adapter.get_flat_storage_manager(); + // FlatStorageChunkView::iter_range() used below to retrieve all key-value pairs in Flat + // Storage only looks at the data committed into the DB. For this reasons comparing Flat + // Storage and Memtries makes sense only if we can retrieve a view at the same height from + // both. + if let FlatStorageStatus::Ready(status) = + flat_storage_manager.get_flat_storage_status(shard_uid) + { + if status.flat_head.hash != final_head.prev_block_hash { + tracing::warn!(target: "test", "skipping flat storage - memtrie state check"); + continue; + } else { + tracing::debug!(target: "test", "checking flat storage - memtrie state"); + } + } else { + continue; + }; + let Some(flat_store_chunk_view) = + flat_storage_manager.chunk_view(shard_uid, final_head.last_block_hash) else { continue; };