Remove unused files (#1359)

asaj/image
Asa Oines 2 years ago committed by GitHub
parent e8ed5f88ce
commit ad87305641
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 323
      rust/chains/hyperlane-ethereum/src/outbox.rs
  2. 208
      rust/chains/hyperlane-ethereum/src/validator_manager.rs
  3. 25
      rust/hyperlane-core/src/traits/inbox.rs
  4. 81
      rust/hyperlane-test/src/mocks/inbox.rs
  5. 111
      rust/hyperlane-test/src/mocks/outbox.rs

@ -1,323 +0,0 @@
#![allow(clippy::enum_variant_names)]
#![allow(missing_docs)]
use std::collections::HashMap;
use std::sync::Arc;
use async_trait::async_trait;
use ethers::prelude::*;
use eyre::Result;
use tracing::instrument;
use hyperlane_core::{
HyperlaneAbi, HyperlaneChain, HyperlaneCommon, HyperlaneContract, ChainCommunicationError, Checkpoint,
ContractLocator, Indexer, LogMeta, Message, Outbox, OutboxIndexer, OutboxState,
RawCommittedMessage, TxOutcome,
};
use crate::contracts::outbox::{Outbox as EthereumOutboxInternal, OUTBOX_ABI};
use crate::trait_builder::MakeableWithProvider;
use crate::tx::report_tx;
impl<M> std::fmt::Display for EthereumOutboxInternal<M>
where
M: Middleware,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
pub struct OutboxIndexerBuilder {
pub finality_blocks: u32,
}
#[async_trait]
impl MakeableWithProvider for OutboxIndexerBuilder {
type Output = Box<dyn OutboxIndexer>;
async fn make_with_provider<M: Middleware + 'static>(
&self,
provider: M,
locator: &ContractLocator,
) -> Self::Output {
Box::new(EthereumOutboxIndexer::new(
Arc::new(provider),
locator,
self.finality_blocks,
))
}
}
#[derive(Debug)]
/// Struct that retrieves event data for an Ethereum outbox
pub struct EthereumOutboxIndexer<M>
where
M: Middleware,
{
contract: Arc<EthereumOutboxInternal<M>>,
provider: Arc<M>,
finality_blocks: u32,
outbox_domain: u32,
}
impl<M> EthereumOutboxIndexer<M>
where
M: Middleware + 'static,
{
/// Create new EthereumOutboxIndexer
pub fn new(provider: Arc<M>, locator: &ContractLocator, finality_blocks: u32) -> Self {
let contract = Arc::new(EthereumOutboxInternal::new(
&locator.address,
provider.clone(),
));
Self {
contract,
provider,
finality_blocks,
outbox_domain: locator.domain,
}
}
}
#[async_trait]
impl<M> Indexer for EthereumOutboxIndexer<M>
where
M: Middleware + 'static,
{
#[instrument(err, skip(self))]
async fn get_finalized_block_number(&self) -> Result<u32> {
Ok(self
.provider
.get_block_number()
.await?
.as_u32()
.saturating_sub(self.finality_blocks))
}
}
#[async_trait]
impl<M> OutboxIndexer for EthereumOutboxIndexer<M>
where
M: Middleware + 'static,
{
#[instrument(err, skip(self))]
async fn fetch_sorted_messages(
&self,
from: u32,
to: u32,
) -> Result<Vec<(RawCommittedMessage, LogMeta)>> {
let mut events: Vec<(RawCommittedMessage, LogMeta)> = self
.contract
.dispatch_filter()
.from_block(from)
.to_block(to)
.query_with_meta()
.await?
.into_iter()
.map(|(event, meta)| {
(
RawCommittedMessage {
leaf_index: event.leaf_index.as_u32(),
message: event.message.to_vec(),
},
meta.into(),
)
})
.collect();
events.sort_by(|a, b| a.0.leaf_index.cmp(&b.0.leaf_index));
Ok(events)
}
#[instrument(err, skip(self))]
async fn fetch_sorted_cached_checkpoints(
&self,
from: u32,
to: u32,
) -> Result<Vec<(Checkpoint, LogMeta)>> {
let mut events: Vec<(Checkpoint, LogMeta)> = self
.contract
.checkpoint_cached_filter()
.from_block(from)
.to_block(to)
.query_with_meta()
.await?
.into_iter()
.map(|(event, meta)| {
(
Checkpoint {
outbox_domain: self.outbox_domain,
root: event.root.into(),
index: event.index.as_u32(),
},
meta.into(),
)
})
.collect();
events.sort_by(|a, b| a.1.cmp(&b.1));
Ok(events)
}
}
pub struct OutboxBuilder {}
#[async_trait]
impl MakeableWithProvider for OutboxBuilder {
type Output = Box<dyn Outbox>;
async fn make_with_provider<M: Middleware + 'static>(
&self,
provider: M,
locator: &ContractLocator,
) -> Self::Output {
Box::new(EthereumOutbox::new(Arc::new(provider), locator))
}
}
/// A reference to an Outbox contract on some Ethereum chain
#[derive(Debug)]
pub struct EthereumOutbox<M>
where
M: Middleware,
{
contract: Arc<EthereumOutboxInternal<M>>,
domain: u32,
chain_name: String,
provider: Arc<M>,
}
impl<M> EthereumOutbox<M>
where
M: Middleware + 'static,
{
/// Create a reference to a outbox at a specific Ethereum address on some
/// chain
pub fn new(provider: Arc<M>, locator: &ContractLocator) -> Self {
Self {
contract: Arc::new(EthereumOutboxInternal::new(
&locator.address,
provider.clone(),
)),
domain: locator.domain,
chain_name: locator.chain_name.to_owned(),
provider,
}
}
}
impl<M> HyperlaneChain for EthereumOutbox<M>
where
M: Middleware + 'static,
{
fn chain_name(&self) -> &str {
&self.chain_name
}
fn local_domain(&self) -> u32 {
self.domain
}
}
impl<M> HyperlaneContract for EthereumOutbox<M>
where
M: Middleware + 'static,
{
fn address(&self) -> H256 {
self.contract.address().into()
}
}
#[async_trait]
impl<M> HyperlaneCommon for EthereumOutbox<M>
where
M: Middleware + 'static,
{
#[tracing::instrument(err, skip(self))]
async fn validator_manager(&self) -> Result<H256, ChainCommunicationError> {
Ok(self.contract.validator_manager().call().await?.into())
}
}
#[async_trait]
impl<M> Outbox for EthereumOutbox<M>
where
M: Middleware + 'static,
{
#[tracing::instrument(err, skip(self))]
async fn dispatch(&self, message: &Message) -> Result<TxOutcome, ChainCommunicationError> {
let tx = self.contract.dispatch(
message.destination,
message.recipient.to_fixed_bytes(),
message.body.clone().into(),
);
Ok(report_tx(tx).await?.into())
}
#[tracing::instrument(err, skip(self))]
async fn state(&self) -> Result<OutboxState, ChainCommunicationError> {
let state = self.contract.state().call().await?;
Ok(OutboxState::try_from(state).expect("Invalid state received from contract"))
}
#[tracing::instrument(err, skip(self))]
async fn count(&self) -> Result<u32, ChainCommunicationError> {
Ok(self.contract.count().call().await?.as_u32())
}
#[tracing::instrument(err, skip(self))]
async fn cache_checkpoint(&self) -> Result<TxOutcome, ChainCommunicationError> {
let tx = self.contract.cache_checkpoint();
Ok(report_tx(tx).await?.into())
}
#[tracing::instrument(err, skip(self))]
async fn latest_cached_root(&self) -> Result<H256, ChainCommunicationError> {
Ok(self.contract.latest_cached_root().call().await?.into())
}
#[tracing::instrument(err, skip(self))]
async fn latest_cached_checkpoint(&self) -> Result<Checkpoint, ChainCommunicationError> {
let (root, index) = self.contract.latest_cached_checkpoint().call().await?;
Ok(Checkpoint {
outbox_domain: self.domain,
root: root.into(),
index: index.as_u32(),
})
}
#[tracing::instrument(err, skip(self))]
async fn latest_checkpoint(
&self,
maybe_lag: Option<u64>,
) -> Result<Checkpoint, ChainCommunicationError> {
let base_call = self.contract.latest_checkpoint();
let call_with_lag = match maybe_lag {
Some(lag) => {
let tip = self
.provider
.get_block_number()
.await
.map_err(|x| ChainCommunicationError::CustomError(Box::new(x)))?
.as_u64();
base_call.block(if lag > tip { 0 } else { tip - lag })
}
None => base_call,
};
let (root, index) = call_with_lag.call().await?;
Ok(Checkpoint {
outbox_domain: self.domain,
root: root.into(),
index: index.as_u32(),
})
}
}
pub struct EthereumOutboxAbi;
impl HyperlaneAbi for EthereumOutboxAbi {
fn fn_map() -> HashMap<Selector, &'static str> {
super::extract_fn_map(&OUTBOX_ABI)
}
}

