Skip to content

Commit

Permalink
Add more logs when setup listener (#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
hiepnv90 authored Mar 20, 2024
1 parent 17f278e commit edb6d5c
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func NewListener(c *cli.Context) (*listener.Listener, error) {
httpClient := &http.Client{
Timeout: defaultRequestTimeout,
}

wsRPC := c.String(wsRPCFlag.Name)
l.Infow("Connect to node websocket rpc", "rpc", wsRPC)
wsEVMClient, err := evmclient.DialContext(context.Background(), wsRPC, httpClient)
if err != nil {
l.Errorw("Fail to connect to node", "rpc", wsRPC, "error", err)
Expand All @@ -64,13 +64,15 @@ func NewListener(c *cli.Context) (*listener.Listener, error) {
}

httpRPC := c.String(httpRPCFlag.Name)
l.Infow("Connect to node http rpc", "rpc", httpRPC)
httpEVMClient, err := evmclient.DialContext(context.Background(), httpRPC, httpClient)
if err != nil {
l.Errorw("Fail to connect to node", "rpc", httpRPC, "error", err)

return nil, err
}

l.Infow("Get chainID from node")
chainID, err := httpEVMClient.ChainID(context.Background())
if err != nil {
l.Errorw("Fail to get chainID", "error", err)
Expand All @@ -84,6 +86,7 @@ func NewListener(c *cli.Context) (*listener.Listener, error) {
var sanityEVMClient evmclient.IClient
sanityRPC := c.String(sanityNodeRPCFlag.Name)
if sanityRPC != "" {
l.Infow("Connect to public node rpc for sanity check", "rpc", sanityRPC)
sanityEVMClient, err = evmclient.DialContext(context.Background(), sanityRPC, httpClient)
if err != nil {
l.Errorw("Fail to setup EVM client for sanity check", "error", err)
Expand All @@ -93,24 +96,33 @@ func NewListener(c *cli.Context) (*listener.Listener, error) {
}

redisConfig := redisConfigFromCli(c)
redisConfigForLog := redisConfig
redisConfigForLog.SentinelPassword = "***"
redisConfigForLog.Password = "***"
l.Infow("Connect to redis", "cfg", redisConfigForLog)
redisClient, err := redis.New(redisConfig)
if err != nil {
l.Errorw("Fail to connect to redis", "cfg", redisConfig, "error", err)
l.Errorw("Fail to connect to redis", "cfg", redisConfigForLog, "error", err)

return nil, err
}

maxNumBlocks := c.Int(maxNumBlocksFlag.Name)
blockExpiration := c.Duration(blockExpirationFlag.Name)
l.Infow("Setup new BlockKeeper", "maxNumBlocks", maxNumBlocks, "expiration", blockExpiration)
blockKeeper := block.NewRedisBlockKeeper(l, redisClient, maxNumBlocks, blockExpiration)

maxLen := c.Int64(publisherMaxLenFlag.Name)
l.Infow("Setup redis stream", "maxLen", maxLen)
redisStream := redis.NewStream(redisClient, maxLen)

topic := c.String(publisherTopicFlag.Name)
l.Infow("Setup handler", "topic", topic)
handler := listener.NewHandler(l, topic, httpEVMClient, blockKeeper, redisStream,
listener.WithEventLogs(nil, nil))

l.Infow("Setup listener")

return listener.New(l, wsEVMClient, httpEVMClient, handler, sanityEVMClient, sanityCheckInterval,
listener.WithEventLogs(nil, nil)), nil
}
Expand Down

0 comments on commit edb6d5c

Please sign in to comment.