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.
This commit is contained in:
Wilmer Paulino 2018-10-05 02:07:55 -07:00
parent 39d86d5731
commit f4cf1073d4
No known key found for this signature in database
GPG Key ID: 6DF57B9F9514972F

@ -127,6 +127,10 @@ func (c *HeightHintCache) CommitSpendHint(height uint32, ops ...wire.OutPoint) e
return nil return nil
} }
if len(ops) == 0 {
return nil
}
Log.Tracef("Updating spend hint to height %d for %v", height, ops) Log.Tracef("Updating spend hint to height %d for %v", height, ops)
return c.db.Batch(func(tx *bolt.Tx) error { return c.db.Batch(func(tx *bolt.Tx) error {
@ -197,6 +201,10 @@ func (c *HeightHintCache) PurgeSpendHint(ops ...wire.OutPoint) error {
return nil return nil
} }
if len(ops) == 0 {
return nil
}
Log.Tracef("Removing spend hints for %v", ops) Log.Tracef("Removing spend hints for %v", ops)
return c.db.Batch(func(tx *bolt.Tx) error { return c.db.Batch(func(tx *bolt.Tx) error {
@ -228,6 +236,10 @@ func (c *HeightHintCache) CommitConfirmHint(height uint32, txids ...chainhash.Ha
return nil return nil
} }
if len(txids) == 0 {
return nil
}
Log.Tracef("Updating confirm hints to height %d for %v", height, txids) Log.Tracef("Updating confirm hints to height %d for %v", height, txids)
return c.db.Batch(func(tx *bolt.Tx) error { return c.db.Batch(func(tx *bolt.Tx) error {
@ -299,6 +311,10 @@ func (c *HeightHintCache) PurgeConfirmHint(txids ...chainhash.Hash) error {
return nil return nil
} }
if len(txids) == 0 {
return nil
}
Log.Tracef("Removing confirm hints for %v", txids) Log.Tracef("Removing confirm hints for %v", txids)
return c.db.Batch(func(tx *bolt.Tx) error { return c.db.Batch(func(tx *bolt.Tx) error {