From 8a8f9ae09ef800bf1ce704b6c3497c0f64be0143 Mon Sep 17 00:00:00 2001 From: Gilad Chase Date: Mon, 9 Dec 2024 12:52:17 +0200 Subject: [PATCH] chore(starknet_l1_provider_types): add crate Only move, no logic changes, this is a setup for upcoming infra support. --- Cargo.lock | 12 ++++++-- Cargo.toml | 2 ++ commitlint.config.js | 1 + crates/starknet_l1_provider/Cargo.toml | 2 +- crates/starknet_l1_provider/src/errors.rs | 25 ----------------- .../src/l1_provider_tests.rs | 5 ++-- crates/starknet_l1_provider/src/lib.rs | 13 ++------- crates/starknet_l1_provider_types/Cargo.toml | 13 +++++++++ .../starknet_l1_provider_types/src/errors.rs | 28 +++++++++++++++++++ crates/starknet_l1_provider_types/src/lib.rs | 12 ++++++++ 10 files changed, 72 insertions(+), 41 deletions(-) create mode 100644 crates/starknet_l1_provider_types/Cargo.toml create mode 100644 crates/starknet_l1_provider_types/src/errors.rs create mode 100644 crates/starknet_l1_provider_types/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 330f1220a1..0a77604cff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -10473,8 +10473,16 @@ dependencies = [ "indexmap 2.6.0", "papyrus_base_layer", "pretty_assertions", - "serde", "starknet_api", + "starknet_l1_provider_types", + "thiserror", +] + +[[package]] +name = "starknet_l1_provider_types" +version = "0.0.0" +dependencies = [ + "serde", "thiserror", ] @@ -10560,9 +10568,9 @@ version = "0.0.0" dependencies = [ "axum", "hyper 0.14.30", + "infra_utils", "metrics 0.21.1", "metrics-exporter-prometheus", - "infra_utils", "papyrus_config", "pretty_assertions", "serde", diff --git a/Cargo.toml b/Cargo.toml index c6d24742d4..912658a344 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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", @@ -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" } diff --git a/commitlint.config.js b/commitlint.config.js index 9f3e1c54a4..f371cc6f69 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -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', diff --git a/crates/starknet_l1_provider/Cargo.toml b/crates/starknet_l1_provider/Cargo.toml index f8aedecabf..3006d7b3ea 100644 --- a/crates/starknet_l1_provider/Cargo.toml +++ b/crates/starknet_l1_provider/Cargo.toml @@ -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] diff --git a/crates/starknet_l1_provider/src/errors.rs b/crates/starknet_l1_provider/src/errors.rs index 9bef42fbbf..40ba30db83 100644 --- a/crates/starknet_l1_provider/src/errors.rs +++ b/crates/starknet_l1_provider/src/errors.rs @@ -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 { diff --git a/crates/starknet_l1_provider/src/l1_provider_tests.rs b/crates/starknet_l1_provider/src/l1_provider_tests.rs index 7e878a0431..6af7ff8cdf 100644 --- a/crates/starknet_l1_provider/src/l1_provider_tests.rs +++ b/crates/starknet_l1_provider/src/l1_provider_tests.rs @@ -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) => {{ diff --git a/crates/starknet_l1_provider/src/lib.rs b/crates/starknet_l1_provider/src/lib.rs index 25e7ab4244..207de91693 100644 --- a/crates/starknet_l1_provider/src/lib.rs +++ b/crates/starknet_l1_provider/src/lib.rs @@ -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 = Result; +use starknet_l1_provider_types::errors::L1ProviderError; +use starknet_l1_provider_types::{L1ProviderResult, ValidationStatus}; #[cfg(test)] #[path = "l1_provider_tests.rs"] @@ -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 { diff --git a/crates/starknet_l1_provider_types/Cargo.toml b/crates/starknet_l1_provider_types/Cargo.toml new file mode 100644 index 0000000000..3af64c191b --- /dev/null +++ b/crates/starknet_l1_provider_types/Cargo.toml @@ -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 diff --git a/crates/starknet_l1_provider_types/src/errors.rs b/crates/starknet_l1_provider_types/src/errors.rs new file mode 100644 index 0000000000..087762af47 --- /dev/null +++ b/crates/starknet_l1_provider_types/src/errors.rs @@ -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() } + } +} diff --git a/crates/starknet_l1_provider_types/src/lib.rs b/crates/starknet_l1_provider_types/src/lib.rs new file mode 100644 index 0000000000..c4be886d80 --- /dev/null +++ b/crates/starknet_l1_provider_types/src/lib.rs @@ -0,0 +1,12 @@ +pub mod errors; + +use crate::errors::L1ProviderError; + +pub type L1ProviderResult = Result; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum ValidationStatus { + Validated, + AlreadyIncludedOnL2, + ConsumedOnL1OrUnknown, +}