Skip to content

Commit

Permalink
chore(sidecar): extra private fields on constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
thedevbirb committed Jul 4, 2024
1 parent 54d2b9b commit 06af6b1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 13 deletions.
17 changes: 10 additions & 7 deletions bolt-sidecar/bin/sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,17 @@ async fn main() -> eyre::Result<()> {
}
};

if let Err(e) = execution_state
let sender = match execution_state
.check_commitment_validity(&request)
.await
.await
{
tracing::error!("Failed to commit request: {:?}", e);
let _ = response_tx.send(Err(ApiError::Custom(e.to_string())));
continue;
}
Ok(sender) => { sender },
Err(e) => {
tracing::error!("Failed to commit request: {:?}", e);
let _ = response_tx.send(Err(ApiError::Custom(e.to_string())));
continue;
}
};

// TODO: match when we have more request types
let CommitmentRequest::Inclusion(request) = request;
Expand All @@ -97,7 +100,7 @@ async fn main() -> eyre::Result<()> {
// TODO: review all this `clone` usage

// parse the request into constraints and sign them with the sidecar signer
let message = ConstraintsMessage::build(validator_index, request.slot, request.clone());
let message = ConstraintsMessage::build(validator_index, request.slot, request.clone(), sender);
let signature = signer.sign(&message.digest())?.to_string();
let signed_constraints = SignedConstraints { message, signature };

Expand Down
26 changes: 22 additions & 4 deletions bolt-sidecar/src/primitives/constraint.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use alloy_primitives::keccak256;
use alloy_primitives::{keccak256, Address};
use reth_primitives::TransactionSigned;
use secp256k1::Message;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -50,8 +51,13 @@ pub struct ConstraintsMessage {

impl ConstraintsMessage {
/// Builds a constraints message from an inclusion request and metadata
pub fn build(validator_index: u64, slot: u64, request: InclusionRequest) -> Self {
let constraints = vec![Constraint::from_inclusion_request(request, None)];
pub fn build(
validator_index: u64,
slot: u64,
request: InclusionRequest,
sender: Address,
) -> Self {
let constraints = vec![Constraint::from_inclusion_request(request, None, sender)];
Self {
validator_index,
slot,
Expand Down Expand Up @@ -83,17 +89,29 @@ pub struct Constraint {
pub tx: String,
/// The optional index at which the transaction needs to be included in the block
pub index: Option<u64>,
/// The decoded transaction for internal use
#[serde(skip)]
pub(crate) tx_decoded: TransactionSigned,
/// The ec-recovered address of the transaction sender for internal use
#[serde(skip)]
pub(crate) sender: Address,
}

impl Constraint {
/// Builds a constraint from an inclusion request and an optional index
pub fn from_inclusion_request(req: InclusionRequest, index: Option<u64>) -> Self {
pub fn from_inclusion_request(
req: InclusionRequest,
index: Option<u64>,
sender: Address,
) -> Self {
let mut encoded_tx = Vec::new();
req.tx.encode_enveloped(&mut encoded_tx);

Self {
tx: format!("0x{}", hex::encode(encoded_tx)),
index,
tx_decoded: req.tx,
sender,
}
}

Expand Down
4 changes: 2 additions & 2 deletions bolt-sidecar/src/state/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ impl<C: StateFetcher> ExecutionState<C> {
pub async fn check_commitment_validity(
&mut self,
request: &CommitmentRequest,
) -> Result<(), ValidationError> {
) -> Result<Address, ValidationError> {
let CommitmentRequest::Inclusion(req) = request;

// Check if there is room for more commitments
Expand Down Expand Up @@ -187,7 +187,7 @@ impl<C: StateFetcher> ExecutionState<C> {
// TODO: check max_fee_per_blob_gas against the blob_base_fee
}

Ok(())
Ok(sender)
}

/// Commits the transaction to the target block. Initializes a new block template
Expand Down

0 comments on commit 06af6b1

Please sign in to comment.