Skip to content

Commit

Permalink
buffer the reserved addresses and remove them at once
Browse files Browse the repository at this point in the history
  • Loading branch information
bharath-123 committed Jan 3, 2025
1 parent c6b52cc commit 359c71f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
16 changes: 11 additions & 5 deletions core/txpool/legacypool/legacypool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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())
Expand All @@ -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
Expand Down
20 changes: 7 additions & 13 deletions core/txpool/legacypool/legacypool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions grpc/shared/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion grpc/shared/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 359c71f

Please sign in to comment.