Skip to content

Commit 15ce6cb

Browse files
apollo_consensus_orchestrator: send CommitmentParts in Fin
1 parent b6092d5 commit 15ce6cb

File tree

7 files changed

+51
-17
lines changed

7 files changed

+51
-17
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/apollo_consensus_orchestrator/src/build_proposal.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use apollo_consensus::types::{ProposalCommitment, Round};
1717
use apollo_l1_gas_price_types::errors::{EthToStrkOracleClientError, L1GasPriceClientError};
1818
use apollo_protobuf::consensus::{
1919
BuildParam,
20+
CommitmentParts,
2021
ProposalFin,
2122
ProposalInit,
2223
ProposalPart,
@@ -308,11 +309,11 @@ async fn get_proposal_content(
308309
.final_n_executed_txs
309310
.try_into()
310311
.expect("Number of executed transactions should fit in u64");
311-
// TODO(Asmaa): Pass the commitment parts.
312+
let commitment_parts = CommitmentParts::from(&info);
312313
let fin = ProposalFin {
313314
proposal_commitment,
314315
executed_transaction_count,
315-
commitment_parts: None,
316+
commitment_parts: Some(commitment_parts),
316317
};
317318
info!("Sending fin={fin:?}");
318319
args.stream_sender.send(ProposalPart::Fin(fin)).await.map_err(|e| {

crates/apollo_consensus_orchestrator/src/sequencer_consensus_context.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use apollo_l1_gas_price_types::L1GasPriceProviderClient;
2525
use apollo_network::network_manager::{BroadcastTopicClient, BroadcastTopicClientTrait};
2626
use apollo_protobuf::consensus::{
2727
BuildParam,
28+
CommitmentParts,
2829
HeightAndRound,
2930
ProposalFin,
3031
ProposalInit,
@@ -623,7 +624,7 @@ impl ConsensusContext for SequencerConsensusContext {
623624
async fn repropose(&mut self, id: ProposalCommitment, build_param: BuildParam) {
624625
info!(?id, ?build_param, "Reproposing.");
625626
let height = build_param.height;
626-
let (init, txs, _, _) = self
627+
let (init, txs, _, finished_info) = self
627628
.valid_proposals
628629
.lock()
629630
.expect("Lock on active proposals was poisoned due to a previous panic")
@@ -635,8 +636,15 @@ impl ConsensusContext for SequencerConsensusContext {
635636
self.start_stream(HeightAndRound(height.0, build_param.round)).await;
636637
let handle = tokio::spawn(
637638
async move {
638-
let res =
639-
send_reproposal(id, init, txs, &mut stream_sender, transaction_converter).await;
639+
let res = send_reproposal(
640+
id,
641+
init,
642+
txs,
643+
finished_info,
644+
&mut stream_sender,
645+
transaction_converter,
646+
)
647+
.await;
640648
match res {
641649
Ok(()) => {
642650
info!(?id, ?build_param, "Reproposal succeeded.");
@@ -923,11 +931,11 @@ async fn send_reproposal(
923931
id: ProposalCommitment,
924932
init: ProposalInit,
925933
txs: Vec<Vec<InternalConsensusTransaction>>,
934+
finished_info: FinishedProposalInfo,
926935
stream_sender: &mut StreamSender,
927936
transaction_converter: Arc<dyn TransactionConverterTrait>,
928937
) -> Result<(), ReproposeError> {
929938
stream_sender.send(ProposalPart::Init(init)).await?;
930-
let mut n_executed_txs: usize = 0;
931939
for batch in txs.iter() {
932940
let transactions = futures::future::join_all(batch.iter().map(|tx| {
933941
// transaction_converter is an external dependency (class manager) and so
@@ -938,12 +946,17 @@ async fn send_reproposal(
938946
.into_iter()
939947
.collect::<Result<Vec<_>, _>>()?;
940948
stream_sender.send(ProposalPart::Transactions(TransactionBatch { transactions })).await?;
941-
n_executed_txs += batch.len();
942949
}
943-
let executed_transaction_count: u64 =
944-
n_executed_txs.try_into().expect("Number of executed transactions should fit in u64");
945-
let fin =
946-
ProposalFin { proposal_commitment: id, executed_transaction_count, commitment_parts: None };
950+
let executed_transaction_count: u64 = finished_info
951+
.final_n_executed_txs
952+
.try_into()
953+
.expect("Number of executed transactions should fit in u64");
954+
let commitment_parts = CommitmentParts::from(&finished_info);
955+
let fin = ProposalFin {
956+
proposal_commitment: id,
957+
executed_transaction_count,
958+
commitment_parts: Some(commitment_parts),
959+
};
947960
stream_sender.send(ProposalPart::Fin(fin)).await?;
948961

949962
Ok(())

crates/apollo_consensus_orchestrator/src/sequencer_consensus_context_test.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ use apollo_l1_gas_price_types::errors::{
2929
use apollo_l1_gas_price_types::{MockL1GasPriceProviderClient, PriceInfo};
3030
use apollo_protobuf::consensus::{
3131
BuildParam,
32+
CommitmentParts,
3233
ProposalCommitment,
3334
ProposalFin,
3435
ProposalPart,
@@ -136,7 +137,7 @@ async fn validate_then_repropose(#[case] execute_all_txs: bool) {
136137
let fin = ProposalPart::Fin(ProposalFin {
137138
proposal_commitment: ProposalCommitment(STATE_DIFF_COMMITMENT.0.0),
138139
executed_transaction_count: n_executed_txs_count.try_into().unwrap(),
139-
commitment_parts: None,
140+
commitment_parts: Some(CommitmentParts::default()),
140141
});
141142
content_sender.send(fin.clone()).await.unwrap();
142143
let fin_receiver = context.validate_proposal(init.clone(), TIMEOUT, content_receiver).await;
@@ -170,7 +171,7 @@ async fn proposals_from_different_rounds() {
170171
let prop_part_fin = ProposalPart::Fin(ProposalFin {
171172
proposal_commitment: ProposalCommitment(STATE_DIFF_COMMITMENT.0.0),
172173
executed_transaction_count: INTERNAL_TX_BATCH.len().try_into().unwrap(),
173-
commitment_parts: None,
174+
commitment_parts: Some(CommitmentParts::default()),
174175
});
175176

176177
// The proposal from the past round is ignored.
@@ -293,7 +294,7 @@ async fn build_proposal() {
293294
ProposalPart::Fin(ProposalFin {
294295
proposal_commitment: ProposalCommitment(STATE_DIFF_COMMITMENT.0.0),
295296
executed_transaction_count: INTERNAL_TX_BATCH.len().try_into().unwrap(),
296-
commitment_parts: None,
297+
commitment_parts: Some(CommitmentParts::default()),
297298
})
298299
);
299300
assert!(receiver.next().await.is_none());
@@ -729,7 +730,7 @@ async fn oracle_fails_on_startup(#[case] l1_oracle_failure: bool) {
729730
ProposalPart::Fin(ProposalFin {
730731
proposal_commitment: ProposalCommitment(STATE_DIFF_COMMITMENT.0.0),
731732
executed_transaction_count: INTERNAL_TX_BATCH.len().try_into().unwrap(),
732-
commitment_parts: None,
733+
commitment_parts: Some(CommitmentParts::default()),
733734
})
734735
);
735736
assert!(receiver.next().await.is_none());
@@ -850,7 +851,7 @@ async fn oracle_fails_on_second_block(#[case] l1_oracle_failure: bool) {
850851
ProposalPart::Fin(ProposalFin {
851852
proposal_commitment: ProposalCommitment(STATE_DIFF_COMMITMENT.0.0),
852853
executed_transaction_count: INTERNAL_TX_BATCH.len().try_into().unwrap(),
853-
commitment_parts: None,
854+
commitment_parts: Some(CommitmentParts::default()),
854855
})
855856
);
856857
assert!(receiver.next().await.is_none());

crates/apollo_protobuf/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ path = "src/bin/generate_protoc_output.rs"
1616
required-features = ["bin-deps"]
1717

1818
[dependencies]
19+
apollo_batcher_types.workspace = true
1920
apollo_test_utils = { workspace = true, optional = true }
2021
asynchronous-codec.workspace = true
2122
bytes.workspace = true

crates/apollo_protobuf/src/consensus.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ pub struct TransactionBatch {
168168

169169
/// Optional parts of a commitment carried in ProposalFin.
170170
// TODO(Asmaa): Send next_l2_gas_price_fri and l2_gas_used in a separate optional message.
171-
#[derive(Debug, Clone, PartialEq)]
171+
#[derive(Debug, Clone, Default, PartialEq)]
172172
pub struct CommitmentParts {
173173
pub concatenated_counts: Felt,
174174
// None for the first block

crates/apollo_protobuf/src/converters/consensus.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ mod consensus_test;
44

55
use std::convert::{TryFrom, TryInto};
66

7+
use apollo_batcher_types::batcher_types::FinishedProposalInfo;
78
use prost::Message;
89
use starknet_api::block::{BlockNumber, GasPrice, StarknetVersion};
910
use starknet_api::consensus_transaction::ConsensusTransaction;
@@ -320,6 +321,22 @@ impl From<CommitmentParts> for protobuf::CommitmentParts {
320321
}
321322
}
322323

324+
impl From<&FinishedProposalInfo> for CommitmentParts {
325+
fn from(info: &FinishedProposalInfo) -> Self {
326+
let commitments = &info.block_header_commitments;
327+
CommitmentParts {
328+
concatenated_counts: commitments.concatenated_counts,
329+
parent_commitment: info
330+
.parent_proposal_commitment
331+
.as_ref()
332+
.map(|p| ProposalCommitment(p.state_diff_commitment.0.0)),
333+
transaction_commitment: commitments.transaction_commitment.0,
334+
event_commitment: commitments.event_commitment.0,
335+
receipt_commitment: commitments.receipt_commitment.0,
336+
}
337+
}
338+
}
339+
323340
impl TryFrom<protobuf::ProposalFin> for ProposalFin {
324341
type Error = ProtobufConversionError;
325342
fn try_from(value: protobuf::ProposalFin) -> Result<Self, Self::Error> {

0 commit comments

Comments
 (0)