Skip to content

Commit

Permalink
feat: cleanup (#3331)
Browse files Browse the repository at this point in the history
  • Loading branch information
benluelo authored Dec 3, 2024
2 parents 52543f4 + 69c3731 commit 77a7924
Show file tree
Hide file tree
Showing 19 changed files with 214 additions and 234 deletions.
4 changes: 2 additions & 2 deletions lib/voyager-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ impl IbcVersionId {
/// IBC version 1.0.0, as per the [ICS-003 connection semantics](ics3).
///
/// [ics3]: https://github.com/cosmos/ibc/blob/main/spec/core/ics-003-connection-semantics/README.md#versioning
pub const V1_0_0: &'static str = "1.0.0";
pub const CLASSIC: &'static str = "ibc-classic";

// TODO: Potentially rename?
/// IBC version <TODO>, as per the [union ethabi IBC specification](union-ethabi).
///
/// [union-ethabi]: https://docs.union.build/protocol/specifications/ibc/
pub const UNION: &'static str = "union";
pub const UNION: &'static str = "ibc-union";
}

/// Identifier used to uniquely identify a chain, as provided by the chain
Expand Down
83 changes: 30 additions & 53 deletions lib/voyager-message/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ use voyager_vm::QueueError;

use crate::{
core::{ChainId, ClientType, IbcInterface},
ibc_union::IbcUnion,
ibc_v1::IbcV1,
into_value,
module::{
ClientModuleClient, ClientModuleInfo, ConsensusModuleClient, ConsensusModuleInfo,
Expand Down Expand Up @@ -70,7 +68,17 @@ pub struct Modules {

// ibc version id => handler
#[debug(skip)]
pub ibc_spec_handlers: HashMap<IbcVersionId, IbcSpecHandler>,
pub ibc_spec_handlers: IbcSpecHandlers,
}

pub struct IbcSpecHandlers {
pub(crate) handlers: HashMap<IbcVersionId, IbcSpecHandler>,
}

impl IbcSpecHandlers {
pub fn register<S: IbcSpec>(&mut self) {
self.handlers.insert(S::ID, IbcSpecHandler::new::<S>());
}
}

/// A type-erased version of the methods on [`IbcSpec`] (essentially a vtable).
Expand Down Expand Up @@ -225,22 +233,24 @@ impl Context {
pub async fn new(
plugin_configs: Vec<PluginConfig>,
module_configs: ModulesConfig,
register_ibc_spec_handlers: fn(&mut IbcSpecHandlers),
) -> anyhow::Result<Self> {
let cancellation_token = CancellationToken::new();

let mut ibc_spec_handlers = IbcSpecHandlers {
handlers: Default::default(),
};

register_ibc_spec_handlers(&mut ibc_spec_handlers);

let mut modules = Modules {
state_modules: Default::default(),
proof_modules: Default::default(),
client_modules: Default::default(),
consensus_modules: Default::default(),
chain_consensus_types: Default::default(),
client_consensus_types: Default::default(),
ibc_spec_handlers: [
(IbcV1::ID, IbcSpecHandler::new::<IbcV1>()),
(IbcUnion::ID, IbcSpecHandler::new::<IbcUnion>()),
]
.into_iter()
.collect(),
ibc_spec_handlers,
};

let mut plugins = HashMap::default();
Expand Down Expand Up @@ -385,7 +395,7 @@ impl Context {

if prev.is_some() {
return Err(anyhow!(
"multiple consensus modules configured for consensus id `{}`",
"multiple consensus modules configured for chain id `{}`",
chain_id
));
}
Expand Down Expand Up @@ -414,6 +424,16 @@ impl Context {
ibc_version_id,
},
rpc_client| {
if !modules
.ibc_spec_handlers
.handlers
.contains_key(ibc_version_id)
{
return Err(anyhow!(
"IBC version `{ibc_version_id}` is not supported in this build of voyager"
));
}

let prev = modules.client_modules.insert(
(
client_type.clone(),
Expand Down Expand Up @@ -450,38 +470,6 @@ impl Context {
)
.await?;

// let plugin_configs = plugin_configs
// .into_iter()
// .map(|plugin_config| {
// let server = main_rpc_server.clone();
// async move {
// let plugin_info = get_plugin_info(&plugin_config)?;

// info!("starting rpc server for {}", plugin_info.name);
// tokio::spawn(module_rpc_server(&plugin_info.name, server).await?);

// Ok::<_, BoxDynError>((plugin_config, plugin_info))
// }
// })
// .collect::<FuturesUnordered<_>>()
// .try_collect::<Vec<_>>()
// .await?;

// match kind {
// ModuleInfo::Client(ClientModuleInfo {
// client_type,
// consensus_type,
// ibc_interface,
// }) => {

// info!(
// %client_type,
// %ibc_interface,
// "registered client module"
// );
// }
// }

main_rpc_server.start(Arc::new(modules));

info!("checking for plugin health...");
Expand Down Expand Up @@ -634,17 +622,6 @@ impl Modules {
})
}

// pub fn chain_module<'a, 'b, 'c: 'a>(
// &'a self,
// chain_id: &ChainId,
// ) -> Result<&'a (impl ChainModuleClient + 'a), ChainModuleNotFound> {
// Ok(self
// .chain_modules
// .get(chain_id)
// .ok_or_else(|| ChainModuleNotFound(chain_id.clone()))?
// .client())
// }

pub fn state_module<'a, 'b, 'c: 'a>(
&'a self,
chain_id: &ChainId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ use voyager_core::{ClientType, IbcVersionId};
use crate::{IbcSpec, IbcStorePathKey};

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum IbcV1 {}
pub enum IbcClassic {}

impl IbcSpec for IbcV1 {
const ID: IbcVersionId = IbcVersionId::new_static(IbcVersionId::V1_0_0);
impl IbcSpec for IbcClassic {
const ID: IbcVersionId = IbcVersionId::new_static(IbcVersionId::CLASSIC);

type ClientId = ClientId;
// type Height = Height;

type StorePath = unionlabs::ics24::Path;

Expand Down Expand Up @@ -70,7 +69,7 @@ macro_rules! impl_ibc_store_path_key_via_ibc_path {
($($ty:ty,)*) => {
$(
impl IbcStorePathKey for $ty {
type Spec = IbcV1;
type Spec = IbcClassic;

type Value = <Self as IbcPath>::Value;
}
Expand Down Expand Up @@ -114,7 +113,7 @@ pub enum IbcMessage {
}

impl IbcMessage {
/// Returns the proof height of the IBC message, if it has one.
/// Returns the proof height of the IBC message, if it contains one.
/// (ConnectionOpenInit does not contain a proof, for example)
pub fn proof_height(&self) -> Option<Height> {
match self {
Expand Down
16 changes: 1 addition & 15 deletions lib/voyager-message/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ pub use reconnecting_jsonrpc_ws_client;
pub use reth_ipc;
pub use voyager_core as core;

pub mod ibc_classic;
pub mod ibc_union;
pub mod ibc_v1;

pub enum VoyagerMessage {}

Expand Down Expand Up @@ -154,20 +154,6 @@ impl RawClientId {
}
}

#[macro_export]
macro_rules! any_ibc_spec {
($ibc_version_id:ident, $V:ident, $expr:expr, $else:expr) => {
if $ibc_version_id == $crate::ibc_v1::IbcV1::ID {
type $V = $crate::ibc_v1::IbcV1;
$expr
}
// else if $ibc_version_id == IbcV1::ID {}
else {
$else
}
};
}

/// Error code for fatal errors. If a plugin or module responds with this error
/// code, it will be treated as fatal and not retried.
pub const FATAL_JSONRPC_ERROR_CODE: i32 = -0xBADBEEF;
Expand Down
1 change: 1 addition & 0 deletions lib/voyager-message/src/rpc/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ impl Server {
(self
.modules()?
.ibc_spec_handlers
.handlers
.get(ibc_version_id)
.unwrap()
.client_state_path)(client_id.clone())
Expand Down
16 changes: 8 additions & 8 deletions voyager/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"path": "./target/debug/voyager-state-module-cosmos-sdk-union",
"info": {
"chain_id": "union-devnet-1",
"ibc_version_id": "union"
"ibc_version_id": "ibc-union"
},
"config": {
"ws_url": "http://localhost:26657",
Expand All @@ -31,7 +31,7 @@
"path": "./target/debug/voyager-state-module-ethereum",
"info": {
"chain_id": "32382",
"ibc_version_id": "union"
"ibc_version_id": "ibc-union"
},
"config": {
"ibc_handler_address": "0xed2af2ad7fe0d92011b26a2e5d1b4dc7d12a47c5",
Expand All @@ -45,7 +45,7 @@
"path": "./target/debug/voyager-proof-module-cosmos-sdk-union",
"info": {
"chain_id": "union-devnet-1",
"ibc_version_id": "union"
"ibc_version_id": "ibc-union"
},
"config": {
"ws_url": "http://localhost:26657",
Expand All @@ -58,7 +58,7 @@
"path": "./target/debug/voyager-proof-module-ethereum",
"info": {
"chain_id": "32382",
"ibc_version_id": "union"
"ibc_version_id": "ibc-union"
},
"config": {
"ibc_handler_address": "0xed2af2ad7fe0d92011b26a2e5d1b4dc7d12a47c5",
Expand Down Expand Up @@ -103,7 +103,7 @@
"client_type": "cometbls",
"consensus_type": "cometbls",
"ibc_interface": "ibc-solidity",
"ibc_version_id": "union"
"ibc_version_id": "ibc-union"
}
},
{
Expand All @@ -113,7 +113,7 @@
"client_type": "cometbls",
"consensus_type": "cometbls",
"ibc_interface": "ibc-move/aptos",
"ibc_version_id": "union"
"ibc_version_id": "ibc-union"
}
},
{
Expand All @@ -123,7 +123,7 @@
"client_type": "cometbls",
"consensus_type": "cometbls",
"ibc_interface": "ibc-go-v8/08-wasm",
"ibc_version_id": "union"
"ibc_version_id": "ibc-union"
}
},
{
Expand All @@ -133,7 +133,7 @@
"client_type": "ethereum",
"consensus_type": "ethereum",
"ibc_interface": "ibc-cosmwasm",
"ibc_version_id": "union"
"ibc_version_id": "ibc-union"
},
"config": {
"chain_spec": "minimal"
Expand Down
8 changes: 4 additions & 4 deletions voyager/modules/proof/cosmos-sdk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use unionlabs::{
};
use voyager_message::{
core::{ChainId, ClientInfo, ClientType, IbcGo08WasmClientMetadata, IbcInterface},
ibc_v1::IbcV1,
ibc_classic::IbcClassic,
into_value,
module::{StateModuleInfo, StateModuleServer},
StateModule, FATAL_JSONRPC_ERROR_CODE,
Expand All @@ -46,7 +46,7 @@ const IBC_STORE_PATH: &str = "store/ibc/key";

#[tokio::main(flavor = "multi_thread")]
async fn main() {
<Module as StateModule<IbcV1>>::run().await;
<Module as StateModule<IbcClassic>>::run().await;
}

#[derive(clap::Subcommand)]
Expand All @@ -73,7 +73,7 @@ pub struct Config {
pub grpc_url: String,
}

impl StateModule<IbcV1> for Module {
impl StateModule<IbcClassic> for Module {
type Config = Config;

async fn new(config: Self::Config, info: StateModuleInfo) -> Result<Self, BoxDynError> {
Expand Down Expand Up @@ -505,7 +505,7 @@ pub struct ChainIdParseError {
}

#[async_trait]
impl StateModuleServer<IbcV1> for Module {
impl StateModuleServer<IbcClassic> for Module {
#[instrument(skip_all, fields(chain_id = %self.chain_id))]
async fn client_info(&self, _: &Extensions, client_id: ClientId) -> RpcResult<ClientInfo> {
match client_id.to_string().rsplit_once('-') {
Expand Down
8 changes: 4 additions & 4 deletions voyager/modules/state/cosmos-sdk/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use unionlabs::{
};
use voyager_message::{
core::{ChainId, ClientInfo, ClientType, IbcGo08WasmClientMetadata, IbcInterface},
ibc_v1::IbcV1,
ibc_classic::IbcClassic,
into_value,
module::{StateModuleInfo, StateModuleServer},
StateModule, FATAL_JSONRPC_ERROR_CODE,
Expand All @@ -46,7 +46,7 @@ const IBC_STORE_PATH: &str = "store/ibc/key";

#[tokio::main(flavor = "multi_thread")]
async fn main() {
<Module as StateModule<IbcV1>>::run().await;
<Module as StateModule<IbcClassic>>::run().await;
}

#[derive(clap::Subcommand)]
Expand All @@ -73,7 +73,7 @@ pub struct Config {
pub grpc_url: String,
}

impl StateModule<IbcV1> for Module {
impl StateModule<IbcClassic> for Module {
type Config = Config;

async fn new(config: Self::Config, info: StateModuleInfo) -> Result<Self, BoxDynError> {
Expand Down Expand Up @@ -505,7 +505,7 @@ pub struct ChainIdParseError {
}

#[async_trait]
impl StateModuleServer<IbcV1> for Module {
impl StateModuleServer<IbcClassic> for Module {
#[instrument(skip_all, fields(chain_id = %self.chain_id))]
async fn client_info(&self, _: &Extensions, client_id: ClientId) -> RpcResult<ClientInfo> {
match client_id.to_string().rsplit_once('-') {
Expand Down
4 changes: 2 additions & 2 deletions voyager/plugins/event-source/cosmos-sdk/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ pub struct MakeChainEvent {

#[model]
pub enum RawEvent {
IbcV1(ibc_events::IbcEvent),
IbcClassic(ibc_events::IbcEvent),
IbcUnion(ibc_events::union_ibc::IbcEvent),
}

impl RawEvent {
pub fn name(&self) -> &'static str {
match self {
RawEvent::IbcV1(ibc_event) => ibc_event.name(),
RawEvent::IbcClassic(ibc_event) => ibc_event.name(),
RawEvent::IbcUnion(ibc_event) => ibc_event.name(),
}
}
Expand Down
Loading

0 comments on commit 77a7924

Please sign in to comment.