chainntnfs: query the hint cache before registering a conf ntfn
In this commit, we alter the different chain notifiers to query their height hint cache before registering a confimation notification. We do this as it's possible that the cache has a higher height hint, which can potentially reduce the amount of blocked fetched when attempting historical dispatches.
This commit is contained in:
parent
30fd219b1c
commit
7e872566c4
@ -869,6 +869,18 @@ type confirmationNotification struct {
|
|||||||
func (b *BitcoindNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
|
func (b *BitcoindNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
|
||||||
_ []byte, numConfs, heightHint uint32) (*chainntnfs.ConfirmationEvent, error) {
|
_ []byte, numConfs, heightHint uint32) (*chainntnfs.ConfirmationEvent, error) {
|
||||||
|
|
||||||
|
// Before proceeding to register the notification, we'll query our
|
||||||
|
// height hint cache to determine whether a better one exists.
|
||||||
|
if hint, err := b.confirmHintCache.QueryConfirmHint(*txid); err == nil {
|
||||||
|
if hint > heightHint {
|
||||||
|
chainntnfs.Log.Debugf("Using height hint %d retrieved "+
|
||||||
|
"from cache for %v", hint, txid)
|
||||||
|
heightHint = hint
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct a notification request for the transaction and send it to
|
||||||
|
// the main event loop.
|
||||||
ntfn := &confirmationNotification{
|
ntfn := &confirmationNotification{
|
||||||
ConfNtfn: chainntnfs.ConfNtfn{
|
ConfNtfn: chainntnfs.ConfNtfn{
|
||||||
ConfID: atomic.AddUint64(&b.confClientCounter, 1),
|
ConfID: atomic.AddUint64(&b.confClientCounter, 1),
|
||||||
|
@ -916,6 +916,18 @@ type confirmationNotification struct {
|
|||||||
func (b *BtcdNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash, _ []byte,
|
func (b *BtcdNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash, _ []byte,
|
||||||
numConfs, heightHint uint32) (*chainntnfs.ConfirmationEvent, error) {
|
numConfs, heightHint uint32) (*chainntnfs.ConfirmationEvent, error) {
|
||||||
|
|
||||||
|
// Before proceeding to register the notification, we'll query our
|
||||||
|
// height hint cache to determine whether a better one exists.
|
||||||
|
if hint, err := b.confirmHintCache.QueryConfirmHint(*txid); err == nil {
|
||||||
|
if hint > heightHint {
|
||||||
|
chainntnfs.Log.Debugf("Using height hint %d retrieved "+
|
||||||
|
"from cache for %v", hint, txid)
|
||||||
|
heightHint = hint
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct a notification request for the transaction and send it to
|
||||||
|
// the main event loop.
|
||||||
ntfn := &confirmationNotification{
|
ntfn := &confirmationNotification{
|
||||||
ConfNtfn: chainntnfs.ConfNtfn{
|
ConfNtfn: chainntnfs.ConfNtfn{
|
||||||
ConfID: atomic.AddUint64(&b.confClientCounter, 1),
|
ConfID: atomic.AddUint64(&b.confClientCounter, 1),
|
||||||
|
@ -869,6 +869,18 @@ func (n *NeutrinoNotifier) RegisterConfirmationsNtfn(txid *chainhash.Hash,
|
|||||||
pkScript []byte,
|
pkScript []byte,
|
||||||
numConfs, heightHint uint32) (*chainntnfs.ConfirmationEvent, error) {
|
numConfs, heightHint uint32) (*chainntnfs.ConfirmationEvent, error) {
|
||||||
|
|
||||||
|
// Before proceeding to register the notification, we'll query our
|
||||||
|
// height hint cache to determine whether a better one exists.
|
||||||
|
if hint, err := n.confirmHintCache.QueryConfirmHint(*txid); err == nil {
|
||||||
|
if hint > heightHint {
|
||||||
|
chainntnfs.Log.Debugf("Using height hint %d retrieved "+
|
||||||
|
"from cache for %v", hint, txid)
|
||||||
|
heightHint = hint
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Construct a notification request for the transaction and send it to
|
||||||
|
// the main event loop.
|
||||||
ntfn := &confirmationsNotification{
|
ntfn := &confirmationsNotification{
|
||||||
ConfNtfn: chainntnfs.ConfNtfn{
|
ConfNtfn: chainntnfs.ConfNtfn{
|
||||||
ConfID: atomic.AddUint64(&n.confClientCounter, 1),
|
ConfID: atomic.AddUint64(&n.confClientCounter, 1),
|
||||||
|
Loading…
Reference in New Issue
Block a user