core: make IsLowPriority work with pre-calculated fee

Don't recalculate it again and again.
This commit is contained in:
Roman Khimov 2020-02-18 18:42:11 +03:00
parent 37c48b00b4
commit 06daeb44f3
6 changed files with 8 additions and 8 deletions

View file

@ -239,6 +239,6 @@ func newTestChain(t *testing.T) *core.Blockchain {
type feer struct{} type feer struct{}
func (fs *feer) NetworkFee(*transaction.Transaction) util.Fixed8 { return util.Fixed8(0) } func (fs *feer) NetworkFee(*transaction.Transaction) util.Fixed8 { return util.Fixed8(0) }
func (fs *feer) IsLowPriority(*transaction.Transaction) bool { return false } func (fs *feer) IsLowPriority(util.Fixed8) bool { return false }
func (fs *feer) FeePerByte(*transaction.Transaction) util.Fixed8 { return util.Fixed8(0) } func (fs *feer) FeePerByte(*transaction.Transaction) util.Fixed8 { return util.Fixed8(0) }
func (fs *feer) SystemFee(*transaction.Transaction) util.Fixed8 { return util.Fixed8(0) } func (fs *feer) SystemFee(*transaction.Transaction) util.Fixed8 { return util.Fixed8(0) }

View file

@ -1019,10 +1019,10 @@ func (bc *Blockchain) SystemFee(t *transaction.Transaction) util.Fixed8 {
return bc.GetConfig().SystemFee.TryGetValue(t.Type) return bc.GetConfig().SystemFee.TryGetValue(t.Type)
} }
// IsLowPriority flags a transaction as low priority if the network fee is less than // IsLowPriority checks given fee for being less than configured
// LowPriorityThreshold. // LowPriorityThreshold.
func (bc *Blockchain) IsLowPriority(t *transaction.Transaction) bool { func (bc *Blockchain) IsLowPriority(fee util.Fixed8) bool {
return bc.NetworkFee(t) < util.Fixed8FromFloat(bc.GetConfig().LowPriorityThreshold) return fee < util.Fixed8FromFloat(bc.GetConfig().LowPriorityThreshold)
} }
// GetMemPool returns the memory pool of the blockchain. // GetMemPool returns the memory pool of the blockchain.

View file

@ -8,7 +8,7 @@ import (
// Feer is an interface that abstract the implementation of the fee calculation. // Feer is an interface that abstract the implementation of the fee calculation.
type Feer interface { type Feer interface {
NetworkFee(t *transaction.Transaction) util.Fixed8 NetworkFee(t *transaction.Transaction) util.Fixed8
IsLowPriority(t *transaction.Transaction) bool IsLowPriority(util.Fixed8) bool
FeePerByte(t *transaction.Transaction) util.Fixed8 FeePerByte(t *transaction.Transaction) util.Fixed8
SystemFee(t *transaction.Transaction) util.Fixed8 SystemFee(t *transaction.Transaction) util.Fixed8
} }

View file

@ -128,8 +128,8 @@ func (mp *Pool) Add(t *transaction.Transaction, fee Feer) error {
timeStamp: time.Now().UTC(), timeStamp: time.Now().UTC(),
perByteFee: fee.FeePerByte(t), perByteFee: fee.FeePerByte(t),
netFee: fee.NetworkFee(t), netFee: fee.NetworkFee(t),
isLowPrio: fee.IsLowPriority(t),
} }
pItem.isLowPrio = fee.IsLowPriority(pItem.netFee)
mp.lock.Lock() mp.lock.Lock()
if !mp.verifyInputs(t) { if !mp.verifyInputs(t) {
mp.lock.Unlock() mp.lock.Unlock()

View file

@ -22,7 +22,7 @@ func (fs *FeerStub) NetworkFee(*transaction.Transaction) util.Fixed8 {
return fs.netFee return fs.netFee
} }
func (fs *FeerStub) IsLowPriority(*transaction.Transaction) bool { func (fs *FeerStub) IsLowPriority(util.Fixed8) bool {
return fs.lowPriority return fs.lowPriority
} }

View file

@ -122,7 +122,7 @@ func (chain testChain) GetMemPool() *mempool.Pool {
panic("TODO") panic("TODO")
} }
func (chain testChain) IsLowPriority(*transaction.Transaction) bool { func (chain testChain) IsLowPriority(util.Fixed8) bool {
panic("TODO") panic("TODO")
} }