Skip to content

Commit

Permalink
Move flag check to p2p (#2987)
Browse files Browse the repository at this point in the history
  • Loading branch information
bruce-riley authored May 25, 2023
1 parent 520757a commit 2cb4288
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 24 deletions.
7 changes: 1 addition & 6 deletions node/cmd/guardiand/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -1184,11 +1184,6 @@ func runNode(cmd *cobra.Command, args []string) {
components := p2p.DefaultComponents()
components.Port = *p2pPort

ccqFeatures := ""
if *ccqEnabled {
ccqFeatures = "ccq"
}

// Run supervisor.
supervisor.New(rootCtx, logger, func(ctx context.Context) error {
if err := supervisor.Run(ctx, "p2p", p2p.Run(
Expand All @@ -1211,7 +1206,7 @@ func runNode(cmd *cobra.Command, args []string) {
nil,
components,
&ibc.Features,
&ccqFeatures,
*ccqEnabled,
signedQueryReqWriteC,
queryResponseReadC)); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions node/cmd/guardiand/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func handleQueryRequests(
chainQueryReqC map[vaa.ChainID]chan *gossipv1.SignedQueryRequest,
enableFlag bool,
) {
qLogger := logger.With(zap.String("component", "queryHandler"))
qLogger := logger.With(zap.String("component", "ccqhandler"))
if enableFlag {
qLogger.Info("cross chain queries are enabled")
}
Expand All @@ -39,7 +39,7 @@ func handleQueryRequests(
return
case signedQueryRequest := <-signedQueryReqC:
if !enableFlag {
qLogger.Debug("dropping query request, feature is not enabled")
qLogger.Error("received a query request when the feature is disabled, dropping it")
continue
}
// requestor validation happens here
Expand Down
8 changes: 4 additions & 4 deletions node/cmd/spy/spy.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,10 +552,10 @@ func runSpy(cmd *cobra.Command, args []string) {
nil,
nil,
components,
nil, // ibc feature string
nil, // cross chain query feature string
nil, // query requests
nil, // query responses
nil, // ibc feature string
false, // ccqEnabled
nil, // query requests
nil, // query responses

)); err != nil {
return err
Expand Down
24 changes: 16 additions & 8 deletions node/pkg/p2p/p2p.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func Run(
signedGovSt chan *gossipv1.SignedChainGovernorStatus,
components *Components,
ibcFeatures *string,
ccqFeatures *string,
ccqEnabled bool,
signedQueryReqC chan<- *gossipv1.SignedQueryRequest,
queryResponseReadC <-chan *node_common.QueryResponsePublication,
) func(ctx context.Context) error {
Expand Down Expand Up @@ -313,8 +313,8 @@ func Run(
if ibcFeatures != nil && *ibcFeatures != "" {
features = append(features, *ibcFeatures)
}
if ccqFeatures != nil && *ccqFeatures != "" {
features = append(features, *ccqFeatures)
if ccqEnabled {
features = append(features, "ccq")
}

heartbeat := &gossipv1.Heartbeat{
Expand Down Expand Up @@ -415,9 +415,13 @@ func Run(
logger.Info("published signed observation request", zap.Any("signed_observation_request", sReq))
}
case msg := <-queryResponseReadC:
if !ccqEnabled {
logger.Error("received a cross chain query response when the feature is disabled, dropping it", zap.String("component", "ccqp2p"))
continue
}
msgBytes, err := msg.Marshal()
if err != nil {
logger.Error("failed to marshal query response", zap.Error(err))
logger.Error("failed to marshal query response", zap.Error(err), zap.String("component", "ccqp2p"))
continue
}
digest := node_common.GetQueryResponseDigestFromBytes(msgBytes)
Expand All @@ -440,9 +444,9 @@ func Run(
err = th.Publish(ctx, b)
p2pMessagesSent.Inc()
if err != nil {
logger.Error("failed to publish query response", zap.Error(err))
logger.Error("failed to publish query response", zap.Error(err), zap.String("component", "ccqp2p"))
} else {
logger.Info("published signed query response", zap.Any("query_response", msg), zap.Any("signature", sig))
logger.Info("published signed query response", zap.Any("query_response", msg), zap.Any("signature", sig), zap.String("component", "ccqp2p"))
}
}
}
Expand Down Expand Up @@ -592,8 +596,12 @@ func Run(
}
case *gossipv1.GossipMessage_SignedQueryRequest:
if signedQueryReqC != nil {
if err := node_common.PostSignedQueryRequest(signedQueryReqC, m.SignedQueryRequest); err != nil {
logger.Warn("failed to handle query request", zap.Error(err))
if ccqEnabled {
if err := node_common.PostSignedQueryRequest(signedQueryReqC, m.SignedQueryRequest); err != nil {
logger.Warn("failed to handle query request", zap.Error(err), zap.String("component", "ccqp2p"))
}
} else {
logger.Debug("dropping cross chain query request because the feature is not enabled", zap.String("component", "ccqp2p"))
}
}
default:
Expand Down
8 changes: 4 additions & 4 deletions node/pkg/p2p/watermark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ func startGuardian(t *testing.T, ctx context.Context, g *G) {
g.signedGovCfg,
g.signedGovSt,
g.components,
nil, // ibc feature string
nil, // cross chain query feature string
nil, // signed query request channel
nil, // query response channel
nil, // ibc feature string
false, // ccqEnabled
nil, // signed query request channel
nil, // query response channel
))
}

0 comments on commit 2cb4288

Please sign in to comment.