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

chore(voyager): clean up code a bit #3489

Merged
merged 2 commits into from
Jan 12, 2025
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
1 change: 0 additions & 1 deletion Cargo.lock

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

53 changes: 26 additions & 27 deletions voyager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
172 changes: 23 additions & 149 deletions voyager/src/main.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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::<Hex<Vec<u8>>>(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::<Hex<Vec<u8>>>(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 {
Expand Down Expand Up @@ -358,96 +301,18 @@ 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?;
}
}

print_json(&record);
}
}
}
// 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>>(&union, &Wasm(cosmos), ty, chains).await
// }
// (AnyChain::Union(union), AnyChain::EthereumMainnet(ethereum)) => {
// mk_handshake::<Wasm<Union>, Ethereum<Mainnet>>(
// &Wasm(union),
// &ethereum,
// ty,
// chains,
// )
// .await
// }
// (AnyChain::Union(union), AnyChain::EthereumMinimal(ethereum)) => {
// mk_handshake::<Wasm<Union>, Ethereum<Minimal>>(
// &Wasm(union),
// &ethereum,
// ty,
// chains,
// )
// .await
// }
// (AnyChain::Union(union), AnyChain::Scroll(scroll)) => {
// mk_handshake::<Wasm<Union>, Scroll>(&Wasm(union), &scroll, ty, chains).await
// }
// (AnyChain::Union(union), AnyChain::Arbitrum(scroll)) => {
// mk_handshake::<Wasm<Union>, Arbitrum>(&Wasm(union), &scroll, ty, chains).await
// }
// (AnyChain::Union(union), AnyChain::Berachain(berachain)) => {
// mk_handshake::<Wasm<Union>, Berachain>(&Wasm(union), &berachain, ty, chains)
// .await
// }
// (AnyChain::Cosmos(cosmos), AnyChain::Union(union)) => {
// mk_handshake::<Wasm<Cosmos>, Union>(&Wasm(cosmos), &union, ty, chains).await
// }
// (AnyChain::Cosmos(cosmos_a), AnyChain::Cosmos(cosmos_b)) => {
// mk_handshake::<Cosmos, Cosmos>(&cosmos_a, &cosmos_b, ty, chains).await
// }
// (AnyChain::EthereumMainnet(ethereum), AnyChain::Union(union)) => {
// mk_handshake::<Ethereum<Mainnet>, Wasm<Union>>(
// &ethereum,
// &Wasm(union),
// ty,
// chains,
// )
// .await
// }
// (AnyChain::EthereumMinimal(ethereum), AnyChain::Union(union)) => {
// mk_handshake::<Ethereum<Minimal>, Wasm<Union>>(
// &ethereum,
// &Wasm(union),
// ty,
// chains,
// )
// .await
// }
// (AnyChain::Scroll(scroll), AnyChain::Union(union)) => {
// mk_handshake::<Scroll, Wasm<Union>>(&scroll, &Wasm(union), ty, chains).await
// }
// (AnyChain::Arbitrum(scroll), AnyChain::Union(union)) => {
// mk_handshake::<Arbitrum, Wasm<Union>>(&scroll, &Wasm(union), ty, chains).await
// }
// (AnyChain::Berachain(berachain), AnyChain::Union(union)) => {
// mk_handshake::<Berachain, Wasm<Union>>(&berachain, &Wasm(union), ty, chains)
// .await
// }
// _ => panic!("invalid"),
// };

// print_json(&all_msgs);
// }
Command::InitFetch {
chain_id,
height,
Expand Down Expand Up @@ -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?;

Expand All @@ -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?;

Expand All @@ -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(),
)?,
Expand All @@ -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?;

Expand Down Expand Up @@ -747,7 +618,10 @@ async fn send_enqueue(
}

fn print_json<T: Serialize>(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
Expand Down
5 changes: 2 additions & 3 deletions voyager/src/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,13 +40,13 @@ pub enum QueueConfig {
PgQueue(PgQueueConfig),
}

#[derive(DebugNoBound, CloneNoBound)]
#[derive(Debug, Clone)]
pub enum QueueImpl {
InMemory(InMemoryQueue<VoyagerMessage>),
PgQueue(PgQueue<VoyagerMessage>),
}

#[derive(DebugNoBound, thiserror::Error)]
#[derive(Debug, thiserror::Error)]
#[error(transparent)]
pub enum AnyQueueError {
InMemory(std::convert::Infallible),
Expand Down
Loading