chainntnfs: add unique ID field to track conf ntfns within notifier

This commit is contained in:
Wilmer Paulino
2018-07-26 21:30:15 -07:00
parent ad904ebe8c
commit c43506dee9
4 changed files with 15 additions and 5 deletions

View File

@@ -54,6 +54,7 @@ type chainUpdate struct {
// chain client. Multiple concurrent clients are supported. All notifications // chain client. Multiple concurrent clients are supported. All notifications
// are achieved via non-blocking sends on client channels. // are achieved via non-blocking sends on client channels.
type BitcoindNotifier struct { type BitcoindNotifier struct {
confClientCounter uint64 // To be used atomically.
spendClientCounter uint64 // To be used atomically. spendClientCounter uint64 // To be used atomically.
epochClientCounter uint64 // To be used atomically. epochClientCounter uint64 // To be used atomically.
@@ -716,6 +717,7 @@ func (b *BitcoindNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
ntfn := &confirmationNotification{ ntfn := &confirmationNotification{
ConfNtfn: chainntnfs.ConfNtfn{ ConfNtfn: chainntnfs.ConfNtfn{
ConfID: atomic.AddUint64(&b.confClientCounter, 1),
TxID: txid, TxID: txid,
NumConfirmations: numConfs, NumConfirmations: numConfs,
Event: chainntnfs.NewConfirmationEvent(numConfs), Event: chainntnfs.NewConfirmationEvent(numConfs),

View File

@@ -61,6 +61,7 @@ type txUpdate struct {
// notifications. Multiple concurrent clients are supported. All notifications // notifications. Multiple concurrent clients are supported. All notifications
// are achieved via non-blocking sends on client channels. // are achieved via non-blocking sends on client channels.
type BtcdNotifier struct { type BtcdNotifier struct {
confClientCounter uint64 // To be used aotmically.
spendClientCounter uint64 // To be used atomically. spendClientCounter uint64 // To be used atomically.
epochClientCounter uint64 // To be used atomically. epochClientCounter uint64 // To be used atomically.
@@ -800,6 +801,7 @@ func (b *BtcdNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
ntfn := &confirmationNotification{ ntfn := &confirmationNotification{
ConfNtfn: chainntnfs.ConfNtfn{ ConfNtfn: chainntnfs.ConfNtfn{
ConfID: atomic.AddUint64(&b.confClientCounter, 1),
TxID: txid, TxID: txid,
NumConfirmations: numConfs, NumConfirmations: numConfs,
Event: chainntnfs.NewConfirmationEvent(numConfs), Event: chainntnfs.NewConfirmationEvent(numConfs),

View File

@@ -48,12 +48,13 @@ var (
// TODO(roasbeef): heavily consolidate with NeutrinoNotifier code // TODO(roasbeef): heavily consolidate with NeutrinoNotifier code
// * maybe combine into single package? // * maybe combine into single package?
type NeutrinoNotifier struct { type NeutrinoNotifier struct {
started int32 // To be used atomically. confClientCounter uint64 // To be used atomically.
stopped int32 // To be used atomically.
spendClientCounter uint64 // To be used atomically. spendClientCounter uint64 // To be used atomically.
epochClientCounter uint64 // To be used atomically. epochClientCounter uint64 // To be used atomically.
started int32 // To be used atomically.
stopped int32 // To be used atomically.
heightMtx sync.RWMutex heightMtx sync.RWMutex
bestHeight uint32 bestHeight uint32
@@ -696,6 +697,7 @@ func (n *NeutrinoNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
ntfn := &confirmationsNotification{ ntfn := &confirmationsNotification{
ConfNtfn: chainntnfs.ConfNtfn{ ConfNtfn: chainntnfs.ConfNtfn{
ConfID: atomic.AddUint64(&n.confClientCounter, 1),
TxID: txid, TxID: txid,
NumConfirmations: numConfs, NumConfirmations: numConfs,
Event: chainntnfs.NewConfirmationEvent(numConfs), Event: chainntnfs.NewConfirmationEvent(numConfs),

View File

@@ -18,6 +18,10 @@ var (
// once the target transaction gets sufficient confirmations. The client is // once the target transaction gets sufficient confirmations. The client is
// asynchronously notified via the ConfirmationEvent channels. // asynchronously notified via the ConfirmationEvent channels.
type ConfNtfn struct { type ConfNtfn struct {
// ConfID uniquely identifies the confirmation notification request for
// the specified transaction.
ConfID uint64
// TxID is the hash of the transaction for which confirmation notifications // TxID is the hash of the transaction for which confirmation notifications
// are requested. // are requested.
TxID *chainhash.Hash TxID *chainhash.Hash
@@ -72,7 +76,7 @@ type TxConfNotifier struct {
// confNotifications is an index of notification requests by transaction // confNotifications is an index of notification requests by transaction
// hash. // hash.
confNotifications map[chainhash.Hash][]*ConfNtfn confNotifications map[chainhash.Hash]map[uint64]*ConfNtfn
// txsByInitialHeight is an index of watched transactions by the height // txsByInitialHeight is an index of watched transactions by the height
// that they are included at in the blockchain. This is tracked so that // that they are included at in the blockchain. This is tracked so that
@@ -95,7 +99,7 @@ func NewTxConfNotifier(startHeight uint32, reorgSafetyLimit uint32) *TxConfNotif
return &TxConfNotifier{ return &TxConfNotifier{
currentHeight: startHeight, currentHeight: startHeight,
reorgSafetyLimit: reorgSafetyLimit, reorgSafetyLimit: reorgSafetyLimit,
confNotifications: make(map[chainhash.Hash][]*ConfNtfn), confNotifications: make(map[chainhash.Hash]map[uint64]*ConfNtfn),
txsByInitialHeight: make(map[uint32]map[chainhash.Hash]struct{}), txsByInitialHeight: make(map[uint32]map[chainhash.Hash]struct{}),
ntfnsByConfirmHeight: make(map[uint32]map[*ConfNtfn]struct{}), ntfnsByConfirmHeight: make(map[uint32]map[*ConfNtfn]struct{}),
quit: make(chan struct{}), quit: make(chan struct{}),