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

Cosmos cleanup 0 #2876

Merged
merged 1 commit into from
Oct 31, 2023
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
70 changes: 0 additions & 70 deletions rust/agents/validator/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,73 +308,3 @@ impl Validator {
Ok(())
}
}

#[cfg(test)]
mod test {
use std::str::FromStr;

use ethers::{
signers::Wallet,
utils::{self},
};
use hyperlane_core::{Announcement, HyperlaneSigner, Signable, H256};
use hyperlane_ethereum::Signers;
use k256::ecdsa::SigningKey;

#[tokio::test]
async fn sign_manual() -> eyre::Result<()> {
let test_key = "45bde72a537e11d1cef58836d9278268fd393c0400852ce045fc0c2de7bbe90d";

let cases = [(
"0xf9e25a6be80f6d48727e42381fc3c3b7834c0cb4",
"0xcb4530690c80917c7e412498e7258fff4569857b2aae8e020091cf2d75730656",
26657,
"file:///var/folders/3v/g38z040x54x8l6b160vv66b40000gn/T/.tmpY4ofw1/checkpoint",
)];

let to_announcement = |c: (&str, &str, u32, &str)| -> eyre::Result<Announcement> {
let validator = hyperlane_core::H160::from_str(c.0)?;
let mailbox_address = hyperlane_core::H256::from_str(c.1)?;
let mailbox_domain = c.2;
let storage_location = c.3.to_string();

Ok(Announcement {
validator,
mailbox_address,
mailbox_domain,
storage_location,
})
};

for c in cases {
let announcement = to_announcement(c)?;
let hash = announcement.signing_hash();

// eth sign
let eth_signer = Signers::Local(Wallet::from_str(test_key)?);
let eth_sign = eth_signer.sign_hash(&hash).await?;
let eth_sign_raw = eth_sign.to_vec();

// raw sign
let cosmos_sign_raw = {
let signing_key =
SigningKey::from_bytes(H256::from_str(test_key)?.as_bytes().into())?;

let message = hash.as_ref();
let message_hash = utils::hash_message(message); // ERC-191

let (sign, recov) =
signing_key.sign_prehash_recoverable(message_hash.as_bytes())?;

let mut sign_raw = sign.to_vec();
sign_raw.push(recov.to_byte() + 27); // ERC-155

sign_raw
};

assert_eq!(eth_sign_raw, cosmos_sign_raw);
}

Ok(())
}
}
20 changes: 0 additions & 20 deletions rust/build

This file was deleted.

1 change: 0 additions & 1 deletion rust/chains/hyperlane-cosmos/.gitignore

This file was deleted.

22 changes: 4 additions & 18 deletions rust/chains/hyperlane-cosmos/src/aggregation_ism.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
use crate::{
grpc::{WasmGrpcProvider, WasmProvider},
payloads::aggregate_ism::{
ModulesAndThresholdRequest, ModulesAndThresholdRequestInner, ModulesAndThresholdResponse,
},
payloads::aggregate_ism::{ModulesAndThresholdRequest, ModulesAndThresholdResponse},
verify::bech32_decode,
ConnectionConf, CosmosProvider, Signer,
};
use async_trait::async_trait;
use hyperlane_core::{
AggregationIsm, ChainResult, ContractLocator, HyperlaneChain, HyperlaneContract,
HyperlaneDomain, HyperlaneMessage, HyperlaneProvider, RawHyperlaneMessage, H256,
HyperlaneDomain, HyperlaneMessage, HyperlaneProvider, H256,
};
use tracing::instrument;

/// A reference to an AggregationIsm contract on some Cosmos chain
#[derive(Debug)]
pub struct CosmosAggregationIsm {
_conf: ConnectionConf,
domain: HyperlaneDomain,
address: H256,
_signer: Signer,
provider: Box<WasmGrpcProvider>,
}

Expand All @@ -29,10 +25,8 @@ impl CosmosAggregationIsm {
let provider = WasmGrpcProvider::new(conf.clone(), locator.clone(), signer.clone());

Self {
_conf: conf,
domain: locator.domain.clone(),
address: locator.address,
_signer: signer,
provider: Box::new(provider),
}
}
Expand Down Expand Up @@ -61,20 +55,12 @@ impl AggregationIsm for CosmosAggregationIsm {
&self,
message: &HyperlaneMessage,
) -> ChainResult<(Vec<H256>, u8)> {
let payload = ModulesAndThresholdRequest {
modules_and_threshold: ModulesAndThresholdRequestInner {
message: hex::encode(RawHyperlaneMessage::from(message)),
},
};
let payload = ModulesAndThresholdRequest::new(message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nicee


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

let modules: Vec<H256> = response
.modules
.iter()
.map(|module| bech32_decode(module.clone()))
.collect();
let modules: Vec<H256> = response.modules.into_iter().map(bech32_decode).collect();

Ok((modules, response.threshold))
}
Expand Down
35 changes: 1 addition & 34 deletions rust/chains/hyperlane-cosmos/src/interchain_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use hyperlane_core::{
};
use hyperlane_core::{HyperlaneDomain, HyperlaneProvider, InterchainGasPayment, LogMeta, H256};
use std::ops::RangeInclusive;
use tracing::info;

use crate::grpc::WasmGrpcProvider;
use crate::rpc::{CosmosWasmIndexer, WasmIndexer};
Expand All @@ -18,11 +17,8 @@ use crate::{ConnectionConf, CosmosProvider};
/// A reference to a InterchainGasPaymaster contract on some Cosmos chain
#[derive(Debug)]
pub struct CosmosInterchainGasPaymaster {
_conf: ConnectionConf,
domain: HyperlaneDomain,
address: H256,
_signer: Signer,
_provider: Box<WasmGrpcProvider>,
}

impl HyperlaneContract for CosmosInterchainGasPaymaster {
Expand All @@ -49,11 +45,8 @@ impl CosmosInterchainGasPaymaster {
let provider = WasmGrpcProvider::new(conf.clone(), locator.clone(), signer.clone());

Self {
_conf: conf,
domain: locator.domain.clone(),
address: locator.address,
_signer: signer,
_provider: Box::new(provider),
}
}
}
Expand Down Expand Up @@ -145,36 +138,10 @@ impl Indexer<InterchainGasPayment> for CosmosInterchainGasPaymasterIndexer {
}
}

#[async_trait]
impl Indexer<H256> for CosmosInterchainGasPaymasterIndexer {
async fn fetch_logs(&self, range: RangeInclusive<u32>) -> ChainResult<Vec<(H256, LogMeta)>> {
let parser = self.get_parser();
let result = self.indexer.get_range_event_logs(range, parser).await?;

Ok(result
.into_iter()
.map(|(msg, meta)| (msg.message_id, meta))
.collect())
}

async fn get_finalized_block_number(&self) -> ChainResult<u32> {
self.indexer.latest_block_height().await
}
}

#[async_trait]
impl SequenceIndexer<InterchainGasPayment> for CosmosInterchainGasPaymasterIndexer {
async fn sequence_and_tip(&self) -> ChainResult<(Option<u32>, u32)> {
// TODO: implement when sealevel scraper support is implemented
let tip = self.indexer.latest_block_height().await?;
Ok((None, tip))
}
}

#[async_trait]
impl SequenceIndexer<H256> for CosmosInterchainGasPaymasterIndexer {
async fn sequence_and_tip(&self) -> ChainResult<(Option<u32>, u32)> {
// TODO: implement when sealevel scraper support is implemented
// TODO: implement when cosmwasm scraper support is implemented
let tip = self.indexer.latest_block_height().await?;
Ok((None, tip))
}
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/hyperlane-cosmos/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ impl CosmosMailboxIndexer {

fn get_parser(&self) -> fn(attrs: Vec<EventAttribute>) -> Option<HyperlaneMessage> {
|attrs: Vec<EventAttribute>| -> Option<HyperlaneMessage> {
let mut res = HyperlaneMessage::default();
let res = HyperlaneMessage::default();

for attr in attrs {
let key = attr.key.as_str();
Expand Down
2 changes: 1 addition & 1 deletion rust/chains/hyperlane-cosmos/src/merkle_tree_hook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use hyperlane_core::{
HyperlaneChain, HyperlaneContract, HyperlaneDomain, HyperlaneProvider, Indexer, LogMeta,
MerkleTreeHook, MerkleTreeInsertion, SequenceIndexer, H256,
};
use tracing::{info, instrument};
use tracing::instrument;

use crate::{
grpc::{WasmGrpcProvider, WasmProvider},
Expand Down
19 changes: 16 additions & 3 deletions rust/chains/hyperlane-cosmos/src/payloads/aggregate_ism.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
use hyperlane_core::{HyperlaneMessage, RawHyperlaneMessage};
use serde::{Deserialize, Serialize};

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

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

#[derive(Serialize, Deserialize, Debug)]
pub struct ModulesAndThresholdRequestInner {
pub message: String, // hexbinary
struct ModulesAndThresholdRequestInner {
/// Hex-encoded Hyperlane message
pub message: String,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one of my comments in the big PR is to stop using these strings entirely, curious to hear what you think

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I like that

}

#[derive(Serialize, Deserialize, Debug)]
pub struct ModulesAndThresholdResponse {
pub threshold: u8,
/// Bech32-encoded module addresses
pub modules: Vec<String>,
}
Loading