From 1e43076272e9814ef5735d26ae63c14cedfdc5d2 Mon Sep 17 00:00:00 2001 From: "Mantas M." Date: Wed, 20 Nov 2024 11:13:04 +0100 Subject: [PATCH] feat(fuelvm-integration): reorg logic --- rust/main/agents/relayer/src/relayer.rs | 1 + rust/main/agents/validator/src/validator.rs | 1 + .../abis/MerkleTreeHook.abi.json | 2 +- .../main/chains/hyperlane-fuel/src/mailbox.rs | 7 +---- .../hyperlane-fuel/src/merkle_tree_hook.rs | 30 +++---------------- rust/main/config/mainnet_config.json | 2 +- rust/main/config/testnet_config.json | 2 +- rust/main/hyperlane-base/src/settings/base.rs | 17 ++++++++++- 8 files changed, 26 insertions(+), 36 deletions(-) diff --git a/rust/main/agents/relayer/src/relayer.rs b/rust/main/agents/relayer/src/relayer.rs index 1ac619792..d612c1639 100644 --- a/rust/main/agents/relayer/src/relayer.rs +++ b/rust/main/agents/relayer/src/relayer.rs @@ -135,6 +135,7 @@ impl BaseAgent for Relayer { .map(|origin| (origin.clone(), HyperlaneRocksDB::new(origin, db.clone()))) .collect::>(); + settings.check_fuel_reorg(); let mailboxes = settings .build_mailboxes(settings.destination_chains.iter(), &core_metrics) .await?; diff --git a/rust/main/agents/validator/src/validator.rs b/rust/main/agents/validator/src/validator.rs index 2d09bd93f..704d6767e 100644 --- a/rust/main/agents/validator/src/validator.rs +++ b/rust/main/agents/validator/src/validator.rs @@ -76,6 +76,7 @@ impl BaseAgent for Validator { // Intentionally using hyperlane_ethereum for the validator's signer let (signer_instance, signer) = SingletonSigner::new(settings.validator.build().await?); + settings.check_fuel_reorg(); let core = settings.build_hyperlane_core(metrics.clone()); let checkpoint_syncer = settings .checkpoint_syncer diff --git a/rust/main/chains/hyperlane-fuel/abis/MerkleTreeHook.abi.json b/rust/main/chains/hyperlane-fuel/abis/MerkleTreeHook.abi.json index d7cf271c9..7f123f9b3 100644 --- a/rust/main/chains/hyperlane-fuel/abis/MerkleTreeHook.abi.json +++ b/rust/main/chains/hyperlane-fuel/abis/MerkleTreeHook.abi.json @@ -353,7 +353,7 @@ { "name": "doc-comment", "arguments": [ - " Gets the stored count of the MerkleTree library." + " Gets the stored count of the MerkleTree." ] }, { diff --git a/rust/main/chains/hyperlane-fuel/src/mailbox.rs b/rust/main/chains/hyperlane-fuel/src/mailbox.rs index d164788cc..ebf1ca391 100644 --- a/rust/main/chains/hyperlane-fuel/src/mailbox.rs +++ b/rust/main/chains/hyperlane-fuel/src/mailbox.rs @@ -21,7 +21,6 @@ use std::{ fmt::{Debug, Formatter}, ops::RangeInclusive, }; - use tracing::{instrument, warn}; const GAS_ESTIMATE_MULTIPLIER: f64 = 1.3; @@ -78,11 +77,7 @@ impl Debug for FuelMailbox { impl Mailbox for FuelMailbox { #[instrument(level = "debug", err, ret, skip(self))] #[allow(clippy::blocks_in_conditions)] // TODO: `rustc` 1.80.1 clippy issue - async fn count(&self, reorg_period: &ReorgPeriod) -> ChainResult { - assert!( - reorg_period.is_none(), - "Fuel does not support querying point-in-time" - ); + async fn count(&self, _reorg_period: &ReorgPeriod) -> ChainResult { self.contract .methods() .nonce() diff --git a/rust/main/chains/hyperlane-fuel/src/merkle_tree_hook.rs b/rust/main/chains/hyperlane-fuel/src/merkle_tree_hook.rs index 44214abb3..11b2722b6 100644 --- a/rust/main/chains/hyperlane-fuel/src/merkle_tree_hook.rs +++ b/rust/main/chains/hyperlane-fuel/src/merkle_tree_hook.rs @@ -17,10 +17,7 @@ use hyperlane_core::{ }; use std::ops::RangeInclusive; -/// Smart contract level enforced finality -const ENFORCED_FINALITY: u8 = 1; - -/// A reference to a AggregationIsm contract on some Fuel chain +/// A reference to a MerkleTreeHook contract on some Fuel chain #[derive(Debug)] pub struct FuelMerkleTreeHook { contract: MerkleTreeHookContract, @@ -46,19 +43,6 @@ impl FuelMerkleTreeHook { provider: fuel_provider, }) } - - /// Asserts the lag - /// The lag or re-org of FuelVM should be set to 1, as it is the soft finality - /// Also, since we cannot query point in time, the lag is built into the contract code - fn assert_lag(&self, reorg_period: &ReorgPeriod) { - assert!( - reorg_period - .as_blocks() - .is_ok_and(|reorg| reorg == ENFORCED_FINALITY as u32), - "FuelVM lag should always be {:?}", - ENFORCED_FINALITY - ); - } } impl HyperlaneContract for FuelMerkleTreeHook { @@ -79,9 +63,7 @@ impl HyperlaneChain for FuelMerkleTreeHook { #[async_trait] impl MerkleTreeHook for FuelMerkleTreeHook { - async fn tree(&self, reorg_period: &ReorgPeriod) -> ChainResult { - self.assert_lag(reorg_period); - + async fn tree(&self, _reorg_period: &ReorgPeriod) -> ChainResult { self.contract .methods() .tree() @@ -97,9 +79,7 @@ impl MerkleTreeHook for FuelMerkleTreeHook { }) } - async fn count(&self, reorg_period: &ReorgPeriod) -> ChainResult { - self.assert_lag(reorg_period); - + async fn count(&self, _reorg_period: &ReorgPeriod) -> ChainResult { self.contract .methods() .count() @@ -109,9 +89,7 @@ impl MerkleTreeHook for FuelMerkleTreeHook { .map(|res| res.value) } - async fn latest_checkpoint(&self, reorg_period: &ReorgPeriod) -> ChainResult { - self.assert_lag(reorg_period); - + async fn latest_checkpoint(&self, _reorg_period: &ReorgPeriod) -> ChainResult { self.contract .methods() .latest_checkpoint() diff --git a/rust/main/config/mainnet_config.json b/rust/main/config/mainnet_config.json index 9fb01989b..b1aa58cb3 100644 --- a/rust/main/config/mainnet_config.json +++ b/rust/main/config/mainnet_config.json @@ -2731,7 +2731,7 @@ "blocks": { "confirmations": 1, "estimateBlockTime": 1, - "reorgPeriod": 1 + "reorgPeriod": 0 }, "chainId": 1717982311, "deployer": { diff --git a/rust/main/config/testnet_config.json b/rust/main/config/testnet_config.json index 0f85b797c..25761985d 100644 --- a/rust/main/config/testnet_config.json +++ b/rust/main/config/testnet_config.json @@ -449,7 +449,7 @@ "blocks": { "confirmations": 1, "estimateBlockTime": 1, - "reorgPeriod": 1 + "reorgPeriod": 0 }, "chainId": 1717982312, "deployer": { diff --git a/rust/main/hyperlane-base/src/settings/base.rs b/rust/main/hyperlane-base/src/settings/base.rs index 6757a545e..32e882378 100644 --- a/rust/main/hyperlane-base/src/settings/base.rs +++ b/rust/main/hyperlane-base/src/settings/base.rs @@ -3,10 +3,11 @@ use std::{collections::HashMap, fmt::Debug, hash::Hash, sync::Arc}; use eyre::{eyre, Context, Result}; use futures_util::future::try_join_all; use hyperlane_core::{ - HyperlaneChain, HyperlaneDomain, HyperlaneLogStore, HyperlaneProvider, + HyperlaneChain, HyperlaneDomain, HyperlaneDomainProtocol, HyperlaneLogStore, HyperlaneProvider, HyperlaneSequenceAwareIndexerStoreReader, HyperlaneWatermarkedLogStore, InterchainGasPaymaster, Mailbox, MerkleTreeHook, MultisigIsm, SequenceAwareIndexer, ValidatorAnnounce, H256, }; +use tracing::warn; use crate::{ cursors::{CursorType, Indexable}, @@ -81,6 +82,20 @@ impl Settings { .ok_or_else(|| eyre!("No chain setup found for {domain}")) } + /// Check and warn if reorg period is set for FuelVM domains. + pub fn check_fuel_reorg(&self) { + self.chains.values().into_iter().for_each(|conf| { + if conf.domain.domain_protocol() == HyperlaneDomainProtocol::Fuel { + if !conf.reorg_period.is_none() { + warn!( + "Reorg period is set for fuel domain {:?}. FuelVM chains are implemented with instant finality", + conf.domain + ); + } + } + }); + } + /// Try to get the domain for a given chain by name. pub fn lookup_domain(&self, chain_name: &str) -> Result { self.chains