diff --git a/Cargo.lock b/Cargo.lock index 82889f14..69595ca6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -927,11 +927,13 @@ name = "bedrock_client" version = "0.1.0" dependencies = [ "anyhow", + "futures", + "log", + "logos-blockchain-chain-broadcast-service", "logos-blockchain-common-http-client", "logos-blockchain-core", "reqwest", "tokio-retry", - "url", ] [[package]] @@ -2707,7 +2709,7 @@ dependencies = [ "common", "futures", "log", - "nomos-core", + "logos-blockchain-core", "serde", "serde_json", "tokio", @@ -3362,7 +3364,7 @@ source = "git+https://github.com/logos-blockchain/logos-blockchain.git#451df112f dependencies = [ "proc-macro2", "quote", - "syn 2.0.111", + "syn 2.0.114", ] [[package]] @@ -6729,3 +6731,9 @@ dependencies = [ "quote", "syn 2.0.114", ] + +[[package]] +name = "zmij" +version = "1.0.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfcd145825aace48cff44a8844de64bf75feec3080e0aa5cdbde72961ae51a65" diff --git a/Cargo.toml b/Cargo.toml index dcc765d9..5214cba2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -85,6 +85,7 @@ tokio-retry = "0.3.0" logos-blockchain-common-http-client = { git = "https://github.com/logos-blockchain/logos-blockchain.git" } logos-blockchain-key-management-system-service = { git = "https://github.com/logos-blockchain/logos-blockchain.git" } logos-blockchain-core = { git = "https://github.com/logos-blockchain/logos-blockchain.git" } +logos-blockchain-chain-broadcast-service = { git = "https://github.com/logos-blockchain/logos-blockchain.git" } rocksdb = { version = "0.24.0", default-features = false, features = [ "snappy", diff --git a/bedrock_client/Cargo.toml b/bedrock_client/Cargo.toml index 50a54815..5506756e 100644 --- a/bedrock_client/Cargo.toml +++ b/bedrock_client/Cargo.toml @@ -6,5 +6,9 @@ edition = "2024" [dependencies] reqwest.workspace = true anyhow.workspace = true +tokio-retry.workspace = true +futures.workspace = true +log.workspace = true logos-blockchain-common-http-client.workspace = true logos-blockchain-core.workspace = true +logos-blockchain-chain-broadcast-service.workspace = true diff --git a/bedrock_client/src/lib.rs b/bedrock_client/src/lib.rs index 154b6bfe..45286e14 100644 --- a/bedrock_client/src/lib.rs +++ b/bedrock_client/src/lib.rs @@ -1,7 +1,11 @@ use anyhow::Result; +use futures::{Stream, TryFutureExt}; +use log::warn; +use logos_blockchain_chain_broadcast_service::BlockInfo; pub use logos_blockchain_common_http_client::{BasicAuthCredentials, CommonHttpClient, Error}; -use logos_blockchain_core::mantle::SignedMantleTx; +use logos_blockchain_core::{block::Block, header::HeaderId, mantle::SignedMantleTx}; use reqwest::{Client, Url}; +use tokio_retry::Retry; // Simple wrapper // maybe extend in the future for our purposes @@ -30,13 +34,12 @@ impl BedrockClient { .await } - pub async fn get_lib_stream(&self, url: Url) -> Result, Error> { - self.0.get_lib_stream(url).await + pub async fn get_lib_stream(&self) -> Result, Error> { + self.http_client.get_lib_stream(self.node_url.clone()).await } pub async fn get_block_by_id( &self, - url: &Url, header_id: HeaderId, start_delay_millis: u64, max_retries: usize, @@ -45,8 +48,8 @@ impl BedrockClient { .take(max_retries); Retry::spawn(strategy, || { - self.0 - .get_block_by_id(url.clone(), header_id) + self.http_client + .get_block_by_id(self.node_url.clone(), header_id) .inspect_err(|err| warn!("Block fetching failed with err: {err:#?}")) }) .await diff --git a/indexer_core/Cargo.toml b/indexer_core/Cargo.toml index 407ec2ac..922f566c 100644 --- a/indexer_core/Cargo.toml +++ b/indexer_core/Cargo.toml @@ -14,5 +14,5 @@ tokio.workspace = true borsh.workspace = true futures.workspace = true url.workspace = true -nomos-core.workspace = true +logos-blockchain-core.workspace = true serde_json.workspace = true diff --git a/indexer_core/src/config.rs b/indexer_core/src/config.rs index df6de144..d73f00c2 100644 --- a/indexer_core/src/config.rs +++ b/indexer_core/src/config.rs @@ -1,7 +1,7 @@ use std::{fs::File, io::BufReader, path::Path}; use anyhow::Result; -use nomos_core::mantle::ops::channel::ChannelId; +use logos_blockchain_core::mantle::ops::channel::ChannelId; use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/indexer_core/src/lib.rs b/indexer_core/src/lib.rs index 2099d55c..c147369a 100644 --- a/indexer_core/src/lib.rs +++ b/indexer_core/src/lib.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use anyhow::Result; +use anyhow::{Context, Result}; use bedrock_client::{BasicAuthCredentials, BedrockClient}; use common::{ block::HashableBlockData, communication::indexer::Message, @@ -8,7 +8,7 @@ use common::{ }; use futures::StreamExt; use log::info; -use nomos_core::mantle::{ +use logos_blockchain_core::mantle::{ Op, SignedMantleTx, ops::channel::{ChannelId, inscribe::InscriptionOp}, }; @@ -24,8 +24,6 @@ pub struct IndexerCore { pub bedrock_client: BedrockClient, pub sequencer_client: SequencerClient, pub config: IndexerConfig, - // ToDo: Remove this duplication by unifying addr representation in all clients. - pub bedrock_url: Url, pub state: IndexerState, } @@ -38,8 +36,9 @@ impl IndexerCore { .auth .clone() .map(|auth| BasicAuthCredentials::new(auth.0, auth.1)), + Url::parse(&config.bedrock_client_config.addr) + .context("Bedrock node addr is not a valid url")?, )?, - bedrock_url: Url::parse(&config.bedrock_client_config.addr)?, sequencer_client: SequencerClient::new_with_auth( config.sequencer_client_config.addr.clone(), config.sequencer_client_config.auth.clone(), @@ -54,11 +53,7 @@ impl IndexerCore { pub async fn subscribe_parse_block_stream(&self) -> Result<()> { loop { - let mut stream_pinned = Box::pin( - self.bedrock_client - .get_lib_stream(self.bedrock_url.clone()) - .await?, - ); + let mut stream_pinned = Box::pin(self.bedrock_client.get_lib_stream().await?); info!("Block stream joined"); @@ -70,7 +65,6 @@ impl IndexerCore { if let Some(l1_block) = self .bedrock_client .get_block_by_id( - &self.bedrock_url, header_id, self.config.start_delay_millis, self.config.max_retries, diff --git a/sequencer_core/src/block_settlement_client.rs b/sequencer_core/src/block_settlement_client.rs index 0aa22420..c643bd5f 100644 --- a/sequencer_core/src/block_settlement_client.rs +++ b/sequencer_core/src/block_settlement_client.rs @@ -1,4 +1,4 @@ -use std::{fs, path::Path}; +use std::{fs, path::Path, str::FromStr}; use anyhow::{Context, Result, anyhow}; use bedrock_client::BedrockClient; @@ -10,6 +10,7 @@ use logos_blockchain_core::mantle::{ use logos_blockchain_key_management_system_service::keys::{ ED25519_SECRET_KEY_SIZE, Ed25519Key, Ed25519PublicKey, }; +use reqwest::Url; use crate::config::BedrockConfig; @@ -26,8 +27,10 @@ impl BlockSettlementClient { let bedrock_signing_key = load_or_create_signing_key(&home.join("bedrock_signing_key")) .context("Failed to load or create signing key")?; let bedrock_channel_id = ChannelId::from(config.channel_id); - let bedrock_client = BedrockClient::new(None, config.node_url.clone()) - .context("Failed to initialize bedrock client")?; + let bedrock_url = Url::from_str(config.node_url.as_ref()) + .context("Bedrock node address is not a valid url")?; + let bedrock_client = + BedrockClient::new(None, bedrock_url).context("Failed to initialize bedrock client")?; let channel_genesis_msg = MsgId::from([0; 32]); Ok(Self { bedrock_client, diff --git a/sequencer_core/src/config.rs b/sequencer_core/src/config.rs index 7307d43c..47d38c37 100644 --- a/sequencer_core/src/config.rs +++ b/sequencer_core/src/config.rs @@ -5,7 +5,7 @@ use std::{ }; use anyhow::Result; -use reqwest::Url; +use logos_blockchain_core::mantle::ops::channel::ChannelId; use serde::{Deserialize, Serialize}; #[derive(Debug, Serialize, Deserialize, Clone)] @@ -57,7 +57,11 @@ pub struct BedrockConfig { /// Bedrock channel ID pub channel_id: ChannelId, /// Bedrock Url - pub node_url: Url, + pub node_url: String, + /// Bedrock user + pub user: String, + /// Bedrock password + pub password: Option, } impl SequencerConfig { diff --git a/sequencer_runner/configs/debug/sequencer_config.json b/sequencer_runner/configs/debug/sequencer_config.json index d7cce5d0..cbd1ef14 100644 --- a/sequencer_runner/configs/debug/sequencer_config.json +++ b/sequencer_runner/configs/debug/sequencer_config.json @@ -159,11 +159,6 @@ "channel_id": "0101010101010101010101010101010101010101010101010101010101010101", "node_url": "http://localhost:8080", "user": "user", - "password": null, - "indexer_config": { - "resubscribe_interval": 1000, - "start_delay": 1000, - "limit_retry": 10 - } + "password": null } }