Skip to content
This repository has been archived by the owner on Sep 23, 2023. It is now read-only.

Commit

Permalink
Fix broadcast issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Somnath committed Aug 18, 2023
1 parent 0f311ab commit 860701b
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions txpool/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -1516,6 +1516,7 @@ func MainLoop(ctx context.Context, db kv.RwDB, coreDB kv.RoDB, p *TxPool, newTxs
var remoteTxSizes []uint32
var remoteTxHashes types.Hashes
var remoteTxRlps [][]byte
var broadCastedHashes types.Hashes
slotsRlp := make([][]byte, 0, announcements.Len())

if err := db.View(ctx, func(tx kv.Tx) error {
Expand All @@ -1532,17 +1533,19 @@ func MainLoop(ctx context.Context, db kv.RwDB, coreDB kv.RoDB, p *TxPool, newTxs
// Empty rlp can happen if a transaction we want to broadcast has just been mined, for example
slotsRlp = append(slotsRlp, slotRlp)
if p.IsLocal(hash) {
localTxTypes = append(localTxTypes, t)
localTxSizes = append(localTxSizes, size)
localTxHashes = append(localTxHashes, hash...)

if t != types.BlobTxType { // "Nodes MUST NOT automatically broadcast blob transactions to their peers" - EIP-4844
localTxTypes = append(localTxTypes, t)
localTxSizes = append(localTxSizes, size)
localTxHashes = append(localTxHashes, hash...)
localTxRlps = append(localTxRlps, slotRlp)
broadCastedHashes = append(broadCastedHashes, hash...)
}
} else {
remoteTxTypes = append(remoteTxTypes, t)
remoteTxSizes = append(remoteTxSizes, size)
remoteTxHashes = append(remoteTxHashes, hash...)
if t != types.BlobTxType { // "Nodes MUST NOT automatically broadcast blob transactions to their peers" - EIP-4844
remoteTxTypes = append(remoteTxTypes, t)
remoteTxSizes = append(remoteTxSizes, size)
remoteTxHashes = append(remoteTxHashes, hash...)
remoteTxRlps = append(remoteTxRlps, slotRlp)
}
}
Expand All @@ -1559,10 +1562,13 @@ func MainLoop(ctx context.Context, db kv.RwDB, coreDB kv.RoDB, p *TxPool, newTxs

// first broadcast all local txs to all peers, then non-local to random sqrt(peersAmount) peers
txSentTo := send.BroadcastPooledTxs(localTxRlps)
for i, peer := range txSentTo {
p.logger.Info("Local tx broadcasted", "txHash", hex.EncodeToString(broadCastedHashes.At(i)), "to peer", peer)
}
hashSentTo := send.AnnouncePooledTxs(localTxTypes, localTxSizes, localTxHashes)
for i := 0; i < localTxHashes.Len(); i++ {
hash := localTxHashes.At(i)
p.logger.Info("local tx propagated", "tx_hash", hex.EncodeToString(hash), "announced to peers", hashSentTo[i], "broadcast to peers", txSentTo[i], "baseFee", p.pendingBaseFee.Load())
p.logger.Info("local tx announced", "tx_hash", hex.EncodeToString(hash), "to peer", hashSentTo[i], "baseFee", p.pendingBaseFee.Load())
}
send.BroadcastPooledTxs(remoteTxRlps)
send.AnnouncePooledTxs(remoteTxTypes, remoteTxSizes, remoteTxHashes)
Expand Down

0 comments on commit 860701b

Please sign in to comment.