@@ -271,11 +271,24 @@ func (c *Custodian) watchInboundAssets() {
271271
272272 // Maybe a proof was delivered while we were shutting down or
273273 // starting up, let's check now.
274- err = c .checkProofAvailable (event )
274+ available , err : = c .checkProofAvailable (event )
275275 if err != nil {
276276 reportErr (err )
277277 return
278278 }
279+
280+ // If we did find a proof, we did import it now and can remove
281+ // the event from our cache.
282+ if available {
283+ delete (c .events , event .Outpoint )
284+
285+ continue
286+ }
287+
288+ // If we didn't find a proof, we'll launch a goroutine to use
289+ // the ProofCourier to import the proof into our local DB.
290+ c .Wg .Add (1 )
291+ go c .receiveProof (event .Addr .Tap , event .Outpoint )
279292 }
280293
281294 // Read all on-chain transactions and make sure they are mapped to an
@@ -594,7 +607,7 @@ func (c *Custodian) importAddrToWallet(addr *address.AddrWithKeyInfo) error {
594607
595608// checkProofAvailable checks the proof storage if a proof for the given event
596609// is already available. If it is, and it checks out, the event is updated.
597- func (c * Custodian ) checkProofAvailable (event * address.Event ) error {
610+ func (c * Custodian ) checkProofAvailable (event * address.Event ) ( bool , error ) {
598611 ctxt , cancel := c .WithCtxQuit ()
599612 defer cancel ()
600613
@@ -610,34 +623,36 @@ func (c *Custodian) checkProofAvailable(event *address.Event) error {
610623 })
611624 switch {
612625 case errors .Is (err , proof .ErrProofNotFound ):
613- return nil
626+ return false , nil
614627
615628 case err != nil :
616- return fmt .Errorf ("error fetching proof for event: %w" , err )
629+ return false , fmt .Errorf ("error fetching proof for event: %w" ,
630+ err )
617631 }
618632
619633 file := proof .NewEmptyFile (proof .V0 )
620634 if err := file .Decode (bytes .NewReader (blob )); err != nil {
621- return fmt .Errorf ("error decoding proof file: %w" , err )
635+ return false , fmt .Errorf ("error decoding proof file: %w" , err )
622636 }
623637
624638 // Exit early on empty proof (shouldn't happen outside of test cases).
625639 if file .IsEmpty () {
626- return fmt .Errorf ("archive contained empty proof file: %w" , err )
640+ return false , fmt .Errorf ("archive contained empty proof file: " +
641+ "%w" , err )
627642 }
628643
629644 lastProof , err := file .LastProof ()
630645 if err != nil {
631- return fmt .Errorf ("error fetching last proof: %w" , err )
646+ return false , fmt .Errorf ("error fetching last proof: %w" , err )
632647 }
633648
634649 // The proof might be an old state, let's make sure it matches our event
635650 // before marking the inbound asset transfer as complete.
636651 if AddrMatchesAsset (event .Addr , & lastProof .Asset ) {
637- return c .setReceiveCompleted (event , lastProof , file )
652+ return true , c .setReceiveCompleted (event , lastProof , file )
638653 }
639654
640- return nil
655+ return false , nil
641656}
642657
643658// mapProofToEvent inspects a new proof and attempts to match it to an existing
0 commit comments