From 38698c0689cb7913757b389808a2cad268368723 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 30 May 2024 11:35:52 +0100 Subject: [PATCH 1/3] Warm up empty trees for accesslists --- .../PersistentStorageProvider.cs | 5 +++++ src/Nethermind/Nethermind.State/StateProvider.cs | 4 ++-- src/Nethermind/Nethermind.State/WorldState.cs | 16 +++++++++++++--- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/Nethermind/Nethermind.State/PersistentStorageProvider.cs b/src/Nethermind/Nethermind.State/PersistentStorageProvider.cs index addbe3cb11c..bb1a8c9f913 100644 --- a/src/Nethermind/Nethermind.State/PersistentStorageProvider.cs +++ b/src/Nethermind/Nethermind.State/PersistentStorageProvider.cs @@ -344,6 +344,11 @@ private StorageTree GetOrCreateStorage(Address address) return value; } + public void WarmUpEmpty(in StorageCell storageCell) + { + _preBlockCache[storageCell] = Array.Empty(); + } + public void WarmUp(in StorageCell storageCell) { LoadFromTree(in storageCell); diff --git a/src/Nethermind/Nethermind.State/StateProvider.cs b/src/Nethermind/Nethermind.State/StateProvider.cs index c2173fcc453..0a910d07b89 100644 --- a/src/Nethermind/Nethermind.State/StateProvider.cs +++ b/src/Nethermind/Nethermind.State/StateProvider.cs @@ -654,9 +654,9 @@ public StateProvider(IScopedTrieStore? trieStore, }; } - public void WarmUp(Address address) + public bool WarmUp(Address address) { - GetState(address); + return GetState(address) is not null; } private Account? GetState(Address address) diff --git a/src/Nethermind/Nethermind.State/WorldState.cs b/src/Nethermind/Nethermind.State/WorldState.cs index 754cf4f01e8..fc5cbde87d1 100644 --- a/src/Nethermind/Nethermind.State/WorldState.cs +++ b/src/Nethermind/Nethermind.State/WorldState.cs @@ -116,10 +116,20 @@ public void WarmUp(AccessList? accessList) { foreach ((Address address, AccessList.StorageKeysEnumerable storages) in accessList) { - _stateProvider.WarmUp(address); - foreach (UInt256 storage in storages) + var exists = _stateProvider.WarmUp(address); + if (exists) { - _persistentStorageProvider.WarmUp(new StorageCell(address, storage)); + foreach (UInt256 storage in storages) + { + _persistentStorageProvider.WarmUp(new StorageCell(address, storage)); + } + } + else + { + foreach (UInt256 storage in storages) + { + _persistentStorageProvider.WarmUpEmpty(new StorageCell(address, storage)); + } } } } From 9a2546f1f5f2964c5d784d78040c1bd1d5c7b241 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 30 May 2024 11:47:23 +0100 Subject: [PATCH 2/3] Feedback --- .../PersistentStorageProvider.cs | 16 +++++++++------- src/Nethermind/Nethermind.State/WorldState.cs | 16 +++------------- 2 files changed, 12 insertions(+), 20 deletions(-) diff --git a/src/Nethermind/Nethermind.State/PersistentStorageProvider.cs b/src/Nethermind/Nethermind.State/PersistentStorageProvider.cs index bb1a8c9f913..a608cac211d 100644 --- a/src/Nethermind/Nethermind.State/PersistentStorageProvider.cs +++ b/src/Nethermind/Nethermind.State/PersistentStorageProvider.cs @@ -344,14 +344,16 @@ private StorageTree GetOrCreateStorage(Address address) return value; } - public void WarmUpEmpty(in StorageCell storageCell) + public void WarmUp(in StorageCell storageCell, bool isEmpty) { - _preBlockCache[storageCell] = Array.Empty(); - } - - public void WarmUp(in StorageCell storageCell) - { - LoadFromTree(in storageCell); + if (isEmpty) + { + _preBlockCache[storageCell] = Array.Empty(); + } + else + { + LoadFromTree(in storageCell); + } } private ReadOnlySpan LoadFromTree(in StorageCell storageCell) diff --git a/src/Nethermind/Nethermind.State/WorldState.cs b/src/Nethermind/Nethermind.State/WorldState.cs index fc5cbde87d1..a46d8e856a8 100644 --- a/src/Nethermind/Nethermind.State/WorldState.cs +++ b/src/Nethermind/Nethermind.State/WorldState.cs @@ -116,20 +116,10 @@ public void WarmUp(AccessList? accessList) { foreach ((Address address, AccessList.StorageKeysEnumerable storages) in accessList) { - var exists = _stateProvider.WarmUp(address); - if (exists) + bool isEmpty = _stateProvider.WarmUp(address); + foreach (UInt256 storage in storages) { - foreach (UInt256 storage in storages) - { - _persistentStorageProvider.WarmUp(new StorageCell(address, storage)); - } - } - else - { - foreach (UInt256 storage in storages) - { - _persistentStorageProvider.WarmUpEmpty(new StorageCell(address, storage)); - } + _persistentStorageProvider.WarmUp(new StorageCell(address, storage), isEmpty); } } } From 62f8f04018be99ca622a43592dd48a28def30ba5 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 30 May 2024 11:50:13 +0100 Subject: [PATCH 3/3] invert condition --- src/Nethermind/Nethermind.State/WorldState.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Nethermind/Nethermind.State/WorldState.cs b/src/Nethermind/Nethermind.State/WorldState.cs index a46d8e856a8..25b683c7fc1 100644 --- a/src/Nethermind/Nethermind.State/WorldState.cs +++ b/src/Nethermind/Nethermind.State/WorldState.cs @@ -116,10 +116,10 @@ public void WarmUp(AccessList? accessList) { foreach ((Address address, AccessList.StorageKeysEnumerable storages) in accessList) { - bool isEmpty = _stateProvider.WarmUp(address); + bool exists = _stateProvider.WarmUp(address); foreach (UInt256 storage in storages) { - _persistentStorageProvider.WarmUp(new StorageCell(address, storage), isEmpty); + _persistentStorageProvider.WarmUp(new StorageCell(address, storage), isEmpty: !exists); } } }