From 5fe7ad8b1adcc911cad9e602d8606d83ddc2faaf Mon Sep 17 00:00:00 2001 From: -f Date: Sat, 4 Jan 2025 23:16:40 +0530 Subject: [PATCH 1/9] rm comma --- rust/main/agents/relayer/src/msg/gas_payment/mod.rs | 4 ++++ rust/main/utils/run-locally/src/main.rs | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/rust/main/agents/relayer/src/msg/gas_payment/mod.rs b/rust/main/agents/relayer/src/msg/gas_payment/mod.rs index fa9f40b453..9a144b1cad 100644 --- a/rust/main/agents/relayer/src/msg/gas_payment/mod.rs +++ b/rust/main/agents/relayer/src/msg/gas_payment/mod.rs @@ -127,6 +127,10 @@ impl GasPaymentEnforcer { ?tx_cost_estimate, "Evaluating if message meets gas payment requirement", ); + println!( + "DELOREN policy: {:?}, {:?}, {:?}", + policy, ¤t_payment, ¤t_expenditure + ); return policy .message_meets_gas_payment_requirement( message, diff --git a/rust/main/utils/run-locally/src/main.rs b/rust/main/utils/run-locally/src/main.rs index 4686c15446..a7e03b4094 100644 --- a/rust/main/utils/run-locally/src/main.rs +++ b/rust/main/utils/run-locally/src/main.rs @@ -227,7 +227,7 @@ fn main() -> ExitCode { "GASPAYMENTENFORCEMENT", r#"[{ "type": "minimum", - "payment": "1", + "payment": "1" }]"#, ) .arg( From 04d321c4e6ed1fceea11508831ba23bd720a16b7 Mon Sep 17 00:00:00 2001 From: -f Date: Tue, 7 Jan 2025 14:19:14 +0530 Subject: [PATCH 2/9] set igp config --- .../agents/relayer/src/msg/gas_payment/mod.rs | 2 +- .../src/db/rocks/hyperlane_db.rs | 2 + .../infra/scripts/send-test-messages.ts | 82 +++++++++++++++++-- 3 files changed, 78 insertions(+), 8 deletions(-) diff --git a/rust/main/agents/relayer/src/msg/gas_payment/mod.rs b/rust/main/agents/relayer/src/msg/gas_payment/mod.rs index 9a144b1cad..83ebfbeedb 100644 --- a/rust/main/agents/relayer/src/msg/gas_payment/mod.rs +++ b/rust/main/agents/relayer/src/msg/gas_payment/mod.rs @@ -128,7 +128,7 @@ impl GasPaymentEnforcer { "Evaluating if message meets gas payment requirement", ); println!( - "DELOREN policy: {:?}, {:?}, {:?}", + "DELOREAN policy: {:?}, {:?}, {:?}", policy, ¤t_payment, ¤t_expenditure ); return policy diff --git a/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs b/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs index 76a51bfe3c..5fdddab1fc 100644 --- a/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs +++ b/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs @@ -326,6 +326,8 @@ impl HyperlaneLogStore for HyperlaneRocksDB { &self, payments: &[(Indexed, LogMeta)], ) -> Result { + println!("Geforce, IGP {:?}", payments); + store_and_count_new( self, payments, diff --git a/typescript/infra/scripts/send-test-messages.ts b/typescript/infra/scripts/send-test-messages.ts index d028263982..1973c7dfa9 100644 --- a/typescript/infra/scripts/send-test-messages.ts +++ b/typescript/infra/scripts/send-test-messages.ts @@ -1,9 +1,16 @@ import { Provider } from '@ethersproject/providers'; -import { Wallet } from 'ethers'; +import { BigNumber, Wallet } from 'ethers'; import fs from 'fs'; import yargs from 'yargs'; -import { Mailbox, TestSendReceiver__factory } from '@hyperlane-xyz/core'; +import { + InterchainGasPaymaster, + InterchainGasPaymaster__factory, + Mailbox, + StorageGasOracle, + StorageGasOracle__factory, + TestSendReceiver__factory, +} from '@hyperlane-xyz/core'; import { ChainName, HookType, @@ -11,7 +18,7 @@ import { MultiProvider, TestChainName, } from '@hyperlane-xyz/sdk'; -import { addressToBytes32, sleep } from '@hyperlane-xyz/utils'; +import { addressToBytes32, formatMessage, sleep } from '@hyperlane-xyz/utils'; const ANVIL_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'; @@ -47,6 +54,45 @@ async function setMailboxHook( console.log(`set the ${mailboxHookType} hook on ${local} to ${hook}`); } +async function setIgpConfig( + remoteId: number, + signer: Wallet, + provider: Provider, + mailbox: Mailbox, + addresses: any, + local: ChainName, + defaultHook: HookType, +) { + const storageGasOracleF = new StorageGasOracle__factory( + signer.connect(provider), + ); + const storageGasOracle = await storageGasOracleF.deploy(); + await storageGasOracle.deployTransaction.wait(); + + const oracleConfigs: Array = []; + oracleConfigs.push({ + remoteDomain: remoteId, + tokenExchangeRate: '10000000000', + gasPrice: '1000000000', + }); + await storageGasOracle.setRemoteGasDataConfigs(oracleConfigs); + + const gasParamsToSet: InterchainGasPaymaster.GasParamStruct[] = []; + gasParamsToSet.push({ + remoteDomain: remoteId, + config: { + gasOracle: storageGasOracle.address, + gasOverhead: 1000000, + }, + }); + + const igpHook = InterchainGasPaymaster__factory.connect( + addresses[local][defaultHook], + signer.connect(provider), + ); + await igpHook.setDestinationGasConfigs(gasParamsToSet); +} + const chainSummary = async (core: HyperlaneCore, chain: ChainName) => { const coreContracts = core.getContracts(chain); const mailbox = coreContracts.mailbox; @@ -157,15 +203,37 @@ async function main() { MailboxHookType.REQUIRED, requiredHook, ); + + if (!defaultHook || defaultHook === HookType.INTERCHAIN_GAS_PAYMASTER) { + await setIgpConfig( + remoteId, + signer, + provider, + mailbox, + addresses, + local, + defaultHook, + ); + } + + const message = formatMessage( + 1, + 0, + multiProvider.getDomainId(local), + recipient.address, + multiProvider.getDomainId(remote), + recipient.address, + '0x1234', + ); const quote = await mailbox['quoteDispatch(uint32,bytes32,bytes)']( remoteId, addressToBytes32(recipient.address), - '0x1234', + message, ); - await recipient['dispatchToSelf(address,uint32,bytes)']( - mailbox.address, + await mailbox['dispatch(uint32,bytes32,bytes)']( remoteId, - '0x1234', + addressToBytes32(recipient.address), + message, { value: quote, }, From f884bd05b6ab0a6d6be4c6ae23aac5fc4666d100 Mon Sep 17 00:00:00 2001 From: -f Date: Tue, 7 Jan 2025 16:38:26 +0530 Subject: [PATCH 3/9] change logs --- .../main/hyperlane-base/src/db/rocks/hyperlane_db.rs | 12 +++++++++++- typescript/infra/scripts/send-test-messages.ts | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs b/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs index 5fdddab1fc..d58b3937b6 100644 --- a/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs +++ b/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs @@ -326,7 +326,17 @@ impl HyperlaneLogStore for HyperlaneRocksDB { &self, payments: &[(Indexed, LogMeta)], ) -> Result { - println!("Geforce, IGP {:?}", payments); + if payments.len() > 1 { + println!( + "Geforce, IGP for message {:?}", + payments[0].0.inner().message_id + ); + println!( + "Geforce, IGP payment: {:?}(limit {:?})", + payments[1].0.inner().payment, + payments[1].0.inner().gas_amount + ); + } store_and_count_new( self, diff --git a/typescript/infra/scripts/send-test-messages.ts b/typescript/infra/scripts/send-test-messages.ts index 1973c7dfa9..e282d9f082 100644 --- a/typescript/infra/scripts/send-test-messages.ts +++ b/typescript/infra/scripts/send-test-messages.ts @@ -241,7 +241,9 @@ async function main() { console.log( `send to ${recipient.address} on ${remote} via mailbox ${ mailbox.address - } on ${local} with nonce ${(await mailbox.nonce()) - 1}`, + } on ${local} with nonce ${ + (await mailbox.nonce()) - 1 + } and quote ${quote.toString()}`, ); console.log(await chainSummary(core, local)); console.log(await chainSummary(core, remote)); From d5107117a3d0b264143a2efd4b5a7a90e9bdbf4b Mon Sep 17 00:00:00 2001 From: -f Date: Tue, 7 Jan 2025 17:26:48 +0530 Subject: [PATCH 4/9] set for aggregation as default --- .../src/db/rocks/hyperlane_db.rs | 2 +- .../infra/scripts/send-test-messages.ts | 19 +++++++------------ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs b/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs index d58b3937b6..a5c71d86a6 100644 --- a/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs +++ b/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs @@ -326,7 +326,7 @@ impl HyperlaneLogStore for HyperlaneRocksDB { &self, payments: &[(Indexed, LogMeta)], ) -> Result { - if payments.len() > 1 { + if payments.len() > 0 { println!( "Geforce, IGP for message {:?}", payments[0].0.inner().message_id diff --git a/typescript/infra/scripts/send-test-messages.ts b/typescript/infra/scripts/send-test-messages.ts index e282d9f082..6775ac5534 100644 --- a/typescript/infra/scripts/send-test-messages.ts +++ b/typescript/infra/scripts/send-test-messages.ts @@ -61,7 +61,6 @@ async function setIgpConfig( mailbox: Mailbox, addresses: any, local: ChainName, - defaultHook: HookType, ) { const storageGasOracleF = new StorageGasOracle__factory( signer.connect(provider), @@ -87,7 +86,7 @@ async function setIgpConfig( }); const igpHook = InterchainGasPaymaster__factory.connect( - addresses[local][defaultHook], + addresses[local].interchainGasPaymaster, signer.connect(provider), ); await igpHook.setDestinationGasConfigs(gasParamsToSet); @@ -204,16 +203,12 @@ async function main() { requiredHook, ); - if (!defaultHook || defaultHook === HookType.INTERCHAIN_GAS_PAYMASTER) { - await setIgpConfig( - remoteId, - signer, - provider, - mailbox, - addresses, - local, - defaultHook, - ); + if ( + defaultHook === HookType.AGGREGATION || + defaultHook === HookType.INTERCHAIN_GAS_PAYMASTER + ) { + console.log('Setting IGP config for message ...'); + await setIgpConfig(remoteId, signer, provider, mailbox, addresses, local); } const message = formatMessage( From 2ba224bea84cc12dce1a7117964fe8168a0f9532 Mon Sep 17 00:00:00 2001 From: -f Date: Tue, 7 Jan 2025 17:57:37 +0530 Subject: [PATCH 5/9] index out of range --- rust/main/agents/relayer/src/settings/mod.rs | 4 ++++ rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/rust/main/agents/relayer/src/settings/mod.rs b/rust/main/agents/relayer/src/settings/mod.rs index dc4c1e543e..ad7d32a835 100644 --- a/rust/main/agents/relayer/src/settings/mod.rs +++ b/rust/main/agents/relayer/src/settings/mod.rs @@ -135,6 +135,10 @@ impl FromRawConf for RelayerSettings { raw_gas_payment_enforcement_path, &raw_gas_payment_enforcement, ); + println!( + "SCOOBY DOO gas_payment_enforcement_parser: {:?}", + gas_payment_enforcement_parser + ); let mut gas_payment_enforcement = gas_payment_enforcement_parser.into_array_iter().map(|itr| { itr.filter_map(|policy| { let policy_type = policy.chain(&mut err).get_opt_key("type").parse_string().end(); diff --git a/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs b/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs index a5c71d86a6..82d6ec8a53 100644 --- a/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs +++ b/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs @@ -333,8 +333,8 @@ impl HyperlaneLogStore for HyperlaneRocksDB { ); println!( "Geforce, IGP payment: {:?}(limit {:?})", - payments[1].0.inner().payment, - payments[1].0.inner().gas_amount + payments[0].0.inner().payment, + payments[0].0.inner().gas_amount ); } From aee95b33f60ca785e7aba8db353023d706e8f0ad Mon Sep 17 00:00:00 2001 From: -f Date: Wed, 8 Jan 2025 02:20:34 +0530 Subject: [PATCH 6/9] add parsing check --- rust/main/agents/relayer/src/settings/mod.rs | 73 ++++++++++++++++--- .../src/db/rocks/hyperlane_db.rs | 12 --- 2 files changed, 63 insertions(+), 22 deletions(-) diff --git a/rust/main/agents/relayer/src/settings/mod.rs b/rust/main/agents/relayer/src/settings/mod.rs index ad7d32a835..6f66cc6514 100644 --- a/rust/main/agents/relayer/src/settings/mod.rs +++ b/rust/main/agents/relayer/src/settings/mod.rs @@ -125,20 +125,49 @@ impl FromRawConf for RelayerSettings { .parse_from_str("Expected database path") .unwrap_or_else(|| std::env::current_dir().unwrap().join("hyperlane_db")); - let (raw_gas_payment_enforcement_path, raw_gas_payment_enforcement) = p - .get_opt_key("gasPaymentEnforcement") - .take_config_err_flat(&mut err) - .and_then(parse_json_array) - .unwrap_or_else(|| (&p.cwp + "gas_payment_enforcement", Value::Array(vec![]))); + // is_gas_payment_enforcement_set determines if we should be checking for the correct gas payment enforcement policy has been provided with "gasPaymentEnforcement" key + let ( + raw_gas_payment_enforcement_path, + raw_gas_payment_enforcement, + is_gas_payment_enforcement_set, + ) = { + match p.get_opt_key("gasPaymentEnforcement") { + Ok(Some(parser)) => match parse_json_array(parser) { + Some((path, value)) => (path, value, true), + None => ( + &p.cwp + "gas_payment_enforcement", + Value::Array(vec![]), + true, + ), + }, + Ok(None) => ( + &p.cwp + "gas_payment_enforcement", + Value::Array(vec![]), + false, + ), + Err(_) => ( + &p.cwp + "gas_payment_enforcement", + Value::Array(vec![]), + false, + ), + } + }; let gas_payment_enforcement_parser = ValueParser::new( - raw_gas_payment_enforcement_path, + raw_gas_payment_enforcement_path.clone(), &raw_gas_payment_enforcement, ); - println!( - "SCOOBY DOO gas_payment_enforcement_parser: {:?}", - gas_payment_enforcement_parser - ); + + if is_gas_payment_enforcement_set + && gas_payment_enforcement_parser + .val + .as_array() + .unwrap() + .is_empty() + { + panic!("GASPAYMENTENFORCEMENT policy cannot be parsed"); + } + let mut gas_payment_enforcement = gas_payment_enforcement_parser.into_array_iter().map(|itr| { itr.filter_map(|policy| { let policy_type = policy.chain(&mut err).get_opt_key("type").parse_string().end(); @@ -350,6 +379,7 @@ fn parse_address_list( mod test { use super::*; use hyperlane_core::H160; + use serde_json::json; #[test] fn test_parse_address_blacklist() { @@ -378,4 +408,27 @@ mod test { assert_eq!(res, vec![valid_address1, valid_address2]); assert!(!err.is_ok()); } + + #[test] + fn test_gas_payment_enforcement_set_invalid_json() { + let input = json!({ + "relayChains": "test1,test2", + "gasPaymentEnforcement": "[{\"type\": \"minimum\",\"payment\": \"1\",}]" + }); + let raw = RawRelayerSettings(input); + let cwp = ConfigPath::default(); + let result = RelayerSettings::from_config_filtered(raw, &cwp, ()); + + assert!( + result.is_err(), + "Configuration should fail to parse with invalid 'gasPaymentEnforcement' JSON." + ); + let err = result.unwrap_err(); + println!("err: {:?}", err); + // TODO: fix this test + // assert!( + // err.to_string().contains("Expected JSON array or stringified JSON"), + // "Error should indicate invalid JSON format." + // ); + } } diff --git a/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs b/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs index 82d6ec8a53..76a51bfe3c 100644 --- a/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs +++ b/rust/main/hyperlane-base/src/db/rocks/hyperlane_db.rs @@ -326,18 +326,6 @@ impl HyperlaneLogStore for HyperlaneRocksDB { &self, payments: &[(Indexed, LogMeta)], ) -> Result { - if payments.len() > 0 { - println!( - "Geforce, IGP for message {:?}", - payments[0].0.inner().message_id - ); - println!( - "Geforce, IGP payment: {:?}(limit {:?})", - payments[0].0.inner().payment, - payments[0].0.inner().gas_amount - ); - } - store_and_count_new( self, payments, From 2c05b12dd9dbf9158742c675af63afa007b5d46b Mon Sep 17 00:00:00 2001 From: -f Date: Wed, 8 Jan 2025 14:55:54 +0530 Subject: [PATCH 7/9] err instead of panic --- rust/main/agents/relayer/src/settings/mod.rs | 27 ++------------------ 1 file changed, 2 insertions(+), 25 deletions(-) diff --git a/rust/main/agents/relayer/src/settings/mod.rs b/rust/main/agents/relayer/src/settings/mod.rs index 6f66cc6514..049c10e702 100644 --- a/rust/main/agents/relayer/src/settings/mod.rs +++ b/rust/main/agents/relayer/src/settings/mod.rs @@ -165,7 +165,8 @@ impl FromRawConf for RelayerSettings { .unwrap() .is_empty() { - panic!("GASPAYMENTENFORCEMENT policy cannot be parsed"); + Err::<(), eyre::Report>(eyre!("GASPAYMENTENFORCEMENT policy cannot be parsed")) + .take_err(&mut err, || cwp + "gas_payment_enforcement"); } let mut gas_payment_enforcement = gas_payment_enforcement_parser.into_array_iter().map(|itr| { @@ -379,7 +380,6 @@ fn parse_address_list( mod test { use super::*; use hyperlane_core::H160; - use serde_json::json; #[test] fn test_parse_address_blacklist() { @@ -408,27 +408,4 @@ mod test { assert_eq!(res, vec![valid_address1, valid_address2]); assert!(!err.is_ok()); } - - #[test] - fn test_gas_payment_enforcement_set_invalid_json() { - let input = json!({ - "relayChains": "test1,test2", - "gasPaymentEnforcement": "[{\"type\": \"minimum\",\"payment\": \"1\",}]" - }); - let raw = RawRelayerSettings(input); - let cwp = ConfigPath::default(); - let result = RelayerSettings::from_config_filtered(raw, &cwp, ()); - - assert!( - result.is_err(), - "Configuration should fail to parse with invalid 'gasPaymentEnforcement' JSON." - ); - let err = result.unwrap_err(); - println!("err: {:?}", err); - // TODO: fix this test - // assert!( - // err.to_string().contains("Expected JSON array or stringified JSON"), - // "Error should indicate invalid JSON format." - // ); - } } From 0fdde68f83ab27187e22eb23761b1b3d30d2d67d Mon Sep 17 00:00:00 2001 From: -f Date: Wed, 8 Jan 2025 14:58:16 +0530 Subject: [PATCH 8/9] cleanup --- rust/main/agents/relayer/src/msg/gas_payment/mod.rs | 4 ---- rust/main/agents/relayer/src/settings/mod.rs | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/rust/main/agents/relayer/src/msg/gas_payment/mod.rs b/rust/main/agents/relayer/src/msg/gas_payment/mod.rs index 83ebfbeedb..fa9f40b453 100644 --- a/rust/main/agents/relayer/src/msg/gas_payment/mod.rs +++ b/rust/main/agents/relayer/src/msg/gas_payment/mod.rs @@ -127,10 +127,6 @@ impl GasPaymentEnforcer { ?tx_cost_estimate, "Evaluating if message meets gas payment requirement", ); - println!( - "DELOREAN policy: {:?}, {:?}, {:?}", - policy, ¤t_payment, ¤t_expenditure - ); return policy .message_meets_gas_payment_requirement( message, diff --git a/rust/main/agents/relayer/src/settings/mod.rs b/rust/main/agents/relayer/src/settings/mod.rs index 049c10e702..2d3d9375de 100644 --- a/rust/main/agents/relayer/src/settings/mod.rs +++ b/rust/main/agents/relayer/src/settings/mod.rs @@ -154,7 +154,7 @@ impl FromRawConf for RelayerSettings { }; let gas_payment_enforcement_parser = ValueParser::new( - raw_gas_payment_enforcement_path.clone(), + raw_gas_payment_enforcement_path, &raw_gas_payment_enforcement, ); From 1df2bce3a5345fe8e6ee62129afc32c2983ee9e3 Mon Sep 17 00:00:00 2001 From: -f Date: Wed, 8 Jan 2025 15:48:09 +0530 Subject: [PATCH 9/9] grammar --- rust/main/agents/relayer/src/settings/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/main/agents/relayer/src/settings/mod.rs b/rust/main/agents/relayer/src/settings/mod.rs index 2d3d9375de..df28d03dee 100644 --- a/rust/main/agents/relayer/src/settings/mod.rs +++ b/rust/main/agents/relayer/src/settings/mod.rs @@ -125,7 +125,7 @@ impl FromRawConf for RelayerSettings { .parse_from_str("Expected database path") .unwrap_or_else(|| std::env::current_dir().unwrap().join("hyperlane_db")); - // is_gas_payment_enforcement_set determines if we should be checking for the correct gas payment enforcement policy has been provided with "gasPaymentEnforcement" key + // is_gas_payment_enforcement_set determines if we should be checking if the correct gas payment enforcement policy has been provided with "gasPaymentEnforcement" key let ( raw_gas_payment_enforcement_path, raw_gas_payment_enforcement,