From 44bcd729131b01e7c73c965412f9538c772049a7 Mon Sep 17 00:00:00 2001 From: jfldde <168934971+jfldde@users.noreply.github.com> Date: Thu, 12 Dec 2024 11:53:17 +0000 Subject: [PATCH 01/10] Derive rpc(server) for LedgerRpc (#1598) --- bin/citrea/src/test_rpc.rs | 3 +- .../tests/bitcoin_e2e/batch_prover_test.rs | 2 +- bin/citrea/tests/bitcoin_e2e/bitcoin_test.rs | 2 +- bin/citrea/tests/bitcoin_e2e/full_node.rs | 2 +- .../tests/bitcoin_e2e/light_client_test.rs | 2 +- .../bitcoin_e2e/sequencer_commitments.rs | 2 +- .../tests/bitcoin_e2e/sequencer_test.rs | 2 +- bin/citrea/tests/e2e/mod.rs | 10 +- bin/citrea/tests/e2e/proving.rs | 10 +- bin/citrea/tests/e2e/sequencer_behaviour.rs | 1 - .../tests/e2e/soft_confirmation_status.rs | 8 +- bin/citrea/tests/test_client/mod.rs | 52 ++-- bin/citrea/tests/test_helpers/mod.rs | 1 - .../full-node/db/sov-db/src/ledger_db/rpc.rs | 5 +- .../full-node/sov-ledger-rpc/src/client.rs | 102 ------- .../full-node/sov-ledger-rpc/src/lib.rs | 131 +++++++- .../full-node/sov-ledger-rpc/src/server.rs | 285 +++++++++--------- .../sov-ledger-rpc/tests/empty_ledger.rs | 9 +- .../src/runtime_rpc.rs | 10 +- .../rollup-interface/src/node/rpc/mod.rs | 6 +- 20 files changed, 321 insertions(+), 324 deletions(-) delete mode 100644 crates/sovereign-sdk/full-node/sov-ledger-rpc/src/client.rs diff --git a/bin/citrea/src/test_rpc.rs b/bin/citrea/src/test_rpc.rs index 75f06acae..21e687900 100644 --- a/bin/citrea/src/test_rpc.rs +++ b/bin/citrea/src/test_rpc.rs @@ -82,8 +82,7 @@ fn test_helper( .await .unwrap(); let addr = server.local_addr().unwrap(); - let server_rpc_module = - sov_ledger_rpc::server::rpc_module::(ledger_db).unwrap(); + let server_rpc_module = sov_ledger_rpc::server::create_rpc_module::(ledger_db); let _server_handle = server.start(server_rpc_module); let rpc_config = RpcConfig { diff --git a/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs b/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs index e792b33bb..6c916e591 100644 --- a/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs +++ b/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs @@ -19,7 +19,7 @@ use citrea_e2e::traits::NodeT; use citrea_e2e::Result; use citrea_primitives::{TO_BATCH_PROOF_PREFIX, TO_LIGHT_CLIENT_PREFIX}; use reth_primitives::{Address, U64}; -use sov_ledger_rpc::client::RpcClient; +use sov_ledger_rpc::LedgerRpcClient; use sov_rollup_interface::da::{DaData, SequencerCommitment}; use sov_rollup_interface::rpc::VerifiedBatchProofResponse; use tokio::time::sleep; diff --git a/bin/citrea/tests/bitcoin_e2e/bitcoin_test.rs b/bin/citrea/tests/bitcoin_e2e/bitcoin_test.rs index e121602a8..3cf4dad4e 100644 --- a/bin/citrea/tests/bitcoin_e2e/bitcoin_test.rs +++ b/bin/citrea/tests/bitcoin_e2e/bitcoin_test.rs @@ -14,7 +14,7 @@ use citrea_e2e::test_case::{TestCase, TestCaseRunner}; use citrea_e2e::traits::Restart; use citrea_e2e::Result; use reth_primitives::U64; -use sov_ledger_rpc::client::RpcClient; +use sov_ledger_rpc::LedgerRpcClient; use tokio::time::sleep; use super::get_citrea_path; diff --git a/bin/citrea/tests/bitcoin_e2e/full_node.rs b/bin/citrea/tests/bitcoin_e2e/full_node.rs index 1c4922ac2..84da04145 100644 --- a/bin/citrea/tests/bitcoin_e2e/full_node.rs +++ b/bin/citrea/tests/bitcoin_e2e/full_node.rs @@ -4,7 +4,7 @@ use citrea_e2e::framework::TestFramework; use citrea_e2e::test_case::{TestCase, TestCaseRunner}; use citrea_e2e::traits::Restart; use citrea_e2e::Result; -use sov_ledger_rpc::client::RpcClient; +use sov_ledger_rpc::LedgerRpcClient; use super::get_citrea_path; diff --git a/bin/citrea/tests/bitcoin_e2e/light_client_test.rs b/bin/citrea/tests/bitcoin_e2e/light_client_test.rs index e9e17ef76..b3ae468d6 100644 --- a/bin/citrea/tests/bitcoin_e2e/light_client_test.rs +++ b/bin/citrea/tests/bitcoin_e2e/light_client_test.rs @@ -13,7 +13,7 @@ use citrea_e2e::test_case::{TestCase, TestCaseRunner}; use citrea_e2e::Result; use citrea_light_client_prover::rpc::LightClientProverRpcClient; use reth_primitives::U64; -use sov_ledger_rpc::client::RpcClient; +use sov_ledger_rpc::LedgerRpcClient; use super::batch_prover_test::wait_for_zkproofs; use super::get_citrea_path; diff --git a/bin/citrea/tests/bitcoin_e2e/sequencer_commitments.rs b/bin/citrea/tests/bitcoin_e2e/sequencer_commitments.rs index 797974048..df90ec252 100644 --- a/bin/citrea/tests/bitcoin_e2e/sequencer_commitments.rs +++ b/bin/citrea/tests/bitcoin_e2e/sequencer_commitments.rs @@ -17,7 +17,7 @@ use citrea_primitives::TO_BATCH_PROOF_PREFIX; use reth_primitives::U64; use rs_merkle::algorithms::Sha256; use rs_merkle::MerkleTree; -use sov_ledger_rpc::client::RpcClient; +use sov_ledger_rpc::LedgerRpcClient; use sov_rollup_interface::da::{BlobReaderTrait, DaData}; use sov_rollup_interface::rpc::SequencerCommitmentResponse; use tokio::time::sleep; diff --git a/bin/citrea/tests/bitcoin_e2e/sequencer_test.rs b/bin/citrea/tests/bitcoin_e2e/sequencer_test.rs index 06e3c987c..c81841b06 100644 --- a/bin/citrea/tests/bitcoin_e2e/sequencer_test.rs +++ b/bin/citrea/tests/bitcoin_e2e/sequencer_test.rs @@ -6,7 +6,7 @@ use citrea_e2e::test_case::{TestCase, TestCaseRunner}; use citrea_e2e::traits::Restart; use citrea_e2e::Result; use reth_primitives::U64; -use sov_ledger_rpc::client::RpcClient; +use sov_ledger_rpc::LedgerRpcClient; use super::get_citrea_path; diff --git a/bin/citrea/tests/e2e/mod.rs b/bin/citrea/tests/e2e/mod.rs index 76f4922db..de2f3c722 100644 --- a/bin/citrea/tests/e2e/mod.rs +++ b/bin/citrea/tests/e2e/mod.rs @@ -189,7 +189,8 @@ async fn test_all_flow() { let prover_proof = prover_node_test_client .ledger_get_batch_proofs_by_slot_height(3) - .await[0] + .await + .unwrap()[0] .clone(); // the proof will be in l1 block #4 because prover publishes it after the commitment and in mock da submitting proof and commitments creates a new block @@ -225,14 +226,12 @@ async fn test_all_flow() { full_node_test_client .ledger_get_soft_confirmation_status(5) .await - .unwrap() .unwrap(); for i in 1..=4 { let status = full_node_test_client .ledger_get_soft_confirmation_status(i) .await - .unwrap() .unwrap(); assert_eq!(status, SoftConfirmationStatus::Proven); @@ -283,7 +282,8 @@ async fn test_all_flow() { let prover_proof_data = prover_node_test_client .ledger_get_batch_proofs_by_slot_height(5) - .await[0] + .await + .unwrap()[0] .clone(); wait_for_proof(&full_node_test_client, 6, Some(Duration::from_secs(120))).await; @@ -329,7 +329,6 @@ async fn test_all_flow() { let status = full_node_test_client .ledger_get_soft_confirmation_status(i) .await - .unwrap() .unwrap(); assert_eq!(status, SoftConfirmationStatus::Proven); @@ -410,7 +409,6 @@ async fn test_ledger_get_head_soft_confirmation() { let head_soft_confirmation_height = seq_test_client .ledger_get_head_soft_confirmation_height() .await - .unwrap() .unwrap(); assert_eq!(head_soft_confirmation_height, 2); diff --git a/bin/citrea/tests/e2e/proving.rs b/bin/citrea/tests/e2e/proving.rs index 8e17ca96e..fd93c6a6a 100644 --- a/bin/citrea/tests/e2e/proving.rs +++ b/bin/citrea/tests/e2e/proving.rs @@ -143,7 +143,8 @@ async fn full_node_verify_proof_and_store() { let prover_proof = prover_node_test_client .ledger_get_batch_proofs_by_slot_height(3) - .await[0] + .await + .unwrap()[0] .clone(); // The proof will be in l1 block #4 because prover publishes it after the commitment and @@ -182,14 +183,12 @@ async fn full_node_verify_proof_and_store() { full_node_test_client .ledger_get_soft_confirmation_status(5) .await - .unwrap() .unwrap(); for i in 1..=4 { let status = full_node_test_client .ledger_get_soft_confirmation_status(i) .await - .unwrap() .unwrap(); assert_eq!(status, SoftConfirmationStatus::Proven); @@ -331,7 +330,8 @@ async fn test_batch_prover_prove_rpc() { let prover_proof = prover_node_test_client .ledger_get_batch_proofs_by_slot_height(3) - .await[0] + .await + .unwrap()[0] .clone(); // The proof will be in l1 block #4 because prover publishes it after the commitment and @@ -359,14 +359,12 @@ async fn test_batch_prover_prove_rpc() { full_node_test_client .ledger_get_soft_confirmation_status(5) .await - .unwrap() .unwrap(); for i in 1..=4 { let status = full_node_test_client .ledger_get_soft_confirmation_status(i) .await - .unwrap() .unwrap(); assert_eq!(status, SoftConfirmationStatus::Proven); diff --git a/bin/citrea/tests/e2e/sequencer_behaviour.rs b/bin/citrea/tests/e2e/sequencer_behaviour.rs index 3dc358bf5..be040feab 100644 --- a/bin/citrea/tests/e2e/sequencer_behaviour.rs +++ b/bin/citrea/tests/e2e/sequencer_behaviour.rs @@ -109,7 +109,6 @@ async fn test_sequencer_fill_missing_da_blocks() -> Result<(), anyhow::Error> { let head_soft_confirmation_num = seq_test_client .ledger_get_head_soft_confirmation_height() .await - .unwrap() .unwrap(); assert_eq!(head_soft_confirmation_num, last_filler_l2_block + 1); diff --git a/bin/citrea/tests/e2e/soft_confirmation_status.rs b/bin/citrea/tests/e2e/soft_confirmation_status.rs index 9f2c8549e..0ecfb3bb0 100644 --- a/bin/citrea/tests/e2e/soft_confirmation_status.rs +++ b/bin/citrea/tests/e2e/soft_confirmation_status.rs @@ -44,7 +44,7 @@ async fn test_soft_confirmations_status_one_l1() -> Result<(), anyhow::Error> { .await .unwrap(); - assert_eq!(SoftConfirmationStatus::Trusted, status_node.unwrap()); + assert_eq!(SoftConfirmationStatus::Trusted, status_node); } // Wait for DA block #2 containing the commitment @@ -58,7 +58,7 @@ async fn test_soft_confirmations_status_one_l1() -> Result<(), anyhow::Error> { .await .unwrap(); - assert_eq!(SoftConfirmationStatus::Finalized, status_node.unwrap()); + assert_eq!(SoftConfirmationStatus::Finalized, status_node); } seq_task.abort(); @@ -117,7 +117,7 @@ async fn test_soft_confirmations_status_two_l1() -> Result<(), anyhow::Error> { .await .unwrap(); - assert_eq!(SoftConfirmationStatus::Finalized, status_node.unwrap()); + assert_eq!(SoftConfirmationStatus::Finalized, status_node); } // Check that these L2 blocks are bounded on different L1 block @@ -148,7 +148,7 @@ async fn test_soft_confirmations_status_two_l1() -> Result<(), anyhow::Error> { .await .unwrap(); - assert_eq!(SoftConfirmationStatus::Finalized, status_node.unwrap()); + assert_eq!(SoftConfirmationStatus::Finalized, status_node); } let status_node = full_node_test_client diff --git a/bin/citrea/tests/test_client/mod.rs b/bin/citrea/tests/test_client/mod.rs index 9855627e5..a3abcefae 100644 --- a/bin/citrea/tests/test_client/mod.rs +++ b/bin/citrea/tests/test_client/mod.rs @@ -18,9 +18,7 @@ use jsonrpsee::ws_client::{PingConfig, WsClient, WsClientBuilder}; use reth_primitives::{Address, BlockId, BlockNumberOrTag, Bytes, TxHash, TxKind, B256, U256, U64}; use reth_rpc_types::trace::geth::{GethDebugTracingOptions, GethTrace}; use reth_rpc_types::RichBlock; -use sequencer_client::GetSoftConfirmationResponse; -use sov_ledger_rpc::client::RpcClient; -use sov_ledger_rpc::HexHash; +use sov_ledger_rpc::{HexHash, LedgerRpcClient}; use sov_rollup_interface::rpc::{ BatchProofResponse, LastVerifiedBatchProofResponse, SequencerCommitmentResponse, SoftConfirmationResponse, SoftConfirmationStatus, VerifiedBatchProofResponse, @@ -495,9 +493,9 @@ impl TestClient { >( &self, num: u64, - ) -> Option { + ) -> Option { self.http_client - .request("ledger_getSoftConfirmationByNumber", rpc_params![num]) + .get_soft_confirmation_by_number(U64::from(num)) .await .unwrap() } @@ -505,21 +503,15 @@ impl TestClient { pub(crate) async fn ledger_get_soft_confirmation_status( &self, soft_confirmation_receipt: u64, - ) -> Result, Box> { - self.http_client - .request( - "ledger_getSoftConfirmationStatus", - rpc_params![soft_confirmation_receipt], - ) - .await - .map_err(|e| e.into()) + ) -> Result> { + Ok(self + .http_client + .get_soft_confirmation_status(U64::from(soft_confirmation_receipt)) + .await?) } pub(crate) async fn ledger_get_last_scanned_l1_height(&self) -> u64 { - self.http_client - .request("ledger_getLastScannedL1Height", rpc_params![]) - .await - .unwrap() + self.http_client.get_last_scanned_l1_height().await.unwrap() } pub(crate) async fn ledger_get_sequencer_commitments_on_slot_by_number( @@ -527,10 +519,7 @@ impl TestClient { height: u64, ) -> anyhow::Result>> { self.http_client - .request( - "ledger_getSequencerCommitmentsOnSlotByNumber", - rpc_params![height], - ) + .get_sequencer_commitments_on_slot_by_number(U64::from(height)) .await .map_err(|e| e.into()) } @@ -538,9 +527,9 @@ impl TestClient { pub(crate) async fn ledger_get_batch_proofs_by_slot_height( &self, height: u64, - ) -> Vec { + ) -> Option> { self.http_client - .request("ledger_getBatchProofsBySlotHeight", rpc_params![height]) + .get_batch_proofs_by_slot_height(U64::from(height)) .await .unwrap() } @@ -550,21 +539,18 @@ impl TestClient { height: u64, ) -> Option> { self.http_client - .request( - "ledger_getVerifiedBatchProofsBySlotHeight", - rpc_params![height], - ) + .get_verified_batch_proofs_by_slot_height(U64::from(height)) .await - .ok() + .unwrap() } pub(crate) async fn ledger_get_last_verified_batch_proof( &self, ) -> Option { self.http_client - .request("ledger_getLastVerifiedBatchProof", rpc_params![]) + .get_last_verified_batch_proof() .await - .ok() + .unwrap() } pub(crate) async fn ledger_get_sequencer_commitments_on_slot_by_hash( @@ -581,16 +567,16 @@ impl TestClient { &self, ) -> Result, Box> { self.http_client - .request("ledger_getHeadSoftConfirmation", rpc_params![]) + .get_head_soft_confirmation() .await .map_err(|e| e.into()) } pub(crate) async fn ledger_get_head_soft_confirmation_height( &self, - ) -> Result, Box> { + ) -> Result> { self.http_client - .request("ledger_getHeadSoftConfirmationHeight", rpc_params![]) + .get_head_soft_confirmation_height() .await .map_err(|e| e.into()) } diff --git a/bin/citrea/tests/test_helpers/mod.rs b/bin/citrea/tests/test_helpers/mod.rs index 9c911404e..8f1b51f93 100644 --- a/bin/citrea/tests/test_helpers/mod.rs +++ b/bin/citrea/tests/test_helpers/mod.rs @@ -208,7 +208,6 @@ pub async fn wait_for_l2_block(client: &TestClient, num: u64, timeout: Option= num { diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/rpc.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/rpc.rs index 3a669d248..e287dae5e 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/rpc.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/rpc.rs @@ -1,4 +1,3 @@ -use serde::de::DeserializeOwned; use sov_rollup_interface::rpc::{ sequencer_commitment_to_response, BatchProofResponse, LastVerifiedBatchProofResponse, LedgerRpcProvider, SequencerCommitmentResponse, SoftConfirmationIdentifier, @@ -36,14 +35,14 @@ impl LedgerRpcProvider for LedgerDB { }) } - fn get_soft_confirmation_by_hash( + fn get_soft_confirmation_by_hash( &self, hash: &[u8; 32], ) -> Result, anyhow::Error> { self.get_soft_confirmation(&SoftConfirmationIdentifier::Hash(*hash)) } - fn get_soft_confirmation_by_number( + fn get_soft_confirmation_by_number( &self, number: u64, ) -> Result, anyhow::Error> { diff --git a/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/client.rs b/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/client.rs deleted file mode 100644 index e3958bc4f..000000000 --- a/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/client.rs +++ /dev/null @@ -1,102 +0,0 @@ -//! A [`jsonrpsee`] client for interacting with the Sovereign SDK ledger -//! JSON-RPC API. -//! -//! See [`RpcClient`]. - -use jsonrpsee::proc_macros::rpc; -use reth_primitives::U64; -use sov_rollup_interface::rpc::{ - BatchProofResponse, SequencerCommitmentResponse, SoftConfirmationResponse, - SoftConfirmationStatus, VerifiedBatchProofResponse, -}; - -use crate::HexHash; - -/// A [`jsonrpsee`] trait for interacting with the ledger JSON-RPC API. -/// -/// Client and server implementations are automatically generated by -/// [`jsonrpsee`], see [`RpcClient`] and [`RpcServer`]. -/// -/// For more information about the specific methods, see the -/// [`sov_rollup_interface::rpc`] module. -#[rpc(client, namespace = "ledger")] -pub trait Rpc { - /// Gets a single soft confirmation by number. - #[method(name = "getSoftConfirmationByNumber")] - async fn get_soft_confirmation_by_number( - &self, - number: U64, - ) -> RpcResult>; - - /// Gets a single soft confirmation by hash. - #[method(name = "getSoftConfirmationByHash")] - async fn get_soft_confirmation_by_hash( - &self, - hash: HexHash, - ) -> RpcResult>; - - /// Gets all soft confirmations with numbers `range.start` to `range.end`. - #[method(name = "getSoftConfirmationRange")] - async fn get_soft_confirmation_range( - &self, - range: (U64, U64), - ) -> RpcResult>>; - - /// Gets a single event by number. - #[method(name = "getSoftConfirmationStatus")] - async fn get_soft_confirmation_status( - &self, - soft_confirmation_receipt: U64, - ) -> RpcResult; - - /// Gets the L2 genesis state root. - #[method(name = "getL2GenesisStateRoot")] - async fn get_l2_genesis_state_root(&self) -> Result>, Error>; - - /// Gets the commitments in the DA slot with the given height. - #[method(name = "getSequencerCommitmentsOnSlotByNumber")] - async fn get_sequencer_commitments_on_slot_by_number( - &self, - height: U64, - ) -> RpcResult>>; - - /// Gets the commitments in the DA slot with the given hash. - #[method(name = "getSequencerCommitmentsOnSlotByHash")] - async fn get_sequencer_commitments_on_slot_by_hash( - &self, - hash: HexHash, - ) -> RpcResult>>; - - /// Gets proof by slot height. - #[method(name = "getBatchProofsBySlotHeight")] - async fn get_batch_proofs_by_slot_height( - &self, - height: U64, - ) -> RpcResult>; - - /// Gets proof by slot hash. - #[method(name = "getBatchProofsBySlotHash")] - async fn get_batch_proofs_by_slot_hash( - &self, - hash: HexHash, - ) -> RpcResult>; - - /// Gets the height pf most recent committed soft confirmation. - #[method(name = "getHeadSoftConfirmation")] - async fn get_head_soft_confirmation(&self) -> RpcResult>; - - /// Gets the height pf most recent committed soft confirmation. - #[method(name = "getHeadSoftConfirmationHeight")] - async fn get_head_soft_confirmation_height(&self) -> RpcResult; - - /// Gets verified proofs by slot height - #[method(name = "getVerifiedBatchProofsBySlotHeight")] - async fn get_verified_batch_proofs_by_slot_height( - &self, - height: U64, - ) -> RpcResult>>; - - /// Gets last verified proog - #[method(name = "getLastVerifiedBatchProof")] - async fn get_last_verified_batch_proof(&self) -> RpcResult>; -} diff --git a/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/lib.rs b/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/lib.rs index d75704b82..634c1804e 100644 --- a/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/lib.rs +++ b/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/lib.rs @@ -1,11 +1,16 @@ #![forbid(unsafe_code)] +use jsonrpsee::core::RpcResult; +use jsonrpsee::proc_macros::rpc; +use reth_primitives::U64; +use sov_rollup_interface::rpc::{ + BatchProofResponse, LastVerifiedBatchProofResponse, SequencerCommitmentResponse, + SoftConfirmationResponse, SoftConfirmationStatus, VerifiedBatchProofResponse, +}; + #[cfg(feature = "server")] pub mod server; -#[cfg(feature = "client")] -pub mod client; - /// A 32-byte hash [`serde`]-encoded as a hex string optionally prefixed with /// `0x`. See [`sov_rollup_interface::rpc::utils::rpc_hex`]. #[derive(Debug, Copy, Clone, serde::Serialize, serde::Deserialize)] @@ -16,3 +21,123 @@ impl From<[u8; 32]> for HexHash { Self(v) } } + +/// A [`jsonrpsee`] trait for interacting with the ledger JSON-RPC API. +/// +/// Client and server implementations are automatically generated by +/// [`jsonrpsee`], see [`LedgerRpcClient`] and [`LedgerRpcServer`]. +/// +/// For more information about the specific methods, see the +/// [`sov_rollup_interface::rpc`] module. + +#[cfg_attr( + all(feature = "server", feature = "client"), + rpc(server, client, namespace = "ledger") +)] +#[cfg_attr( + all(feature = "server", not(feature = "client")), + rpc(server, namespace = "ledger") +)] +#[cfg_attr( + all(not(feature = "server"), feature = "client"), + rpc(client, namespace = "ledger") +)] +pub trait LedgerRpc { + /// Gets a single soft confirmation by number. + #[method(name = "getSoftConfirmationByNumber")] + #[blocking] + fn get_soft_confirmation_by_number( + &self, + number: U64, + ) -> RpcResult>; + + /// Gets a single soft confirmation by hash. + #[method(name = "getSoftConfirmationByHash")] + #[blocking] + fn get_soft_confirmation_by_hash( + &self, + hash: HexHash, + ) -> RpcResult>; + + /// Gets all soft confirmations with numbers `range.start` to `range.end`. + #[method(name = "getSoftConfirmationRange")] + #[blocking] + fn get_soft_confirmation_range( + &self, + start: U64, + end: U64, + ) -> RpcResult>>; + + /// Gets a single event by number. + #[method(name = "getSoftConfirmationStatus")] + #[blocking] + fn get_soft_confirmation_status( + &self, + soft_confirmation_receipt: U64, + ) -> RpcResult; + + /// Gets the L2 genesis state root. + #[method(name = "getL2GenesisStateRoot")] + #[blocking] + fn get_l2_genesis_state_root(&self) -> RpcResult>>; + + /// Gets the commitments in the DA slot with the given height. + #[method(name = "getSequencerCommitmentsOnSlotByNumber")] + #[blocking] + fn get_sequencer_commitments_on_slot_by_number( + &self, + height: U64, + ) -> RpcResult>>; + + /// Gets the commitments in the DA slot with the given hash. + #[method(name = "getSequencerCommitmentsOnSlotByHash")] + #[blocking] + fn get_sequencer_commitments_on_slot_by_hash( + &self, + hash: HexHash, + ) -> RpcResult>>; + + /// Gets proof by slot height. + #[method(name = "getBatchProofsBySlotHeight")] + #[blocking] + fn get_batch_proofs_by_slot_height( + &self, + height: U64, + ) -> RpcResult>>; + + /// Gets proof by slot hash. + #[method(name = "getBatchProofsBySlotHash")] + #[blocking] + fn get_batch_proofs_by_slot_hash( + &self, + hash: HexHash, + ) -> RpcResult>>; + + /// Gets the height pf most recent committed soft confirmation. + #[method(name = "getHeadSoftConfirmation")] + #[blocking] + fn get_head_soft_confirmation(&self) -> RpcResult>; + + /// Gets the height pf most recent committed soft confirmation. + #[method(name = "getHeadSoftConfirmationHeight")] + #[blocking] + fn get_head_soft_confirmation_height(&self) -> RpcResult; + + /// Gets verified proofs by slot height + #[method(name = "getVerifiedBatchProofsBySlotHeight")] + #[blocking] + fn get_verified_batch_proofs_by_slot_height( + &self, + height: U64, + ) -> RpcResult>>; + + /// Gets last verified proog + #[method(name = "getLastVerifiedBatchProof")] + #[blocking] + fn get_last_verified_batch_proof(&self) -> RpcResult>; + + /// Get last scanned l1 height + #[method(name = "getLastScannedL1Height")] + #[blocking] + fn get_last_scanned_l1_height(&self) -> RpcResult; +} diff --git a/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/server.rs b/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/server.rs index 47c69c2ae..34b5848ee 100644 --- a/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/server.rs +++ b/crates/sovereign-sdk/full-node/sov-ledger-rpc/src/server.rs @@ -1,169 +1,170 @@ //! A JSON-RPC server implementation for any [`LedgerRpcProvider`]. +use jsonrpsee::core::RpcResult; use jsonrpsee::types::ErrorObjectOwned; use jsonrpsee::RpcModule; use reth_primitives::U64; -use serde::de::DeserializeOwned; use sov_modules_api::utils::to_jsonrpsee_error_object; -use sov_rollup_interface::rpc::LedgerRpcProvider; +use sov_rollup_interface::rpc::{ + BatchProofResponse, LastVerifiedBatchProofResponse, LedgerRpcProvider, + SequencerCommitmentResponse, SoftConfirmationResponse, SoftConfirmationStatus, + VerifiedBatchProofResponse, +}; -use crate::HexHash; +use crate::{HexHash, LedgerRpcServer}; const LEDGER_RPC_ERROR: &str = "LEDGER_RPC_ERROR"; fn to_ledger_rpc_error(err: impl ToString) -> ErrorObjectOwned { to_jsonrpsee_error_object(LEDGER_RPC_ERROR, err) } +pub struct LedgerRpcServerImpl { + ledger: T, +} + +impl LedgerRpcServerImpl { + pub fn new(ledger: T) -> Self { + Self { ledger } + } +} -/// Creates a new [`jsonrpsee::RpcModule`] that exposes all JSON-RPC methods -/// necessary to interface with the [`LedgerRpcProvider`]. -pub fn rpc_module(ledger: T) -> anyhow::Result> +impl LedgerRpcServer for LedgerRpcServerImpl where T: LedgerRpcProvider + Send + Sync + 'static, - B: serde::Serialize + DeserializeOwned + Clone + 'static, - Tx: serde::Serialize + DeserializeOwned + Clone + 'static, { - let mut rpc = RpcModule::new(ledger); - - rpc.register_blocking_method( - "ledger_getSoftConfirmationByHash", - move |params, ledger, _| { - let args: HexHash = params.one()?; - ledger - .get_soft_confirmation_by_hash::(&args.0) - .map_err(to_ledger_rpc_error) - }, - )?; - rpc.register_blocking_method( - "ledger_getSoftConfirmationByNumber", - move |params, ledger, _| { - let args: U64 = params.one()?; - - ledger - .get_soft_confirmation_by_number::(args.to()) - .map_err(to_ledger_rpc_error) - }, - )?; - rpc.register_blocking_method( - "ledger_getSoftConfirmationRange", - move |params, ledger, _| { - let args: (U64, U64) = params.parse()?; - ledger - .get_soft_confirmations_range(args.0.to(), args.1.to()) - .map_err(to_ledger_rpc_error) - }, - )?; - rpc.register_blocking_method( - "ledger_getSoftConfirmationStatus", - move |params, ledger, _| { - let args: U64 = params.one()?; - ledger - .get_soft_confirmation_status(args.to()) - .map_err(to_ledger_rpc_error) - }, - )?; - rpc.register_blocking_method("ledger_getL2GenesisStateRoot", move |_, ledger, _| { - ledger + fn get_soft_confirmation_by_number( + &self, + number: U64, + ) -> RpcResult> { + self.ledger + .get_soft_confirmation_by_number(number.to()) + .map_err(to_ledger_rpc_error) + } + + fn get_soft_confirmation_by_hash( + &self, + hash: HexHash, + ) -> RpcResult> { + self.ledger + .get_soft_confirmation_by_hash(&hash.0) + .map_err(to_ledger_rpc_error) + } + + fn get_soft_confirmation_range( + &self, + start: U64, + end: U64, + ) -> RpcResult>> { + self.ledger + .get_soft_confirmations_range(start.to(), end.to()) + .map_err(to_ledger_rpc_error) + } + + fn get_soft_confirmation_status( + &self, + soft_confirmation_receipt: U64, + ) -> RpcResult { + self.ledger + .get_soft_confirmation_status(soft_confirmation_receipt.to()) + .map_err(to_ledger_rpc_error) + } + + fn get_l2_genesis_state_root(&self) -> RpcResult>> { + self.ledger .get_l2_genesis_state_root() .map_err(to_ledger_rpc_error) - })?; - rpc.register_blocking_method("ledger_getLastScannedL1Height", move |_, ledger, _| { - ledger + } + + fn get_last_scanned_l1_height(&self) -> RpcResult { + self.ledger .get_last_scanned_l1_height() .map_err(to_ledger_rpc_error) - })?; - - rpc.register_blocking_method( - "ledger_getSequencerCommitmentsOnSlotByNumber", - move |params, ledger, _| { - // Returns commitments on DA slot with given height. - let height: U64 = params.one()?; - - ledger - .get_sequencer_commitments_on_slot_by_number(height.to()) - .map_err(to_ledger_rpc_error) - }, - )?; - - rpc.register_blocking_method( - "ledger_getSequencerCommitmentsOnSlotByHash", - move |params, ledger, _| { - // Returns commitments on DA slot with given hash. - let hash: HexHash = params.one()?; - let Some(height) = ledger - .get_slot_number_by_hash(hash.0) - .map_err(to_ledger_rpc_error)? - else { - return Ok(None); - }; - - ledger - .get_sequencer_commitments_on_slot_by_number(height) - .map_err(to_ledger_rpc_error) - }, - )?; - - rpc.register_blocking_method( - "ledger_getBatchProofsBySlotHeight", - move |params, ledger, _| { - // Returns proof on DA slot with given height - let height: U64 = params.one()?; - ledger - .get_batch_proof_data_by_l1_height(height.to()) - .map_err(to_ledger_rpc_error) - }, - )?; - - rpc.register_blocking_method( - "ledger_getBatchProofsBySlotHash", - move |params, ledger, _| { - // Returns proof on DA slot with given height - let hash: HexHash = params.one()?; - let Some(height) = ledger - .get_slot_number_by_hash(hash.0) - .map_err(to_ledger_rpc_error)? - else { - return Ok(None); - }; - - ledger - .get_batch_proof_data_by_l1_height(height) - .map_err(to_ledger_rpc_error) - }, - )?; - - rpc.register_blocking_method( - "ledger_getVerifiedBatchProofsBySlotHeight", - move |params, ledger, _| { - // Returns proof on DA slot with given height - let height: U64 = params.one()?; - ledger - .get_verified_proof_data_by_l1_height(height.to()) - .map_err(to_ledger_rpc_error) - }, - )?; - - rpc.register_blocking_method("ledger_getLastVerifiedBatchProof", move |_, ledger, _| { - // Returns latest proof data - ledger + } + + fn get_sequencer_commitments_on_slot_by_number( + &self, + height: U64, + ) -> RpcResult>> { + self.ledger + .get_sequencer_commitments_on_slot_by_number(height.to()) + .map_err(to_ledger_rpc_error) + } + + fn get_sequencer_commitments_on_slot_by_hash( + &self, + hash: HexHash, + ) -> RpcResult>> { + let Some(height) = self + .ledger + .get_slot_number_by_hash(hash.0) + .map_err(to_ledger_rpc_error)? + else { + return Ok(None); + }; + + self.ledger + .get_sequencer_commitments_on_slot_by_number(height) + .map_err(to_ledger_rpc_error) + } + + fn get_batch_proofs_by_slot_height( + &self, + height: U64, + ) -> RpcResult>> { + self.ledger + .get_batch_proof_data_by_l1_height(height.to()) + .map_err(to_ledger_rpc_error) + } + + fn get_batch_proofs_by_slot_hash( + &self, + hash: HexHash, + ) -> RpcResult>> { + let Some(height) = self + .ledger + .get_slot_number_by_hash(hash.0) + .map_err(to_ledger_rpc_error)? + else { + return Ok(None); + }; + + self.ledger + .get_batch_proof_data_by_l1_height(height) + .map_err(to_ledger_rpc_error) + } + + fn get_verified_batch_proofs_by_slot_height( + &self, + height: U64, + ) -> RpcResult>> { + self.ledger + .get_verified_proof_data_by_l1_height(height.to()) + .map_err(to_ledger_rpc_error) + } + + fn get_last_verified_batch_proof(&self) -> RpcResult> { + self.ledger .get_last_verified_batch_proof() .map_err(to_ledger_rpc_error) - })?; + } - rpc.register_blocking_method("ledger_getHeadSoftConfirmation", move |_, ledger, _| { - ledger + fn get_head_soft_confirmation(&self) -> RpcResult> { + self.ledger .get_head_soft_confirmation() .map_err(to_ledger_rpc_error) - })?; - - rpc.register_blocking_method( - "ledger_getHeadSoftConfirmationHeight", - move |_, ledger, _| { - ledger - .get_head_soft_confirmation_height() - .map_err(to_ledger_rpc_error) - }, - )?; - - Ok(rpc) + } + + fn get_head_soft_confirmation_height(&self) -> RpcResult { + self.ledger + .get_head_soft_confirmation_height() + .map_err(to_ledger_rpc_error) + } +} + +pub fn create_rpc_module(ledger: T) -> RpcModule> +where + T: LedgerRpcProvider + Send + Sync + 'static, +{ + let server = LedgerRpcServerImpl::new(ledger); + LedgerRpcServer::into_rpc(server) } diff --git a/crates/sovereign-sdk/full-node/sov-ledger-rpc/tests/empty_ledger.rs b/crates/sovereign-sdk/full-node/sov-ledger-rpc/tests/empty_ledger.rs index 7dfe4f051..35e016067 100644 --- a/crates/sovereign-sdk/full-node/sov-ledger-rpc/tests/empty_ledger.rs +++ b/crates/sovereign-sdk/full-node/sov-ledger-rpc/tests/empty_ledger.rs @@ -4,15 +4,14 @@ use std::sync::Arc; use reth_primitives::U64; use sov_db::ledger_db::LedgerDB; use sov_db::rocks_db_config::RocksdbConfig; -use sov_ledger_rpc::client::RpcClient; -use sov_ledger_rpc::server::rpc_module; -use sov_ledger_rpc::HexHash; +use sov_ledger_rpc::server::create_rpc_module; +use sov_ledger_rpc::{HexHash, LedgerRpcClient}; use tempfile::tempdir; async fn rpc_server() -> (jsonrpsee::server::ServerHandle, SocketAddr) { let dir = tempdir().unwrap(); let db = LedgerDB::with_config(&RocksdbConfig::new(dir.path(), None, None)).unwrap(); - let rpc_module = rpc_module::(db).unwrap(); + let rpc_module = create_rpc_module::(db); let server = jsonrpsee::server::ServerBuilder::default() .build("127.0.0.1:0") @@ -22,7 +21,7 @@ async fn rpc_server() -> (jsonrpsee::server::ServerHandle, SocketAddr) { (server.start(rpc_module), addr) } -async fn rpc_client(addr: SocketAddr) -> Arc { +async fn rpc_client(addr: SocketAddr) -> Arc { Arc::new( jsonrpsee::ws_client::WsClientBuilder::new() .build(format!("ws://{}", addr)) diff --git a/crates/sovereign-sdk/module-system/sov-modules-rollup-blueprint/src/runtime_rpc.rs b/crates/sovereign-sdk/module-system/sov-modules-rollup-blueprint/src/runtime_rpc.rs index 3be0f98ca..08e80acd3 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-rollup-blueprint/src/runtime_rpc.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-rollup-blueprint/src/runtime_rpc.rs @@ -1,6 +1,6 @@ use sov_db::ledger_db::LedgerDB; use sov_modules_api::{Context, Spec}; -use sov_modules_stf_blueprint::{Runtime as RuntimeTrait, SequencerOutcome, TxEffect}; +use sov_modules_stf_blueprint::Runtime as RuntimeTrait; use sov_prover_storage_manager::{ProverStorage, SnapshotManager}; use sov_rollup_interface::services::da::DaService; @@ -21,11 +21,9 @@ where // ledger rpc. { - rpc_methods.merge(sov_ledger_rpc::server::rpc_module::< - LedgerDB, - SequencerOutcome<::Address>, - TxEffect, - >(ledger_db.clone())?)?; + rpc_methods.merge(sov_ledger_rpc::server::create_rpc_module::( + ledger_db.clone(), + ))?; } Ok(rpc_methods) diff --git a/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs b/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs index 719c49192..e45b4e52f 100644 --- a/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs +++ b/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs @@ -9,8 +9,6 @@ use alloc::vec::Vec; use core::marker::PhantomData; use borsh::{BorshDeserialize, BorshSerialize}; -#[cfg(feature = "native")] -use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use crate::da::SequencerCommitment; @@ -453,13 +451,13 @@ pub trait LedgerRpcProvider { ) -> Result, anyhow::Error>; /// Get a single soft confirmation by hash. - fn get_soft_confirmation_by_hash( + fn get_soft_confirmation_by_hash( &self, hash: &[u8; 32], ) -> Result, anyhow::Error>; /// Get a single soft confirmation by number. - fn get_soft_confirmation_by_number( + fn get_soft_confirmation_by_number( &self, number: u64, ) -> Result, anyhow::Error>; From ce45b3adcc44a11bd37f4636a47605b610833689 Mon Sep 17 00:00:00 2001 From: Esad Yusuf Atik Date: Thu, 12 Dec 2024 15:49:41 +0300 Subject: [PATCH 02/10] remove sov events (#1601) --- Cargo.lock | 2 - bin/citrea/Cargo.toml | 2 +- crates/evm/src/lib.rs | 2 - .../src/lib.rs | 2 - .../full-node/db/sov-db/src/ledger_db/mod.rs | 2 +- .../db/sov-db/src/ledger_db/traits.rs | 2 +- .../full-node/db/sov-db/src/schema/tables.rs | 4 - .../full-node/db/sov-db/src/schema/types.rs | 28 +-- .../db/sov-schema-db/tests/snapshot_test.rs | 2 +- .../src/nested_modules/helpers.rs | 9 - .../src/nested_modules/tests.rs | 12 +- .../sov-accounts/src/lib.rs | 2 - .../module-system/sov-modules-api/src/lib.rs | 2 +- .../sov-modules-api/src/reexport_macros.rs | 1 - .../sov-modules-core/src/module/mod.rs | 3 - .../src/storage/scratchpad.rs | 21 --- .../tests/cli_wallet_arg/derive_wallet.rs | 2 - .../tests/dispatch/modules.rs | 15 -- .../module_info/field_missing_attribute.rs | 2 - .../tests/module_info/mod_and_state.rs | 4 - .../tests/rpc/expose_rpc.rs | 1 - .../expose_rpc_associated_type_not_static.rs | 1 - ...pose_rpc_associated_type_not_static.stderr | 6 +- .../tests/rpc/expose_rpc_associated_types.rs | 1 - .../rpc/expose_rpc_associated_types_nested.rs | 1 - .../expose_rpc_first_generic_not_context.rs | 1 - ...xpose_rpc_first_generic_not_context.stderr | 178 +++++++++--------- .../sovereign-sdk/rollup-interface/Cargo.toml | 6 - .../rollup-interface/src/node/rpc/mod.rs | 106 ----------- .../rollup-interface/src/state_machine/stf.rs | 64 ------- guests/risc0/batch-proof-bitcoin/Cargo.lock | 1 - guests/risc0/batch-proof-mock/Cargo.lock | 1 - .../light-client-proof-bitcoin/Cargo.lock | 1 - .../risc0/light-client-proof-mock/Cargo.lock | 1 - 34 files changed, 99 insertions(+), 389 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 703b3ad13..cd1e76c14 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7626,8 +7626,6 @@ dependencies = [ "digest 0.10.7", "futures", "hex", - "proptest", - "proptest-derive", "serde", "serde_json", "thiserror", diff --git a/bin/citrea/Cargo.toml b/bin/citrea/Cargo.toml index 596dafb36..1a4a4d582 100644 --- a/bin/citrea/Cargo.toml +++ b/bin/citrea/Cargo.toml @@ -69,7 +69,7 @@ citrea-evm = { path = "../../crates/evm", features = ["native"] } citrea-primitives = { path = "../../crates/primitives", features = ["testing"] } sov-mock-da = { path = "../../crates/sovereign-sdk/adapters/mock-da", default-features = false } sov-prover-storage-manager = { path = "../../crates/sovereign-sdk/full-node/sov-prover-storage-manager", features = ["test-utils"] } -sov-rollup-interface = { path = "../../crates/sovereign-sdk/rollup-interface", features = ["fuzzing", "testing"] } +sov-rollup-interface = { path = "../../crates/sovereign-sdk/rollup-interface", features = ["testing"] } alloy = { workspace = true, features = ["hyper", "consensus", "rpc-types-eth", "provider-http", "signers", "signer-local"] } alloy-rlp = { workspace = true } diff --git a/crates/evm/src/lib.rs b/crates/evm/src/lib.rs index 8985fa1ee..5f96d36a0 100644 --- a/crates/evm/src/lib.rs +++ b/crates/evm/src/lib.rs @@ -166,8 +166,6 @@ impl sov_modules_api::Module for Evm { type CallMessage = call::CallMessage; - type Event = (); - fn genesis(&self, config: &Self::Config, working_set: &mut WorkingSet) { self.init_module(config, working_set) } diff --git a/crates/soft-confirmation-rule-enforcer/src/lib.rs b/crates/soft-confirmation-rule-enforcer/src/lib.rs index 00c1b8e4e..46b1c0864 100644 --- a/crates/soft-confirmation-rule-enforcer/src/lib.rs +++ b/crates/soft-confirmation-rule-enforcer/src/lib.rs @@ -53,8 +53,6 @@ impl sov_modules_api::Module for SoftConfirmationRuleEnf type CallMessage = CallMessage; - type Event = (); - fn call( &mut self, message: Self::CallMessage, diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs index 7bc2e247e..74580b9f0 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs @@ -253,7 +253,7 @@ impl SharedLedgerOps for LedgerDB { Ok(()) } - /// Get the next slot, block, transaction, and event numbers + /// Get the next slot, block, transaction numbers #[instrument(level = "trace", skip(self), ret)] fn get_next_items_numbers(&self) -> ItemNumbers { self.next_item_numbers.lock().unwrap().clone() diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/traits.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/traits.rs index bda51ed88..ad83287f5 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/traits.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/traits.rs @@ -42,7 +42,7 @@ pub trait SharedLedgerOps { l2_height: BatchNumber, ) -> Result<()>; - /// Get the next slot, block, transaction, and event numbers + /// Get the next slot, block, transaction numbers fn get_next_items_numbers(&self) -> ItemNumbers; /// Gets all slots with numbers `range.start` to `range.end`. If `range.end` is outside diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/schema/tables.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/schema/tables.rs index 42b31a354..e19f4bfe5 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/schema/tables.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/schema/tables.rs @@ -13,10 +13,6 @@ //! - `TxNumber -> (TxHash,Tx)` //! - `TxHash -> TxNumber` //! -//! Event Tables: -//! - `(EventKey, TxNumber) -> EventNumber` -//! - `EventNumber -> (EventKey, EventValue)` -//! //! JMT Tables: //! - `KeyHash -> Key` //! - `(Key, Version) -> JmtValue` diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs index 4c929f281..0c6951d45 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs @@ -4,14 +4,11 @@ use std::sync::Arc; use borsh::{BorshDeserialize, BorshSerialize}; use serde::de::DeserializeOwned; -use serde::{Deserialize, Serialize}; use sov_rollup_interface::rpc::{ BatchProofOutputRpcResponse, BatchProofResponse, HexTx, LightClientProofOutputRpcResponse, - LightClientProofResponse, SoftConfirmationResponse, TxIdentifier, TxResponse, - VerifiedBatchProofResponse, + LightClientProofResponse, SoftConfirmationResponse, TxResponse, VerifiedBatchProofResponse, }; use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; -use sov_rollup_interface::stf::EventKey; use sov_rollup_interface::zk::{BatchProofInfo, CumulativeStateDiff, Proof}; /// A cheaply cloneable bytes abstraction for use within the trust boundary of the node @@ -359,29 +356,6 @@ impl TryFrom for TxResponse { } } -/// An identifier that specifies a single event -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub enum EventIdentifier { - /// A unique identifier for an event consisting of a [`TxIdentifier`] and an offset into that transaction's event list - TxIdAndIndex((TxIdentifier, u64)), - /// A unique identifier for an event consisting of a [`TxIdentifier`] and an event key - TxIdAndKey((TxIdentifier, EventKey)), - /// The monotonically increasing number of the event, ordered by the DA layer For example, if the first tx - /// contains 7 events, tx 2 contains 11 events, and tx 3 contains 7 txs, - /// the last event in tx 3 would have number 25. The counter never resets. - Number(EventNumber), -} - -/// An identifier for a group of related events -#[derive(Debug, PartialEq, Serialize, Deserialize)] -pub enum EventGroupIdentifier { - /// All of the events which occurred in a particular transaction - TxId(TxIdentifier), - /// All events which a particular key - /// (typically, these events will have been emitted by several different transactions) - Key(Vec), -} - macro_rules! u64_wrapper { ($name:ident) => { /// A typed wrapper around u64 implementing `Encode` and `Decode` diff --git a/crates/sovereign-sdk/full-node/db/sov-schema-db/tests/snapshot_test.rs b/crates/sovereign-sdk/full-node/db/sov-schema-db/tests/snapshot_test.rs index c656dde66..19c74d81b 100644 --- a/crates/sovereign-sdk/full-node/db/sov-schema-db/tests/snapshot_test.rs +++ b/crates/sovereign-sdk/full-node/db/sov-schema-db/tests/snapshot_test.rs @@ -43,7 +43,7 @@ fn snapshot_lifecycle() { manager.add_snapshot(snapshot_2.into()); } - // Snapshot 3: gets empty result, event value is in some previous snapshots + // Snapshot 3: gets empty result value is in some previous snapshots let snapshot_3 = DbSnapshot::new(2, ReadOnlyLock::new(manager.clone())); assert_eq!(None, snapshot_3.read::(&key).unwrap()); } diff --git a/crates/sovereign-sdk/module-system/module-implementations/integration-tests/src/nested_modules/helpers.rs b/crates/sovereign-sdk/module-system/module-implementations/integration-tests/src/nested_modules/helpers.rs index 18961b323..b308bb80f 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/integration-tests/src/nested_modules/helpers.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/integration-tests/src/nested_modules/helpers.rs @@ -24,8 +24,6 @@ pub mod module_a { type CallMessage = (); - type Event = (); - fn call( &mut self, _message: Self::CallMessage, @@ -39,7 +37,6 @@ pub mod module_a { impl ModuleA { pub fn update(&mut self, key: &str, value: &str, working_set: &mut WorkingSet) { - working_set.add_event("module A", "update"); self.state_1_a .set(&key.to_owned(), &value.to_owned(), working_set); self.state_2_a.set(&value.to_owned(), working_set) @@ -71,8 +68,6 @@ pub mod module_b { type CallMessage = (); - type Event = (); - fn call( &mut self, _message: Self::CallMessage, @@ -86,7 +81,6 @@ pub mod module_b { impl ModuleB { pub fn update(&mut self, key: &str, value: &str, working_set: &mut WorkingSet) { - working_set.add_event("module B", "update"); self.state_1_b .set(&key.to_owned(), &value.to_owned(), working_set); self.mod_1_a.update("key_from_b", value, working_set); @@ -118,8 +112,6 @@ pub(crate) mod module_c { type CallMessage = (); - type Event = (); - fn call( &mut self, _message: Self::CallMessage, @@ -138,7 +130,6 @@ pub(crate) mod module_c { value: &str, working_set: &mut WorkingSet, ) { - working_set.add_event("module C", "execute"); self.mod_1_a.update(key, value, working_set); self.mod_1_b.update(key, value, working_set); self.mod_1_a.update(key, value, working_set); diff --git a/crates/sovereign-sdk/module-system/module-implementations/integration-tests/src/nested_modules/tests.rs b/crates/sovereign-sdk/module-system/module-implementations/integration-tests/src/nested_modules/tests.rs index 55f87aa47..6b38e22c6 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/integration-tests/src/nested_modules/tests.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/integration-tests/src/nested_modules/tests.rs @@ -1,6 +1,6 @@ use sov_modules_api::default_context::{DefaultContext, ZkDefaultContext}; use sov_modules_api::prelude::*; -use sov_modules_api::{Context, Event, ModulePrefix, StateMap, WorkingSet}; +use sov_modules_api::{Context, ModulePrefix, StateMap, WorkingSet}; use sov_prover_storage_manager::new_orphan_storage; use sov_state::{Storage, ZkStorage}; @@ -17,16 +17,6 @@ fn nested_module_call_test() { execute_module_logic::(&mut working_set); test_state_update::(&mut working_set); } - assert_eq!( - working_set.events(), - &vec![ - Event::new("module C", "execute"), - Event::new("module A", "update"), - Event::new("module B", "update"), - Event::new("module A", "update"), - Event::new("module A", "update"), - ] - ); let (log, mut witness) = working_set.checkpoint().freeze(); prover_storage diff --git a/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/src/lib.rs b/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/src/lib.rs index 9ace97977..883a6bd9f 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/src/lib.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/src/lib.rs @@ -55,8 +55,6 @@ impl sov_modules_api::Module for Accounts { type CallMessage = (); - type Event = (); - fn genesis(&self, config: &Self::Config, working_set: &mut WorkingSet) { self.init_module(config, working_set) } diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs index b74142064..f4f2207c2 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/lib.rs @@ -195,7 +195,7 @@ pub use sov_rollup_interface::services::da::SlotData; pub use sov_rollup_interface::soft_confirmation::{ SignedSoftConfirmation, UnsignedSoftConfirmation, UnsignedSoftConfirmationV1, }; -pub use sov_rollup_interface::stf::{Event, StateDiff}; +pub use sov_rollup_interface::stf::StateDiff; pub use sov_rollup_interface::zk::{BatchProofCircuitOutput, Zkvm}; pub use sov_rollup_interface::{digest, BasicAddress, RollupAddress}; diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/reexport_macros.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/reexport_macros.rs index fb9b20f7f..a72a43077 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/reexport_macros.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/reexport_macros.rs @@ -35,7 +35,6 @@ pub use sov_modules_macros::MessageCodec; /// type Context = C; /// type Config = PhantomData; /// type CallMessage = (); -/// type Event = (); /// /// fn call( /// &mut self, diff --git a/crates/sovereign-sdk/module-system/sov-modules-core/src/module/mod.rs b/crates/sovereign-sdk/module-system/sov-modules-core/src/module/mod.rs index 1898e1893..5e22337b8 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-core/src/module/mod.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-core/src/module/mod.rs @@ -32,9 +32,6 @@ pub trait Module { /// Module defined argument to the call method. type CallMessage: Debug + BorshSerialize + BorshDeserialize; - /// Module defined event resulting from a call method. - type Event: Debug + BorshSerialize + BorshDeserialize; - /// Genesis is called when a rollup is deployed and can be used to set initial state values in the module. /// Genesis functions can't return error, they must panic fn genesis( diff --git a/crates/sovereign-sdk/module-system/sov-modules-core/src/storage/scratchpad.rs b/crates/sovereign-sdk/module-system/sov-modules-core/src/storage/scratchpad.rs index 9cad8e18e..486fab408 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-core/src/storage/scratchpad.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-core/src/storage/scratchpad.rs @@ -1,11 +1,8 @@ //! Runtime state machine definitions. use alloc::collections::BTreeMap; -use alloc::vec::Vec; use core::{fmt, mem}; -use sov_rollup_interface::stf::Event; - use self::archival_state::ArchivalOffchainWorkingSet; use crate::archival_state::{ArchivalAccessoryWorkingSet, ArchivalJmtWorkingSet}; use crate::common::Prefix; @@ -378,7 +375,6 @@ impl StateCheckpoint { delta: RevertableWriter::new(self.delta, None), offchain_delta: RevertableWriter::new(self.offchain_delta, None), accessory_delta: RevertableWriter::new(self.accessory_delta, None), - events: Default::default(), archival_working_set: None, archival_accessory_working_set: None, archival_offchain_working_set: None, @@ -423,7 +419,6 @@ pub struct WorkingSet { delta: RevertableWriter>, accessory_delta: RevertableWriter>, offchain_delta: RevertableWriter>, - events: Vec, archival_working_set: Option>, archival_offchain_working_set: Option>, archival_accessory_working_set: Option>, @@ -503,22 +498,6 @@ impl WorkingSet { } } - /// Adds an event to the working set. - pub fn add_event(&mut self, key: &str, value: &str) { - self.events.push(Event::new(key, value)); - } - - /// Extracts all events from this working set. - pub fn take_events(&mut self) -> Vec { - mem::take(&mut self.events) - } - - /// Returns an immutable slice of all events that have been previously - /// written to this working set. - pub fn events(&self) -> &[Event] { - &self.events - } - /// Fetches given value and provides a proof of it presence/absence. pub fn get_with_proof(&mut self, key: StorageKey) -> StorageProof<::Proof> where diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/cli_wallet_arg/derive_wallet.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/cli_wallet_arg/derive_wallet.rs index bbb47c4ee..f113f1225 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/cli_wallet_arg/derive_wallet.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/cli_wallet_arg/derive_wallet.rs @@ -37,7 +37,6 @@ pub mod first_test_module { type Context = C; type Config = (); type CallMessage = MyStruct; - type Event = (); fn genesis(&self, _config: &Self::Config, _working_set: &mut WorkingSet) {} @@ -82,7 +81,6 @@ pub mod second_test_module { type Context = Ctx; type Config = (); type CallMessage = MyEnum; - type Event = (); fn genesis(&self, _config: &Self::Config, _working_set: &mut WorkingSet) {} diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/modules.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/modules.rs index ea26404d9..d9d7ceaad 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/modules.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/dispatch/modules.rs @@ -22,18 +22,10 @@ pub mod first_test_module { } } - #[derive(borsh::BorshDeserialize, borsh::BorshSerialize, Debug, PartialEq)] - pub enum Event { - FirstModuleEnum1(u64), - FirstModuleEnum2, - FirstModuleEnum3(Vec), - } - impl Module for FirstTestStruct { type Context = C; type Config = (); type CallMessage = u8; - type Event = Event; fn genesis(&self, _config: &Self::Config, working_set: &mut WorkingSet) { self.state_in_first_struct.set(&1, working_set); @@ -69,16 +61,10 @@ pub mod second_test_module { } } - #[derive(borsh::BorshDeserialize, borsh::BorshSerialize, Debug, PartialEq)] - pub enum Event { - SecondModuleEnum, - } - impl Module for SecondTestStruct { type Context = Ctx; type Config = (); type CallMessage = u8; - type Event = Event; fn genesis(&self, _config: &Self::Config, working_set: &mut WorkingSet) { self.state_in_second_struct.set(&2, working_set); @@ -130,7 +116,6 @@ pub mod third_test_module { type Context = Ctx; type Config = (); type CallMessage = OtherGeneric; - type Event = (); fn genesis(&self, _config: &Self::Config, working_set: &mut WorkingSet) { self.state_in_third_struct diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/module_info/field_missing_attribute.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/module_info/field_missing_attribute.rs index c81083cc1..591999571 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/module_info/field_missing_attribute.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/module_info/field_missing_attribute.rs @@ -18,8 +18,6 @@ impl Module for TestStruct { type CallMessage = (); - type Event = (); - fn call( &mut self, _message: Self::CallMessage, diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/module_info/mod_and_state.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/module_info/mod_and_state.rs index 6743d1b78..3a0f95467 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/module_info/mod_and_state.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/module_info/mod_and_state.rs @@ -26,8 +26,6 @@ pub mod first_test_module { type CallMessage = (); - type Event = (); - fn call( &mut self, _message: Self::CallMessage, @@ -64,8 +62,6 @@ mod second_test_module { type CallMessage = (); - type Event = (); - fn call( &mut self, _message: Self::CallMessage, diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc.rs index 973e362bc..e8d956983 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc.rs @@ -20,7 +20,6 @@ impl Module for QueryModule { type Context = C; type Config = u8; type CallMessage = u8; - type Event = (); fn genesis(&self, config: &Self::Config, working_set: &mut WorkingSet) { self.data.set(config, working_set); diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_type_not_static.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_type_not_static.rs index fd5287589..09bdd925c 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_type_not_static.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_type_not_static.rs @@ -48,7 +48,6 @@ pub mod my_module { type Context = C; type Config = D; type CallMessage = D; - type Event = (); fn genesis(&self, config: &Self::Config, working_set: &mut WorkingSet) { self.data.set(config, working_set); diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_type_not_static.stderr b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_type_not_static.stderr index 05588b3db..47d5ac3ad 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_type_not_static.stderr +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_type_not_static.stderr @@ -1,7 +1,7 @@ error[E0310]: the parameter type `S` may not live long enough - --> tests/rpc/expose_rpc_associated_type_not_static.rs:97:1 + --> tests/rpc/expose_rpc_associated_type_not_static.rs:96:1 | -97 | #[expose_rpc] +96 | #[expose_rpc] | ^^^^^^^^^^^^^ | | | the parameter type `S` must be valid for the static lifetime... @@ -10,5 +10,5 @@ error[E0310]: the parameter type `S` may not live long enough = note: this error originates in the attribute macro `expose_rpc` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider adding an explicit lifetime bound | -100| struct Runtime { +99 | struct Runtime { | +++++++++ diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types.rs index 3120a3aee..aa9568093 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types.rs @@ -48,7 +48,6 @@ pub mod my_module { type Context = C; type Config = D; type CallMessage = D; - type Event = (); fn genesis(&self, config: &Self::Config, working_set: &mut WorkingSet) { self.data.set(config, working_set); diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types_nested.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types_nested.rs index caa40f4d5..b37798ed2 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types_nested.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_associated_types_nested.rs @@ -53,7 +53,6 @@ pub mod my_module { type Context = C; type Config = D; type CallMessage = D; - type Event = (); fn genesis(&self, config: &Self::Config, working_set: &mut WorkingSet) { self.data.set(config, working_set); diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.rs b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.rs index 635da8c9e..eb5d6957c 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.rs @@ -45,7 +45,6 @@ pub mod my_module { type Context = C; type Config = D; type CallMessage = D; - type Event = (); fn genesis(&self, config: &Self::Config, working_set: &mut WorkingSet) { self.data.set(config, working_set); diff --git a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.stderr b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.stderr index aea84ba5b..b58f0302c 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.stderr +++ b/crates/sovereign-sdk/module-system/sov-modules-macros/tests/rpc/expose_rpc_first_generic_not_context.stderr @@ -1,15 +1,15 @@ error[E0220]: associated type `Storage` not found for `S` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:94:1 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:93:1 | -94 | #[expose_rpc] +93 | #[expose_rpc] | ^^^^^^^^^^^^^ associated type `Storage` not found | = note: this error originates in the attribute macro `expose_rpc` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `S: sov_modules_api::Context` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:16 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:16 | -97 | struct Runtime { +96 | struct Runtime { | ^ the trait `sov_modules_api::Context` is not implemented for `S` | note: required by a bound in `sov_modules_api::Genesis::Context` @@ -19,25 +19,25 @@ note: required by a bound in `sov_modules_api::Genesis::Context` | ^^^^^^^ required by this bound in `Genesis::Context` help: consider further restricting this bound | -97 | struct Runtime { +96 | struct Runtime { | ++++++++++++++++++++++++++ error[E0277]: the trait bound `S: Spec` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:95:10 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:94:10 | -95 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] +94 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] | ^^^^^^^ the trait `Spec` is not implemented for `S` | = note: this error originates in the derive macro `Genesis` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting this bound | -97 | struct Runtime { +96 | struct Runtime { | +++++++++++++++++++++++ error[E0277]: `::Data` cannot be shared between threads safely - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:8 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:8 | -97 | struct Runtime { +96 | struct Runtime { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `::Data` cannot be shared between threads safely | = help: within `Runtime`, the trait `std::marker::Sync` is not implemented for `::Data`, which is required by `Runtime: std::marker::Sync` @@ -57,9 +57,9 @@ note: required because it appears within the type `QueryModule { | ^^^^^^^^^^^ note: required because it appears within the type `Runtime` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:8 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:8 | -97 | struct Runtime { +96 | struct Runtime { | ^^^^^^^ note: required by a bound in `sov_modules_api::DispatchCall` --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs @@ -68,13 +68,13 @@ note: required by a bound in `sov_modules_api::DispatchCall` | ^^^^ required by this bound in `DispatchCall` help: consider further restricting the associated type | -97 | struct Runtime where ::Data: std::marker::Sync { +96 | struct Runtime where ::Data: std::marker::Sync { | ++++++++++++++++++++++++++++++++++++++++++++++ error[E0277]: `::Data` cannot be sent between threads safely - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:8 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:8 | -97 | struct Runtime { +96 | struct Runtime { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `::Data` cannot be sent between threads safely | = help: within `Runtime`, the trait `Send` is not implemented for `::Data`, which is required by `Runtime: Send` @@ -94,9 +94,9 @@ note: required because it appears within the type `QueryModule { | ^^^^^^^^^^^ note: required because it appears within the type `Runtime` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:8 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:8 | -97 | struct Runtime { +96 | struct Runtime { | ^^^^^^^ note: required by a bound in `sov_modules_api::DispatchCall` --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs @@ -105,13 +105,13 @@ note: required by a bound in `sov_modules_api::DispatchCall` | ^^^^ required by this bound in `DispatchCall` help: consider further restricting the associated type | -97 | struct Runtime where ::Data: Send { +96 | struct Runtime where ::Data: Send { | +++++++++++++++++++++++++++++++++ error[E0277]: the trait bound `S: sov_modules_api::Context` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:16 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:16 | -97 | struct Runtime { +96 | struct Runtime { | ^ the trait `sov_modules_api::Context` is not implemented for `S` | note: required by a bound in `sov_modules_api::DispatchCall::Context` @@ -121,20 +121,20 @@ note: required by a bound in `sov_modules_api::DispatchCall::Context` | ^^^^^^^ required by this bound in `DispatchCall::Context` help: consider further restricting this bound | -97 | struct Runtime { +96 | struct Runtime { | ++++++++++++++++++++++++++ error[E0277]: `::Data` cannot be shared between threads safely - --> tests/rpc/expose_rpc_first_generic_not_context.rs:95:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:94:19 | -95 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] +94 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] | ^^^^^^^^^^^^ `::Data` cannot be shared between threads safely | = help: within `RuntimeCall`, the trait `std::marker::Sync` is not implemented for `::Data`, which is required by `RuntimeCall: std::marker::Sync` note: required because it appears within the type `RuntimeCall` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:95:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:94:19 | -95 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] +94 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] | ^^^^^^^^^^^^ note: required by a bound in `sov_modules_api::DispatchCall::Decodable` --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs @@ -144,20 +144,20 @@ note: required by a bound in `sov_modules_api::DispatchCall::Decodable` = note: this error originates in the derive macro `DispatchCall` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting the associated type | -97 | struct Runtime where ::Data: std::marker::Sync { +96 | struct Runtime where ::Data: std::marker::Sync { | ++++++++++++++++++++++++++++++++++++++++++++++ error[E0277]: `::Data` cannot be sent between threads safely - --> tests/rpc/expose_rpc_first_generic_not_context.rs:95:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:94:19 | -95 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] +94 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] | ^^^^^^^^^^^^ `::Data` cannot be sent between threads safely | = help: within `RuntimeCall`, the trait `Send` is not implemented for `::Data`, which is required by `RuntimeCall: Send` note: required because it appears within the type `RuntimeCall` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:95:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:94:19 | -95 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] +94 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] | ^^^^^^^^^^^^ note: required by a bound in `sov_modules_api::DispatchCall::Decodable` --> $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-core/src/module/dispatch.rs @@ -167,37 +167,37 @@ note: required by a bound in `sov_modules_api::DispatchCall::Decodable` = note: this error originates in the derive macro `DispatchCall` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting the associated type | -97 | struct Runtime where ::Data: Send { +96 | struct Runtime where ::Data: Send { | +++++++++++++++++++++++++++++++++ error[E0277]: the trait bound `S: Spec` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:95:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:94:19 | -95 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] +94 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] | ^^^^^^^^^^^^ the trait `Spec` is not implemented for `S` | = note: this error originates in the derive macro `DispatchCall` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting this bound | -97 | struct Runtime { +96 | struct Runtime { | +++++++++++++++++++++++ error[E0277]: the trait bound `S: Spec` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:94:1 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:93:1 | -94 | #[expose_rpc] +93 | #[expose_rpc] | ^^^^^^^^^^^^^ the trait `Spec` is not implemented for `S` | = note: this error originates in the attribute macro `expose_rpc` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting this bound | -97 | struct Runtime { +96 | struct Runtime { | +++++++++++++++++++++++ error[E0599]: no method named `set` found for struct `sov_modules_api::StateValue` in the current scope - --> tests/rpc/expose_rpc_first_generic_not_context.rs:51:23 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:50:23 | -51 | self.data.set(config, working_set); +50 | self.data.set(config, working_set); | ^^^ | ::: $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/traits/value.rs @@ -217,9 +217,9 @@ help: trait `StateValueAccessor` which provides `set` is implemented but not in | error[E0599]: no method named `set` found for struct `sov_modules_api::StateValue` in the current scope - --> tests/rpc/expose_rpc_first_generic_not_context.rs:60:23 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:59:23 | -60 | self.data.set(&msg, working_set); +59 | self.data.set(&msg, working_set); | ^^^ | ::: $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/traits/value.rs @@ -239,9 +239,9 @@ help: trait `StateValueAccessor` which provides `set` is implemented but not in | error[E0599]: no method named `get` found for struct `sov_modules_api::StateValue` in the current scope - --> tests/rpc/expose_rpc_first_generic_not_context.rs:85:39 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:84:39 | -85 | let value = self.data.get(working_set).map(|d| format!("{:?}", d)); +84 | let value = self.data.get(working_set).map(|d| format!("{:?}", d)); | ^^^ | ::: $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/traits/value.rs @@ -257,16 +257,16 @@ help: there is a method `set` with a similar name, but with different arguments | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: trait `StateValueAccessor` which provides `get` is implemented but not in scope; perhaps you want to import it | -67 + use sov_modules_api::StateValueAccessor; +66 + use sov_modules_api::StateValueAccessor; | error[E0271]: type mismatch resolving `::Data> as ModuleInfo>::Context == S` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:95:10 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:94:10 | -95 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] +94 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] | ^^^^^^^ expected type parameter `S`, found type parameter `C` -96 | #[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)] -97 | struct Runtime { +95 | #[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)] +96 | struct Runtime { | - - found type parameter | | | expected type parameter @@ -279,9 +279,9 @@ error[E0271]: type mismatch resolving `::Data> as = note: this error originates in the derive macro `Genesis` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0277]: the trait bound `S: sov_modules_api::Context` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:95:10 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:94:10 | -95 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] +94 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] | ^^^^^^^ the trait `sov_modules_api::Context` is not implemented for `S` | note: required by a bound in `sort_values_by_modules_dependencies` @@ -292,19 +292,19 @@ note: required by a bound in `sort_values_by_modules_dependencies` = note: this error originates in the derive macro `Genesis` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider further restricting this bound | -97 | struct Runtime { +96 | struct Runtime { | ++++++++++++++++++++++++++ error[E0308]: mismatched types - --> tests/rpc/expose_rpc_first_generic_not_context.rs:95:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:94:19 | -95 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] +94 | #[derive(Genesis, DispatchCall, MessageCodec, DefaultRuntime)] | ^^^^^^^^^^^^ | | | expected `&C`, found `&S` | arguments to this function are incorrect -96 | #[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)] -97 | struct Runtime { +95 | #[serialization(borsh::BorshDeserialize, borsh::BorshSerialize)] +96 | struct Runtime { | - - expected type parameter | | | found type parameter @@ -321,15 +321,15 @@ note: method defined here = note: this error originates in the derive macro `DispatchCall` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0599]: the function or associated item `default` exists for struct `Runtime`, but its trait bounds were not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:112:50 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:111:50 | -97 | struct Runtime { +96 | struct Runtime { | --------------------------------------- function or associated item `default` not found for this struct because it doesn't satisfy `_: Default` ... -101 | struct ActualSpec; +100 | struct ActualSpec; | ----------------- doesn't satisfy `ActualSpec: sov_modules_api::Context` ... -112 | let runtime = &mut Runtime::::default(); +111 | let runtime = &mut Runtime::::default(); | ^^^^^^^ function or associated item cannot be called on `Runtime` due to unsatisfied trait bounds | ::: $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-api/src/default_context.rs @@ -350,79 +350,79 @@ note: the trait `sov_modules_api::Context` must be implemented candidate #1: `std::default::Default` error[E0277]: the trait bound `ZkDefaultContext: TestSpec` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:112:24 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:111:24 | -112 | let runtime = &mut Runtime::::default(); +111 | let runtime = &mut Runtime::::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `TestSpec` is not implemented for `ZkDefaultContext` | = help: the trait `TestSpec` is implemented for `ActualSpec` note: required by a bound in `Runtime` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:19 | -97 | struct Runtime { +96 | struct Runtime { | ^^^^^^^^ required by this bound in `Runtime` error[E0277]: the trait bound `ActualSpec: sov_modules_api::Context` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:112:24 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:111:24 | -112 | let runtime = &mut Runtime::::default(); +111 | let runtime = &mut Runtime::::default(); | ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `sov_modules_api::Context` is not implemented for `ActualSpec` | = help: the following other types implement trait `sov_modules_api::Context`: DefaultContext ZkDefaultContext note: required by a bound in `Runtime` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:32 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:32 | -97 | struct Runtime { +96 | struct Runtime { | ^^^^^^^ required by this bound in `Runtime` error[E0277]: the trait bound `Runtime: EncodeCall>` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:118:10 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:117:10 | -118 | >>::encode_call(message); +117 | >>::encode_call(message); | ^^ the trait `EncodeCall>` is not implemented for `Runtime` | = help: the trait `EncodeCall::Data>>` is implemented for `Runtime` error[E0277]: the trait bound `ZkDefaultContext: TestSpec` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:118:10 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:117:10 | -118 | >>::encode_call(message); +117 | >>::encode_call(message); | ^^ the trait `TestSpec` is not implemented for `ZkDefaultContext` | = help: the trait `TestSpec` is implemented for `ActualSpec` note: required by a bound in `Runtime` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:19 | -97 | struct Runtime { +96 | struct Runtime { | ^^^^^^^^ required by this bound in `Runtime` error[E0277]: the trait bound `ActualSpec: sov_modules_api::Context` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:118:10 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:117:10 | -118 | >>::encode_call(message); +117 | >>::encode_call(message); | ^^ the trait `sov_modules_api::Context` is not implemented for `ActualSpec` | = help: the following other types implement trait `sov_modules_api::Context`: DefaultContext ZkDefaultContext note: required by a bound in `Runtime` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:32 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:32 | -97 | struct Runtime { +96 | struct Runtime { | ^^^^^^^ required by this bound in `Runtime` error[E0599]: the function or associated item `decode_call` exists for struct `Runtime`, but its trait bounds were not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:119:22 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:118:22 | -97 | struct Runtime { +96 | struct Runtime { | --------------------------------------- function or associated item `decode_call` not found for this struct because it doesn't satisfy `_: DispatchCall` ... -101 | struct ActualSpec; +100 | struct ActualSpec; | ----------------- doesn't satisfy `ActualSpec: sov_modules_api::Context` ... -119 | let module = RT::decode_call(&serialized_message).unwrap(); +118 | let module = RT::decode_call(&serialized_message).unwrap(); | ^^^^^^^^^^^ function or associated item cannot be called on `Runtime` due to unsatisfied trait bounds | ::: $WORKSPACE/crates/sovereign-sdk/module-system/sov-modules-api/src/default_context.rs @@ -443,29 +443,29 @@ note: the trait `sov_modules_api::Context` must be implemented candidate #1: `sov_modules_api::DispatchCall` error[E0277]: the trait bound `ZkDefaultContext: TestSpec` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:119:18 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:118:18 | -119 | let module = RT::decode_call(&serialized_message).unwrap(); +118 | let module = RT::decode_call(&serialized_message).unwrap(); | ^^ the trait `TestSpec` is not implemented for `ZkDefaultContext` | = help: the trait `TestSpec` is implemented for `ActualSpec` note: required by a bound in `Runtime` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:19 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:19 | -97 | struct Runtime { +96 | struct Runtime { | ^^^^^^^^ required by this bound in `Runtime` error[E0277]: the trait bound `ActualSpec: sov_modules_api::Context` is not satisfied - --> tests/rpc/expose_rpc_first_generic_not_context.rs:119:18 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:118:18 | -119 | let module = RT::decode_call(&serialized_message).unwrap(); +118 | let module = RT::decode_call(&serialized_message).unwrap(); | ^^ the trait `sov_modules_api::Context` is not implemented for `ActualSpec` | = help: the following other types implement trait `sov_modules_api::Context`: DefaultContext ZkDefaultContext note: required by a bound in `Runtime` - --> tests/rpc/expose_rpc_first_generic_not_context.rs:97:32 + --> tests/rpc/expose_rpc_first_generic_not_context.rs:96:32 | -97 | struct Runtime { +96 | struct Runtime { | ^^^^^^^ required by this bound in `Runtime` diff --git a/crates/sovereign-sdk/rollup-interface/Cargo.toml b/crates/sovereign-sdk/rollup-interface/Cargo.toml index f50089139..969264b24 100644 --- a/crates/sovereign-sdk/rollup-interface/Cargo.toml +++ b/crates/sovereign-sdk/rollup-interface/Cargo.toml @@ -29,17 +29,12 @@ thiserror = { workspace = true, optional = true } tokio = { workspace = true, optional = true } tracing = { workspace = true, optional = true } -# Proptest should be a dev-dependency, but those can't be optional -proptest = { workspace = true, optional = true } -proptest-derive = { workspace = true, optional = true } - [dev-dependencies] serde_json = { workspace = true } [features] default = ["std"] native = ["std", "tokio", "futures", "tracing"] -fuzzing = ["proptest", "proptest-derive", "std"] testing = ["native"] arbitrary = ["dep:arbitrary"] std = [ @@ -49,7 +44,6 @@ std = [ "bytes", "digest/default", "hex/default", - "proptest?/default", "serde/default", "thiserror", ] diff --git a/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs b/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs index e45b4e52f..0788a0d29 100644 --- a/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs +++ b/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs @@ -12,52 +12,9 @@ use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; use crate::da::SequencerCommitment; -#[cfg(feature = "native")] -use crate::stf::EventKey; use crate::zk::{BatchProofInfo, CumulativeStateDiff}; /// A struct containing enough information to uniquely specify single batch. -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct SlotIdAndOffset { - /// The [`SlotIdentifier`] of the slot containing this batch. - pub slot_id: SlotIdentifier, - /// The offset into the slot at which this tx is located. - /// Index 0 is the first batch in the slot. - pub offset: u64, -} - -/// A struct containing enough information to uniquely specify single transaction. -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct BatchIdAndOffset { - /// The [`BatchIdentifier`] of the batch containing this transaction. - pub batch_id: BatchIdentifier, - /// The offset into the batch at which this tx is located. - /// Index 0 is the first transaction in the batch. - pub offset: u64, -} - -/// A struct containing enough information to uniquely specify single event. -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct TxIdAndOffset { - /// The [`TxIdentifier`] of the transaction containing this event. - pub tx_id: TxIdentifier, - /// The offset into the tx's events at which this event is located. - /// Index 0 is the first event from this tx. - pub offset: u64, -} - -/// A struct containing enough information to uniquely specify single event. -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[serde(rename_all = "camelCase")] -pub struct TxIdAndKey { - /// The [`TxIdentifier`] of the transaction containing this event. - pub tx_id: TxIdentifier, - /// The key of the event. - pub key: EventKey, -} /// An identifier that specifies a single soft confirmation #[derive(Debug, PartialEq, Serialize, Deserialize)] @@ -69,69 +26,6 @@ pub enum SoftConfirmationIdentifier { Hash(#[serde(with = "utils::rpc_hex")] [u8; 32]), } -/// An identifier that specifies a single batch -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[serde(untagged, rename_all = "camelCase")] -pub enum BatchIdentifier { - /// The hex-encoded hash of the batch, as computed by the DA layer. - Hash(#[serde(with = "utils::rpc_hex")] [u8; 32]), - /// An offset into a particular slot (i.e. the 3rd batch in slot 5). - SlotIdAndOffset(SlotIdAndOffset), - /// The monotonically increasing number of the batch, ordered by the DA layer For example, if the genesis slot - /// contains 0 batches, slot 1 contains 2 txs, and slot 3 contains 3 txs, - /// the last batch in block 3 would have number 5. The counter never resets. - Number(u64), -} - -/// An identifier that specifies a single transaction. -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[serde(untagged, rename_all = "camelCase")] -pub enum TxIdentifier { - /// The hex encoded hash of the transaction. - Hash(#[serde(with = "utils::rpc_hex")] [u8; 32]), - /// An offset into a particular batch (i.e. the 3rd transaction in batch 5). - BatchIdAndOffset(BatchIdAndOffset), - /// The monotonically increasing number of the tx, ordered by the DA layer For example, if genesis - /// contains 0 txs, batch 1 contains 8 txs, and batch 3 contains 7 txs, - /// the last tx in batch 3 would have number 15. The counter never resets. - Number(u64), -} - -/// An identifier that specifies a single event. -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[serde(untagged, rename_all = "camelCase")] -pub enum EventIdentifier { - /// An offset into a particular transaction (i.e. the 3rd event in transaction number 5). - TxIdAndOffset(TxIdAndOffset), - /// A particular event key from a particular transaction. - TxIdAndKey(TxIdAndKey), - /// The monotonically increasing number of the event, ordered by the DA layer For example, if the first tx - /// contains 7 events, tx 2 contains 11 events, and tx 3 contains 7 txs, - /// the last event in tx 3 would have number 25. The counter never resets. - Number(u64), -} - -/// An identifier for a group of related events -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[serde(untagged, rename_all = "camelCase")] -pub enum EventGroupIdentifier { - /// Fetch all events from a particular transaction. - TxId(TxIdentifier), - /// Fetch all events (i.e. from all transactions) with a particular key. - Key(Vec), -} - -/// An identifier that specifies a single slot. -#[derive(Debug, PartialEq, Serialize, Deserialize)] -#[serde(untagged, rename_all = "camelCase")] -pub enum SlotIdentifier { - /// The hex encoded hash of the slot (i.e. the da layer's block hash). - Hash(#[serde(with = "utils::rpc_hex")] [u8; 32]), - /// The monotonically increasing number of the slot, ordered by the DA layer but starting from 0 - /// at the *rollup's* genesis. - Number(u64), -} - /// A type that represents a transaction hash bytes. #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] #[serde(transparent, rename_all = "camelCase")] diff --git a/crates/sovereign-sdk/rollup-interface/src/state_machine/stf.rs b/crates/sovereign-sdk/rollup-interface/src/state_machine/stf.rs index f4e82521e..da4d54ac3 100644 --- a/crates/sovereign-sdk/rollup-interface/src/state_machine/stf.rs +++ b/crates/sovereign-sdk/rollup-interface/src/state_machine/stf.rs @@ -409,67 +409,3 @@ impl std::fmt::Display for StateTransitionError { } } } - -/// A key-value pair representing a change to the rollup state -#[derive(Debug, Clone, PartialEq, BorshSerialize, BorshDeserialize, Serialize, Deserialize)] -#[cfg_attr(any(test, feature = "fuzzing"), derive(proptest_derive::Arbitrary))] -pub struct Event { - key: EventKey, - value: EventValue, -} - -impl Event { - /// Create a new event with the given key and value - pub fn new(key: &str, value: &str) -> Self { - Self { - key: EventKey(key.as_bytes().to_vec()), - value: EventValue(value.as_bytes().to_vec()), - } - } - - /// Get the event key - pub fn key(&self) -> &EventKey { - &self.key - } - - /// Get the event value - pub fn value(&self) -> &EventValue { - &self.value - } -} - -/// The key of an event. This is a wrapper around a `Vec`. -#[derive( - Debug, - Clone, - PartialEq, - Eq, - PartialOrd, - Ord, - Hash, - BorshSerialize, - BorshDeserialize, - Serialize, - Deserialize, -)] -#[cfg_attr(any(test, feature = "fuzzing"), derive(proptest_derive::Arbitrary))] -pub struct EventKey(Vec); - -impl EventKey { - /// Return the inner bytes of the event key. - pub fn inner(&self) -> &Vec { - &self.0 - } -} - -/// The value of an event. This is a wrapper around a `Vec`. -#[derive(Debug, Clone, PartialEq, Eq, BorshSerialize, BorshDeserialize, Serialize, Deserialize)] -#[cfg_attr(any(test, feature = "fuzzing"), derive(proptest_derive::Arbitrary))] -pub struct EventValue(Vec); - -impl EventValue { - /// Return the inner bytes of the event value. - pub fn inner(&self) -> &Vec { - &self.0 - } -} diff --git a/guests/risc0/batch-proof-bitcoin/Cargo.lock b/guests/risc0/batch-proof-bitcoin/Cargo.lock index f8d68b2e8..e37628fd4 100644 --- a/guests/risc0/batch-proof-bitcoin/Cargo.lock +++ b/guests/risc0/batch-proof-bitcoin/Cargo.lock @@ -3019,7 +3019,6 @@ dependencies = [ "bytes", "digest 0.10.7", "hex", - "proptest", "serde", "thiserror", ] diff --git a/guests/risc0/batch-proof-mock/Cargo.lock b/guests/risc0/batch-proof-mock/Cargo.lock index 70c2c408c..76445ed29 100644 --- a/guests/risc0/batch-proof-mock/Cargo.lock +++ b/guests/risc0/batch-proof-mock/Cargo.lock @@ -2821,7 +2821,6 @@ dependencies = [ "bytes", "digest 0.10.7", "hex", - "proptest", "serde", "thiserror", ] diff --git a/guests/risc0/light-client-proof-bitcoin/Cargo.lock b/guests/risc0/light-client-proof-bitcoin/Cargo.lock index e19533338..21c77740d 100644 --- a/guests/risc0/light-client-proof-bitcoin/Cargo.lock +++ b/guests/risc0/light-client-proof-bitcoin/Cargo.lock @@ -2787,7 +2787,6 @@ dependencies = [ "bytes", "digest 0.10.7", "hex", - "proptest", "serde", "thiserror", ] diff --git a/guests/risc0/light-client-proof-mock/Cargo.lock b/guests/risc0/light-client-proof-mock/Cargo.lock index 129d4335c..71590c375 100644 --- a/guests/risc0/light-client-proof-mock/Cargo.lock +++ b/guests/risc0/light-client-proof-mock/Cargo.lock @@ -2573,7 +2573,6 @@ dependencies = [ "bytes", "digest 0.10.7", "hex", - "proptest", "serde", "thiserror", ] From e282dab0097fa485a55d8322f10015710229d8d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erce=20Can=20Bekt=C3=BCre?= <47954181+ercecan@users.noreply.github.com> Date: Fri, 13 Dec 2024 09:36:55 +0300 Subject: [PATCH 03/10] Fix test_offchain_contract_storage (#1603) --- bin/citrea/tests/e2e/mod.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/bin/citrea/tests/e2e/mod.rs b/bin/citrea/tests/e2e/mod.rs index de2f3c722..c52251058 100644 --- a/bin/citrea/tests/e2e/mod.rs +++ b/bin/citrea/tests/e2e/mod.rs @@ -12,11 +12,14 @@ use std::time::Duration; use citrea_common::{BatchProverConfig, SequencerConfig}; use citrea_evm::smart_contracts::SimpleStorageContract; +use citrea_primitives::forks::FORKS; use citrea_stf::genesis_config::GenesisPaths; use reth_primitives::{Address, BlockNumberOrTag, U256}; use sov_mock_da::{MockAddress, MockDaService}; +use sov_modules_api::fork::fork_from_block_number; use sov_rollup_interface::rpc::{LastVerifiedBatchProofResponse, SoftConfirmationStatus}; use sov_rollup_interface::services::da::DaService; +use sov_rollup_interface::spec::SpecId; use tokio::task::JoinHandle; use crate::evm::{init_test_rollup, make_test_client}; @@ -643,10 +646,18 @@ async fn test_offchain_contract_storage() { assert_eq!(code.to_vec()[..runtime_code.len()], runtime_code.to_vec()); // reach the block at which the fork will be activated - for _ in 3..=100 { - sequencer_client.send_publish_batch_request().await; + for _ in 3..=10000 { + sequencer_client.spam_publish_batch_request().await.unwrap(); } + wait_for_l2_block(&sequencer_client, 10000, Some(Duration::from_secs(300))).await; + let seq_height = sequencer_client.eth_block_number().await; + + let seq_fork = fork_from_block_number(FORKS, seq_height); + + // Assert we are at fork1 + assert_eq!(seq_fork.spec_id, SpecId::Fork1); + // This should access the `code` and copy code over to `offchain_code` in EVM let code = sequencer_client .eth_get_code(contract_address, None) From 170138b3c8df1fac70c13ab41cf6e05b1e87ee56 Mon Sep 17 00:00:00 2001 From: Esad Yusuf Atik Date: Fri, 13 Dec 2024 15:18:16 +0300 Subject: [PATCH 04/10] Cleanup remove arbitrary (#1605) --- Cargo.lock | 29 ------- Cargo.toml | 2 - bin/citrea/Cargo.toml | 1 - crates/ethereum-rpc/Cargo.toml | 1 - .../full-node/db/sov-db/Cargo.toml | 10 +-- .../full-node/db/sov-db/src/ledger_db/mod.rs | 1 - .../full-node/db/sov-db/src/schema/types.rs | 52 ------------ .../full-node/db/sov-schema-db/Cargo.toml | 3 - .../full-node/db/sov-schema-db/src/lib.rs | 1 - .../db/sov-schema-db/src/schema_batch.rs | 21 ----- .../sov-accounts/Cargo.toml | 11 --- .../sov-accounts/src/fuzz.rs | 84 ------------------- .../sov-accounts/src/lib.rs | 3 - .../sov-accounts/src/query.rs | 4 - .../module-system/sov-modules-api/Cargo.toml | 12 --- .../src/containers/accessory_map.rs | 37 -------- .../sov-modules-api/src/containers/map.rs | 37 -------- .../src/containers/offchain_map.rs | 37 -------- .../sov-modules-api/src/default_context.rs | 1 - .../sov-modules-api/src/default_signature.rs | 35 -------- .../sov-modules-api/src/pub_key_hex.rs | 11 --- .../module-system/sov-modules-core/Cargo.toml | 10 --- .../sov-modules-core/src/common/address.rs | 5 -- .../sov-modules-core/src/common/bytes.rs | 35 -------- .../module-system/sov-state/Cargo.toml | 9 -- .../sovereign-sdk/rollup-interface/Cargo.toml | 2 - .../rollup-interface/src/spec.rs | 2 - 27 files changed, 1 insertion(+), 455 deletions(-) delete mode 100644 crates/sovereign-sdk/module-system/module-implementations/sov-accounts/src/fuzz.rs diff --git a/Cargo.lock b/Cargo.lock index cd1e76c14..9d3b53697 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1730,7 +1730,6 @@ dependencies = [ "lazy_static", "log", "log-panics", - "proptest", "prover-services", "regex", "reqwest", @@ -2828,7 +2827,6 @@ dependencies = [ "futures", "jsonrpsee", "parking_lot", - "proptest", "reth-primitives", "reth-rpc-eth-types", "reth-rpc-types", @@ -5071,17 +5069,6 @@ dependencies = [ "unarray", ] -[[package]] -name = "proptest-derive" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cf16337405ca084e9c78985114633b6827711d22b9e6ef6c6c0d665eb3f0b6e" -dependencies = [ - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "prost" version = "0.12.6" @@ -7385,12 +7372,9 @@ dependencies = [ name = "sov-accounts" version = "0.5.0-rc.1" dependencies = [ - "arbitrary", "borsh", "clap", "jsonrpsee", - "proptest", - "proptest-derive", "schemars", "serde", "serde_json", @@ -7406,7 +7390,6 @@ name = "sov-db" version = "0.5.0-rc.1" dependencies = [ "anyhow", - "arbitrary", "bincode", "borsh", "byteorder", @@ -7414,8 +7397,6 @@ dependencies = [ "hex", "jmt", "num_cpus", - "proptest", - "proptest-derive", "rand 0.8.5", "rlimit", "rocksdb", @@ -7482,7 +7463,6 @@ name = "sov-modules-api" version = "0.5.0-rc.1" dependencies = [ "anyhow", - "arbitrary", "bech32 0.9.1", "bincode", "borsh", @@ -7493,8 +7473,6 @@ dependencies = [ "hex", "jmt", "jsonrpsee", - "proptest", - "proptest-derive", "rand 0.8.5", "schemars", "serde", @@ -7517,7 +7495,6 @@ name = "sov-modules-core" version = "0.5.0-rc.1" dependencies = [ "anyhow", - "arbitrary", "bech32 0.9.1", "borsh", "derive_more", @@ -7525,7 +7502,6 @@ dependencies = [ "hex", "jmt", "proptest", - "proptest-derive", "schemars", "serde", "serde_json", @@ -7619,7 +7595,6 @@ name = "sov-rollup-interface" version = "0.5.0-rc.1" dependencies = [ "anyhow", - "arbitrary", "async-trait", "borsh", "bytes", @@ -7641,8 +7616,6 @@ dependencies = [ "byteorder", "once_cell", "prometheus", - "proptest", - "proptest-derive", "rocksdb", "sov-schema-db", "tempfile", @@ -7656,12 +7629,10 @@ name = "sov-state" version = "0.5.0-rc.1" dependencies = [ "anyhow", - "arbitrary", "bcs", "borsh", "jmt", "proptest", - "proptest-derive", "serde", "sha2", "sov-db", diff --git a/Cargo.toml b/Cargo.toml index 2640293eb..738ed3fdf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,7 +55,6 @@ jmt = { git = "https://github.com/penumbra-zone/jmt.git", rev = "fd1c8ef" } # External dependencies async-trait = "0.1.71" anyhow = { version = "1.0.68", default-features = false } -arbitrary = { version = "1.3.1", features = ["derive"] } backoff = { version = "0.4.0", features = ["futures", "tokio"] } borsh = { version = "1.5", default-features = false, features = ["derive"] } # TODO: Consider replacing this serialization format @@ -82,7 +81,6 @@ once_cell = { version = "1.19.0", default-features = false, features = ["alloc"] parking_lot = { version = "0.12.3" } prometheus = { version = "0.13.3", default-features = false } proptest = { version = "1.3.1", default-features = false, features = ["alloc"] } -proptest-derive = "0.4.0" rand = "0.8" rayon = "1.8.0" rlimit = "0.10.2" diff --git a/bin/citrea/Cargo.toml b/bin/citrea/Cargo.toml index 1a4a4d582..1f0f926cc 100644 --- a/bin/citrea/Cargo.toml +++ b/bin/citrea/Cargo.toml @@ -76,7 +76,6 @@ alloy-rlp = { workspace = true } bincode = { workspace = true } borsh = { workspace = true } hex = { workspace = true } -proptest = { workspace = true } reqwest = { workspace = true } rs_merkle = { workspace = true } serde_json = { workspace = true } diff --git a/crates/ethereum-rpc/Cargo.toml b/crates/ethereum-rpc/Cargo.toml index 97539e828..9704c7a8e 100644 --- a/crates/ethereum-rpc/Cargo.toml +++ b/crates/ethereum-rpc/Cargo.toml @@ -40,7 +40,6 @@ sov-modules-api = { path = "../sovereign-sdk/module-system/sov-modules-api", def sov-rollup-interface = { path = "../sovereign-sdk/rollup-interface", features = ["native"] } [dev-dependencies] -proptest = { workspace = true } tokio = { workspace = true } [features] diff --git a/crates/sovereign-sdk/full-node/db/sov-db/Cargo.toml b/crates/sovereign-sdk/full-node/db/sov-db/Cargo.toml index 176db14e4..67500409d 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/Cargo.toml +++ b/crates/sovereign-sdk/full-node/db/sov-db/Cargo.toml @@ -21,14 +21,11 @@ sov-schema-db = { path = "../sov-schema-db" } # External anyhow = { workspace = true, default-features = true } -arbitrary = { workspace = true, optional = true } bincode = { workspace = true } borsh = { workspace = true, default-features = true, features = ["bytes", "rc"] } byteorder = { workspace = true, default-features = true } hex = { workspace = true } num_cpus = { workspace = true } -proptest = { workspace = true, optional = true, default-features = true } -proptest-derive = { workspace = true, optional = true } rlimit = { workspace = true } rocksdb = { workspace = true } serde = { workspace = true, default-features = true, features = ["rc"] } @@ -42,12 +39,7 @@ rand = { workspace = true } sha2 = { workspace = true } tempfile = { workspace = true } -[features] -arbitrary = [ - "dep:arbitrary", - "dep:proptest", - "dep:proptest-derive", -] + [[bench]] name = "state_db_single_snapshot" diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs index 74580b9f0..1163a5f2b 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/mod.rs @@ -52,7 +52,6 @@ pub struct LedgerDB { /// A SlotNumber, BatchNumber, TxNumber, and EventNumber which are grouped together, typically representing /// the respective heights at the start or end of slot processing. #[derive(Default, Clone, Debug)] -#[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))] pub struct ItemNumbers { /// The slot number pub slot_number: u64, diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs index 0c6951d45..390163557 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/schema/types.rs @@ -21,7 +21,6 @@ use sov_rollup_interface::zk::{BatchProofInfo, CumulativeStateDiff, Proof}; #[derive( Clone, PartialEq, PartialOrd, Eq, Ord, Debug, Default, BorshDeserialize, BorshSerialize, )] -#[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))] pub struct DbBytes(Arc>); impl DbBytes { @@ -62,7 +61,6 @@ pub(crate) type StateKey = Vec; /// and the hash of the da block. TODO(@preston-evans98): add any additional data /// required to reconstruct the da block proof. #[derive(Debug, PartialEq, BorshDeserialize, BorshSerialize)] -#[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))] pub struct StoredSlot { /// The slot's hash, as reported by the DA layer. pub hash: DbHash, @@ -327,7 +325,6 @@ impl TryFrom for SoftConfirmationResponse { /// The on-disk format for a batch. Stores the hash and identifies the range of transactions /// included in the batch. #[derive(Debug, PartialEq, BorshDeserialize, BorshSerialize)] -#[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))] pub struct StoredBatch { /// The hash of the batch, as reported by the DA layer. pub hash: DbHash, @@ -373,7 +370,6 @@ macro_rules! u64_wrapper { ::serde::Serialize, ::serde::Deserialize, )] - #[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))] pub struct $name(pub u64); impl From<$name> for u64 { @@ -381,13 +377,6 @@ macro_rules! u64_wrapper { value.0 } } - - #[cfg(feature = "arbitrary")] - impl<'a> ::arbitrary::Arbitrary<'a> for $name { - fn arbitrary(u: &mut ::arbitrary::Unstructured<'a>) -> ::arbitrary::Result { - u.arbitrary().map($name) - } - } }; } @@ -395,44 +384,3 @@ u64_wrapper!(SlotNumber); u64_wrapper!(BatchNumber); u64_wrapper!(TxNumber); u64_wrapper!(EventNumber); - -#[cfg(feature = "arbitrary")] -pub mod arbitrary { - //! Arbitrary definitions for the types. - - use super::*; - - impl<'a> ::arbitrary::Arbitrary<'a> for DbBytes { - fn arbitrary(u: &mut ::arbitrary::Unstructured<'a>) -> ::arbitrary::Result { - u.arbitrary().map(DbBytes::new) - } - } - - impl<'a> ::arbitrary::Arbitrary<'a> for StoredTransaction { - fn arbitrary(u: &mut ::arbitrary::Unstructured<'a>) -> ::arbitrary::Result { - Ok(StoredTransaction { - hash: u.arbitrary()?, - body: u.arbitrary()?, - }) - } - } - - impl<'a> ::arbitrary::Arbitrary<'a> for StoredBatch { - fn arbitrary(u: &mut ::arbitrary::Unstructured<'a>) -> ::arbitrary::Result { - Ok(StoredBatch { - hash: u.arbitrary()?, - txs: u.arbitrary()?, - }) - } - } - - impl<'a> ::arbitrary::Arbitrary<'a> for StoredSlot { - fn arbitrary(u: &mut ::arbitrary::Unstructured<'a>) -> ::arbitrary::Result { - Ok(StoredSlot { - hash: u.arbitrary()?, - extra_data: u.arbitrary()?, - batches: u.arbitrary()?, - }) - } - } -} diff --git a/crates/sovereign-sdk/full-node/db/sov-schema-db/Cargo.toml b/crates/sovereign-sdk/full-node/db/sov-schema-db/Cargo.toml index ff4fa3a26..e52d1a2f2 100644 --- a/crates/sovereign-sdk/full-node/db/sov-schema-db/Cargo.toml +++ b/crates/sovereign-sdk/full-node/db/sov-schema-db/Cargo.toml @@ -18,8 +18,6 @@ anyhow = { workspace = true, default-features = true } byteorder = { workspace = true, default-features = true, optional = true } once_cell = { workspace = true, default-features = true } prometheus = { workspace = true } -proptest = { workspace = true, optional = true, default-features = true } -proptest-derive = { workspace = true, optional = true } rocksdb = { workspace = true } tokio = { workspace = true } tracing = { workspace = true, default-features = true } @@ -33,4 +31,3 @@ sov-schema-db = { path = ".", features = ["test-utils"] } [features] default = [] test-utils = ["dep:byteorder"] -arbitrary = ["dep:proptest", "dep:proptest-derive"] diff --git a/crates/sovereign-sdk/full-node/db/sov-schema-db/src/lib.rs b/crates/sovereign-sdk/full-node/db/sov-schema-db/src/lib.rs index 1adea613a..d458f0ddc 100644 --- a/crates/sovereign-sdk/full-node/db/sov-schema-db/src/lib.rs +++ b/crates/sovereign-sdk/full-node/db/sov-schema-db/src/lib.rs @@ -376,7 +376,6 @@ pub type SchemaKey = Vec; /// Readability alias for a value in the DB. pub type SchemaValue = Vec; -#[cfg_attr(feature = "arbitrary", derive(proptest_derive::Arbitrary))] #[derive(Debug, PartialEq, Eq, Hash, Clone)] /// Represents operation written to the database pub enum Operation { diff --git a/crates/sovereign-sdk/full-node/db/sov-schema-db/src/schema_batch.rs b/crates/sovereign-sdk/full-node/db/sov-schema-db/src/schema_batch.rs index d0695fbe0..46952edfa 100644 --- a/crates/sovereign-sdk/full-node/db/sov-schema-db/src/schema_batch.rs +++ b/crates/sovereign-sdk/full-node/db/sov-schema-db/src/schema_batch.rs @@ -117,24 +117,3 @@ where self.inner.as_mut().and_then(|inner| inner.next()) } } - -#[cfg(feature = "arbitrary")] -impl proptest::arbitrary::Arbitrary for SchemaBatch { - type Parameters = &'static [ColumnFamilyName]; - fn arbitrary_with(columns: Self::Parameters) -> Self::Strategy { - use proptest::prelude::any; - use proptest::strategy::Strategy; - - proptest::collection::vec(any::>(), columns.len()) - .prop_map::(|vec_vec_write_ops| { - let mut rows = HashMap::new(); - for (col, write_op) in columns.iter().zip(vec_vec_write_ops.into_iter()) { - rows.insert(*col, write_op); - } - SchemaBatch { last_writes: rows } - }) - .boxed() - } - - type Strategy = proptest::strategy::BoxedStrategy; -} diff --git a/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/Cargo.toml b/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/Cargo.toml index 1bf29b93c..4a9923ed9 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/Cargo.toml +++ b/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/Cargo.toml @@ -12,10 +12,7 @@ readme = "README.md" resolver = "2" [dependencies] -arbitrary = { workspace = true, optional = true } borsh = { workspace = true, features = ["rc"] } -proptest = { workspace = true, optional = true } -proptest-derive = { workspace = true, optional = true } schemars = { workspace = true, optional = true } serde = { workspace = true } serde_json = { workspace = true, optional = true } @@ -41,14 +38,6 @@ sov-prover-storage-manager = { path = "../../../full-node/sov-prover-storage-man [features] default = ["native"] -arbitrary = [ - "dep:arbitrary", - "dep:proptest", - "dep:proptest-derive", - "sov-state/arbitrary", - "sov-modules-api/arbitrary", - "sov-state/arbitrary", -] native = [ "serde", "serde_json", diff --git a/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/src/fuzz.rs b/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/src/fuzz.rs deleted file mode 100644 index f1090bdae..000000000 --- a/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/src/fuzz.rs +++ /dev/null @@ -1,84 +0,0 @@ -use arbitrary::{Arbitrary, Unstructured}; -use proptest::arbitrary::any; -use proptest::strategy::{BoxedStrategy, Strategy}; -use sov_modules_api::{Context, Module, PrivateKey, WorkingSet}; - -use crate::{Account, AccountConfig, Accounts}; - -impl<'a, C> Arbitrary<'a> for Account -where - C: Context, - C::Address: Arbitrary<'a>, -{ - fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result { - let addr = u.arbitrary()?; - let nonce = u.arbitrary()?; - Ok(Self { addr, nonce }) - } -} - -impl proptest::arbitrary::Arbitrary for Account -where - C: Context, - C::Address: proptest::arbitrary::Arbitrary, -{ - type Parameters = (); - type Strategy = BoxedStrategy; - - fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { - (any::(), any::()) - .prop_map(|(addr, nonce)| Account { addr, nonce }) - .boxed() - } -} - -impl<'a, C> Arbitrary<'a> for AccountConfig -where - C: Context, - C::PublicKey: Arbitrary<'a>, -{ - fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result { - // TODO we might want a dedicated struct that will generate the private key counterpart so - // payloads can be signed and verified - Ok(Self { - pub_keys: u.arbitrary_iter()?.collect::>()?, - }) - } -} - -impl proptest::arbitrary::Arbitrary for AccountConfig -where - C: Context, - C::PrivateKey: proptest::arbitrary::Arbitrary, -{ - type Parameters = (); - type Strategy = BoxedStrategy; - - fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { - any::>() - .prop_map(|keys| AccountConfig { - pub_keys: keys.into_iter().map(|k| k.pub_key()).collect(), - }) - .boxed() - } -} - -impl<'a, C> Accounts -where - C: Context, - C::Address: Arbitrary<'a>, - C::PublicKey: Arbitrary<'a>, -{ - /// Creates an arbitrary set of accounts and stores it under `working_set`. - pub fn arbitrary_workset( - u: &mut Unstructured<'a>, - working_set: &mut WorkingSet, - ) -> arbitrary::Result { - let config: AccountConfig = u.arbitrary()?; - let accounts = Accounts::default(); - - accounts.genesis(&config, working_set); - - Ok(accounts) - } -} diff --git a/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/src/lib.rs b/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/src/lib.rs index 883a6bd9f..5cce09056 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/src/lib.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/src/lib.rs @@ -1,5 +1,3 @@ -#[cfg(all(feature = "arbitrary", feature = "native"))] -mod fuzz; mod genesis; mod hooks; pub use genesis::*; @@ -33,7 +31,6 @@ pub struct Account { /// A module responsible for managing accounts on the rollup. #[cfg_attr(feature = "native", derive(sov_modules_api::ModuleCallJsonSchema))] #[derive(ModuleInfo, Clone)] -#[cfg_attr(feature = "arbitrary", derive(Debug))] pub struct Accounts { /// The address of the sov-accounts module. #[address] diff --git a/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/src/query.rs b/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/src/query.rs index 03ac8998e..29d284885 100644 --- a/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/src/query.rs +++ b/crates/sovereign-sdk/module-system/module-implementations/sov-accounts/src/query.rs @@ -7,10 +7,6 @@ use crate::{Account, Accounts}; /// This is the response returned from the accounts_getAccount endpoint. #[derive(Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize, Clone)] -#[cfg_attr( - feature = "arbitrary", - derive(arbitrary::Arbitrary, proptest_derive::Arbitrary) -)] pub enum Response { /// The account corresponding to the given public key exists. AccountExists { diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/Cargo.toml b/crates/sovereign-sdk/module-system/sov-modules-api/Cargo.toml index 720961cdb..804efc89f 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/Cargo.toml +++ b/crates/sovereign-sdk/module-system/sov-modules-api/Cargo.toml @@ -14,7 +14,6 @@ resolver = "2" [dependencies] jsonrpsee = { workspace = true, optional = true } anyhow = { workspace = true } -arbitrary = { workspace = true, optional = true } digest = { workspace = true } sov-state = { path = "../sov-state" } sov-modules-core = { path = "../sov-modules-core" } @@ -23,8 +22,6 @@ sov-modules-macros = { path = "../sov-modules-macros", optional = true, default- sov-prover-storage-manager = { path = "../../full-node/sov-prover-storage-manager", optional = true } serde = { workspace = true } borsh = { workspace = true } -proptest = { workspace = true, optional = true } -proptest-derive = { workspace = true, optional = true } thiserror = { workspace = true } sha2 = { workspace = true } bech32 = { workspace = true } @@ -51,15 +48,6 @@ sov-prover-storage-manager = { path = "../../full-node/sov-prover-storage-manage [features] -arbitrary = [ - "dep:arbitrary", - "dep:proptest", - "dep:proptest-derive", - "native", - "sov-rollup-interface/arbitrary", - "proptest/default", - "sov-state/arbitrary", -] bench = [] default = ["native", "macros"] native = [ diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/accessory_map.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/accessory_map.rs index 1bc0011e8..79665317e 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/accessory_map.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/accessory_map.rs @@ -70,40 +70,3 @@ where &self.codec } } - -#[cfg(feature = "arbitrary")] -impl<'a, K, V, Codec> AccessoryStateMap -where - K: arbitrary::Arbitrary<'a>, - V: arbitrary::Arbitrary<'a>, - Codec: StateCodec + Default, - Codec::KeyCodec: StateKeyCodec, - Codec::ValueCodec: StateValueCodec, -{ - /// Generates an arbitrary [`AccessoryStateMap`] instance. - /// - /// See the [`arbitrary`] crate for more information. - pub fn arbitrary_working_set( - u: &mut arbitrary::Unstructured<'a>, - working_set: &mut AccessoryWorkingSet, - ) -> arbitrary::Result - where - S: Storage, - { - use arbitrary::Arbitrary; - - let prefix = Prefix::arbitrary(u)?; - let len = u.arbitrary_len::<(K, V)>()?; - let codec = Codec::default(); - let map = Self::with_codec(prefix, codec); - - (0..len).try_fold(map, |map, _| { - let key = K::arbitrary(u)?; - let value = V::arbitrary(u)?; - - map.set(&key, &value, working_set); - - Ok(map) - }) - } -} diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/map.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/map.rs index 9c3843822..b4060dbf3 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/map.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/map.rs @@ -72,40 +72,3 @@ where &self.prefix } } - -#[cfg(feature = "arbitrary")] -impl<'a, K, V, Codec> StateMap -where - K: arbitrary::Arbitrary<'a>, - V: arbitrary::Arbitrary<'a>, - Codec: StateCodec + Default, - Codec::KeyCodec: StateKeyCodec, - Codec::ValueCodec: StateValueCodec, -{ - /// Returns an arbitrary [`StateMap`] instance. - /// - /// See the [`arbitrary`] crate for more information. - pub fn arbitrary_working_set( - u: &mut arbitrary::Unstructured<'a>, - working_set: &mut WorkingSet, - ) -> arbitrary::Result - where - S: Storage, - { - use arbitrary::Arbitrary; - - let prefix = Prefix::arbitrary(u)?; - let len = u.arbitrary_len::<(K, V)>()?; - let codec = Codec::default(); - let map = StateMap::with_codec(prefix, codec); - - (0..len).try_fold(map, |map, _| { - let key = K::arbitrary(u)?; - let value = V::arbitrary(u)?; - - map.set(&key, &value, working_set); - - Ok(map) - }) - } -} diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/offchain_map.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/offchain_map.rs index b532a6aa6..d33b790e3 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/offchain_map.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/containers/offchain_map.rs @@ -70,40 +70,3 @@ where &self.codec } } - -#[cfg(feature = "arbitrary")] -impl<'a, K, V, Codec> OffchainStateMap -where - K: arbitrary::Arbitrary<'a>, - V: arbitrary::Arbitrary<'a>, - Codec: StateCodec + Default, - Codec::KeyCodec: StateKeyCodec, - Codec::ValueCodec: StateValueCodec, -{ - /// Generates an arbitrary [`OffchainStateMap`] instance. - /// - /// See the [`arbitrary`] crate for more information. - pub fn arbitrary_working_set( - u: &mut arbitrary::Unstructured<'a>, - working_set: &mut OffchainWorkingSet, - ) -> arbitrary::Result - where - S: Storage, - { - use arbitrary::Arbitrary; - - let prefix = Prefix::arbitrary(u)?; - let len = u.arbitrary_len::<(K, V)>()?; - let codec = Codec::default(); - let map = Self::with_codec(prefix, codec); - - (0..len).try_fold(map, |map, _| { - let key = K::arbitrary(u)?; - let value = V::arbitrary(u)?; - - map.set(&key, &value, working_set); - - Ok(map) - }) - } -} diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/default_context.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/default_context.rs index d57f5e733..a6c21a94f 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/default_context.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/default_context.rs @@ -16,7 +16,6 @@ use crate::default_signature::private_key::DefaultPrivateKey; use crate::default_signature::{DefaultPublicKey, DefaultSignature}; #[cfg(feature = "native")] -#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[derive(Clone, Debug, PartialEq, BorshDeserialize, BorshSerialize, Serialize, Deserialize)] pub struct DefaultContext { pub sender: Address, diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/default_signature.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/default_signature.rs index 5bb59d855..1cfd27f57 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/default_signature.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/default_signature.rs @@ -129,41 +129,6 @@ pub mod private_key { self.pub_key().to_address::
() } } - - #[cfg(feature = "arbitrary")] - impl<'a> arbitrary::Arbitrary<'a> for DefaultPrivateKey { - fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { - use rand::rngs::StdRng; - use rand::SeedableRng; - - // it is important to generate the secret deterministically from the arbitrary argument - // so keys and signatures will be reproducible for a given seed. - // this unlocks fuzzy replay - let seed = <[u8; 32]>::arbitrary(u)?; - let rng = &mut StdRng::from_seed(seed); - let key_pair = SigningKey::generate(rng); - - Ok(Self { key_pair }) - } - } - - #[cfg(feature = "arbitrary")] - impl<'a> arbitrary::Arbitrary<'a> for DefaultPublicKey { - fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { - DefaultPrivateKey::arbitrary(u).map(|p| p.pub_key()) - } - } - - #[cfg(feature = "arbitrary")] - impl<'a> arbitrary::Arbitrary<'a> for DefaultSignature { - fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { - // the secret/public pair is lost; it is impossible to verify this signature - // to run a verification, generate the keys+payload individually - let payload_len = u.arbitrary_len::()?; - let payload = u.bytes(payload_len)?; - DefaultPrivateKey::arbitrary(u).map(|s| s.sign(payload)) - } - } } #[cfg_attr(feature = "native", derive(schemars::JsonSchema))] diff --git a/crates/sovereign-sdk/module-system/sov-modules-api/src/pub_key_hex.rs b/crates/sovereign-sdk/module-system/sov-modules-api/src/pub_key_hex.rs index eb6ab91c6..7fe434ec3 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-api/src/pub_key_hex.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-api/src/pub_key_hex.rs @@ -81,17 +81,6 @@ impl TryFrom<&PublicKeyHex> for DefaultPublicKey { } } -// TODO: Check this and it's relevance with gas_oracle_test -#[cfg(feature = "arbitrary")] -impl<'a> arbitrary::Arbitrary<'a> for PublicKeyHex { - fn arbitrary(u: &mut arbitrary::Unstructured<'a>) -> arbitrary::Result { - use sov_modules_core::PrivateKey; - let public_key = - crate::default_signature::private_key::DefaultPrivateKey::arbitrary(u)?.pub_key(); - Ok(PublicKeyHex::from(&public_key)) - } -} - #[cfg(test)] mod tests { use sov_modules_core::PrivateKey; diff --git a/crates/sovereign-sdk/module-system/sov-modules-core/Cargo.toml b/crates/sovereign-sdk/module-system/sov-modules-core/Cargo.toml index 9d3c23175..de72570e0 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-core/Cargo.toml +++ b/crates/sovereign-sdk/module-system/sov-modules-core/Cargo.toml @@ -14,15 +14,12 @@ resolver = "2" [dependencies] anyhow = { workspace = true } -arbitrary = { workspace = true, optional = true } bech32 = { workspace = true } borsh = { workspace = true } derive_more = { workspace = true, features = ["display", "into"] } digest = { workspace = true } hex = { workspace = true } jmt = { workspace = true, optional = true } -proptest = { workspace = true, optional = true } -proptest-derive = { workspace = true, optional = true } schemars = { workspace = true, optional = true } serde = { workspace = true } sha2 = { workspace = true } @@ -44,13 +41,6 @@ sov-prover-storage-manager = { path = "../../full-node/sov-prover-storage-manage [features] default = ["std"] -arbitrary = [ - "dep:arbitrary", - "dep:proptest", - "dep:proptest-derive", - "proptest/default", - "std", -] native = [] std = [ "anyhow/default", diff --git a/crates/sovereign-sdk/module-system/sov-modules-core/src/common/address.rs b/crates/sovereign-sdk/module-system/sov-modules-core/src/common/address.rs index 10efb7e4a..4019e064e 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-core/src/common/address.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-core/src/common/address.rs @@ -25,10 +25,6 @@ use crate::common::Bech32ParseError; Into, Display, )] -#[cfg_attr( - feature = "arbitrary", - derive(arbitrary::Arbitrary, proptest_derive::Arbitrary) -)] #[serde(try_from = "String", into = "String")] #[display(fmt = "{}", "value")] pub struct AddressBech32 { @@ -37,7 +33,6 @@ pub struct AddressBech32 { /// Module address representation #[cfg_attr(all(feature = "native", feature = "std"), derive(schemars::JsonSchema))] -#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] #[derive(PartialEq, Clone, Copy, Eq, BorshDeserialize, BorshSerialize, Hash)] pub struct Address { addr: [u8; 32], diff --git a/crates/sovereign-sdk/module-system/sov-modules-core/src/common/bytes.rs b/crates/sovereign-sdk/module-system/sov-modules-core/src/common/bytes.rs index 9722d6e52..c9f859d09 100644 --- a/crates/sovereign-sdk/module-system/sov-modules-core/src/common/bytes.rs +++ b/crates/sovereign-sdk/module-system/sov-modules-core/src/common/bytes.rs @@ -84,10 +84,6 @@ impl AsRef> for AlignedVec { borsh::BorshSerialize ) )] -#[cfg_attr( - feature = "arbitrary", - derive(arbitrary::Arbitrary, proptest_derive::Arbitrary) -)] pub struct Prefix { prefix: AlignedVec, } @@ -222,34 +218,3 @@ impl From for Prefix { Prefix::new(combined_prefix) } } - -#[cfg(feature = "arbitrary")] -mod arbitrary_impls { - use arbitrary::{Arbitrary, Unstructured}; - use proptest::arbitrary::any; - use proptest::strategy::{BoxedStrategy, Strategy}; - - use super::*; - - impl<'a> Arbitrary<'a> for AlignedVec { - fn arbitrary(u: &mut Unstructured<'a>) -> arbitrary::Result { - u.arbitrary().map(|v: Vec| { - // we re-allocate so the capacity is also guaranteed to be aligned - Self::new(v[..(v.len() / Self::ALIGNMENT) * Self::ALIGNMENT].to_vec()) - }) - } - } - - impl proptest::arbitrary::Arbitrary for AlignedVec { - type Parameters = (); - type Strategy = BoxedStrategy; - - fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy { - any::>() - .prop_map(|v| { - Self::new(v[..(v.len() / Self::ALIGNMENT) * Self::ALIGNMENT].to_vec()) - }) - .boxed() - } - } -} diff --git a/crates/sovereign-sdk/module-system/sov-state/Cargo.toml b/crates/sovereign-sdk/module-system/sov-state/Cargo.toml index 80487274a..ef469e893 100644 --- a/crates/sovereign-sdk/module-system/sov-state/Cargo.toml +++ b/crates/sovereign-sdk/module-system/sov-state/Cargo.toml @@ -13,11 +13,8 @@ resolver = "2" [dependencies] anyhow = { workspace = true } -arbitrary = { workspace = true, optional = true } borsh = { workspace = true, features = ["rc", "bytes"] } bcs = { workspace = true } -proptest = { workspace = true, optional = true } -proptest-derive = { workspace = true, optional = true } serde = { workspace = true, features = ["rc"] } sov-rollup-interface = { path = "../../rollup-interface" } sov-modules-core = { path = "../sov-modules-core" } @@ -30,11 +27,5 @@ tempfile = { workspace = true } proptest = { workspace = true } [features] -arbitrary = [ - "dep:arbitrary", - "dep:proptest", - "dep:proptest-derive", - "sov-modules-core/arbitrary", -] default = [] native = ["sov-db"] diff --git a/crates/sovereign-sdk/rollup-interface/Cargo.toml b/crates/sovereign-sdk/rollup-interface/Cargo.toml index 969264b24..476aa8a1f 100644 --- a/crates/sovereign-sdk/rollup-interface/Cargo.toml +++ b/crates/sovereign-sdk/rollup-interface/Cargo.toml @@ -16,7 +16,6 @@ resolver = "2" [dependencies] anyhow = { workspace = true } -arbitrary = { workspace = true, optional = true } async-trait = { workspace = true } borsh = { workspace = true } bytes = { workspace = true, optional = true, default-features = true } @@ -36,7 +35,6 @@ serde_json = { workspace = true } default = ["std"] native = ["std", "tokio", "futures", "tracing"] testing = ["native"] -arbitrary = ["dep:arbitrary"] std = [ "anyhow/default", "borsh/default", diff --git a/crates/sovereign-sdk/rollup-interface/src/spec.rs b/crates/sovereign-sdk/rollup-interface/src/spec.rs index eaecfbf0d..abce77fe7 100644 --- a/crates/sovereign-sdk/rollup-interface/src/spec.rs +++ b/crates/sovereign-sdk/rollup-interface/src/spec.rs @@ -24,7 +24,6 @@ mod spec { Hash, )] #[borsh(use_discriminant = true)] - #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub enum SpecId { /// Genesis spec #[default] @@ -56,7 +55,6 @@ mod spec { Hash, )] #[borsh(use_discriminant = true)] - #[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))] pub enum SpecId { /// Genesis spec #[default] From e9c5516dc5e1fc90283a27be238e2e4bc6195b44 Mon Sep 17 00:00:00 2001 From: jfldde <168934971+jfldde@users.noreply.github.com> Date: Fri, 13 Dec 2024 13:35:04 +0000 Subject: [PATCH 05/10] Remove sequencer-client crate (#1606) --- Cargo.lock | 31 +--- Cargo.toml | 1 - bin/citrea/Cargo.toml | 1 - crates/batch-prover/Cargo.toml | 3 +- crates/batch-prover/src/runner.rs | 113 +++++------ crates/ethereum-rpc/Cargo.toml | 3 +- crates/ethereum-rpc/src/ethereum.rs | 6 +- crates/ethereum-rpc/src/lib.rs | 18 +- crates/fullnode/Cargo.toml | 3 +- crates/fullnode/src/runner.rs | 108 +++++------ crates/light-client-prover/Cargo.toml | 7 +- .../src/da_block_handler.rs | 10 +- crates/light-client-prover/src/runner.rs | 15 +- crates/sequencer-client/Cargo.toml | 41 ---- crates/sequencer-client/README.md | 3 - crates/sequencer-client/src/lib.rs | 175 ------------------ .../rollup-interface/src/node/rpc/mod.rs | 39 ++++ 17 files changed, 198 insertions(+), 379 deletions(-) delete mode 100644 crates/sequencer-client/Cargo.toml delete mode 100644 crates/sequencer-client/README.md delete mode 100644 crates/sequencer-client/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 9d3b53697..38285a9de 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1742,7 +1742,6 @@ dependencies = [ "rs_merkle", "rustc_version_runtime", "secp256k1", - "sequencer-client", "serde", "serde_json", "sha2", @@ -1784,11 +1783,12 @@ dependencies = [ "prover-services", "rand 0.8.5", "rayon", + "reth-primitives", "rs_merkle", - "sequencer-client", "serde", "sha2", "sov-db", + "sov-ledger-rpc", "sov-mock-da", "sov-mock-zkvm", "sov-modules-api", @@ -1918,12 +1918,13 @@ dependencies = [ "hex", "jsonrpsee", "rand 0.8.5", + "reth-primitives", "rs_merkle", - "sequencer-client", "serde", "serde_json", "sha2", "sov-db", + "sov-ledger-rpc", "sov-mock-da", "sov-modules-api", "sov-modules-stf-blueprint", @@ -1950,8 +1951,9 @@ dependencies = [ "citrea-primitives", "hex", "jsonrpsee", - "sequencer-client", + "reth-primitives", "sov-db", + "sov-ledger-rpc", "sov-mock-da", "sov-mock-zkvm", "sov-modules-api", @@ -2824,6 +2826,7 @@ dependencies = [ "borsh", "citrea-evm", "citrea-primitives", + "citrea-sequencer", "futures", "jsonrpsee", "parking_lot", @@ -2833,10 +2836,10 @@ dependencies = [ "reth-rpc-types-compat", "rustc_version_runtime", "schnellru", - "sequencer-client", "serde", "serde_json", "sov-db", + "sov-ledger-rpc", "sov-modules-api", "sov-rollup-interface", "tokio", @@ -7066,24 +7069,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f638d531eccd6e23b980caf34876660d38e265409d8e99b397ab71eb3612fad0" -[[package]] -name = "sequencer-client" -version = "0.5.0-rc.1" -dependencies = [ - "anyhow", - "borsh", - "citrea-primitives", - "hex", - "jsonrpsee", - "reth-primitives", - "reth-rpc-types", - "serde", - "serde_json", - "sov-rollup-interface", - "tokio", - "tracing", -] - [[package]] name = "serde" version = "1.0.215" diff --git a/Cargo.toml b/Cargo.toml index 738ed3fdf..7c2470576 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ members = [ "crates/pruning", "crates/risc0", "crates/sequencer", - "crates/sequencer-client", "crates/soft-confirmation-rule-enforcer", # "crates/sp1", # Sovereign sdk diff --git a/bin/citrea/Cargo.toml b/bin/citrea/Cargo.toml index 1f0f926cc..de0c37333 100644 --- a/bin/citrea/Cargo.toml +++ b/bin/citrea/Cargo.toml @@ -26,7 +26,6 @@ citrea-sequencer = { path = "../../crates/sequencer" } citrea-stf = { path = "../../crates/citrea-stf", features = ["native"] } ethereum-rpc = { path = "../../crates/ethereum-rpc" } prover-services = { path = "../../crates/prover-services" } -sequencer-client = { path = "../../crates/sequencer-client" } # Sovereign-SDK deps soft-confirmation-rule-enforcer = { path = "../../crates/soft-confirmation-rule-enforcer" } diff --git a/crates/batch-prover/Cargo.toml b/crates/batch-prover/Cargo.toml index 83cdd5b68..1d7d9d1e9 100644 --- a/crates/batch-prover/Cargo.toml +++ b/crates/batch-prover/Cargo.toml @@ -12,10 +12,10 @@ repository.workspace = true # Citrea Deps citrea-common = { path = "../common" } citrea-primitives = { path = "../primitives", features = ["native"] } -sequencer-client = { path = "../sequencer-client" } # Sov SDK deps sov-db = { path = "../sovereign-sdk/full-node/db/sov-db" } +sov-ledger-rpc = { path = "../sovereign-sdk/full-node/sov-ledger-rpc", features = ["client"] } sov-modules-api = { path = "../sovereign-sdk/module-system/sov-modules-api", default-features = false } sov-modules-core = { path = "../sovereign-sdk/module-system/sov-modules-core" } sov-modules-stf-blueprint = { path = "../sovereign-sdk/module-system/sov-modules-stf-blueprint", features = ["native"] } @@ -35,6 +35,7 @@ num_cpus = { workspace = true } parking_lot = { workspace = true } rand = { workspace = true } rayon = { workspace = true } +reth-primitives = { workspace = true } rs_merkle = { workspace = true } serde = { workspace = true } tokio = { workspace = true } diff --git a/crates/batch-prover/src/runner.rs b/crates/batch-prover/src/runner.rs index a001626a8..00c9184db 100644 --- a/crates/batch-prover/src/runner.rs +++ b/crates/batch-prover/src/runner.rs @@ -14,16 +14,19 @@ use citrea_common::utils::{create_shutdown_signal, soft_confirmation_to_receipt} use citrea_common::{BatchProverConfig, RollupPublicKeys, RpcConfig, RunnerConfig}; use citrea_primitives::types::SoftConfirmationHash; use jsonrpsee::core::client::Error as JsonrpseeError; +use jsonrpsee::http_client::{HttpClient, HttpClientBuilder}; use jsonrpsee::server::{BatchRequestConfig, ServerBuilder}; use jsonrpsee::RpcModule; -use sequencer_client::{GetSoftConfirmationResponse, SequencerClient}; +use reth_primitives::U64; use sov_db::ledger_db::BatchProverLedgerOps; use sov_db::schema::types::{BatchNumber, SlotNumber}; +use sov_ledger_rpc::LedgerRpcClient; use sov_modules_api::{Context, SignedSoftConfirmation, SlotData, Spec}; use sov_modules_stf_blueprint::{Runtime, StfBlueprint}; use sov_prover_storage_manager::{ProverStorage, ProverStorageManager, SnapshotManager}; -use sov_rollup_interface::da::{BlockHeaderTrait, DaSpec}; +use sov_rollup_interface::da::BlockHeaderTrait; use sov_rollup_interface::fork::ForkManager; +use sov_rollup_interface::rpc::SoftConfirmationResponse; use sov_rollup_interface::services::da::DaService; use sov_rollup_interface::spec::SpecId; use sov_rollup_interface::stf::StateTransitionFunction; @@ -60,7 +63,7 @@ where batch_hash: SoftConfirmationHash, rpc_config: RpcConfig, prover_service: Arc, - sequencer_client: SequencerClient, + sequencer_client: HttpClient, sequencer_pub_key: Vec, sequencer_da_pub_key: Vec, phantom: std::marker::PhantomData, @@ -143,7 +146,8 @@ where batch_hash: prev_batch_hash, rpc_config, prover_service, - sequencer_client: SequencerClient::new(runner_config.sequencer_client_url), + sequencer_client: HttpClientBuilder::default() + .build(runner_config.sequencer_client_url)?, sequencer_pub_key: public_keys.sequencer_public_key, sequencer_da_pub_key: public_keys.sequencer_da_pub_key, phantom: std::marker::PhantomData, @@ -279,7 +283,7 @@ where let start_l1_height = match last_scanned_l1_height { Some(height) => height.0, - None => get_initial_slot_height::(&self.sequencer_client).await, + None => get_initial_slot_height(&self.sequencer_client).await, }; let ledger_db = self.ledger_db.clone(); @@ -325,13 +329,12 @@ where let sequencer_client = self.sequencer_client.clone(); let sync_blocks_count = self.sync_blocks_count; - let l2_sync_worker = - sync_l2::(start_l2_height, sequencer_client, l2_tx, sync_blocks_count); + let l2_sync_worker = sync_l2(start_l2_height, sequencer_client, l2_tx, sync_blocks_count); tokio::pin!(l2_sync_worker); // Store L2 blocks and make sure they are processed in order. // Otherwise, processing N+1 L2 block before N would emit prev_hash mismatch. - let mut pending_l2_blocks: VecDeque<(u64, GetSoftConfirmationResponse)> = VecDeque::new(); + let mut pending_l2_blocks = VecDeque::new(); let mut interval = tokio::time::interval(Duration::from_secs(1)); interval.tick().await; @@ -349,7 +352,7 @@ where if let Err(e) = self.process_l2_block(*l2_height, l2_block).await { error!("Could not process L2 block: {}", e); // This block failed to process, add remaining L2 blocks to queue including this one. - let remaining_l2s: Vec<(u64, GetSoftConfirmationResponse)> = l2_blocks[index..].to_vec(); + let remaining_l2s = l2_blocks[index..].to_vec(); pending_l2_blocks.extend(remaining_l2s); } } @@ -389,7 +392,7 @@ where async fn process_l2_block( &mut self, l2_height: u64, - soft_confirmation: &GetSoftConfirmationResponse, + soft_confirmation: &SoftConfirmationResponse, ) -> anyhow::Result<()> { let current_l1_block = get_da_block_at_height( &self.da_service, @@ -492,14 +495,12 @@ where } } -async fn sync_l2( +async fn sync_l2( start_l2_height: u64, - sequencer_client: SequencerClient, - sender: mpsc::Sender>, + sequencer_client: HttpClient, + sender: mpsc::Sender>, sync_blocks_count: u64, -) where - Da: DaService, -{ +) { let mut l2_height = start_l2_height; info!("Starting to sync from L2 height {}", l2_height); loop { @@ -510,44 +511,44 @@ async fn sync_l2( .build(); let inner_client = &sequencer_client; - let soft_confirmations: Vec = - match retry_backoff(exponential_backoff.clone(), || async move { - let soft_confirmations = inner_client - .get_soft_confirmation_range::( - l2_height..=l2_height + sync_blocks_count - 1, - ) - .await; - - match soft_confirmations { - Ok(soft_confirmations) => { - Ok(soft_confirmations.into_iter().flatten().collect::>()) - } - Err(e) => match e.downcast_ref::() { - Some(JsonrpseeError::Transport(e)) => { - let error_msg = format!( - "Soft Confirmation: connection error during RPC call: {:?}", - e - ); - debug!(error_msg); - Err(backoff::Error::Transient { - err: error_msg, - retry_after: None, - }) - } - _ => Err(backoff::Error::Transient { - err: format!("Soft Confirmation: unknown error from RPC call: {:?}", e), - retry_after: None, - }), - }, - } - }) - .await - { - Ok(soft_confirmations) => soft_confirmations, - Err(_) => { - continue; + let soft_confirmations = match retry_backoff(exponential_backoff.clone(), || async move { + let soft_confirmations = inner_client + .get_soft_confirmation_range( + U64::from(l2_height), + U64::from(l2_height + sync_blocks_count - 1), + ) + .await; + + match soft_confirmations { + Ok(soft_confirmations) => { + Ok(soft_confirmations.into_iter().flatten().collect::>()) } - }; + Err(e) => match e { + JsonrpseeError::Transport(e) => { + let error_msg = format!( + "Soft Confirmation: connection error during RPC call: {:?}", + e + ); + debug!(error_msg); + Err(backoff::Error::Transient { + err: error_msg, + retry_after: None, + }) + } + _ => Err(backoff::Error::Transient { + err: format!("Soft Confirmation: unknown error from RPC call: {:?}", e), + retry_after: None, + }), + }, + } + }) + .await + { + Ok(soft_confirmations) => soft_confirmations, + Err(_) => { + continue; + } + }; if soft_confirmations.is_empty() { debug!( @@ -559,7 +560,7 @@ async fn sync_l2( continue; } - let soft_confirmations: Vec<(u64, GetSoftConfirmationResponse)> = (l2_height + let soft_confirmations: Vec<(u64, SoftConfirmationResponse)> = (l2_height ..l2_height + soft_confirmations.len() as u64) .zip(soft_confirmations) .collect(); @@ -572,9 +573,9 @@ async fn sync_l2( } } -async fn get_initial_slot_height(client: &SequencerClient) -> u64 { +async fn get_initial_slot_height(client: &HttpClient) -> u64 { loop { - match client.get_soft_confirmation::(1).await { + match client.get_soft_confirmation_by_number(U64::from(1)).await { Ok(Some(batch)) => return batch.da_slot_height, _ => { // sleep 1 diff --git a/crates/ethereum-rpc/Cargo.toml b/crates/ethereum-rpc/Cargo.toml index 9704c7a8e..2055fcbb0 100644 --- a/crates/ethereum-rpc/Cargo.toml +++ b/crates/ethereum-rpc/Cargo.toml @@ -17,12 +17,12 @@ anyhow = { workspace = true } borsh = { workspace = true } citrea-evm = { path = "../evm", features = ["native"] } citrea-primitives = { path = "../primitives" } +citrea-sequencer = { path = "../sequencer" } futures = { workspace = true } jsonrpsee = { workspace = true, features = ["http-client", "server"] } parking_lot = { workspace = true } rustc_version_runtime = { workspace = true } schnellru = "0.2.1" -sequencer-client = { path = "../sequencer-client" } serde = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true } @@ -36,6 +36,7 @@ reth-rpc-types-compat = { workspace = true } # Sovereign-SDK deps sov-db = { path = "../../crates/sovereign-sdk/full-node/db/sov-db" } +sov-ledger-rpc = { path = "../sovereign-sdk/full-node/sov-ledger-rpc", features = ["client"] } sov-modules-api = { path = "../sovereign-sdk/module-system/sov-modules-api", default-features = false } sov-rollup-interface = { path = "../sovereign-sdk/rollup-interface", features = ["native"] } diff --git a/crates/ethereum-rpc/src/ethereum.rs b/crates/ethereum-rpc/src/ethereum.rs index 387e895d9..9e2c9b31d 100644 --- a/crates/ethereum-rpc/src/ethereum.rs +++ b/crates/ethereum-rpc/src/ethereum.rs @@ -3,11 +3,11 @@ use std::sync::{Arc, Mutex}; #[cfg(feature = "local")] use citrea_evm::DevSigner; use citrea_evm::Evm; +use jsonrpsee::http_client::HttpClient; use reth_primitives::U256; use reth_rpc_types::trace::geth::GethTrace; use rustc_version_runtime::version; use schnellru::{ByLength, LruMap}; -use sequencer_client::SequencerClient; use sov_db::ledger_db::LedgerDB; use sov_modules_api::WorkingSet; use sov_rollup_interface::services::da::DaService; @@ -38,7 +38,7 @@ pub struct Ethereum { pub(crate) eth_signer: DevSigner, pub(crate) storage: C::Storage, pub(crate) ledger_db: LedgerDB, - pub(crate) sequencer_client: Option, + pub(crate) sequencer_client: Option, pub(crate) web3_client_version: String, pub(crate) trace_cache: Mutex, ByLength>>, pub(crate) subscription_manager: Option, @@ -53,7 +53,7 @@ impl Ethereum { #[cfg(feature = "local")] eth_signer: DevSigner, storage: C::Storage, ledger_db: LedgerDB, - sequencer_client: Option, + sequencer_client: Option, soft_confirmation_rx: Option>, ) -> Self { let evm = Evm::::default(); diff --git a/crates/ethereum-rpc/src/lib.rs b/crates/ethereum-rpc/src/lib.rs index 516d1378e..e65ba19ea 100644 --- a/crates/ethereum-rpc/src/lib.rs +++ b/crates/ethereum-rpc/src/lib.rs @@ -8,18 +8,20 @@ use std::sync::Arc; #[cfg(feature = "local")] pub use citrea_evm::DevSigner; use citrea_evm::{Evm, Filter}; +use citrea_sequencer::SequencerRpcClient; pub use ethereum::{EthRpcConfig, Ethereum}; pub use gas_price::fee_history::FeeHistoryCacheConfig; pub use gas_price::gas_oracle::GasPriceOracleConfig; +use jsonrpsee::http_client::HttpClientBuilder; use jsonrpsee::types::ErrorObjectOwned; use jsonrpsee::RpcModule; use reth_primitives::{keccak256, BlockNumberOrTag, Bytes, B256, U256}; use reth_rpc_eth_types::EthApiError; use reth_rpc_types::trace::geth::{GethDebugTracingOptions, GethTrace}; use reth_rpc_types::{FeeHistory, Index}; -use sequencer_client::SequencerClient; use serde_json::json; use sov_db::ledger_db::{LedgerDB, SharedLedgerOps}; +use sov_ledger_rpc::LedgerRpcClient; use sov_modules_api::da::BlockHeaderTrait; use sov_modules_api::utils::to_jsonrpsee_error_object; use sov_modules_api::WorkingSet; @@ -75,7 +77,7 @@ pub fn get_ethereum_rpc( eth_signer, storage, ledger_db, - sequencer_client_url.map(SequencerClient::new), + sequencer_client_url.map(|url| HttpClientBuilder::default().build(url).unwrap()), soft_confirmation_rx, )); @@ -513,7 +515,7 @@ fn register_rpc_methods( .sequencer_client .as_ref() .unwrap() - .send_raw_tx(data) + .eth_send_raw_transaction(data) .await; match tx_hash { @@ -541,7 +543,7 @@ fn register_rpc_methods( .sequencer_client .as_ref() .unwrap() - .get_tx_by_hash(hash, Some(true)) + .eth_get_transaction_by_hash(hash, Some(true)) .await { Ok(tx) => Ok(tx), @@ -563,7 +565,7 @@ fn register_rpc_methods( .sequencer_client .as_ref() .unwrap() - .get_tx_by_hash(hash, Some(true)) + .eth_get_transaction_by_hash(hash, Some(true)) .await { Ok(tx) => Ok(tx), @@ -592,7 +594,11 @@ fn register_rpc_methods( // sequencer client should send latest l2 height // da service should send latest finalized l1 block header let (sequencer_response, da_response) = join!( - ethereum.sequencer_client.as_ref().unwrap().block_number(), + ethereum + .sequencer_client + .as_ref() + .unwrap() + .get_head_soft_confirmation_height(), ethereum.da_service.get_last_finalized_block_header() ); // handle sequencer response diff --git a/crates/fullnode/Cargo.toml b/crates/fullnode/Cargo.toml index 57b192c8a..4bcd728d1 100644 --- a/crates/fullnode/Cargo.toml +++ b/crates/fullnode/Cargo.toml @@ -13,10 +13,10 @@ repository.workspace = true citrea-common = { path = "../common" } citrea-primitives = { path = "../primitives", features = ["native"] } citrea-pruning = { path = "../pruning" } -sequencer-client = { path = "../sequencer-client" } # Sov SDK deps sov-db = { path = "../sovereign-sdk/full-node/db/sov-db" } +sov-ledger-rpc = { path = "../sovereign-sdk/full-node/sov-ledger-rpc", features = ["client"] } sov-modules-api = { path = "../sovereign-sdk/module-system/sov-modules-api", default-features = false } sov-modules-stf-blueprint = { path = "../sovereign-sdk/module-system/sov-modules-stf-blueprint", features = ["native"] } sov-prover-storage-manager = { path = "../sovereign-sdk/full-node/sov-prover-storage-manager" } @@ -31,6 +31,7 @@ futures = { workspace = true } hex = { workspace = true } jsonrpsee = { workspace = true } rand = { workspace = true } +reth-primitives = { workspace = true } rs_merkle = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } diff --git a/crates/fullnode/src/runner.rs b/crates/fullnode/src/runner.rs index 0df88158a..49460c7df 100644 --- a/crates/fullnode/src/runner.rs +++ b/crates/fullnode/src/runner.rs @@ -13,16 +13,19 @@ use citrea_common::{RollupPublicKeys, RpcConfig, RunnerConfig}; use citrea_primitives::types::SoftConfirmationHash; use citrea_pruning::{Pruner, PruningConfig}; use jsonrpsee::core::client::Error as JsonrpseeError; +use jsonrpsee::http_client::{HttpClient, HttpClientBuilder}; use jsonrpsee::server::{BatchRequestConfig, RpcServiceBuilder, ServerBuilder}; use jsonrpsee::RpcModule; -use sequencer_client::{GetSoftConfirmationResponse, SequencerClient}; +use reth_primitives::U64; use sov_db::ledger_db::NodeLedgerOps; use sov_db::schema::types::{BatchNumber, SlotNumber}; +use sov_ledger_rpc::LedgerRpcClient; use sov_modules_api::{Context, SignedSoftConfirmation, Spec}; use sov_modules_stf_blueprint::{Runtime, StfBlueprint}; use sov_prover_storage_manager::{ProverStorage, ProverStorageManager, SnapshotManager}; -use sov_rollup_interface::da::{BlockHeaderTrait, DaSpec}; +use sov_rollup_interface::da::BlockHeaderTrait; use sov_rollup_interface::fork::ForkManager; +use sov_rollup_interface::rpc::SoftConfirmationResponse; use sov_rollup_interface::services::da::{DaService, SlotData}; use sov_rollup_interface::spec::SpecId; use sov_rollup_interface::stf::StateTransitionFunction; @@ -56,7 +59,7 @@ where state_root: StateRoot, batch_hash: SoftConfirmationHash, rpc_config: RpcConfig, - sequencer_client: SequencerClient, + sequencer_client: HttpClient, sequencer_pub_key: Vec, sequencer_da_pub_key: Vec, prover_da_pub_key: Vec, @@ -133,7 +136,8 @@ where state_root: prev_state_root, batch_hash: prev_batch_hash, rpc_config, - sequencer_client: SequencerClient::new(runner_config.sequencer_client_url), + sequencer_client: HttpClientBuilder::default() + .build(runner_config.sequencer_client_url)?, sequencer_pub_key: public_keys.sequencer_public_key, sequencer_da_pub_key: public_keys.sequencer_da_pub_key, prover_da_pub_key: public_keys.prover_da_pub_key, @@ -218,7 +222,7 @@ where async fn process_l2_block( &mut self, l2_height: u64, - soft_confirmation: &GetSoftConfirmationResponse, + soft_confirmation: &SoftConfirmationResponse, ) -> anyhow::Result<()> { let current_l1_block = get_da_block_at_height( &self.da_service, @@ -320,7 +324,7 @@ where match last_scanned_l1_height { Some(height) => height.0, - None => get_initial_slot_height::(&self.sequencer_client).await, + None => get_initial_slot_height(&self.sequencer_client).await, } }; @@ -362,7 +366,7 @@ where }); let (l2_tx, mut l2_rx) = mpsc::channel(1); - let l2_sync_worker = sync_l2::( + let l2_sync_worker = sync_l2( self.start_l2_height, self.sequencer_client.clone(), l2_tx, @@ -372,7 +376,7 @@ where // Store L2 blocks and make sure they are processed in order. // Otherwise, processing N+1 L2 block before N would emit prev_hash mismatch. - let mut pending_l2_blocks: VecDeque<(u64, GetSoftConfirmationResponse)> = VecDeque::new(); + let mut pending_l2_blocks = VecDeque::new(); let mut interval = tokio::time::interval(Duration::from_secs(1)); interval.tick().await; @@ -390,7 +394,7 @@ where if let Err(e) = self.process_l2_block(*l2_height, l2_block).await { error!("Could not process L2 block: {}", e); // This block failed to process, add remaining L2 blocks to queue including this one. - let remaining_l2s: Vec<(u64, GetSoftConfirmationResponse)> = l2_blocks[index..].to_vec(); + let remaining_l2s = l2_blocks[index..].to_vec(); pending_l2_blocks.extend(remaining_l2s); break; } @@ -434,14 +438,12 @@ where } } -async fn sync_l2( +async fn sync_l2( start_l2_height: u64, - sequencer_client: SequencerClient, - sender: mpsc::Sender>, + sequencer_client: HttpClient, + sender: mpsc::Sender>, sync_blocks_count: u64, -) where - Da: DaService, -{ +) { let mut l2_height = start_l2_height; info!("Starting to sync from L2 height {}", l2_height); loop { @@ -451,43 +453,43 @@ async fn sync_l2( .build(); let inner_client = &sequencer_client; - let soft_confirmations: Vec = - match retry_backoff(exponential_backoff.clone(), || async move { - match inner_client - .get_soft_confirmation_range::( - l2_height..=l2_height + sync_blocks_count - 1, - ) - .await - { - Ok(soft_confirmations) => { - Ok(soft_confirmations.into_iter().flatten().collect::>()) - } - Err(e) => match e.downcast_ref::() { - Some(JsonrpseeError::Transport(e)) => { - let error_msg = format!( - "Soft Confirmation: connection error during RPC call: {:?}", - e - ); - debug!(error_msg); - Err(backoff::Error::Transient { - err: error_msg, - retry_after: None, - }) - } - _ => Err(backoff::Error::Transient { - err: format!("Soft Confirmation: unknown error from RPC call: {:?}", e), - retry_after: None, - }), - }, - } - }) - .await + let soft_confirmations = match retry_backoff(exponential_backoff.clone(), || async move { + match inner_client + .get_soft_confirmation_range( + U64::from(l2_height), + U64::from(l2_height + sync_blocks_count - 1), + ) + .await { - Ok(soft_confirmations) => soft_confirmations, - Err(_) => { - continue; + Ok(soft_confirmations) => { + Ok(soft_confirmations.into_iter().flatten().collect::>()) } - }; + Err(e) => match e { + JsonrpseeError::Transport(e) => { + let error_msg = format!( + "Soft Confirmation: connection error during RPC call: {:?}", + e + ); + debug!(error_msg); + Err(backoff::Error::Transient { + err: error_msg, + retry_after: None, + }) + } + _ => Err(backoff::Error::Transient { + err: format!("Soft Confirmation: unknown error from RPC call: {:?}", e), + retry_after: None, + }), + }, + } + }) + .await + { + Ok(soft_confirmations) => soft_confirmations, + Err(_) => { + continue; + } + }; if soft_confirmations.is_empty() { debug!( @@ -499,7 +501,7 @@ async fn sync_l2( continue; } - let mut soft_confirmations: Vec<(u64, GetSoftConfirmationResponse)> = (l2_height + let mut soft_confirmations: Vec<(u64, SoftConfirmationResponse)> = (l2_height ..l2_height + soft_confirmations.len() as u64) .zip(soft_confirmations) .collect(); @@ -516,9 +518,9 @@ async fn sync_l2( } } -async fn get_initial_slot_height(client: &SequencerClient) -> u64 { +async fn get_initial_slot_height(client: &HttpClient) -> u64 { loop { - match client.get_soft_confirmation::(1).await { + match client.get_soft_confirmation_by_number(U64::from(1)).await { Ok(Some(soft_confirmation)) => return soft_confirmation.da_slot_height, _ => { // sleep 1 diff --git a/crates/light-client-prover/Cargo.toml b/crates/light-client-prover/Cargo.toml index f8c07dc71..df53c7a23 100644 --- a/crates/light-client-prover/Cargo.toml +++ b/crates/light-client-prover/Cargo.toml @@ -12,10 +12,10 @@ repository.workspace = true # Citrea Deps citrea-common = { path = "../common", optional = true } citrea-primitives = { path = "../primitives", optional = true } -sequencer-client = { path = "../sequencer-client", optional = true } # Sov SDK deps sov-db = { path = "../sovereign-sdk/full-node/db/sov-db", optional = true } +sov-ledger-rpc = { path = "../sovereign-sdk/full-node/sov-ledger-rpc", features = ["client"], optional = true } sov-modules-api = { path = "../sovereign-sdk/module-system/sov-modules-api", default-features = false } sov-modules-rollup-blueprint = { path = "../sovereign-sdk/module-system/sov-modules-rollup-blueprint", optional = true } sov-rollup-interface = { path = "../sovereign-sdk/rollup-interface" } @@ -28,6 +28,7 @@ bincode = { workspace = true } borsh = { workspace = true } hex = { workspace = true } jsonrpsee = { workspace = true, optional = true, features = ["http-client", "server", "client"] } +reth-primitives = { workspace = true, optional = true } tokio = { workspace = true, optional = true } tokio-util = { workspace = true, optional = true } tower = { workspace = true, optional = true } @@ -43,14 +44,14 @@ default = [] native = [ "dep:citrea-primitives", "dep:citrea-common", - "dep:sequencer-client", "dep:sov-db", "dep:sov-modules-rollup-blueprint", "dep:sov-stf-runner", - + "dep:sov-ledger-rpc", "dep:anyhow", "dep:async-trait", "dep:jsonrpsee", + "dep:reth-primitives", "dep:tokio", "dep:tokio-util", "dep:tower", diff --git a/crates/light-client-prover/src/da_block_handler.rs b/crates/light-client-prover/src/da_block_handler.rs index b2e64c903..a5c06c829 100644 --- a/crates/light-client-prover/src/da_block_handler.rs +++ b/crates/light-client-prover/src/da_block_handler.rs @@ -7,9 +7,11 @@ use citrea_common::cache::L1BlockCache; use citrea_common::da::get_da_block_at_height; use citrea_common::LightClientProverConfig; use citrea_primitives::forks::FORKS; -use sequencer_client::SequencerClient; +use jsonrpsee::http_client::HttpClient; +use reth_primitives::U64; use sov_db::ledger_db::{LightClientProverLedgerOps, SharedLedgerOps}; use sov_db::schema::types::{SlotNumber, StoredLightClientProofOutput}; +use sov_ledger_rpc::LedgerRpcClient; use sov_modules_api::fork::fork_from_block_number; use sov_modules_api::{BatchProofCircuitOutput, BlobReaderTrait, DaSpec, Zkvm}; use sov_rollup_interface::da::{BlockHeaderTrait, DaDataLightClient, DaNamespace}; @@ -42,7 +44,7 @@ where light_client_proof_elfs: HashMap>, l1_block_cache: Arc>>, queued_l1_blocks: VecDeque<::FilteredBlock>, - sequencer_client: Arc, + sequencer_client: Arc, } impl L1BlockHandler @@ -62,7 +64,7 @@ where batch_proof_code_commitments: HashMap, light_client_proof_code_commitments: HashMap, light_client_proof_elfs: HashMap>, - sequencer_client: Arc, + sequencer_client: Arc, ) -> Self { Self { _prover_config: prover_config, @@ -194,7 +196,7 @@ where None => { let soft_confirmation = self .sequencer_client - .get_soft_confirmation::(1) + .get_soft_confirmation_by_number(U64::from(1)) .await? .unwrap(); let initial_l1_height = soft_confirmation.da_slot_height; diff --git a/crates/light-client-prover/src/runner.rs b/crates/light-client-prover/src/runner.rs index 4b8b63124..1675eeb5a 100644 --- a/crates/light-client-prover/src/runner.rs +++ b/crates/light-client-prover/src/runner.rs @@ -4,12 +4,13 @@ use std::sync::Arc; use citrea_common::tasks::manager::TaskManager; use citrea_common::{LightClientProverConfig, RollupPublicKeys, RpcConfig, RunnerConfig}; +use jsonrpsee::http_client::{HttpClient, HttpClientBuilder}; use jsonrpsee::server::{BatchRequestConfig, ServerBuilder}; use jsonrpsee::RpcModule; -use sequencer_client::SequencerClient; +use reth_primitives::U64; use sov_db::ledger_db::{LedgerDB, LightClientProverLedgerOps, SharedLedgerOps}; use sov_db::schema::types::SlotNumber; -use sov_modules_api::DaSpec; +use sov_ledger_rpc::LedgerRpcClient; use sov_modules_rollup_blueprint::RollupBlueprint; use sov_rollup_interface::services::da::DaService; use sov_rollup_interface::spec::SpecId; @@ -69,7 +70,7 @@ where rpc_config: RpcConfig, da_service: Arc, ledger_db: DB, - sequencer_client: SequencerClient, + sequencer_client: HttpClient, prover_service: Arc, prover_config: LightClientProverConfig, task_manager: TaskManager<()>, @@ -106,7 +107,7 @@ where rpc_config, da_service, ledger_db, - sequencer_client: SequencerClient::new(sequencer_client_url), + sequencer_client: HttpClientBuilder::default().build(sequencer_client_url)?, prover_service, prover_config, task_manager, @@ -185,7 +186,7 @@ where let last_l1_height_scanned = match self.ledger_db.get_last_scanned_l1_height()? { Some(l1_height) => l1_height, // If not found, start from the first L2 block's L1 height - None => SlotNumber(get_initial_da_height::(&self.sequencer_client).await), + None => SlotNumber(get_initial_da_height(&self.sequencer_client).await), }; let prover_config = self.prover_config.clone(); @@ -250,9 +251,9 @@ where } } -async fn get_initial_da_height(client: &SequencerClient) -> u64 { +async fn get_initial_da_height(client: &HttpClient) -> u64 { loop { - match client.get_soft_confirmation::(1).await { + match client.get_soft_confirmation_by_number(U64::from(1)).await { Ok(Some(batch)) => return batch.da_slot_height, _ => { // sleep 1 diff --git a/crates/sequencer-client/Cargo.toml b/crates/sequencer-client/Cargo.toml deleted file mode 100644 index 9cb8e654a..000000000 --- a/crates/sequencer-client/Cargo.toml +++ /dev/null @@ -1,41 +0,0 @@ -[package] -name = "sequencer-client" -authors = { workspace = true } -edition = { workspace = true } -homepage = { workspace = true } -license = { workspace = true } -repository = { workspace = true } - -version = { workspace = true } -publish = false -readme = "README.md" -resolver = "2" - -[dependencies] -# 3rd-party dependencies -anyhow = { workspace = true } -borsh = { workspace = true } -hex = { workspace = true } -jsonrpsee = { workspace = true, features = ["http-client"] } -serde = { workspace = true } -serde_json = { workspace = true } -tokio = { workspace = true } -tracing = { workspace = true } - -# Reth Deps -reth-primitives = { workspace = true } -reth-rpc-types = { workspace = true } - -# Sovereign-SDK deps -sov-rollup-interface = { path = "../sovereign-sdk/rollup-interface" } - -# Citrea Deps -citrea-primitives = { path = "../primitives" } - -[dev-dependencies] -tokio = { workspace = true } - -[features] -default = [] -local = [] -native = ["sov-rollup-interface/native"] diff --git a/crates/sequencer-client/README.md b/crates/sequencer-client/README.md deleted file mode 100644 index 14099a1d5..000000000 --- a/crates/sequencer-client/README.md +++ /dev/null @@ -1,3 +0,0 @@ -## Sequencer Client - -An HTTP client to connect to the [Citrea Sequencer](../sequencer/README.md), used by the full nodes, along with some utils for Soft Confirmations. diff --git a/crates/sequencer-client/src/lib.rs b/crates/sequencer-client/src/lib.rs deleted file mode 100644 index aa81ee5af..000000000 --- a/crates/sequencer-client/src/lib.rs +++ /dev/null @@ -1,175 +0,0 @@ -use std::fmt::Debug; -use std::ops::RangeInclusive; - -use borsh::BorshDeserialize; -use citrea_primitives::types::SoftConfirmationHash; -use jsonrpsee::core::client::{ClientT, Error}; -use jsonrpsee::http_client::{HttpClient, HttpClientBuilder}; -use jsonrpsee::rpc_params; -use reth_primitives::{Bytes, B256}; -use serde::Deserialize; -use sov_rollup_interface::rpc::HexTx; -use sov_rollup_interface::soft_confirmation::SignedSoftConfirmation; -use tracing::instrument; - -/// Configuration for SequencerClient. -#[derive(Debug, Clone)] -pub struct SequencerClient { - /// Host config for soft confirmation - pub rpc_url: String, - /// Client object for soft confirmation - pub client: HttpClient, -} - -impl SequencerClient { - /// Creates the sequencer client - #[instrument(level = "trace")] - pub fn new(rpc_url: String) -> Self { - let client = HttpClientBuilder::default().build(&rpc_url).unwrap(); - Self { rpc_url, client } - } - - /// Gets l2 block given l2 height - #[instrument(level = "trace", skip(self), ret)] - pub async fn get_soft_confirmation( - &self, - num: u64, - ) -> anyhow::Result> { - let res: Result, Error> = self - .client - .request("ledger_getSoftConfirmationByNumber", rpc_params![num]) - .await; - - match res { - Ok(res) => Ok(res), - Err(e) => match e { - Error::Transport(e) => anyhow::Result::Err(Error::Transport(e).into()), - _ => Err(anyhow::anyhow!(e)), - }, - } - } - - /// Gets l2 blocks given a range - #[instrument(level = "trace", skip(self), ret)] - pub async fn get_soft_confirmation_range( - &self, - range: RangeInclusive, - ) -> anyhow::Result>> { - let res: Result>, Error> = self - .client - .request( - "ledger_getSoftConfirmationRange", - rpc_params![range.start(), range.end()], - ) - .await; - - match res { - Ok(res) => Ok(res), - Err(e) => match e { - Error::Transport(e) => anyhow::Result::Err(Error::Transport(e).into()), - _ => Err(anyhow::anyhow!(e)), - }, - } - } - - /// Gets l2 block height - #[instrument(level = "trace", skip(self), ret)] - pub async fn block_number(&self) -> Result { - self.client - .request("ledger_getHeadSoftConfirmationHeight", rpc_params![]) - .await - } - - /// Sends raw tx to sequencer - #[instrument(level = "trace", skip_all, ret)] - pub async fn send_raw_tx(&self, tx: Bytes) -> Result { - self.client - .request("eth_sendRawTransaction", rpc_params![tx]) - .await - } - - #[instrument(level = "trace", skip(self), ret)] - pub async fn get_tx_by_hash( - &self, - tx_hash: B256, - mempool_only: Option, - ) -> Result, Error> { - self.client - .request( - "eth_getTransactionByHash", - rpc_params![tx_hash, mempool_only], - ) - .await - } - - #[instrument(level = "trace", skip(self), ret)] - pub async fn get_l2_genesis_state_root(&self) -> Result>, Error> { - self.client - .request("ledger_getL2GenesisStateRoot", rpc_params![]) - .await - } -} - -#[derive(Deserialize, Debug, Clone)] -#[serde(rename_all = "camelCase")] -pub struct GetSoftConfirmationResponse { - pub l2_height: u64, - #[serde(with = "hex::serde")] - pub hash: SoftConfirmationHash, - #[serde(with = "hex::serde")] - pub prev_hash: SoftConfirmationHash, - pub da_slot_height: u64, - #[serde(with = "hex::serde")] - pub da_slot_hash: [u8; 32], - #[serde(with = "hex::serde")] - pub da_slot_txs_commitment: [u8; 32], - #[serde(skip_serializing_if = "Option::is_none")] - pub txs: Option>, - #[serde(with = "hex::serde")] - pub state_root: Vec, - #[serde(with = "hex::serde")] - pub soft_confirmation_signature: Vec, - pub deposit_data: Vec, // Vec wrapper around deposit data - #[serde(with = "hex::serde")] - pub pub_key: Vec, - pub l1_fee_rate: u128, - pub timestamp: u64, -} - -impl<'txs, Tx> TryFrom for SignedSoftConfirmation<'txs, Tx> -where - Tx: Clone + BorshDeserialize, -{ - type Error = borsh::io::Error; - fn try_from(val: GetSoftConfirmationResponse) -> Result { - let parsed_txs = val - .txs - .iter() - .flatten() - .map(|tx| { - let body = &tx.tx; - borsh::from_slice::(body) - }) - .collect::, Self::Error>>()?; - let res = SignedSoftConfirmation::new( - val.l2_height, - val.hash, - val.prev_hash, - val.da_slot_height, - val.da_slot_hash, - val.da_slot_txs_commitment, - val.l1_fee_rate, - val.txs - .unwrap_or_default() - .into_iter() - .map(|tx| tx.tx) - .collect(), - parsed_txs.into(), - val.deposit_data.into_iter().map(|tx| tx.tx).collect(), - val.soft_confirmation_signature, - val.pub_key, - val.timestamp, - ); - Ok(res) - } -} diff --git a/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs b/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs index 0788a0d29..5d7e18205 100644 --- a/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs +++ b/crates/sovereign-sdk/rollup-interface/src/node/rpc/mod.rs @@ -12,6 +12,7 @@ use borsh::{BorshDeserialize, BorshSerialize}; use serde::{Deserialize, Serialize}; use crate::da::SequencerCommitment; +use crate::soft_confirmation::SignedSoftConfirmation; use crate::zk::{BatchProofInfo, CumulativeStateDiff}; /// A struct containing enough information to uniquely specify single batch. @@ -83,6 +84,44 @@ pub struct SoftConfirmationResponse { pub timestamp: u64, } +impl<'txs, Tx> TryFrom for SignedSoftConfirmation<'txs, Tx> +where + Tx: Clone + BorshDeserialize, +{ + type Error = borsh::io::Error; + fn try_from(val: SoftConfirmationResponse) -> Result { + let parsed_txs = val + .txs + .iter() + .flatten() + .map(|tx| { + let body = &tx.tx; + borsh::from_slice::(body) + }) + .collect::, Self::Error>>()?; + let res = SignedSoftConfirmation::new( + val.l2_height, + val.hash, + val.prev_hash, + val.da_slot_height, + val.da_slot_hash, + val.da_slot_txs_commitment, + val.l1_fee_rate, + val.txs + .unwrap_or_default() + .into_iter() + .map(|tx| tx.tx) + .collect(), + parsed_txs.into(), + val.deposit_data.into_iter().map(|tx| tx.tx).collect(), + val.soft_confirmation_signature, + val.pub_key, + val.timestamp, + ); + Ok(res) + } +} + /// The response to a JSON-RPC request for sequencer commitments on a DA Slot. #[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] From 5310950a46d06d678d2c7bc75cfbe1b92c754de9 Mon Sep 17 00:00:00 2001 From: Esad Yusuf Atik Date: Sat, 14 Dec 2024 02:22:59 +0300 Subject: [PATCH 06/10] make testnet4 reorg depth 30 (#1607) Co-authored-by: jfldde <168934971+jfldde@users.noreply.github.com> --- Cargo.lock | 2 +- Cargo.toml | 2 +- .../bitcoin_e2e/sequencer_commitments.rs | 22 +++++-------------- bin/citrea/tests/bitcoin_e2e/tx_chain.rs | 9 +++++++- crates/batch-prover/src/runner.rs | 1 + crates/bitcoin-da/src/service.rs | 2 +- 6 files changed, 18 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 38285a9de..ba276ac1c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1836,7 +1836,7 @@ dependencies = [ [[package]] name = "citrea-e2e" version = "0.1.0" -source = "git+https://github.com/chainwayxyz/citrea-e2e?rev=423db61#423db6182000d4b94b121eed05256de1b4bd0a7c" +source = "git+https://github.com/chainwayxyz/citrea-e2e?rev=6ba7230#6ba7230a137931c0d7a002092f0b38beb4d73d17" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 7c2470576..9061ee790 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -149,7 +149,7 @@ tower-http = { version = "0.5.0", features = ["full"] } tower = { version = "0.4.13", features = ["full"] } hyper = { version = "1.4.0" } -citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "423db61" } +citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "6ba7230" } [patch.crates-io] bitcoincore-rpc = { version = "0.18.0", git = "https://github.com/chainwayxyz/rust-bitcoincore-rpc.git", rev = "ca3cfa2" } diff --git a/bin/citrea/tests/bitcoin_e2e/sequencer_commitments.rs b/bin/citrea/tests/bitcoin_e2e/sequencer_commitments.rs index df90ec252..751eaf70e 100644 --- a/bin/citrea/tests/bitcoin_e2e/sequencer_commitments.rs +++ b/bin/citrea/tests/bitcoin_e2e/sequencer_commitments.rs @@ -204,7 +204,7 @@ struct SequencerSendCommitmentsToDaTest; impl TestCase for SequencerSendCommitmentsToDaTest { fn sequencer_config() -> SequencerConfig { SequencerConfig { - min_soft_confirmations_per_commitment: 12, + min_soft_confirmations_per_commitment: FINALITY_DEPTH * 2, ..Default::default() } } @@ -246,13 +246,6 @@ impl TestCase for SequencerSendCommitmentsToDaTest { // Publish one more L2 block and send commitment sequencer.client.send_publish_batch_request().await?; - sequencer - .wait_for_l2_height( - min_soft_confirmations_per_commitment + FINALITY_DEPTH - 1, - None, - ) - .await?; - // Wait for blob tx to hit the mempool da.wait_mempool_len(2, None).await?; @@ -261,7 +254,10 @@ impl TestCase for SequencerSendCommitmentsToDaTest { tokio::time::sleep(std::time::Duration::from_millis(1000)).await; let start_l2_block = 1; - let end_l2_block = 19; + let end_l2_block = sequencer + .client + .ledger_get_head_soft_confirmation_height() + .await?; self.check_sequencer_commitment(sequencer, da, start_l2_block, end_l2_block) .await?; @@ -269,12 +265,6 @@ impl TestCase for SequencerSendCommitmentsToDaTest { for _ in 0..min_soft_confirmations_per_commitment { sequencer.client.send_publish_batch_request().await?; } - sequencer - .wait_for_l2_height( - end_l2_block + min_soft_confirmations_per_commitment + FINALITY_DEPTH - 2, - None, - ) - .await?; // Wait for blob tx to hit the mempool da.wait_mempool_len(2, None).await?; @@ -282,7 +272,7 @@ impl TestCase for SequencerSendCommitmentsToDaTest { da.generate(FINALITY_DEPTH).await?; let start_l2_block = end_l2_block + 1; - let end_l2_block = end_l2_block + 12; + let end_l2_block = end_l2_block + min_soft_confirmations_per_commitment; self.check_sequencer_commitment(sequencer, da, start_l2_block, end_l2_block) .await?; diff --git a/bin/citrea/tests/bitcoin_e2e/tx_chain.rs b/bin/citrea/tests/bitcoin_e2e/tx_chain.rs index b7ea1ef79..5f5ebd141 100644 --- a/bin/citrea/tests/bitcoin_e2e/tx_chain.rs +++ b/bin/citrea/tests/bitcoin_e2e/tx_chain.rs @@ -3,7 +3,7 @@ use bitcoin::{Amount, Transaction}; use bitcoin_da::REVEAL_OUTPUT_AMOUNT; use bitcoincore_rpc::RpcApi; use citrea_e2e::bitcoin::{BitcoinNode, FINALITY_DEPTH}; -use citrea_e2e::config::TestCaseConfig; +use citrea_e2e::config::{SequencerConfig, TestCaseConfig}; use citrea_e2e::framework::TestFramework; use citrea_e2e::sequencer::Sequencer; use citrea_e2e::test_case::{TestCase, TestCaseRunner}; @@ -275,6 +275,13 @@ impl TestCase for TestProverTransactionChaining { } } + fn sequencer_config() -> SequencerConfig { + SequencerConfig { + min_soft_confirmations_per_commitment: FINALITY_DEPTH * 2, + ..Default::default() + } + } + async fn run_test(&mut self, f: &mut TestFramework) -> Result<()> { let sequencer = f.sequencer.as_mut().unwrap(); let batch_prover = f.batch_prover.as_mut().unwrap(); diff --git a/crates/batch-prover/src/runner.rs b/crates/batch-prover/src/runner.rs index 00c9184db..b91e8cd97 100644 --- a/crates/batch-prover/src/runner.rs +++ b/crates/batch-prover/src/runner.rs @@ -354,6 +354,7 @@ where // This block failed to process, add remaining L2 blocks to queue including this one. let remaining_l2s = l2_blocks[index..].to_vec(); pending_l2_blocks.extend(remaining_l2s); + break; } } continue; diff --git a/crates/bitcoin-da/src/service.rs b/crates/bitcoin-da/src/service.rs index 24e924702..79763dc6e 100644 --- a/crates/bitcoin-da/src/service.rs +++ b/crates/bitcoin-da/src/service.rs @@ -60,7 +60,7 @@ use crate::spec::{BitcoinSpec, RollupParams}; use crate::verifier::BitcoinVerifier; use crate::REVEAL_OUTPUT_AMOUNT; -pub const FINALITY_DEPTH: u64 = 8; // blocks +pub const FINALITY_DEPTH: u64 = 30; // blocks const POLLING_INTERVAL: u64 = 10; // seconds /// Runtime configuration for the DA service From 25eadad692eea277ea02fe8ad6ad905acd282d0b Mon Sep 17 00:00:00 2001 From: Rakan Al-Huneiti Date: Mon, 16 Dec 2024 14:27:41 +0300 Subject: [PATCH 07/10] Prometheus metrics (#1589) --- Cargo.lock | 270 ++++++- Cargo.toml | 45 +- bin/citrea/Cargo.toml | 3 + bin/citrea/src/main.rs | 28 +- bin/citrea/tests/test_helpers/mod.rs | 1 + crates/batch-prover/Cargo.toml | 3 + crates/batch-prover/src/da_block_handler.rs | 3 + crates/batch-prover/src/lib.rs | 1 + crates/batch-prover/src/metrics.rs | 20 + crates/batch-prover/src/runner.rs | 12 +- crates/bitcoin-da/Cargo.toml | 2 + .../helpers/builders/batch_proof_namespace.rs | 10 +- crates/common/src/config.rs | 84 ++ crates/fullnode/Cargo.toml | 3 + crates/fullnode/src/da_block_handler.rs | 14 + crates/fullnode/src/lib.rs | 1 + crates/fullnode/src/metrics.rs | 22 + crates/fullnode/src/runner.rs | 11 + crates/light-client-prover/Cargo.toml | 6 + .../src/da_block_handler.rs | 4 + crates/light-client-prover/src/lib.rs | 2 + crates/light-client-prover/src/metrics.rs | 16 + crates/risc0/Cargo.toml | 2 + crates/risc0/src/host.rs | 3 + crates/sequencer/Cargo.toml | 3 + crates/sequencer/src/commitment/mod.rs | 13 + crates/sequencer/src/lib.rs | 1 + crates/sequencer/src/mempool.rs | 4 + crates/sequencer/src/metrics.rs | 28 + crates/sequencer/src/rpc.rs | 3 + crates/sequencer/src/runner.rs | 20 +- .../db/sov-db/src/ledger_db/traits.rs | 2 + .../full-node/db/sov-schema-db/Cargo.toml | 9 +- .../db/sov-schema-db/src/iterator.rs | 19 +- .../full-node/db/sov-schema-db/src/lib.rs | 50 +- .../full-node/db/sov-schema-db/src/metrics.rs | 142 +--- .../db/sov-schema-db/src/schema_batch.rs | 13 +- docker/docker-compose.telemetry.yaml | 37 + docker/telemetry/prometheus.yml | 22 + resources/grafana/batch-prover.dashboard.json | 469 +++++++++++ resources/grafana/fullnode.dashboard.json | 374 +++++++++ resources/grafana/light-client.dashboard.json | 113 +++ resources/grafana/sequencer.dashboard.json | 729 ++++++++++++++++++ 43 files changed, 2423 insertions(+), 194 deletions(-) create mode 100644 crates/batch-prover/src/metrics.rs create mode 100644 crates/fullnode/src/metrics.rs create mode 100644 crates/light-client-prover/src/metrics.rs create mode 100644 crates/sequencer/src/metrics.rs create mode 100644 docker/docker-compose.telemetry.yaml create mode 100644 docker/telemetry/prometheus.yml create mode 100644 resources/grafana/batch-prover.dashboard.json create mode 100644 resources/grafana/fullnode.dashboard.json create mode 100644 resources/grafana/light-client.dashboard.json create mode 100644 resources/grafana/sequencer.dashboard.json diff --git a/Cargo.lock b/Cargo.lock index ba276ac1c..259ade3d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1052,6 +1052,32 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" +[[package]] +name = "aws-lc-rs" +version = "1.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f47bb8cc16b669d267eeccf585aea077d0882f4777b1c1f740217885d6e6e5a3" +dependencies = [ + "aws-lc-sys", + "paste", + "zeroize", +] + +[[package]] +name = "aws-lc-sys" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2101df3813227bbaaaa0b04cd61c534c7954b22bd68d399b440be937dc63ff7" +dependencies = [ + "bindgen", + "cc", + "cmake", + "dunce", + "fs_extra", + "libc", + "paste", +] + [[package]] name = "backoff" version = "0.4.0" @@ -1167,12 +1193,15 @@ dependencies = [ "itertools 0.12.1", "lazy_static", "lazycell", + "log", + "prettyplease", "proc-macro2", "quote", "regex", "rustc-hash 1.1.0", "shlex", "syn 2.0.87", + "which 4.4.2", ] [[package]] @@ -1232,6 +1261,7 @@ dependencies = [ "hex", "itertools 0.13.0", "jsonrpsee", + "metrics", "pin-project", "rand 0.8.5", "reqwest", @@ -1730,6 +1760,9 @@ dependencies = [ "lazy_static", "log", "log-panics", + "metrics", + "metrics-exporter-prometheus", + "metrics-util", "prover-services", "regex", "reqwest", @@ -1778,7 +1811,10 @@ dependencies = [ "futures", "hex", "jsonrpsee", + "metrics", + "metrics-derive", "num_cpus", + "once_cell", "parking_lot", "prover-services", "rand 0.8.5", @@ -1917,6 +1953,9 @@ dependencies = [ "futures", "hex", "jsonrpsee", + "metrics", + "metrics-derive", + "once_cell", "rand 0.8.5", "reth-primitives", "rs_merkle", @@ -1951,6 +1990,9 @@ dependencies = [ "citrea-primitives", "hex", "jsonrpsee", + "metrics", + "metrics-derive", + "once_cell", "reth-primitives", "sov-db", "sov-ledger-rpc", @@ -2007,6 +2049,7 @@ dependencies = [ "bonsai-sdk", "borsh", "hex", + "metrics", "risc0-zkvm", "serde", "sov-db", @@ -2034,6 +2077,9 @@ dependencies = [ "hex", "hyper", "jsonrpsee", + "metrics", + "metrics-derive", + "once_cell", "parking_lot", "reth-chainspec", "reth-db", @@ -2143,6 +2189,15 @@ version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" +[[package]] +name = "cmake" +version = "0.1.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c682c223677e0e5b6b7f63a64b9351844c3f1b1678a68b7ee617e30fb082620e" +dependencies = [ + "cc", +] + [[package]] name = "colorchoice" version = "1.0.3" @@ -2209,6 +2264,16 @@ dependencies = [ "libc", ] +[[package]] +name = "core-foundation" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b55271e5c8c478ad3f38ad24ef34923091e0548492a266d19b3c0b4d82574c63" +dependencies = [ + "core-foundation-sys", + "libc", +] + [[package]] name = "core-foundation-sys" version = "0.8.7" @@ -2222,7 +2287,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf" dependencies = [ "bitflags 1.3.2", - "core-foundation", + "core-foundation 0.9.4", "libc", ] @@ -2744,6 +2809,12 @@ dependencies = [ "zeroize", ] +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + [[package]] name = "enr" version = "0.12.1" @@ -2990,6 +3061,12 @@ dependencies = [ "percent-encoding", ] +[[package]] +name = "fs_extra" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" + [[package]] name = "funty" version = "2.0.0" @@ -3472,6 +3549,7 @@ dependencies = [ "hyper-util", "log", "rustls", + "rustls-native-certs 0.8.1", "rustls-pki-types", "tokio", "tokio-rustls", @@ -4231,7 +4309,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" dependencies = [ "cfg-if", - "windows-targets 0.48.5", + "windows-targets 0.52.6", ] [[package]] @@ -4435,6 +4513,58 @@ dependencies = [ "portable-atomic", ] +[[package]] +name = "metrics-derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3dbdd96ed57d565ec744cba02862d707acf373c5772d152abae6ec5c4e24f6c" +dependencies = [ + "proc-macro2", + "quote", + "regex", + "syn 2.0.87", +] + +[[package]] +name = "metrics-exporter-prometheus" +version = "0.15.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4f0c8427b39666bf970460908b213ec09b3b350f20c0c2eabcbba51704a08e6" +dependencies = [ + "base64 0.22.1", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "indexmap 2.6.0", + "ipnet", + "metrics", + "metrics-util", + "quanta", + "thiserror", + "tokio", + "tracing", +] + +[[package]] +name = "metrics-util" +version = "0.17.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4259040465c955f9f2f1a4a8a16dc46726169bca0f88e8fb2dbeced487c3e828" +dependencies = [ + "aho-corasick", + "crossbeam-epoch", + "crossbeam-utils", + "hashbrown 0.14.5", + "indexmap 2.6.0", + "metrics", + "num_cpus", + "ordered-float", + "quanta", + "radix_trie", + "sketches-ddsketch", +] + [[package]] name = "mime" version = "0.3.17" @@ -4521,6 +4651,15 @@ dependencies = [ "rayon", ] +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + [[package]] name = "nom" version = "7.1.3" @@ -4757,6 +4896,15 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" +[[package]] +name = "ordered-float" +version = "4.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c65ee1f9701bf938026630b455d5315f490640234259037edb259798b3bcf85e" +dependencies = [ + "num-traits", +] + [[package]] name = "overload" version = "0.1.1" @@ -4985,6 +5133,16 @@ dependencies = [ "zerocopy", ] +[[package]] +name = "prettyplease" +version = "0.2.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64d1ec885c64d0457d564db4ec299b2dae3f9c02808b8ad9c3a089c591b18033" +dependencies = [ + "proc-macro2", + "syn 2.0.87", +] + [[package]] name = "primitive-types" version = "0.12.2" @@ -5038,20 +5196,6 @@ dependencies = [ "unicode-ident", ] -[[package]] -name = "prometheus" -version = "0.13.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d33c28a30771f7f96db69893f78b857f7450d7e0237e9c8fc6427a81bae7ed1" -dependencies = [ - "cfg-if", - "fnv", - "lazy_static", - "memchr", - "parking_lot", - "thiserror", -] - [[package]] name = "proptest" version = "1.5.0" @@ -5163,6 +5307,21 @@ dependencies = [ "parking_lot", ] +[[package]] +name = "quanta" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5167a477619228a0b284fac2674e3c388cba90631d7b7de620e6f1fcd08da5" +dependencies = [ + "crossbeam-utils", + "libc", + "once_cell", + "raw-cpuid", + "wasi 0.11.0+wasi-snapshot-preview1", + "web-sys", + "winapi", +] + [[package]] name = "quick-error" version = "1.2.3" @@ -5233,6 +5392,16 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dc33ff2d4973d518d823d61aa239014831e521c75da58e3df4840d3f47749d09" +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + [[package]] name = "rand" version = "0.7.3" @@ -5313,6 +5482,15 @@ dependencies = [ "rand_core 0.6.4", ] +[[package]] +name = "raw-cpuid" +version = "11.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ab240315c661615f2ee9f0f2cd32d5a7343a84d5ebcccb99d46e6637565e7b0" +dependencies = [ + "bitflags 2.6.0", +] + [[package]] name = "rawpointer" version = "0.2.1" @@ -6404,7 +6582,7 @@ dependencies = [ "rayon", "sha2", "tempfile", - "which", + "which 6.0.3", ] [[package]] @@ -6799,6 +6977,7 @@ version = "0.23.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c9cc1d47e243d655ace55ed38201c19ae02c148ae56412ab8750e8f0166ab7f" dependencies = [ + "aws-lc-rs", "log", "once_cell", "ring", @@ -6818,7 +6997,19 @@ dependencies = [ "rustls-pemfile", "rustls-pki-types", "schannel", - "security-framework", + "security-framework 2.11.1", +] + +[[package]] +name = "rustls-native-certs" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fcff2dd52b58a8d98a70243663a0d234c4e2b79235637849d15913394a247d3" +dependencies = [ + "openssl-probe", + "rustls-pki-types", + "schannel", + "security-framework 3.0.1", ] [[package]] @@ -6842,16 +7033,16 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "afbb878bdfdf63a336a5e63561b1835e7a8c91524f51621db870169eac84b490" dependencies = [ - "core-foundation", + "core-foundation 0.9.4", "core-foundation-sys", "jni", "log", "once_cell", "rustls", - "rustls-native-certs", + "rustls-native-certs 0.7.3", "rustls-platform-verifier-android", "rustls-webpki", - "security-framework", + "security-framework 2.11.1", "security-framework-sys", "webpki-roots", "winapi", @@ -6869,6 +7060,7 @@ version = "0.102.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "64ca1bc8749bd4cf37b5ce386cc146580777b4e8572c7b97baf22c83f444bee9" dependencies = [ + "aws-lc-rs", "ring", "rustls-pki-types", "untrusted", @@ -7010,13 +7202,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "897b2245f0b511c87893af39b033e5ca9cce68824c4d7e7630b5a1d339658d02" dependencies = [ "bitflags 2.6.0", - "core-foundation", + "core-foundation 0.9.4", "core-foundation-sys", "libc", "num-bigint 0.4.6", "security-framework-sys", ] +[[package]] +name = "security-framework" +version = "3.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1415a607e92bec364ea2cf9264646dcce0f91e6d65281bd6f2819cca3bf39c8" +dependencies = [ + "bitflags 2.6.0", + "core-foundation 0.10.0", + "core-foundation-sys", + "libc", + "security-framework-sys", +] + [[package]] name = "security-framework-sys" version = "2.12.1" @@ -7291,6 +7496,12 @@ dependencies = [ "time", ] +[[package]] +name = "sketches-ddsketch" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85636c14b73d81f541e525f585c0a2109e6744e1565b5c1668e31c70c10ed65c" + [[package]] name = "slab" version = "0.4.9" @@ -7599,8 +7810,9 @@ version = "0.5.0-rc.1" dependencies = [ "anyhow", "byteorder", + "metrics", + "metrics-derive", "once_cell", - "prometheus", "rocksdb", "sov-schema-db", "tempfile", @@ -8617,6 +8829,18 @@ dependencies = [ "rustls-pki-types", ] +[[package]] +name = "which" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87ba24419a2078cd2b0f2ede2691b6c66d8e47836da3b6db8265ebad47afbfc7" +dependencies = [ + "either", + "home", + "once_cell", + "rustix", +] + [[package]] name = "which" version = "6.0.3" diff --git a/Cargo.toml b/Cargo.toml index 9061ee790..54a8d1c97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,9 +48,6 @@ publish = false repository = "https://github.com/chainwayxyz/citrea" [workspace.dependencies] -# Dependencies maintained by Sovereign -jmt = { git = "https://github.com/penumbra-zone/jmt.git", rev = "fd1c8ef" } - # External dependencies async-trait = "0.1.71" anyhow = { version = "1.0.68", default-features = false } @@ -62,46 +59,55 @@ bincode = "1.3.3" bitcoin = { version = "0.32.2", features = ["serde", "rand"] } bitcoincore-rpc = { version = "0.18.0" } bcs = "0.1.6" +bech32 = { version = "0.9.1", default-features = false } brotli = "7" byteorder = { version = "1.5.0", default-features = false } bytes = { version = "1.2.1", default-features = false } chrono = { version = "0.4.37", default-features = false } +clap = { version = "4.4.10", features = ["derive"] } crypto-bigint = { version = "0.5.5" } digest = { version = "0.10.6", default-features = false, features = ["alloc"] } +derive_more = { version = "0.99.11", default-features = false } +ed25519-dalek = { version = "2", default-features = false, features = ["serde", "fast"] } +futures = "0.3" +hyper = { version = "1.4.0" } itertools = { version = "0.13.0", default-features = false } +jmt = { git = "https://github.com/penumbra-zone/jmt.git", rev = "fd1c8ef" } +jsonrpsee = { version = "0.24.2", features = ["jsonrpsee-types"] } lru = "0.12.3" -rs_merkle = "1.4.2" -futures = "0.3" -pin-project = { version = "1.1.3" } hex = { version = "0.4.3", default-features = false, features = ["alloc", "serde"] } lazy_static = { version = "1.5.0" } log-panics = { version = "2", features = ["with-backtrace"] } once_cell = { version = "1.19.0", default-features = false, features = ["alloc"] } +metrics = { version = "0.23.0" } +metrics-derive = { version = "0.1.0" } +metrics-exporter-prometheus = { version = "0.15.3" } +metrics-util = { version = "0.17.0" } +num_cpus = "1.0" parking_lot = { version = "0.12.3" } -prometheus = { version = "0.13.3", default-features = false } proptest = { version = "1.3.1", default-features = false, features = ["alloc"] } +pin-project = { version = "1.1.3" } rand = "0.8" rayon = "1.8.0" rlimit = "0.10.2" rustc_version_runtime = { version = "0.3.0", default-features = false } +rs_merkle = "1.4.2" reqwest = { version = "0.12.5", features = ["rustls-tls", "json", "http2"], default-features = false } rocksdb = { version = "0.22.0", features = ["lz4"], default-features = false } serde = { version = "1.0.192", default-features = false, features = ["alloc", "derive"] } serde_json = { version = "1.0", default-features = false, features = ["alloc"] } sha2 = { version = "0.10.8", default-features = false } +schemars = { version = "0.8.16", features = ["derive"] } +secp256k1 = { version = "0.29.0", default-features = false, features = ["global-context", "recovery"] } thiserror = "1.0.50" tracing = { version = "0.1.40", default-features = false, features = ["attributes"] } tracing-subscriber = { version = "0.3.17", features = ["env-filter", "json", "fmt"] } -bech32 = { version = "0.9.1", default-features = false } -derive_more = { version = "0.99.11", default-features = false } -clap = { version = "4.4.10", features = ["derive"] } toml = "0.8.0" -jsonrpsee = { version = "0.24.2", features = ["jsonrpsee-types"] } -schemars = { version = "0.8.16", features = ["derive"] } tempfile = "3.8" tokio = { version = "1.40", features = ["full"] } tokio-util = { version = "0.7.12", features = ["rt"] } -num_cpus = "1.0" +tower-http = { version = "0.5.0", features = ["full"] } +tower = { version = "0.4.13", features = ["full"] } # Risc0 dependencies risc0-binfmt = { version = "1.1.3" } @@ -113,6 +119,9 @@ risc0-build = { version = "1.1.3" } bonsai-sdk = { version = "1.1.3" } # EVM dependencies +revm = { version = "12.1", features = ["serde"], default-features = false } +# forcing cargo for this version or else chooses 3.1.1 and there is some dependency conflicts +revm-primitives = { version = "8", default-features = false } revm-inspectors = { version = "=0.5.5", default-features = false } reth-primitives = { git = "https://github.com/paradigmxyz/reth", rev = "a206eb3690e5a51d3c797fed2a6ed722e36863eb", default-features = false } reth-chainspec = { git = "https://github.com/paradigmxyz/reth", rev = "a206eb3690e5a51d3c797fed2a6ed722e36863eb", default-features = false } @@ -131,9 +140,6 @@ reth-trie = { git = "https://github.com/paradigmxyz/reth", rev = "a206eb3690e5a5 reth-rpc = { git = "https://github.com/paradigmxyz/reth", rev = "a206eb3690e5a51d3c797fed2a6ed722e36863eb", default-features = false } reth-stages = { git = "https://github.com/paradigmxyz/reth", rev = "a206eb3690e5a51d3c797fed2a6ed722e36863eb", default-features = false } -revm = { version = "12.1", features = ["serde"], default-features = false } -# forcing cargo for this version or else chooses 3.1.1 and there is some dependency conflicts -revm-primitives = { version = "8", default-features = false } alloy-trie = { version = "0.3.8", default-features = false } alloy-rlp = { version = "0.3.8", default-features = false } alloy-primitives = { version = "0.7.7", default-features = false } @@ -142,13 +148,6 @@ alloy = { version = "0.2.1", default-features = false } alloy-eips = { version = "0.2.1", default-features = false } alloy-consensus = { version = "0.2.1", default-features = false } -ed25519-dalek = { version = "2", default-features = false, features = ["serde", "fast"] } -secp256k1 = { version = "0.29.0", default-features = false, features = ["global-context", "recovery"] } - -tower-http = { version = "0.5.0", features = ["full"] } -tower = { version = "0.4.13", features = ["full"] } -hyper = { version = "1.4.0" } - citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "6ba7230" } [patch.crates-io] diff --git a/bin/citrea/Cargo.toml b/bin/citrea/Cargo.toml index de0c37333..391db9caf 100644 --- a/bin/citrea/Cargo.toml +++ b/bin/citrea/Cargo.toml @@ -51,6 +51,9 @@ hex = { workspace = true, optional = true } jsonrpsee = { workspace = true, features = ["http-client", "server"] } lazy_static = { workspace = true } log-panics = { workspace = true } +metrics = { workspace = true } +metrics-exporter-prometheus = { workspace = true, default-features = true } +metrics-util = { workspace = true } reth-primitives = { workspace = true } reth-rpc-types = { workspace = true } reth-transaction-pool = { workspace = true } diff --git a/bin/citrea/src/main.rs b/bin/citrea/src/main.rs index b1f26a7b4..82523fc21 100644 --- a/bin/citrea/src/main.rs +++ b/bin/citrea/src/main.rs @@ -1,6 +1,8 @@ use core::fmt::Debug as DebugTrait; +use std::net::SocketAddr; +use std::time::Duration; -use anyhow::Context as _; +use anyhow::{anyhow, Context as _}; use bitcoin_da::service::BitcoinServiceConfig; use citrea::{ initialize_logging, BitcoinRollup, CitreaRollupBlueprint, MockDemoRollup, NetworkArg, @@ -11,11 +13,13 @@ use citrea_common::{ }; use citrea_stf::genesis_config::GenesisPaths; use clap::Parser; +use metrics_exporter_prometheus::PrometheusBuilder; +use metrics_util::MetricKindMask; use sov_mock_da::MockDaConfig; use sov_modules_api::Spec; use sov_modules_rollup_blueprint::{Network, RollupBlueprint}; use sov_state::storage::NativeStorage; -use tracing::{error, info, instrument}; +use tracing::{debug, error, info, instrument}; #[cfg(test)] mod test_rpc; @@ -201,6 +205,26 @@ where None => FullNodeConfig::from_env() .context("Failed to read rollup configuration from the environment")?, }; + + if rollup_config.telemetry.bind_host.is_some() && rollup_config.telemetry.bind_port.is_some() { + let bind_host = rollup_config.telemetry.bind_host.as_ref().unwrap(); + let bind_port = rollup_config.telemetry.bind_port.as_ref().unwrap(); + let telemetry_addr: SocketAddr = format!("{}:{}", bind_host, bind_port) + .parse() + .map_err(|_| anyhow!("Invalid telemetry address"))?; + + debug!("Starting telemetry server on: {}", telemetry_addr); + + let builder = PrometheusBuilder::new().with_http_listener(telemetry_addr); + builder + .idle_timeout( + MetricKindMask::GAUGE | MetricKindMask::HISTOGRAM, + Some(Duration::from_secs(30)), + ) + .install() + .map_err(|_| anyhow!("failed to install Prometheus recorder"))?; + } + let rollup_blueprint = S::new(network); if let Some(sequencer_config) = sequencer_config { diff --git a/bin/citrea/tests/test_helpers/mod.rs b/bin/citrea/tests/test_helpers/mod.rs index 8f1b51f93..97b451c79 100644 --- a/bin/citrea/tests/test_helpers/mod.rs +++ b/bin/citrea/tests/test_helpers/mod.rs @@ -184,6 +184,7 @@ pub fn create_default_rollup_config( sender_address: MockAddress::from([0; 32]), db_path: da_path.to_path_buf(), }, + telemetry: Default::default(), } } diff --git a/crates/batch-prover/Cargo.toml b/crates/batch-prover/Cargo.toml index 1d7d9d1e9..a5be76779 100644 --- a/crates/batch-prover/Cargo.toml +++ b/crates/batch-prover/Cargo.toml @@ -31,7 +31,10 @@ borsh = { workspace = true } futures = { workspace = true } hex = { workspace = true } jsonrpsee = { workspace = true, features = ["http-client", "server", "client"] } +metrics = { workspace = true } +metrics-derive = { workspace = true } num_cpus = { workspace = true } +once_cell = { workspace = true, default-features = true } parking_lot = { workspace = true } rand = { workspace = true } rayon = { workspace = true } diff --git a/crates/batch-prover/src/da_block_handler.rs b/crates/batch-prover/src/da_block_handler.rs index bdd2f1fed..047e3a8e4 100644 --- a/crates/batch-prover/src/da_block_handler.rs +++ b/crates/batch-prover/src/da_block_handler.rs @@ -33,6 +33,7 @@ use tokio_util::sync::CancellationToken; use tracing::{error, info, warn}; use crate::errors::L1ProcessingError; +use crate::metrics::BATCH_PROVER_METRICS; use crate::proving::{data_to_prove, extract_and_store_proof, prove_l1, GroupCommitments}; type CommitmentStateTransitionData<'txs, Witness, Da, Tx> = ( @@ -270,6 +271,8 @@ where ); } + BATCH_PROVER_METRICS.current_l1_block.set(l1_height as f64); + self.pending_l1_blocks.pop_front(); } Ok(()) diff --git a/crates/batch-prover/src/lib.rs b/crates/batch-prover/src/lib.rs index 1f4c35cc6..a590dcd15 100644 --- a/crates/batch-prover/src/lib.rs +++ b/crates/batch-prover/src/lib.rs @@ -3,6 +3,7 @@ pub mod db_migrations; mod errors; mod runner; pub use runner::*; +mod metrics; mod proving; pub mod rpc; diff --git a/crates/batch-prover/src/metrics.rs b/crates/batch-prover/src/metrics.rs new file mode 100644 index 000000000..9d48e279d --- /dev/null +++ b/crates/batch-prover/src/metrics.rs @@ -0,0 +1,20 @@ +use metrics::{Gauge, Histogram}; +use metrics_derive::Metrics; +use once_cell::sync::Lazy; + +#[derive(Metrics)] +#[metrics(scope = "batch_prover")] +pub struct BatchProverMetrics { + #[metric(describe = "The current L1 block number which is used to produce L2 blocks")] + pub current_l1_block: Gauge, + #[metric(describe = "The current L2 block number")] + pub current_l2_block: Gauge, + #[metric(describe = "The duration of processing a single soft confirmation")] + pub process_soft_confirmation: Histogram, +} + +/// Batch prover metrics +pub static BATCH_PROVER_METRICS: Lazy = Lazy::new(|| { + BatchProverMetrics::describe(); + BatchProverMetrics::default() +}); diff --git a/crates/batch-prover/src/runner.rs b/crates/batch-prover/src/runner.rs index b91e8cd97..fdc965c8b 100644 --- a/crates/batch-prover/src/runner.rs +++ b/crates/batch-prover/src/runner.rs @@ -2,7 +2,7 @@ use core::panic; use std::collections::{HashMap, VecDeque}; use std::net::SocketAddr; use std::sync::Arc; -use std::time::Duration; +use std::time::{Duration, Instant}; use anyhow::{anyhow, bail, Context as _}; use backoff::exponential::ExponentialBackoffBuilder; @@ -38,6 +38,7 @@ use tokio::time::sleep; use tracing::{debug, error, info, instrument}; use crate::da_block_handler::L1BlockHandler; +use crate::metrics::BATCH_PROVER_METRICS; use crate::rpc::{create_rpc_module, RpcContext}; type StfStateRoot = as StateTransitionFunction>::StateRoot; @@ -395,6 +396,8 @@ where l2_height: u64, soft_confirmation: &SoftConfirmationResponse, ) -> anyhow::Result<()> { + let start = Instant::now(); + let current_l1_block = get_da_block_at_height( &self.da_service, soft_confirmation.da_slot_height, @@ -487,6 +490,13 @@ where l2_height, self.state_root ); + BATCH_PROVER_METRICS.current_l2_block.set(l2_height as f64); + BATCH_PROVER_METRICS.process_soft_confirmation.record( + Instant::now() + .saturating_duration_since(start) + .as_secs_f64(), + ); + Ok(()) } diff --git a/crates/bitcoin-da/Cargo.toml b/crates/bitcoin-da/Cargo.toml index 1abb57724..8195ebee3 100644 --- a/crates/bitcoin-da/Cargo.toml +++ b/crates/bitcoin-da/Cargo.toml @@ -26,6 +26,7 @@ crypto-bigint = { workspace = true } hex = { workspace = true, features = ["serde"] } itertools = { workspace = true } jsonrpsee = { workspace = true, optional = true } +metrics = { workspace = true, optional = true } pin-project = { workspace = true, optional = true, features = [] } rand = { workspace = true } reqwest = { workspace = true, optional = true } @@ -49,6 +50,7 @@ native = [ "dep:backoff", "dep:tokio", "dep:tokio-util", + "dep:metrics", "dep:pin-project", "dep:tracing", "sov-rollup-interface/native", diff --git a/crates/bitcoin-da/src/helpers/builders/batch_proof_namespace.rs b/crates/bitcoin-da/src/helpers/builders/batch_proof_namespace.rs index bbc22c236..8ea5902fc 100644 --- a/crates/bitcoin-da/src/helpers/builders/batch_proof_namespace.rs +++ b/crates/bitcoin-da/src/helpers/builders/batch_proof_namespace.rs @@ -2,6 +2,7 @@ use core::result::Result::Ok; use std::fs::File; use std::io::{BufWriter, Write}; use std::path::PathBuf; +use std::time::Instant; use bitcoin::blockdata::opcodes::all::{OP_ENDIF, OP_IF}; use bitcoin::blockdata::opcodes::OP_FALSE; @@ -13,6 +14,7 @@ use bitcoin::opcodes::all::{OP_CHECKSIGVERIFY, OP_NIP}; use bitcoin::script::PushBytesBuf; use bitcoin::secp256k1::{Secp256k1, SecretKey, XOnlyPublicKey}; use bitcoin::{Address, Amount, Network, Transaction}; +use metrics::histogram; use serde::Serialize; use tracing::{instrument, trace, warn}; @@ -119,7 +121,7 @@ pub fn create_batchproof_type_0( .push_slice(PushBytesBuf::try_from(body).expect("Cannot push sequencer commitment")) .push_opcode(OP_ENDIF); - println!("reveal_script_builder: {:?}", reveal_script_builder); + let start = Instant::now(); // Start loop to find a 'nonce' i.e. random number that makes the reveal tx hash starting with zeros given length let mut nonce: i64 = 16; // skip the first digits to avoid OP_PUSHNUM_X loop { @@ -211,6 +213,12 @@ pub fn create_batchproof_type_0( commit_tx_address ); + histogram!("mine_da_transaction").record( + Instant::now() + .saturating_duration_since(start) + .as_secs_f64(), + ); + return Ok(BatchProvingTxs { commit: unsigned_commit_tx, reveal: TxWithId { diff --git a/crates/common/src/config.rs b/crates/common/src/config.rs index 84be06932..cf848f1bc 100644 --- a/crates/common/src/config.rs +++ b/crates/common/src/config.rs @@ -10,6 +10,7 @@ use sov_stf_runner::ProverGuestRunConfig; pub trait FromEnv: Sized { fn from_env() -> anyhow::Result; } + impl FromEnv for PruningConfig { fn from_env() -> anyhow::Result { Ok(PruningConfig { @@ -17,6 +18,7 @@ impl FromEnv for PruningConfig { }) } } + impl FromEnv for sov_mock_da::MockDaConfig { fn from_env() -> anyhow::Result { Ok(Self { @@ -39,6 +41,7 @@ pub struct RunnerConfig { /// Configurations for pruning pub pruning_config: Option, } + impl FromEnv for RunnerConfig { fn from_env() -> anyhow::Result { Ok(Self { @@ -52,6 +55,7 @@ impl FromEnv for RunnerConfig { }) } } + /// RPC configuration. #[derive(Debug, Clone, PartialEq, Deserialize, Default, Serialize)] pub struct RpcConfig { @@ -79,6 +83,7 @@ pub struct RpcConfig { #[serde(default = "default_max_subscriptions_per_connection")] pub max_subscriptions_per_connection: u32, } + impl FromEnv for RpcConfig { fn from_env() -> anyhow::Result { Ok(Self { @@ -112,6 +117,7 @@ impl FromEnv for RpcConfig { }) } } + #[inline] const fn default_max_connections() -> u32 { 100 @@ -155,6 +161,7 @@ pub struct StorageConfig { /// File descriptor limit for RocksDB pub db_max_open_files: Option, } + impl FromEnv for StorageConfig { fn from_env() -> anyhow::Result { Ok(Self { @@ -181,6 +188,7 @@ pub struct RollupPublicKeys { #[serde(with = "hex::serde")] pub prover_da_pub_key: Vec, } + impl FromEnv for RollupPublicKeys { fn from_env() -> anyhow::Result { Ok(Self { @@ -190,6 +198,7 @@ impl FromEnv for RollupPublicKeys { }) } } + /// Rollup Configuration #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct FullNodeConfig { @@ -203,7 +212,11 @@ pub struct FullNodeConfig { pub da: BitcoinServiceConfig, /// Important pubkeys pub public_keys: RollupPublicKeys, + /// Telemetry configuration + #[serde(default)] + pub telemetry: TelemetryConfig, } + impl FromEnv for FullNodeConfig { fn from_env() -> anyhow::Result { Ok(Self { @@ -212,9 +225,11 @@ impl FromEnv for FullNodeConfig { runner: RunnerConfig::from_env().ok(), da: DaC::from_env()?, public_keys: RollupPublicKeys::from_env()?, + telemetry: TelemetryConfig::from_env()?, }) } } + /// Prover configuration #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] pub struct BatchProverConfig { @@ -279,6 +294,7 @@ impl FromEnv for LightClientProverConfig { }) } } + /// Reads toml file as a specific type. pub fn from_toml_path, R: DeserializeOwned>(path: P) -> anyhow::Result { let mut contents = String::new(); @@ -327,6 +343,7 @@ impl Default for SequencerConfig { } } } + impl FromEnv for SequencerConfig { fn from_env() -> anyhow::Result { Ok(Self { @@ -343,6 +360,7 @@ impl FromEnv for SequencerConfig { }) } } + /// Mempool Config for the sequencer /// Read: https://github.com/ledgerwatch/erigon/wiki/Transaction-Pool-Design #[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] @@ -376,6 +394,7 @@ impl Default for SequencerMempoolConfig { } } } + impl FromEnv for SequencerMempoolConfig { fn from_env() -> anyhow::Result { Ok(Self { @@ -389,6 +408,36 @@ impl FromEnv for SequencerMempoolConfig { }) } } + +/// Telemetry configuration. +#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] +pub struct TelemetryConfig { + /// Server host. + pub bind_host: Option, + /// Server port. + pub bind_port: Option, +} + +impl Default for TelemetryConfig { + fn default() -> Self { + Self { + bind_host: Some("0.0.0.0".to_owned()), + bind_port: Some(8081), + } + } +} + +impl FromEnv for TelemetryConfig { + fn from_env() -> anyhow::Result { + let bind_host = std::env::var("TELEMETRY_BIND_HOST").ok(); + let bind_port = std::env::var("TELEMETRY_BIND_PORT").ok(); + Ok(Self { + bind_host, + bind_port: bind_port.map(|p| p.parse()).transpose()?, + }) + } +} + #[cfg(test)] mod tests { use std::io::Write; @@ -430,6 +479,10 @@ mod tests { [runner] include_tx_body = true sequencer_client_url = "http://0.0.0.0:12346" + + [telemetry] + bind_host = "0.0.0.0" + bind_port = 8001 "#.to_owned(); let config_file = create_config_from(&config); @@ -467,6 +520,10 @@ mod tests { sequencer_da_pub_key: vec![119; 32], prover_da_pub_key: vec![], }, + telemetry: TelemetryConfig { + bind_host: Some("0.0.0.0".to_owned()), + bind_port: Some(8001), + }, }; assert_eq!(config, expected); } @@ -621,6 +678,8 @@ mod tests { std::env::set_var("SEQUENCER_CLIENT_URL", "http://0.0.0.0:12346"); std::env::set_var("PRUNING_DISTANCE", "1000"); + std::env::set_var("TELEMETRY_BIND_HOST", "0.0.0.0"); + std::env::set_var("TELEMETRY_BIND_PORT", "8082"); let full_node_config: FullNodeConfig = FullNodeConfig::from_env().unwrap(); @@ -654,7 +713,32 @@ mod tests { sequencer_da_pub_key: vec![119; 32], prover_da_pub_key: vec![], }, + telemetry: TelemetryConfig { + bind_host: Some("0.0.0.0".to_owned()), + bind_port: Some(8082), + }, }; assert_eq!(full_node_config, expected); } + + #[test] + fn test_optional_telemetry_config_from_env() { + let telemetry_config = TelemetryConfig::from_env().unwrap(); + + let expected = TelemetryConfig { + bind_host: None, + bind_port: None, + }; + assert_eq!(telemetry_config, expected); + + std::env::set_var("TELEMETRY_BIND_HOST", "0.0.0.0"); + std::env::set_var("TELEMETRY_BIND_PORT", "5000"); + let telemetry_config = TelemetryConfig::from_env().unwrap(); + + let expected = TelemetryConfig { + bind_host: Some("0.0.0.0".to_owned()), + bind_port: Some(5000), + }; + assert_eq!(telemetry_config, expected); + } } diff --git a/crates/fullnode/Cargo.toml b/crates/fullnode/Cargo.toml index 4bcd728d1..72397abfa 100644 --- a/crates/fullnode/Cargo.toml +++ b/crates/fullnode/Cargo.toml @@ -30,6 +30,9 @@ borsh = { workspace = true } futures = { workspace = true } hex = { workspace = true } jsonrpsee = { workspace = true } +metrics = { workspace = true } +metrics-derive = { workspace = true } +once_cell = { workspace = true, default-features = true } rand = { workspace = true } reth-primitives = { workspace = true } rs_merkle = { workspace = true } diff --git a/crates/fullnode/src/da_block_handler.rs b/crates/fullnode/src/da_block_handler.rs index 34799cfda..02880be85 100644 --- a/crates/fullnode/src/da_block_handler.rs +++ b/crates/fullnode/src/da_block_handler.rs @@ -2,6 +2,7 @@ use std::collections::{HashMap, VecDeque}; use std::fmt::Debug; use std::marker::PhantomData; use std::sync::Arc; +use std::time::Instant; use anyhow::anyhow; use borsh::{BorshDeserialize, BorshSerialize}; @@ -31,6 +32,8 @@ use tokio::time::{sleep, Duration}; use tokio_util::sync::CancellationToken; use tracing::{error, info, warn}; +use crate::metrics::FULLNODE_METRICS; + pub(crate) struct L1BlockHandler where C: Context, @@ -134,6 +137,7 @@ where .front() .expect("Just checked pending L1 blocks is not empty"); let l1_height = l1_block.header().height(); + info!("Processing L1 block at height: {}", l1_height); // Set the l1 height of the l1 hash self.ledger_db @@ -164,6 +168,7 @@ where sequencer_commitments[0].l2_start_block_number, sequencer_commitments[sequencer_commitments.len() - 1].l2_end_block_number, ) { + warn!("L1 commitment received, but L2 range is not synced yet..."); return; } } @@ -209,6 +214,8 @@ where error!("Could not set last scanned l1 height: {}", e); }); + FULLNODE_METRICS.current_l1_block.set(l1_height as f64); + self.pending_l1_blocks.pop_front(); } @@ -428,6 +435,8 @@ async fn sync_l1( let mut l1_height = start_l1_height; info!("Starting to sync from L1 height {}", l1_height); + let start = Instant::now(); + 'block_sync: loop { // TODO: for a node, the da block at slot_height might not have been finalized yet // should wait for it to be finalized @@ -458,6 +467,11 @@ async fn sync_l1( if block_number > l1_height { l1_height = block_number; + FULLNODE_METRICS.scan_l1_block.record( + Instant::now() + .saturating_duration_since(start) + .as_secs_f64(), + ); if let Err(e) = sender.send(l1_block).await { error!("Could not notify about L1 block: {}", e); continue 'block_sync; diff --git a/crates/fullnode/src/lib.rs b/crates/fullnode/src/lib.rs index 834bc790e..28406da97 100644 --- a/crates/fullnode/src/lib.rs +++ b/crates/fullnode/src/lib.rs @@ -2,4 +2,5 @@ pub use runner::*; mod da_block_handler; pub mod db_migrations; +mod metrics; mod runner; diff --git a/crates/fullnode/src/metrics.rs b/crates/fullnode/src/metrics.rs new file mode 100644 index 000000000..992038c68 --- /dev/null +++ b/crates/fullnode/src/metrics.rs @@ -0,0 +1,22 @@ +use metrics::{Gauge, Histogram}; +use metrics_derive::Metrics; +use once_cell::sync::Lazy; + +#[derive(Metrics)] +#[metrics(scope = "fullnode")] +pub struct FullnodeMetrics { + #[metric(describe = "The current L1 block number which is used to produce L2 blocks")] + pub current_l1_block: Gauge, + #[metric(describe = "The current L2 block number")] + pub current_l2_block: Gauge, + #[metric(describe = "The duration of scanning and processing a single L1 block")] + pub scan_l1_block: Histogram, + #[metric(describe = "The duration of processing a single soft confirmation")] + pub process_soft_confirmation: Histogram, +} + +/// Fullnode metrics +pub static FULLNODE_METRICS: Lazy = Lazy::new(|| { + FullnodeMetrics::describe(); + FullnodeMetrics::default() +}); diff --git a/crates/fullnode/src/runner.rs b/crates/fullnode/src/runner.rs index 49460c7df..e41527885 100644 --- a/crates/fullnode/src/runner.rs +++ b/crates/fullnode/src/runner.rs @@ -1,6 +1,7 @@ use std::collections::{HashMap, VecDeque}; use std::net::SocketAddr; use std::sync::Arc; +use std::time::Instant; use anyhow::{bail, Context as _}; use backoff::future::retry as retry_backoff; @@ -37,6 +38,7 @@ use tokio::time::{sleep, Duration}; use tracing::{debug, error, info, instrument}; use crate::da_block_handler::L1BlockHandler; +use crate::metrics::FULLNODE_METRICS; type StateRoot = as StateTransitionFunction>::StateRoot; type StfTransaction = @@ -224,6 +226,8 @@ where l2_height: u64, soft_confirmation: &SoftConfirmationResponse, ) -> anyhow::Result<()> { + let start = Instant::now(); + let current_l1_block = get_da_block_at_height( &self.da_service, soft_confirmation.da_slot_height, @@ -307,6 +311,13 @@ where l2_height, self.state_root ); + FULLNODE_METRICS.current_l2_block.set(l2_height as f64); + FULLNODE_METRICS.process_soft_confirmation.record( + Instant::now() + .saturating_duration_since(start) + .as_secs_f64(), + ); + Ok(()) } diff --git a/crates/light-client-prover/Cargo.toml b/crates/light-client-prover/Cargo.toml index df53c7a23..6eed0af60 100644 --- a/crates/light-client-prover/Cargo.toml +++ b/crates/light-client-prover/Cargo.toml @@ -28,6 +28,9 @@ bincode = { workspace = true } borsh = { workspace = true } hex = { workspace = true } jsonrpsee = { workspace = true, optional = true, features = ["http-client", "server", "client"] } +metrics = { workspace = true, optional = true } +metrics-derive = { workspace = true, optional = true } +once_cell = { workspace = true, default-features = true, optional = true } reth-primitives = { workspace = true, optional = true } tokio = { workspace = true, optional = true } tokio-util = { workspace = true, optional = true } @@ -51,6 +54,9 @@ native = [ "dep:anyhow", "dep:async-trait", "dep:jsonrpsee", + "dep:metrics", + "dep:metrics-derive", + "dep:once_cell", "dep:reth-primitives", "dep:tokio", "dep:tokio-util", diff --git a/crates/light-client-prover/src/da_block_handler.rs b/crates/light-client-prover/src/da_block_handler.rs index a5c06c829..0f6cbf0a1 100644 --- a/crates/light-client-prover/src/da_block_handler.rs +++ b/crates/light-client-prover/src/da_block_handler.rs @@ -27,6 +27,8 @@ use tokio::time::{sleep, Duration}; use tokio_util::sync::CancellationToken; use tracing::{error, info}; +use crate::metrics::LIGHT_CLIENT_METRICS; + pub(crate) struct L1BlockHandler where Da: DaService, @@ -293,6 +295,8 @@ where .set_last_scanned_l1_height(SlotNumber(l1_block.header().height())) .expect("Saving last scanned l1 height to ledger db"); + LIGHT_CLIENT_METRICS.current_l1_block.set(l1_height as f64); + Ok(()) } diff --git a/crates/light-client-prover/src/lib.rs b/crates/light-client-prover/src/lib.rs index fac6e95a2..8b9812818 100644 --- a/crates/light-client-prover/src/lib.rs +++ b/crates/light-client-prover/src/lib.rs @@ -4,6 +4,8 @@ pub mod da_block_handler; #[cfg(feature = "native")] pub mod db_migrations; #[cfg(feature = "native")] +pub mod metrics; +#[cfg(feature = "native")] pub mod rpc; #[cfg(feature = "native")] pub mod runner; diff --git a/crates/light-client-prover/src/metrics.rs b/crates/light-client-prover/src/metrics.rs new file mode 100644 index 000000000..d07673242 --- /dev/null +++ b/crates/light-client-prover/src/metrics.rs @@ -0,0 +1,16 @@ +use metrics::Gauge; +use metrics_derive::Metrics; +use once_cell::sync::Lazy; + +#[derive(Metrics)] +#[metrics(scope = "light_client_prover")] +pub struct LightClientProverMetrics { + #[metric(describe = "The current L1 block number which is used to produce L2 blocks")] + pub current_l1_block: Gauge, +} + +/// Light client metrics +pub static LIGHT_CLIENT_METRICS: Lazy = Lazy::new(|| { + LightClientProverMetrics::describe(); + LightClientProverMetrics::default() +}); diff --git a/crates/risc0/Cargo.toml b/crates/risc0/Cargo.toml index 18c46241c..6e49624d9 100644 --- a/crates/risc0/Cargo.toml +++ b/crates/risc0/Cargo.toml @@ -17,6 +17,7 @@ bincode = { workspace = true } bonsai-sdk = { workspace = true, optional = true } borsh = { workspace = true } hex = { workspace = true } +metrics = { workspace = true, optional = true } risc0-zkvm = { workspace = true, default-features = false, features = ["std"] } serde = { workspace = true } sov-db = { path = "../sovereign-sdk/full-node/db/sov-db", optional = true } @@ -28,6 +29,7 @@ default = [] native = [ "dep:bonsai-sdk", "dep:sov-db", + "dep:metrics", "risc0-zkvm/prove", "sov-rollup-interface/native", ] diff --git a/crates/risc0/src/host.rs b/crates/risc0/src/host.rs index cabe1fd85..32b197caf 100644 --- a/crates/risc0/src/host.rs +++ b/crates/risc0/src/host.rs @@ -1,6 +1,7 @@ //! This module implements the [`ZkvmHost`] trait for the RISC0 VM. use borsh::{BorshDeserialize, BorshSerialize}; +use metrics::histogram; use risc0_zkvm::sha::Digest; use risc0_zkvm::{ compute_image_id, default_prover, AssumptionReceipt, ExecutorEnvBuilder, ProveInfo, ProverOpts, @@ -137,6 +138,8 @@ impl ZkvmHost for Risc0BonsaiHost { let ProveInfo { receipt, stats } = prover.prove_with_opts(env, &elf, &ProverOpts::groth16())?; + histogram!("proving_session_cycle_count").record(stats.total_cycles as f64); + tracing::info!("Execution Stats: {:?}", stats); let image_id = compute_image_id(&elf)?; diff --git a/crates/sequencer/Cargo.toml b/crates/sequencer/Cargo.toml index 7fb66e79a..5e97d6d37 100644 --- a/crates/sequencer/Cargo.toml +++ b/crates/sequencer/Cargo.toml @@ -25,6 +25,9 @@ futures = { workspace = true } hex = { workspace = true } hyper = { workspace = true } jsonrpsee = { workspace = true, features = ["http-client", "server", "client"] } +metrics = { workspace = true } +metrics-derive = { workspace = true } +once_cell = { workspace = true } parking_lot = { workspace = true } rs_merkle = { workspace = true } schnellru = "0.2.1" diff --git a/crates/sequencer/src/commitment/mod.rs b/crates/sequencer/src/commitment/mod.rs index 7b47fd4c2..62622486d 100644 --- a/crates/sequencer/src/commitment/mod.rs +++ b/crates/sequencer/src/commitment/mod.rs @@ -1,5 +1,6 @@ use std::ops::RangeInclusive; use std::sync::Arc; +use std::time::Instant; use anyhow::anyhow; use futures::channel::mpsc::UnboundedReceiver; @@ -18,6 +19,7 @@ use tokio_util::sync::CancellationToken; use tracing::{debug, error, info, instrument}; use self::controller::CommitmentController; +use crate::metrics::SEQUENCER_METRICS; mod controller; @@ -128,6 +130,10 @@ where .map(|sb| sb.hash) .collect::>(); + SEQUENCER_METRICS + .commitment_blocks_count + .set(soft_confirmation_hashes.len() as f64); + let commitment = self.get_commitment(commitment_info, soft_confirmation_hashes)?; debug!("Sequencer: submitting commitment: {:?}", commitment); @@ -145,6 +151,7 @@ where l2_start.0, l2_end.0, ); + let start = Instant::now(); let ledger_db = self.ledger_db.clone(); let handle_da_response = async move { let result: anyhow::Result<()> = async move { @@ -153,6 +160,12 @@ where .map_err(|_| anyhow!("DA service is dead!"))? .map_err(|_| anyhow!("Send transaction cannot fail"))?; + SEQUENCER_METRICS.send_commitment_execution.record( + Instant::now() + .saturating_duration_since(start) + .as_secs_f64(), + ); + ledger_db .set_last_commitment_l2_height(l2_end) .map_err(|_| { diff --git a/crates/sequencer/src/lib.rs b/crates/sequencer/src/lib.rs index 391263e6a..bcf94aca1 100644 --- a/crates/sequencer/src/lib.rs +++ b/crates/sequencer/src/lib.rs @@ -3,6 +3,7 @@ pub mod db_migrations; mod db_provider; mod deposit_data_mempool; mod mempool; +mod metrics; mod rpc; mod runner; mod utils; diff --git a/crates/sequencer/src/mempool.rs b/crates/sequencer/src/mempool.rs index 68903e03c..581bd9dd1 100644 --- a/crates/sequencer/src/mempool.rs +++ b/crates/sequencer/src/mempool.rs @@ -130,4 +130,8 @@ impl CitreaMempool { self.0 .best_transactions_with_attributes(best_transactions_attributes) } + + pub(crate) fn len(&self) -> usize { + self.0.len() + } } diff --git a/crates/sequencer/src/metrics.rs b/crates/sequencer/src/metrics.rs new file mode 100644 index 000000000..398756f0a --- /dev/null +++ b/crates/sequencer/src/metrics.rs @@ -0,0 +1,28 @@ +use metrics::{Gauge, Histogram}; +use metrics_derive::Metrics; +use once_cell::sync::Lazy; + +#[derive(Metrics)] +#[metrics(scope = "sequencer")] +pub struct SequencerMetrics { + #[metric(describe = "How many transactions are currently in the mempool")] + pub mempool_txs: Gauge, + #[metric(describe = "The duration of dry running transactions")] + pub dry_run_execution: Histogram, + #[metric(describe = "The duration of executing block transactions")] + pub block_production_execution: Histogram, + #[metric(describe = "The duration of sending a sequencer commitment")] + pub send_commitment_execution: Histogram, + #[metric(describe = "The number of blocks included in a sequencer commitment")] + pub commitment_blocks_count: Gauge, + #[metric(describe = "The current L2 block number")] + pub current_l2_block: Gauge, + #[metric(describe = "The current L1 block number which is used to produce L2 blocks")] + pub current_l1_block: Gauge, +} + +/// Sequencer metrics +pub static SEQUENCER_METRICS: Lazy = Lazy::new(|| { + SequencerMetrics::describe(); + SequencerMetrics::default() +}); diff --git a/crates/sequencer/src/rpc.rs b/crates/sequencer/src/rpc.rs index 79d74a5fa..283b632a5 100644 --- a/crates/sequencer/src/rpc.rs +++ b/crates/sequencer/src/rpc.rs @@ -17,6 +17,7 @@ use tracing::{debug, error}; use crate::deposit_data_mempool::DepositDataMempool; use crate::mempool::CitreaMempool; +use crate::metrics::SEQUENCER_METRICS; use crate::utils::recover_raw_transaction; pub(crate) struct RpcContext { @@ -97,6 +98,8 @@ impl anyhow::Result<(Vec, Vec)> { + let start = Instant::now(); + let silent_subscriber = tracing_subscriber::registry().with(LevelFilter::OFF); tracing::subscriber::with_default(silent_subscriber, || { @@ -365,6 +368,11 @@ where working_set_to_discard = working_set.checkpoint().to_revertable(); all_txs.push(rlp_tx); } + SEQUENCER_METRICS.dry_run_execution.record( + Instant::now() + .saturating_duration_since(start) + .as_secs_f64(), + ); Ok((all_txs, l1_fee_failed_txs)) } @@ -391,6 +399,7 @@ where l1_fee_rate: u128, l2_block_mode: L2BlockMode, ) -> anyhow::Result<(u64, u64, StateDiff)> { + let start = Instant::now(); let da_height = da_block.header().height(); let (l2_height, l1_height) = match self .ledger_db @@ -590,6 +599,7 @@ where txs_to_remove.extend(l1_fee_failed_txs); self.mempool.remove_transactions(txs_to_remove.clone()); + SEQUENCER_METRICS.mempool_txs.set(self.mempool.len() as f64); let account_updates = self.get_account_updates()?; @@ -603,6 +613,13 @@ where warn!("Failed to remove txs from mempool: {:?}", e); } + SEQUENCER_METRICS.block_production_execution.record( + Instant::now() + .saturating_duration_since(start) + .as_secs_f64(), + ); + SEQUENCER_METRICS.current_l2_block.set(l2_height as f64); + Ok(( l2_height, da_block.header().height(), @@ -709,6 +726,7 @@ where missed_da_blocks_count = self.da_blocks_missed(last_finalized_height, last_used_l1_height); } + SEQUENCER_METRICS.current_l1_block.set(last_finalized_height as f64); }, // If sequencer is in test mode, it will build a block every time it receives a message // The RPC from which the sender can be called is only registered for test mode. This means diff --git a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/traits.rs b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/traits.rs index ad83287f5..befd64c1a 100644 --- a/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/traits.rs +++ b/crates/sovereign-sdk/full-node/db/sov-db/src/ledger_db/traits.rs @@ -268,6 +268,8 @@ pub trait SequencerLedgerOps: SharedLedgerOps { /// Test ledger operations #[cfg(test)] pub trait TestLedgerOps { + /// Fetch the test values fn get_values(&self) -> anyhow::Result>; + /// Insert the test values fn put_value(&self, key: u64, value: (u64, u64)) -> anyhow::Result<()>; } diff --git a/crates/sovereign-sdk/full-node/db/sov-schema-db/Cargo.toml b/crates/sovereign-sdk/full-node/db/sov-schema-db/Cargo.toml index e52d1a2f2..6915368fb 100644 --- a/crates/sovereign-sdk/full-node/db/sov-schema-db/Cargo.toml +++ b/crates/sovereign-sdk/full-node/db/sov-schema-db/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "sov-schema-db" +license = "Apache-2.0" # This license is inherited from Aptos description = "A low level interface transforming RocksDB into a type-oriented data store" -license = "Apache-2.0" # This license is inherited from Aptos # Workspace inherited keys version = { workspace = true } @@ -16,17 +16,18 @@ readme = "README.md" # External dependencies anyhow = { workspace = true, default-features = true } byteorder = { workspace = true, default-features = true, optional = true } +metrics = { workspace = true } +metrics-derive = { workspace = true } once_cell = { workspace = true, default-features = true } -prometheus = { workspace = true } rocksdb = { workspace = true } +thiserror = { workspace = true } tokio = { workspace = true } tracing = { workspace = true, default-features = true } -thiserror = { workspace = true } [dev-dependencies] byteorder = { workspace = true, default-features = true } -tempfile = { workspace = true } sov-schema-db = { path = ".", features = ["test-utils"] } +tempfile = { workspace = true } [features] default = [] diff --git a/crates/sovereign-sdk/full-node/db/sov-schema-db/src/iterator.rs b/crates/sovereign-sdk/full-node/db/sov-schema-db/src/iterator.rs index da51a2787..f440c5715 100644 --- a/crates/sovereign-sdk/full-node/db/sov-schema-db/src/iterator.rs +++ b/crates/sovereign-sdk/full-node/db/sov-schema-db/src/iterator.rs @@ -1,9 +1,10 @@ use std::iter::FusedIterator; use std::marker::PhantomData; +use std::time::Instant; use anyhow::Result; +use metrics::histogram; -use crate::metrics::{SCHEMADB_ITER_BYTES, SCHEMADB_ITER_LATENCY_SECONDS}; use crate::schema::{KeyDecoder, Schema, ValueCodec}; use crate::{SchemaKey, SchemaValue}; @@ -96,9 +97,7 @@ where } fn next_impl(&mut self) -> Result>> { - let _timer = SCHEMADB_ITER_LATENCY_SECONDS - .with_label_values(&[S::COLUMN_FAMILY_NAME]) - .start_timer(); + let start = Instant::now(); if !self.db_iter.valid() { self.db_iter.status()?; @@ -108,9 +107,9 @@ where let raw_key = self.db_iter.key().expect("db_iter.key() failed."); let raw_value = self.db_iter.value().expect("db_iter.value() failed."); let value_size_bytes = raw_value.len(); - SCHEMADB_ITER_BYTES - .with_label_values(&[S::COLUMN_FAMILY_NAME]) - .observe((raw_key.len() + raw_value.len()) as f64); + + histogram!("schemadb_iter_bytes", "cf_name" => S::COLUMN_FAMILY_NAME) + .record((raw_key.len() + raw_value.len()) as f64); let key = >::decode_key(raw_key)?; let value = >::decode_value(raw_value)?; @@ -120,6 +119,12 @@ where ScanDirection::Backward => self.db_iter.prev(), } + histogram!("schemadb_iter_latency_seconds", "cf_name" => S::COLUMN_FAMILY_NAME).record( + Instant::now() + .saturating_duration_since(start) + .as_secs_f64(), + ); + Ok(Some(IteratorOutput { key, value, diff --git a/crates/sovereign-sdk/full-node/db/sov-schema-db/src/lib.rs b/crates/sovereign-sdk/full-node/db/sov-schema-db/src/lib.rs index d458f0ddc..136390b3f 100644 --- a/crates/sovereign-sdk/full-node/db/sov-schema-db/src/lib.rs +++ b/crates/sovereign-sdk/full-node/db/sov-schema-db/src/lib.rs @@ -23,20 +23,19 @@ pub mod snapshot; pub mod test; use std::path::Path; +use std::time::Instant; +use ::metrics::{gauge, histogram}; use anyhow::format_err; use iterator::ScanDirection; pub use iterator::{RawDbReverseIterator, SchemaIterator, SeekKeyEncoder}; -use metrics::{ - SCHEMADB_BATCH_COMMIT_BYTES, SCHEMADB_BATCH_COMMIT_LATENCY_SECONDS, SCHEMADB_DELETES, - SCHEMADB_GET_BYTES, SCHEMADB_GET_LATENCY_SECONDS, SCHEMADB_PUT_BYTES, -}; pub use rocksdb; pub use rocksdb::DEFAULT_COLUMN_FAMILY_NAME; use rocksdb::{DBIterator, ReadOptions}; use thiserror::Error; use tracing::info; +pub use crate::metrics::SCHEMADB_METRICS; pub use crate::schema::Schema; use crate::schema::{ColumnFamilyName, KeyCodec, ValueCodec}; pub use crate::schema_batch::{SchemaBatch, SchemaBatchIterator}; @@ -137,22 +136,27 @@ impl DB { } fn _get(&self, schema_key: &impl KeyCodec) -> anyhow::Result> { - let _timer = SCHEMADB_GET_LATENCY_SECONDS - .with_label_values(&[S::COLUMN_FAMILY_NAME]) - .start_timer(); + let start = Instant::now(); let k = schema_key.encode_key()?; let cf_handle = self.get_cf_handle(S::COLUMN_FAMILY_NAME)?; let result = self.inner.get_pinned_cf(cf_handle, k)?; - SCHEMADB_GET_BYTES - .with_label_values(&[S::COLUMN_FAMILY_NAME]) - .observe(result.as_ref().map_or(0.0, |v| v.len() as f64)); - result + histogram!("schemadb_get_bytes", "cf_name" => S::COLUMN_FAMILY_NAME) + .record(result.as_ref().map_or(0.0, |v| v.len() as f64)); + + let result = result .map(|raw_value| >::decode_value(&raw_value)) .transpose() - .map_err(|err| err.into()) + .map_err(|err| err.into()); + + histogram!("schemadb_get_latency_seconds", "cf_name" => S::COLUMN_FAMILY_NAME).record( + Instant::now() + .saturating_duration_since(start) + .as_secs_f64(), + ); + result } /// Writes single record. @@ -282,9 +286,8 @@ impl DB { } fn _write_schemas(&self, batch: SchemaBatch) -> anyhow::Result<()> { - let _timer = SCHEMADB_BATCH_COMMIT_LATENCY_SECONDS - .with_label_values(&[self.name]) - .start_timer(); + let start = Instant::now(); + let mut db_batch = rocksdb::WriteBatch::default(); for (cf_name, rows) in batch.last_writes.iter() { let cf_handle = self.get_cf_handle(cf_name)?; @@ -304,19 +307,22 @@ impl DB { for (key, operation) in rows { match operation { Operation::Put { value } => { - SCHEMADB_PUT_BYTES - .with_label_values(&[cf_name]) - .observe((key.len() + value.len()) as f64); + histogram!("schemadb_put_bytes").record((key.len() + value.len()) as f64); } Operation::Delete => { - SCHEMADB_DELETES.with_label_values(&[cf_name]).inc(); + gauge!("schemadb_deletes", "cf_name" => cf_name.to_owned()).increment(1) } } } } - SCHEMADB_BATCH_COMMIT_BYTES - .with_label_values(&[self.name]) - .observe(serialized_size as f64); + + histogram!("schemadb_batch_commit_bytes").record(serialized_size as f64); + + histogram!("schemadb_batch_commit_latency_seconds", "db_name" => self.name).record( + Instant::now() + .saturating_duration_since(start) + .as_secs_f64(), + ); Ok(()) } diff --git a/crates/sovereign-sdk/full-node/db/sov-schema-db/src/metrics.rs b/crates/sovereign-sdk/full-node/db/sov-schema-db/src/metrics.rs index d0e94dd41..15ccff1ab 100644 --- a/crates/sovereign-sdk/full-node/db/sov-schema-db/src/metrics.rs +++ b/crates/sovereign-sdk/full-node/db/sov-schema-db/src/metrics.rs @@ -1,112 +1,42 @@ // Copyright (c) Aptos // SPDX-License-Identifier: Apache-2.0 +use metrics::{Counter, Histogram}; +use metrics_derive::Metrics; use once_cell::sync::Lazy; -use prometheus::{ - exponential_buckets, register_histogram_vec, register_int_counter_vec, HistogramVec, - IntCounterVec, -}; -pub static SCHEMADB_ITER_LATENCY_SECONDS: Lazy = Lazy::new(|| { - register_histogram_vec!( - // metric name - "schemadb_iter_latency_seconds", - // metric description - "Schemadb iter latency in seconds", - // metric labels (dimensions) - &["cf_name"], - exponential_buckets(/*start=*/ 1e-6, /*factor=*/ 2.0, /*count=*/ 22).unwrap(), - ) - .unwrap() -}); - -pub static SCHEMADB_ITER_BYTES: Lazy = Lazy::new(|| { - register_histogram_vec!( - // metric name - "schemadb_iter_bytes", - // metric description - "Schemadb iter size in bytes", - // metric labels (dimensions) - &["cf_name"] - ) - .unwrap() -}); - -pub static SCHEMADB_GET_LATENCY_SECONDS: Lazy = Lazy::new(|| { - register_histogram_vec!( - // metric name - "schemadb_get_latency_seconds", - // metric description - "Schemadb get latency in seconds", - // metric labels (dimensions) - &["cf_name"], - exponential_buckets(/*start=*/ 1e-6, /*factor=*/ 2.0, /*count=*/ 22).unwrap(), - ) - .unwrap() -}); - -pub static SCHEMADB_GET_BYTES: Lazy = Lazy::new(|| { - register_histogram_vec!( - // metric name - "schemadb_get_bytes", - // metric description - "Schemadb get call returned data size in bytes", - // metric labels (dimensions) - &["cf_name"] - ) - .unwrap() -}); - -pub static SCHEMADB_BATCH_COMMIT_LATENCY_SECONDS: Lazy = Lazy::new(|| { - register_histogram_vec!( - // metric name - "schemadb_batch_commit_latency_seconds", - // metric description - "Schemadb schema batch commit latency in seconds", - // metric labels (dimensions) - &["db_name"], - exponential_buckets(/*start=*/ 1e-3, /*factor=*/ 2.0, /*count=*/ 20).unwrap(), - ) - .unwrap() -}); - -pub static SCHEMADB_BATCH_COMMIT_BYTES: Lazy = Lazy::new(|| { - register_histogram_vec!( - // metric name - "schemadb_batch_commit_bytes", - // metric description - "Schemadb schema batch commit size in bytes", - // metric labels (dimensions) - &["db_name"] - ) - .unwrap() -}); - -pub static SCHEMADB_PUT_BYTES: Lazy = Lazy::new(|| { - register_histogram_vec!( - // metric name - "sov_schema_db_put_bytes", - // metric description - "sov_schema_db put call puts data size in bytes", - // metric labels (dimensions) - &["cf_name"] - ) - .unwrap() -}); - -pub static SCHEMADB_DELETES: Lazy = Lazy::new(|| { - register_int_counter_vec!("storage_deletes", "Storage delete calls", &["cf_name"]).unwrap() -}); - -pub static SCHEMADB_BATCH_PUT_LATENCY_SECONDS: Lazy = Lazy::new(|| { - register_histogram_vec!( - // metric name - "sov_schema_db_batch_put_latency_seconds", - // metric description - "sov_schema_db schema batch put latency in seconds", - // metric labels (dimensions) - &["db_name"], - exponential_buckets(/*start=*/ 1e-3, /*factor=*/ 2.0, /*count=*/ 20).unwrap(), - ) - .unwrap() +/// This defines the struct which encapsulates all metrics used for schema DB. +/// +/// It is unused because we directly use gauge and histogram macros since that is the +/// only way in which we can provide additional labels to the metric. +/// However, deriving `Metrics` here is convenient to provide descriptions for each of +/// the metrics. +#[allow(unused)] +#[derive(Metrics)] +#[metrics(scope = "schemadb")] +pub struct SchemaDbMetrics { + #[metric(describe = "Storage delete calls")] + pub(crate) deletes: Counter, + #[metric(describe = "Schemadb iter latency in seconds")] + pub(crate) iter_latency_seconds: Histogram, + #[metric(describe = "Schemadb iter size in bytes")] + pub(crate) iter_bytes: Histogram, + #[metric(describe = "Schemadb get latency in seconds")] + pub(crate) get_latency_seconds: Histogram, + #[metric(describe = "Schemadb get call returned data size in bytes")] + pub(crate) get_bytes: Histogram, + #[metric(describe = "Schemadb schema batch commit latency in seconds")] + pub(crate) batch_commit_latency_seconds: Histogram, + #[metric(describe = "Schemadb schema batch commit size in bytes")] + pub(crate) batch_commit_bytes: Histogram, + #[metric(describe = "sov_schema_db put call puts data size in bytes")] + pub(crate) batch_put_bytes: Histogram, + #[metric(describe = "sov_schema_db schema batch put latency in seconds")] + pub(crate) batch_put_latency_seconds: Histogram, +} + +/// Schema DB metrics +pub static SCHEMADB_METRICS: Lazy = Lazy::new(|| { + SchemaDbMetrics::describe(); + SchemaDbMetrics::default() }); diff --git a/crates/sovereign-sdk/full-node/db/sov-schema-db/src/schema_batch.rs b/crates/sovereign-sdk/full-node/db/sov-schema-db/src/schema_batch.rs index 46952edfa..0a83d3439 100644 --- a/crates/sovereign-sdk/full-node/db/sov-schema-db/src/schema_batch.rs +++ b/crates/sovereign-sdk/full-node/db/sov-schema-db/src/schema_batch.rs @@ -1,7 +1,9 @@ use std::collections::{btree_map, BTreeMap, HashMap}; use std::iter::Rev; +use std::time::Instant; + +use metrics::histogram; -use crate::metrics::SCHEMADB_BATCH_PUT_LATENCY_SECONDS; use crate::schema::{ColumnFamilyName, KeyCodec, ValueCodec}; use crate::{Operation, Schema, SchemaKey}; @@ -26,14 +28,17 @@ impl SchemaBatch { key: &impl KeyCodec, value: &impl ValueCodec, ) -> anyhow::Result<()> { - let _timer = SCHEMADB_BATCH_PUT_LATENCY_SECONDS - .with_label_values(&["unknown"]) - .start_timer(); + let start = Instant::now(); let key = key.encode_key()?; let put_operation = Operation::Put { value: value.encode_value()?, }; self.insert_operation::(key, put_operation); + histogram!("schemadb_batch_put_latency_seconds").record( + Instant::now() + .saturating_duration_since(start) + .as_secs_f64(), + ); Ok(()) } diff --git a/docker/docker-compose.telemetry.yaml b/docker/docker-compose.telemetry.yaml new file mode 100644 index 000000000..6a36ee934 --- /dev/null +++ b/docker/docker-compose.telemetry.yaml @@ -0,0 +1,37 @@ +services: + prometheus: + image: prom/prometheus + ports: + - 9090:9090 + volumes: + - ./telemetry/prometheus.yml:/etc/prometheus/prometheus.yml + networks: + - monitoring + extra_hosts: + - "host.docker.internal:host-gateway" + + grafana: + image: grafana/grafana-enterprise + ports: + - 3000:3000 + environment: + - GF_SECURITY_ADMIN_PASSWORD=password + networks: + - monitoring + + cadvisor: + image: gcr.io/cadvisor/cadvisor + ports: + - 8080:8080 + volumes: + - /:/rootfs:ro + - /var/run:/var/run:ro + - /sys:/sys:ro + - /var/lib/docker/:/var/lib/docker:ro + - /var/run/docker.sock:/var/run/docker.sock:ro # Add only if you have your containers running on Mac + networks: + - monitoring + +networks: + monitoring: + driver: bridge diff --git a/docker/telemetry/prometheus.yml b/docker/telemetry/prometheus.yml new file mode 100644 index 000000000..f862e6fec --- /dev/null +++ b/docker/telemetry/prometheus.yml @@ -0,0 +1,22 @@ +global: + scrape_interval: 15s + +scrape_configs: + - job_name: 'prometheus' + static_configs: + - targets: ['localhost:9090'] + - job_name: 'cadvisor' + static_configs: + - targets: ['cadvisor:8080'] + - job_name: 'sequencer' + static_configs: + - targets: ['host.docker.internal:8001'] + - job_name: 'fullnode' + static_configs: + - targets: ['host.docker.internal:8002'] + - job_name: 'batch-prover' + static_configs: + - targets: ['host.docker.internal:8003'] + - job_name: 'light-client' + static_configs: + - targets: ['host.docker.internal:8004'] diff --git a/resources/grafana/batch-prover.dashboard.json b/resources/grafana/batch-prover.dashboard.json new file mode 100644 index 000000000..6d536838b --- /dev/null +++ b/resources/grafana/batch-prover.dashboard.json @@ -0,0 +1,469 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 4, + "links": [], + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 1, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "batch_prover_current_l1_block", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Current L1 block", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 0 + }, + "id": 2, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "disableTextWrap": false, + "editorMode": "builder", + "expr": "batch_prover_current_l2_block", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Current L2 block", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 8 + }, + "id": 3, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "disableTextWrap": false, + "editorMode": "builder", + "expr": "batch_prover_process_soft_confirmation", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Process soft confirmation", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 8 + }, + "id": 4, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "disableTextWrap": false, + "editorMode": "builder", + "expr": "proving_session_cycle_count", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Proving session cycle count", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 16 + }, + "id": 5, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "disableTextWrap": false, + "editorMode": "builder", + "expr": "mine_da_transaction", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Mine DA transaction", + "type": "timeseries" + } + ], + "preload": false, + "schemaVersion": 40, + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "browser", + "title": "Citrea Batch Prover", + "uid": "ee6vu1k3xzb40b", + "version": 8, + "weekStart": "" +} diff --git a/resources/grafana/fullnode.dashboard.json b/resources/grafana/fullnode.dashboard.json new file mode 100644 index 000000000..eb1b6f9ba --- /dev/null +++ b/resources/grafana/fullnode.dashboard.json @@ -0,0 +1,374 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 3, + "links": [], + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 1, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "fullnode_current_l1_block", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Current L1 block", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 0 + }, + "id": 2, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "disableTextWrap": false, + "editorMode": "builder", + "expr": "fullnode_current_l2_block", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Current L2 block", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 8 + }, + "id": 3, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "disableTextWrap": false, + "editorMode": "builder", + "expr": "fullnode_scan_l1_block", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "L1 block scan", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 8 + }, + "id": 4, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "disableTextWrap": false, + "editorMode": "builder", + "expr": "fullnode_process_soft_confirmation", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Process soft confirmation", + "type": "timeseries" + } + ], + "preload": false, + "refresh": "5s", + "schemaVersion": 40, + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "browser", + "title": "Citrea Fullnode", + "uid": "fe6skeqv8msxsb", + "version": 6, + "weekStart": "" +} diff --git a/resources/grafana/light-client.dashboard.json b/resources/grafana/light-client.dashboard.json new file mode 100644 index 000000000..00042e53a --- /dev/null +++ b/resources/grafana/light-client.dashboard.json @@ -0,0 +1,113 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 5, + "links": [], + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 1, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "light_client_prover_current_l1_block", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Current L1 block", + "type": "stat" + } + ], + "preload": false, + "schemaVersion": 40, + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "browser", + "title": "Citrea Light Client", + "uid": "de6vv8uc47cowf", + "version": 3, + "weekStart": "" +} diff --git a/resources/grafana/sequencer.dashboard.json b/resources/grafana/sequencer.dashboard.json new file mode 100644 index 000000000..fdba52384 --- /dev/null +++ b/resources/grafana/sequencer.dashboard.json @@ -0,0 +1,729 @@ +{ + "annotations": { + "list": [ + { + "builtIn": 1, + "datasource": { + "type": "grafana", + "uid": "-- Grafana --" + }, + "enable": true, + "hide": true, + "iconColor": "rgba(0, 211, 255, 1)", + "name": "Annotations & Alerts", + "type": "dashboard" + } + ] + }, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": 2, + "links": [], + "panels": [ + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 0 + }, + "id": 1, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "disableTextWrap": false, + "editorMode": "builder", + "expr": "sequencer_current_l1_block", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Current L1 block", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 0 + }, + "id": 8, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "disableTextWrap": false, + "editorMode": "builder", + "expr": "sequencer_current_l2_block", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Current L2 block", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 8 + }, + "id": 5, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "disableTextWrap": false, + "editorMode": "builder", + "expr": "sequencer_block_production_execution", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Produce L2 block", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "thresholds" + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 8 + }, + "id": 2, + "options": { + "colorMode": "value", + "graphMode": "none", + "justifyMode": "auto", + "orientation": "auto", + "percentChangeColorMode": "standard", + "reduceOptions": { + "calcs": [ + "lastNotNull" + ], + "fields": "", + "values": false + }, + "showPercentChange": false, + "textMode": "auto", + "wideLayout": true + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "disableTextWrap": false, + "editorMode": "builder", + "expr": "sequencer_mempool_txs", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Mempool transactions", + "type": "stat" + }, + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 16 + }, + "id": 4, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "disableTextWrap": false, + "editorMode": "builder", + "expr": "sequencer_dry_run_execution", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Dry run transactions", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 16 + }, + "id": 3, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "disableTextWrap": false, + "editorMode": "builder", + "expr": "rate(sequencer_mempool_txs[$__rate_interval])", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Mempool inbound tx/s", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "linear", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 0, + "y": 24 + }, + "id": 6, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "disableTextWrap": false, + "editorMode": "builder", + "expr": "sequencer_send_commitment_execution", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Commit to L1", + "type": "timeseries" + }, + { + "datasource": { + "type": "prometheus", + "uid": "ee6shwrmylmo0b" + }, + "fieldConfig": { + "defaults": { + "color": { + "mode": "palette-classic" + }, + "custom": { + "axisBorderShow": false, + "axisCenteredZero": false, + "axisColorMode": "text", + "axisLabel": "", + "axisPlacement": "auto", + "barAlignment": 0, + "barWidthFactor": 0.6, + "drawStyle": "line", + "fillOpacity": 0, + "gradientMode": "none", + "hideFrom": { + "legend": false, + "tooltip": false, + "viz": false + }, + "insertNulls": false, + "lineInterpolation": "stepBefore", + "lineWidth": 1, + "pointSize": 5, + "scaleDistribution": { + "type": "linear" + }, + "showPoints": "auto", + "spanNulls": false, + "stacking": { + "group": "A", + "mode": "none" + }, + "thresholdsStyle": { + "mode": "off" + } + }, + "mappings": [], + "thresholds": { + "mode": "absolute", + "steps": [ + { + "color": "green", + "value": null + }, + { + "color": "red", + "value": 80 + } + ] + } + }, + "overrides": [] + }, + "gridPos": { + "h": 8, + "w": 12, + "x": 12, + "y": 24 + }, + "id": 7, + "options": { + "legend": { + "calcs": [], + "displayMode": "list", + "placement": "bottom", + "showLegend": true + }, + "tooltip": { + "mode": "single", + "sort": "none" + } + }, + "pluginVersion": "11.4.0", + "targets": [ + { + "disableTextWrap": false, + "editorMode": "builder", + "expr": "sequencer_commitment_blocks_count", + "fullMetaSearch": false, + "includeNullMetadata": true, + "legendFormat": "__auto", + "range": true, + "refId": "A", + "useBackend": false + } + ], + "title": "Commitment blocks count", + "type": "timeseries" + } + ], + "preload": false, + "schemaVersion": 40, + "tags": [], + "templating": { + "list": [] + }, + "time": { + "from": "now-6h", + "to": "now" + }, + "timepicker": {}, + "timezone": "browser", + "title": "Citrea Sequencer", + "uid": "ce6shz4qdkow0f", + "version": 11, + "weekStart": "" +} From 94e2bb2ca2357a84e9241cc9ad8dbf6b5c27e1ba Mon Sep 17 00:00:00 2001 From: Rakan Al-Huneiti Date: Mon, 16 Dec 2024 16:48:23 +0300 Subject: [PATCH 08/10] Fix ci tests - metrics related (#1612) --- Makefile | 1 + crates/common/src/config.rs | 11 +---------- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index 739c962b7..c925c1375 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,7 @@ clean: ## Cleans compiled @cargo clean clean-node: ## Cleans local dbs needed for sequencer and nodes + rm -rf resources/dbs/da-db rm -rf resources/dbs/sequencer-db rm -rf resources/dbs/batch-prover-db rm -rf resources/dbs/light-client-prover-db diff --git a/crates/common/src/config.rs b/crates/common/src/config.rs index cf848f1bc..3985b02dd 100644 --- a/crates/common/src/config.rs +++ b/crates/common/src/config.rs @@ -410,7 +410,7 @@ impl FromEnv for SequencerMempoolConfig { } /// Telemetry configuration. -#[derive(Debug, Clone, PartialEq, Deserialize, Serialize)] +#[derive(Debug, Default, Clone, PartialEq, Deserialize, Serialize)] pub struct TelemetryConfig { /// Server host. pub bind_host: Option, @@ -418,15 +418,6 @@ pub struct TelemetryConfig { pub bind_port: Option, } -impl Default for TelemetryConfig { - fn default() -> Self { - Self { - bind_host: Some("0.0.0.0".to_owned()), - bind_port: Some(8081), - } - } -} - impl FromEnv for TelemetryConfig { fn from_env() -> anyhow::Result { let bind_host = std::env::var("TELEMETRY_BIND_HOST").ok(); From fee8fbd44268b03e5b05c3ed0f713c37edf2ce1c Mon Sep 17 00:00:00 2001 From: jfldde <168934971+jfldde@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:00:41 +0100 Subject: [PATCH 09/10] E2E Tests: Fix flakiness (#1615) --- Cargo.lock | 2 +- Cargo.toml | 2 +- .../tests/bitcoin_e2e/batch_prover_test.rs | 98 +++++++------------ .../tests/bitcoin_e2e/light_client_test.rs | 14 +-- .../bitcoin_e2e/sequencer_commitments.rs | 12 ++- bin/citrea/tests/bitcoin_e2e/tx_chain.rs | 9 ++ bin/citrea/tests/e2e/mod.rs | 4 +- crates/primitives/src/forks.rs | 4 +- 8 files changed, 59 insertions(+), 86 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 259ade3d7..16c3bca3f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1872,7 +1872,7 @@ dependencies = [ [[package]] name = "citrea-e2e" version = "0.1.0" -source = "git+https://github.com/chainwayxyz/citrea-e2e?rev=6ba7230#6ba7230a137931c0d7a002092f0b38beb4d73d17" +source = "git+https://github.com/chainwayxyz/citrea-e2e?rev=efde07d#efde07d66183948e1a4d6ee6ab0d364fd2b5d05c" dependencies = [ "anyhow", "async-trait", diff --git a/Cargo.toml b/Cargo.toml index 54a8d1c97..51c4d9692 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -148,7 +148,7 @@ alloy = { version = "0.2.1", default-features = false } alloy-eips = { version = "0.2.1", default-features = false } alloy-consensus = { version = "0.2.1", default-features = false } -citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "6ba7230" } +citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "efde07d" } [patch.crates-io] bitcoincore-rpc = { version = "0.18.0", git = "https://github.com/chainwayxyz/rust-bitcoincore-rpc.git", rev = "ca3cfa2" } diff --git a/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs b/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs index 6c916e591..cf2e49452 100644 --- a/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs +++ b/bin/citrea/tests/bitcoin_e2e/batch_prover_test.rs @@ -33,7 +33,7 @@ pub async fn wait_for_zkproofs( timeout: Option, ) -> Result> { let start = Instant::now(); - let timeout = timeout.unwrap_or(Duration::from_secs(30)); + let timeout = timeout.unwrap_or(Duration::from_secs(240)); loop { if start.elapsed() >= timeout { @@ -68,32 +68,11 @@ impl TestCase for BasicProverTest { } } - fn sequencer_config() -> SequencerConfig { - SequencerConfig { - min_soft_confirmations_per_commitment: 10, - ..Default::default() - } - } - async fn run_test(&mut self, f: &mut TestFramework) -> Result<()> { - let Some(sequencer) = &f.sequencer else { - bail!("Sequencer not running. Set TestCaseConfig with_sequencer to true") - }; - - let Some(batch_prover) = &f.batch_prover else { - bail!("Batch Prover not running. Set TestCaseConfig with_batch_prover to true") - }; - - let Some(full_node) = &f.full_node else { - bail!("FullNode not running. Set TestCaseConfig with_full_node to true") - }; - - let Some(da) = f.bitcoin_nodes.get(0) else { - bail!("bitcoind not running. Test cannot run with bitcoind running as DA") - }; - - // Generate confirmed UTXOs - da.generate(120).await?; + let da = f.bitcoin_nodes.get(0).unwrap(); + let sequencer = f.sequencer.as_ref().unwrap(); + let batch_prover = f.batch_prover.as_ref().unwrap(); + let full_node = f.full_node.as_ref().unwrap(); let min_soft_confirmations_per_commitment = sequencer.min_soft_confirmations_per_commitment(); @@ -102,8 +81,6 @@ impl TestCase for BasicProverTest { sequencer.client.send_publish_batch_request().await?; } - da.generate(FINALITY_DEPTH).await?; - // Wait for blob inscribe tx to be in mempool da.wait_mempool_len(2, None).await?; @@ -114,6 +91,9 @@ impl TestCase for BasicProverTest { .wait_for_l1_height(finalized_height, None) .await?; + // Wait for batch proof tx to hit mempool + da.wait_mempool_len(2, None).await?; + da.generate(FINALITY_DEPTH).await?; let proofs = wait_for_zkproofs( full_node, @@ -168,23 +148,10 @@ impl TestCase for SkipPreprovenCommitmentsTest { } async fn run_test(&mut self, f: &mut TestFramework) -> Result<()> { - let Some(sequencer) = &f.sequencer else { - bail!("Sequencer not running. Set TestCaseConfig with_sequencer to true") - }; - - let Some(prover) = &f.batch_prover else { - bail!("Batch Prover not running. Set TestCaseConfig with_batch_prover to true") - }; - - let Some(full_node) = &f.full_node else { - bail!("FullNode not running. Set TestCaseConfig with_full_node to true") - }; - - let Some(da) = f.bitcoin_nodes.get(0) else { - bail!("bitcoind not running. Test cannot run with bitcoind running as DA") - }; - - let _initial_height = f.initial_da_height; + let da = f.bitcoin_nodes.get(0).unwrap(); + let sequencer = f.sequencer.as_ref().unwrap(); + let batch_prover = f.batch_prover.as_ref().unwrap(); + let full_node = f.full_node.as_ref().unwrap(); let da_config = &f.bitcoin_nodes.get(0).unwrap().config; let bitcoin_da_service_config = BitcoinServiceConfig { @@ -240,26 +207,23 @@ impl TestCase for SkipPreprovenCommitmentsTest { sequencer.client.send_publish_batch_request().await?; } - da.generate(FINALITY_DEPTH).await?; - // Wait for blob inscribe tx to be in mempool da.wait_mempool_len(2, None).await?; da.generate(FINALITY_DEPTH).await?; let finalized_height = da.get_finalized_height().await?; - prover + batch_prover .wait_for_l1_height(finalized_height, Some(Duration::from_secs(300))) .await?; + // Wait for batch proof tx to hit mempool + da.wait_mempool_len(2, None).await?; + da.generate(FINALITY_DEPTH).await?; - let proofs = wait_for_zkproofs( - full_node, - finalized_height + FINALITY_DEPTH, - Some(Duration::from_secs(120)), - ) - .await - .unwrap(); + let proofs = wait_for_zkproofs(full_node, finalized_height + FINALITY_DEPTH, None) + .await + .unwrap(); assert!(proofs .first() @@ -313,22 +277,23 @@ impl TestCase for SkipPreprovenCommitmentsTest { da.wait_mempool_len(4, None).await?; da.generate(FINALITY_DEPTH).await?; - let finalized_height = da.get_finalized_height().await?; - prover + batch_prover .wait_for_l1_height(finalized_height, Some(Duration::from_secs(300))) .await?; + // Wait for batch proof tx to hit mempool + da.wait_mempool_len(2, None).await?; + da.generate(FINALITY_DEPTH).await?; + let finalized_height = da.get_finalized_height().await?; - let proofs = wait_for_zkproofs( - full_node, - finalized_height + FINALITY_DEPTH, - Some(Duration::from_secs(120)), - ) - .await - .unwrap(); + // Wait for the full node to see all process verify and store all batch proofs + full_node.wait_for_l1_height(finalized_height, None).await?; + let proofs = wait_for_zkproofs(full_node, finalized_height, None) + .await + .unwrap(); assert_eq!( proofs @@ -519,12 +484,15 @@ impl TestCase for ParallelProvingTest { .wait_for_l1_height(finalized_height, Some(Duration::from_secs(1800))) .await?; + // Wait for batch proof tx to hit mempool + da.wait_mempool_len(2, None).await?; + // Write 2 batch proofs to a finalized DA block da.generate(FINALITY_DEPTH).await?; let finalized_height = da.get_finalized_height().await?; // Retrieve proofs from fullnode - let proofs = wait_for_zkproofs(full_node, finalized_height, Some(Duration::from_secs(120))) + let proofs = wait_for_zkproofs(full_node, finalized_height, None) .await .unwrap(); dbg!(proofs.len()); diff --git a/bin/citrea/tests/bitcoin_e2e/light_client_test.rs b/bin/citrea/tests/bitcoin_e2e/light_client_test.rs index b3ae468d6..f444a6dbf 100644 --- a/bin/citrea/tests/bitcoin_e2e/light_client_test.rs +++ b/bin/citrea/tests/bitcoin_e2e/light_client_test.rs @@ -254,12 +254,7 @@ impl TestCase for LightClientProvingTestMultipleProofs { full_node .wait_for_l1_height(batch_proof_l1_height, Some(TEN_MINS)) .await?; - let batch_proofs = wait_for_zkproofs( - full_node, - batch_proof_l1_height, - Some(Duration::from_secs(30)), - ) - .await?; + let batch_proofs = wait_for_zkproofs(full_node, batch_proof_l1_height, None).await?; assert_eq!(batch_proofs.len(), 2); // Wait for light client prover to process batch proofs. @@ -394,12 +389,7 @@ impl TestCase for LightClientProvingTestMultipleProofs { full_node .wait_for_l1_height(batch_proof_l1_height, Some(TEN_MINS)) .await?; - let batch_proofs = wait_for_zkproofs( - full_node, - batch_proof_l1_height, - Some(Duration::from_secs(30)), - ) - .await?; + let batch_proofs = wait_for_zkproofs(full_node, batch_proof_l1_height, None).await?; assert_eq!(batch_proofs.len(), 1); // Wait for light client prover to process batch proofs. diff --git a/bin/citrea/tests/bitcoin_e2e/sequencer_commitments.rs b/bin/citrea/tests/bitcoin_e2e/sequencer_commitments.rs index 751eaf70e..b37afe582 100644 --- a/bin/citrea/tests/bitcoin_e2e/sequencer_commitments.rs +++ b/bin/citrea/tests/bitcoin_e2e/sequencer_commitments.rs @@ -30,7 +30,7 @@ pub async fn wait_for_sequencer_commitments( timeout: Option, ) -> Result> { let start = Instant::now(); - let timeout = timeout.unwrap_or(Duration::from_secs(30)); + let timeout = timeout.unwrap_or(Duration::from_secs(120)); loop { if start.elapsed() >= timeout { @@ -102,7 +102,10 @@ impl TestCase for LedgerGetCommitmentsProverTest { assert_eq!(commitments.len(), 1); assert_eq!(commitments[0].l2_start_block_number, 1); - assert_eq!(commitments[0].l2_end_block_number, 4); + assert_eq!( + commitments[0].l2_end_block_number, + min_soft_confirmations_per_commitment + ); assert_eq!(commitments[0].found_in_l1, finalized_height); @@ -172,7 +175,10 @@ impl TestCase for LedgerGetCommitmentsTest { assert_eq!(commitments.len(), 1); assert_eq!(commitments[0].l2_start_block_number, 1); - assert_eq!(commitments[0].l2_end_block_number, 4); + assert_eq!( + commitments[0].l2_end_block_number, + min_soft_confirmations_per_commitment + ); assert_eq!(commitments[0].found_in_l1, finalized_height); diff --git a/bin/citrea/tests/bitcoin_e2e/tx_chain.rs b/bin/citrea/tests/bitcoin_e2e/tx_chain.rs index 5f5ebd141..d7877f29b 100644 --- a/bin/citrea/tests/bitcoin_e2e/tx_chain.rs +++ b/bin/citrea/tests/bitcoin_e2e/tx_chain.rs @@ -304,6 +304,9 @@ impl TestCase for TestProverTransactionChaining { .wait_for_l1_height(finalized_height, None) .await?; + // Wait for batch proof tx to hit mempool + da.wait_mempool_len(2, None).await?; + da.generate(1).await?; let block_height = da.get_block_count().await?; @@ -344,6 +347,9 @@ impl TestCase for TestProverTransactionChaining { .wait_for_l1_height(finalized_height, None) .await?; + // Wait for batch proof tx to hit mempool + da.wait_mempool_len(2, None).await?; + da.generate(1).await?; let block_height = da.get_block_count().await?; @@ -386,6 +392,9 @@ impl TestCase for TestProverTransactionChaining { .wait_for_l1_height(finalized_height, None) .await?; + // Wait for batch proof tx to hit mempool + da.wait_mempool_len(2, None).await?; + da.generate(1).await?; let block_height = da.get_block_count().await?; diff --git a/bin/citrea/tests/e2e/mod.rs b/bin/citrea/tests/e2e/mod.rs index c52251058..ff60ca61a 100644 --- a/bin/citrea/tests/e2e/mod.rs +++ b/bin/citrea/tests/e2e/mod.rs @@ -646,11 +646,11 @@ async fn test_offchain_contract_storage() { assert_eq!(code.to_vec()[..runtime_code.len()], runtime_code.to_vec()); // reach the block at which the fork will be activated - for _ in 3..=10000 { + for _ in 3..=1000 { sequencer_client.spam_publish_batch_request().await.unwrap(); } - wait_for_l2_block(&sequencer_client, 10000, Some(Duration::from_secs(300))).await; + wait_for_l2_block(&sequencer_client, 1000, Some(Duration::from_secs(300))).await; let seq_height = sequencer_client.eth_block_number().await; let seq_fork = fork_from_block_number(FORKS, seq_height); diff --git a/crates/primitives/src/forks.rs b/crates/primitives/src/forks.rs index 34ea70d00..6934c7c86 100644 --- a/crates/primitives/src/forks.rs +++ b/crates/primitives/src/forks.rs @@ -25,11 +25,11 @@ pub const FORKS: &[Fork] = &[ }, Fork { spec_id: SpecId::Fork1, - activation_height: 10000, + activation_height: 1000, }, Fork { spec_id: SpecId::Fork2, - activation_height: 20000, + activation_height: 2000, }, ]; From 7e1480bb0abc7f6d55377d2f520838b221d83aac Mon Sep 17 00:00:00 2001 From: Rakan Al-Huneiti Date: Mon, 16 Dec 2024 22:12:02 +0300 Subject: [PATCH 10/10] Improve light client initialization (#1611) --- Cargo.lock | 5 +- Cargo.toml | 2 +- bin/citrea/src/main.rs | 8 ++- bin/citrea/src/rollup/mod.rs | 15 +++-- .../tests/bitcoin_e2e/light_client_test.rs | 2 + bin/citrea/tests/test_helpers/mod.rs | 9 ++- crates/batch-prover/src/runner.rs | 15 +---- crates/common/Cargo.toml | 2 + crates/common/src/config.rs | 4 ++ crates/common/src/da.rs | 16 ++++++ crates/light-client-prover/Cargo.toml | 2 - crates/light-client-prover/src/runner.rs | 55 +------------------ 12 files changed, 53 insertions(+), 82 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 16c3bca3f..3577e0692 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1854,9 +1854,11 @@ dependencies = [ "hyper", "jsonrpsee", "lru", + "reth-primitives", "serde", "serde_json", "sov-db", + "sov-ledger-rpc", "sov-mock-da", "sov-modules-api", "sov-rollup-interface", @@ -1872,7 +1874,7 @@ dependencies = [ [[package]] name = "citrea-e2e" version = "0.1.0" -source = "git+https://github.com/chainwayxyz/citrea-e2e?rev=efde07d#efde07d66183948e1a4d6ee6ab0d364fd2b5d05c" +source = "git+https://github.com/chainwayxyz/citrea-e2e?rev=51a4d19#51a4d1958ead4021115bd81ac9aa1b1fcf6f7e0c" dependencies = [ "anyhow", "async-trait", @@ -1999,7 +2001,6 @@ dependencies = [ "sov-mock-da", "sov-mock-zkvm", "sov-modules-api", - "sov-modules-rollup-blueprint", "sov-rollup-interface", "sov-stf-runner", "tempfile", diff --git a/Cargo.toml b/Cargo.toml index 51c4d9692..ab9603ef6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -148,7 +148,7 @@ alloy = { version = "0.2.1", default-features = false } alloy-eips = { version = "0.2.1", default-features = false } alloy-consensus = { version = "0.2.1", default-features = false } -citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "efde07d" } +citrea-e2e = { git = "https://github.com/chainwayxyz/citrea-e2e", rev = "51a4d19" } [patch.crates-io] bitcoincore-rpc = { version = "0.18.0", git = "https://github.com/chainwayxyz/rust-bitcoincore-rpc.git", rev = "ca3cfa2" } diff --git a/bin/citrea/src/main.rs b/bin/citrea/src/main.rs index 82523fc21..d6596a0f9 100644 --- a/bin/citrea/src/main.rs +++ b/bin/citrea/src/main.rs @@ -256,13 +256,19 @@ where error!("Error: {}", e); } } else if let Some(light_client_prover_config) = light_client_prover_config { - let prover = CitreaRollupBlueprint::create_new_light_client_prover( + let (mut prover, rpc_methods) = CitreaRollupBlueprint::create_new_light_client_prover( &rollup_blueprint, rollup_config, light_client_prover_config, ) .await .expect("Could not start light client prover"); + + prover + .start_rpc_server(rpc_methods, None) + .await + .expect("Failed to start rpc server"); + if let Err(e) = prover.run().await { error!("Error: {}", e); } diff --git a/bin/citrea/src/rollup/mod.rs b/bin/citrea/src/rollup/mod.rs index e67bf7395..964c16ccb 100644 --- a/bin/citrea/src/rollup/mod.rs +++ b/bin/citrea/src/rollup/mod.rs @@ -6,7 +6,7 @@ use citrea_batch_prover::CitreaBatchProver; use citrea_common::tasks::manager::TaskManager; use citrea_common::{BatchProverConfig, FullNodeConfig, LightClientProverConfig, SequencerConfig}; use citrea_fullnode::CitreaFullnode; -use citrea_light_client_prover::runner::{CitreaLightClientProver, LightClientProver}; +use citrea_light_client_prover::runner::CitreaLightClientProver; use citrea_primitives::forks::FORKS; use citrea_sequencer::CitreaSequencer; use jsonrpsee::RpcModule; @@ -424,7 +424,13 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { &self, rollup_config: FullNodeConfig, prover_config: LightClientProverConfig, - ) -> Result, anyhow::Error> + ) -> Result< + ( + CitreaLightClientProver, + RpcModule<()>, + ), + anyhow::Error, + > where ::Storage: NativeStorage, { @@ -501,9 +507,6 @@ pub trait CitreaRollupBlueprint: RollupBlueprint { task_manager, )?; - Ok(LightClientProver { - runner, - rpc_methods, - }) + Ok((runner, rpc_methods)) } } diff --git a/bin/citrea/tests/bitcoin_e2e/light_client_test.rs b/bin/citrea/tests/bitcoin_e2e/light_client_test.rs index f444a6dbf..5ca293243 100644 --- a/bin/citrea/tests/bitcoin_e2e/light_client_test.rs +++ b/bin/citrea/tests/bitcoin_e2e/light_client_test.rs @@ -53,6 +53,7 @@ impl TestCase for LightClientProvingTest { fn light_client_prover_config() -> LightClientProverConfig { LightClientProverConfig { enable_recovery: false, + initial_da_height: 171, ..Default::default() } } @@ -187,6 +188,7 @@ impl TestCase for LightClientProvingTestMultipleProofs { fn light_client_prover_config() -> LightClientProverConfig { LightClientProverConfig { enable_recovery: false, + initial_da_height: 171, ..Default::default() } } diff --git a/bin/citrea/tests/test_helpers/mod.rs b/bin/citrea/tests/test_helpers/mod.rs index 97b451c79..795003091 100644 --- a/bin/citrea/tests/test_helpers/mod.rs +++ b/bin/citrea/tests/test_helpers/mod.rs @@ -107,7 +107,7 @@ pub async fn start_rollup( rollup.run().instrument(span).await.unwrap(); } else if let Some(light_client_prover_config) = light_client_prover_config { let span = info_span!("LightClientProver"); - let rollup = CitreaRollupBlueprint::create_new_light_client_prover( + let (mut rollup, rpc_methods) = CitreaRollupBlueprint::create_new_light_client_prover( &mock_demo_rollup, rollup_config.clone(), light_client_prover_config, @@ -115,11 +115,14 @@ pub async fn start_rollup( .instrument(span.clone()) .await .unwrap(); + rollup - .run_and_report_rpc_port(Some(rpc_reporting_channel)) - .instrument(span) + .start_rpc_server(rpc_methods, Some(rpc_reporting_channel)) + .instrument(span.clone()) .await .unwrap(); + + rollup.run().instrument(span).await.unwrap(); } else { let span = info_span!("FullNode"); let (mut rollup, rpc_methods) = CitreaRollupBlueprint::create_new_rollup( diff --git a/crates/batch-prover/src/runner.rs b/crates/batch-prover/src/runner.rs index fdc965c8b..f522ba7e3 100644 --- a/crates/batch-prover/src/runner.rs +++ b/crates/batch-prover/src/runner.rs @@ -8,7 +8,7 @@ use anyhow::{anyhow, bail, Context as _}; use backoff::exponential::ExponentialBackoffBuilder; use backoff::future::retry as retry_backoff; use citrea_common::cache::L1BlockCache; -use citrea_common::da::get_da_block_at_height; +use citrea_common::da::{get_da_block_at_height, get_initial_slot_height}; use citrea_common::tasks::manager::TaskManager; use citrea_common::utils::{create_shutdown_signal, soft_confirmation_to_receipt}; use citrea_common::{BatchProverConfig, RollupPublicKeys, RpcConfig, RunnerConfig}; @@ -583,16 +583,3 @@ async fn sync_l2( } } } - -async fn get_initial_slot_height(client: &HttpClient) -> u64 { - loop { - match client.get_soft_confirmation_by_number(U64::from(1)).await { - Ok(Some(batch)) => return batch.da_slot_height, - _ => { - // sleep 1 - tokio::time::sleep(std::time::Duration::from_secs(1)).await; - continue; - } - } - } -} diff --git a/crates/common/Cargo.toml b/crates/common/Cargo.toml index 9fd80e067..d76a8195a 100644 --- a/crates/common/Cargo.toml +++ b/crates/common/Cargo.toml @@ -20,6 +20,7 @@ hex = { workspace = true } hyper = { workspace = true } jsonrpsee = { workspace = true, features = ["http-client", "server"] } lru = { workspace = true } +reth-primitives = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } tokio = { workspace = true } @@ -30,6 +31,7 @@ tracing = { workspace = true } # Sov SDK deps sov-db = { path = "../sovereign-sdk/full-node/db/sov-db" } +sov-ledger-rpc = { path = "../sovereign-sdk/full-node/sov-ledger-rpc", features = ["client"] } sov-mock-da = { path = "../sovereign-sdk/adapters/mock-da" } sov-modules-api = { path = "../sovereign-sdk/module-system/sov-modules-api" } sov-rollup-interface = { path = "../sovereign-sdk/rollup-interface" } diff --git a/crates/common/src/config.rs b/crates/common/src/config.rs index 3985b02dd..bf9f39d7a 100644 --- a/crates/common/src/config.rs +++ b/crates/common/src/config.rs @@ -253,6 +253,8 @@ pub struct LightClientProverConfig { pub proof_sampling_number: usize, /// If true prover will try to recover ongoing proving sessions pub enable_recovery: bool, + /// The starting DA block to sync from + pub initial_da_height: u64, } impl Default for BatchProverConfig { @@ -271,6 +273,7 @@ impl Default for LightClientProverConfig { proving_mode: ProverGuestRunConfig::Execute, proof_sampling_number: 0, enable_recovery: true, + initial_da_height: 1, } } } @@ -291,6 +294,7 @@ impl FromEnv for LightClientProverConfig { proving_mode: serde_json::from_str(&format!("\"{}\"", std::env::var("PROVING_MODE")?))?, proof_sampling_number: std::env::var("PROOF_SAMPLING_NUMBER")?.parse()?, enable_recovery: std::env::var("ENABLE_RECOVERY")?.parse()?, + initial_da_height: std::env::var("INITIAL_DA_HEIGHT")?.parse()?, }) } } diff --git a/crates/common/src/da.rs b/crates/common/src/da.rs index f2cdad2dd..779f42de8 100644 --- a/crates/common/src/da.rs +++ b/crates/common/src/da.rs @@ -4,6 +4,9 @@ use std::time::Duration; use anyhow::anyhow; use backoff::future::retry as retry_backoff; use backoff::ExponentialBackoffBuilder; +use jsonrpsee::http_client::HttpClient; +use reth_primitives::U64; +use sov_ledger_rpc::LedgerRpcClient; use sov_rollup_interface::da::{BlockHeaderTrait, SequencerCommitment}; use sov_rollup_interface::services::da::{DaService, SlotData}; use sov_rollup_interface::zk::Proof; @@ -72,3 +75,16 @@ pub async fn extract_zk_proofs( .extract_relevant_zk_proofs(l1_block, prover_da_pub_key) .await } + +pub async fn get_initial_slot_height(client: &HttpClient) -> u64 { + loop { + match client.get_soft_confirmation_by_number(U64::from(1)).await { + Ok(Some(batch)) => return batch.da_slot_height, + _ => { + // sleep 1 + tokio::time::sleep(std::time::Duration::from_secs(1)).await; + continue; + } + } + } +} diff --git a/crates/light-client-prover/Cargo.toml b/crates/light-client-prover/Cargo.toml index 6eed0af60..e3ff4092c 100644 --- a/crates/light-client-prover/Cargo.toml +++ b/crates/light-client-prover/Cargo.toml @@ -17,7 +17,6 @@ citrea-primitives = { path = "../primitives", optional = true } sov-db = { path = "../sovereign-sdk/full-node/db/sov-db", optional = true } sov-ledger-rpc = { path = "../sovereign-sdk/full-node/sov-ledger-rpc", features = ["client"], optional = true } sov-modules-api = { path = "../sovereign-sdk/module-system/sov-modules-api", default-features = false } -sov-modules-rollup-blueprint = { path = "../sovereign-sdk/module-system/sov-modules-rollup-blueprint", optional = true } sov-rollup-interface = { path = "../sovereign-sdk/rollup-interface" } sov-stf-runner = { path = "../sovereign-sdk/full-node/sov-stf-runner", optional = true } @@ -48,7 +47,6 @@ native = [ "dep:citrea-primitives", "dep:citrea-common", "dep:sov-db", - "dep:sov-modules-rollup-blueprint", "dep:sov-stf-runner", "dep:sov-ledger-rpc", "dep:anyhow", diff --git a/crates/light-client-prover/src/runner.rs b/crates/light-client-prover/src/runner.rs index 1675eeb5a..aa69afef4 100644 --- a/crates/light-client-prover/src/runner.rs +++ b/crates/light-client-prover/src/runner.rs @@ -7,11 +7,8 @@ use citrea_common::{LightClientProverConfig, RollupPublicKeys, RpcConfig, Runner use jsonrpsee::http_client::{HttpClient, HttpClientBuilder}; use jsonrpsee::server::{BatchRequestConfig, ServerBuilder}; use jsonrpsee::RpcModule; -use reth_primitives::U64; -use sov_db::ledger_db::{LedgerDB, LightClientProverLedgerOps, SharedLedgerOps}; +use sov_db::ledger_db::{LightClientProverLedgerOps, SharedLedgerOps}; use sov_db::schema::types::SlotNumber; -use sov_ledger_rpc::LedgerRpcClient; -use sov_modules_rollup_blueprint::RollupBlueprint; use sov_rollup_interface::services::da::DaService; use sov_rollup_interface::spec::SpecId; use sov_rollup_interface::zk::ZkvmHost; @@ -23,41 +20,6 @@ use tracing::{error, info, instrument}; use crate::da_block_handler::L1BlockHandler; use crate::rpc::{create_rpc_module, RpcContext}; -/// Dependencies needed to run the rollup. -pub struct LightClientProver { - /// The State Transition Runner. - #[allow(clippy::type_complexity)] - pub runner: CitreaLightClientProver, - /// Rpc methods for the rollup. - pub rpc_methods: jsonrpsee::RpcModule<()>, -} - -impl LightClientProver { - /// Runs the rollup. - #[instrument(level = "trace", skip_all, err, ret(level = "error"))] - pub async fn run(self) -> Result<(), anyhow::Error> { - self.run_and_report_rpc_port(None).await - } - - /// Only run the rpc. - pub async fn run_rpc(mut self) -> Result<(), anyhow::Error> { - self.runner.start_rpc_server(self.rpc_methods, None).await?; - Ok(()) - } - - /// Runs the rollup. Reports rpc port to the caller using the provided channel. - pub async fn run_and_report_rpc_port( - self, - channel: Option>, - ) -> Result<(), anyhow::Error> { - let mut runner = self.runner; - runner.start_rpc_server(self.rpc_methods, channel).await?; - - runner.run().await?; - Ok(()) - } -} - pub struct CitreaLightClientProver where Da: DaService + Send + Sync, @@ -186,7 +148,7 @@ where let last_l1_height_scanned = match self.ledger_db.get_last_scanned_l1_height()? { Some(l1_height) => l1_height, // If not found, start from the first L2 block's L1 height - None => SlotNumber(get_initial_da_height(&self.sequencer_client).await), + None => SlotNumber(self.prover_config.initial_da_height), }; let prover_config = self.prover_config.clone(); @@ -250,16 +212,3 @@ where Ok(rpc_methods) } } - -async fn get_initial_da_height(client: &HttpClient) -> u64 { - loop { - match client.get_soft_confirmation_by_number(U64::from(1)).await { - Ok(Some(batch)) => return batch.da_slot_height, - _ => { - // sleep 1 - tokio::time::sleep(std::time::Duration::from_secs(1)).await; - continue; - } - } - } -}