From 693bb977e73f78b7d0814a7c8c35441c267b3fdf Mon Sep 17 00:00:00 2001 From: Santosh Kumar Date: Wed, 15 May 2024 18:22:22 +0530 Subject: [PATCH 1/7] Added doc update how to start chaincode as a service, and how to set grpc parameters in the startup Signed-off-by: Santosh Kumar --- docs/_jsdoc/index.md | 55 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/docs/_jsdoc/index.md b/docs/_jsdoc/index.md index 35d85f6a9..7990e7cfa 100644 --- a/docs/_jsdoc/index.md +++ b/docs/_jsdoc/index.md @@ -12,7 +12,7 @@ The `fabric-shim` provides the *chaincode interface*, a lower level API for impl To confirm that the `fabric-shim` maintains API and functional compatibility with previous versions of Hyperledger Fabric. -A more detailed explanation on the concept and programming model can be found in the [smart contract processing topic](https://hyperledger-fabric.readthedocs.io/en/latest/developapps/smartcontract.html). +A more detailed explanation on the concept and programming model can be found in the [smart contract processing topic](https://hyperledger-fabric.readthedocs.io/en/release-2.3/developapps/smartcontract.html). ## Contract Interface @@ -124,6 +124,59 @@ Start the chaincode process and listen for incoming endorsement requests: shim.start(new Chaincode()); ``` +To run chaincode as an external service, fabric-shim provides the `shim.server` API. If you are using contract APIs, you may want to use the `server` command provided by `fabric-chaincode-node` CLI to run a contract in the external service mode. + +The following is a sample chaincode using `fabric-shim`: +```javascript +const shim = require('fabric-shim'); + +class SimpleChaincode extends shim.ChaincodeInterface { + async Init(stub) { + // ... Init code + } + async Invoke(stub) { + // ... Invoke code + } +} + +const server = shim.server(new SimpleChaincode(), { + ccid: "mycc:fcbf8724572d42e859a7dd9a7cd8e2efb84058292017df6e3d89178b64e6c831", + address: "0.0.0.0:9999" +}); + +server.start(); +``` + +To run a chaincode with the `fabric-contract` API as an external service, simply use `fabric-chaincode-node server` instead of `fabric-chaincode-node start`. Here is a sample for `package.json`: +```javascript +{ + "scripts": { + "start": "fabric-chaincode-node server" + }, + ... +} +``` + +When `fabric-chaincode-node server` is used, the following options should be set as either arguments or environment variables: +* **CORE_CHAINCODE_ID (--chaincode-id)**: See **CCID** in the Go chaincode above. +* **CORE_CHAINCODE_ADDRESS (--chaincode-address)**: See **Address** in the Go chaincode above. + +If TLS is enabled, the following additional options are required: +* **CORE_CHAINCODE_TLS_CERT_FILE (--chaincode-tls-cert-file)**: path to a certificate +* **CORE_CHAINCODE_TLS_KEY_FILE (--chaincode-tls-key-file)**: path to a private key + +When mutual TLS is enabled, **CORE_CHAINCODE_TLS_CLIENT_CACERT_FILE (--chaincode-tls-client-cacert-file)** option should be set to specify the path to the CA certificate for acceptable client certificates. + +There are other optional arguments can be set to pass gRPC options which will be used to override the default values. Here is a sample for ``package.json`: +```javascript +{ + "scripts": { + "start": "fabric-chaincode-node server --chaincode-address=localhost:7100 --chaincode-id= --grpc.max_send_message_length 100000000 --grpc.max_receive_message_length 100000000" + }, + ... +} +``` + ## Support Tested with node.js 8.9.0 (LTS). From e94f0b1dd178672618c8759b1e8bf560202ea799 Mon Sep 17 00:00:00 2001 From: Santosh Kumar Date: Wed, 15 May 2024 19:37:29 +0530 Subject: [PATCH 2/7] corrected the format Signed-off-by: Santosh Kumar --- docs/_jsdoc/index.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/_jsdoc/index.md b/docs/_jsdoc/index.md index 7990e7cfa..6c3c98029 100644 --- a/docs/_jsdoc/index.md +++ b/docs/_jsdoc/index.md @@ -167,7 +167,8 @@ If TLS is enabled, the following additional options are required: When mutual TLS is enabled, **CORE_CHAINCODE_TLS_CLIENT_CACERT_FILE (--chaincode-tls-client-cacert-file)** option should be set to specify the path to the CA certificate for acceptable client certificates. -There are other optional arguments can be set to pass gRPC options which will be used to override the default values. Here is a sample for ``package.json`: +There are other optional arguments can be set to pass gRPC options which will be used to override the default values. Here is a sample for `package.json`: + ```javascript { "scripts": { From c25a9fcce239cfccb54ec5c2b697548f183f5fb8 Mon Sep 17 00:00:00 2001 From: Santosh Kumar Date: Wed, 15 May 2024 19:46:36 +0530 Subject: [PATCH 3/7] corrected the format Signed-off-by: Santosh Kumar --- docs/_jsdoc/index.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/_jsdoc/index.md b/docs/_jsdoc/index.md index 6c3c98029..bc8fa740f 100644 --- a/docs/_jsdoc/index.md +++ b/docs/_jsdoc/index.md @@ -158,8 +158,8 @@ To run a chaincode with the `fabric-contract` API as an external service, simply ``` When `fabric-chaincode-node server` is used, the following options should be set as either arguments or environment variables: -* **CORE_CHAINCODE_ID (--chaincode-id)**: See **CCID** in the Go chaincode above. -* **CORE_CHAINCODE_ADDRESS (--chaincode-address)**: See **Address** in the Go chaincode above. +* **CORE_CHAINCODE_ID (--chaincode-id)** +* **CORE_CHAINCODE_ADDRESS (--chaincode-address)** If TLS is enabled, the following additional options are required: * **CORE_CHAINCODE_TLS_CERT_FILE (--chaincode-tls-cert-file)**: path to a certificate From c5322233d451a04cccea9a68a8b916791d275aef Mon Sep 17 00:00:00 2001 From: Santosh Kumar Date: Fri, 24 May 2024 11:53:02 +0530 Subject: [PATCH 4/7] added doc for run chaincode as an external service Signed-off-by: Santosh Kumar --- docs/_jsdoc/index.md | 49 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/docs/_jsdoc/index.md b/docs/_jsdoc/index.md index bc8fa740f..4aab3db85 100644 --- a/docs/_jsdoc/index.md +++ b/docs/_jsdoc/index.md @@ -129,19 +129,30 @@ To run chaincode as an external service, fabric-shim provides the `shim.server` The following is a sample chaincode using `fabric-shim`: ```javascript const shim = require('fabric-shim'); +const yargs = require('yargs'); class SimpleChaincode extends shim.ChaincodeInterface { - async Init(stub) { - // ... Init code - } - async Invoke(stub) { - // ... Invoke code - } + async Init(stub) { + // ... Init code + } + + async Invoke(stub) { + // ... Invoke code + } } +const argv = yargs(process.argv.slice(2)) + .option('chaincode-address', { + alias: 'ccid' + }) + .option('chaincode-id', { + alias: 'address' + }) + .argv; + const server = shim.server(new SimpleChaincode(), { - ccid: "mycc:fcbf8724572d42e859a7dd9a7cd8e2efb84058292017df6e3d89178b64e6c831", - address: "0.0.0.0:9999" + ccid: argv['chaincode-id'], + address: argv['chaincode-address'] }); server.start(); @@ -165,7 +176,7 @@ If TLS is enabled, the following additional options are required: * **CORE_CHAINCODE_TLS_CERT_FILE (--chaincode-tls-cert-file)**: path to a certificate * **CORE_CHAINCODE_TLS_KEY_FILE (--chaincode-tls-key-file)**: path to a private key -When mutual TLS is enabled, **CORE_CHAINCODE_TLS_CLIENT_CACERT_FILE (--chaincode-tls-client-cacert-file)** option should be set to specify the path to the CA certificate for acceptable client certificates. +When mutual TLS is enabled, **CORE_CHAINCODE_TLS_CLIENT_CACERT_FILE (--chaincode-tls-client-cacert-file)** option should be set to specify the path to the CA certificate for acceptable client certific There are other optional arguments can be set to pass gRPC options which will be used to override the default values. Here is a sample for `package.json`: @@ -178,6 +189,26 @@ There are other optional arguments can be set to pass gRPC options which will be } ``` +The valid options are as listed below: +``` + --chaincode-address [string] [required] + --chaincode-id [string] [required] + --grpc.max_send_message_length [number] [default: -1] + --grpc.max_receive_message_length [number] [default: -1] + --grpc.keepalive_time_ms [number] [default: 110000] + --grpc.http2.min_time_between_pings_ms [number] [default: 110000] + --grpc.keepalive_timeout_ms [number] [default: 20000] + --grpc.http2.max_pings_without_data [number] [default: 0] + --grpc.keepalive_permit_without_calls [number] [default: 1] + --chaincode-tls-cert-file [string] + --chaincode-tls-cert-path [string] + --chaincode-tls-key-file [string] + --chaincode-tls-key-path [string] + --chaincode-tls-client-cacert-file [string] + --chaincode-tls-client-cacert-path [string] + --module-path [string] +``` + ## Support Tested with node.js 8.9.0 (LTS). From 4acd713cc56952d7bf78b1f33c31a8056a8fcbbb Mon Sep 17 00:00:00 2001 From: Santosh Kumar Date: Fri, 24 May 2024 12:02:39 +0530 Subject: [PATCH 5/7] added doc for run chaincode as an external service Signed-off-by: Santosh Kumar --- docs/_jsdoc/index.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/_jsdoc/index.md b/docs/_jsdoc/index.md index 4aab3db85..aaf2ff4f1 100644 --- a/docs/_jsdoc/index.md +++ b/docs/_jsdoc/index.md @@ -188,6 +188,7 @@ There are other optional arguments can be set to pass gRPC options which will be ... } ``` +This would increase the grpc limit from the default of 4MB to 100MB. This gRPC parameter overirde feature has been added in node chaincode v2.5.4. The valid options are as listed below: ``` From 1b9975a9d7f33846c11122ad6cca6a4c65fd4f14 Mon Sep 17 00:00:00 2001 From: Santosh Kumar Date: Fri, 24 May 2024 12:07:05 +0530 Subject: [PATCH 6/7] added doc for run chaincode as an external service Signed-off-by: Santosh Kumar --- docs/_jsdoc/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/_jsdoc/index.md b/docs/_jsdoc/index.md index aaf2ff4f1..09191689b 100644 --- a/docs/_jsdoc/index.md +++ b/docs/_jsdoc/index.md @@ -188,7 +188,7 @@ There are other optional arguments can be set to pass gRPC options which will be ... } ``` -This would increase the grpc limit from the default of 4MB to 100MB. This gRPC parameter overirde feature has been added in node chaincode v2.5.4. +This would increase the grpc limit from the default of 4MB to 100MB. This gRPC parameter override option has been added in node chaincode v2.5.4. The valid options are as listed below: ``` From dc16f9afb7bf5c187ddeb460f45e4d5450c3b990 Mon Sep 17 00:00:00 2001 From: Santosh Kumar Date: Fri, 24 May 2024 18:30:20 +0530 Subject: [PATCH 7/7] added a specific section for chaincode-as-a-service Signed-off-by: Santosh Kumar --- docs/_jsdoc/index.md | 37 ++----------------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/docs/_jsdoc/index.md b/docs/_jsdoc/index.md index 09191689b..b22c293fd 100644 --- a/docs/_jsdoc/index.md +++ b/docs/_jsdoc/index.md @@ -124,41 +124,8 @@ Start the chaincode process and listen for incoming endorsement requests: shim.start(new Chaincode()); ``` -To run chaincode as an external service, fabric-shim provides the `shim.server` API. If you are using contract APIs, you may want to use the `server` command provided by `fabric-chaincode-node` CLI to run a contract in the external service mode. - -The following is a sample chaincode using `fabric-shim`: -```javascript -const shim = require('fabric-shim'); -const yargs = require('yargs'); - -class SimpleChaincode extends shim.ChaincodeInterface { - async Init(stub) { - // ... Init code - } - - async Invoke(stub) { - // ... Invoke code - } -} - -const argv = yargs(process.argv.slice(2)) - .option('chaincode-address', { - alias: 'ccid' - }) - .option('chaincode-id', { - alias: 'address' - }) - .argv; - -const server = shim.server(new SimpleChaincode(), { - ccid: argv['chaincode-id'], - address: argv['chaincode-address'] -}); - -server.start(); -``` - -To run a chaincode with the `fabric-contract` API as an external service, simply use `fabric-chaincode-node server` instead of `fabric-chaincode-node start`. Here is a sample for `package.json`: +## Run chaincode as a external service +To run chaincode as an external service, fabric-shim provides the `shim.server` API. If you are using contract APIs, you may want to use the `server` command provided by `fabric-chaincode-node` CLI to run a contract in the external service mode. To run a chaincode with the `fabric-contract` API as an external service, simply use `fabric-chaincode-node server` instead of `fabric-chaincode-node start`. Here is a sample for `package.json`: ```javascript { "scripts": {