Skip to content

messaging, core: PayoutScriptOverrides on DlcOffer, following dlcdevkit #224 - #242

Open
matthewjablack wants to merge 9 commits into
masterfrom
feat/payout-script-overrides
Open

matthewjablack wants to merge 9 commits into
masterfrom
feat/payout-script-overrides

Conversation

@matthewjablack

@matthewjablack matthewjablack commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Adds the PayoutScriptOverrides TLV on DlcOffer, type 65005, following the rules dlcdevkit merged in bennyhodl/dlcdevkit#224. An override names an enum outcome or an inclusive range of numeric values, and each CET it covers pays the override script in place of the accepter's payout script. Amounts stay in the descriptor. In a loan the accepter is the lender, so a liquidation outcome written offer = 0, accept = total pays the liquidator in the lender's place.

Wire format. Same as dlc-messages: a BigSize count, then per entry a u8 variant (0 enum, 1 numeric), the variant body (a BigSize-prefixed UTF-8 outcome, or start and end as u64), and a u16-prefixed script. The test pins the bytes dlcdevkit pins. Decoding rejects an unknown variant, trailing bytes and invalid UTF-8, and keeps a leading byte order mark as dlcdevkit does.

Offer checks. An offer with two records of the type fails to deserialize, since dlcdevkit reads the first copy and node-dlc used to read the last. DlcOffer.validate rejects an empty script, a range that starts after it ends, an override covering no CET, two overrides on one CET, and an enum CET that pays the accepter under the 1000-sat dust limit, across every contract info of a disjoint contract. For a numeric range it only checks that a numeric descriptor exists: which CETs the range covers, and whether it covers any only in part, depends on dlcdevkit's range payouts, which node-dlc doesn't compute, so that is checked where the CETs are built.

Fees. An override script can be longer than the accepter's payout script, e.g. a liquidator's taproot address for a P2WPKH lender. As in dlcdevkit, the CET fee for the accepter's output is reserved at the longest of the two. Each extra byte is one vbyte, paid by the accepter when it funds and by the offerer when it funds alone. In a batch each funding output carries its own contract's extra. dualFees, dualFundingCoinSelect and calculateMaxCollateral take the extra bytes as an optional argument. Offers without overrides fund exactly as before.

Things to know:

  • For one dual-funded contract this matches dlcdevkit byte for byte. A single-funded contract already funded differently from dlcdevkit before this PR: node-dlc never prices the counterparty's output. The override increment is the same on both sides, but the base fee isn't. Full parity would be a separate change.
  • dlcdevkit's manager now rejects offer TLV types the application hasn't allowed, so dlcd-rs has to allow 65005 to accept these offers.
  • toJSON and fromJSON don't carry TLVs, this one included, same as before.

Messaging and core tests, lint and build pass.

Names the enum outcomes whose CET pays a script other than the offerer's, so
a liquidated-by-<address> outcome can pay the liquidator's Bitcoin address.
Type 65005, same wire format as the ddk-messages record, with the bytes
pinned in a test on both sides.

The offer reads it back as a typed field instead of an unknown TLV, writes it
in the TLV stream, and includes it in toJSON's tlvs.
dlcdevkit #224 changed the record: an override now names an enum outcome
or an inclusive numeric range, written as a u8 variant then the outcome
or two u64s, and pays in place of the accepter. The encoder follows it and
the test pins the bytes dlcdevkit pins.

DlcOffer rejects a second record of the type, since dlcdevkit reads the
first copy and node-dlc the last. validate checks what the offer can show:
an empty script, a range that starts after it ends, an override covering
no CET, two overrides on one CET, and an enum CET paying the accepter
under the dust limit. Which CETs a numeric range covers is checked where
the CETs are built.
An override script can be longer than the accepter's payout script, a
liquidator's taproot address for a P2WPKH lender. dlcdevkit reserves the
accepter's CET fee at the longest of the two, so the funding transaction
does the same here and an overridden CET keeps the offer's fee rate.
dlcdevkit refuses one when it reads the record, so node-dlc no longer
decodes it with replacement characters.
When the accepter funds nothing it pays no fees here, so a longer override
script left the overridden CET under the offer's fee rate. dlcdevkit has
the party paying for the accepter's output pay the difference, so the
offerer reserves the bytes beyond the accepter's payout script. Offers
without overrides fund as before.
TextDecoder drops one by default, so an outcome starting with U+FEFF came
back as a different string than dlcdevkit reads.
A batch charged every contract for the longest override on any of them,
and the coin selection and max collateral helpers left the override bytes
out, so an offer could select too little to fund. The finalizer now takes
the extra override bytes summed over the batch, each funding output
carries its own contract's share, and dualFees, dualFundingCoinSelect and
calculateMaxCollateral take the bytes as an optional argument.
@matthewjablack matthewjablack changed the title messaging: add the PayoutScriptOverrides TLV on DlcOffer messaging, core: PayoutScriptOverrides on DlcOffer, following dlcdevkit #224 Nov 3, 2026
Adds dlcdevkit's enum_dual_funded offer fixture with a PayoutScriptOverrides
record that dlcdevkit set and encoded, and checks node-dlc decodes it,
validates it and re-encodes the same bytes.
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