From d899820c6e77116e1af2ea6b6c025e956fbef7cb Mon Sep 17 00:00:00 2001 From: Trevor Porter Date: Mon, 18 Mar 2024 17:34:18 +0000 Subject: [PATCH] Only use Jito for mainnet --- rust/chains/hyperlane-sealevel/src/mailbox.rs | 40 +++++++++++++++---- rust/hyperlane-core/src/chain.rs | 7 ++-- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/rust/chains/hyperlane-sealevel/src/mailbox.rs b/rust/chains/hyperlane-sealevel/src/mailbox.rs index 61d9838db7..db65d383fc 100644 --- a/rust/chains/hyperlane-sealevel/src/mailbox.rs +++ b/rust/chains/hyperlane-sealevel/src/mailbox.rs @@ -10,8 +10,8 @@ use tracing::{debug, info, instrument, warn}; use hyperlane_core::{ accumulator::incremental::IncrementalMerkle, ChainCommunicationError, ChainResult, Checkpoint, ContractLocator, Decode as _, Encode as _, HyperlaneAbi, HyperlaneChain, HyperlaneContract, - HyperlaneDomain, HyperlaneMessage, HyperlaneProvider, Indexer, LogMeta, Mailbox, - SequenceIndexer, TxCostEstimate, TxOutcome, H256, H512, U256, + HyperlaneDomain, HyperlaneMessage, HyperlaneProvider, Indexer, KnownHyperlaneDomain, LogMeta, + Mailbox, SequenceIndexer, TxCostEstimate, TxOutcome, H256, H512, U256, }; use hyperlane_sealevel_interchain_security_module_interface::{ InterchainSecurityModuleInstruction, VerifyInstruction, @@ -271,6 +271,28 @@ impl SealevelMailbox { self.get_account_metas(instruction).await } + fn use_jito(&self) -> bool { + matches!( + self.domain, + HyperlaneDomain::Known(KnownHyperlaneDomain::Solana) + ) + } + + async fn send_and_confirm_transaction( + &self, + transaction: &Transaction, + ) -> ChainResult { + if self.use_jito() { + self.send_and_confirm_transaction_with_jito(transaction) + .await + } else { + self.rpc_client + .send_and_confirm_transaction(transaction) + .await + .map_err(ChainCommunicationError::from_other) + } + } + // Stolen from Solana's non-blocking client, but with Jito! pub async fn send_and_confirm_transaction_with_jito( &self, @@ -522,15 +544,17 @@ impl Mailbox for SealevelMailbox { .as_ref() .ok_or_else(|| ChainCommunicationError::SignerUnavailable)?; - let mut instructions = Vec::with_capacity(2); + let mut instructions = Vec::with_capacity(4); // Set the compute unit limit. instructions.push(ComputeBudgetInstruction::set_compute_unit_limit( PROCESS_COMPUTE_UNITS, )); - // // Set the compute unit price. - // instructions.push(ComputeBudgetInstruction::set_compute_unit_price( - // PROCESS_COMPUTE_UNIT_PRICE_MICRO_LAMPORTS, - // )); + // Set the compute unit price, but only if we're not using Jito. + if !self.use_jito() { + instructions.push(ComputeBudgetInstruction::set_compute_unit_price( + PROCESS_COMPUTE_UNIT_PRICE_MICRO_LAMPORTS, + )); + } // "processed" level commitment does not guarantee finality. // roughly 5% of blocks end up on a dropped fork. @@ -634,7 +658,7 @@ impl Mailbox for SealevelMailbox { tracing::info!(?txn, "Created sealevel transaction to process message"); - let signature = self.send_and_confirm_transaction_with_jito(&txn).await?; + let signature = self.send_and_confirm_transaction(&txn).await?; tracing::info!(?txn, ?signature, "Sealevel transaction sent"); diff --git a/rust/hyperlane-core/src/chain.rs b/rust/hyperlane-core/src/chain.rs index e037bf0de4..592d35be7c 100644 --- a/rust/hyperlane-core/src/chain.rs +++ b/rust/hyperlane-core/src/chain.rs @@ -79,6 +79,8 @@ pub enum KnownHyperlaneDomain { Zksync2Testnet = 280, + Solana = 1399811149, + // -- Local test chains -- /// Test1 local chain Test1 = 13371, @@ -182,8 +184,7 @@ impl KnownHyperlaneDomain { many_to_one!(match self { Mainnet: [ Ethereum, Avalanche, Arbitrum, Polygon, Optimism, BinanceSmartChain, Celo, - Moonbeam, - Gnosis + Moonbeam, Gnosis, Solana ], Testnet: [ Goerli, Mumbai, Fuji, ArbitrumGoerli, OptimismGoerli, BinanceSmartChainTestnet, @@ -203,7 +204,7 @@ impl KnownHyperlaneDomain { Alfajores, Moonbeam, MoonbaseAlpha, Zksync2Testnet, Test1, Test2, Test3 ], HyperlaneDomainProtocol::Fuel: [FuelTest1], - HyperlaneDomainProtocol::Sealevel: [SealevelTest1, SealevelTest2], + HyperlaneDomainProtocol::Sealevel: [Solana, SealevelTest1, SealevelTest2], }) } }