@ -1,208 +0,0 @@
#![allow(clippy::enum_variant_names)]
#![allow(missing_docs)]
use std::fmt::Display;
use std::sync::Arc;
use hyperlane_core::TxCostEstimate;
use async_trait::async_trait;
use ethers::abi::AbiEncode;
use ethers::prelude::*;
use ethers_contract::builders::ContractCall;
use eyre::{eyre, Result};
use hyperlane_core::{
accumulator::merkle::Proof, HyperlaneMessage, ChainCommunicationError, ContractLocator, Encode,
InboxValidatorManager, MultisigSignedCheckpoint, TxOutcome,
};
use crate::contracts::inbox_validator_manager::{
InboxValidatorManager as EthereumInboxValidatorManagerInternal, ProcessCall,
};
use crate::trait_builder::MakeableWithProvider;
use crate::tx::report_tx;
pub use crate::contracts::inbox_validator_manager::INBOXVALIDATORMANAGER_ABI;
impl<M> Display for EthereumInboxValidatorManagerInternal<M>
where
M: Middleware,
{
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{:?}", self)
}
}
pub struct InboxValidatorManagerBuilder {
pub inbox_address: Address,
}
#[async_trait]
impl MakeableWithProvider for InboxValidatorManagerBuilder {
type Output = Box<dyn InboxValidatorManager>;
async fn make_with_provider<M: Middleware + 'static>(
&self,
provider: M,
locator: &ContractLocator,
) -> Self::Output {
Box::new(EthereumInboxValidatorManager::new(
Arc::new(provider),
locator,
self.inbox_address,
))
}
}
/// A struct that provides access to an Ethereum InboxValidatorManager contract
#[derive(Debug)]
pub struct EthereumInboxValidatorManager<M>
where
M: Middleware,
{
contract: Arc<EthereumInboxValidatorManagerInternal<M>>,
#[allow(unused)]
domain: u32,
#[allow(unused)]
chain_name: String,
#[allow(unused)]
provider: Arc<M>,
inbox_address: Address,
}
impl<M> EthereumInboxValidatorManager<M>
where
M: Middleware,
{
/// Create a reference to a inbox at a specific Ethereum address on some
/// chain
pub fn new(provider: Arc<M>, locator: &ContractLocator, inbox_address: Address) -> Self {
Self {
contract: Arc::new(EthereumInboxValidatorManagerInternal::new(
&locator.address,
provider.clone(),
)),
domain: locator.domain,
chain_name: locator.chain_name.to_owned(),
provider,
inbox_address,
}
}
}
#[async_trait]
impl<M> InboxValidatorManager for EthereumInboxValidatorManager<M>
where
M: Middleware + 'static,
{
#[tracing::instrument(skip(self))]
async fn process(
&self,
multisig_signed_checkpoint: &MultisigSignedCheckpoint,
message: &HyperlaneMessage,
proof: &Proof,
tx_gas_limit: Option<U256>,
) -> Result<TxOutcome, ChainCommunicationError> {
let contract_call = self
.process_contract_call(multisig_signed_checkpoint, message, proof, tx_gas_limit)
.await?;
let receipt = report_tx(contract_call).await?;
Ok(receipt.into())
}
async fn process_estimate_costs(
&self,
multisig_signed_checkpoint: &MultisigSignedCheckpoint,
message: &HyperlaneMessage,
proof: &Proof,
) -> Result<TxCostEstimate> {
let contract_call = self
.process_contract_call(multisig_signed_checkpoint, message, proof, None)
.await?;
let gas_limit = contract_call
.tx
.gas()
.ok_or_else(|| eyre!("Expected gas limit for process contract call"))?;
let gas_price = self.provider.get_gas_price().await?;
Ok(TxCostEstimate {
gas_limit: *gas_limit,
gas_price,
})
}
fn process_calldata(
&self,
multisig_signed_checkpoint: &MultisigSignedCheckpoint,
message: &HyperlaneMessage,
proof: &Proof,
) -> Vec<u8> {
let mut sol_proof: [[u8; 32]; 32] = Default::default();
sol_proof
.iter_mut()
.enumerate()
.for_each(|(i, elem)| *elem = proof.path[i].to_fixed_bytes());
let process_call = ProcessCall {
inbox: self.inbox_address,
root: multisig_signed_checkpoint.checkpoint.root.to_fixed_bytes(),
index: multisig_signed_checkpoint.checkpoint.index.into(),
signatures: multisig_signed_checkpoint
.signatures
.iter()
.map(|s| s.to_vec().into())
.collect(),
message: message.to_vec().into(),
proof: sol_proof,
leaf_index: proof.index.into(),
};
process_call.encode()
}
fn contract_address(&self) -> hyperlane_core::Address {
self.contract.address().into()
}
}
impl<M> EthereumInboxValidatorManager<M>
where
M: Middleware + 'static,
{
/// Returns a ContractCall that processes the provided message.
/// If the provided tx_gas_limit is None, gas estimation occurs.
async fn process_contract_call(
&self,
multisig_signed_checkpoint: &MultisigSignedCheckpoint,
message: &HyperlaneMessage,
proof: &Proof,
tx_gas_limit: Option<U256>,
) -> Result<ContractCall<M, ()>, ChainCommunicationError> {
let mut sol_proof: [[u8; 32]; 32] = Default::default();
sol_proof
.iter_mut()
.enumerate()
.for_each(|(i, elem)| *elem = proof.path[i].to_fixed_bytes());
let tx = self.contract.process(
self.inbox_address,
multisig_signed_checkpoint.checkpoint.root.to_fixed_bytes(),
multisig_signed_checkpoint.checkpoint.index.into(),
multisig_signed_checkpoint
.signatures
.iter()
.map(|s| s.to_vec().into())
.collect(),
message.to_vec().into(),
sol_proof,
proof.index.into(),
);
let gas_limit = if let Some(gas_limit) = tx_gas_limit {
gas_limit
} else {
tx.estimate_gas().await?.saturating_add(U256::from(100000))
};
Ok(tx.gas(gas_limit))
}
}

