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

feat(sidecar): commit-boost integration #203

Merged
merged 19 commits into from
Sep 5, 2024

Conversation

namn-grg
Copy link
Contributor

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

partially solves #201

Note - This is not e2e tested with commit-boost

Summary by CodeRabbit

  • New Features

    • Introduced new configuration options for commit boosting, including an API endpoint and JWT for authentication.
    • Added a new client type, CommitBoostSigner, to the public interface.
  • Improvements

    • Enhanced BLS signing functionality with support for different signer types and improved type safety.
    • Updated the SidecarDriver to streamline the signing process and support asynchronous operations.
    • Improved the flexibility and security of the configuration management system.
  • Bug Fixes

    • Simplified error handling in the signature request process and enhanced the clarity of the commit_and_sign method.
  • Chores

    • Removed unnecessary dependencies to improve project requirements.

@namn-grg namn-grg marked this pull request as ready for review August 29, 2024 06:51
@namn-grg
Copy link
Contributor Author

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Aug 29, 2024

Walkthrough

Ahoy there! The changes to the bolt-sidecar project bring forth new configuration variables for commit boosting, refine the management of dependencies, and enhance the signing functionalities. The CommitBoostClient now sails with a SignerClient for handling requests, while the configuration structures have been updated to embrace new JWT settings. The code's overall structure has been streamlined for better clarity and maintainability, savvy?

Changes

Files Change Summary
bolt-sidecar/.env.example Added BOLT_SIDECAR_COMMIT_BOOST_URL and BOLT_SIDECAR_COMMIT_BOOST_JWT_HEX for commit boosting.
bolt-sidecar/Cargo.toml Updated cb-common dependency with a specific revision; removed cb-crypto.
bolt-sidecar/src/client/commit_boost.rs Refactored to use CommitBoostSigner with a focus on signing operations.
bolt-sidecar/src/config/mod.rs Renamed commit_boost_url to commit_boost_address and added commit_boost_jwt_hex.
bolt-sidecar/src/config/signing.rs Introduced commit_boost_jwt_hex field to SigningOpts structure.
bolt-sidecar/src/crypto/bls.rs Updated signing methods to use fixed-size arrays for better performance.
bolt-sidecar/src/driver.rs Simplified SidecarDriver struct; updated signing process to accommodate new signer types.
bolt-sidecar/src/lib.rs Added CommitBoostSigner to the public interface.
bolt-sidecar/src/primitives/commitment.rs Modified commit_and_sign to require SignerECDSAAsync and updated error handling.
bolt-sidecar/src/test_util.rs Changed TestSignableData to use fixed-size arrays for data handling.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant CommitBoostSigner
    participant SignerClient

    Client->>CommitBoostSigner: Request to sign data
    CommitBoostSigner->>SignerClient: Forward signing request
    SignerClient-->>CommitBoostSigner: Return signed data
    CommitBoostSigner-->>Client: Send signed data
