-
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
client: create snap sync fetcher to sync accounts #2107
Conversation
295c386
to
4b7480d
Compare
Codecov Report
Additional details and impacted files
Flags with carried forward coverage won't be shown. Click here to find out more. |
When calling
Sometimes, the proof is
Will need to also finish implementing |
Now that there is reference data for |
awesome glad to see you got it working! |
yes we need separate fetchers for fetching each of the ranges 👍 |
@g11tech I wasn't able to get
I ended up hardcoding it to |
looks alright to me the way you set, i will check and add a fix in this PR |
a8d306b
to
9a56af0
Compare
430b925
to
877a5e1
Compare
12272fb
to
d472cb2
Compare
f3a7314
to
f49938a
Compare
8451520
to
c0995bb
Compare
if (accounts.length > 0 && accounts[accounts.length - 1]?.hash.compare(limit) >= 0) { | ||
return false | ||
} else { | ||
// TODO: Check if there is a proof of missing limit in state |
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.
@jochem-brouwer @scorbajio Is there an early check that can be done which can see there are no more accounts between the last and the limit
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.
verifyRangeProof
returns a boolean if there are more items or not. We could maybe early-check hasRightElement
but I don't know if this really speeds it up?
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 was originally thinking that if there is an empty response to a request, it means there are no accounts in a given range. There might also be a cryptographic way to check this.
await trie.verifyRangeProof(stateRoot, origin, keys[keys.length - 1], keys, values, <any>proof) | ||
} | ||
|
||
private isMissingRightRange( |
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.
@jochem-brouwer @scorbajio pls review the correctness of this fn
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.
Isn't this intended to be the same as trie's hasRightElement
?
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.
It seems like the way it is being done is in line with the approach used in geth. If the returned account hash is past the limit requested, it is discarded since it is a part of the next range. This also guarantees there are no more accounts to the right of the last account received within the requested range.
} else { | ||
// validate the proof | ||
try { | ||
// verifyRangeProof will also verify validate there are no missed states between origin and |
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.
@jochem-brouwer @scorbajio pls review if my understanding of proof verification is correct here w.r.t origin that using origin
in verifyRangeProof (see the definition of this private function) will validate that there are no missed
accounts between origin and the first account recieved
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.
It /should/ throw if there are missing nodes, but we should probably test this (or it is already tested in 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.
The way you are verifying makes sense to me. Could be useful to add some try-except blocks and log any errors in each function body.
* @param result fetch result | ||
*/ | ||
async store(result: AccountData[]): Promise<void> { | ||
this.debug(`Stored ${result.length} accounts in account 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.
right now store doesn't do anything, as a separate helper class with be added in a followup PR to track and aid the fetcher
7ff31da
to
9fef3e0
Compare
0e386c8
to
5a73cd3
Compare
…s-monorepo into snap-client-fetchers
92b1c19
to
5b46855
Compare
* @param job | ||
* @param withIndex pass true to additionally output job.index | ||
*/ | ||
jobStr(job: Job<JobTask, JobResult, StorageItem>, withIndex = false) { |
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.
is this something that relates to PR or you added for convenience factor?
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.
ahh i see because you added jobstr as abstract method
@@ -107,7 +107,6 @@ export class BlockFetcher extends BlockFetcherBase<Block[], Block> { | |||
} else if (result.length > 0 && result.length < job.task.count) { | |||
// Save partial result to re-request missing items. | |||
job.partialResult = result | |||
this.debug(`Partial result received=${result.length} expected=${job.task.count}`) |
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.
why remove debug log?
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.
looks good though still needs to be extensively tested locally and on testnets for the fetcher start/end conditions and consistency, but any fixes regarding those can be done in followup PRs as this is still wip
Congrats, your important contribution to this open-source project has earned you a GitPOAP! GitPOAP: 2023 EthereumJS Contributor: Head to gitpoap.io & connect your GitHub account to mint! Learn more about GitPOAPs here. |
AccountFetcher
Capture data now done/part of
getAccountRange
getStorageRanges
getByteCodes
getTrieNodes
My understanding is that there needs to be one fetcher per each
get
call defined in the snap specs. Open to suggestions on this design plan.