-
Notifications
You must be signed in to change notification settings - Fork 690
feat: add proof_getProofWithMeta JSON-RPC method
#11498
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
Open
AnkushinDaniil
wants to merge
5
commits into
master
Choose a base branch
from
feature/eth-get-proof-meta
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
346d4bc
feat: add proof_getProofWithMeta JSON-RPC method
AnkushinDaniil 2d5ce84
refactor: address PR review on proof_getProofWithMeta
AnkushinDaniil 746e249
docs: inheritdoc on IBlockchainBridge.RunTreeVisitorMetered
AnkushinDaniil 4bb4f77
refactor: collapse Accept/AcceptMetered into a single Accept
AnkushinDaniil 2460dfb
refactor: collapse RunTreeVisitor/RunTreeVisitorMetered into one method
AnkushinDaniil File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
145 changes: 145 additions & 0 deletions
145
src/Nethermind/Nethermind.JsonRpc.Test/Modules/Proof/ProofRpcModuleMetaTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,145 @@ | ||
| // SPDX-FileCopyrightText: 2026 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using Autofac; | ||
| using FluentAssertions; | ||
| using Nethermind.Blockchain; | ||
| using Nethermind.Blockchain.Find; | ||
| using Nethermind.Blockchain.Headers; | ||
| using Nethermind.Blockchain.Receipts; | ||
| using Nethermind.Config; | ||
| using Nethermind.Consensus.Processing; | ||
| using Nethermind.Core; | ||
| using Nethermind.Core.Crypto; | ||
| using Nethermind.Core.Specs; | ||
| using Nethermind.Core.Test; | ||
| using Nethermind.Core.Test.Builders; | ||
| using Nethermind.Core.Test.Db; | ||
| using Nethermind.Core.Test.Modules; | ||
| using Nethermind.Crypto; | ||
| using Nethermind.Db; | ||
| using Nethermind.Evm.State; | ||
| using Nethermind.Int256; | ||
| using Nethermind.JsonRpc.Modules; | ||
| using Nethermind.JsonRpc.Modules.Proof; | ||
| using Nethermind.Logging; | ||
| using Nethermind.Specs; | ||
| using Nethermind.Specs.Forks; | ||
| using Nethermind.State; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace Nethermind.JsonRpc.Test.Modules.Proof; | ||
|
|
||
| [Parallelizable(ParallelScope.None)] | ||
| public class ProofRpcModuleMetaTests | ||
| { | ||
| private IProofRpcModule _proofRpcModule = null!; | ||
| private IBlockTree _blockTree = null!; | ||
| private IDbProvider _dbProvider = null!; | ||
| private TestSpecProvider _specProvider = null!; | ||
| private WorldStateManager _worldStateManager = null!; | ||
| private IContainer _container = null!; | ||
|
|
||
| [SetUp] | ||
| public async Task Setup() | ||
| { | ||
| _dbProvider = await TestMemDbProvider.InitAsync(); | ||
| _worldStateManager = TestWorldStateFactory.CreateWorldStateManagerForTest(_dbProvider, LimboLogs.Instance); | ||
|
|
||
| Hash256 stateRoot; | ||
| IWorldState worldState = new WorldState(_worldStateManager.GlobalWorldState, LimboLogs.Instance); | ||
| using (System.IDisposable _ = worldState.BeginScope(IWorldState.PreGenesis)) | ||
| { | ||
| worldState.CreateAccount(TestItem.AddressA, 100_000); | ||
| worldState.CreateAccount(TestItem.AddressB, 200_000); | ||
| worldState.CreateAccount(TestItem.AddressC, 300_000); | ||
| worldState.Commit(London.Instance); | ||
| worldState.CommitTree(0); | ||
| stateRoot = worldState.StateRoot; | ||
| } | ||
|
|
||
| InMemoryReceiptStorage receiptStorage = new(); | ||
| _specProvider = new TestSpecProvider(London.Instance); | ||
| BlockTreeBuilder blockTreeBuilder = Build.A.BlockTree(new Block(Build.A.BlockHeader.WithStateRoot(stateRoot).TestObject, new BlockBody()), _specProvider) | ||
| .WithTransactions(receiptStorage) | ||
| .OfChainLength(5); | ||
| _blockTree = blockTreeBuilder.TestObject; | ||
|
|
||
| _container = new ContainerBuilder() | ||
| .AddModule(new TestNethermindModule(new ConfigProvider())) | ||
| .AddSingleton<ISpecProvider>(_specProvider) | ||
| .AddSingleton<IBlockPreprocessorStep>(new CompositeBlockPreprocessorStep(new RecoverSignatures(new EthereumEcdsa(TestBlockchainIds.ChainId), _specProvider, LimboLogs.Instance))) | ||
| .AddSingleton<IBlockTree>(_blockTree) | ||
| .AddSingleton<IDbProvider>(_dbProvider) | ||
| .AddSingleton<IHeaderFinder>(blockTreeBuilder.HeaderStore) | ||
| .AddSingleton<IReceiptStorage>(receiptStorage) | ||
| .AddSingleton<IWorldStateManager>(_worldStateManager) | ||
| .Build(); | ||
| _proofRpcModule = _container.Resolve<IRpcModuleFactory<IProofRpcModule>>().Create(); | ||
| } | ||
|
|
||
| [TearDown] | ||
| public void TearDown() => _container.Dispose(); | ||
|
|
||
| [Test] | ||
| public void Returns_proof_payload_alongside_meta() | ||
| { | ||
| ResultWrapper<AccountProofWithMeta> result = _proofRpcModule.proof_getProofWithMeta( | ||
| TestItem.AddressA, new HashSet<UInt256>(), BlockParameter.Earliest); | ||
|
|
||
| result.Result.ResultType.Should().Be(ResultType.Success); | ||
| AccountProofWithMeta payload = result.Data; | ||
|
|
||
| payload.Should().NotBeNull(); | ||
| payload.Proof.Should().NotBeNull(); | ||
| payload.Proof.Address.Should().Be(TestItem.AddressA); | ||
| payload.Proof.Balance.Should().Be(100_000); | ||
| payload.Proof.Proof.Should().NotBeNull(); | ||
| payload.Proof.Proof.Length.Should().BeGreaterThan(0); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Meta_counters_have_sane_values() | ||
| { | ||
| AccountProofWithMeta payload = _proofRpcModule.proof_getProofWithMeta( | ||
| TestItem.AddressA, new HashSet<UInt256>(), BlockParameter.Earliest).Data; | ||
|
|
||
| payload.Meta.Should().NotBeNull(); | ||
| payload.Meta.NodeLookups.Should().BeGreaterThan(0, | ||
| "every proof generation must perform at least one node lookup"); | ||
| payload.Meta.CacheHits.Should().BeGreaterThanOrEqualTo(0); | ||
| payload.Meta.CacheHits.Should().BeLessThanOrEqualTo(payload.Meta.NodeLookups, | ||
| "cache hits cannot exceed total lookups"); | ||
| payload.Meta.MaxDepth.Should().BeGreaterThanOrEqualTo(0); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Repeated_calls_increase_cache_hits_on_warm_path() | ||
| { | ||
| AccountProofWithMeta first = _proofRpcModule.proof_getProofWithMeta( | ||
| TestItem.AddressA, new HashSet<UInt256>(), BlockParameter.Earliest).Data; | ||
| AccountProofWithMeta second = _proofRpcModule.proof_getProofWithMeta( | ||
| TestItem.AddressA, new HashSet<UInt256>(), BlockParameter.Earliest).Data; | ||
|
|
||
| second.Meta.CacheHits.Should().BeGreaterThanOrEqualTo(first.Meta.CacheHits, | ||
| "warming the cache should not reduce hit count on identical query"); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Rejects_too_many_storage_keys() | ||
| { | ||
| HashSet<UInt256> storageKeys = new(); | ||
| for (int i = 0; i < 1001; i++) | ||
| { | ||
| storageKeys.Add((UInt256)i); | ||
| } | ||
|
|
||
| ResultWrapper<AccountProofWithMeta> result = _proofRpcModule.proof_getProofWithMeta( | ||
| TestItem.AddressA, storageKeys, BlockParameter.Earliest); | ||
|
|
||
| result.Result.ResultType.Should().Be(ResultType.Failure); | ||
| result.ErrorCode.Should().Be(ErrorCodes.InvalidParams); | ||
| } | ||
| } |
20 changes: 20 additions & 0 deletions
20
src/Nethermind/Nethermind.JsonRpc/Modules/Proof/AccountProofWithMeta.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // SPDX-FileCopyrightText: 2026 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| using Nethermind.State.Proofs; | ||
|
|
||
| namespace Nethermind.JsonRpc.Modules.Proof | ||
| { | ||
| /// <summary> | ||
| /// Response payload of <c>proof_getProofWithMeta</c> — the EIP-1186 account proof plus | ||
| /// per-call diagnostics from <see cref="ProofMeta"/>. | ||
| /// </summary> | ||
| public class AccountProofWithMeta | ||
| { | ||
| /// <summary>EIP-1186 account proof, identical in shape to <c>eth_getProof</c>'s result.</summary> | ||
| public AccountProof Proof { get; set; } = null!; | ||
|
|
||
| /// <summary>Per-call diagnostics captured during proof construction.</summary> | ||
| public ProofMeta Meta { get; set; } = null!; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/Nethermind/Nethermind.JsonRpc/Modules/Proof/ProofMeta.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| // SPDX-FileCopyrightText: 2026 Demerzel Solutions Limited | ||
| // SPDX-License-Identifier: LGPL-3.0-only | ||
|
|
||
| namespace Nethermind.JsonRpc.Modules.Proof | ||
| { | ||
| /// <summary> | ||
| /// Per-call diagnostics returned by <c>proof_getProofWithMeta</c> alongside the EIP-1186 proof. | ||
| /// </summary> | ||
| public class ProofMeta | ||
| { | ||
| /// <summary> | ||
| /// Total trie-node fetches the proof construction triggered (account + any storage tries). | ||
| /// </summary> | ||
| public long NodeLookups { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Subset of <see cref="NodeLookups"/> served from the in-process trie store cache. | ||
| /// </summary> | ||
| public long CacheHits { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Deepest level the visitor reached in the account or any storage trie, in nibbles. | ||
| /// </summary> | ||
| public int MaxDepth { get; set; } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.