mempool: replace timeStamp with blockStamp

Time is not really relevant for us here and we don't use this timestamp in any
way. Yet it occupies 24 bytes and we do two clock_gettime calls to get it.

Replace it with blockStamp which is going to be used in the future for
transaction retransmissions.

It allows to improve single-node TPS by another 3%.
This commit is contained in:
Roman Khimov 2020-09-09 15:32:31 +03:00
parent bc31ab3d2c
commit 5df726db68
5 changed files with 13 additions and 6 deletions

View file

@ -22,7 +22,6 @@ type Blockchainer interface {
AddHeaders(...*block.Header) error
AddBlock(*block.Block) error
AddStateRoot(r *state.MPTRoot) error
BlockHeight() uint32
CalculateClaimable(value *big.Int, startHeight, endHeight uint32) *big.Int
Close()
HeaderHeight() uint32

View file

@ -10,4 +10,5 @@ import (
type Feer interface {
FeePerByte() int64
GetUtilityTokenBalance(util.Uint160) *big.Int
BlockHeight() uint32
}

View file

@ -5,7 +5,6 @@ import (
"math/big"
"sort"
"sync"
"time"
"github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/util"
@ -31,7 +30,7 @@ var (
// item represents a transaction in the the Memory pool.
type item struct {
txn *transaction.Transaction
timeStamp time.Time
blockStamp uint32
}
// items is a slice of item.
@ -149,7 +148,7 @@ func checkBalance(tx *transaction.Transaction, balance utilityBalanceAndFees) er
func (mp *Pool) Add(t *transaction.Transaction, fee Feer) error {
var pItem = item{
txn: t,
timeStamp: time.Now().UTC(),
blockStamp: fee.BlockHeight(),
}
mp.lock.Lock()
if mp.containsKey(t.Hash()) {

View file

@ -23,6 +23,10 @@ func (fs *FeerStub) FeePerByte() int64 {
return fs.feePerByte
}
func (fs *FeerStub) BlockHeight() uint32 {
return 0
}
func (fs *FeerStub) GetUtilityTokenBalance(uint160 util.Uint160) *big.Int {
return balance
}

View file

@ -91,6 +91,10 @@ func (fs *FeerStub) FeePerByte() int64 {
return 0
}
func (fs *FeerStub) BlockHeight() uint32 {
return 0
}
func (fs *FeerStub) GetUtilityTokenBalance(acc util.Uint160) *big.Int {
return big.NewInt(1000000 * native.GASFactor)
}