@ -1,25 +0,0 @@
use std::fmt::Debug;
use async_trait::async_trait;
use auto_impl::auto_impl;
use ethers::core::types::H256;
use eyre::Result;
use crate::{
traits::{HyperlaneCommon, ChainCommunicationError},
Address, MessageStatus,
};
/// Interface for on-chain inboxes
#[async_trait]
#[auto_impl(Box, Arc)]
pub trait Inbox: HyperlaneCommon + Send + Sync + Debug {
/// Return the domain of the inbox's linked outbox
fn remote_domain(&self) -> u32;
/// Fetch the status of a message
async fn message_status(&self, leaf: H256) -> Result<MessageStatus, ChainCommunicationError>;
/// The on-chain address of the inbox contract.
fn contract_address(&self) -> Address;
}

@ -1,81 +0,0 @@
#![allow(non_snake_case)]
use async_trait::async_trait;
use ethers::types::H256;
use mockall::*;
use hyperlane_core::{accumulator::merkle::Proof, *};
mock! {
pub InboxContract {
// Inbox
pub fn _address(&self) -> H256 {}
pub fn _local_domain(&self) -> u32 {}
pub fn _contract_address(&self) -> Address {}
pub fn _remote_domain(&self) -> u32 {}
pub fn _prove(&self, proof: &Proof) -> Result<TxOutcome, ChainCommunicationError> {}
pub fn _checkpoint(
&self,
signed_checkpoint: &SignedCheckpoint,
) -> Result<TxOutcome, ChainCommunicationError> {}
// HyperlaneCommon
pub fn _status(&self, txid: H256) -> Result<Option<TxOutcome>, ChainCommunicationError> {}
pub fn _validator_manager(&self) -> Result<H256, ChainCommunicationError> {}
pub fn _message_status(&self, leaf: H256) -> Result<MessageStatus, ChainCommunicationError> {}
// HyperlaneContract
pub fn _chain_name(&self) -> &str {}
}
}
impl std::fmt::Debug for MockInboxContract {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "MockInboxContract")
}
}
#[async_trait]
impl Inbox for MockInboxContract {
fn remote_domain(&self) -> u32 {
self._remote_domain()
}
async fn message_status(&self, leaf: H256) -> Result<MessageStatus, ChainCommunicationError> {
self._message_status(leaf)
}
fn contract_address(&self) -> Address {
self._contract_address()
}
}
impl HyperlaneChain for MockInboxContract {
fn chain_name(&self) -> &str {
self._chain_name()
}
fn local_domain(&self) -> u32 {
self._local_domain()
}
}
impl HyperlaneContract for MockInboxContract {
fn address(&self) -> H256 {
self._address()
}
}
#[async_trait]
impl HyperlaneCommon for MockInboxContract {
async fn validator_manager(&self) -> Result<H256, ChainCommunicationError> {
self._validator_manager()
}
}

