Skip to content

Commit b3927e4

Browse files
committed
Filter out spent inputs from orderbook
Confirmed or broadcasted
1 parent 72c5304 commit b3927e4

3 files changed

Lines changed: 21 additions & 4 deletions

File tree

cospend.toml.example

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[simulation]
22
seed = 42
3-
max_timestep = 40
4-
num_payment_obligations = 10
3+
max_timestep = 15
4+
num_payment_obligations = 5
55

66
# Takers: have payment obligations, build cospend proposals using the order book
77
[[wallet_types]]
@@ -30,6 +30,7 @@ payment_obligation_weight = 1.0
3030
coordination_weight = 2.0
3131

3232
# Aggregators: create aggregate proposals from pending interests
33+
# For now they are a distinct role that should not have payment obligations
3334
[[wallet_types]]
3435
name = "aggregator"
3536
count = 1

src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,10 @@ impl<'a> Simulation {
608608
let info = &self.wallet_info[wallet.last_wallet_info_id.0];
609609
info.registered_inputs
610610
.iter()
611-
.filter(|outpoint| info.confirmed_utxos.contains(outpoint))
611+
.filter(|outpoint| {
612+
info.confirmed_utxos.contains(outpoint)
613+
&& !info.unconfirmed_spends.contains(outpoint)
614+
})
612615
.map(|outpoint| UtxoWithMetadata {
613616
outpoint: *outpoint,
614617
amount: outpoint.with(self).data().amount,

src/wallet.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,10 @@ impl<'a> WalletHandleMut<'a> {
467467
BroadcastMessageType::ContributeInputs(op) => Some(op),
468468
_ => None,
469469
})
470-
.filter(|op| self.info().confirmed_utxos.contains(op))
470+
.filter(|op| {
471+
self.info().confirmed_utxos.contains(op)
472+
&& !self.info().unconfirmed_spends.contains(op)
473+
})
471474
.map(|op| Input { outpoint: *op })
472475
.collect();
473476
self.info_mut().active_multi_party_payjoins.insert(
@@ -495,6 +498,16 @@ impl<'a> WalletHandleMut<'a> {
495498
.iter()
496499
.flat_map(|i| i.utxos.iter())
497500
.filter(|u| seen_outpoints.insert(u.outpoint))
501+
// Skip UTXOs that have been spent since the interest was recorded.
502+
// Interests are non-committal and may go stale between proposal and
503+
// aggregation (e.g. the owner spent the coin unilaterally in the same
504+
// tick before the aggregator ran).
505+
.filter(|u| {
506+
let info = &self.sim.wallet_info
507+
[self.sim.wallet_data[u.owner.0].last_wallet_info_id.0];
508+
info.confirmed_utxos.contains(&u.outpoint)
509+
&& !info.unconfirmed_spends.contains(&u.outpoint)
510+
})
498511
.collect();
499512
// Pre-fill all unique inputs on the bulletin board
500513
for u in &unique_utxos {

0 commit comments

Comments
 (0)