Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into pb/decent
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbalaji committed Jan 29, 2025
2 parents a9e962d + f250b19 commit 990156f
Show file tree
Hide file tree
Showing 39 changed files with 555 additions and 230 deletions.
5 changes: 0 additions & 5 deletions .changeset/fast-comics-wave.md

This file was deleted.

5 changes: 0 additions & 5 deletions .changeset/selfish-drinks-add.md

This file was deleted.

3 changes: 2 additions & 1 deletion rust/main/agents/relayer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod msg;

mod merkle_tree;
mod msg;
mod processor;
mod prover;
mod relayer;
Expand Down
6 changes: 6 additions & 0 deletions rust/main/agents/relayer/src/merkle_tree/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ impl Display for MerkleTreeBuilder {
}
}

impl Default for MerkleTreeBuilder {
fn default() -> Self {
Self::new()
}
}

/// MerkleTreeBuilder errors
#[derive(Debug, thiserror::Error)]
pub enum MerkleTreeBuilderError {
Expand Down
3 changes: 2 additions & 1 deletion rust/main/agents/relayer/src/msg/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ pub(crate) mod gas_payment;
pub(crate) mod metadata;
pub(crate) mod op_queue;
pub(crate) mod op_submitter;
pub(crate) mod pending_message;
pub(crate) mod processor;

pub mod pending_message;

pub use gas_payment::GAS_EXPENDITURE_LOG_MESSAGE;
10 changes: 2 additions & 8 deletions rust/main/agents/relayer/src/msg/op_submitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,8 @@ async fn receive_task(
// make sure things are getting wired up correctly; if this works in testing it
// should also be valid in production.
debug_assert_eq!(*op.destination_domain(), domain);
let status = op.retrieve_status_from_db().unwrap_or_else(|| {
trace!(
?op,
"No status found for message, defaulting to FirstPrepareAttempt"
);
PendingOperationStatus::FirstPrepareAttempt
});
prepare_queue.push(op, Some(status)).await;
let op_status = op.status();
prepare_queue.push(op, Some(op_status)).await;
}
}

Expand Down
64 changes: 46 additions & 18 deletions rust/main/agents/relayer/src/msg/pending_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use hyperlane_core::{
};
use prometheus::{IntCounter, IntGauge};
use serde::Serialize;
use tracing::{debug, error, info, info_span, instrument, trace, warn, Instrument};
use tracing::{debug, error, info, info_span, instrument, trace, warn, Instrument, Level};

use super::{
gas_payment::{GasPaymentEnforcer, GasPolicyStatus},
Expand All @@ -36,6 +36,8 @@ pub const CONFIRM_DELAY: Duration = if cfg!(any(test, feature = "test-utils")) {
Duration::from_secs(60 * 10)
};

pub const RETRIEVED_MESSAGE_LOG: &str = "Message status retrieved from db";

/// The message context contains the links needed to submit a message. Each
/// instance is for a unique origin -> destination pairing.
pub struct MessageContext {
Expand Down Expand Up @@ -510,27 +512,53 @@ impl PendingMessage {
ctx: Arc<MessageContext>,
app_context: Option<String>,
) -> Self {
let mut pm = Self::new(
message,
ctx,
// Since we don't persist the message status for now, assume it's the first attempt
PendingOperationStatus::FirstPrepareAttempt,
app_context,
);
match pm
.ctx
// Attempt to fetch status about message from database
let message_status = match ctx.origin_db.retrieve_status_by_message_id(&message.id()) {
Ok(Some(status)) => {
// This event is used for E2E tests to ensure message statuses
// are being properly loaded from the db
tracing::event!(
if cfg!(feature = "test-utils") {
Level::DEBUG
} else {
Level::TRACE
},
?status,
id=?message.id(),
RETRIEVED_MESSAGE_LOG,
);
status
}
_ => {
tracing::event!(
if cfg!(feature = "test-utils") {
Level::DEBUG
} else {
Level::TRACE
},
"Message status not found in db"
);
PendingOperationStatus::FirstPrepareAttempt
}
};

let num_retries = match ctx
.origin_db
.retrieve_pending_message_retry_count_by_message_id(&pm.message.id())
.retrieve_pending_message_retry_count_by_message_id(&message.id())
{
Ok(Some(num_retries)) => {
let next_attempt_after = PendingMessage::calculate_msg_backoff(num_retries)
.map(|dur| Instant::now() + dur);
pm.num_retries = num_retries;
pm.next_attempt_after = next_attempt_after;
}
Ok(Some(num_retries)) => num_retries,
r => {
trace!(message_id = ?pm.message.id(), result = ?r, "Failed to read retry count from HyperlaneDB for message.")
trace!(message_id = ?message.id(), result = ?r, "Failed to read retry count from HyperlaneDB for message.");
0
}
};

let mut pm = Self::new(message, ctx, message_status, app_context);
if num_retries > 0 {
let next_attempt_after =
PendingMessage::calculate_msg_backoff(num_retries).map(|dur| Instant::now() + dur);
pm.num_retries = num_retries;
pm.next_attempt_after = next_attempt_after;
}
pm
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_trait::async_trait;
use num_traits::cast::FromPrimitive;
use solana_sdk::{instruction::Instruction, pubkey::Pubkey, signature::Keypair};
use solana_sdk::{instruction::Instruction, pubkey::Pubkey};
use tracing::warn;

use hyperlane_core::{
Expand All @@ -10,19 +10,23 @@ use hyperlane_core::{
use hyperlane_sealevel_interchain_security_module_interface::InterchainSecurityModuleInstruction;
use serializable_account_meta::SimulationReturnData;

use crate::{ConnectionConf, SealevelProvider, SealevelRpcClient};
use crate::{ConnectionConf, SealevelKeypair, SealevelProvider, SealevelRpcClient};

/// A reference to an InterchainSecurityModule contract on some Sealevel chain
#[derive(Debug)]
pub struct SealevelInterchainSecurityModule {
payer: Option<Keypair>,
payer: Option<SealevelKeypair>,
program_id: Pubkey,
provider: SealevelProvider,
}

impl SealevelInterchainSecurityModule {
/// Create a new sealevel InterchainSecurityModule
pub fn new(conf: &ConnectionConf, locator: ContractLocator, payer: Option<Keypair>) -> Self {
pub fn new(
conf: &ConnectionConf,
locator: ContractLocator,
payer: Option<SealevelKeypair>,
) -> Self {
let provider = SealevelProvider::new(locator.domain.clone(), conf);
let program_id = Pubkey::from(<[u8; 32]>::from(locator.address));
Self {
Expand Down
52 changes: 52 additions & 0 deletions rust/main/chains/hyperlane-sealevel/src/keypair.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
use std::ops::Deref;

use solana_sdk::{signature::Keypair, signer::Signer};

/// Wrapper around solana_sdk's Keypair.
/// This implements a custom Debug so the private keys are
/// not exposed.
pub struct SealevelKeypair(pub Keypair);

impl SealevelKeypair {
/// create new SealevelKeypair
pub fn new(keypair: Keypair) -> Self {
Self(keypair)
}
/// Return the underlying keypair
pub fn keypair(&self) -> &Keypair {
&self.0
}
}

impl Deref for SealevelKeypair {
type Target = Keypair;

/// Return the underlying keypair
fn deref(&self) -> &Self::Target {
&self.0
}
}

impl std::fmt::Debug for SealevelKeypair {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0.pubkey())
}
}

#[cfg(test)]
mod test {
use solana_sdk::signature::Keypair;

use super::SealevelKeypair;

#[test]
fn test_no_exposed_secret_key() {
let priv_key = "2ckDxzDFpZGeWd7VbHzd6dMgxYpqVDPA8XzeXFuuUJ1K8CjtyTBenD1TSPPovahXEFw3kBihoyAKktyro22MP4bN";
let pub_key = "6oKnHXD2LRzQ4iNsgvkGSNNx68vj5GCYYpR2icy5JZhE";

let keypair = SealevelKeypair(Keypair::from_base58_string(priv_key));

let actual = format!("{:?}", keypair);
assert_eq!(pub_key, actual);
}
}
2 changes: 2 additions & 0 deletions rust/main/chains/hyperlane-sealevel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
pub use crate::multisig_ism::*;
pub use interchain_gas::*;
pub use interchain_security_module::*;
pub use keypair::*;
pub use mailbox::*;
pub use merkle_tree_hook::*;
pub use provider::*;
Expand All @@ -19,6 +20,7 @@ mod account;
mod error;
mod interchain_gas;
mod interchain_security_module;
mod keypair;
mod log_meta_composer;
mod mailbox;
mod merkle_tree_hook;
Expand Down
17 changes: 10 additions & 7 deletions rust/main/chains/hyperlane-sealevel/src/mailbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ use solana_sdk::{
commitment_config::CommitmentConfig,
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
signer::{keypair::Keypair, Signer as _},
signer::Signer as _,
};
use tracing::{debug, info, instrument, warn};

Expand All @@ -40,14 +40,17 @@ use hyperlane_core::{
ReorgPeriod, SequenceAwareIndexer, TxCostEstimate, TxOutcome, H256, H512, U256,
};

use crate::log_meta_composer::{
is_message_delivery_instruction, is_message_dispatch_instruction, LogMetaComposer,
};
use crate::tx_submitter::TransactionSubmitter;
use crate::{
account::{search_accounts_by_discriminator, search_and_validate_account},
priority_fee::PriorityFeeOracle,
};
use crate::{
log_meta_composer::{
is_message_delivery_instruction, is_message_dispatch_instruction, LogMetaComposer,
},
SealevelKeypair,
};
use crate::{ConnectionConf, SealevelProvider, SealevelRpcClient};

const SYSTEM_PROGRAM: &str = "11111111111111111111111111111111";
Expand Down Expand Up @@ -79,7 +82,7 @@ pub struct SealevelMailbox {
inbox: (Pubkey, u8),
pub(crate) outbox: (Pubkey, u8),
pub(crate) provider: SealevelProvider,
payer: Option<Keypair>,
payer: Option<SealevelKeypair>,
priority_fee_oracle: Box<dyn PriorityFeeOracle>,
tx_submitter: Box<dyn TransactionSubmitter>,
}
Expand All @@ -89,7 +92,7 @@ impl SealevelMailbox {
pub fn new(
conf: &ConnectionConf,
locator: ContractLocator,
payer: Option<Keypair>,
payer: Option<SealevelKeypair>,
) -> ChainResult<Self> {
let provider = SealevelProvider::new(locator.domain.clone(), conf);
let program_id = Pubkey::from(<[u8; 32]>::from(locator.address));
Expand Down Expand Up @@ -379,7 +382,7 @@ impl SealevelMailbox {
Ok(inbox)
}

fn get_payer(&self) -> ChainResult<&Keypair> {
fn get_payer(&self) -> ChainResult<&SealevelKeypair> {
self.payer
.as_ref()
.ok_or_else(|| ChainCommunicationError::SignerUnavailable)
Expand Down
11 changes: 7 additions & 4 deletions rust/main/chains/hyperlane-sealevel/src/multisig_ism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ use serializable_account_meta::SimulationReturnData;
use solana_sdk::{
instruction::{AccountMeta, Instruction},
pubkey::Pubkey,
signature::Keypair,
};

use crate::{ConnectionConf, SealevelProvider, SealevelRpcClient};
use crate::{ConnectionConf, SealevelKeypair, SealevelProvider, SealevelRpcClient};

use multisig_ism::interface::{
MultisigIsmInstruction, VALIDATORS_AND_THRESHOLD_ACCOUNT_METAS_PDA_SEEDS,
Expand All @@ -20,15 +19,19 @@ use multisig_ism::interface::{
/// A reference to a MultisigIsm contract on some Sealevel chain
#[derive(Debug)]
pub struct SealevelMultisigIsm {
payer: Option<Keypair>,
payer: Option<SealevelKeypair>,
program_id: Pubkey,
domain: HyperlaneDomain,
provider: SealevelProvider,
}

impl SealevelMultisigIsm {
/// Create a new Sealevel MultisigIsm.
pub fn new(conf: &ConnectionConf, locator: ContractLocator, payer: Option<Keypair>) -> Self {
pub fn new(
conf: &ConnectionConf,
locator: ContractLocator,
payer: Option<SealevelKeypair>,
) -> Self {
let provider = SealevelProvider::new(locator.domain.clone(), conf);
let program_id = Pubkey::from(<[u8; 32]>::from(locator.address));

Expand Down
Loading

0 comments on commit 990156f

Please sign in to comment.