Skip to content

ddk-manager: splice offers that spend several contracts - #235

Open
matthewjablack wants to merge 1 commit into
bennyhodl:masterfrom
matthewjablack:feat/merge-splice-offer
Open

matthewjablack wants to merge 1 commit into
bennyhodl:masterfrom
matthewjablack:feat/merge-splice-offer

Conversation

@matthewjablack

Copy link
Copy Markdown
Contributor

Summary

A splice offer can now spend several Confirmed contracts at once, merging them into one contract.

  • Manager::send_merge_splice_offer and send_merge_splice_offer_with_announcements take a slice of contract ids and build one offer with one DLC input per contract.
  • send_splice_offer_with_announcements delegates to the new method with a one-element slice, so the single-contract path is unchanged.
  • A contract named twice, an unknown or non-Confirmed contract, a contract with another counterparty, or an empty list is refused with InvalidParameters / InvalidState before anything is reserved or persisted.

Everything downstream of the offer already handled a list of DLC inputs: PartyParams::dlc_inputs is a Vec, create_spliced_dlc_transactions appends every one, the sign and verify steps loop per funding input, and preclose_spliced_contracts pre-closes every contract a splice funding transaction spends. The only single-contract spot was the offer entry point, since SignedContract::get_dlc_input is crate-private.

Tests

manager_execution_tests gets a MergeSplice path: fund a second contract, merge both, settle the merged contract. It asserts the merged funding transaction spends both prior funding outputs, the offer carries one DLC input per prior contract, both prior contracts go PreClosed on sign and Closed against the merged funding transaction on confirm, the splicing party's wallet pays only the fee, a replaced contract cannot be spliced again alone or in another merge, and the merged contract settles from either party.

  • merge_splice_enum_single_oracle_test
  • merge_splice_enum_single_oracle_by_accept_party_test (the acceptor of both contracts offers the merge, so its key is the remote key on both inputs)
  • merge_splice_numerical_3_of_3_test

Run locally with the test env, all three pass, as does splice_in_enum_single_oracle_test for the delegating path. cargo clippy -p ddk-manager -- -D warnings and cargo fmt --check are clean.

Why

Lygos wants to merge two live loans into one lock without settling either on chain first. The contracts and enclave already treat every funding input as a possible prior claim, so the only missing piece was an offer that names more than one.

Add send_merge_splice_offer and send_merge_splice_offer_with_announcements,
which build one offer whose funding transaction spends the funding outputs
of several Confirmed contracts at once. The single-contract splice methods
now delegate to them. A contract may be named only once, every one must be
Confirmed with the counterparty, and an empty list is refused.

The rest of the splice path already handled a list of DLC inputs: funding
transaction construction, per-input signing and verification, and
pre-closing every spent contract once the splice is seen. Only the offer
entry point took a single contract id.

Tests drive two confirmed contracts through a merge and assert the merged
funding transaction spends both, both prior contracts close against it,
and the merged contract settles.
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.

1 participant