From 935ab1a8250b2cc221a95594befb1ad6b1efe980 Mon Sep 17 00:00:00 2001 From: benluelo Date: Sun, 12 Jan 2025 08:04:13 +0000 Subject: [PATCH 1/2] chore(voyager): clean up code a bit --- voyager/src/main.rs | 172 ++++++-------------------------------------- 1 file changed, 23 insertions(+), 149 deletions(-) diff --git a/voyager/src/main.rs b/voyager/src/main.rs index 2bb2635977..202a9fba3e 100644 --- a/voyager/src/main.rs +++ b/voyager/src/main.rs @@ -1,5 +1,5 @@ #![feature(trait_alias, try_find)] -#![warn(clippy::pedantic)] +#![warn(clippy::pedantic, clippy::unwrap_used)] #![allow( // required due to return_position_impl_trait_in_trait false positives clippy::manual_async_fn, @@ -79,7 +79,7 @@ fn main() -> ExitCode { .enable_all() .thread_stack_size(args.stack_size) .build() - .unwrap() + .expect("building the tokio runtime is infallible; qed;") .block_on(do_main(args)); match res { @@ -248,63 +248,6 @@ async fn do_main(args: cli::AppArgs) -> anyhow::Result<()> { ModuleCmd::Consensus(_) => todo!(), ModuleCmd::Client(_) => todo!(), }, - // Command::Query { on, height, path } => { - // let voyager = Voyager::new(get_voyager_config()?).await?; - - // let height = voyager.context.rpc_server.query_height(&on, height).await?; - - // let state = voyager - // .context - // .rpc_server - // .query_ibc_state(&on, height, path.clone()) - // .await? - // .state; - - // let state = match &path { - // ics24::Path::ClientState(path) => { - // let client_info = voyager - // .context - // .rpc_server - // .client_info(&on, path.client_id.clone()) - // .await?; - - // voyager - // .context - // .rpc_server - // .decode_client_state( - // &client_info.client_type, - // &client_info.ibc_interface, - // serde_json::from_value::>>(state).unwrap().0, - // ) - // .await? - // } - // ics24::Path::ClientConsensusState(path) => { - // let client_info = voyager - // .context - // .rpc_server - // .client_info(&on, path.client_id.clone()) - // .await?; - - // voyager - // .context - // .rpc_server - // .decode_consensus_state( - // &client_info.client_type, - // &client_info.ibc_interface, - // serde_json::from_value::>>(state).unwrap().0, - // ) - // .await? - // } - // _ => state, - // }; - - // voyager.shutdown().await; - - // print_json(&json!({ - // "path": path.to_string(), - // "state": state, - // })); - // } Command::Queue(cli_msg) => { let db = || { Ok(match get_voyager_config()?.voyager.queue { @@ -358,8 +301,11 @@ async fn do_main(args: cli::AppArgs) -> anyhow::Result<()> { if requeue { if let Some(record) = record.as_ref().map(|r| r.item.0.clone()) { - q.enqueue(record, &JaqInterestFilter::new(vec![]).unwrap()) - .await?; + q.enqueue( + record, + &JaqInterestFilter::new(vec![]).expect("empty filter can be built"), + ) + .await?; } } @@ -367,87 +313,6 @@ async fn do_main(args: cli::AppArgs) -> anyhow::Result<()> { } } } - // Command::Handshake(HandshakeCmd { - // chain_a, - // chain_b, - // ty, - // }) => { - // let chain_a = voyager_config.get_chain(&chain_a).await?; - // let chain_b = voyager_config.get_chain(&chain_b).await?; - - // let chains = Arc::new(chains_from_config(voyager_config.chain).await.unwrap()); - - // let all_msgs = match (chain_a, chain_b) { - // (AnyChain::Union(union), AnyChain::Cosmos(cosmos)) => { - // mk_handshake::>(&union, &Wasm(cosmos), ty, chains).await - // } - // (AnyChain::Union(union), AnyChain::EthereumMainnet(ethereum)) => { - // mk_handshake::, Ethereum>( - // &Wasm(union), - // ðereum, - // ty, - // chains, - // ) - // .await - // } - // (AnyChain::Union(union), AnyChain::EthereumMinimal(ethereum)) => { - // mk_handshake::, Ethereum>( - // &Wasm(union), - // ðereum, - // ty, - // chains, - // ) - // .await - // } - // (AnyChain::Union(union), AnyChain::Scroll(scroll)) => { - // mk_handshake::, Scroll>(&Wasm(union), &scroll, ty, chains).await - // } - // (AnyChain::Union(union), AnyChain::Arbitrum(scroll)) => { - // mk_handshake::, Arbitrum>(&Wasm(union), &scroll, ty, chains).await - // } - // (AnyChain::Union(union), AnyChain::Berachain(berachain)) => { - // mk_handshake::, Berachain>(&Wasm(union), &berachain, ty, chains) - // .await - // } - // (AnyChain::Cosmos(cosmos), AnyChain::Union(union)) => { - // mk_handshake::, Union>(&Wasm(cosmos), &union, ty, chains).await - // } - // (AnyChain::Cosmos(cosmos_a), AnyChain::Cosmos(cosmos_b)) => { - // mk_handshake::(&cosmos_a, &cosmos_b, ty, chains).await - // } - // (AnyChain::EthereumMainnet(ethereum), AnyChain::Union(union)) => { - // mk_handshake::, Wasm>( - // ðereum, - // &Wasm(union), - // ty, - // chains, - // ) - // .await - // } - // (AnyChain::EthereumMinimal(ethereum), AnyChain::Union(union)) => { - // mk_handshake::, Wasm>( - // ðereum, - // &Wasm(union), - // ty, - // chains, - // ) - // .await - // } - // (AnyChain::Scroll(scroll), AnyChain::Union(union)) => { - // mk_handshake::>(&scroll, &Wasm(union), ty, chains).await - // } - // (AnyChain::Arbitrum(scroll), AnyChain::Union(union)) => { - // mk_handshake::>(&scroll, &Wasm(union), ty, chains).await - // } - // (AnyChain::Berachain(berachain), AnyChain::Union(union)) => { - // mk_handshake::>(&berachain, &Wasm(union), ty, chains) - // .await - // } - // _ => panic!("invalid"), - // }; - - // print_json(&all_msgs); - // } Command::InitFetch { chain_id, height, @@ -555,9 +420,10 @@ async fn do_main(args: cli::AppArgs) -> anyhow::Result<()> { on.clone(), ibc_spec_id.clone(), height, - (ibc_handlers.get(&ibc_spec_id).unwrap().client_state_path)( - client_id.clone(), - )?, + (ibc_handlers + .get(&ibc_spec_id) + .context(anyhow!("unknown IBC spec `{ibc_spec_id}`"))? + .client_state_path)(client_id.clone())?, ) .await?; @@ -571,7 +437,8 @@ async fn do_main(args: cli::AppArgs) -> anyhow::Result<()> { client_info.client_type, client_info.ibc_interface, ibc_spec_id, - serde_json::from_value(ibc_state.state).unwrap(), + serde_json::from_value(ibc_state.state) + .expect("serialization is infallible; qed;"), ) .await?; @@ -597,7 +464,10 @@ async fn do_main(args: cli::AppArgs) -> anyhow::Result<()> { on.clone(), ibc_spec_id.clone(), height, - (ibc_handlers.get(&ibc_spec_id).unwrap().consensus_state_path)( + (ibc_handlers + .get(&ibc_spec_id) + .context(anyhow!("unknown IBC spec `{ibc_spec_id}`"))? + .consensus_state_path)( client_id.clone(), trusted_height.to_string(), )?, @@ -614,7 +484,8 @@ async fn do_main(args: cli::AppArgs) -> anyhow::Result<()> { client_info.client_type, client_info.ibc_interface, ibc_spec_id, - serde_json::from_value(ibc_state.state).unwrap(), + serde_json::from_value(ibc_state.state) + .expect("serialization is infallible; qed;"), ) .await?; @@ -747,7 +618,10 @@ async fn send_enqueue( } fn print_json(t: &T) { - println!("{}", serde_json::to_string(&t).unwrap()); + println!( + "{}", + serde_json::to_string(&t).expect("serialization is infallible; qed;") + ); } // TODO: Extract all logic here to a plugin From 39b70ffca86f7750bf18ec119790c0833ba50323 Mon Sep 17 00:00:00 2001 From: benluelo Date: Sun, 12 Jan 2025 08:08:27 +0000 Subject: [PATCH 2/2] chore(voyager): remove frame-support-procedural --- Cargo.lock | 1 - voyager/Cargo.toml | 53 ++++++++++++++++++++++---------------------- voyager/src/queue.rs | 5 ++--- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 21a256c44d..e9f138ca6f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -12879,7 +12879,6 @@ dependencies = [ "axum 0.6.20", "clap 4.5.4", "derive_more 0.99.17", - "frame-support-procedural", "futures", "ibc-classic-spec", "ibc-union-spec", diff --git a/voyager/Cargo.toml b/voyager/Cargo.toml index 99e60127ec..cd3fb85abe 100644 --- a/voyager/Cargo.toml +++ b/voyager/Cargo.toml @@ -15,33 +15,32 @@ test-include = [] workspace = true [dependencies] -anyhow = "1.0.93" -axum = { workspace = true, features = ["macros", "tokio", "json"] } -clap = { workspace = true, features = ["default", "derive", "env", "error-context", "color"] } -derive_more = { workspace = true } -frame-support-procedural = { workspace = true } -futures = { workspace = true } -ibc-classic-spec.workspace = true -ibc-union-spec.workspace = true -jsonrpsee = { workspace = true, features = ["client", "full", "tracing"] } -pg-queue = { workspace = true } -pin-utils = "0.1.0" -prometheus = "0.13.4" -reqwest = { workspace = true, features = ["tokio-rustls"] } -schemars = { workspace = true } -serde = { workspace = true, features = ["derive"] } -serde_json = { workspace = true } -serde_jsonc = "1.0.108" -sqlx = { workspace = true, features = ["postgres", "migrate", "tls-rustls"] } -thiserror = { workspace = true } -tikv-jemallocator = "0.5" -tokio = { workspace = true, features = ["macros"] } -tracing = { workspace = true, features = ["max_level_trace"] } -tracing-futures = { version = "0.2.5", features = ["futures-03"] } -tracing-subscriber = { workspace = true, features = ["env-filter", "json"] } -unionlabs = { workspace = true, features = ["ethabi"] } -voyager-message = { workspace = true } -voyager-vm = { workspace = true } +anyhow = "1.0.93" +axum = { workspace = true, features = ["macros", "tokio", "json"] } +clap = { workspace = true, features = ["default", "derive", "env", "error-context", "color"] } +derive_more = { workspace = true } +futures = { workspace = true } +ibc-classic-spec = { workspace = true } +ibc-union-spec = { workspace = true } +jsonrpsee = { workspace = true, features = ["client", "full", "tracing"] } +pg-queue = { workspace = true } +pin-utils = "0.1.0" +prometheus = "0.13.4" +reqwest = { workspace = true, features = ["tokio-rustls"] } +schemars = { workspace = true } +serde = { workspace = true, features = ["derive"] } +serde_json = { workspace = true } +serde_jsonc = "1.0.108" +sqlx = { workspace = true, features = ["postgres", "migrate", "tls-rustls"] } +thiserror = { workspace = true } +tikv-jemallocator = "0.5" +tokio = { workspace = true, features = ["macros"] } +tracing = { workspace = true, features = ["max_level_trace"] } +tracing-futures = { version = "0.2.5", features = ["futures-03"] } +tracing-subscriber = { workspace = true, features = ["env-filter", "json"] } +unionlabs = { workspace = true, features = ["ethabi"] } +voyager-message = { workspace = true } +voyager-vm = { workspace = true } [features] default = [] diff --git a/voyager/src/queue.rs b/voyager/src/queue.rs index 3778aa6689..47e7e6aa6d 100644 --- a/voyager/src/queue.rs +++ b/voyager/src/queue.rs @@ -3,7 +3,6 @@ use std::{fmt::Debug, net::SocketAddr, panic::AssertUnwindSafe}; use anyhow::{bail, Context as _}; -use frame_support_procedural::{CloneNoBound, DebugNoBound}; use futures::{future::BoxFuture, stream::FuturesUnordered, Future, FutureExt, StreamExt}; use ibc_classic_spec::IbcClassic; use ibc_union_spec::IbcUnion; @@ -41,13 +40,13 @@ pub enum QueueConfig { PgQueue(PgQueueConfig), } -#[derive(DebugNoBound, CloneNoBound)] +#[derive(Debug, Clone)] pub enum QueueImpl { InMemory(InMemoryQueue), PgQueue(PgQueue), } -#[derive(DebugNoBound, thiserror::Error)] +#[derive(Debug, thiserror::Error)] #[error(transparent)] pub enum AnyQueueError { InMemory(std::convert::Infallible),