Skip to content

Commit

Permalink
Remove Compression & Decompression from RLPMemo (#456)
Browse files Browse the repository at this point in the history
* initial commit

* modify/add tests

* minor changes

* minor fixes

* add nibbleset in RlpMemo to remember the order

* nit spacing fix

* merge with latest main

* address comments, re-order header - breaking merkle computation tests

* improve test to catch failures

* minor whitespace fixes in test

* passing test + index at end

* improve dictionary/memo comparison

* add test case for keccak->rlp modification

* minor format changes in the new test

* fix issues
  • Loading branch information
dipkakwani authored Jan 22, 2025
1 parent 2a09a23 commit 7ba23f0
Show file tree
Hide file tree
Showing 6 changed files with 679 additions and 317 deletions.
61 changes: 0 additions & 61 deletions src/Paprika.Tests/Chain/PrefetchingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,67 +71,6 @@ public async Task Prefetches_properly_on_not_changed_structure()
}
}

[Test]
public async Task Makes_all_decompression_on_prefetch()
{
using var db = PagedDb.NativeMemoryDb(8 * 1024 * 1024, 2);
var merkle = new ComputeMerkleBehavior(ComputeMerkleBehavior.ParallelismNone);
await using var blockchain = new Blockchain(db, merkle);

// Create one block with some values, commit it and finalize
var hash = Keccak.EmptyTreeHash;

hash = BuildBlock(blockchain, hash, 1);
blockchain.Finalize(hash);
await blockchain.WaitTillFlush(hash);

hash = BuildBlock(blockchain, hash, 2);

return;

static Keccak BuildBlock(Blockchain blockchain, Keccak parent, uint number)
{
var isFirst = number == 1;

byte[] value = isFirst ? [17] : [23];

const int seed = 13;
const int contracts = 10;
const int slots = 10;

using var block = blockchain.StartNew(parent);
var random = new Random(seed);

// Open prefetcher on blocks beyond first
var prefetcher = isFirst == false ? block.OpenPrefetcher() : null;

for (var i = 0; i < contracts; i++)
{
var contract = random.NextKeccak();
prefetcher?.PrefetchAccount(contract);

if (isFirst)
{
block.SetAccount(contract, new Account(1, 1, Keccak.Zero, Keccak.Zero));
}

for (var j = 0; j < slots; j++)
{
var storage = random.NextKeccak();
prefetcher?.PrefetchStorage(contract, storage);
block.SetStorage(contract, storage, value);
}
}

prefetcher?.SpinTillPrefetchDone();

using (RlpMemo.NoDecompression())
{
return block.Commit(number);
}
}
}

private static void Set(Keccak[] accounts, uint account, IWorldState start, UInt256 bigNonce)
{
ref var k = ref accounts[account];
Expand Down
Loading

0 comments on commit 7ba23f0

Please sign in to comment.