More post v2 cleanup (#1388)

* Removed code files that are not part of project anymore

* Removed unused metric

* Refactor some obj names

* Update string constants for outbox and inbox

* Update comments

* Changes for PR review

* Fix typo
pull/1403/head
Mattie Conover 2 years ago committed by GitHub
parent f814286998
commit de4ed8bf2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      rust/agents/relayer/src/main.rs
  2. 2
      rust/agents/relayer/src/msg/gelato_submitter/sponsored_call_op.rs
  3. 2
      rust/agents/relayer/src/msg/processor.rs
  4. 19
      rust/agents/relayer/src/msg/serial_submitter.rs
  5. 4
      rust/agents/relayer/src/relayer.rs
  6. 2
      rust/agents/scraper/migration/src/m20221122_000004_create_table_message.rs
  7. 2
      rust/agents/scraper/src/chain_scraper/sync.rs
  8. 4
      rust/agents/scraper/src/db/message.rs
  9. 2
      rust/agents/validator/src/main.rs
  10. 240
      rust/chains/hyperlane-ethereum/src/inbox.rs
  11. 2
      rust/chains/hyperlane-ethereum/src/interchain_gas.rs
  12. 2
      rust/chains/hyperlane-ethereum/src/lib.rs
  13. 2
      rust/chains/hyperlane-ethereum/src/mailbox.rs
  14. 2
      rust/ethers-prometheus/src/middleware/mod.rs
  15. 8
      rust/hyperlane-base/src/contract_sync/mailbox.rs
  16. 4
      rust/hyperlane-base/src/contract_sync/schema.rs
  17. 2
      rust/hyperlane-base/src/lib.rs
  18. 28
      rust/hyperlane-base/src/metrics/core.rs
  19. 10
      rust/hyperlane-base/src/settings/chains.rs
  20. 8
      rust/hyperlane-base/src/settings/mod.rs
  21. 2
      rust/hyperlane-core/src/db/mod.rs
  22. 2
      rust/hyperlane-core/src/lib.rs
  23. 7
      rust/hyperlane-core/src/traits/indexer.rs
  24. 8
      rust/hyperlane-test/src/test_utils.rs
  25. 7
      rust/utils/run-locally/src/main.rs

@ -1,7 +1,8 @@
//! The relayer forwards signed checkpoints from the outbox to chain to inboxes
//! The relayer forwards signed checkpoints from the current chain's mailbox to
//! the other chains' mailboxes
//!
//! At a regular interval, the relayer polls Outbox for signed checkpoints and
//! submits them as checkpoints on the inbox.
//! At a regular interval, the relayer polls the current chain's mailbox for
//! signed checkpoints and submits them as checkpoints on the remote mailbox.
#![forbid(unsafe_code)]
#![warn(missing_docs)]

@ -163,7 +163,7 @@ impl SponsoredCallOp {
loop {
sleep(self.opts.poll_interval).await;
// Check if the message has been processed. Checking with the Inbox directly
// Check if the message has been processed. Checking with the Mailbox directly
// is the best source of truth, and is the only way in which a message can be
// marked as processed.
if let Ok(true) = self.message_delivered().await {

@ -118,7 +118,7 @@ impl MessageProcessor {
return Ok(());
};
// Skip if for different inbox.
// Skip if for different domain.
if message.destination != self.destination_mailbox.domain() {
debug!(
id=?message.id(),

@ -165,7 +165,7 @@ impl SerialSubmitter {
}
/// Tick represents a single round of scheduling wherein we will process each queue and
/// await at most one message submission. It is extracted from the main loop to allow for
/// await at most one message submission. It is extracted from the main loop to allow for
/// testing the state of the scheduler at particular points without having to worry about
/// concurrent access.
async fn tick(&mut self) -> Result<()> {
@ -185,7 +185,7 @@ impl SerialSubmitter {
}
// TODO(webbhorn): Scan verification queue, dropping messages that have been confirmed
// processed by the inbox indexer observing it. For any still-unverified messages that
// processed by the mailbox indexer observing it. For any still-unverified messages that
// have been in the verification queue for > threshold_time, move them back to the wait
// queue for further processing.
@ -237,16 +237,15 @@ impl SerialSubmitter {
}
/// Returns the message's status. If the message is processed, either by a transaction
/// in this fn or by a view call to the Inbox contract discovering the message has already
/// been processed, Ok(MessageStatus::Processed) is returned. If this message is unable to
/// in this fn or by a view call to the Mailbox contract discovering the message has already
/// been processed, Ok(true) is returned. If this message is unable to
/// be processed, either due to failed gas estimation or an insufficient gas payment,
/// Ok(MessageStatus::None) is returned.
/// Ok(false) is returned.
#[instrument(skip(self, msg), fields(msg_nonce=msg.message.nonce))]
async fn process_message(&self, msg: &SubmitMessageArgs) -> Result<bool> {
// If the message has already been processed according to message_status call on
// inbox, e.g. due to another relayer having already processed, then mark it as
// already-processed, and move on to the next tick.
// TODO(webbhorn): Make this robust to re-orgs on inbox.
// If the message has already been processed, e.g. due to another relayer having already
// processed, then mark it as already-processed, and move on to the next tick.
// TODO(webbhorn): Make this robust to re-orgs on mailbox.
if self.mailbox.delivered(msg.message.id()).await? {
info!("Message already processed");
return Ok(true);
@ -297,7 +296,7 @@ impl SerialSubmitter {
.await;
match process_result {
// TODO(trevor): Instead of immediately marking as processed, move to a verification
// queue, which will wait for finality and indexing by the inbox indexer and then mark
// queue, which will wait for finality and indexing by the mailbox indexer and then mark
// as processed (or eventually retry if no confirmation is ever seen).
// Only mark the message as processed if the transaction didn't revert.

@ -263,10 +263,10 @@ impl Relayer {
let process_fut = message_processor.spawn();
tokio::spawn(async move {
let res = tokio::try_join!(submit_fut, process_fut)?;
info!(?res, "try_join finished for inbox");
info!(?res, "try_join finished for mailbox");
Ok(())
})
.instrument(info_span!("run inbox"))
.instrument(info_span!("run mailbox"))
}
}

@ -134,7 +134,7 @@ pub enum Message {
Origin,
/// Domain ID of the destination chain
Destination,
/// Nonce of this message in the merkle tree of the outbox
/// Nonce of this message in the merkle tree of the mailbox
Nonce,
/// Address of the message sender on the origin chain (not necessarily the
/// transaction signer)

@ -218,7 +218,7 @@ impl Syncer {
from,
to,
message_count = sorted_messages.len(),
"Filtered any messages already indexed for outbox."
"Filtered any messages already indexed for mailbox"
);
Ok((sorted_messages, deliveries))

@ -55,7 +55,7 @@ impl ScraperDb {
.map(|idx| idx as u32))
}
/// Store deliveries from an inbox into the database (or update an existing
/// Store deliveries from a mailbox into the database (or update an existing
/// one).
#[instrument(skip_all)]
pub async fn store_deliveries(
@ -96,7 +96,7 @@ impl ScraperDb {
Ok(())
}
/// Store messages from an outbox into the database (or update an existing
/// Store messages from a mailbox into the database (or update an existing
/// one).
#[instrument(skip_all)]
pub async fn store_messages(

@ -1,4 +1,4 @@
//! The validator signs Outbox checkpoints that have reached finality.
//! The validator signs Mailbox checkpoints that have reached finality.
#![forbid(unsafe_code)]
#![warn(missing_docs)]

@ -1,240 +0,0 @@
#![allow(clippy::enum_variant_names)]
#![allow(missing_docs)]
use std::collections::HashMap;
use std::fmt::{self, Debug, Display};
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, Address, ChainCommunicationError,
ContractLocator, Inbox, InboxIndexer, Indexer, MessageStatus,
};
use crate::contracts::inbox::{Inbox as EthereumInboxInternal, INBOX_ABI};
use crate::trait_builder::MakeableWithProvider;
impl<M> Display for EthereumInboxInternal<M>
where
M: Middleware,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}
pub struct InboxBuilder {}
#[async_trait]
impl MakeableWithProvider for InboxBuilder {
type Output = Box<dyn Inbox>;
async fn make_with_provider<M: Middleware + 'static>(
&self,
provider: M,
locator: &ContractLocator,
) -> Self::Output {
Box::new(EthereumInbox::new(Arc::new(provider), locator).await)
}
}
pub struct InboxIndexerBuilder {
pub finality_blocks: u32,
}
#[async_trait]
impl MakeableWithProvider for InboxIndexerBuilder {
type Output = Box<dyn InboxIndexer>;
async fn make_with_provider<M: Middleware + 'static>(
&self,
provider: M,
locator: &ContractLocator,
) -> Self::Output {
Box::new(EthereumInboxIndexer::new(
Arc::new(provider),
locator,
self.finality_blocks,
))
}
}
#[derive(Debug)]
pub struct EthereumInboxIndexer<M>
where
M: Middleware,
{
contract: Arc<EthereumInboxInternal<M>>,
provider: Arc<M>,
finality_blocks: u32,
}
impl<M> EthereumInboxIndexer<M>
where
M: Middleware + 'static,
{
pub fn new(provider: Arc<M>, locator: &ContractLocator, finality_blocks: u32) -> Self {
let contract = Arc::new(EthereumInboxInternal::new(
&locator.address,
provider.clone(),
));
Self {
contract,
provider,
finality_blocks,
}
}
}
#[async_trait]
impl<M> Indexer for EthereumInboxIndexer<M>
where
M: Middleware + 'static,
{
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> InboxIndexer for EthereumInboxIndexer<M>
where
M: Middleware + 'static,
{
#[instrument(err, skip(self))]
async fn fetch_processed_messages(
&self,
from: u32,
to: u32,
) -> Result<Vec<(H256, hyperlane_core::LogMeta)>> {
Ok(self
.contract
.process_filter()
.from_block(from)
.to_block(to)
.query_with_meta()
.await?
.into_iter()
.map(|(event, meta)| (H256::from(event.message_hash), meta.into()))
.collect())
}
}
/// A struct that provides access to an Ethereum inbox contract
#[derive(Debug)]
pub struct EthereumInbox<M>
where
M: Middleware,
{
contract: Arc<EthereumInboxInternal<M>>,
remote_domain: u32,
chain_name: String,
local_domain: u32,
}
impl<M> EthereumInbox<M>
where
M: Middleware,
{
/// Create a reference to a inbox at a specific Ethereum address on some
/// chain
pub async fn new(
provider: Arc<M>,
ContractLocator {
chain_name,
domain,
address,
}: &ContractLocator,
) -> Self {
let contract = Arc::new(EthereumInboxInternal::new(address, provider));
let remote_domain = contract
.remote_domain()
.call()
.await
.expect("Failed to get inbox's local_domain");
debug_assert_eq!(
contract
.local_domain()
.call()
.await
.expect("Failed to get inbox's remote_domain"),
*domain
);
Self {
contract,
remote_domain,
local_domain: *domain,
chain_name: chain_name.to_owned(),
}
}
}
impl<M> HyperlaneChain for EthereumInbox<M>
where
M: Middleware + 'static,
{
fn chain_name(&self) -> &str {
&self.chain_name
}
fn local_domain(&self) -> u32 {
self.local_domain
}
}
impl<M> HyperlaneContract for EthereumInbox<M>
where
M: Middleware + 'static,
{
fn address(&self) -> H256 {
self.contract.address().into()
}
}
#[async_trait]
impl<M> HyperlaneCommon for EthereumInbox<M>
where
M: Middleware + 'static,
{
#[tracing::instrument(err)]
async fn validator_manager(&self) -> Result<H256, ChainCommunicationError> {
Ok(self.contract.validator_manager().call().await?.into())
}
}
#[async_trait]
impl<M> Inbox for EthereumInbox<M>
where
M: Middleware + 'static,
{
fn remote_domain(&self) -> u32 {
self.remote_domain
}
#[tracing::instrument(err)]
async fn message_status(&self, leaf: H256) -> Result<MessageStatus, ChainCommunicationError> {
let status = self.contract.messages(leaf.into()).call().await?;
Ok(MessageStatus::try_from(status).expect("Bad status from solidity"))
}
fn contract_address(&self) -> Address {
self.contract.address().into()
}
}
pub struct EthereumInboxAbi;
impl HyperlaneAbi for EthereumInboxAbi {
fn fn_map() -> HashMap<Selector, &'static str> {
super::extract_fn_map(&INBOX_ABI)
}
}

@ -167,7 +167,7 @@ impl<M> EthereumInterchainGasPaymaster<M>
where
M: Middleware + 'static,
{
/// Create a reference to a outbox at a specific Ethereum address on some
/// Create a reference to a mailbox at a specific Ethereum address on some
/// chain
pub fn new(provider: Arc<M>, locator: &ContractLocator) -> Self {
Self {

@ -20,7 +20,7 @@ pub use crate::{interchain_gas::*, mailbox::*, multisig_ism::*, provider::*, tra
#[cfg(not(doctest))]
mod tx;
/// Outbox abi
/// Mailbox abi
#[cfg(not(doctest))]
mod mailbox;

@ -152,7 +152,7 @@ impl MakeableWithProvider for MailboxBuilder {
}
}
/// A reference to an Mailbox contract on some Ethereum chain
/// A reference to a Mailbox contract on some Ethereum chain
#[derive(Debug)]
pub struct EthereumMailbox<M>
where

@ -68,7 +68,7 @@ pub struct WalletInfo {
#[cfg_attr(feature = "serde", serde(tag = "type", rename_all = "camelCase"))]
pub struct ContractInfo {
/// A human-friendly name for the contract. This should be a short string
/// like "inbox".
/// like "mailbox".
pub name: Option<String>,
/// Mapping from function selectors to human readable names.
pub functions: HashMap<Selector, String>,

@ -6,7 +6,7 @@ use hyperlane_core::{
};
use crate::contract_sync::last_message::validate_message_continuity;
use crate::{contract_sync::schema::OutboxContractSyncDB, ContractSync};
use crate::{contract_sync::schema::MailboxContractSyncDB, ContractSync};
const MESSAGES_LABEL: &str = "messages";
@ -244,7 +244,7 @@ mod test {
use hyperlane_test::test_utils;
use crate::contract_sync::mailbox::MOCK_CURSOR;
use crate::contract_sync::schema::OutboxContractSyncDB;
use crate::contract_sync::schema::MailboxContractSyncDB;
use crate::contract_sync::IndexSettings;
use crate::ContractSync;
use crate::{ContractSyncMetrics, CoreMetrics};
@ -387,7 +387,7 @@ mod test {
});
}
let hyperlane_db = HyperlaneDB::new("outbox_1", db);
let hyperlane_db = HyperlaneDB::new("mailbox_1", db);
// Set the latest valid message range start block
hyperlane_db
@ -406,7 +406,7 @@ mod test {
let sync_metrics = ContractSyncMetrics::new(metrics);
let contract_sync = ContractSync::new(
"outbox_1".into(),
"mailbox_1".into(),
hyperlane_db.clone(),
indexer,
IndexSettings {

@ -10,12 +10,12 @@ use hyperlane_core::db::HyperlaneDB;
static LATEST_VALID_MESSAGE_RANGE_START_BLOCK: &str = "latest_valid_message_range_start_block";
static LATEST_INDEXED_GAS_PAYMENT_BLOCK: &str = "latest_indexed_gas_payment_block";
pub(crate) trait OutboxContractSyncDB {
pub(crate) trait MailboxContractSyncDB {
fn store_latest_valid_message_range_start_block(&self, block_num: u32) -> Result<(), DbError>;
fn retrieve_latest_valid_message_range_start_block(&self) -> Option<u32>;
}
impl OutboxContractSyncDB for HyperlaneDB {
impl MailboxContractSyncDB for HyperlaneDB {
fn store_latest_valid_message_range_start_block(&self, block_num: u32) -> Result<(), DbError> {
self.store_encodable("", LATEST_VALID_MESSAGE_RANGE_START_BLOCK, &block_num)
}

@ -2,7 +2,7 @@
//! It has common utils and tools for configuring the app, interacting with the
//! smart contracts, etc.
//!
//! Implementations of the `Outbox` and `Inbox` traits on different chains
//! Implementations of the `Mailbox` traits on different chains
//! ought to live here.
// Forbid unsafe code outside of tests

@ -48,7 +48,6 @@ pub struct CoreMetrics {
messages_processed_count: IntCounterVec,
outbox_state: IntGaugeVec,
latest_checkpoint: IntGaugeVec,
/// Set of metrics that tightly wrap the JsonRpcClient for use with the
@ -146,20 +145,10 @@ impl CoreMetrics {
registry
)?;
let outbox_state = register_int_gauge_vec_with_registry!(
opts!(
namespaced!("outbox_state"),
"Outbox contract state value",
const_labels_ref
),
&["chain"],
registry
)?;
let latest_checkpoint = register_int_gauge_vec_with_registry!(
opts!(
namespaced!("latest_checkpoint"),
"Outbox latest checkpoint",
"Mailbox latest checkpoint",
const_labels_ref
),
&["phase", "chain"],
@ -192,7 +181,6 @@ impl CoreMetrics {
messages_processed_count,
outbox_state,
latest_checkpoint,
json_rpc_client_metrics: OnceCell::new(),
@ -305,7 +293,7 @@ impl CoreMetrics {
/// the nonces are contiguous by origin not remote.
///
/// The following phases are implemented:
/// - `dispatch`: Highest nonce which has been indexed on the outbox
/// - `dispatch`: Highest nonce which has been indexed on the mailbox
/// contract syncer and stored in the relayer DB.
/// - `signed_offchain_checkpoint`: Highest nonce of a checkpoint which is
/// known to have been signed by a quorum of validators.
@ -325,21 +313,11 @@ impl CoreMetrics {
self.validator_checkpoint_index.clone()
}
/// Gauge for reporting the current outbox state. This is either 0 (for
/// UnInitialized), 1 (for Active), or 2 (for Failed). These are from the
/// outbox contract States enum.
///
/// Labels:
/// - `chain`: The chain the outbox is for.
pub fn outbox_state(&self) -> IntGaugeVec {
self.outbox_state.clone()
}
/// Latest message nonce in the validator.
///
/// Phase:
/// - `validator_observed`: When the validator has observed the checkpoint
/// on the outbox contract.
/// on the mailbox contract.
/// - `validator_processed`: When the validator has written this checkpoint.
pub fn latest_checkpoint(&self) -> IntGaugeVec {
self.latest_checkpoint.clone()

@ -53,7 +53,7 @@ pub struct GelatoConf {
pub sponsorapikey: String,
}
/// Addresses for outbox chain contracts
/// Addresses for mailbox chain contracts
#[derive(Clone, Debug, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct CoreContractAddresses {
@ -65,14 +65,14 @@ pub struct CoreContractAddresses {
pub interchain_gas_paymaster: String,
}
/// Outbox indexing settings
/// Indexing settings
#[derive(Debug, Deserialize, Default, Clone)]
#[serde(rename_all = "camelCase")]
pub struct IndexSettings {
/// The height at which to start indexing the Outbox contract
pub from: Option<String>,
/// The number of blocks to query at once at which to start indexing the
/// Outbox contract
/// Mailbox contract
pub chunk: Option<String>,
}
@ -94,8 +94,8 @@ impl IndexSettings {
}
}
/// A chain setup is a domain ID, an address on that chain (where the outbox or
/// inbox is deployed) and details for connecting to the chain API.
/// A chain setup is a domain ID, an address on that chain (where the mailbox is deployed) and
/// details for connecting to the chain API.
#[derive(Clone, Debug, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct ChainSetup {

@ -4,8 +4,8 @@
//!
//! Hyperlane Agents have a shared core, which contains connection info for rpc,
//! relevant contract addresses on each chain, etc. In addition, each agent has
//! agent-specific settings. Be convention, we represent these as a base config
//! per-Outbox contract, and a "partial" config per agent. On bootup, the agent
//! agent-specific settings. By convention above, we represent these as a base config
//! per-Mailbox contract, and a "partial" config per agent. On bootup, the agent
//! loads the configuration, establishes RPC connections, and monitors each
//! configured chain.
//!
@ -41,7 +41,7 @@
//! {
//! "environment": "test",
//! "signers": {},
//! "inboxes": {
//! "chains": {
//! "test2": {
//! "domain": "13372",
//! ...
@ -52,7 +52,7 @@
//! ```
//!
//! and an environment variable is supplied which defines
//! `HYP_BASE_INBOXES_TEST3_DOMAIN=1`, then the `decl_settings` macro in
//! `HYP_BASE_CHAINS_TEST2_DOMAIN=1`, then the `decl_settings` macro in
//! `rust/hyperlane-base/src/macros.rs` will directly override the 'domain'
//! field found in the json config to be `1`, since the fields in the
//! environment variable name describe the path traversal to arrive at this

@ -10,7 +10,7 @@ pub mod iterator;
mod typed_db;
pub use typed_db::*;
/// DB operations tied to specific Outbox
/// DB operations tied to specific Mailbox
mod hyperlane_db;
pub use hyperlane_db::*;

@ -9,7 +9,7 @@
/// Accumulator management
pub mod accumulator;
/// Async Traits for Outboxes & Inboxes for use in applications
/// Async Traits for contract instances for use in applications
mod traits;
use ethers_signers::WalletError;
pub use traits::*;

@ -2,10 +2,7 @@
//! event-data to another entity (e.g. a `ContractSync`). For example, the only
//! way to retrieve data such as the chain's latest block number or a list of
//! checkpoints/messages emitted within a certain block range by calling out to
//! a chain-specific library and provider (e.g. ethers::provider). A
//! chain-specific mailbox or inbox should implement one or both of the Indexer
//! traits (CommonIndexer or MailboxIndexer) to provide an common interface
//! which other entities can retrieve this chain-specific info.
//! a chain-specific library and provider (e.g. ethers::provider).
use std::fmt::Debug;
@ -25,7 +22,7 @@ pub trait Indexer: Send + Sync + Debug {
}
/// Interface for Mailbox contract indexer. Interface for allowing other
/// entities to retrieve chain-specific data from an mailbox.
/// entities to retrieve chain-specific data from a mailbox.
#[async_trait]
#[auto_impl(Box, Arc)]
pub trait MailboxIndexer: Indexer {

@ -39,8 +39,8 @@ mod test {
#[tokio::test]
async fn db_stores_and_retrieves_messages() {
run_test_db(|db| async move {
let outbox_name = "outbox_1".to_owned();
let db = HyperlaneDB::new(outbox_name, db);
let mailbox_name = "mailbox_1".to_owned();
let db = HyperlaneDB::new(mailbox_name, db);
let m = HyperlaneMessage {
nonce: 100,
@ -72,8 +72,8 @@ mod test {
#[tokio::test]
async fn db_stores_and_retrieves_proofs() {
run_test_db(|db| async move {
let outbox_name = "outbox_1".to_owned();
let db = HyperlaneDB::new(outbox_name, db);
let mailbox_name = "mailbox_1".to_owned();
let db = HyperlaneDB::new(mailbox_name, db);
let proof = Proof {
leaf: H256::from_low_u64_be(15),

@ -439,15 +439,16 @@ fn assert_termination_invariants(num_expected_messages_processed: u32) {
"Could not find message_processed phase metric"
);
// The max index is one less than the number delivered messages, since it is an index into the
// outbox merkle tree leafs. Since the metric is parameterized by inbox, and the test
// non-deterministically selects the destination inbox between test2 and test3 for the highest
// mailbox merkle tree leafs. Since the metric is parameterized by mailbox, and the test
// non-deterministically selects the destination mailbox between test2 and test3 for the highest
// message, we take the max over the metric vector.
assert_eq!(
msg_processed_max_index.into_iter().max().unwrap(),
num_expected_messages_processed - 1
);
// Also ensure the counter is as expected (total number of messages), summed across all inboxes.
// Also ensure the counter is as expected (total number of messages), summed across all
// mailboxes.
let msg_processed_count: Vec<_> = ureq::get("http://127.0.0.1:9092/metrics")
.call()
.unwrap()

Loading…
Cancel
Save