-
Notifications
You must be signed in to change notification settings - Fork 144
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
BlockSync provider #724
BlockSync provider #724
Conversation
a655574
to
ae8e9a6
Compare
c11581f
to
909e90e
Compare
19b2452
to
61c4300
Compare
61c4300
to
62d6e1a
Compare
Thanks so much for this contribution! Looks generally good, and happy to help with any of the changes or suggestions if you would like :) |
c0bd0b8
to
54a9cd1
Compare
54a9cd1
to
367ed61
Compare
0a42ced
to
6f12372
Compare
pub fn include_blocks(&self) -> bool { | ||
self.options == BLOCKS || self.options == BLOCKS_MESSAGES | ||
} | ||
|
||
/// If a request expects messages to be included in response. | ||
pub fn include_messages(&self) -> bool { | ||
self.options == MESSAGES || self.options == BLOCKS_MESSAGES | ||
} |
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.
These can be bit operations, BLOCKS
is the least significant bit, and MESSAGES
is the second least significant bit.
Can be something like:
pub fn include_blocks(&self) -> bool {
self.options & BLOCKS != 0
}
/// If a request expects messages to be included in response.
pub fn include_messages(&self) -> bool {
self.options & MESSAGES != 0
}
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.
feels a little less readable imo 🤔
use std::convert::TryFrom; | ||
|
||
/// Blocksync request options | ||
pub const BLOCKS: u64 = 1; | ||
pub const MESSAGES: u64 = 2; | ||
pub const BLOCKS_MESSAGES: u64 = 3; |
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.
Don't need 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.
it's in a spec though?
https://spec.filecoin.io/#algorithms__block_sync
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 it's not necessary though, that only exists because it wasn't bit flags before. 0b01 | 0b10 == 3
. There is no need to use this constant itself.
Edit: Also that blocksync spec is wildly incorrect, don't use it for anything meaningful
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 it's not necessary though, that only exists because it wasn't bit flags before
Sorry, when you say before
are you referring to your suggestion here: #724 (comment), or these are bit flags in a spec now too?
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, thanks so much for the contribution. The only comments left are opinionated and I'm good with 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.
Sorry was just waiting for branch to update before pulling in, didn't want to merge into your branch if you were making changes. I just updated the branch and will pull in when CI passes. Thanks!
Summary of changes
Changes introduced in this pull request:
BlockSync "provider" - the logic to run for an incoming
BlockSync
libp2p request.Test notes
It was somewhat hard to test this MR. I've added a unit test prepopulating MemoryDB with some chain data (thanks @austinabell for generating file for me), and compared the response with FilFox, see comments in the test.
Reference issue to close (if applicable)
Closes #673
Other information and links