From 5b3e127cd0ceae4b11a4ac92e9782013abcddd01 Mon Sep 17 00:00:00 2001 From: jfldde <168934971+jfldde@users.noreply.github.com> Date: Fri, 8 Nov 2024 09:18:28 +0000 Subject: [PATCH] Remove circular dependency on citrea --- Cargo.toml | 4 ---- src/client.rs | 50 +++--------------------------------------- src/full_node.rs | 57 +----------------------------------------------- src/node.rs | 2 +- tests/docker.rs | 6 ++--- 5 files changed, 7 insertions(+), 112 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a323b4c..80f2b3f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,9 +22,5 @@ toml = "0.8.0" tracing = { version = "0.1.40", default-features = false } tracing-subscriber = { version = "0.3.17", features = ["env-filter", "json", "fmt"] } -# Citrea dependencies -sov-ledger-rpc = { git = "https://github.com/chainwayxyz/citrea", rev = "962e125", default-features = false, features = ["client"] } -sov-rollup-interface = { git = "https://github.com/chainwayxyz/citrea", rev = "962e125"} - [patch.crates-io] bitcoincore-rpc = { version = "0.18.0", git = "https://github.com/chainwayxyz/rust-bitcoincore-rpc.git", rev = "5ce1bed" } diff --git a/src/client.rs b/src/client.rs index 7f29991..92216bd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -6,10 +6,6 @@ use jsonrpsee::{ http_client::{HttpClient, HttpClientBuilder}, rpc_params, }; -use sov_ledger_rpc::client::RpcClient; -use sov_rollup_interface::rpc::{ - SequencerCommitmentResponse, SoftConfirmationResponse, VerifiedBatchProofResponse, -}; use tokio::time::sleep; use tracing::trace; @@ -51,59 +47,19 @@ impl Client { .await?) } - pub async fn ledger_get_head_soft_confirmation( - &self, - ) -> Result> { - Ok(self.client.get_head_soft_confirmation().await?) - } - - pub async fn ledger_get_verified_batch_proofs_by_slot_height( - &self, - height: u64, - ) -> Result>> { - Ok(self - .client - .get_verified_batch_proofs_by_slot_height(height) - .await?) - } - - pub async fn ledger_get_sequencer_commitments_on_slot_by_number( - &self, - height: u64, - ) -> Result>> { + pub async fn ledger_get_head_soft_confirmation_height(&self) -> Result { Ok(self .client - .get_sequencer_commitments_on_slot_by_number(height) + .request("ledger_getHeadSoftConfirmationHeight", rpc_params![]) .await?) } - pub async fn ledger_get_soft_confirmation_by_number( - &self, - num: u64, - ) -> Result> { - Ok(self.client.get_soft_confirmation_by_number(num).await?) - } - - pub async fn ledger_get_sequencer_commitments_on_slot_by_hash( - &self, - hash: [u8; 32], - ) -> Result>> { - self.client - .get_sequencer_commitments_on_slot_by_hash(hash) - .await - .map_err(Into::into) - } - - pub async fn ledger_get_head_soft_confirmation_height(&self) -> Result { - Ok(self.client.get_head_soft_confirmation_height().await?) - } - pub async fn wait_for_l2_block(&self, num: u64, timeout: Option) -> Result<()> { let start = SystemTime::now(); let timeout = timeout.unwrap_or(Duration::from_secs(30)); // Default 30 seconds timeout loop { trace!("Waiting for soft confirmation {}", num); - let latest_block = self.client.get_head_soft_confirmation_height().await?; + let latest_block = self.ledger_get_head_soft_confirmation_height().await?; if latest_block >= num { break; diff --git a/src/full_node.rs b/src/full_node.rs index 0f932b1..abe9f3f 100644 --- a/src/full_node.rs +++ b/src/full_node.rs @@ -1,59 +1,4 @@ -use anyhow::bail; -use sov_rollup_interface::rpc::{SequencerCommitmentResponse, VerifiedBatchProofResponse}; -use tokio::time::{sleep, Duration, Instant}; - -use super::{config::FullFullNodeConfig, Result}; +use super::config::FullFullNodeConfig; use crate::node::Node; pub type FullNode = Node; - -impl FullNode { - pub async fn wait_for_sequencer_commitments( - &self, - height: u64, - timeout: Option, - ) -> Result> { - let start = Instant::now(); - let timeout = timeout.unwrap_or(Duration::from_secs(30)); - - loop { - if start.elapsed() >= timeout { - bail!("FullNode failed to get sequencer commitments within the specified timeout"); - } - - match self - .client - .ledger_get_sequencer_commitments_on_slot_by_number(height) - .await - { - Ok(Some(commitments)) => return Ok(commitments), - Ok(None) => sleep(Duration::from_millis(500)).await, - Err(e) => bail!("Error fetching sequencer commitments: {}", e), - } - } - } - - pub async fn wait_for_zkproofs( - &self, - height: u64, - timeout: Option, - ) -> Result> { - let start = Instant::now(); - let timeout = timeout.unwrap_or(Duration::from_secs(30)); - - loop { - if start.elapsed() >= timeout { - bail!("FullNode failed to get zkproofs within the specified timeout"); - } - - match self - .client - .ledger_get_verified_batch_proofs_by_slot_height(height) - .await? - { - Some(proofs) => return Ok(proofs), - None => sleep(Duration::from_millis(500)).await, - } - } - } -} diff --git a/src/node.rs b/src/node.rs index e16649e..30d02bc 100644 --- a/src/node.rs +++ b/src/node.rs @@ -200,7 +200,7 @@ where while start.elapsed() < timeout { if self .client - .ledger_get_head_soft_confirmation() + .ledger_get_head_soft_confirmation_height() .await .is_ok() { diff --git a/tests/docker.rs b/tests/docker.rs index 3399098..c97b187 100644 --- a/tests/docker.rs +++ b/tests/docker.rs @@ -47,12 +47,10 @@ impl TestCase for DockerIntegrationTest { .wait_for_l1_height(finalized_height, None) .await?; - let commitments = full_node - .wait_for_sequencer_commitments(finalized_height, None) + full_node + .wait_for_l2_height(min_soft_confirmations_per_commitment, None) .await?; - assert_eq!(commitments.len(), 1); - let unspent_sequencer = sequencer .da .list_unspent(None, None, None, None, None)