@@ -1415,7 +1415,26 @@ func importOutputProofs(scid lnwire.ShortChannelID,
14151415// the funding outputs we need.
14161416//
14171417// TODO(roasbeef): assume single asset for now, also additional inputs
1418+ ctxb := context .Background ()
14181419for _ , proofToImport := range outputProofs {
1420+ // Check if the proof is already imported to avoid redundant
1421+ // work.
1422+ fundingLocator := proof.Locator {
1423+ AssetID : fn .Ptr (proofToImport .Asset .ID ()),
1424+ ScriptKey : * proofToImport .Asset .ScriptKey .PubKey ,
1425+ OutPoint : fn .Ptr (proofToImport .OutPoint ()),
1426+ }
1427+ proofExists , err := proofArchive .HasProof (ctxb , fundingLocator )
1428+ if err != nil {
1429+ return fmt .Errorf ("unable to check if proof " +
1430+ "exists: %w" , err )
1431+ }
1432+ if proofExists {
1433+ log .Infof ("Proof already imported for %v, skipping" ,
1434+ limitSpewer .Sdump (fundingLocator ))
1435+ continue
1436+ }
1437+
14191438proofPrevID , err := proofToImport .Asset .PrimaryPrevID ()
14201439if err != nil {
14211440return fmt .Errorf ("unable to get primary prev " +
@@ -1443,7 +1462,6 @@ func importOutputProofs(scid lnwire.ShortChannelID,
14431462
14441463// First, we'll make a courier to use in fetching the proofs we
14451464// need.
1446- ctxb := context .Background ()
14471465proofFetcher , err := proofDispatch .NewCourier (
14481466ctxb , courierAddr , true ,
14491467)
@@ -1505,18 +1523,10 @@ func importOutputProofs(scid lnwire.ShortChannelID,
15051523return fmt .Errorf ("unable to encode proof: %w" , err )
15061524}
15071525
1508- fundingUTXO := proofToImport .Asset
15091526err = proofArchive .ImportProofs (
15101527ctxb , vCtx , false , & proof.AnnotatedProof {
1511- //nolint:lll
1512- Locator : proof.Locator {
1513- AssetID : fn .Ptr (fundingUTXO .ID ()),
1514- ScriptKey : * fundingUTXO .ScriptKey .PubKey ,
1515- OutPoint : fn .Ptr (
1516- proofToImport .OutPoint (),
1517- ),
1518- },
1519- Blob : finalProofBuf .Bytes (),
1528+ Locator : fundingLocator ,
1529+ Blob : finalProofBuf .Bytes (),
15201530},
15211531)
15221532if err != nil {
@@ -1576,26 +1586,24 @@ func (a *AuxSweeper) importCommitTx(req lnwallet.ResolutionReq,
15761586fundingInputProofs [inputProof .Asset .ID ()] = inputProof
15771587}
15781588
1579- // If we're the responder, then we'll also fetch+complete the proofs
1580- // for the funding transaction here so we can properly recognize the
1581- // spent input below.
1582- if ! req .Initiator {
1583- vCtx := proof.VerifierCtx {
1584- HeaderVerifier : a .cfg .HeaderVerifier ,
1585- MerkleVerifier : proof .DefaultMerkleVerifier ,
1586- GroupVerifier : a .cfg .GroupVerifier ,
1587- ChainLookupGen : a .cfg .ChainBridge ,
1588- IgnoreChecker : a .cfg .IgnoreChecker ,
1589- }
1590- err := importOutputProofs (
1591- req .ShortChanID , maps .Values (fundingInputProofs ),
1592- a .cfg .DefaultCourierAddr , a .cfg .ProofFetcher ,
1593- a .cfg .ChainBridge , vCtx , a .cfg .ProofArchive ,
1594- )
1595- if err != nil {
1596- return fmt .Errorf ("unable to import output " +
1597- "proofs: %w" , err )
1598- }
1589+ // We'll always attempt to import the proof for the funding outputs.
1590+ // It's possible that the initiator failed to do so after the funding
1591+ // transaction confirmed.
1592+ vCtx := proof.VerifierCtx {
1593+ HeaderVerifier : a .cfg .HeaderVerifier ,
1594+ MerkleVerifier : proof .DefaultMerkleVerifier ,
1595+ GroupVerifier : a .cfg .GroupVerifier ,
1596+ ChainLookupGen : a .cfg .ChainBridge ,
1597+ IgnoreChecker : a .cfg .IgnoreChecker ,
1598+ }
1599+ err = importOutputProofs (
1600+ req .ShortChanID , maps .Values (fundingInputProofs ),
1601+ a .cfg .DefaultCourierAddr , a .cfg .ProofFetcher ,
1602+ a .cfg .ChainBridge , vCtx , a .cfg .ProofArchive ,
1603+ )
1604+ if err != nil {
1605+ return fmt .Errorf ("unable to import output " +
1606+ "proofs: %w" , err )
15991607}
16001608
16011609err = updateProofsFromShortChanID (
0 commit comments