Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/key-command
Browse files Browse the repository at this point in the history
  • Loading branch information
ljankovic-txfusion committed Nov 15, 2024
2 parents 0b92c68 + 25a927d commit ea205dc
Show file tree
Hide file tree
Showing 45 changed files with 957 additions and 383 deletions.
5 changes: 5 additions & 0 deletions .changeset/mighty-panthers-play.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': minor
---

Enroll new validators for alephzeroevmmainnet, chilizmainnet, flowmainnet, immutablezkevmmainnet, metal, polynomialfi, rarichain, rootstockmainnet, superpositionmainnet, flame, prom, inevm.
7 changes: 7 additions & 0 deletions .changeset/rare-llamas-float.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperlane-xyz/widgets': minor
---

New Icons
Updated modal with new props
Updated storybook for modal and icon list
7 changes: 7 additions & 0 deletions .changeset/real-phones-bake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hyperlane-xyz/infra': minor
'@hyperlane-xyz/cli': minor
'@hyperlane-xyz/sdk': minor
---

Implements persistent relayer for use in CLI
3 changes: 2 additions & 1 deletion .github/workflows/monorepo-docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ on:
- '**'
pull_request:
paths:
# For now, because this image is only used to use `infra`, we just build for infra changes
# For now, because this image is only used to use `infra`, we just build for infra or .registryrc changes
- 'typescript/infra/**'
- '.registryrc'
- 'Dockerfile'
- '.dockerignore'
- '.github/workflows/monorepo-docker.yml'
Expand Down
2 changes: 1 addition & 1 deletion .registryrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10fdae0f566c7c213b6b1b27b8620e8776f2895f
3e366eae1d49da4270695b157d7af00bb761156a
2 changes: 1 addition & 1 deletion rust/main/agents/relayer/src/msg/pending_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ impl PendingOperation for PendingMessage {
actual_gas_for_message = ?gas_used_by_operation,
message_gas_estimate = ?operation_estimate,
submission_gas_estimate = ?submission_estimated_cost,
message = ?self.message,
hyp_message = ?self.message,
"Gas used by message submission"
);
}
Expand Down
28 changes: 18 additions & 10 deletions rust/main/chains/hyperlane-ethereum/src/contracts/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ where
tx,
self.provider.clone(),
&self.conn.transaction_overrides.clone(),
&self.domain,
)
.await
}
Expand Down Expand Up @@ -382,6 +383,7 @@ where
call,
provider: self.provider.clone(),
transaction_overrides: self.conn.transaction_overrides.clone(),
domain: self.domain.clone(),
}
}
}
Expand Down Expand Up @@ -418,12 +420,18 @@ pub struct SubmittableBatch<M> {
pub call: ContractCall<M, Vec<MulticallResult>>,
provider: Arc<M>,
transaction_overrides: TransactionOverrides,
domain: HyperlaneDomain,
}

impl<M: Middleware + 'static> SubmittableBatch<M> {
pub async fn submit(self) -> ChainResult<TxOutcome> {
let call_with_gas_overrides =
fill_tx_gas_params(self.call, self.provider, &self.transaction_overrides).await?;
let call_with_gas_overrides = fill_tx_gas_params(
self.call,
self.provider,
&self.transaction_overrides,
&self.domain,
)
.await?;
let outcome = report_tx(call_with_gas_overrides).await?;
Ok(outcome.into())
}
Expand Down Expand Up @@ -615,10 +623,10 @@ mod test {
TxCostEstimate, H160, H256, U256,
};

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

/// An amount of gas to add to the estimated gas
const GAS_ESTIMATE_BUFFER: u32 = 75_000;
use crate::{
contracts::EthereumMailbox, tx::apply_gas_estimate_buffer, ConnectionConf,
RpcConnectionConf,
};

fn get_test_mailbox(
domain: HyperlaneDomain,
Expand Down Expand Up @@ -650,9 +658,9 @@ mod test {

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

let message = HyperlaneMessage::default();
let metadata: Vec<u8> = vec![];
Expand Down Expand Up @@ -696,8 +704,8 @@ mod test {
.await
.unwrap();

// The TxCostEstimate's gas limit includes the buffer
let estimated_gas_limit = gas_limit.saturating_add(GAS_ESTIMATE_BUFFER.into());
// The TxCostEstimate's gas limit includes a buffer
let estimated_gas_limit = apply_gas_estimate_buffer(gas_limit, &domain).unwrap();

assert_eq!(
tx_cost_estimate,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,13 @@ where
announcement.value.storage_location,
serialized_signature.into(),
);
fill_tx_gas_params(tx, self.provider.clone(), &self.conn.transaction_overrides).await
fill_tx_gas_params(
tx,
self.provider.clone(),
&self.conn.transaction_overrides,
&self.domain,
)
.await
}
}

Expand Down
31 changes: 26 additions & 5 deletions rust/main/chains/hyperlane-ethereum/src/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ use ethers_core::{
},
};
use hyperlane_core::{
utils::bytes_to_hex, ChainCommunicationError, ChainResult, ReorgPeriod, H256, U256,
utils::bytes_to_hex, ChainCommunicationError, ChainResult, HyperlaneDomain, ReorgPeriod, H256,
U256,
};
use tracing::{debug, error, info, warn};

