Skip to content

Commit

Permalink
refactor(base_layer): remove optional finality
Browse files Browse the repository at this point in the history
No finality is equivalent to passing finality 0.

commit-id:2f82d223
  • Loading branch information
Gilad Chase committed Sep 19, 2024
1 parent 4f0d83f commit c15b065
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
12 changes: 6 additions & 6 deletions crates/papyrus_base_layer/src/base_layer_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u64>, Option<(BlockNumber, BlockHash)>);
type Scenario = (u64, Option<(BlockNumber, BlockHash)>);
let scenarios: Vec<Scenario> = 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();
Expand Down
10 changes: 3 additions & 7 deletions crates/papyrus_base_layer/src/ethereum_base_layer_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,10 @@ impl BaseLayerContract for EthereumBaseLayerContract {

async fn latest_proved_block(
&self,
finality: Option<u64>,
finality: u64,
) -> Result<Option<(BlockNumber, BlockHash)>, 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);
};
Expand Down
2 changes: 1 addition & 1 deletion crates/papyrus_base_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ pub trait BaseLayerContract {
/// Optionally, require minimum confirmations.
async fn latest_proved_block(
&self,
finality: Option<u64>,
finality: u64,
) -> Result<Option<(BlockNumber, BlockHash)>, Self::Error>;
}

0 comments on commit c15b065

Please sign in to comment.