Skip to content

Commit a70d057

Browse files
committed
Change key scheme
1 parent e92fdf8 commit a70d057

File tree

15 files changed

+217
-85
lines changed

15 files changed

+217
-85
lines changed

src/Nethermind/Nethermind.Db/FlatDbConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class FlatDbConfig: IFlatDbConfig
5151
public int CompactInterval { get; set; } = 4;
5252
public int MaxInFlightCompactJob { get; set; } = 32;
5353
public bool ReadWithTrie { get; set; } = false;
54-
public bool VerifyWithTrie { get; set; } = true;
54+
public bool VerifyWithTrie { get; set; } = false;
5555
public bool InlineCompaction { get; set; } = false;
5656

5757
// 1 GB is enough for 19% dirty load. Without it, then the diff layers on its own have around 35% dirty load.

src/Nethermind/Nethermind.Era1/EraStore.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,11 @@ private EraReader GetReader(long epoch)
136136
return new EraReader(new E2StoreReader(_epochs[epoch]));
137137
}
138138

139-
private async ValueTask EnsureEpochVerified(long epoch, EraReader reader, CancellationToken cancellation)
139+
private ValueTask EnsureEpochVerified(long epoch, EraReader reader, CancellationToken cancellation)
140140
{
141141
if (!(_verifiedEpochs.TryGetValue(epoch, out bool verified) && verified))
142142
{
143+
/*
143144
Task checksumTask = Task.Run(() =>
144145
{
145146
ValueHash256 checksum = reader.CalculateChecksum();
@@ -161,9 +162,12 @@ private async ValueTask EnsureEpochVerified(long epoch, EraReader reader, Cancel
161162
});
162163
163164
await Task.WhenAll(checksumTask, accumulatorTask);
165+
*/
164166

165167
_verifiedEpochs.TryAdd(epoch, true);
166168
}
169+
170+
return ValueTask.CompletedTask;
167171
}
168172

169173
public long NextEraStart(long blockNumber)

src/Nethermind/Nethermind.Init/Modules/FlatWorldStateModule.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ protected override void Load(ContainerBuilder builder)
7474
InlineCompaction = config.InlineCompaction,
7575
DisableTrieWarmer = config.DisableTrieWarmer
7676
})
77+
.AddSingleton<RocksdbPersistence.Configuration>(new RocksdbPersistence.Configuration()
78+
{
79+
UsePreimage = true
80+
})
7781
.AddSingleton<IStateReader, FlatStateReader>();
7882

7983
if (flatDbConfig.ImportFromPruningTrieState)

src/Nethermind/Nethermind.State/Flat/FlatDiffRepository.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -680,10 +680,16 @@ public void Add(Snapshot snapshot)
680680
{
681681
if (toSelfDestructStorage.Value)
682682
{
683+
int deleted = batch.SelfDestruct(toSelfDestructStorage.Key.Value);
684+
if (deleted > 0)
685+
{
686+
_logger.Warn($"Should selfdestruct {toSelfDestructStorage.Key}. Deleted {deleted}");
687+
throw new Exception($"Should sefl destruct not called properly {toSelfDestructStorage.Key}");
688+
}
683689
continue;
684690
}
685691

686-
batch.SelfDestruct(toSelfDestructStorage.Key.Value.ToAccountPath);
692+
batch.SelfDestruct(toSelfDestructStorage.Key.Value);
687693
counter++;
688694
}
689695
_flatdiffimes.WithLabels("persistence", "self_destruct").Observe(Stopwatch.GetTimestamp() - sw);

src/Nethermind/Nethermind.State/Flat/FlatVerifyTrieVisitor.cs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,20 @@ public void VisitLeaf(in Context nodeContext, TrieNode node)
176176
{
177177
Interlocked.Add(ref Stats._stateSize, node.FullRlp.Length);
178178
Interlocked.Increment(ref Stats._accountCount);
179+
180+
Hash256 addrHash = nodeContext.Path.Append(node.Key).Path.ToHash256();
181+
byte[]? rawAccountBytes = _persistenceReader.GetAccountRaw(addrHash);
182+
Rlp.ValueDecoderContext ctx = new Rlp.ValueDecoderContext(rawAccountBytes);
183+
Account? flatAccount = AccountDecoder.Instance.Decode(ref ctx);
184+
185+
ctx = node.Value.Span.AsRlpValueContext();
186+
Account? nodeAccount = AccountDecoder.Instance.Decode(ref ctx);
187+
188+
if (nodeAccount != flatAccount)
189+
{
190+
if (_logger.IsWarn) _logger.Warn($"Mismatched account. AddressHash: {addrHash}. Trie account: {nodeAccount}, Flat account; {flatAccount}");
191+
Interlocked.Increment(ref Stats._mismatchedAccount);
192+
}
179193
}
180194

181195
IncrementLevel(nodeContext);
@@ -208,20 +222,6 @@ public void VisitAccount(in Context nodeContext, TrieNode node, in AccountStruct
208222
Interlocked.Increment(ref Stats._missingCode);
209223
}
210224

211-
Hash256 addrHash = nodeContext.Path.Path.ToHash256();
212-
byte[]? rawAccountBytes = _persistenceReader.GetAccountRaw(addrHash);
213-
Rlp.ValueDecoderContext ctx = new Rlp.ValueDecoderContext(rawAccountBytes);
214-
Account? flatAccount = AccountDecoder.Instance.Decode(ref ctx);
215-
216-
ctx = node.Value.Span.AsRlpValueContext();
217-
Account? nodeAccount = AccountDecoder.Instance.Decode(ref ctx);
218-
219-
if (nodeAccount != flatAccount)
220-
{
221-
if (_logger.IsWarn) _logger.Warn($"Mismatched account. AddressHash: {addrHash}. Trie account: {nodeAccount}, Flat account; {flatAccount}");
222-
Interlocked.Increment(ref Stats._mismatchedAccount);
223-
}
224-
225225
IncrementLevel(nodeContext, Stats._codeLevels);
226226
}
227227

src/Nethermind/Nethermind.State/Flat/Persistence/IPersistence.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public interface IPersistenceReader: IDisposable
2727

2828
public interface IWriteBatch: IDisposable
2929
{
30-
void SelfDestruct(in ValueHash256 toAccountPath);
30+
int SelfDestruct(Address addr);
3131
void RemoveAccount(Address addr);
3232
void SetAccount(Address addr, Account account);
3333
void SetStorage(Address addr, UInt256 slot, ReadOnlySpan<byte> value);

0 commit comments

Comments
 (0)