From f4cf1073d4feb8f8d717269b86c473d4b56d684f Mon Sep 17 00:00:00 2001 From: Wilmer Paulino Date: Fri, 5 Oct 2018 02:07:55 -0700 Subject: [PATCH] chainntnfs/height_hint_cache: prevent db transactions with no updates In this commit, we modify our height hint cache to no longer start a database transaction if no outpoints/txids are provided to update the height hints for. --- chainntnfs/height_hint_cache.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/chainntnfs/height_hint_cache.go b/chainntnfs/height_hint_cache.go index 33dac971..cd499a6e 100644 --- a/chainntnfs/height_hint_cache.go +++ b/chainntnfs/height_hint_cache.go @@ -127,6 +127,10 @@ func (c *HeightHintCache) CommitSpendHint(height uint32, ops ...wire.OutPoint) e return nil } + if len(ops) == 0 { + return nil + } + Log.Tracef("Updating spend hint to height %d for %v", height, ops) return c.db.Batch(func(tx *bolt.Tx) error { @@ -197,6 +201,10 @@ func (c *HeightHintCache) PurgeSpendHint(ops ...wire.OutPoint) error { return nil } + if len(ops) == 0 { + return nil + } + Log.Tracef("Removing spend hints for %v", ops) return c.db.Batch(func(tx *bolt.Tx) error { @@ -228,6 +236,10 @@ func (c *HeightHintCache) CommitConfirmHint(height uint32, txids ...chainhash.Ha return nil } + if len(txids) == 0 { + return nil + } + Log.Tracef("Updating confirm hints to height %d for %v", height, txids) return c.db.Batch(func(tx *bolt.Tx) error { @@ -299,6 +311,10 @@ func (c *HeightHintCache) PurgeConfirmHint(txids ...chainhash.Hash) error { return nil } + if len(txids) == 0 { + return nil + } + Log.Tracef("Removing confirm hints for %v", txids) return c.db.Batch(func(tx *bolt.Tx) error {