Skip to content

Commit

Permalink
Merge pull request #1881 from CortexFoundation/dev
Browse files Browse the repository at this point in the history
large tx count
  • Loading branch information
ucwong committed Jan 3, 2024
2 parents a634461 + 575cb0a commit 70362c0
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions ctxc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -966,6 +966,8 @@ func (pm *ProtocolManager) BroadcastBlock(block *types.Block, propagate bool) {
// already have the given transaction.
func (pm *ProtocolManager) BroadcastTransactions(txs types.Transactions) {
var (
largeTxs int // Number of large transactions to announce only

annoCount int // Count of announcements made
annoPeers int
directCount int // Count of the txs sent directly to peers
Expand All @@ -979,9 +981,14 @@ func (pm *ProtocolManager) BroadcastTransactions(txs types.Transactions) {
peers := pm.peers.PeersWithoutTx(tx.Hash())
// Send the tx unconditionally to a subset of our peers
var numDirect int
if tx.Size() <= txMaxBroadcastSize {

switch {
case tx.Size() > txMaxBroadcastSize:
largeTxs++
default:
numDirect = int(math.Sqrt(float64(len(peers))))
}
// Send the tx unconditionally to a subset of our peers
for _, peer := range peers[:numDirect] {
txset[peer] = append(txset[peer], tx.Hash())
}
Expand All @@ -1004,7 +1011,7 @@ func (pm *ProtocolManager) BroadcastTransactions(txs types.Transactions) {
peer.AsyncSendTransactions(hashes)
}
}
log.Debug("Transaction broadcast", "txs", len(txs),
log.Debug("Transaction broadcast", "txs", len(txs)-largeTxs, "largetxs", largeTxs,
"announce packs", annoPeers, "announced hashes", annoCount,
"tx packs", directPeers, "broadcast txs", directCount)
}
Expand All @@ -1021,9 +1028,9 @@ func (pm *ProtocolManager) minedBroadcastLoop() {
}
}

// txBroadcastLoop announces new transactions to connected peers.
func (pm *ProtocolManager) txBroadcastLoop() {
defer pm.wg.Done()

for {
select {
case event := <-pm.txsCh:
Expand Down

0 comments on commit 70362c0

Please sign in to comment.