lnwallet: only set funding TX witness if we publish

During the final part of the channel funding negotiation we only need to
assemble the full funding TX with the witness if we are going to publish
the transaction ourselves. If the final funding TX is published
externally we don't need this information. This will make it possible to
skip the verify process for fully externally funded PSBT channels.
This commit is contained in:
Oliver Gugger
2021-06-07 11:16:36 +02:00
parent 9b04ae45e3
commit d4136002c1
2 changed files with 38 additions and 21 deletions

View File

@@ -139,6 +139,11 @@ type PsbtIntent struct {
// NOTE: This channel must always be buffered. // NOTE: This channel must always be buffered.
PsbtReady chan error PsbtReady chan error
// shouldPublish specifies if the intent assumes its assembler should
// publish the transaction once the channel funding has completed. If
// this is set to false then the finalize step can be skipped.
shouldPublish bool
// signalPsbtReady is a Once guard to make sure the PsbtReady channel is // signalPsbtReady is a Once guard to make sure the PsbtReady channel is
// only closed exactly once. // only closed exactly once.
signalPsbtReady sync.Once signalPsbtReady sync.Once
@@ -449,6 +454,12 @@ func (i *PsbtIntent) Outputs() []*wire.TxOut {
} }
} }
// ShouldPublishFundingTX returns true if the intent assumes that its assembler
// should publish the funding TX once the funding negotiation is complete.
func (i *PsbtIntent) ShouldPublishFundingTX() bool {
return i.shouldPublish
}
// PsbtAssembler is a type of chanfunding.Assembler wherein the funding // PsbtAssembler is a type of chanfunding.Assembler wherein the funding
// transaction is constructed outside of lnd by using partially signed bitcoin // transaction is constructed outside of lnd by using partially signed bitcoin
// transactions (PSBT). // transactions (PSBT).
@@ -503,6 +514,7 @@ func (p *PsbtAssembler) ProvisionChannel(req *Request) (Intent, error) {
State: PsbtShimRegistered, State: PsbtShimRegistered,
BasePsbt: p.basePsbt, BasePsbt: p.basePsbt,
PsbtReady: make(chan error, 1), PsbtReady: make(chan error, 1),
shouldPublish: p.shouldPublish,
netParams: p.netParams, netParams: p.netParams,
} }

View File

@@ -1454,9 +1454,11 @@ func (l *LightningWallet) handleChanPointReady(req *continueContributionMsg) {
// is needed to construct and publish the full funding transaction. // is needed to construct and publish the full funding transaction.
intent := pendingReservation.fundingIntent intent := pendingReservation.fundingIntent
if psbtIntent, ok := intent.(*chanfunding.PsbtIntent); ok { if psbtIntent, ok := intent.(*chanfunding.PsbtIntent); ok {
// With our keys bound, we can now construct+sign the final // With our keys bound, we can now construct and possibly sign
// funding transaction and also obtain the chanPoint that // the final funding transaction and also obtain the chanPoint
// creates the channel. // that creates the channel. We _have_ to call CompileFundingTx
// even if we don't publish ourselves as that sets the actual
// funding outpoint in stone for this channel.
fundingTx, err := psbtIntent.CompileFundingTx() fundingTx, err := psbtIntent.CompileFundingTx()
if err != nil { if err != nil {
req.err <- fmt.Errorf("unable to construct funding "+ req.err <- fmt.Errorf("unable to construct funding "+
@@ -1470,12 +1472,14 @@ func (l *LightningWallet) handleChanPointReady(req *continueContributionMsg) {
return return
} }
// Finally, we'll populate the relevant information in our
// pendingReservation so the rest of the funding flow can
// continue as normal.
pendingReservation.fundingTx = fundingTx
pendingReservation.partialState.FundingOutpoint = *chanPointPtr pendingReservation.partialState.FundingOutpoint = *chanPointPtr
chanPoint = *chanPointPtr chanPoint = *chanPointPtr
// Finally, we'll populate the relevant information in our
// pendingReservation so the rest of the funding flow can
// continue as normal in case we are going to publish ourselves.
if psbtIntent.ShouldPublishFundingTX() {
pendingReservation.fundingTx = fundingTx
pendingReservation.ourFundingInputScripts = make( pendingReservation.ourFundingInputScripts = make(
[]*input.Script, 0, len(ourContribution.Inputs), []*input.Script, 0, len(ourContribution.Inputs),
) )
@@ -1489,6 +1493,7 @@ func (l *LightningWallet) handleChanPointReady(req *continueContributionMsg) {
) )
} }
} }
}
// Initialize an empty sha-chain for them, tracking the current pending // Initialize an empty sha-chain for them, tracking the current pending
// revocation hash (we don't yet know the preimage so we can't add it // revocation hash (we don't yet know the preimage so we can't add it