Skip to content

Commit

Permalink
Remove sequencer-client crate (#1606)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfldde authored Dec 13, 2024
1 parent 170138b commit e9c5516
Show file tree
Hide file tree
Showing 17 changed files with 198 additions and 379 deletions.
31 changes: 8 additions & 23 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ members = [
"crates/pruning",
"crates/risc0",
"crates/sequencer",
"crates/sequencer-client",
"crates/soft-confirmation-rule-enforcer",
# "crates/sp1",
# Sovereign sdk
Expand Down
1 change: 0 additions & 1 deletion bin/citrea/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
3 changes: 2 additions & 1 deletion crates/batch-prover/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand All @@ -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 }
Expand Down
113 changes: 57 additions & 56 deletions crates/batch-prover/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -60,7 +63,7 @@ where
batch_hash: SoftConfirmationHash,
rpc_config: RpcConfig,
prover_service: Arc<Ps>,
sequencer_client: SequencerClient,
sequencer_client: HttpClient,
sequencer_pub_key: Vec<u8>,
sequencer_da_pub_key: Vec<u8>,
phantom: std::marker::PhantomData<C>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -279,7 +283,7 @@ where

let start_l1_height = match last_scanned_l1_height {
Some(height) => height.0,
None => get_initial_slot_height::<Da::Spec>(&self.sequencer_client).await,
None => get_initial_slot_height(&self.sequencer_client).await,
};

let ledger_db = self.ledger_db.clone();
Expand Down Expand Up @@ -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::<Da>(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;

Expand All @@ -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);
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -492,14 +495,12 @@ where
}
}

async fn sync_l2<Da>(
async fn sync_l2(
start_l2_height: u64,
sequencer_client: SequencerClient,
sender: mpsc::Sender<Vec<(u64, GetSoftConfirmationResponse)>>,
sequencer_client: HttpClient,
sender: mpsc::Sender<Vec<(u64, SoftConfirmationResponse)>>,
sync_blocks_count: u64,
) where
Da: DaService,
{
) {
let mut l2_height = start_l2_height;
info!("Starting to sync from L2 height {}", l2_height);
loop {
Expand All @@ -510,44 +511,44 @@ async fn sync_l2<Da>(
.build();

let inner_client = &sequencer_client;
let soft_confirmations: Vec<GetSoftConfirmationResponse> =
match retry_backoff(exponential_backoff.clone(), || async move {
let soft_confirmations = inner_client
.get_soft_confirmation_range::<Da::Spec>(
l2_height..=l2_height + sync_blocks_count - 1,
)
.await;

match soft_confirmations {
Ok(soft_confirmations) => {
Ok(soft_confirmations.into_iter().flatten().collect::<Vec<_>>())
}
Err(e) => match e.downcast_ref::<JsonrpseeError>() {
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::<Vec<_>>())
}
};
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!(
Expand All @@ -559,7 +560,7 @@ async fn sync_l2<Da>(
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();
Expand All @@ -572,9 +573,9 @@ async fn sync_l2<Da>(
}
}

async fn get_initial_slot_height<Da: DaSpec>(client: &SequencerClient) -> u64 {
async fn get_initial_slot_height(client: &HttpClient) -> u64 {
loop {
match client.get_soft_confirmation::<Da>(1).await {
match client.get_soft_confirmation_by_number(U64::from(1)).await {
Ok(Some(batch)) => return batch.da_slot_height,
_ => {
// sleep 1
Expand Down
3 changes: 2 additions & 1 deletion crates/ethereum-rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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"] }

Expand Down
6 changes: 3 additions & 3 deletions crates/ethereum-rpc/src/ethereum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -38,7 +38,7 @@ pub struct Ethereum<C: sov_modules_api::Context, Da: DaService> {
pub(crate) eth_signer: DevSigner,
pub(crate) storage: C::Storage,
pub(crate) ledger_db: LedgerDB,
pub(crate) sequencer_client: Option<SequencerClient>,
pub(crate) sequencer_client: Option<HttpClient>,
pub(crate) web3_client_version: String,
pub(crate) trace_cache: Mutex<LruMap<u64, Vec<GethTrace>, ByLength>>,
pub(crate) subscription_manager: Option<SubscriptionManager>,
Expand All @@ -53,7 +53,7 @@ impl<C: sov_modules_api::Context, Da: DaService> Ethereum<C, Da> {
#[cfg(feature = "local")] eth_signer: DevSigner,
storage: C::Storage,
ledger_db: LedgerDB,
sequencer_client: Option<SequencerClient>,
sequencer_client: Option<HttpClient>,
soft_confirmation_rx: Option<broadcast::Receiver<u64>>,
) -> Self {
let evm = Evm::<C>::default();
Expand Down
Loading

0 comments on commit e9c5516

Please sign in to comment.