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:
parent
bc31ab3d2c
commit
5df726db68
5 changed files with 13 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -10,4 +10,5 @@ import (
|
|||
type Feer interface {
|
||||
FeePerByte() int64
|
||||
GetUtilityTokenBalance(util.Uint160) *big.Int
|
||||
BlockHeight() uint32
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
@ -30,8 +29,8 @@ var (
|
|||
|
||||
// item represents a transaction in the the Memory pool.
|
||||
type item struct {
|
||||
txn *transaction.Transaction
|
||||
timeStamp time.Time
|
||||
txn *transaction.Transaction
|
||||
blockStamp uint32
|
||||
}
|
||||
|
||||
// items is a slice of item.
|
||||
|
@ -148,8 +147,8 @@ func checkBalance(tx *transaction.Transaction, balance utilityBalanceAndFees) er
|
|||
// Add tries to add given transaction to the Pool.
|
||||
func (mp *Pool) Add(t *transaction.Transaction, fee Feer) error {
|
||||
var pItem = item{
|
||||
txn: t,
|
||||
timeStamp: time.Now().UTC(),
|
||||
txn: t,
|
||||
blockStamp: fee.BlockHeight(),
|
||||
}
|
||||
mp.lock.Lock()
|
||||
if mp.containsKey(t.Hash()) {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue