Implement sharded mempool

This commit is contained in:
Arunima Chaudhuri 2025-06-11 00:17:04 +05:30
parent a4ae7bab4d
commit c0991455cd

View file

@ -514,16 +514,36 @@ func handlePooledTransactions(backend Backend, msg Decoder, peer *Peer) error {
if err := msg.Decode(&txs); err != nil { if err := msg.Decode(&txs); err != nil {
return err return err
} }
peerID := peer.ID()
peerIDLast4 := peerID[len(peerID)-1] & 0x0F
var filteredTxs []*types.Transaction
for i, tx := range txs.PooledTransactionsResponse { for i, tx := range txs.PooledTransactionsResponse {
// Validate and mark the remote transaction // Validate and mark the remote transaction
if tx == nil { if tx == nil {
return fmt.Errorf("PooledTransactions: transaction %d is nil", i) return fmt.Errorf("PooledTransactions: transaction %d is nil", i)
} }
txHash := tx.Hash()
txHashLast4 := txHash[len(txHash)-1] & 0x0F
if txHashLast4 != peerIDLast4 && tx.Type() == types.BlobTxType {
continue
}
peer.markTransaction(tx.Hash()) peer.markTransaction(tx.Hash())
filteredTxs = append(filteredTxs, tx)
} }
requestTracker.Fulfil(peer.id, peer.version, PooledTransactionsMsg, txs.RequestId) requestTracker.Fulfil(peer.id, peer.version, PooledTransactionsMsg, txs.RequestId)
return backend.Handle(peer, &txs.PooledTransactionsResponse) if len(filteredTxs) == 0 {
return nil
}
return backend.Handle(peer, &PooledTransactionsPacket{
PooledTransactionsResponse: filteredTxs,
RequestId: txs.RequestId,
})
} }
func handleBlockRangeUpdate(backend Backend, msg Decoder, peer *Peer) error { func handleBlockRangeUpdate(backend Backend, msg Decoder, peer *Peer) error {