Skip to content

Commit

Permalink
WIP: run locally
Browse files Browse the repository at this point in the history
  • Loading branch information
NOOMA-42 committed Dec 4, 2024
1 parent 2363e07 commit a9bf645
Show file tree
Hide file tree
Showing 11 changed files with 238 additions and 61 deletions.
2 changes: 1 addition & 1 deletion rust/main/agents/relayer/src/msg/metadata/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ impl BaseMetadataBuilder {
}

match config
.build(None, self.origin_chain_setup.clone(), self.metrics.clone())
.build(Some(&self.origin_chain_setup), Some(&self.metrics), None)
.await
{
Ok(checkpoint_syncer) => {
Expand Down
5 changes: 2 additions & 3 deletions rust/main/agents/validator/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,10 @@ fn parse_checkpoint_syncer(syncer: ValueParser) -> ConfigResult<CheckpointSyncer
.chain(&mut err)
.get_key("contractAddress")
.parse_address_hash()
.end()
.map(str::to_owned);
.end();
cfg_unwrap_all!(&syncer.cwp, err: [chain_name, contract_address]);
err.into_result(CheckpointSyncerConf::OnChain {
chain_name: chain_name.unwrap().to_string(),
chain_name: chain_name.to_string(),
contract_address,
})
}
Expand Down
12 changes: 7 additions & 5 deletions rust/main/agents/validator/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,14 @@ impl BaseAgent for Validator {
let checkpoint_syncer = settings
.checkpoint_syncer
.build(
Some(
&settings
.chain_setup(&settings.origin_chain)
.unwrap()
.clone(),
),
Some(&metrics),
None,
settings
.chain_setup(&settings.origin_chain)
.unwrap()
.clone(),
&metrics,
)
.await?
.into();
Expand Down
51 changes: 18 additions & 33 deletions rust/main/chains/hyperlane-ethereum/src/contracts/checkpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ impl HyperlaneAbi for EthereumCheckpointStorageAbi {
}
}

/* TODO: Add tests for checkpoint storage
#[cfg(test)]
mod test {
use std::{str::FromStr, sync::Arc};
Expand All @@ -228,19 +227,18 @@ mod test {
};

use hyperlane_core::{
ContractLocator, HyperlaneDomain, HyperlaneMessage, KnownHyperlaneDomain, Mailbox,
TxCostEstimate, H160, H256, U256,
ContractLocator, HyperlaneDomain, KnownHyperlaneDomain, TxCostEstimate, H160, H256, U256,
};

use crate::{contracts::EthereumMailbox, ConnectionConf, RpcConnectionConf};
use crate::{contracts::EthereumCheckpointStorage, ConnectionConf, RpcConnectionConf};

/// An amount of gas to add to the estimated gas
const GAS_ESTIMATE_BUFFER: u32 = 75_000;

fn get_test_mailbox(
fn get_test_checkpoint_storage(
domain: HyperlaneDomain,
) -> (
EthereumMailbox<Provider<Arc<MockProvider>>>,
EthereumCheckpointStorage<Provider<Arc<MockProvider>>>,
Arc<MockProvider>,
) {
let mock_provider = Arc::new(MockProvider::new());
Expand All @@ -253,7 +251,7 @@ mod test {
operation_batch: Default::default(),
};

let mailbox = EthereumMailbox::new(
let storage = EthereumCheckpointStorage::new(
provider.clone(),
&connection_conf,
&ContractLocator {
Expand All @@ -262,22 +260,19 @@ mod test {
address: H256::default(),
},
);
(mailbox, mock_provider)
(storage, mock_provider)
}

#[tokio::test]
async fn test_process_estimate_costs_sets_l2_gas_limit_for_arbitrum() {
// An Arbitrum Nitro chain
let (mailbox, mock_provider) =
get_test_mailbox(HyperlaneDomain::Known(KnownHyperlaneDomain::PlumeTestnet));
let (storage, mock_provider) =
get_test_checkpoint_storage(HyperlaneDomain::Known(KnownHyperlaneDomain::PlumeTestnet));

let message = HyperlaneMessage::default();
let metadata: Vec<u8> = vec![];
assert!(mailbox.arbitrum_node_interface.is_some());
assert!(storage.arbitrum_node_interface.is_some());
// Confirm `H160::from_low_u64_ne(0xC8)` does what's expected
assert_eq!(
H160::from(mailbox.arbitrum_node_interface.as_ref().unwrap().address()),
H160::from(storage.arbitrum_node_interface.as_ref().unwrap().address()),
H160::from_str("0x00000000000000000000000000000000000000C8").unwrap(),
);

Expand Down Expand Up @@ -308,31 +303,25 @@ mod test {
let gas_limit = U256::from(1000000u32);
mock_provider.push(gas_limit).unwrap();

let tx_cost_estimate = mailbox
.process_estimate_costs(&message, &metadata)
.await
.unwrap();
let tx_cost_estimate = storage.latest_index(None).await.unwrap();

// The TxCostEstimate's gas limit includes the buffer
let estimated_gas_limit = gas_limit.saturating_add(GAS_ESTIMATE_BUFFER.into());

assert_eq!(
/* assert_eq!(
tx_cost_estimate,
TxCostEstimate {
gas_limit: estimated_gas_limit,
gas_price: gas_price.try_into().unwrap(),
l2_gas_limit: Some(l2_gas_limit),
},
);
); */
}

