mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-26 17:52:25 +01:00
contractcourt: split commit blob into settled vs breached
For the breach case, we'll have more than one output to sweep. So we'll need more than one blob to use.
This commit is contained in:
parent
e01e2be459
commit
85e288d1fd
@ -1558,7 +1558,7 @@ func encodeTaprootAuxData(w io.Writer, c *ContractResolutions) error {
|
||||
tapCase.CtrlBlocks.Val.CommitSweepCtrlBlock = commitSignDesc.ControlBlock
|
||||
|
||||
c.CommitResolution.ResolutionBlob.WhenSome(func(b []byte) {
|
||||
tapCase.CommitBlob = tlv.SomeRecordT(
|
||||
tapCase.SettledCommitBlob = tlv.SomeRecordT(
|
||||
tlv.NewPrimitiveRecord[tlv.TlvType2](b),
|
||||
)
|
||||
})
|
||||
@ -1649,7 +1649,7 @@ func decodeTapRootAuxData(r io.Reader, c *ContractResolutions) error {
|
||||
c.CommitResolution.SelfOutputSignDesc.ControlBlock =
|
||||
tapCase.CtrlBlocks.Val.CommitSweepCtrlBlock
|
||||
|
||||
tapCase.CommitBlob.WhenSomeV(func(b []byte) {
|
||||
tapCase.SettledCommitBlob.WhenSomeV(func(b []byte) {
|
||||
c.CommitResolution.ResolutionBlob = fn.Some(b)
|
||||
})
|
||||
}
|
||||
|
@ -30,10 +30,16 @@ type taprootBriefcase struct {
|
||||
// revocation paths.
|
||||
TapTweaks tlv.RecordT[tlv.TlvType1, tapTweaks]
|
||||
|
||||
// CommitBlob is an optional record that contains an opaque blob that
|
||||
// may be used to properly sweep commitment outputs on a force close
|
||||
// transaction.
|
||||
CommitBlob tlv.OptionalRecordT[tlv.TlvType2, tlv.Blob]
|
||||
// SettledCommitBlob is an optional record that contains an opaque blob
|
||||
// that may be used to properly sweep commitment outputs on a force
|
||||
// close transaction.
|
||||
SettledCommitBlob tlv.OptionalRecordT[tlv.TlvType2, tlv.Blob]
|
||||
|
||||
// BreachCommitBlob is an optional record that contains an opaque blob
|
||||
// used to sweep a remote party's breached output.
|
||||
BreachedCommitBlob tlv.OptionalRecordT[tlv.TlvType3, tlv.Blob]
|
||||
|
||||
// TODO(roasbeef): htlc blobs
|
||||
}
|
||||
|
||||
// TODO(roasbeef): morph into new tlv record
|
||||
@ -53,9 +59,16 @@ func (t *taprootBriefcase) EncodeRecords() []tlv.Record {
|
||||
t.CtrlBlocks.Record(), t.TapTweaks.Record(),
|
||||
}
|
||||
|
||||
t.CommitBlob.WhenSome(func(r tlv.RecordT[tlv.TlvType2, tlv.Blob]) {
|
||||
records = append(records, r.Record())
|
||||
})
|
||||
t.SettledCommitBlob.WhenSome(
|
||||
func(r tlv.RecordT[tlv.TlvType2, tlv.Blob]) {
|
||||
records = append(records, r.Record())
|
||||
},
|
||||
)
|
||||
t.BreachedCommitBlob.WhenSome(
|
||||
func(r tlv.RecordT[tlv.TlvType3, tlv.Blob]) {
|
||||
records = append(records, r.Record())
|
||||
},
|
||||
)
|
||||
|
||||
return records
|
||||
}
|
||||
@ -79,8 +92,12 @@ func (t *taprootBriefcase) Encode(w io.Writer) error {
|
||||
|
||||
// Decode decodes the given reader into the target struct.
|
||||
func (t *taprootBriefcase) Decode(r io.Reader) error {
|
||||
commitBlob := t.CommitBlob.Zero()
|
||||
records := append(t.DecodeRecords(), commitBlob.Record())
|
||||
settledCommitBlob := t.SettledCommitBlob.Zero()
|
||||
breachedCommitBlob := t.BreachedCommitBlob.Zero()
|
||||
records := append(
|
||||
t.DecodeRecords(), settledCommitBlob.Record(),
|
||||
breachedCommitBlob.Record(),
|
||||
)
|
||||
stream, err := tlv.NewStream(records...)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -91,8 +108,11 @@ func (t *taprootBriefcase) Decode(r io.Reader) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if val, ok := typeMap[t.CommitBlob.TlvType()]; ok && val == nil {
|
||||
t.CommitBlob = tlv.SomeRecordT(commitBlob)
|
||||
if val, ok := typeMap[t.SettledCommitBlob.TlvType()]; ok && val == nil {
|
||||
t.SettledCommitBlob = tlv.SomeRecordT(settledCommitBlob)
|
||||
}
|
||||
if v, ok := typeMap[t.BreachedCommitBlob.TlvType()]; ok && v == nil {
|
||||
t.BreachedCommitBlob = tlv.SomeRecordT(breachedCommitBlob)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -87,9 +87,12 @@ func TestTaprootBriefcase(t *testing.T) {
|
||||
BreachedHtlcTweaks: randHtlcTweaks(t),
|
||||
BreachedSecondLevelHltcTweaks: randHtlcTweaks(t),
|
||||
}),
|
||||
CommitBlob: tlv.SomeRecordT(
|
||||
SettledCommitBlob: tlv.SomeRecordT(
|
||||
tlv.NewPrimitiveRecord[tlv.TlvType2](commitBlob[:]),
|
||||
),
|
||||
BreachedCommitBlob: tlv.SomeRecordT(
|
||||
tlv.NewPrimitiveRecord[tlv.TlvType3](commitBlob[:]),
|
||||
),
|
||||
}
|
||||
|
||||
var b bytes.Buffer
|
||||
|
Loading…
x
Reference in New Issue
Block a user