Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ impl StarknetVersion {
// Poseidon hash, even when `class_commitment` is zero.
pub const V_0_14_0: Self = Self::new(0, 14, 0, 0);
pub const V_0_14_1: Self = Self::new(0, 14, 1, 0);
pub const V_0_14_3: Self = Self::new(0, 14, 3, 0);
}

impl FromStr for StarknetVersion {
Expand Down
12 changes: 11 additions & 1 deletion crates/gateway-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ pub trait GatewayApi: Sync {
async fn preconfirmed_block(
&self,
block: BlockId,
round: u64,
transaction_count: u64,
) -> Result<PreConfirmedBlock, SequencerError> {
unimplemented!();
}
Expand Down Expand Up @@ -161,8 +163,12 @@ impl<T: GatewayApi + Sync + Send> GatewayApi for Arc<T> {
async fn preconfirmed_block(
&self,
block: BlockId,
round: u64,
transaction_count: u64,
) -> Result<PreConfirmedBlock, SequencerError> {
self.as_ref().preconfirmed_block(block).await
self.as_ref()
.preconfirmed_block(block, round, transaction_count)
.await
}

async fn block_header(
Expand Down Expand Up @@ -512,6 +518,8 @@ impl GatewayApi for Client {
async fn preconfirmed_block(
&self,
block: BlockId,
round: u64,
transaction_count: u64,
) -> Result<PreConfirmedBlock, SequencerError> {
// Note that we don't do retries here.
// The pre-confirmed block is polled continuously by the sync logic,
Expand All @@ -520,6 +528,8 @@ impl GatewayApi for Client {
.feeder_gateway_request()
.get_preconfirmed_block()
.block(block)
.param("round", &round.to_string())
.param("transactionCount", &transaction_count.to_string())
.retry(false)
.get()
.await?;
Expand Down
48 changes: 48 additions & 0 deletions crates/gateway-types/src/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ pub struct PreConfirmedBlock {
>,

pub transaction_state_diffs: Vec<Option<state_update::StateDiff>>,

/// Current consensus round at this height (TODO: Pending spec confirmation)
///
/// From Starknet 0.14.3 onward, the pre-confirmed block endpoint returns
/// transactions added after the caller-supplied `transaction_count`.
/// Will default to `None` for earlier versions.
#[serde(default)]
pub round: Option<u64>,
}

#[derive(Copy, Clone, Debug, Default, Deserialize, PartialEq, Eq, serde::Serialize)]
Expand Down Expand Up @@ -2565,5 +2573,45 @@ mod tests {

let _pre_confirmed_block: PreConfirmedBlock = serde_json::from_str(json).unwrap();
}

mod round_field {
use super::super::super::PreConfirmedBlock;

fn pre_confirmed_block_json(round: Option<u64>) -> serde_json::Value {
let mut body = serde_json::json!({
"l1_gas_price": {"price_in_wei": "0x0", "price_in_fri": "0x0"},
"l1_data_gas_price":{"price_in_wei": "0x0", "price_in_fri": "0x0"},
"l2_gas_price": {"price_in_wei": "0x0", "price_in_fri": "0x0"},
"sequencer_address": "0x0",
"status": "PRE_CONFIRMED",
"timestamp": 0,
"starknet_version": "0.14.3",
"l1_da_mode": "BLOB",
"transactions": [],
"transaction_receipts": [],
"transaction_state_diffs": [],
});
if let Some(r) = round {
body.as_object_mut()
.unwrap()
.insert("round".into(), r.into());
}
body
}

#[test]
fn round_present_parses_to_some() {
let body = pre_confirmed_block_json(Some(5));
let block: PreConfirmedBlock = serde_json::from_value(body).unwrap();
assert_eq!(block.round, Some(5));
}

#[test]
fn round_absent_parses_to_none() {
let body = pre_confirmed_block_json(None);
let block: PreConfirmedBlock = serde_json::from_value(body).unwrap();
assert_eq!(block.round, None);
}
}
}
}
Loading
Loading