Skip to content
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

fix: commitment deadline in case of missed block #188

Merged
merged 5 commits into from
Aug 7, 2024

Conversation

namn-grg
Copy link
Contributor

@namn-grg namn-grg commented Aug 7, 2024

Fixes #180

Summary by CodeRabbit

  • New Features

    • Enhanced consensus management with the addition of a consensus_clock for improved time representation related to consensus slots.
    • New method to retrieve the cached beacon genesis timestamp from the HeadTracker.
  • Bug Fixes

    • Improved resilience in fetching the beacon genesis timestamp with a retry mechanism.
  • Refactor

    • Simplified ConsensusState by removing the header field and renaming update_head to update_slot for clearer slot management.
    • Standardized retry logic for subscribing to new head events in the HeadTracker.
  • Tests

    • Added test cases to verify the correct behavior of the updated slot management functionality.

@namn-grg namn-grg marked this pull request as ready for review August 7, 2024 09:41
Comment on lines 99 to 109
// TODO: this can be replaced with ethereum_consensus::clock::from_system_time()
// but using beacon node events is easier to work on a custom devnet for now
// (as we don't need to specify genesis time and slot duration)
let head_tracker = HeadTracker::start(beacon_client.clone());

// Initialize the consensus clock.
let consensus_clock = from_system_time(
head_tracker.beacon_genesis_timestamp(),
cfg.chain.slot_time(),
SLOTS_PER_EPOCH,
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

reminder: this is not great because head tracker initializes the genesis timestamp to 0.
We should add a fn to simply async fetch that value instead for safety

This can be done in another issue

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a comment for this.

but I don't understand how the soln for this should be.

let genesis_time = loop {
                    match beacon_client.get_genesis_details().await {
                        Ok(genesis_info) => break genesis_info.genesis_time,
                        Err(err) => {
                            warn!(?err, "failed to get genesis details");
                            sleep(RETRY_DELAY).await;
                            continue;
                        }
                    }
};

I am fetching the value like this

Copy link
Collaborator

@merklefruit merklefruit Aug 7, 2024

Choose a reason for hiding this comment

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

on second thought, we should really have this value in ChainConfig anyway - for now it's fine though 👍

@@ -35,6 +40,23 @@ pub struct SidecarDriver<C, BLS, ECDSA> {
mevboost_client: MevBoostClient,
api_events_rx: mpsc::Receiver<CommitmentEvent>,
payload_requests_rx: mpsc::Receiver<FetchPayloadRequest>,
consensus_clock: Clock<SystemTimeProvider>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

if we only need the SlotStream from the clock, I would prefer to keep that in the struct instead of the Clock.
It should be of type SlotStream<something> but if it's an issue let me know!

Copy link
Contributor

@mempirate mempirate left a comment

Choose a reason for hiding this comment

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

Nice one, some smol nits

@@ -110,6 +139,7 @@ impl<C: StateFetcher, BLS: SignerBLS, ECDSA: SignerECDSA> SidecarDriver<C, BLS,
mevboost_client,
api_events_rx,
payload_requests_rx,
consensus_clock,
Copy link
Contributor

Choose a reason for hiding this comment

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

We can already turn it into a stream here!

@@ -117,22 +114,17 @@ impl ConsensusState {
}

/// Update the latest head and fetch the relevant data from the beacon chain.
pub async fn update_head(&mut self, head: u64) -> Result<(), ConsensusError> {
pub async fn update_slot(&mut self, head: u64) -> Result<(), ConsensusError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Rename param head -> slot for consistency

Comment on lines 167 to 170
Some(slot) = slot_stream.next() => {
if let Err(e) = self.consensus.update_slot(slot).await {
error!(err = ?e, "Failed to update consensus state slot");
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome!

Copy link
Collaborator

@merklefruit merklefruit left a comment

Choose a reason for hiding this comment

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

Very nice work! Just left some minor comments

@namn-grg
Copy link
Contributor Author

namn-grg commented Aug 7, 2024

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Aug 7, 2024

Walkthrough

Ahoy there! This grand update brings a treasure trove of changes to the SidecarDriver, ConsensusState, and HeadTracker. With enhancements to consensus management and more robust state handling, ye now have a mechanism that keeps better time with the blockchain—ensuring that missed blocks don’t leave ye stranded in the storm! The crew has made it easier to track events and state updates, setting a course for smoother sailing ahead.

Changes

Files Change Summary
.../driver.rs, .../consensus.rs Introduced consensus_clock in SidecarDriver for handling time and slot updates; removed header from ConsensusState for simplified management. Renamed update_head to update_slot.
.../head_tracker.rs Added beacon_genesis_timestamp to cache the beacon genesis time; improved retry logic for fetching genesis details; introduced a public method for accessing the cached timestamp.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SidecarDriver
    participant ConsensusClock
    participant HeadTracker

    User->>SidecarDriver: Start driver
    SidecarDriver->>ConsensusClock: Initialize clock
    ConsensusClock-->>SidecarDriver: Clock ready
    SidecarDriver->>HeadTracker: Subscribe to new heads
    HeadTracker-->>SidecarDriver: New head event
    SidecarDriver->>ConsensusClock: Check for slot updates
    ConsensusClock-->>SidecarDriver: Slot updated
    SidecarDriver->>User: Respond with latest state
Loading

Assessment against linked issues

Objective Addressed Explanation
Fault tolerance for missed block initiation (180)
Improved timing logic with consensus slot updates (180)
Maintain separation of execution and consensus state (180) The new logic does not fully decouple timing from execution state updates.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@namn-grg
Copy link
Contributor Author

namn-grg commented Aug 7, 2024

Thanks for the speedy review! Addressed it

Copy link
Collaborator

@merklefruit merklefruit left a comment

Choose a reason for hiding this comment

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

LGTM!

@mempirate mempirate merged commit 7e2022d into unstable Aug 7, 2024
2 checks passed
@mempirate mempirate deleted the naman/fix/missed-block branch August 7, 2024 12:55
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.

Bug: missed block fails to kick off sidecar round
3 participants