From 87ef16fd5b284269a86d2bb98603eb64ad375b5d Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Fri, 27 Aug 2021 09:51:58 +0700 Subject: [PATCH] add state check assert routine --- txpool/pool.go | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/txpool/pool.go b/txpool/pool.go index 9993ff175..0f3582f9d 100644 --- a/txpool/pool.go +++ b/txpool/pool.go @@ -558,6 +558,26 @@ var PoolProtocolBaseFeeKey = []byte("protocol_base_fee") func (sc *SendersCache) flush(tx kv.RwTx, byNonce *ByNonce) error { sc.lock.Lock() defer sc.lock.Unlock() + + //TODO: it's very naive eviction of all senders without transactions - and with O(n) complexity. We need more soft eviction policy. + if err := tx.ForEach(kv.PooledSenderID, nil, func(addr, id []byte) error { + if byNonce.count(binary.BigEndian.Uint64(id)) > 0 { + return nil + } + if err := tx.Delete(kv.PooledSenderID, addr, nil); err != nil { + return err + } + if err := tx.Delete(kv.PooledSenderIDToAdress, id, nil); err != nil { + return err + } + if err := tx.Delete(kv.PooledSender, id, nil); err != nil { + return err + } + return nil + }); err != nil { + return err + } + encID := make([]byte, 8) encIDs := make([]byte, 0, 1024) for addr, id := range sc.senderIDs { @@ -579,25 +599,6 @@ func (sc *SendersCache) flush(tx kv.RwTx, byNonce *ByNonce) error { encIDs = append(encIDs, encID...) } - //TODO: it's very naive eviction of all senders without transactions - and with O(n) complexity. We need more soft eviction policy. - if err := tx.ForEach(kv.PooledSenderID, nil, func(addr, id []byte) error { - if byNonce.count(binary.BigEndian.Uint64(id)) > 0 { - return nil - } - if err := tx.Delete(kv.PooledSenderID, addr, nil); err != nil { - return err - } - if err := tx.Delete(kv.PooledSenderIDToAdress, id, nil); err != nil { - return err - } - if err := tx.Delete(kv.PooledSender, id, nil); err != nil { - return err - } - return nil - }); err != nil { - return err - } - sc.senderIDs = map[string]uint64{} v := make([]byte, 8, 8+32)