@ -1,111 +0,0 @@
#![allow(non_snake_case)]
use async_trait::async_trait;
use ethers::core::types::H256;
use mockall::*;
use hyperlane_core::*;
mock! {
pub OutboxContract {
// Outbox
pub fn _address(&self) -> H256 {}
pub fn _local_domain(&self) -> u32 {}
pub fn _domain_hash(&self) -> H256 {}
pub fn _raw_message_by_leaf(
&self,
leaf: H256,
) -> Result<Option<RawCommittedMessage>, ChainCommunicationError> {}
pub fn _leaf_by_tree_index(
&self,
tree_index: usize,
) -> Result<Option<H256>, ChainCommunicationError> {}
pub fn _dispatch(&self, message: &Message) -> Result<TxOutcome, ChainCommunicationError> {}
pub fn _count(&self) -> Result<u32, ChainCommunicationError> {}
pub fn _cache_checkpoint(&self) -> Result<TxOutcome, ChainCommunicationError> {}
pub fn _latest_cached_root(&self) -> Result<H256, ChainCommunicationError> {}
pub fn _latest_cached_checkpoint(&self) -> Result<Checkpoint, ChainCommunicationError> {}
pub fn _latest_checkpoint(&self, maybe_lag: Option<u64>) -> Result<Checkpoint, ChainCommunicationError> {}
// HyperlaneCommon
pub fn _validator_manager(&self) -> Result<H256, ChainCommunicationError> {}
pub fn _state(&self) -> Result<OutboxState, ChainCommunicationError> {}
// HyperlaneContract
pub fn _chain_name(&self) -> &str {}
}
}
impl std::fmt::Debug for MockOutboxContract {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "MockOutboxContract")
}
}
#[async_trait]
impl Outbox for MockOutboxContract {
async fn state(&self) -> Result<OutboxState, ChainCommunicationError> {
self._state()
}
async fn count(&self) -> Result<u32, ChainCommunicationError> {
self._count()
}
async fn dispatch(&self, message: &Message) -> Result<TxOutcome, ChainCommunicationError> {
self._dispatch(message)
}
async fn cache_checkpoint(&self) -> Result<TxOutcome, ChainCommunicationError> {
self._cache_checkpoint()
}
async fn latest_cached_root(&self) -> Result<H256, ChainCommunicationError> {
self._latest_cached_root()
}
async fn latest_cached_checkpoint(&self) -> Result<Checkpoint, ChainCommunicationError> {
self._latest_cached_checkpoint()
}
async fn latest_checkpoint(
&self,
maybe_lag: Option<u64>,
) -> Result<Checkpoint, ChainCommunicationError> {
self._latest_checkpoint(maybe_lag)
}
}
impl HyperlaneChain for MockOutboxContract {
fn chain_name(&self) -> &str {
self._chain_name()
}
fn local_domain(&self) -> u32 {
self._local_domain()
}
}
impl HyperlaneContract for MockOutboxContract {
fn address(&self) -> H256 {
self._address()
}
}
#[async_trait]
impl HyperlaneCommon for MockOutboxContract {
async fn validator_manager(&self) -> Result<H256, ChainCommunicationError> {
self._validator_manager()
}
}
Loading…
Cancel
Save