Skip to content

Commit

Permalink
Merge pull request zingolabs#634 from zancas/better_scan_handling_in_…
Browse files Browse the repository at this point in the history
…send_addresses_inner

fix premature utxo confirmation
  • Loading branch information
Oscar-Pepper authored Oct 27, 2023
2 parents b93c7b2 + b30dbbb commit fe9a81d
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 5 deletions.
31 changes: 31 additions & 0 deletions zingocli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,37 @@ fn check_view_capability_bounds(
mod fast {
use super::*;
#[tokio::test]
async fn utxos_are_not_prematurely_confirmed() {
let (regtest_manager, _cph, faucet, recipient) =
scenarios::faucet_recipient_default().await;
faucet
.do_send(vec![(
&get_base_address!(recipient, "transparent"),
100_000,
None,
)])
.await
.unwrap();
increase_height_and_wait_for_client(&regtest_manager, &recipient, 1)
.await
.unwrap();
let preshield_utxos = dbg!(recipient.wallet.get_utxos().await);
recipient
.do_shield(&[Pool::Transparent], None)
.await
.unwrap();
let postshield_utxos = dbg!(recipient.wallet.get_utxos().await);
assert_eq!(preshield_utxos[0].address, postshield_utxos[0].address);
assert_eq!(
preshield_utxos[0].output_index,
postshield_utxos[0].output_index
);
assert_eq!(preshield_utxos[0].value, postshield_utxos[0].value);
assert_eq!(preshield_utxos[0].script, postshield_utxos[0].script);
assert!(preshield_utxos[0].unconfirmed_spent.is_none());
assert!(postshield_utxos[0].unconfirmed_spent.is_some());
}
#[tokio::test]
async fn send_without_reorg_buffer_blocks_gives_correct_error() {
let (_regtest_manager, _cph, faucet, mut recipient) =
scenarios::faucet_recipient_default().await;
Expand Down
15 changes: 11 additions & 4 deletions zingolib/src/blaze/fetch_full_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,10 +309,17 @@ impl TransactionContext {
// Mark that this Tx spent some funds
*is_outgoing_transaction = true;

self.transaction_metadata_set
.write()
.await
.mark_txid_utxo_spent(prev_transaction_id, prev_n, transaction_id, height.into());
if !unconfirmed {
self.transaction_metadata_set
.write()
.await
.mark_txid_utxo_spent(
prev_transaction_id,
prev_n,
transaction_id,
height.into(),
);
}
}

// If this transaction spent value, add the spent amount to the TxID
Expand Down
2 changes: 1 addition & 1 deletion zingolib/src/wallet/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ pub(crate) fn write_sapling_rseed<W: Write>(
}
}

#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq)]
pub struct ReceivedTransparentOutput {
pub address: String,
pub txid: TxId,
Expand Down

0 comments on commit fe9a81d

Please sign in to comment.