Skip to content

Commit d08d356

Browse files
committed
pool: Reinstate Fetch txBroadcaster/txCreator.
These funcs were mistakenly removed because they seemed to be unnecessary, but actually they are required due to the extremely tight coupling between PaymentManager and Hub. Removing them is possible, but requires more involved work to untangle the construction of the two components.
1 parent d8ba4a4 commit d08d356

3 files changed

Lines changed: 275 additions & 229 deletions

File tree

pool/hub.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ func NewHub(hcfg *HubConfig) (*Hub, error) {
245245
WalletAccount: h.cfg.WalletAccount,
246246
WalletPass: h.cfg.WalletPass,
247247
GetBlockConfirmations: h.getBlockConfirmations,
248-
TxCreator: h.nodeConn,
249-
TxBroadcaster: h.walletConn,
248+
FetchTxCreator: func() txCreator { return h.nodeConn },
249+
FetchTxBroadcaster: func() txBroadcaster { return h.walletConn },
250250
CoinbaseConfTimeout: h.cfg.CoinbaseConfTimeout,
251251
SignalCache: h.SignalCache,
252252
}

pool/paymentmgr.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,12 @@ type PaymentMgrConfig struct {
106106
// GetBlockConfirmations returns the number of block confirmations for the
107107
// provided block hash.
108108
GetBlockConfirmations func(context.Context, *chainhash.Hash) (int64, error)
109-
// TxCreator is a transaction creator that allows coinbase lookups and
110-
// payment transaction creation.
111-
TxCreator txCreator
112-
// TxBroadcaster is a transaction broadcaster that allows signing and
113-
// publishing of transactions.
114-
TxBroadcaster txBroadcaster
109+
// FetchTxCreator returns a transaction creator that allows coinbase lookups
110+
// and payment transaction creation.
111+
FetchTxCreator func() txCreator
112+
// FetchTxBroadcaster returns a transaction broadcaster that allows signing
113+
// and publishing of transactions.
114+
FetchTxBroadcaster func() txBroadcaster
115115
// CoinbaseConfTimeout is the duration to wait for coinbase confirmations
116116
// when generating a payout transaction.
117117
CoinbaseConfTimeout time.Duration
@@ -718,7 +718,7 @@ func (pm *PaymentMgr) payDividends(ctx context.Context, height uint32, coinbaseI
718718
pm.mtx.Unlock()
719719
}()
720720

721-
txB := pm.cfg.TxBroadcaster
721+
txB := pm.cfg.FetchTxBroadcaster()
722722
if txB == nil {
723723
desc := fmt.Sprintf("%s: tx broadcaster cannot be nil", funcName)
724724
return errs.PoolError(errs.Disconnected, desc)
@@ -775,7 +775,7 @@ func (pm *PaymentMgr) payDividends(ctx context.Context, height uint32, coinbaseI
775775
}
776776
}
777777

778-
txC := pm.cfg.TxCreator
778+
txC := pm.cfg.FetchTxCreator()
779779
if txC == nil {
780780
desc := fmt.Sprintf("%s: tx creator cannot be nil", funcName)
781781
return errs.PoolError(errs.Disconnected, desc)

0 commit comments

Comments
 (0)