Skip to content

Commit

Permalink
lock output on mwixnet creation, add further testing
Browse files Browse the repository at this point in the history
  • Loading branch information
yeastplume committed Sep 3, 2024
1 parent fc33d9b commit 4555b1e
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
4 changes: 2 additions & 2 deletions api/src/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -837,11 +837,11 @@ where
keychain_mask: Option<&SecretKey>,
params: &MixnetReqCreationParams,
commitment: &pedersen::Commitment,
// use_test_rng: bool,
lock_output: bool, // use_test_rng: bool,
) -> Result<SwapReq, Error> {
let mut w_lock = self.wallet_inst.lock();
let w = w_lock.lc_provider()?.wallet_inst()?;
owner::create_mwixnet_req(&mut **w, keychain_mask, params, commitment)
owner::create_mwixnet_req(&mut **w, keychain_mask, params, commitment, lock_output)
}

/// Processes an invoice tranaction created by another party, essentially
Expand Down
9 changes: 8 additions & 1 deletion controller/tests/contract_srs_mwmixnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,16 @@ fn contract_srs_mwixnet_tx_impl(test_dir: &'static str) -> Result<(), libwallet:
// get last output
let last_output = outputs.1[outputs.1.len() - 1].clone();

let mwixnet_req = api.create_mwixnet_req(m, &params, &last_output.commit)?;
let mwixnet_req = api.create_mwixnet_req(m, &params, &last_output.commit, true)?;

println!("MWIXNET REQ: {:?}", mwixnet_req);

// check output we created comsig for is indeed locked
let outputs = api.retrieve_outputs(recv_mask, false, false, None)?;
// get last output
let last_output = outputs.1[outputs.1.len() - 1].clone();
assert!(last_output.output.status == libwallet::OutputStatus::Locked);

Ok(())
})?;

Expand Down
12 changes: 10 additions & 2 deletions libwallet/src/api_impl/owner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,7 @@ pub fn create_mwixnet_req<'a, T: ?Sized, C, K>(
keychain_mask: Option<&SecretKey>,
params: &MixnetReqCreationParams,
commitment: &pedersen::Commitment,
lock_output: bool,
) -> Result<SwapReq, Error>
where
T: WalletBackend<'a, C, K>,
Expand Down Expand Up @@ -1682,7 +1683,14 @@ where
let onion = create_onion(&commitment, &hops).unwrap();
let comsig = ComSignature::sign(amount, &input_blind, &onion.serialize().unwrap()).unwrap();

Ok(SwapReq { comsig, onion })
// Lock output if requested
if lock_output {
let mut batch = w.batch(keychain_mask)?;
let mut update_output = batch.get(&output.as_ref().unwrap().key_id, &None)?;
update_output.lock();
batch.lock_output(&mut update_output)?;
batch.commit()?;
}

//slate.find_index_matching_context(&keychain, &context)
Ok(SwapReq { comsig, onion })
}
6 changes: 3 additions & 3 deletions libwallet/src/internal/selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ where
sender_address: sender_address.to_ed25519()?,
sender_address_path,
sender_signature: None,
/// TODO: Will fill these as separate steps for now, check whether this
/// can be merged in a general case (which means knowing which nonces here belong to
/// the recipient)
// TODO: Will fill these as separate steps for now, check whether this
// can be merged in a general case (which means knowing which nonces here belong to
// the recipient)
proof_type: None,
receiver_public_nonce: None,
receiver_public_excess: None,
Expand Down

0 comments on commit 4555b1e

Please sign in to comment.