add state check assert routine

This commit is contained in:
alex.sharov 2021-08-28 09:21:23 +07:00
parent ed2b1c3232
commit fdd1498415
2 changed files with 5 additions and 72 deletions

View File

@ -792,6 +792,8 @@ func (p *TxPool) printDebug(prefix string) {
func (p *TxPool) logStats(tx kv.Tx) error {
protocolBaseFee, pendingBaseFee := p.protocolBaseFee.Load(), p.pendingBaseFee.Load()
p.lock.RLock()
defer p.lock.RUnlock()
idsInMem, idsInDb, err := p.senders.idsCount(tx)
if err != nil {
return err
@ -800,8 +802,6 @@ func (p *TxPool) logStats(tx kv.Tx) error {
if err != nil {
return err
}
p.lock.RLock()
defer p.lock.RUnlock()
log.Info(fmt.Sprintf("baseFee: %dm->%dm; queuesSize: pending=%d/%d, baseFee=%d/%d, queued=%d/%d; sendersCache: id=%d+%d,info=%d+%d",
protocolBaseFee/1_000_000, pendingBaseFee/1_000_000,
p.pending.Len(), PendingSubPoolLimit, p.baseFee.Len(), BaseFeeSubPoolLimit, p.queued.Len(), QueuedSubPoolLimit,
@ -1083,9 +1083,6 @@ func (p *TxPool) discardLocked(mt *metaTx) {
func (p *TxPool) fromDB(ctx context.Context, tx kv.RwTx, coreTx kv.Tx) error {
p.lock.Lock()
defer p.lock.Unlock()
if err := p.senders.fromDB(ctx, tx, coreTx); err != nil {
return err
}
if ASSERT {
_ = tx.ForEach(kv.PooledTransaction, nil, func(k, v []byte) error {
vv, err := tx.GetOne(kv.PooledSenderIDToAdress, v[:8])
@ -1103,6 +1100,9 @@ func (p *TxPool) fromDB(ctx context.Context, tx kv.RwTx, coreTx kv.Tx) error {
return nil
})
}
if err := p.senders.fromDB(ctx, tx, coreTx); err != nil {
return err
}
if err := tx.ForEach(kv.RecentLocalTransaction, nil, func(k, v []byte) error {
hashID := [32]byte{}

View File

@ -15,70 +15,3 @@
*/
package txpool
/*
func TestSubPoolOrder(t *testing.T) {
sub := NewSubPool()
sub.OnNewTxs(&metaTx{subPool: 0b10101})
sub.OnNewTxs(&metaTx{subPool: 0b11110})
sub.OnNewTxs(&metaTx{subPool: 0b11101})
sub.OnNewTxs(&metaTx{subPool: 0b10001})
require.Equal(t, uint8(0b11110), uint8(sub.Best().subPool))
require.Equal(t, uint8(0b10001), uint8(sub.Worst().subPool))
require.Equal(t, uint8(sub.Best().subPool), uint8(sub.PopBest().subPool))
require.Equal(t, uint8(sub.Worst().subPool), uint8(sub.PopWorst().subPool))
sub = NewSubPool()
sub.OnNewTxs(&metaTx{subPool: 0b00001})
sub.OnNewTxs(&metaTx{subPool: 0b01110})
sub.OnNewTxs(&metaTx{subPool: 0b01101})
sub.OnNewTxs(&metaTx{subPool: 0b00101})
require.Equal(t, uint8(0b00001), uint8(sub.Worst().subPool))
require.Equal(t, uint8(0b01110), uint8(sub.Best().subPool))
require.Equal(t, uint8(sub.Worst().subPool), uint8(sub.PopWorst().subPool))
require.Equal(t, uint8(sub.Best().subPool), uint8(sub.PopBest().subPool))
}
func TestSubPoolsPromote(t *testing.T) {
s1 := []uint8{0b11000, 0b101, 0b111}
s2 := []uint8{0b11000, 0b101, 0b111}
s3 := []uint8{0b11000, 0b101, 0b111}
pending, baseFee, queued := NewSubPool(), NewSubPool(), NewSubPool()
for _, i := range s1 {
pending.OnNewTxs(&metaTx{subPool: SubPoolMarker(i & 0b11111)})
}
for _, i := range s2 {
baseFee.OnNewTxs(&metaTx{subPool: SubPoolMarker(i & 0b11111)})
}
for _, i := range s3 {
queued.OnNewTxs(&metaTx{subPool: SubPoolMarker(i & 0b11111)})
}
promote(pending, baseFee, queued)
if pending.Worst() != nil {
require.Less(t, uint8(0b01111), uint8(pending.Worst().subPool))
}
if baseFee.Worst() != nil {
require.Less(t, uint8(0b01111), uint8(baseFee.Worst().subPool))
}
if queued.Worst() != nil {
require.Less(t, uint8(0b01111), uint8(queued.Worst().subPool))
}
// if limit reached, worst must be greater than X
}
//nolint
func hexToSubPool(s string) []uint8 {
a, err := hex.DecodeString(s)
if err != nil {
panic(err)
}
for i := range a {
a[i] &= 0b11111
}
return a
}
*/