Repository navigation
messaging, core: PayoutScriptOverrides on DlcOffer, following dlcdevkit #224 - #242
Open
matthewjablack wants to merge 9 commits into
Open
matthewjablack wants to merge 9 commits into
matthewjablack wants to merge 9 commits into
Conversation
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the
PayoutScriptOverridesTLV onDlcOffer, 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 writtenoffer = 0, accept = totalpays 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
startandendas 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.validaterejects 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,dualFundingCoinSelectandcalculateMaxCollateraltake the extra bytes as an optional argument. Offers without overrides fund exactly as before.Things to know:
toJSONandfromJSONdon't carry TLVs, this one included, same as before.Messaging and core tests, lint and build pass.