diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index 81dfb958e..46e594d7d 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -1782,9 +1782,12 @@ func (pool *LegacyPool) truncateQueue() { // it assumes that the pool lock is being held func (pool *LegacyPool) clearPendingAndQueued(newHead *types.Header) { // Iterate over all accounts and demote any non-executable transactions + addrsForWhichTxsRemoved := []common.Address{} + for addr, list := range pool.pending { dropped, invalids := list.ClearList() - pendingGauge.Dec(int64(len(dropped) + len(invalids))) + + pendingGauge.Dec(int64(dropped.Len() + invalids.Len())) for _, tx := range dropped { pool.all.Remove(tx.Hash()) @@ -1796,12 +1799,14 @@ func (pool *LegacyPool) clearPendingAndQueued(newHead *types.Header) { if list.Empty() { delete(pool.pending, addr) delete(pool.beats, addr) + + addrsForWhichTxsRemoved = append(addrsForWhichTxsRemoved, addr) } } for addr, list := range pool.queue { dropped, invalids := list.ClearList() - queuedGauge.Dec(int64(len(dropped) + len(invalids))) + queuedGauge.Dec(int64(dropped.Len() + invalids.Len())) for _, tx := range dropped { pool.all.Remove(tx.Hash()) @@ -1811,12 +1816,13 @@ func (pool *LegacyPool) clearPendingAndQueued(newHead *types.Header) { } if list.Empty() { - if _, ok := pool.queue[addr]; !ok { - pool.reserve(addr, false) - } delete(pool.queue, addr) } } + + for _, addr := range addrsForWhichTxsRemoved { + pool.reserve(addr, false) + } } // demoteUnexecutables removes invalid and processed transactions from the pools diff --git a/core/txpool/legacypool/legacypool_test.go b/core/txpool/legacypool/legacypool_test.go index 00620ec68..a1395bebc 100644 --- a/core/txpool/legacypool/legacypool_test.go +++ b/core/txpool/legacypool/legacypool_test.go @@ -689,21 +689,15 @@ func TestDropping(t *testing.T) { tx11 = transaction(11, 200, key) tx12 = transaction(12, 300, key) ) - pool.all.Add(tx0, false) - pool.priced.Put(tx0, false) - pool.promoteTx(account, tx0.Hash(), tx0) - pool.all.Add(tx1, false) - pool.priced.Put(tx1, false) - pool.promoteTx(account, tx1.Hash(), tx1) + pool.add(tx0, false) + pool.add(tx1, false) + pool.add(tx2, false) + pool.add(tx10, false) + pool.add(tx11, false) + pool.add(tx12, false) - pool.all.Add(tx2, false) - pool.priced.Put(tx2, false) - pool.promoteTx(account, tx2.Hash(), tx2) - - pool.enqueueTx(tx10.Hash(), tx10, false, true) - pool.enqueueTx(tx11.Hash(), tx11, false, true) - pool.enqueueTx(tx12.Hash(), tx12, false, true) + pool.promoteExecutables([]common.Address{account}) // Check that pre and post validations leave the pool as is if pool.pending[account].Len() != 3 { diff --git a/grpc/shared/validation.go b/grpc/shared/validation.go index e0bd7ea84..2848846e8 100644 --- a/grpc/shared/validation.go +++ b/grpc/shared/validation.go @@ -118,6 +118,7 @@ func validateAndUnmarshallSequenceAction(tx *sequencerblockv1.RollupData) (*type } func unmarshallAllocationTxs(allocation *bundlev1alpha1.Allocation, prevBlockHash []byte, auctioneerBech32Address string, addressPrefix string) (types.Transactions, error) { + log.Info("Found a potential allocation in the rollup data. Checking if it is valid.") processedTxs := types.Transactions{} payload := allocation.GetPayload() @@ -136,14 +137,15 @@ func unmarshallAllocationTxs(allocation *bundlev1alpha1.Allocation, prevBlockHas message, err := proto.Marshal(allocation.GetPayload()) if err != nil { - return nil, WrapError(err, "failed to marshal allocation") + return nil, WrapError(err, "failed to marshal allocation to verify signature") } signature := allocation.GetSignature() if !ed25519.Verify(publicKey, message, signature) { - return nil, fmt.Errorf("failed to verify signature") + return nil, fmt.Errorf("signature in allocation does not match the public key") } + log.Info("Allocation is valid. Unmarshalling the transactions in the bundle.") // unmarshall the transactions in the bundle for _, allocationTx := range payload.GetTransactions() { ethtx := new(types.Transaction) @@ -162,6 +164,7 @@ func unmarshallAllocationTxs(allocation *bundlev1alpha1.Allocation, prevBlockHas // TODO - this function has become too big. we should start breaking it down func UnbundleRollupDataTransactions(txs []*sequencerblockv1.RollupData, height uint64, bridgeAddresses map[string]*params.AstriaBridgeAddressConfig, bridgeAllowedAssets map[string]struct{}, prevBlockHash []byte, auctioneerBech32Address string, addressPrefix string) types.Transactions { + processedTxs := types.Transactions{} allocationTxs := types.Transactions{} // we just return the allocation here and do not unmarshall the transactions in the bundle if we find it diff --git a/grpc/shared/validation_test.go b/grpc/shared/validation_test.go index 57c404366..a917bc2c4 100644 --- a/grpc/shared/validation_test.go +++ b/grpc/shared/validation_test.go @@ -159,7 +159,7 @@ func TestUnmarshallAllocationTxs(t *testing.T) { }, prevBlockHash: []byte("prev rollup block hash"), expectedOutput: types.Transactions{}, - wantErr: "failed to verify signature", + wantErr: "signature in allocation does not match the public key", }, { description: "valid allocation",