From a44f416d4187b83a3bce4325e4871c044daf4e60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Jo=C3=A3o=20Pedro=20de=20Oliveira?= Date: Mon, 5 Jun 2023 11:22:09 -0300 Subject: [PATCH 1/3] Using the CLI provided gRPC configurations when starting the chaincode in external mode (#318) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: André João Pedro de Oliveira --- libraries/fabric-shim/lib/server.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/fabric-shim/lib/server.js b/libraries/fabric-shim/lib/server.js index f075086a..aff9ee1a 100644 --- a/libraries/fabric-shim/lib/server.js +++ b/libraries/fabric-shim/lib/server.js @@ -59,7 +59,15 @@ class ChaincodeServer { } // Create GRPC Server and register RPC handler - this._server = new grpc.Server(); + 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'], + }); this._server.addService(peer.ChaincodeService, this); this._serverOpts = serverOpts; From 2cd89d1ecce188426804a2d411a03b427150e5d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Jo=C3=A3o=20Pedro=20de=20Oliveira?= Date: Fri, 9 Jun 2023 18:54:25 -0300 Subject: [PATCH 2/3] Typing ChaincodeServerOpts to address gRPC Server options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- libraries/fabric-shim/lib/server.js | 14 +++++--------- libraries/fabric-shim/types/index.d.ts | 6 +++--- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/libraries/fabric-shim/lib/server.js b/libraries/fabric-shim/lib/server.js index aff9ee1a..9d6336b6 100644 --- a/libraries/fabric-shim/lib/server.js +++ b/libraries/fabric-shim/lib/server.js @@ -58,16 +58,12 @@ class ChaincodeServer { this._credentials = grpc.ServerCredentials.createInsecure(); } + const grpcOptions = Object.fromEntries( + Object.entries(serverOpts).filter(([key]) => key.startsWith('grpc.')) + ); + // Create GRPC Server and register RPC handler - 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'], - }); + this._server = new grpc.Server(grpcOptions); this._server.addService(peer.ChaincodeService, this); this._serverOpts = serverOpts; diff --git a/libraries/fabric-shim/types/index.d.ts b/libraries/fabric-shim/types/index.d.ts index 2ebf37c7..9d1be29e 100644 --- a/libraries/fabric-shim/types/index.d.ts +++ b/libraries/fabric-shim/types/index.d.ts @@ -6,8 +6,8 @@ */ declare module 'fabric-shim' { - import { EventEmitter } from 'events'; import { Logger } from 'winston'; + import { ChannelOptions as GRPCOptions } from '@grpc/grpc-js' import { ChaincodeInterface, @@ -53,7 +53,7 @@ declare module 'fabric-shim' { start(): Promise; } - export interface ChaincodeServerOpts { + export interface ChaincodeServerOpts extends Partial { ccid: string; address: string; tlsProps: ChaincodeServerTLSProperties; @@ -140,7 +140,7 @@ declare module 'fabric-shim' { constructor(policy?: Uint8Array); getPolicy(): Uint8Array; addOrgs(role: string, ...newOrgs: string[]): void; - delOrgs(...delOrgs: string[]):void; + delOrgs(...delOrgs: string[]): void; listOrgs(): string[]; } From 92cb17123ea5c154e173906adefbdb86b6911380 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Jo=C3=A3o=20Pedro=20de=20Oliveira?= Date: Mon, 12 Jun 2023 09:14:03 -0300 Subject: [PATCH 3/3] Updating the JSDoc and index.d.ts types for the chaincode server options MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: André João Pedro de Oliveira --- libraries/fabric-shim/lib/chaincode.js | 6 ++++++ libraries/fabric-shim/types/index.d.ts | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libraries/fabric-shim/lib/chaincode.js b/libraries/fabric-shim/lib/chaincode.js index 39552cdd..65c1fc78 100644 --- a/libraries/fabric-shim/lib/chaincode.js +++ b/libraries/fabric-shim/lib/chaincode.js @@ -199,6 +199,11 @@ class Shim { return Logger.getLogger(name); } + /** + * @interface GRPCOptions + * @description ChannelOptions on "@grpc/grpc-js". For a complete list, refer to @grpc/grpc-js Documentation + * @property {unknown[]} ['grpc.${string}'] Connection options defined on "@grpc/grpc-js" + */ /** * @interface ChaincodeServerTLSProperties * @property {Buffer} key Private key for TLS @@ -207,6 +212,7 @@ class Shim { */ /** * @interface ChaincodeServerOpts + * @extends GRPCOptions * @property {string} ccid Chaincode ID * @property {string} address Listen address for the server * @property {ChaincodeServerTLSProperties} [tlsProps] TLS properties if TLS is required. diff --git a/libraries/fabric-shim/types/index.d.ts b/libraries/fabric-shim/types/index.d.ts index 9d1be29e..2e948cef 100644 --- a/libraries/fabric-shim/types/index.d.ts +++ b/libraries/fabric-shim/types/index.d.ts @@ -7,7 +7,7 @@ declare module 'fabric-shim' { import { Logger } from 'winston'; - import { ChannelOptions as GRPCOptions } from '@grpc/grpc-js' + import { ChannelOptions } from '@grpc/grpc-js' import { ChaincodeInterface, @@ -53,7 +53,11 @@ declare module 'fabric-shim' { start(): Promise; } - export interface ChaincodeServerOpts extends Partial { + type GRPCOptions = { + [K in keyof ChannelOptions as string extends K ? never : K]?: ChannelOptions[K]; + } + + export interface ChaincodeServerOpts extends GRPCOptions { ccid: string; address: string; tlsProps: ChaincodeServerTLSProperties;