From 073c9baa2de54d3f6e936e45962f08e60ac8fead Mon Sep 17 00:00:00 2001 From: moudyellaz Date: Sun, 16 Aug 2026 23:41:00 +0200 Subject: [PATCH] perf(lez)!: borrow account data in the guests instead of cloning BREAKING CHANGE: six guest image ids move. --- lez/programs/bridge_lock/src/main.rs | 6 +++--- lez/programs/clock/src/main.rs | 2 +- lez/programs/cross_zone_inbox/src/main.rs | 8 +++----- lez/programs/ping_receiver/src/main.rs | 8 ++++---- lez/programs/ping_sender/src/main.rs | 8 ++++---- lez/programs/wrapped_token/src/main.rs | 10 +++++----- test_programs/guest/src/bin/pinata_cooldown.rs | 4 ++-- test_programs/guest/src/bin/time_locked_transfer.rs | 2 +- 8 files changed, 23 insertions(+), 25 deletions(-) diff --git a/lez/programs/bridge_lock/src/main.rs b/lez/programs/bridge_lock/src/main.rs index b7c5997e5..8b2f174ec 100644 --- a/lez/programs/bridge_lock/src/main.rs +++ b/lez/programs/bridge_lock/src/main.rs @@ -89,7 +89,7 @@ fn lock( config_account_id(self_program_id), "first account must be the bridge-lock config PDA" ); - let (outbox_program_id, pinned_target) = read_config(&config.account.data.clone().into_inner()) + let (outbox_program_id, pinned_target) = read_config(&config.account.data) .expect("config account holds an outbox and a mint target"); // Value conservation: the forwarded payload must mint exactly what is locked. @@ -221,8 +221,8 @@ fn init_config( "bridge-lock config PDA is owned by another program" ); assert_eq!( - config.account.data.clone().into_inner(), - config_bytes(outbox_program_id, target_program_id).to_vec(), + *config.account.data, + config_bytes(outbox_program_id, target_program_id), "bridge-lock config already pins a different outbox or mint target" ); } diff --git a/lez/programs/clock/src/main.rs b/lez/programs/clock/src/main.rs index 989394f71..9249a1111 100644 --- a/lez/programs/clock/src/main.rs +++ b/lez/programs/clock/src/main.rs @@ -67,7 +67,7 @@ fn main() { panic!("Clock accounts must be owned by the clock program"); } - let prev_data = ClockAccountData::from_bytes(&pre_01.account.data.clone().into_inner()); + let prev_data = ClockAccountData::from_bytes(&pre_01.account.data); let current_block_id = prev_data .block_id .checked_add(1) diff --git a/lez/programs/cross_zone_inbox/src/main.rs b/lez/programs/cross_zone_inbox/src/main.rs index 55eb15cff..42372b65a 100644 --- a/lez/programs/cross_zone_inbox/src/main.rs +++ b/lez/programs/cross_zone_inbox/src/main.rs @@ -102,15 +102,13 @@ fn dispatch( "Third account must be the source marker PDA for this message" ); - let cfg = InboxConfig::from_bytes(&config.account.data.clone().into_inner()) - .expect("inbox config decodes"); + let cfg = InboxConfig::from_bytes(&config.account.data).expect("inbox config decodes"); assert!( msg.src_zone != cfg.self_zone, "Source zone must not be this zone" ); - let mut shard = - SeenShard::from_bytes(&seen.account.data.clone().into_inner()).expect("seen shard decodes"); + let mut shard = SeenShard::from_bytes(&seen.account.data).expect("seen shard decodes"); // One block id, one delivering block. The address binds the zone and block // id but not which block claimed them, so an equivocating peer's two blocks @@ -209,7 +207,7 @@ fn init_config( "inbox config PDA is owned by another program" ); assert_eq!( - config_meta.account.data.clone().into_inner(), + *config_meta.account.data, config.to_bytes(), "inbox config already initialized differently" ); diff --git a/lez/programs/ping_receiver/src/main.rs b/lez/programs/ping_receiver/src/main.rs index 19d804e54..9a2ad5fe2 100644 --- a/lez/programs/ping_receiver/src/main.rs +++ b/lez/programs/ping_receiver/src/main.rs @@ -69,7 +69,7 @@ fn record( receiver_config_account_id(self_program_id), "second account must be the receiver config PDA" ); - let cfg = ReceiverConfig::from_bytes(&config.account.data.clone().into_inner()) + let cfg = ReceiverConfig::from_bytes(&config.account.data) .expect("config account holds a receiver config"); assert_eq!( caller_program_id, @@ -128,7 +128,7 @@ fn renounce_authority( receiver_config_account_id(self_program_id), "first account must be the receiver config PDA" ); - let mut cfg = ReceiverConfig::from_bytes(&config_meta.account.data.clone().into_inner()) + let mut cfg = ReceiverConfig::from_bytes(&config_meta.account.data) .expect("config account holds a receiver config"); // Top-level, or the governance program the config names; see // `ReceiverConfig::governance` for why the escape hatch exists. @@ -200,7 +200,7 @@ fn update_sources( receiver_config_account_id(self_program_id), "first account must be the receiver config PDA" ); - let mut cfg = ReceiverConfig::from_bytes(&config_meta.account.data.clone().into_inner()) + let mut cfg = ReceiverConfig::from_bytes(&config_meta.account.data) .expect("config account holds a receiver config"); // Top-level, or the governance program the config names; see // `ReceiverConfig::governance` for why the escape hatch exists. @@ -285,7 +285,7 @@ fn init_config( "receiver config PDA is owned by another program" ); assert_eq!( - config.account.data.clone().into_inner(), + *config.account.data, config_value.to_bytes(), "receiver config already initialized differently" ); diff --git a/lez/programs/ping_sender/src/main.rs b/lez/programs/ping_sender/src/main.rs index 7ae0ea038..dcbf44cd1 100644 --- a/lez/programs/ping_sender/src/main.rs +++ b/lez/programs/ping_sender/src/main.rs @@ -81,8 +81,8 @@ fn send( sender_config_account_id(self_program_id), "first account must be the ping-sender config PDA" ); - let outbox_program_id = read_outbox(&config.account.data.clone().into_inner()) - .expect("config account holds an outbox program id"); + let outbox_program_id = + read_outbox(&config.account.data).expect("config account holds an outbox program id"); let call = ChainedCall::new( outbox_program_id, @@ -135,8 +135,8 @@ fn init_config( "ping-sender config PDA is owned by another program" ); assert_eq!( - config.account.data.clone().into_inner(), - outbox_bytes(outbox_program_id).to_vec(), + *config.account.data, + outbox_bytes(outbox_program_id), "ping-sender config already pins a different outbox" ); } diff --git a/lez/programs/wrapped_token/src/main.rs b/lez/programs/wrapped_token/src/main.rs index 6c367d86f..ae70694c7 100644 --- a/lez/programs/wrapped_token/src/main.rs +++ b/lez/programs/wrapped_token/src/main.rs @@ -72,7 +72,7 @@ fn mint( config_account_id(self_program_id), "second account must be the wrapped-token config PDA" ); - let cfg = WrappedTokenConfig::from_bytes(&config.account.data.clone().into_inner()) + let cfg = WrappedTokenConfig::from_bytes(&config.account.data) .expect("config account holds a wrapped-token config"); assert_eq!( caller_program_id, @@ -102,7 +102,7 @@ fn mint( "mint amount exceeds the per-mint cap" ); // The backstop against accumulation, which the per-mint cap does not bound. - let new_balance = read_balance(&holding.account.data.clone().into_inner()) + let new_balance = read_balance(&holding.account.data) .checked_add(amount) .expect("wrapped-token balance overflow"); let mut holding_account = holding.account.clone(); @@ -147,7 +147,7 @@ fn renounce_authority( config_account_id(self_program_id), "first account must be the wrapped-token config PDA" ); - let mut cfg = WrappedTokenConfig::from_bytes(&config_meta.account.data.clone().into_inner()) + let mut cfg = WrappedTokenConfig::from_bytes(&config_meta.account.data) .expect("config account holds a wrapped-token config"); // Top-level, or the governance program the config names; see // `WrappedTokenConfig::governance` for why the escape hatch exists. @@ -219,7 +219,7 @@ fn update_sources( config_account_id(self_program_id), "first account must be the wrapped-token config PDA" ); - let mut cfg = WrappedTokenConfig::from_bytes(&config_meta.account.data.clone().into_inner()) + let mut cfg = WrappedTokenConfig::from_bytes(&config_meta.account.data) .expect("config account holds a wrapped-token config"); // Top-level, or the governance program the config names; see // `WrappedTokenConfig::governance` for why the escape hatch exists. @@ -306,7 +306,7 @@ fn init_config( "wrapped-token config PDA is owned by another program" ); assert_eq!( - config.account.data.clone().into_inner(), + *config.account.data, config_value.to_bytes(), "wrapped-token config already initialized differently" ); diff --git a/test_programs/guest/src/bin/pinata_cooldown.rs b/test_programs/guest/src/bin/pinata_cooldown.rs index 160fba21a..24e572dc7 100644 --- a/test_programs/guest/src/bin/pinata_cooldown.rs +++ b/test_programs/guest/src/bin/pinata_cooldown.rs @@ -63,10 +63,10 @@ fn main() { // Check the clock account is the system clock account assert_eq!(clock_pre.account_id, CLOCK_01_PROGRAM_ACCOUNT_ID); - let clock_data = ClockAccountData::from_bytes(&clock_pre.account.data.clone().into_inner()); + let clock_data = ClockAccountData::from_bytes(&clock_pre.account.data); let current_timestamp = clock_data.timestamp; - let pinata_state = PinataState::from_bytes(&pinata.account.data.clone().into_inner()); + let pinata_state = PinataState::from_bytes(&pinata.account.data); // Enforce cooldown: the elapsed time since the last claim must exceed the cooldown period. let elapsed = current_timestamp.saturating_sub(pinata_state.last_claim_timestamp); diff --git a/test_programs/guest/src/bin/time_locked_transfer.rs b/test_programs/guest/src/bin/time_locked_transfer.rs index 8746ef846..76391b892 100644 --- a/test_programs/guest/src/bin/time_locked_transfer.rs +++ b/test_programs/guest/src/bin/time_locked_transfer.rs @@ -34,7 +34,7 @@ fn main() { assert_eq!(clock_pre.account_id, CLOCK_01_PROGRAM_ACCOUNT_ID); // Read the current timestamp from the clock account. - let clock_data = ClockAccountData::from_bytes(&clock_pre.account.data.clone().into_inner()); + let clock_data = ClockAccountData::from_bytes(&clock_pre.account.data); assert!( clock_data.timestamp >= deadline,