Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-savu committed Nov 21, 2023
1 parent e5f0bbc commit b36c558
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 103 deletions.
26 changes: 2 additions & 24 deletions rust/Cargo.lock

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

2 changes: 1 addition & 1 deletion rust/chains/hyperlane-cosmos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ hyper-tls = { workspace = true }
sha256 = { workspace = true }
hex = { workspace = true }
tendermint = { workspace = true, features = ["rust-crypto", "secp256k1"]}
hpl-interface = { version = "0.0.2" }
hpl-interface = { version = "=0.0.6-rc3" }

hyperlane-core = { path = "../../hyperlane-core" }
3 changes: 3 additions & 0 deletions rust/chains/hyperlane-cosmos/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ pub enum HyperlaneCosmosError {
/// Cosmos error report
#[error("{0}")]
CosmosErrorReport(#[from] cosmrs::ErrorReport),
/// Cosmwasm std error.
#[error("{0}")]
StdError(#[from] cosmwasm_std::StdError),
}

impl From<HyperlaneCosmosError> for ChainCommunicationError {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl InterchainSecurityModule for CosmosInterchainSecurityModule {
async fn module_type(&self) -> ChainResult<ModuleType> {
let query = IsmQueryMsg::ModuleType {};

let data = self.provider.wasm_query(query.wrap(), None).await?;
let data = self.provider.wasm_query(query, None).await?;

let module_type_response =
serde_json::from_slice::<hpl_interface::ism::ModuleTypeResponse>(&data)?;
Expand Down
31 changes: 13 additions & 18 deletions rust/chains/hyperlane-cosmos/src/merkle_tree_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{fmt::Debug, num::NonZeroU64, ops::RangeInclusive, str::FromStr};
use async_trait::async_trait;
use base64::{engine::general_purpose::STANDARD as BASE64, Engine};
use cosmrs::tendermint::abci::EventAttribute;
use hpl_interface::hook::merkle::{MerkleHookQueryMsg, QueryMsg, TreeResponse};
use hpl_interface::hook::merkle::{self, MerkleHookQueryMsg, QueryMsg, TreeResponse};
use hyperlane_core::{
accumulator::incremental::IncrementalMerkle, ChainCommunicationError, ChainResult, Checkpoint,
ContractLocator, HyperlaneChain, HyperlaneContract, HyperlaneDomain, HyperlaneProvider,
Expand All @@ -25,6 +25,7 @@ use crate::{
},
ConnectionConf,
CosmosProvider,
HyperlaneCosmosError,
Signer,
};

Expand Down Expand Up @@ -87,8 +88,7 @@ impl MerkleTreeHook for CosmosMerkleTreeHook {
let branch = response
.branch
.iter()
.map(|s| s.to_string().as_str())
.map(H256::from_str)
.map(|s| H256::from_str(s.to_string().as_str()))
.collect::<Result<Vec<H256>, _>>()?;

let branch_res: [H256; 32] = branch.try_into().map_err(|_| {
Expand All @@ -107,27 +107,22 @@ impl MerkleTreeHook for CosmosMerkleTreeHook {

#[instrument(level = "debug", err, ret, skip(self))]
async fn latest_checkpoint(&self, lag: Option<NonZeroU64>) -> ChainResult<Checkpoint> {
let payload = merkle_tree_hook::requests::CheckPoint {
check_point: general::EmptyStruct {},
};
let payload = QueryMsg::MerkleHook(MerkleHookQueryMsg::CheckPoint {});

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

let data = self
.provider
.wasm_query(
merkle_tree_hook::MerkleTreeGenericRequest {
merkle_hook: payload,
},
block_height,
)
.await?;
let response: merkle_tree_hook::responses::CheckPoint = serde_json::from_slice(&data)?;
let data = self.provider.wasm_query(payload, block_height).await?;
let response: merkle::CheckPointResponse = serde_json::from_slice(&data)?;

let root_slice: [u8; 32] = response
.root
.to_array()
.map_err(Into::<HyperlaneCosmosError>::into)?;

Ok(Checkpoint {
merkle_tree_hook_address: self.address,
mailbox_domain: self.domain.id(),
root: response.root.parse()?,
root: H256::from(root_slice),
index: response.count,
})
}
Expand All @@ -138,7 +133,7 @@ impl CosmosMerkleTreeHook {
async fn count_at_block(&self, block_height: Option<u64>) -> ChainResult<u32> {
let payload = QueryMsg::MerkleHook(MerkleHookQueryMsg::Count {});
let data = self.provider.wasm_query(payload, block_height).await?;
let response: merkle_tree_hook::responses::MerkleTreeCount = serde_json::from_slice(&data)?;
let response: merkle::CountResponse = serde_json::from_slice(&data)?;

Ok(response.count)
}
Expand Down
3 changes: 0 additions & 3 deletions rust/chains/hyperlane-cosmos/src/payloads/general.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
pub struct EmptyStruct {}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Log {
pub msg_index: u64,
Expand Down
4 changes: 2 additions & 2 deletions rust/chains/hyperlane-cosmos/src/payloads/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub mod aggregate_ism;
// pub mod general;
pub mod general;
// pub mod ism_routes;
// pub mod mailbox;
// pub mod merkle_tree_hook;
// pub mod multisig_ism;
// pub mod validator_announce;
pub mod validator_announce;
29 changes: 0 additions & 29 deletions rust/chains/hyperlane-cosmos/src/payloads/validator_announce.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
use serde::{Deserialize, Serialize};

use super::general::EmptyStruct;

#[derive(Serialize, Deserialize, Debug)]
pub struct GetAnnouncedValidatorsRequest {
pub get_announced_validators: EmptyStruct,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct GetAnnounceStorageLocationsRequest {
pub get_announce_storage_locations: GetAnnounceStorageLocationsRequestInner,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct GetAnnounceStorageLocationsRequestInner {
pub validators: Vec<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct AnnouncementRequest {
pub announce: AnnouncementRequestInner,
Expand All @@ -28,15 +11,3 @@ pub struct AnnouncementRequestInner {
pub storage_location: String,
pub signature: String,
}

// ========= resp ============

#[derive(Serialize, Deserialize, Debug)]
pub struct GetAnnouncedValidatorsResponse {
pub validators: Vec<String>,
}

#[derive(Serialize, Deserialize, Debug)]
pub struct GetAnnounceStorageLocationsResponse {
pub storage_locations: Vec<(String, Vec<String>)>,
}
4 changes: 2 additions & 2 deletions rust/chains/hyperlane-cosmos/src/routing_ism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ impl HyperlaneChain for CosmosRoutingIsm {
#[async_trait]
impl RoutingIsm for CosmosRoutingIsm {
async fn route(&self, message: &HyperlaneMessage) -> ChainResult<H256> {
let payload = QueryMsg::Route {
let payload = QueryMsg::RoutingIsm(RoutingIsmQueryMsg::Route {
message: HexBinary::from(RawHyperlaneMessage::from(message)),
};
});
let data = self.provider.wasm_query(payload, None).await?;
let response: RouteResponse = serde_json::from_slice(&data)?;

Expand Down
22 changes: 11 additions & 11 deletions rust/chains/hyperlane-cosmos/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
use hyperlane_core::ModuleType;

pub struct IsmType(pub hpl_interface::ism::ISMType);
pub struct IsmType(pub hpl_interface::ism::IsmType);

impl From<hpl_interface::ism::ISMType> for IsmType {
fn from(value: hpl_interface::ism::ISMType) -> Self {
impl From<hpl_interface::ism::IsmType> for IsmType {
fn from(value: hpl_interface::ism::IsmType) -> Self {
IsmType(value)
}
}

impl From<IsmType> for ModuleType {
fn from(value: IsmType) -> Self {
match value.0 {
hpl_interface::ism::ISMType::Unused => ModuleType::Unused,
hpl_interface::ism::ISMType::Routing => ModuleType::Routing,
hpl_interface::ism::ISMType::Aggregation => ModuleType::Aggregation,
hpl_interface::ism::ISMType::LegacyMultisig => ModuleType::MessageIdMultisig,
hpl_interface::ism::ISMType::MerkleRootMultisig => ModuleType::MerkleRootMultisig,
hpl_interface::ism::ISMType::MessageIdMultisig => ModuleType::MessageIdMultisig,
hpl_interface::ism::ISMType::Null => ModuleType::Null,
hpl_interface::ism::ISMType::CcipRead => ModuleType::CcipRead,
hpl_interface::ism::IsmType::Unused => ModuleType::Unused,
hpl_interface::ism::IsmType::Routing => ModuleType::Routing,
hpl_interface::ism::IsmType::Aggregation => ModuleType::Aggregation,
hpl_interface::ism::IsmType::LegacyMultisig => ModuleType::MessageIdMultisig,
hpl_interface::ism::IsmType::MerkleRootMultisig => ModuleType::MerkleRootMultisig,
hpl_interface::ism::IsmType::MessageIdMultisig => ModuleType::MessageIdMultisig,
hpl_interface::ism::IsmType::Null => ModuleType::Null,
hpl_interface::ism::IsmType::CcipRead => ModuleType::CcipRead,
}
}
}
17 changes: 7 additions & 10 deletions rust/chains/hyperlane-cosmos/src/validator_announce.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use async_trait::async_trait;

use cosmrs::proto::cosmos::base::abci::v1beta1::TxResponse;
use cosmwasm_std::HexBinary;
use hpl_interface::core::va::{GetAnnounceStorageLocationsResponse, QueryMsg};
use hyperlane_core::{
Announcement, ChainResult, ContractLocator, HyperlaneChain, HyperlaneContract, HyperlaneDomain,
HyperlaneProvider, SignedType, TxOutcome, ValidatorAnnounce, H160, H256, U256,
};

use crate::{
grpc::{WasmGrpcProvider, WasmProvider},
payloads::validator_announce::{AnnouncementRequest, AnnouncementRequestInner},
signers::Signer,
validator_announce, ConnectionConf, CosmosProvider,
};
Expand Down Expand Up @@ -61,19 +64,13 @@ impl ValidatorAnnounce for CosmosValidatorAnnounce {
) -> ChainResult<Vec<Vec<String>>> {
let vss = validators
.iter()
.map(|v| H160::from(*v))
.map(|v| hex::encode(v.as_bytes()))
.collect::<Vec<String>>();
.map(|v| HexBinary::from(v.as_bytes()))
.collect();

let payload = GetAnnounceStorageLocationsRequest {
get_announce_storage_locations: GetAnnounceStorageLocationsRequestInner {
validators: vss,
},
};
let payload = QueryMsg::GetAnnounceStorageLocations { validators: vss };

let data: Vec<u8> = self.provider.wasm_query(payload, None).await?;
let response: validator_announce::GetAnnounceStorageLocationsResponse =
serde_json::from_slice(&data)?;
let response: GetAnnounceStorageLocationsResponse = serde_json::from_slice(&data)?;

Ok(response
.storage_locations
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 @@ -21,8 +21,8 @@ use serde_json::Value;
pub use self::json_value_parser::ValueParser;
pub use super::envs::*;
use crate::settings::{
chains::IndexSettings, parser::connection_parser::build_connection_conf, trace::TracingConfig,
ChainConf, CoreContractAddresses, Settings, SignerConf,
chains::IndexSettings, trace::TracingConfig, ChainConf, ChainConnectionConf,
CoreContractAddresses, Settings, SignerConf,
};

mod json_value_parser;
Expand Down

0 comments on commit b36c558

Please sign in to comment.