Skip to content

Commit

Permalink
chore: use different subscription name
Browse files Browse the repository at this point in the history
  • Loading branch information
rach-id committed Oct 9, 2024
1 parent 020787b commit d08249a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
16 changes: 14 additions & 2 deletions rpc/grpc/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package coregrpc
import (
"context"
"errors"
"fmt"
"github.com/tendermint/tendermint/libs/rand"
"sync"
"time"

Expand Down Expand Up @@ -60,7 +62,12 @@ func (blockAPI *BlockAPI) StartNewBlockEventListener(ctx context.Context) {
env := core.GetEnvironment()
if blockAPI.newBlockSubscription == nil {
var err error
blockAPI.newBlockSubscription, err = env.EventBus.Subscribe(ctx, "new-block-grpc-subscription", types2.EventQueryNewBlock, 500)
blockAPI.newBlockSubscription, err = env.EventBus.Subscribe(
ctx,
fmt.Sprintf("new-block-grpc-subscription-%s", rand.Str(6)),
types2.EventQueryNewBlock,
500,
)
if err != nil {
env.Logger.Error("Failed to subscribe to new blocks", "err", err)
return
Expand Down Expand Up @@ -122,7 +129,12 @@ func (blockAPI *BlockAPI) retryNewBlocksSubscription(ctx context.Context) (bool,
return false, nil
case <-ticker.C:
var err error
blockAPI.newBlockSubscription, err = env.EventBus.Subscribe(ctx, "new-block-grpc-subscription", types2.EventQueryNewBlock, 500)
blockAPI.newBlockSubscription, err = env.EventBus.Subscribe(
ctx,
fmt.Sprintf("new-block-grpc-subscription-%s", rand.Str(6)),
types2.EventQueryNewBlock,
500,
)
if err != nil {
env.Logger.Error("Failed to subscribe to new blocks. retrying", "err", err, "retry_number", i)
} else {
Expand Down
4 changes: 3 additions & 1 deletion rpc/grpc/client_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ type Config struct {
func StartGRPCServer(ln net.Listener) error {
grpcServer := grpc.NewServer()
RegisterBroadcastAPIServer(grpcServer, &broadcastAPI{})
RegisterBlockAPIServer(grpcServer, NewBlockAPI())
api := NewBlockAPI()
go api.StartNewBlockEventListener(context.Background())
RegisterBlockAPIServer(grpcServer, api)
return grpcServer.Serve(ln)
}

Expand Down

0 comments on commit d08249a

Please sign in to comment.