From 8e26a7eb1385c017191b6e7c9b4864df2cc7c565 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Tue, 17 Aug 2021 11:06:17 +0700 Subject: [PATCH] fix many nil-pointers --- txpool/fetch.go | 2 +- txpool/pool.go | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/txpool/fetch.go b/txpool/fetch.go index 35a710e3b..24c0d9535 100644 --- a/txpool/fetch.go +++ b/txpool/fetch.go @@ -55,7 +55,7 @@ type Timings struct { var DefaultTimings = Timings{ syncToNewPeersEvery: 2 * time.Minute, - logEvery: 10 * time.Second, + logEvery: 30 * time.Second, } // NewFetch creates a new fetch object that will work with given sentry clients. Since the diff --git a/txpool/pool.go b/txpool/pool.go index cbd25ac60..a8470ab41 100644 --- a/txpool/pool.go +++ b/txpool/pool.go @@ -150,6 +150,7 @@ func New(newTxs chan Hashes, db kv.RwDB) (*TxPool, error) { } return &TxPool{ lock: &sync.RWMutex{}, + senderIDs: map[string]uint64{}, senderInfo: map[uint64]*senderInfo{}, byHash: map[string]*metaTx{}, localsHistory: localsHistory, @@ -327,9 +328,10 @@ func (p *TxPool) setBaseFee(protocolBaseFee, pendingBaseFee uint64) (uint64, uin hasNewVal := pendingBaseFee > 0 if pendingBaseFee < protocolBaseFee { pendingBaseFee = protocolBaseFee + hasNewVal = true } if hasNewVal { - p.protocolBaseFee.Store(pendingBaseFee) + p.pendingBaseFee.Store(pendingBaseFee) } log.Debug("set base fee", "protocol", protocolBaseFee, "pending", pendingBaseFee) return protocolBaseFee, p.pendingBaseFee.Load() @@ -339,9 +341,9 @@ func (p *TxPool) OnNewBlock(coreDB kv.Tx, stateChanges map[string]senderInfo, un log.Debug("[txpool.onNewBlock]", "unwinded", len(unwindTxs.txs), "mined", len(minedTxs.txs), "protocolBaseFee", protocolBaseFee, "blockHeight", blockHeight) p.lock.Lock() defer p.lock.Unlock() - log.Debug("before set base fee", "protocol", protocolBaseFee, "pending", pendingBaseFee) p.blockHeight.Store(blockHeight) protocolBaseFee, pendingBaseFee = p.setBaseFee(protocolBaseFee, pendingBaseFee) + log.Debug("before set base fee", "protocol", p.protocolBaseFee.Load(), "pending", p.pendingBaseFee.Load()) if err := unwindTxs.Valid(); err != nil { return err @@ -358,7 +360,7 @@ func (p *TxPool) OnNewBlock(coreDB kv.Tx, stateChanges map[string]senderInfo, un } for addr, id := range p.senderIDs { // merge state changes if v, ok := stateChanges[addr]; ok { - p.senderInfo[id] = &v + p.senderInfo[id] = newSenderInfo(v.nonce, v.balance) } } @@ -428,7 +430,7 @@ func setTxSenderID(coreDB kv.Tx, senderIDSequence *uint64, senderIDs map[string] if err != nil { return err } - sendersInfo[txs.txs[i].senderID] = &senderInfo{nonce: nonce, balance: balance} + sendersInfo[txs.txs[i].senderID] = newSenderInfo(nonce, balance) } } return nil