blockchain: Add memoryUsage() method on UtxoEntry

This change is part of the effort to add utxocache support to btcd.

Getting the memory usage of an entry is very useful for the utxo cache
as we need to know how much memory all the cached entries are using to
guarantee a cache usage limit for the end user.
This commit is contained in:
Calvin Kim 2023-05-16 17:04:12 +09:00
parent 35c42688d9
commit 27cf70216f

View file

@ -71,6 +71,16 @@ func (entry *UtxoEntry) isFresh() bool {
return entry.packedFlags&tfFresh == tfFresh
}
// memoryUsage returns the memory usage in bytes of for the utxo entry.
// It returns 0 for a nil entry.
func (entry *UtxoEntry) memoryUsage() uint64 {
if entry == nil {
return 0
}
return baseEntrySize + uint64(cap(entry.pkScript))
}
// IsCoinBase returns whether or not the output was contained in a coinbase
// transaction.
func (entry *UtxoEntry) IsCoinBase() bool {