From cbfd09812fde59954d3cdf63cdd0bbe0ec82baf7 Mon Sep 17 00:00:00 2001 From: Jakob Date: Tue, 5 Jan 2021 18:00:44 +0100 Subject: [PATCH 1/3] Allowing the creation of height locked Slates Fixes #564 --- libwallet/src/slate.rs | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/libwallet/src/slate.rs b/libwallet/src/slate.rs index 84856da6c..9f4de7465 100644 --- a/libwallet/src/slate.rs +++ b/libwallet/src/slate.rs @@ -250,8 +250,21 @@ impl Slate { tx } - /// Create a new slate + /// Create a new slate with a plain kernel pub fn blank(num_participants: u8, is_invoice: bool) -> Slate { + Slate::blank_with_kernel_features(num_participants, is_invoice, 0, None) + } + + /// Create a new slate with custom kernel_feature and lock height + /// If a lock_height is set kernel_features will have to be either HeightLocked (2) or NoRecentDuplicate (3) + /// otherwise the value passed as lock_height will be ignored and a plain kernel will be created + /// Invalid arguments for kernel_features (>3) will be set to 0 (Plain) + pub fn blank_with_kernel_features( + num_participants: u8, + is_invoice: bool, + kernel_feat_param: u8, + lock_height_param: Option, + ) -> Slate { let np = match num_participants { 0 => 2, n => n, @@ -260,6 +273,20 @@ impl Slate { true => SlateState::Invoice1, false => SlateState::Standard1, }; + let kernel_features = if kernel_feat_param > 3 { + 0 + } else { + kernel_feat_param + }; + let is_height_locked = + lock_height_param.is_some() && (kernel_features == 2 || kernel_features == 3); + let kernel_feat_args = if is_height_locked { + Some(KernelFeaturesArgs { + lock_height: lock_height_param.unwrap(), + }) + } else { + None + }; Slate { num_participants: np, // assume 2 if not present id: Uuid::new_v4(), @@ -268,7 +295,7 @@ impl Slate { amount: 0, fee_fields: FeeFields::zero(), ttl_cutoff_height: 0, - kernel_features: 0, + kernel_features: kernel_features, offset: BlindingFactor::zero(), participant_data: vec![], version_info: VersionCompatInfo { @@ -276,9 +303,10 @@ impl Slate { block_header_version: GRIN_BLOCK_HEADER_VERSION, }, payment_proof: None, - kernel_features_args: None, + kernel_features_args: kernel_feat_args, } } + /// Removes any signature data that isn't mine, for compacting /// slates for a return journey pub fn remove_other_sigdata( From 08bd462a996dc623f0e3cb558580670c5378f736 Mon Sep 17 00:00:00 2001 From: Jakob Date: Fri, 19 Mar 2021 18:07:00 +0100 Subject: [PATCH 2/3] [Dev] panic in case of invalid kernel_feat_param #PR-564 --- libwallet/src/slate.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libwallet/src/slate.rs b/libwallet/src/slate.rs index 9f4de7465..cb3b0b9a0 100644 --- a/libwallet/src/slate.rs +++ b/libwallet/src/slate.rs @@ -273,11 +273,10 @@ impl Slate { true => SlateState::Invoice1, false => SlateState::Standard1, }; - let kernel_features = if kernel_feat_param > 3 { - 0 - } else { - kernel_feat_param - }; + if kernel_feat_param > 3 { + panic!("Invalid value passed as kernel_feat_param to blank_with_kernel_features"); + } + let kernel_features = kernel_feat_param; let is_height_locked = lock_height_param.is_some() && (kernel_features == 2 || kernel_features == 3); let kernel_feat_args = if is_height_locked { From a896b195753a4ff937eb86aa3a1a6a7b8f5dfec9 Mon Sep 17 00:00:00 2001 From: Jakob Date: Sat, 27 Mar 2021 11:12:22 +0100 Subject: [PATCH 3/3] [Doc] Updated comment to better reflect behavior of blank_with_kernel_features #564 --- libwallet/src/slate.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libwallet/src/slate.rs b/libwallet/src/slate.rs index cb3b0b9a0..95a809c66 100644 --- a/libwallet/src/slate.rs +++ b/libwallet/src/slate.rs @@ -258,7 +258,7 @@ impl Slate { /// Create a new slate with custom kernel_feature and lock height /// If a lock_height is set kernel_features will have to be either HeightLocked (2) or NoRecentDuplicate (3) /// otherwise the value passed as lock_height will be ignored and a plain kernel will be created - /// Invalid arguments for kernel_features (>3) will be set to 0 (Plain) + /// Invalid arguments for kernel_features (>3) are not allowed and will make the function panic pub fn blank_with_kernel_features( num_participants: u8, is_invoice: bool,