Expand All @@ -25,8 +26,26 @@ use crate::{EthereumReorgPeriod, Middleware, TransactionOverrides};
/// An amount of gas to add to the estimated gas
pub const GAS_ESTIMATE_BUFFER: u32 = 75_000;

pub fn apply_gas_estimate_buffer(gas: U256) -> U256 {
gas.saturating_add(GAS_ESTIMATE_BUFFER.into())
// A multiplier to apply to the estimated gas, i.e. 10%.
pub const GAS_ESTIMATE_MULTIPLIER_NUMERATOR: u32 = 11;
pub const GAS_ESTIMATE_MULTIPLIER_DENOMINATOR: u32 = 10;

pub fn apply_gas_estimate_buffer(gas: U256, domain: &HyperlaneDomain) -> ChainResult<U256> {
// Arbitrum Nitro chains use 2d fees are are especially prone to costs increasing
// by the time the transaction lands on chain, requiring a higher gas limit.
// In this case, we apply a multiplier to the gas estimate.
let gas = if domain.is_arbitrum_nitro() {
gas.saturating_mul(GAS_ESTIMATE_MULTIPLIER_NUMERATOR.into())
.checked_div(GAS_ESTIMATE_MULTIPLIER_DENOMINATOR.into())
.ok_or_else(|| {
ChainCommunicationError::from_other_str("Gas estimate buffer divide by zero")
})?
} else {
gas
};

// Always add a flat buffer
Ok(gas.saturating_add(GAS_ESTIMATE_BUFFER.into()))
}

const PENDING_TRANSACTION_POLLING_INTERVAL: Duration = Duration::from_secs(2);
Expand Down Expand Up @@ -92,17 +111,19 @@ pub(crate) async fn fill_tx_gas_params<M, D>(
tx: ContractCall<M, D>,
provider: Arc<M>,
transaction_overrides: &TransactionOverrides,
domain: &HyperlaneDomain,
) -> ChainResult<ContractCall<M, D>>
where
M: Middleware + 'static,
D: Detokenize,
{
// either use the pre-estimated gas limit or estimate it
let estimated_gas_limit: U256 = match tx.tx.gas() {
let mut estimated_gas_limit: U256 = match tx.tx.gas() {
Some(&estimate) => estimate.into(),
None => tx.estimate_gas().await?.into(),
};
let estimated_gas_limit = apply_gas_estimate_buffer(estimated_gas_limit);

estimated_gas_limit = apply_gas_estimate_buffer(estimated_gas_limit, domain)?;
let gas_limit: U256 = if let Some(gas_limit) = transaction_overrides.gas_limit {
estimated_gas_limit.max(gas_limit)
} else {
Expand Down
57 changes: 34 additions & 23 deletions rust/main/chains/hyperlane-sealevel/src/interchain_gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use tracing::{info, instrument};
use hyperlane_core::{
config::StrOrIntParseError, ChainCommunicationError, ChainResult, ContractLocator,
HyperlaneChain, HyperlaneContract, HyperlaneDomain, HyperlaneProvider, Indexed, Indexer,
InterchainGasPaymaster, InterchainGasPayment, LogMeta, SequenceAwareIndexer, H256, U256,
InterchainGasPaymaster, InterchainGasPayment, LogMeta, SequenceAwareIndexer, H256, H512, U256,
};

use crate::account::{search_accounts_by_discriminator, search_and_validate_account};
Expand Down Expand Up @@ -91,7 +91,7 @@ impl InterchainGasPaymaster for SealevelInterchainGasPaymaster {}
pub struct SealevelInterchainGasPaymasterIndexer {
rpc_client: SealevelRpcClient,
igp: SealevelInterchainGasPaymaster,
log_meta_composer: LogMetaComposer,
_log_meta_composer: LogMetaComposer,
}

/// IGP payment data on Sealevel
Expand Down Expand Up @@ -122,7 +122,7 @@ impl SealevelInterchainGasPaymasterIndexer {
Ok(Self {
rpc_client,
igp,
log_meta_composer,
_log_meta_composer: log_meta_composer,
})
}

Expand Down Expand Up @@ -168,13 +168,24 @@ impl SealevelInterchainGasPaymasterIndexer {
gas_amount: gas_payment_account.gas_amount.into(),
};

let log_meta = self
.interchain_payment_log_meta(
U256::from(sequence_number),
&valid_payment_pda_pubkey,
&gas_payment_account.slot,
)
.await?;
// let log_meta = self
// .interchain_payment_log_meta(
// U256::from(sequence_number),
// &valid_payment_pda_pubkey,
// &gas_payment_account.slot,
// )
// .await?;

let log_meta = LogMeta {
address: self.igp.program_id.to_bytes().into(),
block_number: gas_payment_account.slot,
// TODO: get these when building out scraper support.
// It's inconvenient to get these :|
block_hash: H256::zero(),
transaction_id: H512::zero(),
transaction_index: 0,
log_index: sequence_number.into(),
};

Ok(SealevelGasPayment::new(
Indexed::new(igp_payment).with_sequence(
Expand All @@ -187,19 +198,6 @@ impl SealevelInterchainGasPaymasterIndexer {
))
}

async fn interchain_payment_log_meta(
&self,
log_index: U256,
payment_pda_pubkey: &Pubkey,
payment_pda_slot: &Slot,
) -> ChainResult<LogMeta> {
let block = self.rpc_client.get_block(*payment_pda_slot).await?;

self.log_meta_composer
.log_meta(block, log_index, payment_pda_pubkey, payment_pda_slot)
.map_err(Into::<ChainCommunicationError>::into)
}

fn interchain_payment_account(&self, account: &Account) -> ChainResult<Pubkey> {
let unique_gas_payment_pubkey = Pubkey::new(&account.data);
let (expected_pubkey, _bump) = Pubkey::try_find_program_address(
Expand All @@ -213,6 +211,19 @@ impl SealevelInterchainGasPaymasterIndexer {
})?;
Ok(expected_pubkey)
}

async fn _interchain_payment_log_meta(
&self,
log_index: U256,
payment_pda_pubkey: &Pubkey,
payment_pda_slot: &Slot,
) -> ChainResult<LogMeta> {
let block = self.rpc_client.get_block(*payment_pda_slot).await?;

self._log_meta_composer
.log_meta(block, log_index, payment_pda_pubkey, payment_pda_slot)
.map_err(Into::<ChainCommunicationError>::into)
}
}

#[async_trait]
Expand Down
54 changes: 38 additions & 16 deletions rust/main/chains/hyperlane-sealevel/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -716,13 +716,24 @@ impl SealevelMailboxIndexer {
let hyperlane_message =
HyperlaneMessage::read_from(&mut &dispatched_message_account.encoded_message[..])?;

let log_meta = self
.dispatch_message_log_meta(
U256::from(nonce),
&valid_message_storage_pda_pubkey,
&dispatched_message_account.slot,
)
.await?;
// let log_meta = self
// .dispatch_message_log_meta(
// U256::from(nonce),
// &valid_message_storage_pda_pubkey,
// &dispatched_message_account.slot,
// )
// .await?;

let log_meta = LogMeta {
address: self.program_id.to_bytes().into(),
block_number: dispatched_message_account.slot,
// TODO: get these when building out scraper support.
// It's inconvenient to get these :|
block_hash: H256::zero(),
transaction_id: H512::zero(),
transaction_index: 0,
log_index: U256::zero(),
};

Ok((hyperlane_message.into(), log_meta))
}
Expand All @@ -741,7 +752,7 @@ impl SealevelMailboxIndexer {
Ok(expected_pubkey)
}

async fn dispatch_message_log_meta(
async fn _dispatch_message_log_meta(
&self,
log_index: U256,
message_storage_pda_pubkey: &Pubkey,
Expand Down Expand Up @@ -798,13 +809,24 @@ impl SealevelMailboxIndexer {
.into_inner();
let message_id = delivered_message_account.message_id;

let log_meta = self
.delivered_message_log_meta(
U256::from(nonce),
&valid_message_storage_pda_pubkey,
&delivered_message_account.slot,
)
.await?;
// let log_meta = self
// .delivered_message_log_meta(
// U256::from(nonce),
// &valid_message_storage_pda_pubkey,
// &delivered_message_account.slot,
// )
// .await?;

let log_meta = LogMeta {
address: self.program_id.to_bytes().into(),
block_number: delivered_message_account.slot,
// TODO: get these when building out scraper support.
// It's inconvenient to get these :|
block_hash: H256::zero(),
transaction_id: H512::zero(),
transaction_index: 0,
log_index: U256::zero(),
};

Ok((message_id.into(), log_meta))
}
Expand All @@ -821,7 +843,7 @@ impl SealevelMailboxIndexer {
Ok(expected_pubkey)
}

async fn delivered_message_log_meta(
async fn _delivered_message_log_meta(
&self,
log_index: U256,
message_storage_pda_pubkey: &Pubkey,
Expand Down
Loading

0 comments on commit ea205dc

Please sign in to comment.