-
Notifications
You must be signed in to change notification settings - Fork 147
Using the CLI provided gRPC configurations when starting the chaincode #401
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
Using the CLI provided gRPC configurations when starting the chaincode #401
Conversation
in external mode (hyperledger#318) When utilizing the chaincode as a service, it is possible to pass some gRPC options as an argument, such as grpc.max_send_message_length. However, these server options were not utilized when declaring the server. Resolves hyperledger#318 Signed-off-by: André João Pedro de Oliveira <andre@ibm.com>
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.
Thank you for the contribution. An inline comment and a few things that should be addressed:
- This change is exposed in the public API on the Shim.server() function in
libraries/fabric-shim/lib/chaincode.js. The JSDoc for that function (specifically the ChaincodeServerOpts interface) should be updated to reflect the new behaviour. Off the top of my head, I am not sure the best (or if there even is) JSDoc syntax for expressing an arbitrary set of properties all beginning with a certain string. - TypeScript type definitions in
libraries/fabric-shim/types/index.d.tsneed to be updated to reflect the API change. The ChaincodeServerOpts interface probably needs an index property added similar to:[grpcOption: `grpc.${string}`]: unknown;
If practical, it would be great to also have a unit test in libraries/fabric-shim/test/unit/server.js to confirm that gRPC options are passed to the grpc.Server() constructor.
libraries/fabric-shim/lib/server.js
Outdated
| this._server = new grpc.Server({ | ||
| 'grpc.max_send_message_length': serverOpts['grpc.max_send_message_length'], | ||
| 'grpc.max_receive_message_length': serverOpts['grpc.max_receive_message_length'], | ||
| 'grpc.keepalive_time_ms': serverOpts['grpc.keepalive_time_ms'], | ||
| 'grpc.http2.min_time_between_pings_ms': serverOpts['grpc.http2.min_time_between_pings_ms'], | ||
| 'grpc.keepalive_timeout_ms': serverOpts['grpc.keepalive_timeout_ms'], | ||
| 'grpc.http2.max_pings_without_data': serverOpts['grpc.http2.max_pings_without_data'], | ||
| 'grpc.keepalive_permit_without_calls': serverOpts['grpc.keepalive_permit_without_calls'], | ||
| }); |
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.
There are more options that can be passed to the grpc.Server constructor, and that list of options might change over time. Maybe just passing through any properties beginning with "grpc." would cover the possibilities more simply?
| this._server = new grpc.Server({ | |
| 'grpc.max_send_message_length': serverOpts['grpc.max_send_message_length'], | |
| 'grpc.max_receive_message_length': serverOpts['grpc.max_receive_message_length'], | |
| 'grpc.keepalive_time_ms': serverOpts['grpc.keepalive_time_ms'], | |
| 'grpc.http2.min_time_between_pings_ms': serverOpts['grpc.http2.min_time_between_pings_ms'], | |
| 'grpc.keepalive_timeout_ms': serverOpts['grpc.keepalive_timeout_ms'], | |
| 'grpc.http2.max_pings_without_data': serverOpts['grpc.http2.max_pings_without_data'], | |
| 'grpc.keepalive_permit_without_calls': serverOpts['grpc.keepalive_permit_without_calls'], | |
| }); | |
| const grpcOptions = Object.fromEntries( | |
| Object.entries(serverOpts).filter(([key]) => key.startsWith('grpc.')) | |
| ); | |
| this._server = new grpc.Server(grpcOptions); |
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.
Hello Mark, I chose to be explicit on the entries for the object because those were the ones specified on fabric-shim/cmds/serverCommand.js under validOptions. I treated this as a bug, since any one of those weren't being passed to the gRPC Server.
I agree that there is discrepancies in the index.d.ts in regards to this ChaincodeServerOpts interface and the what serverCommand/startCommand.js are implying with their validOptions.
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.
To keep the code simple and the CLI command more easily extended to accommodate additional gRPC options, I think I would still be tempted to pass any property that starts with grpc. on to the gRPC Server, and let the CLI command worry about explicitly defining the options that the CLI command accepts. Whichever approach you prefer is OK with me though. Just the JSDoc and TypeScript type definitions need to match the implementation.
Using a filtered subset of serverOpts in fabric-shim/lib/server.js to generalize gRPC server options Signed-off-by: André João Pedro de Oliveira <andre@ibm.com>
|
Hello @bestbeforetoday, What do you think? |
| } | ||
|
|
||
| export interface ChaincodeServerOpts { | ||
| export interface ChaincodeServerOpts extends Partial<GRPCOptions> { |
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.
It is annoying that the grpc-js GRPCOptions also contains the index signature [key: string]: any, which makes our type extending it less helpful for users since it won't flag up invalid or typos in property names as an error.
How about this as an approach?
| export interface ChaincodeServerOpts extends Partial<GRPCOptions> { | |
| type GRPCOptions = { | |
| [K in keyof ChannelOptions as string extends K ? never : K]?: ChannelOptions[K]; | |
| } | |
| export interface ChaincodeServerOpts extends GRPCOptions { |
I think it more accurately reflects the code behaviour, where only property names starting with grpc. are considered.
|
I couldn't dig up any way of expressing the type in JSDoc so your solution looks OK to me. Just as long as it builds the documentation successfully and produces something that makes sense to somebody ready it. I guess the alternative is to explicitly list all (or perhaps a smaller set) of gRPC option property names. I suspect it's better to just reference the gRPC documentation, as you've done. |
Signed-off-by: André João Pedro de Oliveira <andre@ibm.com>
in external mode (#318)
When utilizing the chaincode as a service, it is possible to pass some gRPC options as an argument, such as grpc.max_send_message_length. However, these server options were not utilized when declaring the server.
Resolves #318