From 8f600fef10e23f3041b8d8b8c65b37ac62206250 Mon Sep 17 00:00:00 2001 From: Gilad Chase Date: Wed, 18 Sep 2024 18:35:37 +0300 Subject: [PATCH] refactor(base_layer): remove optional finality No finality is equivalent to passing finality 0. commit-id:2f82d223 --- crates/papyrus_base_layer/src/base_layer_test.rs | 12 ++++++------ .../src/ethereum_base_layer_contract.rs | 10 +++------- crates/papyrus_base_layer/src/lib.rs | 2 +- crates/papyrus_sync/src/sources/base_layer.rs | 3 ++- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/crates/papyrus_base_layer/src/base_layer_test.rs b/crates/papyrus_base_layer/src/base_layer_test.rs index 2159aa9107..d9b0081899 100644 --- a/crates/papyrus_base_layer/src/base_layer_test.rs +++ b/crates/papyrus_base_layer/src/base_layer_test.rs @@ -86,13 +86,13 @@ async fn latest_proved_block_ethereum() { let second_sn_state_update = (BlockNumber(200), BlockHash(felt!("0x200"))); let third_sn_state_update = (BlockNumber(300), BlockHash(felt!("0x300"))); - type Scenario = (Option, Option<(BlockNumber, BlockHash)>); + type Scenario = (u64, Option<(BlockNumber, BlockHash)>); let scenarios: Vec = vec![ - (None, Some(third_sn_state_update)), - (Some(5), Some(third_sn_state_update)), - (Some(15), Some(second_sn_state_update)), - (Some(25), Some(first_sn_state_update)), - (Some(1000), None), + (0, Some(third_sn_state_update)), + (5, Some(third_sn_state_update)), + (15, Some(second_sn_state_update)), + (25, Some(first_sn_state_update)), + (1000, None), ]; for (scenario, expected) in scenarios { let latest_block = contract.latest_proved_block(scenario).await.unwrap(); diff --git a/crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs b/crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs index 3522c68fb8..6f5d4191f5 100644 --- a/crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs +++ b/crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs @@ -99,14 +99,10 @@ impl BaseLayerContract for EthereumBaseLayerContract { async fn latest_proved_block( &self, - finality: Option, + finality: u64, ) -> Result, Self::Error> { - let ethereum_block_number = self - .contract - .provider() - .get_block_number() - .await? - .checked_sub(finality.unwrap_or_default()); + let ethereum_block_number = + self.contract.provider().get_block_number().await?.checked_sub(finality); let Some(ethereum_block_number) = ethereum_block_number else { return Ok(None); }; diff --git a/crates/papyrus_base_layer/src/lib.rs b/crates/papyrus_base_layer/src/lib.rs index 61a98d9860..b0dff595db 100644 --- a/crates/papyrus_base_layer/src/lib.rs +++ b/crates/papyrus_base_layer/src/lib.rs @@ -15,6 +15,6 @@ pub trait BaseLayerContract { /// Optionally, require minimum confirmations. async fn latest_proved_block( &self, - finality: Option, + finality: u64, ) -> Result, Self::Error>; } diff --git a/crates/papyrus_sync/src/sources/base_layer.rs b/crates/papyrus_sync/src/sources/base_layer.rs index 5c4eddb7a1..2ecac3b8c4 100644 --- a/crates/papyrus_sync/src/sources/base_layer.rs +++ b/crates/papyrus_sync/src/sources/base_layer.rs @@ -36,7 +36,8 @@ impl< async fn latest_proved_block( &self, ) -> Result, BaseLayerSourceError> { - self.latest_proved_block(None) + let finality = 0; + self.latest_proved_block(finality) .await .map_err(|e| BaseLayerSourceError::BaseLayerContractError(Box::new(e))) }