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