Skip to content

Commit a2fba92

Browse files
Merge pull request #11395 from starkware-libs/nadin/merge-main-v0.14.1-into-main-v0.14.1-committer-1767535122
Merge main-v0.14.1 into main-v0.14.1-committer
2 parents 47335a1 + 78f390a commit a2fba92

File tree

47 files changed

+1206
-480
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+1206
-480
lines changed

.github/workflows/committer_ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ on:
1515
- "crates/starknet_api/**"
1616
- "crates/starknet_committer/**"
1717
- "crates/starknet_patricia/**"
18-
- "scripts/dependencies.sh"
1918

2019
env:
2120
RUSTFLAGS: "-D warnings"

.github/workflows/hybrid_system_test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ env:
1818
overlay: hybrid.testing.node-0
1919
cluster_name: hybrid-system-test
2020
crate_triggers: "apollo_node,apollo_deployments,apollo_integration_tests"
21-
path_triggers: ".github/workflows/hybrid_system_test.yaml,scripts/*.py,scripts/system_tests/**/*.py,deployments/sequencer/**,deployments/images/**"
21+
path_triggers: ".github/workflows/hybrid_system_test.yaml,scripts/**,deployments/sequencer/**,deployments/images/**"
2222
path_triggers_exclude: "scripts/prod/**/*"
2323
pvc_storage_class_name: "premium-rwo"
2424
anvil_port: "8545"

