mirror of
https://github.com/btcsuite/btcd.git
synced 2025-03-13 11:35:52 +01:00
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:
parent
35c42688d9
commit
27cf70216f
1 changed files with 10 additions and 0 deletions
|
@ -71,6 +71,16 @@ func (entry *UtxoEntry) isFresh() bool {
|
||||||
return entry.packedFlags&tfFresh == tfFresh
|
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
|
// IsCoinBase returns whether or not the output was contained in a coinbase
|
||||||
// transaction.
|
// transaction.
|
||||||
func (entry *UtxoEntry) IsCoinBase() bool {
|
func (entry *UtxoEntry) IsCoinBase() bool {
|
||||||
|
|
Loading…
Add table
Reference in a new issue