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{}
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) 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)
}
// IsLowPriority flags a transaction as low priority if the network fee is less than
// IsLowPriority checks given fee for being less than configured
// LowPriorityThreshold.
func (bc *Blockchain) IsLowPriority(t *transaction.Transaction) bool {
return bc.NetworkFee(t) < util.Fixed8FromFloat(bc.GetConfig().LowPriorityThreshold)
func (bc *Blockchain) IsLowPriority(fee util.Fixed8) bool {
return fee < util.Fixed8FromFloat(bc.GetConfig().LowPriorityThreshold)
}
// 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.
type Feer interface {
NetworkFee(t *transaction.Transaction) util.Fixed8
IsLowPriority(t *transaction.Transaction) bool
IsLowPriority(util.Fixed8) bool
FeePerByte(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(),
perByteFee: fee.FeePerByte(t),
netFee: fee.NetworkFee(t),
isLowPrio: fee.IsLowPriority(t),
}
pItem.isLowPrio = fee.IsLowPriority(pItem.netFee)
mp.lock.Lock()
if !mp.verifyInputs(t) {
mp.lock.Unlock()

View file

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

View file

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