Skip to content

Commit

Permalink
Using the CLI provided gRPC configurations when starting the chaincode (
Browse files Browse the repository at this point in the history
#401)

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.

Signed-off-by: André João Pedro de Oliveira <andre@ibm.com>
  • Loading branch information
delaooliveira committed Jun 12, 2023
1 parent cf179e7 commit 690c91a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 6 additions & 0 deletions libraries/fabric-shim/lib/chaincode.js
Expand Up @@ -199,6 +199,11 @@ class Shim {
return Logger.getLogger(name);
}

/**
* @interface GRPCOptions
* @description ChannelOptions on "@grpc/grpc-js". For a complete list, refer to <a href=https://www.npmjs.com/package/@grpc/grpc-js#supported-channel-options>@grpc/grpc-js Documentation</a>
* @property {unknown[]} ['grpc.${string}'] Connection options defined on "@grpc/grpc-js"
*/
/**
* @interface ChaincodeServerTLSProperties
* @property {Buffer} key Private key for TLS
Expand All @@ -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.
Expand Down
6 changes: 5 additions & 1 deletion libraries/fabric-shim/lib/server.js
Expand Up @@ -58,8 +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();
this._server = new grpc.Server(grpcOptions);
this._server.addService(peer.ChaincodeService, this);

this._serverOpts = serverOpts;
Expand Down
10 changes: 7 additions & 3 deletions libraries/fabric-shim/types/index.d.ts
Expand Up @@ -6,8 +6,8 @@
*/
declare module 'fabric-shim' {

import { EventEmitter } from 'events';
import { Logger } from 'winston';
import { ChannelOptions } from '@grpc/grpc-js'

import {
ChaincodeInterface,
Expand Down Expand Up @@ -53,7 +53,11 @@ declare module 'fabric-shim' {
start(): Promise<void>;
}

export interface ChaincodeServerOpts {
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;
Expand Down Expand Up @@ -140,7 +144,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[];
}

Expand Down

0 comments on commit 690c91a

Please sign in to comment.