From c233bcb2e6311756a73ec653c8239295da1ae7c0 Mon Sep 17 00:00:00 2001 From: "alex.sharov" Date: Sun, 22 Aug 2021 17:29:39 +0700 Subject: [PATCH] persistence --- txpool/pool.go | 18 ++++++++++-------- txpool/pool_fuzz_test.go | 3 +++ txpool/types.go | 1 - 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/txpool/pool.go b/txpool/pool.go index 386118020..f38c7d02f 100644 --- a/txpool/pool.go +++ b/txpool/pool.go @@ -600,7 +600,6 @@ func onNewTxs(senders *SendersCache, newTxs TxSlots, protocolBaseFee, pendingBas } } }) - fmt.Printf("aaa: %d\n", pending.Len()) for _, sender := range changedSenders { onSenderChange(sender, protocolBaseFee, pendingBaseFee) @@ -609,6 +608,7 @@ func onNewTxs(senders *SendersCache, newTxs TxSlots, protocolBaseFee, pendingBas pending.EnforceInvariants() baseFee.EnforceInvariants() queued.EnforceInvariants() + fmt.Printf("aaa2: %d, %d, %d\n", pending.Len(), baseFee.Len(), queued.Len()) promote(pending, baseFee, queued, func(i *metaTx) { delete(byHash, string(i.Tx.idHash[:])) @@ -618,6 +618,7 @@ func onNewTxs(senders *SendersCache, newTxs TxSlots, protocolBaseFee, pendingBas localsHistory.Add(i.Tx.idHash, struct{}{}) } }) + fmt.Printf("aaa3: %d, %d, %d\n", pending.Len(), baseFee.Len(), queued.Len()) return nil } @@ -770,7 +771,6 @@ func (p *TxPool) fromDB(tx kv.Tx, senders *SendersCache) error { txs.txs[i] = &TxSlot{} _, err := parseCtx.ParseTransaction(v, 8+8, txs.txs[i], nil) if err != nil { - fmt.Printf("ddd1 load: %s\n", err) return err } txs.txs[i].senderID = binary.BigEndian.Uint64(v) @@ -780,21 +780,23 @@ func (p *TxPool) fromDB(tx kv.Tx, senders *SendersCache) error { txs.isLocal[i] = isLocalTx i++ } - fmt.Printf("ddd load: %d\n", len(p.byHash)) - protocolBaseFee, err := tx.GetOne(kv.PoolInfo, []byte("protocol_base_fee")) + protocolBaseFeeV, err := tx.GetOne(kv.PoolInfo, []byte("protocol_base_fee")) if err != nil { return err } - pendingBaseFee, err := tx.GetOne(kv.PoolInfo, []byte("pending_base_fee")) + pendingBaseFeeV, err := tx.GetOne(kv.PoolInfo, []byte("pending_base_fee")) if err != nil { return err } - fmt.Printf("a:%d,%d,%d\n", total, len(txs.txs), i) - if err := onNewTxs(senders, txs, binary.BigEndian.Uint64(protocolBaseFee), binary.BigEndian.Uint64(pendingBaseFee), p.pending, p.baseFee, p.queued, p.byHash, p.localsHistory); err != nil { + protocolBaseFee := binary.BigEndian.Uint64(protocolBaseFeeV) + pendingBaseFee := binary.BigEndian.Uint64(pendingBaseFeeV) + if err := onNewTxs(senders, txs, protocolBaseFee, pendingBaseFee, p.pending, p.baseFee, p.queued, p.byHash, p.localsHistory); err != nil { return err } + p.pendingBaseFee.Store(pendingBaseFee) + p.protocolBaseFee.Store(protocolBaseFee) //TODO: flush deletes @@ -1034,7 +1036,7 @@ func promote(pending, baseFee, queued *SubPool, discard func(tx *metaTx)) { if worst.subPool >= 0b11111 { // TODO: here must 'subPool == 0b1111' or 'subPool <= 0b1111' ? break } - pending.PopWorst() + discard(pending.PopWorst()) } //3. If the top element in the best yellow queue has subPool == 0b1111, promote to the green pool. diff --git a/txpool/pool_fuzz_test.go b/txpool/pool_fuzz_test.go index d15801864..151f4bdb4 100644 --- a/txpool/pool_fuzz_test.go +++ b/txpool/pool_fuzz_test.go @@ -7,6 +7,7 @@ import ( "bytes" "context" "encoding/binary" + "fmt" "testing" "github.com/google/btree" @@ -503,6 +504,8 @@ func FuzzOnNewBlocks11(f *testing.F) { require.NoError(t, err) check(minedTxs1, TxSlots{}, "fromDB") checkNotify(minedTxs1, TxSlots{}, "fromDB") + fmt.Printf("bef: %d, %d, %d\n", pool.pending.Len(), pool.baseFee.Len(), pool.queued.Len()) + fmt.Printf("bef2: %d, %d, %d\n", p2.pending.Len(), p2.baseFee.Len(), p2.queued.Len()) assert.Equal(pool.pending.Len(), p2.pending.Len()) assert.Equal(pool.baseFee.Len(), p2.baseFee.Len()) assert.Equal(pool.queued.Len(), p2.queued.Len()) diff --git a/txpool/types.go b/txpool/types.go index 56aea85cb..c7a3ba96b 100644 --- a/txpool/types.go +++ b/txpool/types.go @@ -152,7 +152,6 @@ func (ctx *TxParseContext) ParseTransaction(payload []byte, pos int, slot *TxSlo } dataPos, dataLen, err = rlp.List(payload, p) if err != nil { - fmt.Printf("ii: %d, %x, %x\n", p, payload, payload[8:]) return 0, fmt.Errorf("%s: envelope Prefix: %v", ParseTransactionErrorPrefix, err) } // Hash the envelope, not the full payload