-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merkleization #77
Comments
To start working on this, I suggest writing some test on the current Nethermind client (here, probably: https://github.com/NethermindEth/nethermind/blob/22cc2b238e72e59a28c4b9e99019a4a145cc5895/src/Nethermind/Nethermind.Trie.Test/TrieTests.cs#L26) and check what we get as the |
Following the approach described above, I've written the following test in the Nethermind client (NC moving forward) and translated it into Paprika: [Test]
public void Single_account()
{
MemDb memDb = new();
using TrieStore trieStore = new(memDb, Prune.WhenCacheReaches(1.MB()), Persist.EveryBlock, _logManager);
PatriciaTree patriciaTree = new(trieStore, _logManager);
var key = new Keccak(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7 });
var account = new Account(23, 13);
patriciaTree.Set(key.Bytes, new AccountDecoder().Encode(account).Bytes);
patriciaTree.Commit(blockNumber: 0);
patriciaTree.UpdateRootHash();
var rootHash = patriciaTree.RootHash;
TestContext.WriteLine(rootHash);
} This, translated to Paprika looks something like: [Test]
public void Single_account()
{
using var db = PagedDb.NativeMemoryDb(SmallDb);
var key = Values.Key0;
var account = new Account(Values.Balance0, Values.Nonce0);
using (var batch = db.BeginNextBatch())
{
batch.Set(key, account);
batch.Commit(CommitOptions.FlushDataAndRoot);
}
using (var batch = db.BeginReadOnlyBatch())
{
var rootHash = batch.GetRootHash();
var expectedRootHash =
new Keccak(Convert.FromHexString("E2533A0A0C4F1DDB72FEB7BFAAD12A83853447DEAAB6F28FA5C443DD2D37C3FB"));
Assert.That(rootHash, Is.EqualTo(expectedRootHash));
}
}
This raises a couple of questions:
|
As for testing, eventually I think it could be useful to have some sort of test generator on NC: this generator would randomly produce a sequence of actions (setting, committing, ???), execute them, compute the root hash, and then save the sequence into a file. Then, Paprika could load those files, run the same actions, compute the root hash and validate it against the expected hash. |
why not bring Nethermind Client modules to Paprika or Paprika to Nethermind Client for this and actually have it integrated? Or create a 3rd project that would integrate and fuzz both and then compare. |
What NC does it uses the I don't think the block number is problematic at all, as Paprika needs to deliver a single hash at the end of the day. The hash is the hash of the state tree. The rest, how it's used etc. it's up to NC. It's fine to have
That would be the ultimate testing scenario. Initially, it'd be great to have a suite of unit tests that are capable of showing that basic scenarios are covered. Unfortunately one needs to write the same tests with NC first so that the value is calculated properly. We could have a submodule for NC or build some parts as packages to be reused. |
For parallelization - if you can |
Memoization will be addressed at #120 |
Storage will be handled at #121 |
The |
The leftovers are in separate issues. |
Implement Merkleization for the tree
Branch
,Leaf
andExtension
to aSpan
(De)serialization of Merkle Nodes #98PagedDb
The last 3 will be addressed in separate issues.
The text was updated successfully, but these errors were encountered: