From 2f3f65a2273117a9de54c668247eb82e8490bbfd Mon Sep 17 00:00:00 2001 From: wiesche Date: Sat, 12 Sep 2026 17:57:28 +0200 Subject: [PATCH] avoid slate copies --- libwallet/src/api_impl/owner.rs | 3 +- libwallet/src/contract/actions/sign.rs | 13 ++++--- libwallet/src/contract/actions/view.rs | 2 +- libwallet/src/slate.rs | 47 +++----------------------- 4 files changed, 12 insertions(+), 53 deletions(-) diff --git a/libwallet/src/api_impl/owner.rs b/libwallet/src/api_impl/owner.rs index cf61036..00e0e7a 100644 --- a/libwallet/src/api_impl/owner.rs +++ b/libwallet/src/api_impl/owner.rs @@ -1615,8 +1615,7 @@ where C: NodeClient, K: Keychain, { - let mut slate = slate.clone(); - contract::view(&mut *w, keychain_mask, &mut slate) + contract::view(&mut *w, keychain_mask, slate) } /// Sign transaction contract diff --git a/libwallet/src/contract/actions/sign.rs b/libwallet/src/contract/actions/sign.rs index e5c5ff1..8d981e3 100644 --- a/libwallet/src/contract/actions/sign.rs +++ b/libwallet/src/contract/actions/sign.rs @@ -92,28 +92,27 @@ where C: NodeClient, K: Keychain, { - let sl = slate.clone(); - contract::utils::verify_not_signed(w, sl.id)?; + contract::utils::verify_not_signed(w, slate.id)?; // Reject terminal and unknown states before setup reserves keys. - contract::slate::next_state(&sl.state)?; + contract::slate::next_state(&slate.state)?; // Ensure net_change has been provided let expected_net_change = contract::utils::get_net_change(existing_context.as_ref(), setup_args.net_change)?; if existing_context.is_none() { - verify_first_sign_net_change(&sl.state, sl.amount, expected_net_change)?; + verify_first_sign_net_change(&slate.state, slate.amount, expected_net_change)?; } // Define the values that must be provided in the setup phase at the sign step let mut setup_args = setup_args.clone(); setup_args.net_change = Some(expected_net_change); - setup_args.num_participants = sl.num_participants; + setup_args.num_participants = slate.num_participants; setup_args.add_outputs = true; // we add outputs to the Context in case we haven't done that yet - contract::slate::verify_incoming_own_commitments(w, keychain_mask, &sl)?; + contract::slate::verify_incoming_own_commitments(w, keychain_mask, slate)?; // Ensure Setup phase is done and that inputs/outputs have been added to the Context let (mut sl, mut context) = - setup::compute(w, keychain_mask, &sl, &setup_args, existing_context)?; + setup::compute(w, keychain_mask, slate, &setup_args, existing_context)?; // Add outputs to the slate, verify the payment proof and sign the slate contract::slate::add_outputs(w, keychain_mask, &mut sl, &context)?; contract::slate::verify_own_commitments(w, keychain_mask, &sl, &context)?; diff --git a/libwallet/src/contract/actions/view.rs b/libwallet/src/contract/actions/view.rs index 7e99d8c..b0f32a8 100644 --- a/libwallet/src/contract/actions/view.rs +++ b/libwallet/src/contract/actions/view.rs @@ -58,7 +58,7 @@ fn tx_net_change(tx: &TxLogEntry) -> Result { pub fn view( w: &mut WalletBackend, keychain_mask: Option<&SecretKey>, - slate: &mut Slate, + slate: &Slate, ) -> Result where C: NodeClient, diff --git a/libwallet/src/slate.rs b/libwallet/src/slate.rs index ffcba0c..bd72d44 100644 --- a/libwallet/src/slate.rs +++ b/libwallet/src/slate.rs @@ -975,47 +975,7 @@ impl Serialize for Slate { ////// V5 impl From for SlateV5 { fn from(slate: Slate) -> SlateV5 { - let Slate { - num_participants: num_parts, - id, - state, - tx: _, - amount, - fee_fields, - kernel_features, - ttl_cutoff_height: ttl, - offset: off, - participant_data, - version_info, - payment_proof, - kernel_features_args, - } = slate.clone(); - let participant_data = map_vec!(participant_data, |data| ParticipantDataV5::from(data)); - let ver = VersionCompatInfoV5::from(&version_info); - let payment_proof = match payment_proof { - Some(p) => Some(PaymentInfoV5::from(&p)), - None => None, - }; - let feat_args = match kernel_features_args { - Some(a) => Some(KernelFeaturesArgsV5::from(&a)), - None => None, - }; - let sta = SlateStateV5::from(&state); - SlateV5 { - num_parts, - id, - sta, - coms: (&slate).into(), - amt: amount, - fee: fee_fields, - feat: kernel_features, - ttl, - off, - sigs: participant_data, - ver, - proof: payment_proof, - feat_args, - } + Self::from(&slate) } } @@ -1191,6 +1151,7 @@ impl From for OutputFeaturesV5 { ///// V5 impl From for Slate { fn from(slate: SlateV5) -> Slate { + let tx = (&slate).into(); let SlateV5 { num_parts: num_participants, id, @@ -1205,7 +1166,7 @@ impl From for Slate { ver, proof: payment_proof, feat_args, - } = slate.clone(); + } = slate; let participant_data = map_vec!(participant_data, |data| ParticipantData::from(data)); let version_info = VersionCompatInfo::from(&ver); let payment_proof = match &payment_proof { @@ -1221,7 +1182,7 @@ impl From for Slate { num_participants, id, state, - tx: (&slate).into(), + tx, amount, fee_fields, kernel_features,