Skip to content

Commit 3f24bde

Browse files
committed
fix: gas estimation for tron
1 parent e4e9a9d commit 3f24bde

5 files changed

Lines changed: 40 additions & 15 deletions

File tree

rust/main/chains/hyperlane-ethereum/src/ism/interchain_security_module.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,19 +152,10 @@ where
152152
if self.module_type().await? == ModuleType::Null {
153153
if let Some(sender) = self.contract.client().default_sender() {
154154
let tr = ITrustedRelayerIsm::new(self.contract.address(), self.contract.client());
155-
match tr.trusted_relayer().call().await {
156-
Ok(trusted_relayer) if trusted_relayer == sender => {
155+
if let Ok(trusted_relayer) = tr.trusted_relayer().call().await {
156+
if trusted_relayer == sender {
157157
return Ok(Some(U256::zero()));
158158
}
159-
Ok(_) => {} // not the trusted relayer, return None below
160-
Err(err) => {
161-
warn!(
162-
?err,
163-
ism_address = ?self.contract.address(),
164-
?sender,
165-
"Failed to query trustedRelayer() on Null ISM"
166-
);
167-
}
168159
}
169160
}
170161
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[
2+
{
3+
"inputs": [],
4+
"name": "trustedRelayer",
5+
"outputs": [
6+
{
7+
"internalType": "address",
8+
"name": "",
9+
"type": "address"
10+
}
11+
],
12+
"stateMutability": "view",
13+
"type": "function"
14+
}
15+
]

rust/main/chains/hyperlane-tron/src/ism/interchain_security_module.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use hyperlane_core::{
1515
use num_traits::cast::FromPrimitive;
1616

1717
use crate::interfaces::i_interchain_security_module::IInterchainSecurityModule as TronInterchainSecurityModuleInternal;
18+
use crate::interfaces::i_trusted_relayer_ism::ITrustedRelayerIsm;
1819
use crate::TronProvider;
1920

2021
/// A reference to an InterchainSecurityModule contract on some Tron chain
@@ -78,9 +79,21 @@ impl InterchainSecurityModule for TronInterchainSecurityModule {
7879
);
7980
let (verifies, gas_estimate) = try_join(tx.call(), tx.estimate_gas()).await?;
8081
if verifies {
81-
Ok(Some(gas_estimate.into()))
82-
} else {
83-
Ok(None)
82+
return Ok(Some(gas_estimate.into()));
83+
}
84+
// For Null-typed ISMs (e.g. TrustedRelayerIsm), verify() returns false
85+
// during a dry run because it depends on mailbox state set during process().
86+
// If we are the configured trusted relayer, include it with gas=0.
87+
if self.module_type().await? == ModuleType::Null {
88+
if let Some(sender) = self.contract.client().signer_address() {
89+
let tr = ITrustedRelayerIsm::new(self.contract.address(), self.contract.client());
90+
if let Ok(trusted_relayer) = tr.trusted_relayer().call().await {
91+
if trusted_relayer == sender {
92+
return Ok(Some(U256::zero()));
93+
}
94+
}
95+
}
8496
}
97+
Ok(None)
8598
}
8699
}

rust/main/chains/hyperlane-tron/src/provider/tron.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ impl TronProvider {
8484
})
8585
}
8686

87+
/// Returns the signer's Ethereum-style address, if a signer is configured.
88+
pub fn signer_address(&self) -> Option<H160> {
89+
self.signer.as_ref().map(|s| s.address())
90+
}
91+
8792
fn get_signer(&self) -> ChainResult<&TronSigner> {
8893
Ok(self
8994
.signer

rust/main/hyperlane-base/src/settings/chains.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,8 @@ impl ChainConf {
10731073
Ok(Box::new(ism) as Box<dyn InterchainSecurityModule>)
10741074
}
10751075
ChainConnectionConf::Tron(conf) => {
1076-
let provider = build_tron_provider(self, conf, metrics, &locator, None)?;
1076+
let signer = self.tron_signer().await.context(ctx)?;
1077+
let provider = build_tron_provider(self, conf, metrics, &locator, signer)?;
10771078
let ism = h_tron::TronInterchainSecurityModule::new(provider, &locator);
10781079
Ok(Box::new(ism) as Box<dyn InterchainSecurityModule>)
10791080
}

0 commit comments

Comments
 (0)