Skip to content

Commit 9de52be

Browse files
committed
tapchannel: import funding output proofs for responder during co-op close
Otherwise, the transfer insert for the responder may fail as they don't have the funding output in their database, so shipping the transfer fails as it can't find the proof. Fixes #985.
1 parent 6730a9f commit 9de52be

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

tapcfg/server.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,13 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger,
447447
AddrBook: addrBook,
448448
TxSender: chainPorter,
449449
DefaultCourierAddr: proofCourierAddr,
450+
ProofArchive: proofArchive,
451+
ProofFetcher: proofCourierDispatcher,
452+
HeaderVerifier: headerVerifier,
453+
GroupVerifier: tapgarden.GenGroupVerifier(
454+
context.Background(), assetMintingStore,
455+
),
456+
ChainBridge: chainBridge,
450457
},
451458
)
452459
auxSweeper := tapchannel.NewAuxSweeper(

tapchannel/aux_closer.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/lightninglabs/taproot-assets/proof"
1818
"github.com/lightninglabs/taproot-assets/tapchannelmsg"
1919
"github.com/lightninglabs/taproot-assets/tapfreighter"
20+
"github.com/lightninglabs/taproot-assets/tapgarden"
2021
"github.com/lightninglabs/taproot-assets/tappsbt"
2122
"github.com/lightninglabs/taproot-assets/tapsend"
2223
lfn "github.com/lightningnetwork/lnd/fn"
@@ -45,6 +46,22 @@ type AuxChanCloserCfg struct {
4546
// DefaultCourierAddr is the default address we'll use to send/receive
4647
// proofs for the co-op close process
4748
DefaultCourierAddr *url.URL
49+
50+
// ProofFetcher is used to fetch proofs needed to properly import the
51+
// funding output into the database as our own.
52+
ProofFetcher proof.CourierDispatch
53+
54+
// ProofArchive is used to store import funding output proofs.
55+
ProofArchive proof.Archiver
56+
57+
// HeaderVerifier is used to verify headers in a proof.
58+
HeaderVerifier proof.HeaderVerifier
59+
60+
// GroupVerifier is used to verify group keys in a proof.
61+
GroupVerifier proof.GroupVerifier
62+
63+
// ChainBridge is used to fetch blocks from the main chain.
64+
ChainBridge tapgarden.ChainBridge
4865
}
4966

5067
// assetCloseInfo houses the information we need to finalize the close of an
@@ -624,6 +641,37 @@ func (a *AuxChanCloser) FinalizeClose(desc chancloser.AuxCloseDesc,
624641
desc.ChanPoint)
625642
}
626643

644+
// Before we finalize the close process, we'll make sure to also import
645+
// a transfer for the funding outputs. This way we'll ensure that we're
646+
// able to insert the transfer that spends these outputs. We only need
647+
// to do this for the responder though, as the creator of the channel
648+
// already has these proofs inserted.
649+
if !desc.Initiator {
650+
fundingInfo, err := tapchannelmsg.DecodeOpenChannel(
651+
desc.FundingBlob.UnwrapOr(nil),
652+
)
653+
if err != nil {
654+
return err
655+
}
656+
657+
fundingInputProofs := fn.Map(
658+
fundingInfo.FundedAssets.Val.Outputs,
659+
func(a *tapchannelmsg.AssetOutput) *proof.Proof {
660+
return &a.Proof.Val
661+
},
662+
)
663+
err = importOutputProofs(
664+
desc.ShortChanID, fundingInputProofs,
665+
a.cfg.DefaultCourierAddr, a.cfg.ProofFetcher,
666+
a.cfg.ChainBridge, a.cfg.HeaderVerifier,
667+
a.cfg.GroupVerifier, a.cfg.ProofArchive,
668+
)
669+
if err != nil {
670+
return fmt.Errorf("unable to import output "+
671+
"proofs: %w", err)
672+
}
673+
}
674+
627675
log.Infof("Finalizing close for ChannelPoint(%v): ", desc.ChanPoint)
628676

629677
defer delete(a.closeInfo, desc.ChanPoint)

0 commit comments

Comments
 (0)