From 3204f70409a400f791cfa1cfabc441668cdbffdc Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Wed, 4 Aug 2021 11:53:30 +0700 Subject: [PATCH] pool constructor --- txpool/pool.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/txpool/pool.go b/txpool/pool.go index cc893a023..b39f8224c 100644 --- a/txpool/pool.go +++ b/txpool/pool.go @@ -99,8 +99,7 @@ func (i *nonce2TxItem) Less(than btree.Item) bool { // TxPool - holds all pool-related data structures and lock-based tiny methods // most of logic implemented by pure tests-friendly functions type TxPool struct { - lock *sync.RWMutex - logger log.Logger //nolint + lock *sync.RWMutex protocolBaseFee atomic.Uint64 blockBaseFee atomic.Uint64 @@ -117,6 +116,20 @@ type TxPool struct { //lastTxPropagationTimestamp time.Time } +func New() *TxPool { + localsHistory, _ := lru.New(1024) + return &TxPool{ + lock: &sync.RWMutex{}, + senderInfo: map[uint64]SenderInfo{}, + byHash: map[string]*MetaTx{}, + localsHistory: localsHistory, + recentlyConnectedPeers: &recentlyConnectedPeers{}, + pending: NewSubPool(), + baseFee: NewSubPool(), + queued: NewSubPool(), + } +} + func (p *TxPool) GetRlp(hash []byte) []byte { p.lock.RLock() defer p.lock.RUnlock() @@ -557,12 +570,6 @@ type PoolImpl struct { logger log.Logger } -func NewPool() *PoolImpl { - return &PoolImpl{ - recentlyConnectedPeers: &recentlyConnectedPeers{}, - } -} - // Loop - does: // send pending byHash to p2p: // - new byHash