Skip to content

Commit 17d1a3e

Browse files
committed
Revert "Merge branch 'master' of https://github.com/NethermindEth/nethermind into perf/block-processing-pipeline-v1"
This reverts commit 1d7dede, reversing changes made to 46ae4aa.
1 parent 1d7dede commit 17d1a3e

4 files changed

Lines changed: 15 additions & 126 deletions

File tree

src/Nethermind/Nethermind.Consensus/Processing/BlockProcessor.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ protected virtual TxReceipt[] ProcessBlock(
101101

102102
StoreBeaconRoot(block, spec);
103103
blockHashStore.ApplyBlockhashStateChanges(header, spec);
104-
// System call changes (beacon root, blockhash) accumulate in journal and are
105-
// flushed together with transaction changes in the commit after ProcessTransactions.
104+
_stateProvider.Commit(spec, commitRoots: false);
106105

107106
TxReceipt[] receipts = blockTransactionsExecutor.ProcessTransactions(block, options, ReceiptsTracer, token);
108107

src/Nethermind/Nethermind.Evm/TransactionProcessing/TransactionProcessor.cs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,13 +211,7 @@ protected virtual TransactionResult Execute(Transaction tx, ITxTracer tracer, Ex
211211
return result;
212212
}
213213

214-
// Commit pre-execution changes (nonce increment, gas reservation) when:
215-
// - restore: CallAndRestore needs state in _blockChanges to survive Reset()
216-
// - tracer.IsTracingState: tracers need to see nonce/gas changes separately
217-
// In the normal block-processing path (commit && !restore && !IsTracingState), skip this commit —
218-
// pre-execution changes stay in the journal and are flushed with execution changes, saving one Commit cycle.
219-
if (commit && (restore || tracer.IsTracingState))
220-
WorldState.Commit(spec, tracer.IsTracingState ? tracer : NullStateTracer.Instance, commitRoots: false);
214+
if (commit) WorldState.Commit(spec, tracer.IsTracingState ? tracer : NullTxTracer.Instance, commitRoots: false);
221215

222216
// substate.Logs contains a reference to accessTracker.Logs so we can't Dispose until end of the method
223217
using StackAccessTracker accessTracker = new();

src/Nethermind/Nethermind.State/PersistentStorageProvider.cs

Lines changed: 8 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ internal sealed class PersistentStorageProvider : PartialStorageProviderBase
4343

4444
private readonly HashSet<StorageCell> _committedThisRound = new();
4545

46-
// Read-only cache: storage values loaded from the tree but not modified in the current tx.
47-
// Avoids creating JustCache journal entries for pure reads, reducing Commit iteration cost.
48-
private readonly Dictionary<StorageCell, byte[]> _storageReadCache = new();
49-
5046
/// <summary>
5147
/// Manages persistent storage allowing for snapshotting and restoring
5248
/// Persists data to ITrieStore
@@ -66,7 +62,6 @@ public override void Reset(bool resetBlockChanges = true)
6662
base.Reset();
6763
_originalValues.Clear();
6864
_committedThisRound.Clear();
69-
_storageReadCache.Clear();
7065
if (resetBlockChanges)
7166
{
7267
_storages.ResetAndClear();
@@ -84,16 +79,8 @@ public void SetBackendScope(IWorldStateScopeProvider.IScope scope)
8479
/// </summary>
8580
/// <param name="storageCell">Storage location</param>
8681
/// <returns>Value at location</returns>
87-
protected override ReadOnlySpan<byte> GetCurrentValue(in StorageCell storageCell)
88-
{
89-
if (TryGetCachedValue(storageCell, out byte[]? bytes))
90-
return bytes!;
91-
92-
if (_storageReadCache.TryGetValue(storageCell, out byte[]? cached))
93-
return cached;
94-
95-
return LoadFromTree(storageCell);
96-
}
82+
protected override ReadOnlySpan<byte> GetCurrentValue(in StorageCell storageCell) =>
83+
TryGetCachedValue(storageCell, out byte[]? bytes) ? bytes! : LoadFromTree(storageCell);
9784

9885
/// <summary>
9986
/// Return the original persistent storage value from the storage cell
@@ -135,26 +122,16 @@ public bool IsStorageEmpty(Address address) =>
135122
/// Used for persistent storage specific logic
136123
/// </summary>
137124
/// <param name="tracer">Storage tracer</param>
138-
// Override Commit to also call CommitCore when storage read-cache has entries for tracing
139-
public new void Commit(IStorageTracer tracer)
140-
{
141-
if (_changes.Count == 0 && (!tracer.IsTracingStorage || _storageReadCache.Count == 0))
142-
{
143-
if (_logger.IsTrace) _logger.Trace("No storage changes to commit");
144-
_storageReadCache.Clear();
145-
}
146-
else
147-
{
148-
CommitCore(tracer);
149-
}
150-
}
151-
152125
protected override void CommitCore(IStorageTracer tracer)
153126
{
154127
if (_logger.IsTrace) _logger.Trace("Committing storage changes");
155128

156129
int currentPosition = _changes.Count - 1;
157-
if (currentPosition >= 0 && _changes[currentPosition].IsNull)
130+
if (currentPosition < 0)
131+
{
132+
return;
133+
}
134+
if (_changes[currentPosition].IsNull)
158135
{
159136
throw new InvalidOperationException($"Change at current position {currentPosition} was null when committing {nameof(PartialStorageProviderBase)}");
160137
}
@@ -247,26 +224,9 @@ protected override void CommitCore(IStorageTracer tracer)
247224
}
248225
toUpdateRoots.Clear();
249226

250-
// Report storage reads from read cache for tracing (read-cache entries bypass the journal)
251-
if (isTracing)
252-
{
253-
foreach (KeyValuePair<StorageCell, byte[]> kvp in _storageReadCache)
254-
{
255-
if (!_committedThisRound.Contains(kvp.Key))
256-
{
257-
tracer!.ReportStorageRead(kvp.Key);
258-
}
259-
else if (trace!.TryGetValue(kvp.Key, out StorageChangeTrace existingTrace))
260-
{
261-
trace[kvp.Key] = new StorageChangeTrace(kvp.Value, existingTrace.After);
262-
}
263-
}
264-
}
265-
266227
base.CommitCore(tracer);
267228
_originalValues.Clear();
268229
_committedThisRound.Clear();
269-
_storageReadCache.Clear();
270230

271231
if (isTracing)
272232
{
@@ -422,19 +382,6 @@ public override void ClearStorage(Address address)
422382
{
423383
base.ClearStorage(address);
424384

425-
// Cells in _storageReadCache bypassed the journal, so base.ClearStorage (which
426-
// iterates _intraBlockCache) didn't set them to zero. Write explicit Update entries
427-
// for cells belonging to this address so CommitCore flushes zeros to BlockChange.
428-
// ClearStorage is rare (selfdestruct only).
429-
foreach (KeyValuePair<StorageCell, byte[]> kvp in _storageReadCache)
430-
{
431-
if (kvp.Key.Address == address)
432-
{
433-
Set(kvp.Key, StorageTree.ZeroBytes);
434-
}
435-
}
436-
_storageReadCache.Clear();
437-
438385
_toUpdateRoots.TryAdd(address, true);
439386

440387
PerContractState state = GetOrCreateStorage(address);
@@ -607,13 +554,7 @@ public ReadOnlySpan<byte> LoadFromTree(in StorageCell storageCell)
607554
Db.Metrics.IncrementStorageTreeCache();
608555
}
609556

610-
if (!storageCell.IsHash)
611-
{
612-
// Populate _originalValues for EIP-2200 net gas metering and _storageReadCache
613-
// to avoid creating JustCache journal entries that add commit overhead.
614-
_provider._originalValues[storageCell] = valueChange.After;
615-
_provider._storageReadCache[storageCell] = valueChange.After;
616-
}
557+
if (!storageCell.IsHash) _provider.PushToRegistryOnly(storageCell, valueChange.After);
617558
return valueChange.After;
618559
}
619560

src/Nethermind/Nethermind.State/StateProvider.cs

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ internal class StateProvider
3333
private readonly Dictionary<AddressAsKey, StackList<int>> _intraTxCache = new();
3434
private readonly HashSet<AddressAsKey> _committedThisRound = new();
3535
private readonly HashSet<AddressAsKey> _nullAccountReads = new();
36-
// Read-only cache: accounts looked up from _blockChanges but not modified in the current tx.
37-
// Avoids creating JustCache journal entries for pure reads, reducing Commit iteration cost.
38-
private readonly Dictionary<AddressAsKey, Account?> _readCache = new();
3936
// Only guarding against hot duplicates so filter doesn't need to be too big
4037
// Note:
4138
// False negatives are fine as they will just result in a overwrite set
@@ -93,23 +90,10 @@ public bool IsContract(Address address)
9390
return account is not null && account.IsContract;
9491
}
9592

96-
public bool AccountExists(Address address)
97-
{
98-
if (_intraTxCache.TryGetValue(address, out StackList<int> value))
99-
{
100-
return _changes[value.Peek()]!.ChangeType != ChangeType.Delete;
101-
}
102-
103-
AddressAsKey key = address;
104-
if (_readCache.TryGetValue(key, out Account? cached))
105-
{
106-
return cached is not null;
107-
}
108-
109-
Account? account = GetState(address);
110-
_readCache[key] = account;
111-
return account is not null;
112-
}
93+
public bool AccountExists(Address address) =>
94+
_intraTxCache.TryGetValue(address, out StackList<int> value)
95+
? _changes[value.Peek()]!.ChangeType != ChangeType.Delete
96+
: GetAndAddToCache(address) is not null;
11397

11498
public Account GetAccount(Address address) => GetThroughCache(address) ?? Account.TotallyEmpty;
11599

@@ -619,31 +603,12 @@ public void Commit(IReleaseSpec releaseSpec, IWorldStateTracer stateTracer, bool
619603
}
620604
}
621605

