@@ -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
0 commit comments