Skip to content

Commit

Permalink
Merge branch 'main' into trevor/relayer-validator-metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
tkporter authored Dec 20, 2023
2 parents aaa98e5 + c2cf7be commit b92095e
Show file tree
Hide file tree
Showing 10 changed files with 128 additions and 102 deletions.
7 changes: 3 additions & 4 deletions rust/agents/relayer/src/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use derive_new::new;
use eyre::Result;
use hyperlane_core::HyperlaneDomain;
use tokio::task::JoinHandle;
use tracing::{info_span, instrument, instrument::Instrumented, Instrument};
use tracing::instrument;

#[async_trait]
pub trait ProcessorExt: Send + Debug {
Expand All @@ -23,9 +23,8 @@ pub struct Processor {
}

impl Processor {
pub fn spawn(self) -> Instrumented<JoinHandle<Result<()>>> {
let span = info_span!("MessageProcessor");
tokio::spawn(async move { self.main_loop().await }).instrument(span)
pub fn spawn(self) -> JoinHandle<Result<()>> {
tokio::spawn(async move { self.main_loop().await })
}

#[instrument(ret, err, skip(self), level = "info", fields(domain=%self.ticker.domain()))]
Expand Down
32 changes: 23 additions & 9 deletions rust/chains/hyperlane-cosmos/src/aggregation_ism.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
use std::str::FromStr;

use crate::{
address::CosmosAddress,
grpc::WasmProvider,
payloads::aggregate_ism::{ModulesAndThresholdRequest, ModulesAndThresholdResponse},
payloads::{
ism_routes::QueryIsmGeneralRequest,
multisig_ism::{VerifyInfoRequest, VerifyInfoRequestInner, VerifyInfoResponse},
},
ConnectionConf, CosmosProvider, Signer,
};
use async_trait::async_trait;
use hyperlane_core::{
AggregationIsm, ChainResult, ContractLocator, HyperlaneChain, HyperlaneContract,
HyperlaneDomain, HyperlaneMessage, HyperlaneProvider, H256,
HyperlaneDomain, HyperlaneMessage, HyperlaneProvider, RawHyperlaneMessage, H256,
};
use tracing::instrument;

Expand Down Expand Up @@ -66,15 +68,27 @@ impl AggregationIsm for CosmosAggregationIsm {
&self,
message: &HyperlaneMessage,
) -> ChainResult<(Vec<H256>, u8)> {
let payload = ModulesAndThresholdRequest::new(message);
let payload = VerifyInfoRequest {
verify_info: VerifyInfoRequestInner {
message: hex::encode(RawHyperlaneMessage::from(message)),
},
};

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

// Note that due to a misnomer in the CosmWasm implementation, the `modules` field is called `validators`.
let modules: ChainResult<Vec<H256>> = response
.modules
.into_iter()
.map(|module| CosmosAddress::from_str(&module).map(|ca| ca.digest()))
.validators
.iter()
// The returned values are Bech32-decoded Cosmos addresses.
// Since they are not EOAs but rather contracts, they are 32 bytes long and
// need to be parsed directly as an `H256`.
.map(|module| H256::from_str(module).map_err(Into::into))
.collect();

Ok((modules?, response.threshold))
Expand Down
23 changes: 21 additions & 2 deletions rust/chains/hyperlane-cosmos/src/interchain_security_module.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use async_trait::async_trait;
use hyperlane_core::{
ChainResult, ContractLocator, HyperlaneChain, HyperlaneContract, HyperlaneDomain,
HyperlaneMessage, HyperlaneProvider, InterchainSecurityModule, ModuleType, H256, U256,
HyperlaneMessage, HyperlaneProvider, InterchainSecurityModule, ModuleType, RawHyperlaneMessage,
H256, U256,
};

use crate::{
grpc::WasmProvider,
payloads::{
aggregate_ism::{VerifyRequest, VerifyRequestInner, VerifyResponse},
general::EmptyStruct,
ism_routes::{QueryIsmGeneralRequest, QueryIsmModuleTypeRequest},
},
Expand Down Expand Up @@ -91,6 +93,23 @@ impl InterchainSecurityModule for CosmosInterchainSecurityModule {
message: &HyperlaneMessage,
metadata: &[u8],
) -> ChainResult<Option<U256>> {
Ok(Some(U256::from(1000))) // TODO
let payload = VerifyRequest {
verify: VerifyRequestInner {
metadata: hex::encode(metadata),
message: hex::encode(RawHyperlaneMessage::from(message)),
},
};
let data = self
.provider
.grpc()
.wasm_query(QueryIsmGeneralRequest { ism: payload }, None)
.await?;
let response: VerifyResponse = serde_json::from_slice(&data)?;
// We can't simulate the `verify` call in CosmWasm because
// it's not marked as an entrypoint. So we just use the query interface
// and hardcode a gas value - this can be inefficient if one ISM is
// vastly cheaper than another one.
let dummy_gas_value = U256::one();
Ok(response.verified.then_some(dummy_gas_value))
}
}
25 changes: 6 additions & 19 deletions rust/chains/hyperlane-cosmos/src/payloads/aggregate_ism.rs
Original file line number Diff line number Diff line change
@@ -1,30 +1,17 @@
use hyperlane_core::{HyperlaneMessage, RawHyperlaneMessage};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
pub struct ModulesAndThresholdRequest {
modules_and_threshold: ModulesAndThresholdRequestInner,
}

impl ModulesAndThresholdRequest {
pub fn new(message: &HyperlaneMessage) -> Self {
Self {
modules_and_threshold: ModulesAndThresholdRequestInner {
message: hex::encode(RawHyperlaneMessage::from(message)),
},
}
}
pub struct VerifyRequest {
pub verify: VerifyRequestInner,
}

#[derive(Serialize, Deserialize, Debug)]
struct ModulesAndThresholdRequestInner {
/// Hex-encoded Hyperlane message
pub struct VerifyRequestInner {
pub metadata: String,
pub message: String,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct ModulesAndThresholdResponse {
pub threshold: u8,
/// Bech32-encoded module addresses
pub modules: Vec<String>,
pub struct VerifyResponse {
pub verified: bool,
}
92 changes: 47 additions & 45 deletions rust/config/test_sealevel_config.json
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
{
"chains": {
"sealeveltest1": {
"name": "sealeveltest1",
"chainId": 13375,
"domainId": 13375,
"mailbox": "692KZJaoe2KRcD6uhCQDLLXnLNA5ZLnfvdqjE4aX9iu1",
"interchainGasPaymaster": "DrFtxirPPsfdY4HQiNZj2A9o4Ux7JaL3gELANgAoihhp",
"validatorAnnounce": "DH43ae1LwemXAboWwSh8zc9pG8j72gKUEXNi57w8fEnn",
"protocol": "sealevel",
"blocks": {
"reorgPeriod": 0,
"confirmations": 0
},
"rpcUrls": [
{
"http": "http://localhost:8899"
}
],
"index": {
"from": 1,
"mode": "sequence"
}
},
"sealeveltest2": {
"name": "sealeveltest2",
"chainId": 13376,
"domainId": 13376,
"mailbox": "9tCUWNjpqcf3NUSrtp7vquYVCwbEByvLjZUrhG5dgvhj",
"interchainGasPaymaster": "G5rGigZBL8NmxCaukK2CAKr9Jq4SUfAhsjzeri7GUraK",
"validatorAnnounce": "3Uo5j2Bti9aZtrDqJmAyuwiFaJFPFoNL5yxTpVCNcUhb",
"protocol": "sealevel",
"blocks": {
"reorgPeriod": 0,
"confirmations": 0
},
"rpcUrls": [
{
"http": "http://localhost:8899"
}
],
"index": {
"from": 1,
"mode": "sequence"
}
"chains": {
"sealeveltest1": {
"name": "sealeveltest1",
"chainId": 13375,
"domainId": 13375,
"mailbox": "692KZJaoe2KRcD6uhCQDLLXnLNA5ZLnfvdqjE4aX9iu1",
"merkleTreeHook": "692KZJaoe2KRcD6uhCQDLLXnLNA5ZLnfvdqjE4aX9iu1",
"interchainGasPaymaster": "DrFtxirPPsfdY4HQiNZj2A9o4Ux7JaL3gELANgAoihhp",
"validatorAnnounce": "DH43ae1LwemXAboWwSh8zc9pG8j72gKUEXNi57w8fEnn",
"protocol": "sealevel",
"blocks": {
"reorgPeriod": 0,
"confirmations": 0
},
"rpcUrls": [
{
"http": "http://localhost:8899"
}
],
"index": {
"from": 1,
"mode": "sequence"
}
},
"sealeveltest2": {
"name": "sealeveltest2",
"chainId": 13376,
"domainId": 13376,
"mailbox": "9tCUWNjpqcf3NUSrtp7vquYVCwbEByvLjZUrhG5dgvhj",
"merkleTreeHook": "9tCUWNjpqcf3NUSrtp7vquYVCwbEByvLjZUrhG5dgvhj",
"interchainGasPaymaster": "G5rGigZBL8NmxCaukK2CAKr9Jq4SUfAhsjzeri7GUraK",
"validatorAnnounce": "3Uo5j2Bti9aZtrDqJmAyuwiFaJFPFoNL5yxTpVCNcUhb",
"protocol": "sealevel",
"blocks": {
"reorgPeriod": 0,
"confirmations": 0
},
"rpcUrls": [
{
"http": "http://localhost:8899"
}
],
"index": {
"from": 1,
"mode": "sequence"
}
}
}
}
}
28 changes: 8 additions & 20 deletions rust/hyperlane-base/src/settings/chains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub struct CoreContractAddresses {
/// Address of the ValidatorAnnounce contract
pub validator_announce: H256,
/// Address of the MerkleTreeHook contract
pub merkle_tree_hook: Option<H256>,
pub merkle_tree_hook: H256,
}

/// Indexing settings
Expand Down Expand Up @@ -173,13 +173,7 @@ impl ChainConf {
metrics: &CoreMetrics,
) -> Result<Box<dyn MerkleTreeHook>> {
let ctx = "Building merkle tree hook";
// TODO: if the merkle tree hook is set for sealevel, it's still a mailbox program
// that the connection is made to using the pda seeds, which will not be usable.
let address = self
.addresses
.merkle_tree_hook
.unwrap_or(self.addresses.mailbox);
let locator = self.locator(address);
let locator = self.locator(self.addresses.merkle_tree_hook);

match &self.connection {
ChainConnectionConf::Ethereum(conf) => {
Expand Down Expand Up @@ -368,11 +362,7 @@ impl ChainConf {
metrics: &CoreMetrics,
) -> Result<Box<dyn SequenceIndexer<MerkleTreeInsertion>>> {
let ctx = "Building merkle tree hook indexer";
let address = self
.addresses
.merkle_tree_hook
.unwrap_or(self.addresses.mailbox);
let locator = self.locator(address);
let locator = self.locator(self.addresses.merkle_tree_hook);

match &self.connection {
ChainConnectionConf::Ethereum(conf) => {
Expand Down Expand Up @@ -704,13 +694,11 @@ impl ChainConf {
self.addresses.interchain_gas_paymaster,
EthereumInterchainGasPaymasterAbi::fn_map_owned(),
);
if let Some(address) = self.addresses.merkle_tree_hook {
register_contract(
"merkle_tree_hook",
address,
EthereumInterchainGasPaymasterAbi::fn_map_owned(),
);
}
register_contract(
"merkle_tree_hook",
self.addresses.merkle_tree_hook,
EthereumInterchainGasPaymasterAbi::fn_map_owned(),
);

cfg
}
Expand Down
4 changes: 2 additions & 2 deletions rust/hyperlane-base/src/settings/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ fn parse_chain(
.end();
let merkle_tree_hook = chain
.chain(&mut err)
.get_opt_key("merkleTreeHook")
.get_key("merkleTreeHook")
.parse_address_hash()
.end();

Expand All @@ -234,7 +234,7 @@ fn parse_chain(
default_rpc_consensus_type,
);

cfg_unwrap_all!(&chain.cwp, err: [connection, mailbox, interchain_gas_paymaster, validator_announce]);
cfg_unwrap_all!(&chain.cwp, err: [connection, mailbox, interchain_gas_paymaster, validator_announce, merkle_tree_hook]);
err.into_result(ChainConf {
domain,
signer,
Expand Down
15 changes: 15 additions & 0 deletions rust/utils/run-locally/src/cosmos/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,20 @@ pub fn deploy_cw_hyperlane(
"hpl_ism_multisig",
);

// deploy ism - aggregation
let ism_aggregate = cli.wasm_init(
&endpoint,
&deployer,
Some(deployer_addr),
codes.hpl_ism_aggregate,
ism::aggregate::InstantiateMsg {
owner: deployer_addr.clone(),
threshold: 1,
isms: vec![ism_multisig.clone()],
},
"hpl_ism_aggregate",
);

// deploy merkle hook
let hook_merkle = cli.wasm_init(
&endpoint,
Expand Down Expand Up @@ -188,6 +202,7 @@ pub fn deploy_cw_hyperlane(
hook_routing,
igp,
igp_oracle,
ism_aggregate,
ism_routing,
ism_multisig,
mailbox,
Expand Down
2 changes: 1 addition & 1 deletion rust/utils/run-locally/src/cosmos/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ fn link_network(
ism::routing::ExecuteMsg::Set {
ism: ism::routing::IsmSet {
domain: target_domain,
address: network.deployments.ism_multisig.clone(),
address: network.deployments.ism_aggregate.clone(),
},
},
vec![],
Expand Down
2 changes: 2 additions & 0 deletions rust/utils/run-locally/src/cosmos/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ pub struct Codes {
pub hpl_hook_routing: u64,
pub hpl_igp: u64,
pub hpl_igp_oracle: u64,
pub hpl_ism_aggregate: u64,
pub hpl_ism_multisig: u64,
pub hpl_ism_routing: u64,
pub hpl_test_mock_ism: u64,
Expand All @@ -57,6 +58,7 @@ pub struct Deployments {
pub hook_routing: String,
pub igp: String,
pub igp_oracle: String,
pub ism_aggregate: String,
pub ism_routing: String,
pub ism_multisig: String,
pub mailbox: String,
Expand Down

0 comments on commit b92095e

Please sign in to comment.