Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(base_layer): remove optional finality #869

Merged
merged 1 commit into from
Sep 22, 2024
Merged
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
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
12 changes: 5 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 @@ -97,16 +97,14 @@ impl EthereumBaseLayerContract {
impl BaseLayerContract for EthereumBaseLayerContract {
type Error = EthereumBaseLayerError;

/// Returns the latest proved block on Ethereum, where finality determines how many
/// blocks back (0 = latest).
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>;
}
3 changes: 2 additions & 1 deletion crates/papyrus_sync/src/sources/base_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ impl<
async fn latest_proved_block(
&self,
) -> Result<Option<(BlockNumber, BlockHash)>, BaseLayerSourceError> {
self.latest_proved_block(None)
let finality = 0;
self.latest_proved_block(finality)
.await
.map_err(|e| BaseLayerSourceError::BaseLayerContractError(Box::new(e)))
}
Expand Down
Loading