mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-28 08:11:08 +00:00
Use batches in broadcast to avoid resource communication errors
This commit is contained in:
parent
b26b9f6c4b
commit
ee5dacc72e
@ -42,15 +42,30 @@ func broadcast(conf *broadcastConfig) error {
|
||||
return err
|
||||
}
|
||||
|
||||
response, err := daemonClient.Broadcast(ctx, &pb.BroadcastRequest{Transactions: transactions})
|
||||
const batch = 50
|
||||
position := 0
|
||||
|
||||
// We send in batches to avoid communication errors
|
||||
for position < len(transactions) {
|
||||
var transactionBatch [][]byte
|
||||
if position+batch > len(transactions) {
|
||||
transactionBatch = transactions[position:]
|
||||
} else {
|
||||
transactionBatch = transactions[position : position+batch]
|
||||
}
|
||||
response, err := daemonClient.Broadcast(ctx, &pb.BroadcastRequest{Transactions: transactionBatch})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if position == 0 {
|
||||
fmt.Println("Transactions were sent successfully")
|
||||
}
|
||||
fmt.Println("Transaction ID(s): ")
|
||||
for _, txID := range response.TxIDs {
|
||||
fmt.Printf("\t%s\n", txID)
|
||||
}
|
||||
position += batch
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user