-
Notifications
You must be signed in to change notification settings - Fork 549
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
Add bitswap block encoding/decoding to ocaml #10579
Conversation
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.
Also, what do you think of cross-testing both implementations on random samples of data?
Like, adding a new RPC for testing purposes to query libp2p helper for blocks generated for the data provided.
And then checking that representation by both versions of the code is same.
in | ||
loop ls >>| List.concat | ||
loop ls (return []) >>| List.rev >>| List.concat |
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 don't we rewrite above with fold instead of manual recursive loop ?
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.
Because a fold won't terminate if acc
returns error (will continue to iterate regardless). I could use a fold_until
instead, but the implementation would be much uglier I fear.
let size = Bigstring.length chunk in | ||
last_leaf_block_data_size := | ||
if !last_leaf_block_data_size = 0 then size | ||
else min !last_leaf_block_data_size size |
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 understand the logic here, like leaf is the smallest block and for it queue is empty. But use of min
strikes my sight, could we get rid of 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.
Although it's just a test and isn't so important.
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.
Yeah, the min was just the easy way to make this work, since the "last leaf" isn't the last block you traverse here.
aed20a9
to
e5daaa6
Compare
Closes #9451.