diff --git a/tapcfg/server.go b/tapcfg/server.go index 6f909b4e4..7c2687057 100644 --- a/tapcfg/server.go +++ b/tapcfg/server.go @@ -180,32 +180,14 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger, } } - var hashMailCourier proof.Courier - if cfg.HashMailCourier != nil && - proofCourierAddr.Type() == proof.ApertureCourier { - - hashMailBox, err := proof.NewHashMailBox( - proofCourierAddr.Url(), cfg.HashMailCourier.TlsCertPath, - ) - if err != nil { - return nil, fmt.Errorf("unable to make mailbox: %v", - err) - } - - hashMailCourier, err = proof.NewHashMailCourier( - cfg.HashMailCourier, hashMailBox, assetStore, - ) - if err != nil { - return nil, fmt.Errorf("unable to make hashmail "+ - "courier: %v", err) + var proofCourierCfg *proof.CourierCfg + if cfg.HashMailCourier != nil { + proofCourierCfg = &proof.CourierCfg{ + HashMailCfg: cfg.HashMailCourier, + DeliveryLog: assetStore, } } - proofCourierCfg := proof.CourierCfg{ - HashMailCfg: cfg.HashMailCourier, - DeliveryLog: assetStore, - } - reOrgWatcher := tapgarden.NewReOrgWatcher(&tapgarden.ReOrgWatcherConfig{ ChainBridge: chainBridge, ProofArchive: proofArchive, @@ -315,7 +297,7 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger, ProofArchive: proofArchive, ProofNotifier: assetStore, ErrChan: mainErrChan, - ProofCourierCfg: &proofCourierCfg, + ProofCourierCfg: proofCourierCfg, ProofWatcher: reOrgWatcher, }, ), @@ -327,17 +309,17 @@ func genServerConfig(cfg *Config, cfgLogger btclog.Logger, CoinSelect: coinSelect, ChainPorter: tapfreighter.NewChainPorter( &tapfreighter.ChainPorterConfig{ - Signer: virtualTxSigner, - TxValidator: &tap.ValidatorV0{}, - ExportLog: assetStore, - ChainBridge: chainBridge, - Wallet: walletAnchor, - KeyRing: keyRing, - AssetWallet: assetWallet, - AssetProofs: proofFileStore, - ProofCourier: hashMailCourier, - ProofWatcher: reOrgWatcher, - ErrChan: mainErrChan, + Signer: virtualTxSigner, + TxValidator: &tap.ValidatorV0{}, + ExportLog: assetStore, + ChainBridge: chainBridge, + Wallet: walletAnchor, + KeyRing: keyRing, + AssetWallet: assetWallet, + AssetProofs: proofFileStore, + ProofCourierCfg: proofCourierCfg, + ProofWatcher: reOrgWatcher, + ErrChan: mainErrChan, }, ), BaseUniverse: baseUni, diff --git a/tapfreighter/chain_porter.go b/tapfreighter/chain_porter.go index 76079b09b..c61ba38af 100644 --- a/tapfreighter/chain_porter.go +++ b/tapfreighter/chain_porter.go @@ -55,9 +55,7 @@ type ChainPorterConfig struct { // TODO(roasbeef): replace with proof.Courier in the future/ AssetProofs proof.Archiver - // ProofCourier is used to optionally deliver the final proof to the - // user using an asynchronous transport mechanism. - ProofCourier proof.Courier + ProofCourierCfg *proof.CourierCfg // ProofWatcher is used to watch new proofs for their anchor transaction // to be confirmed safely with a minimum number of confirmations. @@ -607,14 +605,43 @@ func (p *ChainPorter) transferReceiverProof(pkg *sendPackage) error { log.Debugf("Attempting to deliver proof for script key %x", key.SerializeCompressed()) + proofCourierAddr, err := proof.ParseCourierAddrString( + string(out.ProofCourierAddr), + ) + if err != nil { + return fmt.Errorf("failed to parse proof courier "+ + "address: %w", err) + } + + // Initiate proof courier service handle from the proof + // courier address found in the Tap address. + courier, err := proofCourierAddr.NewCourier( + ctx, p.cfg.ProofCourierCfg, + ) + if err != nil { + return fmt.Errorf("unable to initiate proof courier "+ + "service handle: %w", err) + } + + // Update courier events subscribers before attempting to + // deliver proof. + p.subscriberMtx.Lock() + courier.SetSubscribers(p.subscribers) + p.subscriberMtx.Unlock() + + // Deliver proof to proof courier service. recipient := proof.Recipient{ ScriptKey: key, AssetID: *receiverProof.AssetID, Amount: out.Amount, } - err := p.cfg.ProofCourier.DeliverProof( + err = courier.DeliverProof( ctx, recipient, receiverProof, ) + if err != nil { + return fmt.Errorf("failed to deliver proof via "+ + "courier service: %w", err) + } // If the proof courier returned a backoff error, then // we'll just return nil here so that we can retry @@ -632,7 +659,7 @@ func (p *ChainPorter) transferReceiverProof(pkg *sendPackage) error { // If we have a proof courier instance active, then we'll launch several // goroutines to deliver the proof(s) to the receiver(s). - if p.cfg.ProofCourier != nil { + if p.cfg.ProofCourierCfg != nil { ctx, cancel := p.WithCtxQuitNoTimeout() defer cancel() @@ -1016,11 +1043,6 @@ func (p *ChainPorter) RegisterSubscriber( p.subscribers[receiver.ID()] = receiver - // If we have a proof courier, we'll also update its subscribers. - if p.cfg.ProofCourier != nil { - p.cfg.ProofCourier.SetSubscribers(p.subscribers) - } - return nil } @@ -1041,11 +1063,6 @@ func (p *ChainPorter) RemoveSubscriber( subscriber.Stop() delete(p.subscribers, subscriber.ID()) - // If we have a proof courier, we'll also update its subscribers. - if p.cfg.ProofCourier != nil { - p.cfg.ProofCourier.SetSubscribers(p.subscribers) - } - return nil }