input: add ResolutionBlob method to inputKit

We also update breachedOutput w/ the new API.
This commit is contained in:
Olaoluwa Osuntokun 2024-06-03 23:02:57 -07:00
parent 3f50339898
commit bf3cf9ef3c
No known key found for this signature in database
GPG Key ID: 3BBD59E99B280306
2 changed files with 48 additions and 7 deletions

View File

@ -15,6 +15,7 @@ import (
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/chainntnfs"
"github.com/lightningnetwork/lnd/channeldb"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/input"
"github.com/lightningnetwork/lnd/kvdb"
"github.com/lightningnetwork/lnd/labels"
@ -22,6 +23,7 @@ import (
"github.com/lightningnetwork/lnd/lnutils"
"github.com/lightningnetwork/lnd/lnwallet"
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
"github.com/lightningnetwork/lnd/tlv"
)
const (
@ -1067,6 +1069,10 @@ type breachedOutput struct {
secondLevelTapTweak [32]byte
witnessFunc input.WitnessGenerator
resolutionBlob fn.Option[tlv.Blob]
// TODO(roasbeef): function opt and hook into brar
}
// makeBreachedOutput assembles a new breachedOutput that can be used by the
@ -1174,6 +1180,12 @@ func (bo *breachedOutput) UnconfParent() *input.TxInfo {
return nil
}
// ResolutionBlob returns a special opaque blob to be used to sweep/resolve this
// input.
func (bo *breachedOutput) ResolutionBlob() fn.Option[tlv.Blob] {
return bo.resolutionBlob
}
// Add compile-time constraint ensuring breachedOutput implements the Input
// interface.
var _ input.Input = (*breachedOutput)(nil)

View File

@ -6,7 +6,9 @@ import (
"github.com/btcsuite/btcd/btcutil"
"github.com/btcsuite/btcd/txscript"
"github.com/btcsuite/btcd/wire"
"github.com/lightningnetwork/lnd/fn"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/tlv"
)
// EmptyOutPoint is a zeroed outpoint.
@ -63,6 +65,10 @@ type Input interface {
// UnconfParent returns information about a possibly unconfirmed parent
// tx.
UnconfParent() *TxInfo
// ResolutionBlob returns a special opaque blob to be used to
// sweep/resolve this input.
ResolutionBlob() fn.Option[tlv.Blob]
}
// TxInfo describes properties of a parent tx that are relevant for CPFP.
@ -106,6 +112,10 @@ type inputKit struct {
// unconfParent contains information about a potential unconfirmed
// parent transaction.
unconfParent *TxInfo
// resolutionBlob is an optional blob that can be used to resolve an
// input.
resolutionBlob fn.Option[tlv.Blob]
}
// OutPoint returns the breached output's identifier that is to be included as
@ -156,8 +166,17 @@ func (i *inputKit) UnconfParent() *TxInfo {
return i.unconfParent
}
// inputOpts holds options for the input.
// ResolutionBlob returns a special opaque blob to be used to sweep/resolve
// this input.
func (i *inputKit) ResolutionBlob() fn.Option[tlv.Blob] {
return i.resolutionBlob
}
// inputOpts contains options for constructing a new input.
type inputOpts struct {
// resolutionBlob is an optional blob that can be used to resolve an
// input.
resolutionBlob fn.Option[tlv.Blob]
}
// defaultInputOpts returns a new inputOpts with default values.
@ -165,9 +184,18 @@ func defaultInputOpts() *inputOpts {
return &inputOpts{}
}
// InputOpt is a functional option argument to the input constructor.
// InputOpt is a functional option that can be used to modify the default input
// options.
type InputOpt func(*inputOpts) //nolint:revive
// WithResolutionBlob is an option that can be used to set a resolution blob on
// for an input.
func WithResolutionBlob(b fn.Option[tlv.Blob]) InputOpt {
return func(o *inputOpts) {
o.resolutionBlob = b
}
}
// BaseInput contains all the information needed to sweep a basic
// output (CSV/CLTV/no time lock).
type BaseInput struct {
@ -187,11 +215,12 @@ func MakeBaseInput(outpoint *wire.OutPoint, witnessType WitnessType,
return BaseInput{
inputKit{
outpoint: *outpoint,
witnessType: witnessType,
signDesc: *signDescriptor,
heightHint: heightHint,
unconfParent: unconfParent,
outpoint: *outpoint,
witnessType: witnessType,
signDesc: *signDescriptor,
heightHint: heightHint,
unconfParent: unconfParent,
resolutionBlob: opt.resolutionBlob,
},
}
}