Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove circular dependency on citrea #50

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
50 changes: 3 additions & 47 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -51,59 +47,19 @@ impl Client {
.await?)
}

pub async fn ledger_get_head_soft_confirmation(
&self,
) -> Result<Option<SoftConfirmationResponse>> {
Ok(self.client.get_head_soft_confirmation().await?)
}

pub async fn ledger_get_verified_batch_proofs_by_slot_height(
&self,
height: u64,
) -> Result<Option<Vec<VerifiedBatchProofResponse>>> {
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<Option<Vec<SequencerCommitmentResponse>>> {
pub async fn ledger_get_head_soft_confirmation_height(&self) -> Result<u64> {
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<Option<SoftConfirmationResponse>> {
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<Option<Vec<SequencerCommitmentResponse>>> {
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<u64> {
Ok(self.client.get_head_soft_confirmation_height().await?)
}

pub async fn wait_for_l2_block(&self, num: u64, timeout: Option<Duration>) -> 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;
Expand Down
57 changes: 1 addition & 56 deletions src/full_node.rs
Original file line number Diff line number Diff line change
@@ -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<FullFullNodeConfig>;

impl FullNode {
pub async fn wait_for_sequencer_commitments(
&self,
height: u64,
timeout: Option<Duration>,
) -> Result<Vec<SequencerCommitmentResponse>> {
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<Duration>,
) -> Result<Vec<VerifiedBatchProofResponse>> {
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,
}
}
}
}
2 changes: 1 addition & 1 deletion src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
6 changes: 2 additions & 4 deletions tests/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading