add state check assert routine

This commit is contained in:
alex.sharov 2021-08-27 09:51:58 +07:00
parent f160918baa
commit 87ef16fd5b

View File

@ -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)