-
Notifications
You must be signed in to change notification settings - Fork 3
3SF & Fork-choice #24
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
Conversation
Signed-off-by: turuslan <[email protected]>
Signed-off-by: turuslan <[email protected]>
Signed-off-by: turuslan <[email protected]>
Signed-off-by: turuslan <[email protected]>
Signed-off-by: turuslan <[email protected]>
Signed-off-by: turuslan <[email protected]>
Signed-off-by: turuslan <[email protected]>
…nt FCBlockTree class for fork choice logic
…t retrieval; refactor BlockBody to use variable size containers
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.
Pull Request Overview
This PR implements a fork choice rule mechanism and integrates foundational infrastructure for fork choice logic in the blockchain module. The changes introduce the ForkChoiceStore class with vote processing, block production, and head selection capabilities, along with a new FCBlockTree implementation and updates to support interval-based timeline execution.
Key changes:
- Implements
ForkChoiceStorewith comprehensive fork choice algorithms including vote processing, safe target computation, and block production - Adds
FCBlockTreeas a fork choice-aware block tree implementation - Updates timeline logic to support interval-based execution with slot subdivision
- Integrates fork choice store into production and networking modules
Reviewed Changes
Copilot reviewed 38 out of 38 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| src/blockchain/fork_choice.hpp/cpp | Core fork choice store implementation with vote processing and block production |
| src/blockchain/impl/fc_block_tree.hpp/cpp | Fork choice-aware block tree implementation |
| src/modules/production/production.cpp | Integration of fork choice for block and vote production |
| src/modules/networking/networking.cpp | Integration of fork choice for attestation processing |
| src/app/impl/timeline_impl.cpp | Enhanced timeline with interval-based slot execution |
| tests/unit/blockchain/fork_choice_test.cpp | Comprehensive test suite for fork choice functionality |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/blockchain/fork_choice.cpp
Outdated
| }; | ||
| store.blocks_.emplace(anchor_root, std::move(anchor_block)); | ||
| store.states_.emplace(anchor_root, std::move(anchor_state)); | ||
| std::cout << "Genesis (anchor) root " << anchor_root.toHex() << "\n"; |
Copilot
AI
Sep 26, 2025
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.
Using std::cout for output in production code violates logging conventions. This should use the proper logging system (SL_INFO, SL_DEBUG, etc.) or be removed entirely.
src/executable/lean_node.cpp
Outdated
| std::chrono::duration_cast<std::chrono::milliseconds>( | ||
| std::chrono::system_clock::now().time_since_epoch()) | ||
| .count(); | ||
| genesis_time += 12000 - (genesis_time % 12000); // 1758719218000 |
Copilot
AI
Sep 26, 2025
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 magic number 12000 should be replaced with a named constant (e.g., GENESIS_TIME_INTERVAL_MS) to improve code readability and maintainability. The comment with the hardcoded timestamp should also be removed.
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.
Pull Request Overview
Copilot reviewed 39 out of 39 changed files in this pull request and generated 6 comments.
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/blockchain/fork_choice.hpp
Outdated
|
|
||
| private: | ||
| STF stf_; | ||
| std::shared_ptr<clock::SystemClock> clock_; |
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.
time_ counter tracks time observed and incremented by ForkChoiceStore state machine.
It's not expected to be real clock, and not mockable.
| std::shared_ptr<clock::SystemClock> clock_; | |
| Interval time_ = 0; |
May add separate slotFromClock method
| } else { | ||
| // forkchoice should be correctly ticked to current time before importing | ||
| // gossiped attestations | ||
| if (vote.slot > getCurrentSlot() + 1) { |
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.
getCurrentSlot() should return slot from time_, not clock.now()
| if (vote.slot > getCurrentSlot() + 1) { | |
| if (vote.slot > getCurrentSlot()) { |
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.
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
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.
Pull Request Overview
Copilot reviewed 39 out of 39 changed files in this pull request and generated 5 comments.
Comments suppressed due to low confidence (2)
src/modules/shared/prodution_types.tmp.hpp:1
- The filename contains a typo: 'prodution_types.tmp.hpp' should be 'production_types.tmp.hpp' (missing 'c' in 'production').
/**
src/blockchain/fork_choice.cpp:1
- Large block of commented debug code should be removed from production code. If debugging functionality is needed, consider using a proper logging mechanism with debug levels instead.
/**
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| blocks_.emplace(block_hash, final_block); | ||
| states_.emplace(block_hash, std::move(final_state)); | ||
|
|
||
| // update head (not in spec) |
Copilot
AI
Sep 29, 2025
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 comment '(not in spec)' indicates a deviation from specification. This should be properly documented with rationale for the deviation and potential implications.
| // update head (not in spec) | |
| /** | |
| * Deviation from specification: update head_ to the newly produced block. | |
| * | |
| * Rationale: | |
| * The specification does not require the fork choice head to be updated immediately | |
| * upon block production. However, in this implementation, we update head_ here to | |
| * ensure that subsequent queries to getHead() reflect the most recently produced block. | |
| * This can simplify block production logic and improve responsiveness for clients | |
| * querying the current head. | |
| * | |
| * Potential implications: | |
| * - May cause temporary divergence from the canonical fork choice rule if other | |
| * blocks are produced or imported concurrently. | |
| * - Should be reviewed to ensure it does not affect consensus safety or liveness. | |
| * - If strict spec compliance is required, consider removing or gating this update. | |
| */ |
…ot notifications and improve time management
…to feature/fork_choice_timeline
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.
Pull Request Overview
Copilot reviewed 39 out of 39 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (2)
src/blockchain/fork_choice.cpp:1
- Remove commented-out debug code. This clutters the codebase and should be replaced with proper logging if needed.
/**
src/blockchain/state_transition_function.cpp:1
- Remove commented-out code. If this assignment is intentionally disabled, add a comment explaining why.
/**
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| } else { | ||
| // forkchoice should be correctly ticked to current time before importing | ||
| // gossiped attestations | ||
| if (vote.slot > getCurrentSlot() + 1) { |
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.
| auto block_hash = block.hash(); | ||
| blocks_.emplace(block_hash, block); | ||
| states_.emplace(block_hash, std::move(state)); | ||
|
|
||
| // update head (not in spec) | ||
| head_ = block_hash; |
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.
| auto block_hash = block.hash(); | |
| blocks_.emplace(block_hash, block); | |
| states_.emplace(block_hash, std::move(state)); | |
| // update head (not in spec) | |
| head_ = block_hash; | |
| BOOST_OUTCOME_TRY(onBlock(block)); |
…_timeline # Conflicts: # src/executable/lean_node.cpp
| AnchorState genesis_state = STF::generateGenesisState(*genesis_config); | ||
| AnchorBlock genesis_block = STF::genesisBlock(genesis_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.
I'd like to refactor it to use only injections. AnchorState inherited on State and having ctor by genesis_config. And the same for AnchorBlock with ctor by AnchorState.
This pull request introduces a new fork choice rule implementation and integrates foundational infrastructure for fork choice logic in the blockchain module. The main changes include the addition of the
ForkChoiceStoreand related APIs, a newFCBlockTreeclass, and updates to the state transition function. There are also improvements to the timeline logic and node initialization to support the new fork choice mechanism.Known issues