Skip to content

Propose co spends #12

Merged
arminsabouri merged 18 commits intomasterfrom
create-co-spends
Apr 13, 2026
Merged

Propose co spends #12
arminsabouri merged 18 commits intomasterfrom
create-co-spends

Conversation

@arminsabouri
Copy link
Copy Markdown
Collaborator

All order book entries are considered atm. Takers will want to be selective and assign a payoff to each order book entry. At somepoint the cospend will be "good enough" (this will vary by wallet preference). Makers will register their input. The cost should consider their current payment obligation's deadlines.

In this current state the taker will prefer orderbook inputs that are closer in magnitude to its own inputs that it picked. I think we are missing two angles here:

  • Takers run BNB and then consider orderbook utxos. But they could pick other utxos that BNB would not select that would be "closer" to the a subset of order utxos.
  • Maybe there are no good order book utxos. The cost needs to be considered and if its high enough the take should then prefer a unilateral batch.

other todos (maybe for future Prs):

  • change decomposition
  • counter party payoffs (how much does a taker prefer a orderbook utxo -- privacy budget)
  • ensuring monotonic decreasing cost as information is learned. Given the inputs in the cost spend and my own decomposition, I should be happy with subset sum density. And new information (output registration) should not worsen subset sum desnsity. TBD

@0xZaddyy
Copy link
Copy Markdown
Contributor

Everything is looking good right now, just few things we might consider adding:
in the cospend.rs file, the generate_candidates function assumes all entries are valid

  • i think adding a filter to check for spent/invalid UTXOs before scoring will be necesaary.
  • also a check for duplicates if a UTXO appears multiple times in order book.

The taker/maker separation is clean and the scoring logic makes sense.

@arminsabouri arminsabouri force-pushed the create-co-spends branch 2 times, most recently from 0783917 to 3fb4271 Compare April 2, 2026 20:31
@arminsabouri
Copy link
Copy Markdown
Collaborator Author

went thru a messy rebase bc of #14 . will look thru history and clean it up again

@arminsabouri arminsabouri force-pushed the create-co-spends branch 7 times, most recently from 885e280 to 7e3e43f Compare April 10, 2026 12:55
Given an order book of UTXOs and a takers utxos which
order book utxos we generate a list of cospends candidates.
This action costs more if you have payment obligations. Or
if you already have a input registered. In the future this can be
smarter and internalize the cost of registering specific inputs with
respect to the po's and privacy budget.
As its replaced by create cospend. 
And explicitly assign cost to accepting the co spend.
Return registered inputs from order book
Mark po's as success if they are handled in the a cospend.
This commit also folds all action outcomes into on Outcome struct which
defines how the wallet state has changes. This allows us to reconcile cost terms
to one metacost function and eval global wallet changes in one place.
As its replaced by create cospend methods
First run all unilateral actions available to a strategy, find what inputs are
common in all plans, register than inputs.
Comment thread src/wallet.rs Outdated
Comment thread src/actions.rs
BatchSpend(Vec<PaymentObligationId>),
/// Pay a payment obligation while consolidating all UTXOs into change
ConsolidateSelf(PaymentObligationId),
UnilateralPayments(Vec<PaymentObligationId>, CoinSelectionStrategy),
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For future work: This may need happen at two level:
generate different alt payment sequences
and then if these look good then we decide on coin selection.

You may want to consider different coin selection strats for a specific payment.

Comment thread src/actions.rs
BatchSpend(Vec<PaymentObligationId>),
/// Pay a payment obligation while consolidating all UTXOs into change
ConsolidateSelf(PaymentObligationId),
UnilateralPayments(Vec<PaymentObligationId>, CoinSelectionStrategy),
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This action should fully define what inputs are going to be spent. Coinselection strat should be evaluate before

Comment thread src/actions.rs
.collect()
})
.collect();
let common_input: Option<Outpoint> = per_action_spent
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO comment for picking your "luckiest" coins per the random beacon strategy https://gist.github.com/nothingmuch/f5b9a559958c6116606d9da0d4d884f2

Comment thread src/actions.rs
.collect()
})
.collect();
let common_input: Option<Outpoint> = per_action_spent
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The distinction between maker and taker should be removed.

Orderbook utxos are utxos that capture some metadata including:
amount and owner.
@arminsabouri arminsabouri marked this pull request as ready for review April 13, 2026 18:54
@arminsabouri
Copy link
Copy Markdown
Collaborator Author

In its current state this PR implements the maker, taker and aggregator roles.
Makers simulate their unilateral behavior, pick common inputs and register them. Takers Pick all orderbook utxos and init a cospend proposals. These are non-commital actions. Aggregator will wait until there are cospends and send agg proposals. From there its the same tx construction state machine. This is the most naive and leaks the most about the wallets preferences. Since this PR refactors as well as adds new features I will merge this and iterate on it.

@arminsabouri arminsabouri merged commit 10c385b into master Apr 13, 2026
1 check passed
@arminsabouri arminsabouri deleted the create-co-spends branch April 13, 2026 19:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants