Skip to content

Commit

Permalink
chore(batcher): add block info to block proposal input
Browse files Browse the repository at this point in the history
  • Loading branch information
ArniStarkware committed Nov 28, 2024
1 parent 50403e4 commit a90de83
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ impl ConsensusContext for SequencerConsensusContext {
number: BlockNumber::default(),
hash: BlockHash::default(),
}),
// TODO: Fill block info.
block_info: Default::default(),
};
self.maybe_start_height(proposal_init.height).await;
// TODO: Should we be returning an error?
Expand Down Expand Up @@ -172,6 +174,8 @@ impl ConsensusContext for SequencerConsensusContext {
number: BlockNumber::default(),
hash: BlockHash::default(),
}),
// TODO: Fill block info.
block_info: Default::default(),
};
self.maybe_start_height(height).await;
batcher.validate_block(input).await.expect("Failed to initiate proposal validation");
Expand Down
7 changes: 4 additions & 3 deletions crates/starknet_api/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ macro_rules! impl_try_from_uint_for_nonzero_gas_price {

impl_try_from_uint_for_nonzero_gas_price!(u8, u16, u32, u64, u128);

#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct GasPriceVector {
pub l1_gas_price: NonzeroGasPrice,
pub l1_data_gas_price: NonzeroGasPrice,
Expand All @@ -452,7 +452,8 @@ pub enum FeeType {
Eth,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
// TODO(Arni): Remove derive of Default. Gas prices should always be set.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
pub struct GasPrices {
pub eth_gas_prices: GasPriceVector, // In wei.
pub strk_gas_prices: GasPriceVector, // In fri.
Expand Down Expand Up @@ -485,7 +486,7 @@ impl GasPrices {
)]
pub struct BlockTimestamp(pub u64);

#[derive(Clone, Debug, Deserialize, Serialize)]
#[derive(Clone, Debug, Deserialize, Default, Serialize)]
pub struct BlockInfo {
pub block_number: BlockNumber,
pub block_timestamp: BlockTimestamp,
Expand Down
6 changes: 6 additions & 0 deletions crates/starknet_batcher/src/batcher_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ async fn no_active_height() {
proposal_id: ProposalId(0),
retrospective_block_hash: None,
deadline: chrono::Utc::now() + chrono::Duration::seconds(1),
block_info: Default::default(),
})
.await;
assert_eq!(result, Err(BatcherError::NoActiveHeight));
Expand All @@ -209,6 +210,7 @@ async fn no_active_height() {
proposal_id: ProposalId(0),
retrospective_block_hash: None,
deadline: chrono::Utc::now() + chrono::Duration::seconds(1),
block_info: Default::default(),
})
.await;
assert_eq!(result, Err(BatcherError::NoActiveHeight));
Expand All @@ -229,6 +231,7 @@ async fn validate_block_full_flow() {
proposal_id: PROPOSAL_ID,
deadline: deadline(),
retrospective_block_hash: None,
block_info: Default::default(),
};
batcher.validate_block(validate_block_input).await.unwrap();

Expand Down Expand Up @@ -347,6 +350,7 @@ async fn send_finish_to_an_invalid_proposal() {
proposal_id: PROPOSAL_ID,
deadline: deadline(),
retrospective_block_hash: None,
block_info: Default::default(),
};
batcher.validate_block(validate_block_input).await.unwrap();

Expand Down Expand Up @@ -379,6 +383,7 @@ async fn propose_block_full_flow() {
proposal_id: PROPOSAL_ID,
retrospective_block_hash: None,
deadline: chrono::Utc::now() + chrono::Duration::seconds(1),
block_info: Default::default(),
})
.await
.unwrap();
Expand Down Expand Up @@ -438,6 +443,7 @@ async fn propose_block_without_retrospective_block_hash() {
proposal_id: PROPOSAL_ID,
retrospective_block_hash: None,
deadline: deadline(),
block_info: Default::default(),
})
.await;

Expand Down
9 changes: 4 additions & 5 deletions crates/starknet_batcher_types/src/batcher_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::fmt::Debug;

use chrono::prelude::*;
use serde::{Deserialize, Serialize};
use starknet_api::block::{BlockHashAndNumber, BlockNumber};
use starknet_api::block::{BlockHashAndNumber, BlockInfo, BlockNumber};
use starknet_api::core::StateDiffCommitment;
use starknet_api::executable_transaction::Transaction;

Expand Down Expand Up @@ -35,9 +35,7 @@ pub struct ProposeBlockInput {
pub proposal_id: ProposalId,
pub deadline: chrono::DateTime<Utc>,
pub retrospective_block_hash: Option<BlockHashAndNumber>,
// TODO: Should we get the gas price here?
// TODO: add proposer address.
// TODO: add whether the kzg mechanism is used for DA.
pub block_info: BlockInfo,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand All @@ -63,6 +61,7 @@ pub struct ValidateBlockInput {
pub proposal_id: ProposalId,
pub deadline: chrono::DateTime<Utc>,
pub retrospective_block_hash: Option<BlockHashAndNumber>,
pub block_info: BlockInfo,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -92,7 +91,7 @@ pub enum ProposalStatus {
// Only sent in response to `Abort`.
Aborted,
// May be caused due to handling of a previous item of the new proposal.
// In this case, the propsal is aborted and no additional content will be processed.
// In this case, the proposal is aborted and no additional content will be processed.
InvalidProposal,
}

Expand Down

0 comments on commit a90de83

Please sign in to comment.