#[tokio::test]
async fn test_tx_gas_limit_caps_at_block_gas_limit() {
let (mailbox, mock_provider) =
get_test_mailbox(HyperlaneDomain::Known(KnownHyperlaneDomain::Ethereum));
let message = HyperlaneMessage::default();
let metadata: Vec<u8> = vec![];
let (storage, mock_provider) =
get_test_checkpoint_storage(HyperlaneDomain::Known(KnownHyperlaneDomain::Ethereum));

// The MockProvider responses we push are processed in LIFO
// order, so we start with the final RPCs and work toward the first
Expand All @@ -358,20 +347,16 @@ mod test {
let gas_limit = U256::from(1000000u32);
mock_provider.push(gas_limit).unwrap();

let tx_cost_estimate = mailbox
.process_estimate_costs(&message, &metadata)
.await
.unwrap();
let tx_cost_estimate = storage.latest_index(None).await.unwrap();

assert_eq!(
/* assert_eq!(
tx_cost_estimate,
TxCostEstimate {
// The block gas limit is the cap
gas_limit: latest_block_gas_limit,
gas_price: gas_price.try_into().unwrap(),
l2_gas_limit: None,
},
);
); */
}
}
*/
188 changes: 188 additions & 0 deletions rust/main/config/testnet_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,194 @@
"index": {
"from": 1921514
}
},
"test1": {
"blockExplorers": [
{
"apiKey": "fakekey",
"apiUrl": "https://api.etherscan.io/api",
"family": "etherscan",
"name": "Etherscan",
"url": "https://etherscan.io"
}
],
"blocks": {
"confirmations": 1,
"estimateBlockTime": 3,
"reorgPeriod": 0
},
"chainId": 9913371,
"displayName": "Test 1",
"domainId": 9913371,
"isTestnet": true,
"name": "test1",
"nativeToken": {
"decimals": 18,
"name": "Ether",
"symbol": "ETH"
},
"protocol": "ethereum",
"rpcUrls": [
{
"http": "http://127.0.0.1:8545"
}
],
"domainRoutingIsm": "0xb0279Db6a2F1E01fbC8483FCCef0Be2bC6299cC3",
"merkleTreeHook": "0x4826533B4897376654Bb4d4AD88B7faFD0C98528",
"proxyAdmin": "0xc5a5C42992dECbae36851359345FE25997F5C42d",
"storageGasOracle": "0x0E801D84Fa97b50751Dbf25036d067dCf18858bF",
"interchainGasPaymaster": "0x5eb3Bc0a489C5A8288765d2336659EbCA68FCd00",
"aggregationHook": "0x7F54A0734c5B443E5B04cc26B54bb8ecE0455785",
"fallbackRoutingHook": "0x99bbA657f2BbC93c02D617f8bA121cB8Fc104Acf",
"protocolFee": "0x1291Be112d480055DaFd8a610b7d1e203891C274",
"testRecipient": "0xCD8a1C3ba11CF5ECfa6267617243239504a98d90",
"mailbox": "0xE6E340D132b5f46d1e472DebcD681B2aBc16e57E",
"validatorAnnounce": "0xb7278A61aa25c888815aFC32Ad3cC52fF24fE575",
"interchainSecurityModule": "0xb0279Db6a2F1E01fbC8483FCCef0Be2bC6299cC3",
"index": {
"from": 30
}
},
"test2": {
"blockExplorers": [
{
"apiKey": "fakekey",
"apiUrl": "https://api.etherscan.io/api",
"family": "etherscan",
"name": "Etherscan",
"url": "https://etherscan.io"
}
],
"blocks": {
"confirmations": 1,
"estimateBlockTime": 3,
"reorgPeriod": 1
},
"chainId": 9913372,
"displayName": "Test 2",
"domainId": 9913372,
"isTestnet": true,
"name": "test2",
"nativeToken": {
"decimals": 18,
"name": "Ether",
"symbol": "ETH"
},
"protocol": "ethereum",
"rpcUrls": [
{
"http": "http://127.0.0.1:8545"
}
],
"domainRoutingIsm": "0x3Ca8f9C04c7e3E1624Ac2008F92f6F366A869444",
"merkleTreeHook": "0x04C89607413713Ec9775E14b954286519d836FEf",
"proxyAdmin": "0x2bdCC0de6bE1f7D2ee689a0342D76F52E8EFABa3",
"storageGasOracle": "0x21dF544947ba3E8b3c32561399E88B52Dc8b2823",
"interchainGasPaymaster": "0xDC11f7E700A4c898AE5CAddB1082cFfa76512aDD",
"aggregationHook": "0x5f07F66a6c12BAE727A0e0C84c2f83Ef3c83b44c",
"fallbackRoutingHook": "0x4C4a2f8c81640e47606d3fd77B353E87Ba015584",
"protocolFee": "0x0355B7B8cb128fA5692729Ab3AAa199C1753f726",
"testRecipient": "0x172076E0166D1F9Cc711C77Adf8488051744980C",
"mailbox": "0x7bc06c482DEAd17c0e297aFbC32f6e63d3846650",
"validatorAnnounce": "0xf4B146FbA71F41E0592668ffbF264F1D186b2Ca8",
"interchainSecurityModule": "0x3Ca8f9C04c7e3E1624Ac2008F92f6F366A869444",
"index": {
"from": 57
}
},
"test3": {
"blockExplorers": [
{
"apiKey": "fakekey",
"apiUrl": "https://api.etherscan.io/api",
"family": "etherscan",
"name": "Etherscan",
"url": "https://etherscan.io"
}
],
"blocks": {
"confirmations": 1,
"estimateBlockTime": 3,
"reorgPeriod": 2
},
"chainId": 9913373,
"displayName": "Test 3",
"domainId": 9913373,
"isTestnet": true,
"name": "test3",
"nativeToken": {
"decimals": 18,
"name": "Ether",
"symbol": "ETH"
},
"protocol": "ethereum",
"rpcUrls": [
{
"http": "http://127.0.0.1:8545"
}
],
"domainRoutingIsm": "0xa12fFA0B9f159BB4C54bce579611927Addc51610",
"merkleTreeHook": "0xA4899D35897033b927acFCf422bc745916139776",
"proxyAdmin": "0xBEc49fA140aCaA83533fB00A2BB19bDdd0290f25",
"storageGasOracle": "0xAA292E8611aDF267e563f334Ee42320aC96D0463",
"interchainGasPaymaster": "0xe8D2A1E88c91DCd5433208d4152Cc4F399a7e91d",
"aggregationHook": "0xd5BA21a5bDE25af311a900191c52ce9Fc8Ab9b8d",
"fallbackRoutingHook": "0xf953b3A269d80e3eB0F2947630Da976B896A8C5b",
"protocolFee": "0xCace1b78160AE76398F486c8a18044da0d66d86D",
"testRecipient": "0xc0F115A19107322cFBf1cDBC7ea011C19EbDB4F8",
"mailbox": "0x2B0d36FACD61B71CC05ab8F3D2355ec3631C0dd5",
"validatorAnnounce": "0xF8e31cb472bc70500f08Cd84917E5A1912Ec8397",
"interchainSecurityModule": "0xa12fFA0B9f159BB4C54bce579611927Addc51610",
"index": {
"from": 84
}
},
"test4": {
"blockExplorers": [
{
"apiKey": "fakekey",
"apiUrl": "https://api.etherscan.io/api",
"family": "etherscan",
"name": "Etherscan",
"url": "https://etherscan.io"
}
],
"blocks": {
"confirmations": 1,
"estimateBlockTime": 3,
"reorgPeriod": 0
},
"chainId": 31337,
"displayName": "Test 4",
"domainId": 31337,
"isTestnet": true,
"name": "test4",
"nativeToken": {
"decimals": 18,
"name": "Ether",
"symbol": "ETH"
},
"protocol": "ethereum",
"rpcUrls": [
{
"http": "http://127.0.0.1:8545"
}
],
"domainRoutingIsm": "0x532B02BD614Fd18aEE45603d02866cFb77575CB3",
"merkleTreeHook": "0xE3011A37A904aB90C8881a99BD1F6E21401f1522",
"proxyAdmin": "0x34B40BA116d5Dec75548a9e9A8f15411461E8c70",
"storageGasOracle": "0x457cCf29090fe5A24c19c1bc95F492168C0EaFdb",
"interchainGasPaymaster": "0x5fc748f1FEb28d7b76fa1c6B07D8ba2d5535177c",
"aggregationHook": "0xfD4Ab5938aAcE9B094cc3B298d18be83E170B2fc",
"fallbackRoutingHook": "0x1f10F3Ba7ACB61b2F50B9d6DdCf91a6f787C0E82",
"protocolFee": "0x8A93d247134d91e0de6f96547cB0204e5BE8e5D8",
"testRecipient": "0xd6e1afe5cA8D00A2EFC01B89997abE2De47fdfAf",
"mailbox": "0x07882Ae1ecB7429a84f1D53048d35c4bB2056877",
"validatorAnnounce": "0xF32D39ff9f6Aa7a7A64d7a4F00a54826Ef791a55",
"interchainSecurityModule": "0x532B02BD614Fd18aEE45603d02866cFb77575CB3",
"index": {
"from": 111
}
}
},
"defaultRpcConsensusType": "fallback"
Expand Down
1 change: 1 addition & 0 deletions rust/main/hyperlane-base/src/settings/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ impl Settings {
.collect()
}

/// Build an onchain checkpoint storage
pub async fn build_onchain_checkpoint_storage(
&self,
checkpoint_address: H256,
Expand Down
5 changes: 4 additions & 1 deletion rust/main/hyperlane-base/src/settings/checkpoint_syncer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ pub enum CheckpointSyncerConf {
/// `gcloud auth application-default login`
user_secrets: Option<String>,
},
/// A checkpoint syncer on an onchain storage contract
OnChain {
/// The name of the chain
chain_name: String,
/// The contract address of the checkpoint storage contract
contract_address: H256,
},
}
Expand Down Expand Up @@ -118,9 +121,9 @@ impl CheckpointSyncerConf {
/// Turn conf info a Checkpoint Syncer
pub async fn build(
&self,
latest_index_gauge: Option<IntGauge>,
chain_setup: Option<&ChainConf>,
metrics: Option<&CoreMetrics>,
latest_index_gauge: Option<IntGauge>,
) -> Result<Box<dyn CheckpointSyncer>, Report> {
Ok(match self {
CheckpointSyncerConf::LocalStorage { path } => {
Expand Down
Loading

0 comments on commit a9bf645

Please sign in to comment.