chanbackup: add Single.CloseTxInputs field
The field is optional. It stores inputs needed to produce signed commit tx using chantools scbforceclose, which calls function GetSignedCommitTx. New backups have this field filled if commit tx is available (for all cases except when DLP is active). If a backup has this data, the field is filled from it, otherwise it is kept empty. Modified test function genRandomOpenChannelShell to cover new types of channels (simple taproot channel and custom channel) and to cover combinations of bits. Make sure that TapscriptRoot field is properly packed and unpacked.
This commit is contained in:
4 files changed
+421
-5
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
"github.com/btcsuite/btcd/btcec/v2"
|
||||
"github.com/btcsuite/btcd/wire"
|
||||
"github.com/lightningnetwork/lnd/channeldb"
|
||||
"github.com/lightningnetwork/lnd/fn"
|
||||
"github.com/lightningnetwork/lnd/kvdb"
|
||||
)
|
||||
|
||||
@@ -53,6 +54,48 @@ func assembleChanBackup(addrSource AddressSource,
|
||||
return &single, nil
|
||||
}
|
||||
|
||||
// buildCloseTxInputs generates inputs needed to force close a channel from
|
||||
// an open channel. Anyone having these inputs and the signer, can sign the
|
||||
// force closure transaction. Warning! If the channel state updates, an attempt
|
||||
// to close the channel using this method with outdated CloseTxInputs can result
|
||||
// in loss of funds! This may happen if an outdated channel backup is attempted
|
||||
// to be used to force close the channel.
|
||||
func buildCloseTxInputs(
|
||||
targetChan *channeldb.OpenChannel) fn.Option[CloseTxInputs] {
|
||||
|
||||
log.Debugf("Crafting CloseTxInputs for ChannelPoint(%v)",
|
||||
targetChan.FundingOutpoint)
|
||||
|
||||
localCommit := targetChan.LocalCommitment
|
||||
|
||||
if localCommit.CommitTx == nil {
|
||||
log.Infof("CommitTx is nil for ChannelPoint(%v), "+
|
||||
"skipping CloseTxInputs. This is possible when "+
|
||||
"DLP is active.", targetChan.FundingOutpoint)
|
||||
|
||||
return fn.None[CloseTxInputs]()
|
||||
}
|
||||
|
||||
// We need unsigned force close tx and the counterparty's signature.
|
||||
inputs := CloseTxInputs{
|
||||
CommitTx: localCommit.CommitTx,
|
||||
CommitSig: localCommit.CommitSig,
|
||||
}
|
||||
|
||||
// In case of a taproot channel, commit height is needed as well to
|
||||
// produce verification nonce for the taproot channel using shachain.
|
||||
if targetChan.ChanType.IsTaproot() {
|
||||
inputs.CommitHeight = localCommit.CommitHeight
|
||||
}
|
||||
|
||||
// In case of a custom taproot channel, TapscriptRoot is needed as well.
|
||||
if targetChan.ChanType.HasTapscriptRoot() {
|
||||
inputs.TapscriptRoot = targetChan.TapscriptRoot
|
||||
}
|
||||
|
||||
return fn.Some(inputs)
|
||||
}
|
||||
|
||||
// FetchBackupForChan attempts to create a plaintext static channel backup for
|
||||
// the target channel identified by its channel point. If we're unable to find
|
||||
// the target channel, then an error will be returned.
|
||||
|
||||
Reference in new issue
Block a user