Skip to content

Get block hashes in one HyperSync query - #431

Merged
DZakh merged 4 commits into
mainfrom
dz/block-hashes-in-one-query
Jan 24, 2025
Merged

Get block hashes in one HyperSync query#431
DZakh merged 4 commits into
mainfrom
dz/block-hashes-in-one-query

Conversation

@DZakh

@DZakh DZakh commented Jan 21, 2025

Copy link
Copy Markdown
Member

No description provided.

@DZakh
DZakh requested a review from JonoPrest January 21, 2025 10:09
Comment on lines +362 to +367
let res = await queryBlockData(
~fromBlock=fromBlock.contents,
~toBlock=toBlock.contents,
~serverUrl,
~logger,
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a check for a reasonable block range here?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually that's not really the behaviour I'm interested in. More along the lines of if say - block [10, 5_000_000, 5_000_001] is passed then this would be inefficient.

We don't necessarily need an alternative approach for the one case we use this for but we should probably just validate somewhere that we're getting reasonable numbers on this.

Comment on lines +368 to +372
res->Result.map(datas => {
datas->Array.keep(data => set->Utils.Set.has(data.blockNumber))
})
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And it would probably be good to validate that all block numbers that are queried, are in fact returned

@JonoPrest JonoPrest left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some suggestions for improvement but I'll leave it up to you. Thanks!

@DZakh

DZakh commented Jan 24, 2025

Copy link
Copy Markdown
Member Author

@JonoPrest Made the fixes in the commit. I'll appreciate a rereview b81fd58

Belt.Array.concat(acc, [v.blockNumber])
let getThresholdBlockNumbers = (self: t, ~currentBlockHeight) => {
let blockNumbers = []
self.lastBlockScannedDataList->Belt.List.reduceReverseU((), ((), v) => {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think probably better to use forEach here. Maybe List.reverse->List.forEach

Maybe we don't even need to worry about ordering here.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to rewrite the module to use a hash-map data structure, otherwise some reorg detections might be lost for merge queries. I'll leave it for then.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accepted your suggestion

Comment thread codegenerator/cli/npm/envio/src/ReorgDetection.res
Comment on lines +429 to +432
let getBlockHashes = switch getBlockHashesMock {
| Some(getBlockHashes) => getBlockHashes
| None => chainFetcher.chainConfig.source.getBlockHashes
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it makes a difference to the compiled code but you could default the param instead of to ? rather chainFetcher.chainConfig.source.getBlockHashes

@JonoPrest JonoPrest left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome thanks Dmitry 💪🏼

@DZakh
DZakh enabled auto-merge (squash) January 24, 2025 12:50
Co-authored-by: Jono Prest <65739024+JonoPrest@users.noreply.github.com>
@DZakh
DZakh force-pushed the dz/block-hashes-in-one-query branch from 8ac8714 to e8cdab5 Compare January 24, 2025 13:06
@DZakh
DZakh merged commit 76f41a0 into main Jan 24, 2025
@DZakh
DZakh deleted the dz/block-hashes-in-one-query branch January 24, 2025 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants