-
Notifications
You must be signed in to change notification settings - Fork 3.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(serevr/v2/cometbft): update RegisterQueryHandlers
and GRPC queries
#22403
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -642,7 +642,7 @@ func registerServices[T transaction.Tx](s appmodulev2.AppModule, app *App[T], re | |
|
||
// if module implements register msg handlers | ||
if module, ok := s.(appmodulev2.HasMsgHandlers); ok { | ||
wrapper := stfRouterWrapper{stfRouter: app.msgRouterBuilder} | ||
wrapper := NewStfRouterWrapper(app.msgRouterBuilder) | ||
module.RegisterMsgHandlers(&wrapper) | ||
if wrapper.error != nil { | ||
return fmt.Errorf("unable to register handlers: %w", wrapper.error) | ||
|
@@ -651,7 +651,7 @@ func registerServices[T transaction.Tx](s appmodulev2.AppModule, app *App[T], re | |
|
||
// if module implements register query handlers | ||
if module, ok := s.(appmodulev2.HasQueryHandlers); ok { | ||
wrapper := stfRouterWrapper{stfRouter: app.queryRouterBuilder} | ||
wrapper := NewStfRouterWrapper(app.queryRouterBuilder) | ||
module.RegisterQueryHandlers(&wrapper) | ||
|
||
for path, handler := range wrapper.handlers { | ||
|
@@ -842,6 +842,13 @@ type stfRouterWrapper struct { | |
handlers map[string]appmodulev2.Handler | ||
} | ||
|
||
func NewStfRouterWrapper(stfRouterBuilder *stf.MsgRouterBuilder) stfRouterWrapper { | ||
wrapper := stfRouterWrapper{stfRouter: stfRouterBuilder} | ||
wrapper.error = nil | ||
wrapper.handlers = map[string]appmodulev2.Handler{} | ||
return wrapper | ||
} | ||
|
||
func (s *stfRouterWrapper) RegisterHandler(handler appmodulev2.Handler) { | ||
req := handler.MakeMsg() | ||
requestName := gogoproto.MessageName(req) | ||
|
@@ -854,7 +861,7 @@ func (s *stfRouterWrapper) RegisterHandler(handler appmodulev2.Handler) { | |
s.error = errors.Join(s.error, err) | ||
|
||
// also make the decoder | ||
if s.error == nil { | ||
if s.error != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shall we just check if |
||
s.handlers = map[string]appmodulev2.Handler{} | ||
} | ||
s.handlers[requestName] = handler | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -259,12 +259,15 @@ func (c *Consensus[T]) maybeRunGRPCQuery(ctx context.Context, req *abci.QueryReq | |
return nil, false, err | ||
} | ||
|
||
var handlerFullName string | ||
md, isGRPC := desc.(protoreflect.MethodDescriptor) | ||
if !isGRPC { | ||
return nil, false, nil | ||
handlerFullName = string(desc.FullName()) | ||
} else { | ||
handlerFullName = string(md.Input().FullName()) | ||
} | ||
|
||
handler, found := c.queryHandlersMap[string(md.Input().FullName())] | ||
handler, found := c.queryHandlersMap[handlerFullName] | ||
if !found { | ||
return nil, true, fmt.Errorf("no query handler found for %s", req.Path) | ||
} | ||
|
@@ -282,7 +285,7 @@ func (c *Consensus[T]) maybeRunGRPCQuery(ctx context.Context, req *abci.QueryReq | |
} | ||
|
||
resp, err = queryResponse(res, req.Height) | ||
return resp, isGRPC, err | ||
return resp, true, err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why r we assume isGRPC here is true ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it possible to change the return type to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we couldn't, its using as flag to run GRPC request or |
||
} | ||
|
||
// InitChain implements types.Application. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this public? it should be made private imho