Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Late locking #530

Merged
merged 5 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions api/src/foreign_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,17 @@ pub trait ForeignRpc {
}
],
"id": "0436430c-2b02-624c-2032-570501212b00",
"off": "a4052c9200000001a6052c9200000002ed564fab50b75fc5ea32ce052fc9bebf",
"off": "a4f88ac429dee1d453ae33ed9f944417a52c7310477936e484fd83f0f22db483",
"proof": {
"raddr": "32cdd63928854f8b2628b1dce4626ddcdf35d56cb7cfdf7d64cca5822b78d4d3",
"rsig": "feb98c299e8328ea6b73b06e756eb3094180c3cc5ba01ed82dce75a5bfbe14f3ea235d9d9c2cee3e72cd162d9e5b5b77fcb8e34ad6a40551924bb010c9afdc0f",
"rsig": "02357a13b304ba8e22f4896d5664b72ad6d1b824e88782e2b716686ea14ec47281ef5ee14c03ead84c3260f5b0c1529ad3ddae57f28f6b8b1b66532bfcb2ee0f",
"saddr": "32cdd63928854f8b2628b1dce4626ddcdf35d56cb7cfdf7d64cca5822b78d4d3"
},
"sigs": [
{
"nonce": "031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f",
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841b54735cb9ed2f59fb457144f7b1c8226d08b54cbdd0eb7e6492950751b0bb54f9",
"xs": "03b0d73a044f1f9ae06cf96ef91593f121864b66bf7f7e7ac481b0ce61e39847fe"
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841babbc82d2e200efe3a3b70cdfbed5b4e1d2a87641d0c4f6a3d7e73b80facb8507",
"xs": "02e3c128e436510500616fef3f9a22b15ca015f407c8c5cf96c9059163c873828f"
}
],
"sta": "S2",
Expand Down Expand Up @@ -209,13 +209,13 @@ pub trait ForeignRpc {
"ver": "4:2",
"id": "0436430c-2b02-624c-2032-570501212b00",
"sta": "I2",
"off": "750dbf4fd43b7f4cfd68d2698a522f3ff6e6a00ad9895b33f1ec46493b837b49",
"off": "dbd68b83e4d6f9ebaebf179fdde3efd4309734124937bcb5f5a7df49120eca7f",
"fee": "7000000",
"sigs": [
{
"xs": "030152d2d72e2dba7c6086ad49a219d9ff0dfe0fd993dcaea22e058c210033ce93",
"xs": "0384a71f13c434e79b70f9a0649e34887f1c6caf3021636cfced448a146ca23c7a",
"nonce": "031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f",
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841bdad934daa17db7e477c4eed90afed40d1117896df8c4f5861b6309a949878074"
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841b6485299a0be2e4306663dcc78f1bc9d029c7be30e423558fe3f4fcfc9ad79a8e"
}
],
"coms": [
Expand Down Expand Up @@ -262,17 +262,17 @@ pub trait ForeignRpc {
],
"fee": "7000000",
"id": "0436430c-2b02-624c-2032-570501212b00",
"off": "750dbf4fd43b7f4cfd68d2698a522f3ff6e6a00ad9895b33f1ec46493b837b49",
"off": "4940f497462b7140383738c1665fa3989e6fff5d9f411a33aa04438f75d6de2c",
"sigs": [
{
"nonce": "031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f",
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841bdad934daa17db7e477c4eed90afed40d1117896df8c4f5861b6309a949878074",
"xs": "030152d2d72e2dba7c6086ad49a219d9ff0dfe0fd993dcaea22e058c210033ce93"
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841b6485299a0be2e4306663dcc78f1bc9d029c7be30e423558fe3f4fcfc9ad79a8e",
"xs": "0384a71f13c434e79b70f9a0649e34887f1c6caf3021636cfced448a146ca23c7a"
},
{
"nonce": "031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f",
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841b35fdfe55271f2ae73d75f58c70d1efb69b3384c7bc507d57e99e56de77e20874",
"xs": "033bbe2a419ea2e9d6810a8d66552e709d1783ca50759a44dbaf63fc79c0164c4c"
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841b32617ea149fa6faf220f4212530517809e9ed2193f5e558b1de9d339414fda91",
"xs": "02e89cce4499ac1e9bb498dab9e3fab93cc40cd3d26c04a0292e00f4bf272499ec"
}
],
"sta": "I3",
Expand Down
40 changes: 19 additions & 21 deletions api/src/owner_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,15 +395,14 @@ pub trait OwnerRpc {
"amt": "6000000000",
"fee": "8000000",
"id": "0436430c-2b02-624c-2032-570501212b00",
"off": "d202964900000000d302964900000000d402964900000000d502964900000000",
"proof": {
"raddr": "32cdd63928854f8b2628b1dce4626ddcdf35d56cb7cfdf7d64cca5822b78d4d3",
"saddr": "32cdd63928854f8b2628b1dce4626ddcdf35d56cb7cfdf7d64cca5822b78d4d3"
},
"sigs": [
{
"nonce": "031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f",
"xs": "023878ce845727f3a4ec76ca3f3db4b38a2d05d636b8c3632108b857fed63c96de"
"xs": "02e89cce4499ac1e9bb498dab9e3fab93cc40cd3d26c04a0292e00f4bf272499ec"
}
],
"sta": "S1",
Expand Down Expand Up @@ -447,11 +446,10 @@ pub trait OwnerRpc {
"Ok": {
"amt": "6000000000",
"id": "0436430c-2b02-624c-2032-570501212b00",
"off": "d202964900000000d302964900000000d402964900000000d502964900000000",
"sigs": [
{
"nonce": "031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f",
"xs": "028e95921cc0d5be5922362265d352c9bdabe51a9e1502a3f0d4a10387f1893f40"
"xs": "02e89cce4499ac1e9bb498dab9e3fab93cc40cd3d26c04a0292e00f4bf272499ec"
}
],
"sta": "I1",
Expand Down Expand Up @@ -529,12 +527,12 @@ pub trait OwnerRpc {
],
"fee": "8000000",
"id": "0436430c-2b02-624c-2032-570501212b00",
"off": "9b6e26e78b49c7136ce70334dd83acb89c78f6c54cfab64ba62e598837241d36",
"off": "bca108f36955448dacfc0464d75d010641f9e1a81709c27bc4404eea895c4f91",
"sigs": [
{
"nonce": "031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f",
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841bf1804f6fe8e55f5556bbd807fefbcd72b30d90cf708f8c56447acc63228274e6",
"xs": "023878ce845727f3a4ec76ca3f3db4b38a2d05d636b8c3632108b857fed63c96de"
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841b20b8e09af72b6b7212c1bf6a4c17d56ce0048e05bb5309c1394a3d763a102a7e",
"xs": "02e3c128e436510500616fef3f9a22b15ca015f407c8c5cf96c9059163c873828f"
}
],
"sta": "I2",
Expand Down Expand Up @@ -616,12 +614,12 @@ pub trait OwnerRpc {
"ver": "4:2",
"id": "0436430c-2b02-624c-2032-570501212b00",
"sta": "S2",
"off": "a4052c9200000001a6052c9200000002ed564fab50b75fc5ea32ce052fc9bebf",
"off": "696a69136154775485782121887bb3c32487a8320551fdb9702ec2d333fe54ee",
"sigs": [
{
"xs": "033bbe2a419ea2e9d6810a8d66552e709d1783ca50759a44dbaf63fc79c0164c4c",
"xs": "0384a71f13c434e79b70f9a0649e34887f1c6caf3021636cfced448a146ca23c7a",
"nonce": "031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f",
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841b35fdfe55271f2ae73d75f58c70d1efb69b3384c7bc507d57e99e56de77e20874"
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841b6485299a0be2e4306663dcc78f1bc9d029c7be30e423558fe3f4fcfc9ad79a8e"
}
],
"coms": [
Expand Down Expand Up @@ -661,17 +659,17 @@ pub trait OwnerRpc {
],
"fee": "7000000",
"id": "0436430c-2b02-624c-2032-570501212b00",
"off": "750dbf4fd43b7f4cfd68d2698a522f3ff6e6a00ad9895b33f1ec46493b837b49",
"off": "4940f497462b7140383738c1665fa3989e6fff5d9f411a33aa04438f75d6de2c",
"sigs": [
{
"nonce": "031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f",
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841b35fdfe55271f2ae73d75f58c70d1efb69b3384c7bc507d57e99e56de77e20874",
"xs": "033bbe2a419ea2e9d6810a8d66552e709d1783ca50759a44dbaf63fc79c0164c4c"
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841b6485299a0be2e4306663dcc78f1bc9d029c7be30e423558fe3f4fcfc9ad79a8e",
"xs": "0384a71f13c434e79b70f9a0649e34887f1c6caf3021636cfced448a146ca23c7a"
},
{
"nonce": "031b84c5567b126440995d3ed5aaba0565d71e1834604819ff9c17f5e9d5dd078f",
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841bdad934daa17db7e477c4eed90afed40d1117896df8c4f5861b6309a949878074",
"xs": "030152d2d72e2dba7c6086ad49a219d9ff0dfe0fd993dcaea22e058c210033ce93"
"part": "8f07ddd5e9f5179cff19486034181ed76505baaad53e5d994064127b56c5841b32617ea149fa6faf220f4212530517809e9ed2193f5e558b1de9d339414fda91",
"xs": "02e89cce4499ac1e9bb498dab9e3fab93cc40cd3d26c04a0292e00f4bf272499ec"
}
],
"sta": "S3",
Expand Down Expand Up @@ -1626,11 +1624,11 @@ pub trait OwnerRpc {
"result": {
"Ok": {
"amount": "60000000000",
"excess": "091f151170bfac881479bfb56c7012c52cd4ce4198ad661586374dd499925922fb",
"excess": "09eac5f5872fa5e08e0c29fd900f1b8f77ff3ad1d0d1c46aeb202cbf92363fe0af",
"recipient_address": "tgrin10qlk22rxjap2ny8qltc2tl996kenxr3hhwuu6hrzs6tdq08yaqgqq6t83r",
"recipient_sig": "b9b1885a3f33297df32e1aa4db23220bd305da8ed92ff6873faf3ab2c116fea25e9d0e34bd4f567f022b88a37400821ffbcaec71c9a8c3a327c4626611886d0d",
"recipient_sig": "02868f2d2b983981f8f98043701687a8531ed2de564ea3df48e9e7e0229ccbe8359efe506896df2efbe3528e977252c50e4a41ca3cc9896e7c5a30bbb1d33604",
"sender_address": "tgrin1xtxavwfgs48ckf3gk8wwgcndmn0nt4tvkl8a7ltyejjcy2mc6nfs9gm2lp",
"sender_sig": "611b92331e395c3d29871ac35b1fce78ec595e28ccbe8cc55452da40775e8e46d35a2e84eaffd986935da3275e34d46a8d777d02dabcf4339704c2a621da9700"
"sender_sig": "c511764f3f61ed3d1cbca9514df8bc6811fad5662b1cb0e0587b9c9e49db9f33183cce71af6cb24b507fabf525a2bc405c6e84e63a60334edff0b451ae5e6102"
}
}
}
Expand Down Expand Up @@ -1659,11 +1657,11 @@ pub trait OwnerRpc {
"token": "d202964900000000d302964900000000d402964900000000d502964900000000",
"proof": {
"amount": "60000000000",
"excess": "091f151170bfac881479bfb56c7012c52cd4ce4198ad661586374dd499925922fb",
"excess": "09eac5f5872fa5e08e0c29fd900f1b8f77ff3ad1d0d1c46aeb202cbf92363fe0af",
"recipient_address": "slatepack10qlk22rxjap2ny8qltc2tl996kenxr3hhwuu6hrzs6tdq08yaqgqnlumr7",
"recipient_sig": "b9b1885a3f33297df32e1aa4db23220bd305da8ed92ff6873faf3ab2c116fea25e9d0e34bd4f567f022b88a37400821ffbcaec71c9a8c3a327c4626611886d0d",
"recipient_sig": "02868f2d2b983981f8f98043701687a8531ed2de564ea3df48e9e7e0229ccbe8359efe506896df2efbe3528e977252c50e4a41ca3cc9896e7c5a30bbb1d33604",
"sender_address": "slatepack1xtxavwfgs48ckf3gk8wwgcndmn0nt4tvkl8a7ltyejjcy2mc6nfskdvkdu",
"sender_sig": "611b92331e395c3d29871ac35b1fce78ec595e28ccbe8cc55452da40775e8e46d35a2e84eaffd986935da3275e34d46a8d777d02dabcf4339704c2a621da9700"
"sender_sig": "c511764f3f61ed3d1cbca9514df8bc6811fad5662b1cb0e0587b9c9e49db9f33183cce71af6cb24b507fabf525a2bc405c6e84e63a60334edff0b451ae5e6102"
}
},
"id": 1
Expand Down
2 changes: 2 additions & 0 deletions controller/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ pub struct SendArgs {
pub minimum_confirmations: u64,
pub selection_strategy: String,
pub estimate_selection_strategies: bool,
pub late_lock: bool,
pub dest: String,
pub change_outputs: usize,
pub fluff: bool,
Expand Down Expand Up @@ -307,6 +308,7 @@ where
payment_proof_recipient_address: args.payment_proof_address.clone(),
ttl_blocks: args.ttl_blocks,
send_args: None,
late_lock: Some(args.late_lock),
..Default::default()
};
let result = api.init_send_tx(m, init_args);
Expand Down
163 changes: 163 additions & 0 deletions controller/tests/late_lock.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
// Copyright 2020 The Grin Developers
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

//! Tests and experimentations with late locking
#[macro_use]
extern crate log;
extern crate grin_wallet_controller as wallet;
extern crate grin_wallet_impls as impls;
extern crate grin_wallet_libwallet as libwallet;

use self::libwallet::{InitTxArgs, Slate};
use impls::test_framework::{self, LocalWalletClient};
use std::sync::atomic::Ordering;
use std::thread;
use std::time::Duration;

#[macro_use]
mod common;
use common::{clean_output_dir, create_wallet_proxy, setup};

/// self send impl
fn late_lock_test_impl(test_dir: &'static str) -> Result<(), libwallet::Error> {
// Create a new proxy to simulate server and wallet responses
let mut wallet_proxy = create_wallet_proxy(test_dir);
let chain = wallet_proxy.chain.clone();
let stopper = wallet_proxy.running.clone();

// Create a new wallet test client, and set its queues to communicate with the
// proxy
create_wallet_and_add!(
client1,
wallet1,
mask1_i,
test_dir,
"wallet1",
None,
&mut wallet_proxy,
false
);
let mask1 = (&mask1_i).as_ref();
create_wallet_and_add!(
client2,
wallet2,
mask2_i,
test_dir,
"wallet2",
None,
&mut wallet_proxy,
false
);
let mask2 = (&mask2_i).as_ref();

// Set the wallet proxy listener running
thread::spawn(move || {
if let Err(e) = wallet_proxy.run() {
error!("Wallet Proxy error: {}", e);
}
});

// add some accounts
wallet::controller::owner_single_use(Some(wallet1.clone()), mask1, None, |api, m| {
api.create_account_path(m, "mining")?;
api.create_account_path(m, "listener")?;
Ok(())
})?;

// add some accounts
wallet::controller::owner_single_use(Some(wallet2.clone()), mask2, None, |api, m| {
api.create_account_path(m, "account1")?;
api.create_account_path(m, "account2")?;
Ok(())
})?;

// Get some mining done
{
wallet_inst!(wallet1, w);
w.set_parent_key_id_by_name("mining")?;
}
{
wallet_inst!(wallet2, w);
w.set_parent_key_id_by_name("account1")?;
}

let bh = 10u64;
let _ =
test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, bh as usize, false);

let mut slate = Slate::blank(2, false);
let amount = 60_000_000_000;

wallet::controller::owner_single_use(Some(wallet1.clone()), mask1, None, |sender_api, m| {
let args = InitTxArgs {
src_acct_name: Some("mining".to_owned()),
amount,
minimum_confirmations: 2,
max_outputs: 500,
num_change_outputs: 1,
selection_strategy_is_use_all: false,
late_lock: Some(true),
..Default::default()
};
let slate_i = sender_api.init_send_tx(m, args)?;
println!("S1 SLATE: {}", slate_i);
slate = client1.send_tx_slate_direct("wallet2", &slate_i)?;
println!("S2 SLATE: {}", slate);

// Note we don't call `tx_lock_outputs` on the sender side here,
// as the outputs will only be locked during finalization

slate = sender_api.finalize_tx(m, &slate)?;
println!("S3 SLATE: {}", slate);

Ok(())
})?;

let _ = test_framework::award_blocks_to_wallet(&chain, wallet1.clone(), mask1, 3, false);

// update/test contents of both accounts
wallet::controller::owner_single_use(Some(wallet1.clone()), mask1, None, |api, m| {
let (wallet1_refreshed, wallet_info) = api.retrieve_summary_info(m, true, 1)?;
assert!(wallet1_refreshed);
print!(
"Wallet 1 amount: {}",
wallet_info.amount_currently_spendable
);
Ok(())
})?;

wallet::controller::owner_single_use(Some(wallet2.clone()), mask2, None, |api, m| {
let (wallet2_refreshed, wallet_info) = api.retrieve_summary_info(m, true, 1)?;
assert!(wallet2_refreshed);
println!(
"Wallet 2 amount: {}",
wallet_info.amount_currently_spendable
);
Ok(())
})?;

// let logging finish
stopper.store(false, Ordering::Relaxed);
thread::sleep(Duration::from_millis(200));
Ok(())
}

#[test]
fn late_lock() {
let test_dir = "test_output/late_lock";
setup(test_dir);
if let Err(e) = late_lock_test_impl(test_dir) {
panic!("Libwallet Error: {} - {}", e, e.backtrace().unwrap());
}
clean_output_dir(test_dir);
}
6 changes: 6 additions & 0 deletions libwallet/src/api_impl/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ where
use_test_rng,
)?;

// Add our contribution to the offset
ret_slate.adjust_offset(&keychain, &context)?;

let excess = ret_slate.calc_excess(keychain.secp())?;

if let Some(ref mut p) = ret_slate.payment_proof {
Expand Down Expand Up @@ -143,6 +146,9 @@ where
if sl.state == SlateState::Invoice2 {
check_ttl(w, &sl)?;

// Add our contribution to the offset
sl.adjust_offset(&w.keychain(keychain_mask)?, &context)?;

let mut temp_ctx = context.clone();
temp_ctx.sec_key = context.initial_sec_key.clone();
temp_ctx.sec_nonce = context.initial_sec_nonce.clone();
Expand Down
Loading