diff --git a/bolt-sidecar/src/driver.rs b/bolt-sidecar/src/driver.rs index 99a37912d..9429867a4 100644 --- a/bolt-sidecar/src/driver.rs +++ b/bolt-sidecar/src/driver.rs @@ -220,21 +220,23 @@ impl SidecarDriver SignedConstraints { message, signature }, - Err(err) => { - error!(?err, "Failed to sign constraints"); - let _ = response.send(Err(CommitmentError::Internal)); - return; - } - }; - // Track the number of transactions preconfirmed considering their type - signed_constraints.message.transactions.iter().for_each(|full_tx| { - ApiMetrics::increment_transactions_preconfirmed(full_tx.tx_type()); - }); - self.execution.add_constraint(slot, signed_constraints); + for tx in inclusion_request.txs { + let tx_type = tx.tx_type(); + let message = ConstraintsMessage::from_transaction(validator_pubkey.clone(), slot, tx); + + let signed_constraints = match self.constraint_signer.sign(&message.digest()).await { + Ok(signature) => SignedConstraints { message, signature }, + Err(err) => { + error!(?err, "Failed to sign constraints"); + let _ = response.send(Err(CommitmentError::Internal)); + return; + } + }; + + ApiMetrics::increment_transactions_preconfirmed(tx_type); + self.execution.add_constraint(slot, signed_constraints); + } // Create a commitment by signing the request match request.commit_and_sign(&self.commitment_signer).await { diff --git a/bolt-sidecar/src/primitives/constraint.rs b/bolt-sidecar/src/primitives/constraint.rs index a3e0bc37d..6f65011f5 100644 --- a/bolt-sidecar/src/primitives/constraint.rs +++ b/bolt-sidecar/src/primitives/constraint.rs @@ -70,6 +70,11 @@ impl ConstraintsMessage { Self { pubkey, slot: request.slot, top: false, transactions } } + + /// Builds a constraints message from a single transaction. + pub fn from_transaction(pubkey: BlsPublicKey, slot: u64, transaction: FullTransaction) -> Self { + Self { pubkey, slot, top: false, transactions: vec![transaction] } + } } impl SignableBLS for ConstraintsMessage {