622-
// When tracing, reconcile _readCache entries with the trace:
623-
// - Accounts both read-cached and modified: set the Before value from read cache
624-
// - Accounts only read-cached: report as read-only via _nullAccountReads
625-
if (trace is not null)
626-
{
627-
foreach (KeyValuePair<AddressAsKey, Account?> kvp in _readCache)
628-
{
629-
if (trace.TryGetValue(kvp.Key, out ChangeTrace existingTrace))
630-
{
631-
trace[kvp.Key] = new ChangeTrace(kvp.Value, existingTrace.After);
632-
}
633-
else
634-
{
635-
_nullAccountReads.Add(kvp.Key);
636-
}
637-
}
638-
}
639-
640606
trace?.ReportStateTrace(stateTracer, _nullAccountReads, this);
641607

642608
_changes.Clear();
643609
_committedThisRound.Clear();
644610
_nullAccountReads.Clear();
645611
_intraTxCache.ResetAndClear();
646-
_readCache.Clear();
647612

648613
codeFlushTask.GetAwaiter().GetResult();
649614

@@ -791,15 +756,7 @@ internal void SetState(Address address, Account? account)
791756
return _changes[value.Peek()].Account;
792757
}
793758

794-
// Check read-only cache before falling through to journal
795-
AddressAsKey key = address;
796-
if (_readCache.TryGetValue(key, out Account? cached))
797-
{
798-
return cached;
799-
}
800-
801-
Account? account = GetState(address);
802-
_readCache[key] = account;
759+
Account account = GetAndAddToCache(address);
803760
return account;
804761
}
805762

@@ -822,7 +779,6 @@ private void Push(Address address, Account? touchedAccount, ChangeType changeTyp
822779
{
823780
StackList<int> stack = SetupCache(address);
824781
if (changeType == ChangeType.Touch
825-
&& stack.Count > 0
826782
&& _changes[stack.Peek()]!.ChangeType == ChangeType.Touch)
827783
{
828784
return;
@@ -886,7 +842,6 @@ public void Reset(bool resetBlockChanges = true)
886842
_intraTxCache.ResetAndClear();
887843
_committedThisRound.Clear();
888844
_nullAccountReads.Clear();
889-
_readCache.Clear();
890845
_changes.Clear();
891846
_needsStateRootUpdate = false;
892847

0 commit comments

Comments
 (0)