chainntnfs/txconfnotifier: split out ntfn dispatch into helper
This commit is contained in:
parent
217b1fc0ef
commit
9ae6d43916
@ -222,9 +222,6 @@ func (tcn *TxConfNotifier) Register(
|
|||||||
tcn.Lock()
|
tcn.Lock()
|
||||||
defer tcn.Unlock()
|
defer tcn.Unlock()
|
||||||
|
|
||||||
// TODO(conner): promote immediately to confNotifications if a
|
|
||||||
// historical dispatch has already completed.
|
|
||||||
|
|
||||||
confSet, ok := tcn.confNotifications[*ntfn.TxID]
|
confSet, ok := tcn.confNotifications[*ntfn.TxID]
|
||||||
if !ok {
|
if !ok {
|
||||||
confSet = newConfNtfnSet()
|
confSet = newConfNtfnSet()
|
||||||
@ -238,6 +235,10 @@ func (tcn *TxConfNotifier) Register(
|
|||||||
// A prior rescan has already completed and we are actively watching at
|
// A prior rescan has already completed and we are actively watching at
|
||||||
// tip for this txid.
|
// tip for this txid.
|
||||||
case rescanComplete:
|
case rescanComplete:
|
||||||
|
// If conf details for this set of notifications has already
|
||||||
|
// been found, we'll attempt to deliver them immediately to this
|
||||||
|
// client.
|
||||||
|
tcn.dispatchConfDetails(ntfn, confSet.details)
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
|
||||||
// A rescan is already in progress, return here to prevent dispatching
|
// A rescan is already in progress, return here to prevent dispatching
|
||||||
@ -327,12 +328,37 @@ func (tcn *TxConfNotifier) UpdateConfDetails(txid chainhash.Hash,
|
|||||||
details.BlockHeight, txid, err)
|
details.BlockHeight, txid, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the conf details of all ntfns that don't yet have them.
|
// Cache the details found in the rescan and attempt to dispatch any
|
||||||
|
// notifications that have not yet been delivered.
|
||||||
|
confSet.details = details
|
||||||
for _, ntfn := range confSet.ntfns {
|
for _, ntfn := range confSet.ntfns {
|
||||||
if ntfn.details != nil {
|
err = tcn.dispatchConfDetails(ntfn, details)
|
||||||
continue
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// dispatchConfDetails attempts to cache and dispatch details to a particular
|
||||||
|
// client if the transaction has sufficiently confirmed. If the provided details
|
||||||
|
// are nil, this method will be a no-op.
|
||||||
|
func (tcn *TxConfNotifier) dispatchConfDetails(
|
||||||
|
ntfn *ConfNtfn, details *TxConfirmation) error {
|
||||||
|
|
||||||
|
// If no details are provided, return early as we can't dispatch.
|
||||||
|
if details == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the confirmation details for this notification, only if the
|
||||||
|
// notification doesn't already have details. This ensure we only fall
|
||||||
|
// through the following logic at most once, which could cause the
|
||||||
|
// buffered channels to block when exceeding their allocated capacity.
|
||||||
|
if ntfn.details != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
ntfn.details = details
|
ntfn.details = details
|
||||||
|
|
||||||
// Now, we'll examine whether the transaction of this
|
// Now, we'll examine whether the transaction of this
|
||||||
@ -391,8 +417,7 @@ func (tcn *TxConfNotifier) UpdateConfDetails(txid chainhash.Hash,
|
|||||||
txSet = make(map[chainhash.Hash]struct{})
|
txSet = make(map[chainhash.Hash]struct{})
|
||||||
tcn.txsByInitialHeight[blockHeight] = txSet
|
tcn.txsByInitialHeight[blockHeight] = txSet
|
||||||
}
|
}
|
||||||
txSet[txid] = struct{}{}
|
txSet[*ntfn.TxID] = struct{}{}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user