crates/apollo_consensus/src/manager.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,7 @@ impl<ContextT: ConsensusContext> MultiHeightManager<ContextT> {
433433
self.wait_until_sync_reaches_height(height, context).await;
434434
RunHeightRes::Sync
435435
}
436-
e @ ConsensusError::BlockInfoConversion(_)
437-
| e @ ConsensusError::InternalNetworkError(_)
438-
| e @ ConsensusError::Other(_) => {
436+
e @ ConsensusError::InternalNetworkError(_) => {
439437
// The node is missing required components/data and cannot continue
440438
// participating in the consensus. A fix and node restart are required.
441439
return Err(e);
@@ -476,7 +474,7 @@ impl<ContextT: ConsensusContext> MultiHeightManager<ContextT> {
476474
CONSENSUS_BLOCK_NUMBER.set_lossy(height.0);
477475
self.cache.report_max_cached_block_number_metric(height);
478476

479-
if let Some(sync_result) = self.check_and_wait_for_sync(context, height).await? {
477+
if let Some(sync_result) = self.check_and_wait_for_sync(context, height).await {
480478
return Ok(sync_result);
481479
}
482480

@@ -503,12 +501,12 @@ impl<ContextT: ConsensusContext> MultiHeightManager<ContextT> {
503501
}
504502

505503
/// Check if we need to sync and wait if necessary.
506-
/// Returns Some(RunHeightRes::Sync) if sync is needed, None otherwise.
504+
/// Returns Some(RunHeightRes::Sync) if sync height was learned via sync, None otherwise.
507505
async fn check_and_wait_for_sync(
508506
&mut self,
509507
context: &mut ContextT,
510508
height: BlockNumber,
511-
) -> Result<Option<RunHeightRes>, ConsensusError> {
509+
) -> Option<RunHeightRes> {
512510
// If we already voted for this height, do not proceed until we sync to this height.
513511
// Otherwise, just check if we can sync to this height, immediately. If not, proceed with
514512
// consensus.
@@ -524,11 +522,11 @@ impl<ContextT: ConsensusContext> MultiHeightManager<ContextT> {
524522
self.last_voted_height_at_initialization.unwrap().0
525523
);
526524
self.wait_until_sync_reaches_height(height, context).await;
527-
return Ok(Some(RunHeightRes::Sync));
525+
return Some(RunHeightRes::Sync);
528526
} else if context.try_sync(height).await {
529-
return Ok(Some(RunHeightRes::Sync));
527+
return Some(RunHeightRes::Sync);
530528
}
531-
Ok(None)
529+
None
532530
}
533531

534532
/// Initialize consensus for a height: get validators, create SHC, and set up events.

crates/apollo_consensus/src/types.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,4 @@ pub enum ConsensusError {
154154
// As opposed to an error between this node and peer nodes.
155155
#[error("{0}")]
156156
InternalNetworkError(String),
157-
#[error("Block info conversion error: {0}")]
158-
BlockInfoConversion(#[from] starknet_api::StarknetApiError),
159-
#[error("{0}")]
160-
Other(String),
161157
}

crates/apollo_consensus_orchestrator/src/build_proposal.rs

Lines changed: 42 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ use apollo_protobuf::consensus::{
2323
ProposalPart,
2424
TransactionBatch,
2525
};
26-
use apollo_time::time::DateTime;
26+
use apollo_state_sync_types::communication::SharedStateSyncClient;
27+
use apollo_time::time::{Clock, DateTime};
2728
use starknet_api::block::{BlockNumber, GasPrice};
2829
use starknet_api::consensus_transaction::InternalConsensusTransaction;
2930
use starknet_api::core::ContractAddress;
@@ -64,6 +65,7 @@ pub(crate) struct ProposalBuildArguments {
6465
pub proposal_round: Round,
6566
pub retrospective_block_hash_deadline: DateTime,
6667
pub retrospective_block_hash_retry_interval_millis: Duration,
68+
pub use_state_sync_block_timestamp: bool,
6769
}
6870

6971
type BuildProposalResult<T> = Result<T, BuildProposalError>;
@@ -81,9 +83,8 @@ pub(crate) enum BuildProposalError {
8183
StateSyncClientError(String),
8284
#[error("State sync is not ready: block number {0} not found")]
8385
StateSyncNotReady(BlockNumber),
84-
// Consensus may exit early (e.g. sync).
85-
#[error("Failed to send commitment to consensus: {0}")]
86-
SendError(ProposalCommitment),
86+
#[error("Failed to send proposal part: {0}")]
87+
SendError(String),
8788
#[error("EthToStrkOracle error: {0}")]
8889
EthToStrkOracle(#[from] EthToStrkOracleClientError),
8990
#[error("L1GasPriceProvider error: {0}")]
@@ -106,14 +107,13 @@ pub(crate) async fn build_proposal(
106107
mut args: ProposalBuildArguments,
107108
) -> BuildProposalResult<ProposalCommitment> {
108109
let block_info = initiate_build(&args).await?;
109-
args.stream_sender
110-
.send(ProposalPart::Init(args.proposal_init))
111-
.await
112-
.expect("Failed to send proposal init");
110+
args.stream_sender.send(ProposalPart::Init(args.proposal_init)).await.map_err(|e| {
111+
BuildProposalError::SendError(format!("Failed to send proposal init: {e:?}"))
112+
})?;
113113
args.stream_sender
114114
.send(ProposalPart::BlockInfo(block_info.clone()))
115115
.await
116-
.expect("Failed to send block info");
116+
.map_err(|e| BuildProposalError::SendError(format!("Failed to send block info: {e:?}")))?;
117117

118118
let (proposal_commitment, content) = get_proposal_content(&mut args).await?;
119119

@@ -130,8 +130,27 @@ pub(crate) async fn build_proposal(
130130
Ok(proposal_commitment)
131131
}
132132

133+
async fn get_proposal_timestamp(
134+
use_state_sync_block_timestamp: bool,
135+
state_sync_client: &SharedStateSyncClient,
136+
clock: &dyn Clock,
137+
) -> u64 {
138+
if use_state_sync_block_timestamp {
139+
if let Ok(Some(block_header)) = state_sync_client.get_latest_block_header().await {
140+
return block_header.block_header_without_hash.timestamp.0;
141+
}
142+
warn!("No latest block header available from state sync, falling back to clock time");
143+
}
144+
clock.unix_now()
145+
}
146+
133147
async fn initiate_build(args: &ProposalBuildArguments) -> BuildProposalResult<ConsensusBlockInfo> {
134-
let timestamp = args.deps.clock.unix_now();
148+
let timestamp = get_proposal_timestamp(
149+
args.use_state_sync_block_timestamp,
150+
&args.deps.state_sync_client,
151+
args.deps.clock.as_ref(),
152+
)
153+
.await;
135154
let (eth_to_fri_rate, l1_prices) = get_oracle_rate_and_prices(
136155
args.deps.l1_gas_price_provider.clone(),
137156
timestamp,
@@ -225,7 +244,11 @@ async fn get_proposal_content(
225244
args.stream_sender
226245
.send(ProposalPart::Transactions(TransactionBatch { transactions }))
227246
.await
228-
.expect("Failed to broadcast proposal content");
247+
.map_err(|e| {
248+
BuildProposalError::SendError(format!(
249+
"Failed to send transaction batch: {e:?}"
250+
))
251+
})?;
229252
}
230253
GetProposalContent::Finished { id, final_n_executed_txs } => {
231254
let proposal_commitment = ProposalCommitment(id.state_diff_commitment.0.0);
@@ -272,13 +295,16 @@ async fn get_proposal_content(
272295
args.stream_sender
273296
.send(ProposalPart::ExecutedTransactionCount(final_n_executed_txs_u64))
274297
.await
275-
.expect("Failed to broadcast executed transaction count");
298+
.map_err(|e| {
299+
BuildProposalError::SendError(format!(
300+
"Failed to send executed transaction count: {e:?}"
301+
))
302+
})?;
276303
let fin = ProposalFin { proposal_commitment };
277304
info!("Sending fin={fin:?}");
278-
args.stream_sender
279-
.send(ProposalPart::Fin(fin))
280-
.await
281-
.expect("Failed to broadcast proposal fin");
305+
args.stream_sender.send(ProposalPart::Fin(fin)).await.map_err(|e| {
306+
BuildProposalError::SendError(format!("Failed to send proposal fin: {e:?}"))
307+
})?;
282308
return Ok((proposal_commitment, content));
283309
}
284310
}

crates/apollo_consensus_orchestrator/src/build_proposal_test.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ struct TestProposalBuildArguments {
6060
pub proposal_round: Round,
6161
pub retrospective_block_hash_deadline: DateTime,
6262
pub retrospective_block_hash_retry_interval_millis: Duration,
63+
pub use_state_sync_block_timestamp: bool,
6364
}
6465

6566
impl From<TestProposalBuildArguments> for ProposalBuildArguments {
@@ -82,6 +83,7 @@ impl From<TestProposalBuildArguments> for ProposalBuildArguments {
8283
retrospective_block_hash_deadline: args.retrospective_block_hash_deadline,
8384
retrospective_block_hash_retry_interval_millis: args
8485
.retrospective_block_hash_retry_interval_millis,
86+
use_state_sync_block_timestamp: args.use_state_sync_block_timestamp,
8587
}
8688
}
8789
}
@@ -108,7 +110,7 @@ fn create_proposal_build_arguments() -> (TestProposalBuildArguments, mpsc::Recei
108110
let cancel_token = CancellationToken::new();
109111
let previous_block_info = None;
110112
let proposal_round = 0;
111-
113+
let use_state_sync_block_timestamp = false;
112114
(
113115
TestProposalBuildArguments {
114116
deps,
@@ -127,6 +129,7 @@ fn create_proposal_build_arguments() -> (TestProposalBuildArguments, mpsc::Recei
127129
proposal_round,
128130
retrospective_block_hash_deadline,
129131
retrospective_block_hash_retry_interval_millis,
132+
use_state_sync_block_timestamp,
130133
},
131134
proposal_receiver,
132135
)

0 commit comments

Comments
 (0)