Added support for IBD #240
Conversation
30ca670 to
f26a26f
Compare
f26a26f to
cf673d1
Compare
mcelrath
left a comment
There was a problem hiding this comment.
Overall this is good, it just lacks tests. Here is a list from Gemini of missing tests:
- No
get_beads_afterLogic Tests: The new Braid::get_beads_after() function in
node/src/braid/mod.rs, which contains the core logic for this feature, has no unit
tests. As I mentioned in the review, the logic of this function might be fragile,
making the lack of tests a critical issue. - No Serialization Tests: The new BeadRequest::GetBeadsAfter and
BeadResponse::GetBeadsAfter variants are not tested for serialization and
deserialization in node/src/bead/tests.rs. This means there's no guarantee they can be
correctly encoded and decoded for transmission over the network. - No
BeadSyncErrorSerialization Tests: The new BeadSyncError enum itself lacks unit
tests for its Encodable and Decodable implementations. - No End-to-End Test: There are no integration tests that simulate a full
request-response cycle for the GetBeadsAfter flow between two peers. The test in
node/src/behaviour/tests.rs only covers the older GetBeads flow. - No
GenesisMismatchTest: The new logic for handling a GenesisMismatch error (where a
peer receives this error and then requests the genesis beads) is not covered by any
test.
ac989f3 to
06e0aca
Compare
06e0aca to
6717040
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR implements support for GetBeadsAfter request-response functionality to enable efficient incremental synchronization between nodes in the braid pool network.
- Added
GetBeadsAfterrequest/response variants to enable requesting beads after a specific set of tip hashes - Introduced
BeadSyncErrorenum for better error handling with structured error types - Implemented
get_beads_after()algorithm in the Braid that relies on topologically sorted cohorts
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| } else { | ||
| swarm.behaviour_mut().respond_with_error( | ||
| channel, | ||
| BeadSyncError::Other(String::from( |
There was a problem hiding this comment.
Replace hardcoded error message with a more specific BeadSyncError variant. The TODO comment indicates this should be addressed.
424cefe to
8f45124
Compare
9c907f9 to
c3450e5
Compare
c3450e5 to
ba3de98
Compare
f5fdbb1 to
3088752
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 32 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
d25b907 to
ad256e4
Compare
- Copies/reimplements some macros from rust-bitcoin (that are not
exported)
- Allows an "enum" variant that can include both integer and
data-carrying variants with explicit discriminant assignment
(because discriminants are protocol "magic numbers" and would be
needed for any alternative implementation)
- Automatically implements consensus_encode/decode including Vec
arguments
- Update BeadRequest, BeadResponse, BeadSyncError to use
braidpool_protocol!
- Remove DRY-violating BeadRequestType
- Add rustdoc comments to all these messages
- Refuse to respond to most messages if ibd_spinlock is held
condition for no sync peer in connection mapping
removing unwraps and typos in comments
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 10 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
|
Currently, this PR is not working to download any beads, because:
I verified that a node in IBD correctly refuses Stratum connections. To fix this:
The dynamics of the Braid are that it should never fork, and we never discard valid beads. If we had a fork, both sides of the fork need to share their beads. Then someone names both sides as parents and ties them up into a big cohort. The side with lower hashrate on the fork won't get paid, but this is expected behavior. But we have to evaluate that by actually getting those beads, computing the cohorts, and evaluating their work. We make payout decisions on beads we didn't receive so shouldn't be using any kind of timing decisions on whether we should ask for beads. We should always ask for beads. I think we should remove the So I propose:
I will implement (4) as part of #299. |
Changing verbosity of logs
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 14 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| continue; | ||
| } | ||
| }; | ||
| let _val = _ibd_bridge_rx.await.unwrap(); |
There was a problem hiding this comment.
The error handling in line 1148 uses unwrap() on _ibd_bridge_rx.await, which can panic if the sender is dropped. This is inconsistent with the error handling pattern used elsewhere in the code (e.g., lines 1143-1146).
Recommendation: Handle the potential error properly:
let _val = match _ibd_bridge_rx.await {
Ok(val) => val,
Err(error) => {
error!(error=?error, "Failed to receive offset initialization response");
continue;
}
};| let _val = _ibd_bridge_rx.await.unwrap(); | |
| let _val = match _ibd_bridge_rx.await { | |
| Ok(val) => val, | |
| Err(error) => { | |
| error!(error=?error, "Failed to receive offset initialization response"); | |
| continue; | |
| } | |
| }; |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| ) -> anyhow::Result<(String, String, String)> { | ||
| let mut parent_set: HashMap<usize, HashSet<usize>> = HashMap::new(); | ||
|
|
||
| for (idx, b) in beads.iter().enumerate() { |
There was a problem hiding this comment.
There was a problem hiding this comment.
Yes, agreed will replace it accordingly .
There was a problem hiding this comment.
This will panic if the bead is not added. Move this block of code up into the AddBeadStatus::BeadAdded match block.
Changing verbosity of logs refactor: moving condition in lib.rs to if branch

Additional changes made
IBDfunctionality following the flow asGetTips--->GetBeads---->GetDataalong with acknowledgement.IBDHandlerfor managing the cache requirements corresponding toIBD.NOTE: Algorithm works only if Braid::cohorts vector is topologically sorted
I have read the extend function and it seems that the above condition is always true, please review this once again for any edge cases.