Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-savu committed Nov 27, 2023
1 parent 1cebc39 commit cf5b5ec
Show file tree
Hide file tree
Showing 32 changed files with 480 additions and 234 deletions.
2 changes: 2 additions & 0 deletions rust/Cargo.lock

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

13 changes: 12 additions & 1 deletion rust/agents/relayer/src/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,20 @@ impl BaseAgent for Relayer {
.collect();

let mut msg_ctxs = HashMap::new();
// let mut custom_metrics = HashMap::new();
for destination in &settings.destination_chains {
let destination_chain_setup = core.settings.chain_setup(destination).unwrap().clone();

let agent_metrics_conf = destination_chain_setup
.agent_metrics_conf("relayer".to_owned())
.await?;
println!("~~~ agent metrics: {:?}", agent_metrics_conf);
println!("~~~ agent signer: {:?}", destination_chain_setup.signer);
// custom_metrics.insert(
// destination.id(),
// destination_chain_setup
// .metrics(destination)
// .expect("Missing metrics config"),
// );
let transaction_gas_limit: Option<U256> =
if skip_transaction_gas_limit_for.contains(&destination.id()) {
None
Expand Down
13 changes: 9 additions & 4 deletions rust/chains/hyperlane-cosmos/src/aggregation_ism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use tracing::instrument;
pub struct CosmosAggregationIsm {
domain: HyperlaneDomain,
address: H256,
provider: Box<WasmGrpcProvider>,
provider: Box<CosmosProvider>,
}

impl CosmosAggregationIsm {
Expand All @@ -28,7 +28,12 @@ impl CosmosAggregationIsm {
locator: ContractLocator,
signer: Option<Signer>,
) -> ChainResult<Self> {
let provider = WasmGrpcProvider::new(conf.clone(), locator.clone(), signer)?;
let provider = CosmosProvider::new(
locator.domain.clone(),
conf.clone(),
Some(locator.clone()),
signer,
)?;

Ok(Self {
domain: locator.domain.clone(),
Expand All @@ -50,7 +55,7 @@ impl HyperlaneChain for CosmosAggregationIsm {
}

fn provider(&self) -> Box<dyn HyperlaneProvider> {
Box::new(CosmosProvider::new(self.domain.clone()))
Box::new(self.provider.clone())
}
}

Expand All @@ -63,7 +68,7 @@ impl AggregationIsm for CosmosAggregationIsm {
) -> ChainResult<(Vec<H256>, u8)> {
let payload = ModulesAndThresholdRequest::new(message);

let data = self.provider.wasm_query(payload, None).await?;
let data = self.provider.grpc().wasm_query(payload, None).await?;
let response: ModulesAndThresholdResponse = serde_json::from_slice(&data)?;

let modules: ChainResult<Vec<H256>> = response
Expand Down
11 changes: 9 additions & 2 deletions rust/chains/hyperlane-cosmos/src/interchain_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use crate::{
pub struct CosmosInterchainGasPaymaster {
domain: HyperlaneDomain,
address: H256,
provider: CosmosProvider,
}

impl HyperlaneContract for CosmosInterchainGasPaymaster {
Expand All @@ -36,7 +37,7 @@ impl HyperlaneChain for CosmosInterchainGasPaymaster {
}

fn provider(&self) -> Box<dyn HyperlaneProvider> {
Box::new(CosmosProvider::new(self.domain.clone()))
Box::new(self.provider.clone())
}
}

Expand All @@ -49,11 +50,17 @@ impl CosmosInterchainGasPaymaster {
locator: ContractLocator,
signer: Option<Signer>,
) -> ChainResult<Self> {
let provider = WasmGrpcProvider::new(conf.clone(), locator.clone(), signer)?;
let provider = CosmosProvider::new(
locator.domain.clone(),
conf.clone(),
Some(locator.clone()),
signer,
)?;

Ok(Self {
domain: locator.domain.clone(),
address: locator.address,
provider,
})
}
}
Expand Down
15 changes: 10 additions & 5 deletions rust/chains/hyperlane-cosmos/src/interchain_security_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct CosmosInterchainSecurityModule {
/// The address of the ISM contract.
address: H256,
/// The provider for the ISM contract.
provider: Box<WasmGrpcProvider>,
provider: CosmosProvider,
}

/// The Cosmos Interchain Security Module Implementation.
Expand All @@ -33,13 +33,17 @@ impl CosmosInterchainSecurityModule {
locator: ContractLocator,
signer: Option<Signer>,
) -> ChainResult<Self> {
let provider: WasmGrpcProvider =
WasmGrpcProvider::new(conf.clone(), locator.clone(), signer)?;
let provider = CosmosProvider::new(
locator.domain.clone(),
conf.clone(),
Some(locator.clone()),
signer,
)?;

Ok(Self {
domain: locator.domain.clone(),
address: locator.address,
provider: Box::new(provider),
provider,
})
}
}
Expand All @@ -56,7 +60,7 @@ impl HyperlaneChain for CosmosInterchainSecurityModule {
}

fn provider(&self) -> Box<dyn HyperlaneProvider> {
Box::new(CosmosProvider::new(self.domain.clone()))
Box::new(self.provider.clone())
}
}

Expand All @@ -71,6 +75,7 @@ impl InterchainSecurityModule for CosmosInterchainSecurityModule {

let data = self
.provider
.grpc()
.wasm_query(QueryIsmGeneralRequest { ism: query }, None)
.await?;

Expand Down
6 changes: 4 additions & 2 deletions rust/chains/hyperlane-cosmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod interchain_security_module;
mod libs;
mod mailbox;
mod merkle_tree_hook;
mod metrics_fetcher;
mod multisig_ism;
mod payloads;
mod providers;
Expand All @@ -24,6 +25,7 @@ mod validator_announce;

pub use self::{
aggregation_ism::*, error::*, interchain_gas::*, interchain_security_module::*, libs::*,
mailbox::*, merkle_tree_hook::*, multisig_ism::*, providers::*, routing_ism::*, signers::*,
trait_builder::*, trait_builder::*, validator_announce::*, validator_announce::*,
mailbox::*, merkle_tree_hook::*, metrics_fetcher::*, multisig_ism::*, providers::*,
routing_ism::*, signers::*, trait_builder::*, trait_builder::*, validator_announce::*,
validator_announce::*,
};
2 changes: 1 addition & 1 deletion rust/chains/hyperlane-cosmos/src/libs/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tendermint::public_key::PublicKey as TendermintPublicKey;
use crate::HyperlaneCosmosError;

/// Wrapper around the cosmrs AccountId type that abstracts bech32 encoding
#[derive(new, Debug)]
#[derive(new, Debug, Clone)]
pub struct CosmosAddress {
/// Bech32 encoded cosmos account
account_id: AccountId,
Expand Down
26 changes: 20 additions & 6 deletions rust/chains/hyperlane-cosmos/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct CosmosMailbox {
config: ConnectionConf,
domain: HyperlaneDomain,
address: H256,
provider: Box<WasmGrpcProvider>,
provider: CosmosProvider,
}

impl CosmosMailbox {
Expand All @@ -51,13 +51,18 @@ impl CosmosMailbox {
locator: ContractLocator,
signer: Option<Signer>,
) -> ChainResult<Self> {
let provider = WasmGrpcProvider::new(conf.clone(), locator.clone(), signer)?;
let provider = CosmosProvider::new(
locator.domain.clone(),
conf.clone(),
Some(locator.clone()),
signer,
)?;

Ok(Self {
config: conf,
domain: locator.domain.clone(),
address: locator.address,
provider: Box::new(provider),
provider,
})
}

Expand All @@ -79,7 +84,7 @@ impl HyperlaneChain for CosmosMailbox {
}

fn provider(&self) -> Box<dyn HyperlaneProvider> {
Box::new(CosmosProvider::new(self.domain.clone()))
Box::new(self.provider.clone())
}
}

Expand All @@ -94,7 +99,7 @@ impl Debug for CosmosMailbox {
impl Mailbox for CosmosMailbox {
#[instrument(level = "debug", err, ret, skip(self))]
async fn count(&self, lag: Option<NonZeroU64>) -> ChainResult<u32> {
let block_height = get_block_height_for_lag(&self.provider, lag).await?;
let block_height = get_block_height_for_lag(&self.provider.grpc(), lag).await?;
self.nonce_at_block(block_height).await
}

Expand All @@ -107,6 +112,7 @@ impl Mailbox for CosmosMailbox {

let delivered = match self
.provider
.grpc()
.wasm_query(GeneralMailboxQuery { mailbox: payload }, None)
.await
{
Expand Down Expand Up @@ -136,6 +142,7 @@ impl Mailbox for CosmosMailbox {

let data = self
.provider
.grpc()
.wasm_query(GeneralMailboxQuery { mailbox: payload }, None)
.await?;
let response: mailbox::DefaultIsmResponse = serde_json::from_slice(&data)?;
Expand All @@ -157,6 +164,7 @@ impl Mailbox for CosmosMailbox {

let data = self
.provider
.grpc()
.wasm_query(GeneralMailboxQuery { mailbox: payload }, None)
.await?;
let response: mailbox::RecipientIsmResponse = serde_json::from_slice(&data)?;
Expand All @@ -182,6 +190,7 @@ impl Mailbox for CosmosMailbox {

let response: TxResponse = self
.provider
.grpc()
.wasm_send(process_message, tx_gas_limit)
.await?;

Expand All @@ -201,7 +210,11 @@ impl Mailbox for CosmosMailbox {
},
};

let gas_limit = self.provider.wasm_estimate_gas(process_message).await?;
let gas_limit = self
.provider
.grpc()
.wasm_estimate_gas(process_message)
.await?;

let result = TxCostEstimate {
gas_limit: gas_limit.into(),
Expand All @@ -226,6 +239,7 @@ impl CosmosMailbox {

let data = self
.provider
.grpc()
.wasm_query(GeneralMailboxQuery { mailbox: payload }, block_height)
.await?;

Expand Down
22 changes: 15 additions & 7 deletions rust/chains/hyperlane-cosmos/src/merkle_tree_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct CosmosMerkleTreeHook {
/// Contract address
address: H256,
/// Provider
provider: Box<WasmGrpcProvider>,
provider: CosmosProvider,
}

impl CosmosMerkleTreeHook {
Expand All @@ -43,12 +43,17 @@ impl CosmosMerkleTreeHook {
locator: ContractLocator,
signer: Option<Signer>,
) -> ChainResult<Self> {
let provider = WasmGrpcProvider::new(conf.clone(), locator.clone(), signer)?;
let provider = CosmosProvider::new(
locator.domain.clone(),
conf.clone(),
Some(locator.clone()),
signer,
)?;

Ok(Self {
domain: locator.domain.clone(),
address: locator.address,
provider: Box::new(provider),
provider,
})
}
}
Expand All @@ -65,7 +70,7 @@ impl HyperlaneChain for CosmosMerkleTreeHook {
}

fn provider(&self) -> Box<dyn HyperlaneProvider> {
Box::new(CosmosProvider::new(self.domain.clone()))
Box::new(self.provider.clone())
}
}

Expand All @@ -78,10 +83,11 @@ impl MerkleTreeHook for CosmosMerkleTreeHook {
tree: general::EmptyStruct {},
};

let block_height = get_block_height_for_lag(&self.provider, lag).await?;
let block_height = get_block_height_for_lag(&self.provider.grpc(), lag).await?;

let data = self
.provider
.grpc()
.wasm_query(
merkle_tree_hook::MerkleTreeGenericRequest {
merkle_hook: payload,
Expand Down Expand Up @@ -111,7 +117,7 @@ impl MerkleTreeHook for CosmosMerkleTreeHook {
count: general::EmptyStruct {},
};

let block_height = get_block_height_for_lag(&self.provider, lag).await?;
let block_height = get_block_height_for_lag(&self.provider.grpc(), lag).await?;

self.count_at_block(block_height).await
}
Expand All @@ -122,10 +128,11 @@ impl MerkleTreeHook for CosmosMerkleTreeHook {
check_point: general::EmptyStruct {},
};

let block_height = get_block_height_for_lag(&self.provider, lag).await?;
let block_height = get_block_height_for_lag(&self.provider.grpc(), lag).await?;

let data = self
.provider
.grpc()
.wasm_query(
merkle_tree_hook::MerkleTreeGenericRequest {
merkle_hook: payload,
Expand Down Expand Up @@ -153,6 +160,7 @@ impl CosmosMerkleTreeHook {

let data = self
.provider
.grpc()
.wasm_query(
merkle_tree_hook::MerkleTreeGenericRequest {
merkle_hook: payload,
Expand Down
Loading

0 comments on commit cf5b5ec

Please sign in to comment.