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

chore(starknet_l1_provider_types): add crate #2579

Merged
merged 1 commit into from
Dec 9, 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: 10 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ members = [
"crates/starknet_http_server",
"crates/starknet_integration_tests",
"crates/starknet_l1_provider",
"crates/starknet_l1_provider_types",
"crates/starknet_mempool",
"crates/starknet_mempool_p2p",
"crates/starknet_mempool_p2p_types",
Expand Down Expand Up @@ -222,6 +223,7 @@ starknet_gateway = { path = "crates/starknet_gateway", version = "0.0.0" }
starknet_gateway_types = { path = "crates/starknet_gateway_types", version = "0.0.0" }
starknet_http_server = { path = "crates/starknet_http_server", version = "0.0.0" }
starknet_l1_provider = { path = "crates/starknet_l1_provider", version = "0.0.0" }
starknet_l1_provider_types = { path = "crates/starknet_l1_provider_types", version = "0.0.0" }
starknet_mempool = { path = "crates/starknet_mempool", version = "0.0.0" }
starknet_mempool_p2p = { path = "crates/starknet_mempool_p2p", version = "0.0.0" }
starknet_mempool_p2p_types = { path = "crates/starknet_mempool_p2p_types", version = "0.0.0" }
Expand Down
1 change: 1 addition & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const Configuration = {
'starknet_http_server',
'starknet_integration_tests',
'starknet_l1_provider',
'starknet_l1_provider_types',
'starknet_mempool',
'starknet_mempool_p2p',
'starknet_mempool_p2p_types',
Expand Down
2 changes: 1 addition & 1 deletion crates/starknet_l1_provider/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ license.workspace = true
[dependencies]
indexmap.workspace = true
papyrus_base_layer.workspace = true
serde.workspace = true
starknet_api.workspace = true
starknet_l1_provider_types.workspace = true
thiserror.workspace = true

[dev-dependencies]
Expand Down
25 changes: 0 additions & 25 deletions crates/starknet_l1_provider/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,6 @@
use papyrus_base_layer::ethereum_base_layer_contract::EthereumBaseLayerError;
use serde::{Deserialize, Serialize};
use thiserror::Error;

#[derive(Clone, Debug, Error, PartialEq, Eq, Serialize, Deserialize)]
pub enum L1ProviderError {
#[error(
"`get_txs` called while in `Pending` state, likely due to a crash; restart block proposal"
)]
GetTransactionsInPendingState,
#[error("`get_txs` while in validate state")]
GetTransactionConsensusBug,
#[error("Cannot transition from {from} to {to}")]
UnexpectedProviderStateTransition { from: String, to: String },
#[error(
"`validate` called while in `Pending` state, likely due to a crash; restart block proposal"
)]
ValidateInPendingState,
#[error("`validate` called while in `Propose`")]
ValidateTransactionConsensusBug,
}

impl L1ProviderError {
pub fn unexpected_transition(from: impl ToString, to: impl ToString) -> Self {
Self::UnexpectedProviderStateTransition { from: from.to_string(), to: to.to_string() }
}
}

// TODO(Gilad): move to scraper module once it's created.
#[derive(Error, Debug)]
pub enum L1ScraperError {
Expand Down
5 changes: 3 additions & 2 deletions crates/starknet_l1_provider/src/l1_provider_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ use pretty_assertions::assert_eq;
use starknet_api::test_utils::l1_handler::executable_l1_handler_tx;
use starknet_api::transaction::TransactionHash;
use starknet_api::{l1_handler_tx_args, tx_hash};
use starknet_l1_provider_types::errors::L1ProviderError;
use starknet_l1_provider_types::ValidationStatus;

use crate::errors::L1ProviderError;
use crate::test_utils::L1ProviderContentBuilder;
use crate::L1Provider;
use crate::ProviderState::{Pending, Propose, Uninitialized, Validate};
use crate::{L1Provider, ValidationStatus};

macro_rules! tx {
(tx_hash: $tx_hash:expr) => {{
Expand Down
13 changes: 2 additions & 11 deletions crates/starknet_l1_provider/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ pub mod test_utils;
use indexmap::{IndexMap, IndexSet};
use starknet_api::executable_transaction::L1HandlerTransaction;
use starknet_api::transaction::TransactionHash;

use crate::errors::L1ProviderError;

type L1ProviderResult<T> = Result<T, L1ProviderError>;
use starknet_l1_provider_types::errors::L1ProviderError;
use starknet_l1_provider_types::{L1ProviderResult, ValidationStatus};

#[cfg(test)]
#[path = "l1_provider_tests.rs"]
Expand Down Expand Up @@ -142,13 +140,6 @@ impl TransactionManager {
}
}

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ValidationStatus {
Validated,
AlreadyIncludedOnL2,
ConsumedOnL1OrUnknown,
}

/// Current state of the provider, where pending means: idle, between proposal/validation cycles.
#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
pub enum ProviderState {
Expand Down
13 changes: 13 additions & 0 deletions crates/starknet_l1_provider_types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "starknet_l1_provider_types"
version.workspace = true
edition.workspace = true
repository.workspace = true
license.workspace = true

[dependencies]
serde.workspace = true
thiserror.workspace = true

[lints]
workspace = true
28 changes: 28 additions & 0 deletions crates/starknet_l1_provider_types/src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::fmt::Debug;

use serde::{Deserialize, Serialize};
use thiserror::Error;

#[derive(Clone, Debug, Error, PartialEq, Eq, Serialize, Deserialize)]
pub enum L1ProviderError {
#[error(
"`get_txs` called while in `Pending` state, likely due to a crash; restart block proposal"
)]
GetTransactionsInPendingState,
#[error("`get_txs` while in validate state")]
GetTransactionConsensusBug,
#[error("Cannot transition from {from} to {to}")]
UnexpectedProviderStateTransition { from: String, to: String },
#[error(
"`validate` called while in `Pending` state, likely due to a crash; restart block proposal"
)]
ValidateInPendingState,
#[error("`validate` called while in `Propose`")]
ValidateTransactionConsensusBug,
}

impl L1ProviderError {
pub fn unexpected_transition(from: impl ToString, to: impl ToString) -> Self {
Self::UnexpectedProviderStateTransition { from: from.to_string(), to: to.to_string() }
}
}
12 changes: 12 additions & 0 deletions crates/starknet_l1_provider_types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
pub mod errors;

use crate::errors::L1ProviderError;

pub type L1ProviderResult<T> = Result<T, L1ProviderError>;

#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum ValidationStatus {
Validated,
AlreadyIncludedOnL2,
ConsumedOnL1OrUnknown,
}
Loading