Loading

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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Comment on lines 72 to 82
// Constraints are signed with a BLS private key or Commit-Boost
let constraint_signer = if let Some(private_key) = cfg.private_key.clone() {
BlsSignerType::PrivateKey(BlsSigner::new(private_key))
} else {
let commit_boost_client = CommitBoostClient::new(
cfg.commit_boost_address.clone().expect("CommitBoost URL must be provided"),
&cfg.commit_boost_jwt_hex.clone().expect("CommitBoost JWT must be provided"),
)
.await?;
BlsSignerType::CommitBoost(commit_boost_client)
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

It would be nice to refactor the signing config (SigningOpts) to avoid unwrapping CLI options here.
can be done in a separate PR.

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 job, take a look at Nico's comment to use a BLS signer trait instead of an enum

bolt-sidecar/src/crypto/bls.rs Outdated Show resolved Hide resolved
@namn-grg namn-grg added C: bolt-sidecar Component: bolt-sidecar T: feature Type: Feature labels Aug 30, 2024
@namn-grg namn-grg self-assigned this Sep 2, 2024
@namn-grg
Copy link
Contributor Author

namn-grg commented Sep 2, 2024

@coderabbitai review

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 21

Outside diff range comments (3)
bolt-sidecar/src/primitives/constraint.rs (1)

Line range hint 66-78: Ahoy, me hearty! This be a fine piece of code ye've crafted!

Shiver me timbers! Ye've made the digest method as sleek as a pirate's cutlass. Returnin' a fixed-size array instead of a vector be a smart move, savvy? It'll save us from the curse of unnecessary memory allocation.

But wait, ye scurvy dog! I spy with me eye a chance to make this treasure even shinier. How 'bout we combine the data into a single vector, eh? It'll save us from walkin' the plank of multiple allocations. Feast yer eyes on this:

 fn digest(&self) -> [u8; 32] {
-    let mut data = Vec::new();
-    data.extend_from_slice(&self.validator_index.to_le_bytes());
-    data.extend_from_slice(&self.slot.to_le_bytes());
-
-    let mut constraint_bytes = Vec::new();
-    for constraint in &self.constraints {
-        constraint_bytes.extend_from_slice(&constraint.as_bytes());
-    }
-    data.extend_from_slice(&constraint_bytes);
+    let mut data = Vec::with_capacity(16 + self.constraints.iter().map(|c| c.as_bytes().len()).sum::<usize>());
+    data.extend_from_slice(&self.validator_index.to_le_bytes());
+    data.extend_from_slice(&self.slot.to_le_bytes());
+    self.constraints.iter().for_each(|constraint| data.extend_from_slice(&constraint.as_bytes()));

     // Compute the Keccak-256 hash and return the 32-byte array directly
     keccak256(data).0
 }

This be reducin' the number of times we need to swab the deck (reallocate memory), makin' our code run faster than a ship with the wind at its back!

bolt-sidecar/src/primitives/commitment.rs (1)

Line range hint 1-329: Avast ye, matey! Our ship be sailing true, but there be room for more treasure!

While ye've done a fine job with the changes, I spy with me eye some opportunities for future plunder:

  1. Consider making other methods async where it makes sense, to keep pace with our new async ways.
  2. Mayhaps we could add some more error context using eyre::WrapErr in places where we're returning errors.
  3. Think about adding some doc comments to explain the SignerECDSAAsync trait for any landlubbers who might join our crew later.

What say ye to these ideas for our next voyage, eh? They'd make our code shine brighter than buried treasure!

bolt-sidecar/src/driver.rs (1)

Line range hint 1-320: Avast ye, we've reached the end of our code voyage!

Ye've navigated these treacherous waters with the skill of a seasoned captain. The changes ye've made be integrating smoother than a well-oiled cannon, and the rest of the code be standin' strong like the mast of the Black Pearl.

Now, before we weigh anchor, I've got one last piece of advice from me treasure trove of wisdom. Consider addin' some error logging in the handle_fetch_payload_request method. It'd be mighty helpful for debuggin' if the seas get rough. Something like this:

fn handle_fetch_payload_request(&mut self, request: FetchPayloadRequest) {
    info!(slot = request.slot, "Received local payload request");

    let Some(payload_and_bid) = self.local_builder.get_cached_payload() else {
        warn!(slot = request.slot, "No local payload found");
        if let Err(e) = request.response_tx.send(None) {
            error!(err = ?e, "Failed to send None response for missing payload");
        }
        return;
    };

    // ... rest of the method ...
}

What say ye to this final touch to our map of code?

bolt-sidecar/src/config/signing.rs Outdated Show resolved Hide resolved
bolt-sidecar/Cargo.toml Show resolved Hide resolved
bolt-sidecar/src/crypto/ecdsa.rs Outdated Show resolved Hide resolved
bolt-sidecar/src/crypto/ecdsa.rs Show resolved Hide resolved
bolt-sidecar/src/client/commit_boost.rs Outdated Show resolved Hide resolved
bolt-sidecar/src/config/mod.rs Show resolved Hide resolved
bolt-sidecar/src/driver.rs Show resolved Hide resolved
bolt-sidecar/src/driver.rs Show resolved Hide resolved
bolt-sidecar/src/driver.rs Show resolved Hide resolved
bolt-sidecar/src/driver.rs Show resolved Hide resolved
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.

Great work!

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.

Great work. Some small nits and then we can merge!

bolt-sidecar/src/config/signing.rs Outdated Show resolved Hide resolved
bolt-sidecar/src/crypto/ecdsa.rs Outdated Show resolved Hide resolved
@namn-grg
Copy link
Contributor Author

namn-grg commented Sep 4, 2024

Just working on a mock test

@mempirate mempirate merged commit 75b0e6d into unstable Sep 5, 2024
2 checks passed
@mempirate mempirate deleted the naman/feat/commitboost/integration branch September 5, 2024 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: bolt-sidecar Component: bolt-sidecar T: feature Type: Feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants