Skip to content

Commit

Permalink
Merge branch 'main' into rossy/cli
Browse files Browse the repository at this point in the history
  • Loading branch information
jmrossy committed Aug 2, 2023
2 parents 9ff88de + 2fc4903 commit 91e4262
Show file tree
Hide file tree
Showing 51 changed files with 1,498 additions and 1,254 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ jobs:
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: Install mold linker
uses: rui314/setup-mold@v1
with:
mold-version: 2.0.0
make-default: true
- name: rust cache
uses: Swatinem/rust-cache@v2
with:
Expand Down
17 changes: 17 additions & 0 deletions rust/Cargo.lock

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

12 changes: 8 additions & 4 deletions rust/agents/relayer/src/relayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,10 +266,11 @@ impl Relayer {
&self,
origin: &HyperlaneDomain,
) -> Instrumented<JoinHandle<eyre::Result<()>>> {
let index_settings = self.as_ref().settings.chains[origin.name()].index.clone();
let (index_settings, index_mode) =
self.as_ref().settings.chains[origin.name()].index_settings_and_mode();
let contract_sync = self.message_syncs.get(origin).unwrap().clone();
let cursor = contract_sync
.forward_backward_message_sync_cursor(index_settings)
.forward_backward_message_sync_cursor(index_settings, index_mode)
.await;
tokio::spawn(async move {
contract_sync
Expand All @@ -284,13 +285,16 @@ impl Relayer {
&self,
origin: &HyperlaneDomain,
) -> Instrumented<JoinHandle<eyre::Result<()>>> {
let index_settings = self.as_ref().settings.chains[origin.name()].index.clone();
let (index_settings, index_mode) =
self.as_ref().settings.chains[origin.name()].index_settings_and_mode();
let contract_sync = self
.interchain_gas_payment_syncs
.get(origin)
.unwrap()
.clone();
let cursor = contract_sync.rate_limited_cursor(index_settings).await;
let cursor = contract_sync
.rate_limited_cursor(index_settings, index_mode)
.await;
tokio::spawn(async move { contract_sync.clone().sync("gas_payments", cursor).await })
.instrument(info_span!("ContractSync"))
}
Expand Down
8 changes: 6 additions & 2 deletions rust/agents/scraper/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ macro_rules! spawn_sync_task {
.await
.unwrap();
let cursor = sync
.$cursor(index_settings.clone())
.$cursor(index_settings.clone(), domain.clone().index_mode())
.await;
tokio::spawn(async move {
sync
Expand Down Expand Up @@ -275,7 +275,11 @@ impl Scraper {
.unwrap_or(None)
.unwrap_or(0);
let cursor = sync
.forward_message_sync_cursor(index_settings.clone(), latest_nonce.saturating_sub(1))
.forward_message_sync_cursor(
index_settings.clone(),
domain.index_mode(),
latest_nonce.saturating_sub(1),
)
.await;
tokio::spawn(async move { sync.sync("message_dispatch", cursor).await }).instrument(
info_span!("ChainContractSync", chain=%domain.name(), event="message_dispatch"),
Expand Down
9 changes: 4 additions & 5 deletions rust/agents/validator/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,11 @@ impl BaseAgent for Validator {

impl Validator {
async fn run_message_sync(&self) -> Instrumented<JoinHandle<Result<()>>> {
let index_settings = self.as_ref().settings.chains[self.origin_chain.name()]
.index
.clone();
let (index_settings, index_mode) =
self.as_ref().settings.chains[self.origin_chain.name()].index_settings_and_mode();
let contract_sync = self.message_sync.clone();
let cursor = contract_sync
.forward_backward_message_sync_cursor(index_settings)
.forward_backward_message_sync_cursor(index_settings, index_mode)
.await;
tokio::spawn(async move {
contract_sync
Expand Down Expand Up @@ -271,14 +270,14 @@ impl Validator {
validator_address=?announcement.validator,
"Please send tokens to the validator address to announce",
);
sleep(self.interval).await;
} else {
let result = self
.validator_announce
.announce(signed_announcement.clone(), None)
.await;
Self::log_on_announce_failure(result);
}
sleep(self.interval).await;
}
}
Ok(())
Expand Down
36 changes: 23 additions & 13 deletions rust/chains/hyperlane-ethereum/src/interchain_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

use std::collections::HashMap;
use std::fmt::Display;
use std::ops::RangeInclusive;
use std::sync::Arc;

use async_trait::async_trait;
use ethers::prelude::Middleware;
use tracing::instrument;

use hyperlane_core::{
BlockRange, ChainCommunicationError, ChainResult, ContractLocator, HyperlaneAbi,
HyperlaneChain, HyperlaneContract, HyperlaneDomain, HyperlaneProvider, IndexRange, Indexer,
InterchainGasPaymaster, InterchainGasPayment, LogMeta, H160, H256,
ChainCommunicationError, ChainResult, ContractLocator, HyperlaneAbi, HyperlaneChain,
HyperlaneContract, HyperlaneDomain, HyperlaneProvider, Indexer, InterchainGasPaymaster,
InterchainGasPayment, LogMeta, SequenceIndexer, H160, H256,
};
use tracing::instrument;

use crate::contracts::i_interchain_gas_paymaster::{
IInterchainGasPaymaster as EthereumInterchainGasPaymasterInternal, IINTERCHAINGASPAYMASTER_ABI,
Expand All @@ -36,7 +36,7 @@ pub struct InterchainGasPaymasterIndexerBuilder {

#[async_trait]
impl BuildableWithProvider for InterchainGasPaymasterIndexerBuilder {
type Output = Box<dyn Indexer<InterchainGasPayment>>;
type Output = Box<dyn SequenceIndexer<InterchainGasPayment>>;

async fn build_with_provider<M: Middleware + 'static>(
&self,
Expand Down Expand Up @@ -87,14 +87,8 @@ where
#[instrument(err, skip(self))]
async fn fetch_logs(
&self,
range: IndexRange,
range: RangeInclusive<u32>,
) -> ChainResult<Vec<(InterchainGasPayment, LogMeta)>> {
let BlockRange(range) = range else {
return Err(ChainCommunicationError::from_other_str(
"EthereumInterchainGasPaymasterIndexer only supports block-based indexing",
));
};

let events = self
.contract
.gas_payment_filter()
Expand Down Expand Up @@ -130,6 +124,22 @@ where
}
}

#[async_trait]
impl<M> SequenceIndexer<InterchainGasPayment> for EthereumInterchainGasPaymasterIndexer<M>
where
M: Middleware + 'static,
{
async fn sequence_at_tip(&self) -> ChainResult<(u32, u32)> {
// The InterchainGasPaymasterIndexerBuilder must return a `SequenceIndexer` type.
// It's fine if only a blanket implementation is provided for EVM chains, since their
// indexing only uses the `Index` trait, which is a supertrait of `SequenceIndexer`.
// TODO: if `SequenceIndexer` turns out to not depend on `Indexer` at all, then the supertrait
// dependency could be removed, even if the builder would still need to return a type that is both
// ``SequenceIndexer` and `Indexer`.
panic!("Gas payment nonce indexing not implemented");
}
}

pub struct InterchainGasPaymasterBuilder {}

#[async_trait]
Expand Down
42 changes: 23 additions & 19 deletions rust/chains/hyperlane-ethereum/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,23 @@

use std::collections::HashMap;
use std::num::NonZeroU64;
use std::ops::RangeInclusive;
use std::sync::Arc;

use async_trait::async_trait;
use ethers::abi::AbiEncode;
use ethers::prelude::Middleware;
use ethers_contract::builders::ContractCall;
use hyperlane_core::SequenceIndexer;
use tracing::instrument;

use hyperlane_core::accumulator::incremental::IncrementalMerkle;
use hyperlane_core::accumulator::TREE_DEPTH;
use hyperlane_core::{
utils::fmt_bytes, BlockRange, ChainCommunicationError, ChainResult, Checkpoint,
ContractLocator, HyperlaneAbi, HyperlaneChain, HyperlaneContract, HyperlaneDomain,
HyperlaneMessage, HyperlaneProtocolError, HyperlaneProvider, IndexRange, Indexer, LogMeta,
Mailbox, MessageIndexer, RawHyperlaneMessage, TxCostEstimate, TxOutcome, H160, H256, U256,
utils::fmt_bytes, ChainCommunicationError, ChainResult, Checkpoint, ContractLocator,
HyperlaneAbi, HyperlaneChain, HyperlaneContract, HyperlaneDomain, HyperlaneMessage,
HyperlaneProtocolError, HyperlaneProvider, Indexer, LogMeta, Mailbox, MessageIndexer,
RawHyperlaneMessage, TxCostEstimate, TxOutcome, H160, H256, U256,
};

use crate::contracts::arbitrum_node_interface::ArbitrumNodeInterface;
Expand Down Expand Up @@ -65,7 +67,7 @@ pub struct DeliveryIndexerBuilder {

#[async_trait]
impl BuildableWithProvider for DeliveryIndexerBuilder {
type Output = Box<dyn Indexer<H256>>;
type Output = Box<dyn SequenceIndexer<H256>>;

async fn build_with_provider<M: Middleware + 'static>(
&self,
Expand Down Expand Up @@ -130,13 +132,10 @@ where
}

#[instrument(err, skip(self))]
async fn fetch_logs(&self, range: IndexRange) -> ChainResult<Vec<(HyperlaneMessage, LogMeta)>> {
let BlockRange(range) = range else {
return Err(ChainCommunicationError::from_other_str(
"EthereumMailboxIndexer only supports block-based indexing",
))
};

async fn fetch_logs(
&self,
range: RangeInclusive<u32>,
) -> ChainResult<Vec<(HyperlaneMessage, LogMeta)>> {
let mut events: Vec<(HyperlaneMessage, LogMeta)> = self
.contract
.dispatch_filter()
Expand Down Expand Up @@ -178,13 +177,7 @@ where
}

#[instrument(err, skip(self))]
async fn fetch_logs(&self, range: IndexRange) -> ChainResult<Vec<(H256, LogMeta)>> {
let BlockRange(range) = range else {
return Err(ChainCommunicationError::from_other_str(
"EthereumMailboxIndexer only supports block-based indexing",
))
};

async fn fetch_logs(&self, range: RangeInclusive<u32>) -> ChainResult<Vec<(H256, LogMeta)>> {
Ok(self
.contract
.process_id_filter()
Expand All @@ -197,6 +190,17 @@ where
.collect())
}
}

#[async_trait]
impl<M> SequenceIndexer<H256> for EthereumMailboxIndexer<M>
where
M: Middleware + 'static,
{
async fn sequence_at_tip(&self) -> ChainResult<(u32, u32)> {
panic!("Message delivery sequence indexing not implemented");
}
}

pub struct MailboxBuilder {}

#[async_trait]
Expand Down
6 changes: 4 additions & 2 deletions rust/chains/hyperlane-fuel/src/interchain_gas.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use std::ops::RangeInclusive;

use async_trait::async_trait;

use hyperlane_core::{
ChainResult, HyperlaneChain, HyperlaneContract, IndexRange, Indexer, InterchainGasPaymaster,
ChainResult, HyperlaneChain, HyperlaneContract, Indexer, InterchainGasPaymaster,
};
use hyperlane_core::{HyperlaneDomain, HyperlaneProvider, InterchainGasPayment, LogMeta, H256};

Expand Down Expand Up @@ -35,7 +37,7 @@ pub struct FuelInterchainGasPaymasterIndexer {}
impl Indexer<InterchainGasPayment> for FuelInterchainGasPaymasterIndexer {
async fn fetch_logs(
&self,
range: IndexRange,
range: RangeInclusive<u32>,
) -> ChainResult<Vec<(InterchainGasPayment, LogMeta)>> {
todo!()
}
Expand Down
11 changes: 7 additions & 4 deletions rust/chains/hyperlane-fuel/src/mailbox.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::collections::HashMap;
use std::fmt::{Debug, Formatter};
use std::num::NonZeroU64;
use std::ops::RangeInclusive;

use async_trait::async_trait;
use fuels::prelude::{Bech32ContractId, WalletUnlocked};
Expand All @@ -10,8 +11,7 @@ use tracing::instrument;
use hyperlane_core::{
utils::fmt_bytes, ChainCommunicationError, ChainResult, Checkpoint, ContractLocator,
HyperlaneAbi, HyperlaneChain, HyperlaneContract, HyperlaneDomain, HyperlaneMessage,
HyperlaneProvider, IndexRange, Indexer, LogMeta, Mailbox, TxCostEstimate, TxOutcome, H256,
U256,
HyperlaneProvider, Indexer, LogMeta, Mailbox, TxCostEstimate, TxOutcome, H256, U256,
};

use crate::{
Expand Down Expand Up @@ -154,7 +154,10 @@ pub struct FuelMailboxIndexer {}

#[async_trait]
impl Indexer<HyperlaneMessage> for FuelMailboxIndexer {
async fn fetch_logs(&self, range: IndexRange) -> ChainResult<Vec<(HyperlaneMessage, LogMeta)>> {
async fn fetch_logs(
&self,
range: RangeInclusive<u32>,
) -> ChainResult<Vec<(HyperlaneMessage, LogMeta)>> {
todo!()
}

Expand All @@ -165,7 +168,7 @@ impl Indexer<HyperlaneMessage> for FuelMailboxIndexer {

#[async_trait]
impl Indexer<H256> for FuelMailboxIndexer {
async fn fetch_logs(&self, range: IndexRange) -> ChainResult<Vec<(H256, LogMeta)>> {
async fn fetch_logs(&self, range: RangeInclusive<u32>) -> ChainResult<Vec<(H256, LogMeta)>> {
todo!()
}

Expand Down
8 changes: 4 additions & 4 deletions rust/chains/hyperlane-sealevel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ tracing-futures.workspace = true
tracing.workspace = true
url.workspace = true

account-utils = { path = "../../sealevel/libraries/account-utils" }
hyperlane-core = { path = "../../hyperlane-core" }
hyperlane-sealevel-mailbox = { path = "../../sealevel/programs/mailbox", features = ["no-entrypoint"] }
hyperlane-sealevel-interchain-security-module-interface = { path = "../../sealevel/libraries/interchain-security-module-interface" }
hyperlane-sealevel-mailbox = { path = "../../sealevel/programs/mailbox", features = ["no-entrypoint"] }
hyperlane-sealevel-message-recipient-interface = { path = "../../sealevel/libraries/message-recipient-interface" }
serializable-account-meta = { path = "../../sealevel/libraries/serializable-account-meta" }
account-utils = { path = "../../sealevel/libraries/account-utils" }
multisig-ism = { path = "../../sealevel/libraries/multisig-ism" }
hyperlane-sealevel-multisig-ism-message-id = { path = "../../sealevel/programs/ism/multisig-ism-message-id", features = ["no-entrypoint"] }
hyperlane-sealevel-validator-announce = { path = "../../sealevel/programs/validator-announce", features = ["no-entrypoint"] }
multisig-ism = { path = "../../sealevel/libraries/multisig-ism" }
serializable-account-meta = { path = "../../sealevel/libraries/serializable-account-meta" }
16 changes: 13 additions & 3 deletions rust/chains/hyperlane-sealevel/src/interchain_gas.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::ops::RangeInclusive;

use async_trait::async_trait;
use hyperlane_core::{
ChainResult, ContractLocator, HyperlaneChain, HyperlaneContract, HyperlaneDomain,
HyperlaneProvider, IndexRange, Indexer, InterchainGasPaymaster, InterchainGasPayment, LogMeta,
H256,
HyperlaneProvider, Indexer, InterchainGasPaymaster, InterchainGasPayment, LogMeta,
SequenceIndexer, H256,
};
use tracing::{info, instrument};

Expand Down Expand Up @@ -61,7 +63,7 @@ impl Indexer<InterchainGasPayment> for SealevelInterchainGasPaymasterIndexer {
#[instrument(err, skip(self))]
async fn fetch_logs(
&self,
_range: IndexRange,
_range: RangeInclusive<u32>,
) -> ChainResult<Vec<(InterchainGasPayment, LogMeta)>> {
info!("Gas payment indexing not implemented for Sealevel");
Ok(vec![])
Expand All @@ -74,3 +76,11 @@ impl Indexer<InterchainGasPayment> for SealevelInterchainGasPaymasterIndexer {
Ok(1)
}
}

#[async_trait]
impl SequenceIndexer<InterchainGasPayment> for SealevelInterchainGasPaymasterIndexer {
async fn sequence_at_tip(&self) -> ChainResult<(u32, u32)> {
info!("Gas payment indexing not implemented for Sealevel");
Ok((1, 1))
}
}
Loading

0 comments on commit 91e4262

Please sign in to comment.