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 committed by Evgenii Stratonikov
parent 49d176010e
commit 06f3c34981
5 changed files with 11 additions and 4 deletions

View file

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

View file

@ -7,6 +7,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 {
BlockHeight() uint32
NetworkFee(t *transaction.Transaction) util.Fixed8 NetworkFee(t *transaction.Transaction) util.Fixed8
IsLowPriority(util.Fixed8) bool IsLowPriority(util.Fixed8) bool
FeePerByte(t *transaction.Transaction) util.Fixed8 FeePerByte(t *transaction.Transaction) util.Fixed8

View file

@ -4,7 +4,6 @@ import (
"errors" "errors"
"sort" "sort"
"sync" "sync"
"time"
"github.com/nspcc-dev/neo-go/pkg/core/transaction" "github.com/nspcc-dev/neo-go/pkg/core/transaction"
"github.com/nspcc-dev/neo-go/pkg/util" "github.com/nspcc-dev/neo-go/pkg/util"
@ -26,7 +25,7 @@ var (
// item represents a transaction in the the Memory pool. // item represents a transaction in the the Memory pool.
type item struct { type item struct {
txn *transaction.Transaction txn *transaction.Transaction
timeStamp time.Time blockStamp uint32
perByteFee util.Fixed8 perByteFee util.Fixed8
netFee util.Fixed8 netFee util.Fixed8
isLowPrio bool isLowPrio bool
@ -162,7 +161,7 @@ func dropInputFromSortedSlice(slice *[]*transaction.Input, input *transaction.In
func (mp *Pool) Add(t *transaction.Transaction, fee Feer) error { func (mp *Pool) Add(t *transaction.Transaction, fee Feer) error {
var pItem = &item{ var pItem = &item{
txn: t, txn: t,
timeStamp: time.Now().UTC(), blockStamp: fee.BlockHeight(),
perByteFee: fee.FeePerByte(t), perByteFee: fee.FeePerByte(t),
netFee: fee.NetworkFee(t), netFee: fee.NetworkFee(t),
} }

View file

@ -18,6 +18,10 @@ type FeerStub struct {
perByteFee util.Fixed8 perByteFee util.Fixed8
} }
func (fs *FeerStub) BlockHeight() uint32 {
return 0
}
func (fs *FeerStub) NetworkFee(*transaction.Transaction) util.Fixed8 { func (fs *FeerStub) NetworkFee(*transaction.Transaction) util.Fixed8 {
return fs.netFee return fs.netFee
} }

View file

@ -85,6 +85,10 @@ func initServerWithInMemoryChain(t *testing.T) (*core.Blockchain, *Server, *http
type FeerStub struct{} type FeerStub struct{}
func (fs *FeerStub) BlockHeight() uint32 {
return 0
}
func (fs *FeerStub) NetworkFee(*transaction.Transaction) util.Fixed8 { func (fs *FeerStub) NetworkFee(*transaction.Transaction) util.Fixed8 {
return 0 return 0
} }