paritytech / smoldot

Alternative client for Substrate-based chains.
GNU General Public License v3.0
305 stars 74 forks source link

Panic while full syncing #628

Open tomaka opened 3 years ago

tomaka commented 3 years ago
thread 'tasks-pool-0' panicked at 'assertion failed: stored_value.is_some()', /home/user/git-clones/smoldot/src/trie/calculate_root.rs:455:9

A bit above Polkadot block 2719744

tomaka commented 3 years ago

Problem likely caused by the fact that a storage transaction rollback doesn't revert the trie cache.

tomaka commented 3 years ago
diff --git a/src/executor/runtime_host.rs b/src/executor/runtime_host.rs
index 8f483b25..324d1419 100644
--- a/src/executor/runtime_host.rs
+++ b/src/executor/runtime_host.rs
@@ -725,8 +725,16 @@ impl Inner {
                     if rollback {
                         for (key, value) in self.top_trie_transaction_revert.take().unwrap() {
                             if let Some(value) = value {
+                                self.top_trie_root_calculation_cache
+                                    .as_mut()
+                                    .unwrap()
+                                    .storage_value_update(&key, value.is_some());
                                 let _ = self.top_trie_changes.insert(key, value);
                             } else {
+                                self.top_trie_root_calculation_cache
+                                    .as_mut()
+                                    .unwrap()
+                                    .storage_value_update(&key, false); // TODO: `false` is wrong!
                                 let _ = self.top_trie_changes.remove(&key);
                             }
                         }

This false requires much deeper changes to the trie cache.