Skip to content

Commit

Permalink
don't broadcast blob txs per eip-4844 (ethereum#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
roberto-bayardo authored Jan 19, 2023
1 parent d8a774b commit db177b8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
14 changes: 9 additions & 5 deletions eth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,13 +636,17 @@ func (h *handler) BroadcastTransactions(txs types.Transactions) {
annos = make(map[*ethPeer][]common.Hash) // Set peer->hash to announce

)
// Broadcast transactions to a batch of peers not knowing about it
// Broadcast transactions to a batch of peers not knowing about it, exluding
// only blob transactions which are never to be broadcast per EIP-4844
for _, tx := range txs {
peers := h.peers.peersWithoutTransaction(tx.Hash())
// Send the tx unconditionally to a subset of our peers
numDirect := int(math.Sqrt(float64(len(peers))))
for _, peer := range peers[:numDirect] {
txset[peer] = append(txset[peer], tx.Hash())
var numDirect int
if tx.Type() != types.BlobTxType {
// Send the tx unconditionally to a subset of our peers
numDirect = int(math.Sqrt(float64(len(peers))))
for _, peer := range peers[:numDirect] {
txset[peer] = append(txset[peer], tx.Hash())
}
}
// For the remaining peers, send announcement only
for _, peer := range peers[numDirect:] {
Expand Down
7 changes: 7 additions & 0 deletions eth/handler_eth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ func (h *testEthHandler) Handle(peer *eth.Peer, packet eth.Packet) error {
return nil

case *eth.TransactionsPacket:
txs := packet.Unwrap()
for i, tx := range txs {
if tx.Type() == types.BlobTxType {
// blob txs should never be broadcast
return fmt.Errorf("transaction %v is a blob tx", i)
}
}
h.txBroadcasts.Send(packet.Unwrap())
return nil

Expand Down
7 changes: 7 additions & 0 deletions eth/protocols/eth/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,13 @@ func handleTransactions(backend Backend, msg Decoder, peer *Peer) error {
if tx == nil {
return fmt.Errorf("%w: transaction %d is nil", errDecode, i)
}
// TODO(eip-4844): implement penalizing of clients who send unrequested
// blob transactions. While we're interop testing we'll go ahead and
// accept any that happen to come our way.
/*if tx.Tx.Type() == types.BlobTxType {
// blob txs should never be broadcast
return fmt.Errorf("transaction %v is a blob tx", i)
}*/
peer.markTransaction(tx.Hash())
}
return backend.Handle(peer, &txs)
Expand Down

0 comments on commit db177b8

Please sign in to comment.