-
Notifications
You must be signed in to change notification settings - Fork 781
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
Trie proof API refactor #2949
Trie proof API refactor #2949
Conversation
Codecov ReportAttention:
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. |
Linking #2927 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if we want to make fromProof
static
@@ -113,6 +113,50 @@ export class Trie { | |||
return new Trie(opts) | |||
} | |||
|
|||
static async fromProof(proof: Proof, opts?: TrieOpts): Promise<Trie> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if I want to import two proofs? Or, I want to import a new proof in my trie later? This is now not possible anymore, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, let's bring this back to the drawing board and first decide if this is a change we want respectively which makes sense and is thought through to the end.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will give this a "blocked" label for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(this change (i.e. make fromProof
static) does not seem to be referred in the linked issue)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if I want to import two proofs? Or, I want to import a new proof in my trie later? This is now not possible anymore, right?
It seems like these tasks are possible with the new updateFromProof
function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes you are right, I somehow missed that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feel free to "unblock" this again or course of you guys think you've gotten answers for most of the questions here and things can be introduced in a non breaking way, you guys have a lot better overview than me here what's useful and makes sense regarding all this proof stuff!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, updateFromProof
is just the old fromProof
with the word update
tagged on to distinguish from the other. To avoid actual breaking changes, we could instead use createFromProof
for the static method, and leave fromProof
as it was.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now have #3186. I think we want to make the methods static in some cases? (But this is breaking)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the goal is to have a static version of verifyProof
so that a new trie instantiation isn't needed for each proof verification, or the less-than-ideal proofTrie
pattern where we keep a trie around in both the statemanager and snap sync fetchers to perform proof verification.
The changes for #3186 are included, so we should have a static and non-static version of verifyProof
and fromProof
. This shouldn't be breaking? Since users can just use the previously available non-static versions if they chose to.
packages/trie/src/trie.ts
Outdated
async fromProof(proof: Proof): Promise<void> { | ||
|
||
async updateFromProof(proof: Proof): Promise<void> { | ||
if (!equalsBytes(this.root(), this.hash(proof.shift()!))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure if I like this check, have to think about the practical downsides of this 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you try to update a sparse trie with an invalid proof, this will throw.
shift() because the root node is already in the trie, so we'll never need to add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 I'd have to hear the upside to allowing a trie to update itself from a proof to a different trie!
Should be non-breaking now 🥚 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not entirely sure about the state of this PR. We now have #3186, it seems that if we want this in this seems to be merely marking some methods as static
? (Note: we should make this non-breaking, so it should both be static and non-static). I will remove the blocked
label until we resolve what we want with this PR. (I think the gist is to make the methods static which should have been static in the first place? 🤔 )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Random changes in this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Must have been from one of the merges. I fixed it so it's just the single extra space removed and any other unnecessary changes excluded.
@@ -113,6 +113,50 @@ export class Trie { | |||
return new Trie(opts) | |||
} | |||
|
|||
static async fromProof(proof: Proof, opts?: TrieOpts): Promise<Trie> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We now have #3186. I think we want to make the methods static in some cases? (But this is breaking)
@jochem-brouwer I assume that you intended to write "I will not remove..." if not otherwise stated since that would make more sense 🙂 @scorbajio don't know, are you getting along with the things we get from #3186 ? If so, @jochem-brouwer: would you then recommend to close this PR and rather not merge? |
Yes indeed I did intend to write: I will not remove :) I think that this PR can be updated with the changes of #3186, but I think we should update this PR to also include small changes such as also making ( @holgerd77 I think you intended to ping @ScottyPoi in your last post) |
Ah, no, I indeed intended to mention @scorbajio since he requested this work to be updated and reviewed for some other follow up work. |
…orepo into trie-proof-api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two nits @scorbajio
keys[keys.length - 1], | ||
keys, | ||
values, | ||
<any>proof, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait, it is client, I think this is beyond the scope of this PR (should do a client type cleanup at some point)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I've reverted it for now. Will make the cleanup in a followup PR.
await trie._db.batch(opStack) | ||
trie.root(trie.hash(proof[0])) | ||
await trie.persistRoot() | ||
return trie |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one needs to be checked @scorbajio
This reverts commit 4801912.
…orepo into trie-proof-api
Updated this via UI I think we can take this in after having done a rough review? Will wait for a confirmation from @jochem-brouwer though (then optimally directly merge). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolved merge conflicts and fixed the example. LGTM (assuming CI passes, will directly merge)
This PR improves upon the proof methods in the
Trie
library.The Trie methods
fromProof
andverifyProof
require a new Trie object to be instantiated by the user simply for the purpose of calling the methods. This can be confusing, and seems unnecessarily indirect.With static versions of the same methods, users can now accomplish these tasks in one step.
Trie.fromProof
trie.fromProof
, with an additionalopts
parameter to pass in keyHashing settings.Now instead of:
We can just do:
Trie.verifyProof
trie.verifyProof
, with an additionalopts
parameter to pass in keyHashing settings.rootHash
parameter as expected by class method.Now instead of:
We can just do: