Skip to content

Commit

Permalink
[api] Enable message batching (#3857)
Browse files Browse the repository at this point in the history
  • Loading branch information
Liuhaai authored May 18, 2023
1 parent eefc49d commit f899c86
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion api/coreservice.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ func newCoreService(
opt(&core)
}

if core.broadcastHandler != nil {
core.messageBatcher = batch.NewManager(func(msg *batch.Message) error {
return core.broadcastHandler(context.Background(), core.bc.ChainID(), msg.Data)
})
}

return &core, nil
}

Expand Down Expand Up @@ -447,13 +453,14 @@ func (core *coreService) SendAction(ctx context.Context, in *iotextypes.Action)
// If there is no error putting into local actpool,
// Broadcast it to the network
msg := in
if core.messageBatcher != nil {
if ge := core.bc.Genesis(); ge.IsToBeEnabled(core.bc.TipHeight()) {
err = core.messageBatcher.Put(&batch.Message{
ChainID: core.bc.ChainID(),
Target: nil,
Data: msg,
})
} else {
//TODO: remove height check after activated
err = core.broadcastHandler(ctx, core.bc.ChainID(), msg)
}
if err != nil {
Expand Down

0 comments on commit f899c86

Please sign in to comment.