Skip to content

Commit 98a754d

Browse files
Use Node 24 in Docker image with Node 20 minimum
Node 24 is the latest LTS release and is used as the runtime in the fabric-nodeenv Docker image to provide access to the latest features and performance improvements. Node 20 is now the minimum supported version since Node 18 is no longer supported. Signed-off-by: Mark S. Lewis <[email protected]>
1 parent 0ca91ec commit 98a754d

File tree

29 files changed

+114
-135
lines changed

29 files changed

+114
-135
lines changed

.github/workflows/scan.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
ref: ${{ inputs.ref }}
2626
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
2727
with:
28-
node-version: 18
28+
node-version: "lts/*"
2929
- name: Install
3030
run: node common/scripts/install-run-rush.js install
3131
- name: Build packages

.github/workflows/test.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
4343
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
4444
with:
45-
node-version: "18.x"
45+
node-version: "20.x"
4646
- name: Install/Rebuild/UnitTest
4747
run: |
4848
set -xev
@@ -80,7 +80,7 @@ jobs:
8080
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
8181
- uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
8282
with:
83-
node-version: "18.x"
83+
node-version: "20.x"
8484
- uses: actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53 # v6.0.0
8585
with:
8686
name: nodeenv-docker-image

COMPATIBILITY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ This table shows the summary of the compatibility of the Node chaincode packages
1212
| v2.2 | 12 | 12 | amd64 |
1313
| v2.5.0 - v2.5.4 | 18 | 18 | amd64, arm64 |
1414
| v2.5.5 - v2.5.7 | 18 | 20 | amd64, arm64 |
15-
| v2.5.8+ | 18 | 22 | amd64, arm64 |
15+
| v2.5.8 | 18 | 22 | amd64, arm64 |
16+
| v2.5.9+ | 20 | 24 | amd64, arm64 |
1617

1718
The Node runtime provided by the chaincode Docker image determines the maximum Node version (and features) that smart contract code can exploit when using the default Node chaincode container.
1819

CONTRIBUTING.md

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,52 +22,47 @@ The following [Rush categories](https://rushjs.io/pages/maintainer/add_to_repo/)
2222

2323
### Pre-requisites
2424

25-
* node v18 => recommend to use [nvm](https://github.com/nvm-sh/nvm)
26-
* rush => `npm install -g @microsoft/rush`
25+
- node 20+ => recommend to use [nvm](https://github.com/nvm-sh/nvm)
26+
- rush => `npm install -g @microsoft/rush`
2727

2828
> As an alternative to installing rush on your system, you can also have node install it for executing single commands similar to what is done in CI, for example from the `libraries/fabric-shim` directory you could add or update a dependency by running `node ../../common/scripts/install-run-rush.js add --package @grpc/grpc-js@latest`
2929
3030
> Note that npm v6 has some bugs that mean adding new dependencies etc are not properly picked up. Longer term we should consider moving to yarn or pnpm. However in practice this isn't a serious problem and has been possible to be worked around by issuing `rm ./common/config/rush/npm-shrinkwrap.json` and then `rush update`
3131
32-
The fv and e2e tests require a set of docker images of Fabric Peers, Orderers and CAs. To ensure you have the correct images ensure these have been dowloaded and tagged. `rush edge-docker` will do this for you.
33-
34-
They also need to have the `nodeenv` image present - this is build as part of the `rush rebuild` so please ensure this has been run first. It is advisable to clean up the docker containers and images between test runs to avoid any odd behaviour. Commands to help do this are below.
32+
They also need to have the `nodeenv` image present - this is build as part of the `rush rebuild` so please ensure this has been run first. It is advisable to clean up the docker containers and images between test runs to avoid any odd behaviour. Commands to help do this are below.
3533

3634
## Using the repo
3735

38-
* Clone the repo, and ensure you are using node v18, and have rush installed
39-
* `rush update` is needed to ensure everything is correctly linked and updated.
40-
- For example, after updating dependencies in `libraries/fabric-shim/package.json` run `rush update` which will delegate to `pnpm` to update the appropriate project files.
41-
- Note - you could also use `rush add` to have rush manage the `package.json` updates.
42-
* `rush edge-docker` will pull down and tag the very latest docker images for the peers, orderes etc to test against
36+
- Clone the repo, and ensure you are using node v18, and have rush installed
37+
- `rush update` is needed to ensure everything is correctly linked and updated.
38+
- For example, after updating dependencies in `libraries/fabric-shim/package.json` run `rush update` which will delegate to `pnpm` to update the appropriate project files.
39+
- Note - you could also use `rush add` to have rush manage the `package.json` updates.
4340

4441
At this point the repo is fully ready for use and running tests, etc. A full sequence of build-test that is equivalent to the CI pipeline is
4542

46-
* `rush rebuild` will run the linting, and unit tests across the codebase, as well as building the docker images, and jsdoc API docs
47-
* `rush start-verdaccio` & `rush stop-verdaccio` will start/stop verdaccio (used for local hosting of NPM modules)
48-
* `rush start-fabric` & `rush stop-fabric` will start/stop the test fabric ready for running FV tests
49-
* `rush test:fv` will run the fv tests, ensure that both the fabric and verdaccio have already been started
50-
* `rush test:e2e` to run e2e tests across the repos
43+
- `rush rebuild` will run the linting, and unit tests across the codebase, as well as building the docker images, and jsdoc API docs
44+
- `rush start-verdaccio` & `rush stop-verdaccio` will start/stop verdaccio (used for local hosting of NPM modules)
45+
- `rush start-fabric` & `rush stop-fabric` will start/stop the test fabric ready for running FV tests
46+
- `rush test:fv` will run the fv tests, ensure that both the fabric and verdaccio have already been started
47+
- `rush test:e2e` to run e2e tests across the repos
5148

5249
For more specific purposes during development the following are useful:
5350

54-
* `rush publish --include-all --pack --release-folder ./tarballs --publish`
55-
If you want to get a set of `.tar.gz` files of the node modules to use for local testing this command will put them into the `tarballs` directory
56-
* `rush rebuild --to fvtests` to run the unit tests for the core modules, but not the docker or jsdoc
57-
* `rush rebuild --to fabric-contract-api` to build, lint and run just the `fabric-contract-api`
58-
* `rush logs` will show the location of all the log files
51+
- `rush publish --include-all --pack --release-folder ./tarballs --publish`
52+
If you want to get a set of `.tar.gz` files of the node modules to use for local testing this command will put them into the `tarballs` directory
53+
- `rush rebuild --to fvtests` to run the unit tests for the core modules, but not the docker or jsdoc
54+
- `rush rebuild --to fabric-contract-api` to build, lint and run just the `fabric-contract-api`
55+
- `rush logs` will show the location of all the log files
5956

6057
To clean up docker
6158

62-
* `docker kill $(docker ps -q) && docker rm $(docker ps -aq)` will remove the running containers
63-
* `docker rmi $(docker images 'dev-*' -q) --force` will remove the images for the chaincode containers
59+
- `docker kill $(docker ps -q) && docker rm $(docker ps -aq)` will remove the running containers
60+
- `docker rmi $(docker images 'dev-*' -q) --force` will remove the images for the chaincode containers
6461

6562
## Mechanics of Contributing
6663

6764
The codebase is maintained in [github](https://github.com/hyperledger/fabric-chaincode-node), with a CI pipeline run with [Github Actions](https://github.com/hyperledger/fabric-chaincode-node/actions). Issues are handled in [Github Issues](https://github.com/hyperledger/fabric-chaincode-node/issues).
6865

69-
70-
7166
## Code of Conduct Guidelines <a name="conduct"></a>
7267

7368
See our [Code of Conduct Guidelines](https://github.com/hyperledger/fabric-chaincode-node/blob/main/CODE_OF_CONDUCT.md).

TUTORIAL.md

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ The dependencies of `fabric-contract-api` and `fabric-shim` will be required.
1515
"name": "chaincode",
1616
"description": "My first exciting chaincode implemented in node.js",
1717
"engines": {
18-
"node": ">=18"
18+
"node": ">=20"
1919
},
2020
"scripts": {
2121
"test": "mocha....."
@@ -33,6 +33,7 @@ The dependencies of `fabric-contract-api` and `fabric-shim` will be required.
3333
}
3434
3535
```
36+
3637
Remember to add in any additional business logic, and testing libraries needed
3738

3839
Adding `fabric-shim` as a dependency, gives a command `fabric-chaincode-node` that is the script to run for `npm start`.
@@ -45,7 +46,6 @@ Adding `fabric-shim` as a dependency, gives a command `fabric-chaincode-node` th
4546
},
4647
```
4748

48-
4949
### 2: How is chaincode deployed?
5050

5151
Chaincode is deployed by the peer in response to issuing a number of (usually CLI) commands. For node.js chaincode the location of the chaincode npm project is required (the directory that the package.json is in). This does not need to be an installed project, but has to have all the code, and the package.json.
@@ -54,7 +54,7 @@ A docker image is built for this chaincode, the package.json and code copied in.
5454

5555
After the install there is a 'bootstrap' process that starts the chaincode up (more details later). The constructors of the exported Contracts will be run at this point; these constructors are for setting the name and optional setup of the 'error/monitoring functions', (again more later). This instance of the contract will existing whilst this chaincode docker image is up.
5656

57-
When chaincode is instantiated or updated, the `init()` function in the chaincode is called. As with the `invoke()` call from the client, a fn name and parameters can be passed. Remember therefore to have specific functions to call on `init()` and `update()` in order to do any data initialisation or migration that might be needed. These two functions have been abstracted away to focus on specific function implementations.
57+
When chaincode is instantiated or updated, the `init()` function in the chaincode is called. As with the `invoke()` call from the client, a fn name and parameters can be passed. Remember therefore to have specific functions to call on `init()` and `update()` in order to do any data initialisation or migration that might be needed. These two functions have been abstracted away to focus on specific function implementations.
5858

5959
It is strongly recommended to use the npm shrinkwrap mechanism so the versions of the modules that are used are fixed.
6060

@@ -77,7 +77,7 @@ module.exports.contracts = [UpdateValues, RemoveValues];
7777
```
7878

7979
This exports two classes that together form the Contract. There can be other code that within the model that is used in a support role.
80-
*Note that the 'contracts' word is mandatory.*
80+
_Note that the 'contracts' word is mandatory._
8181

8282
### 4: What do these classes need to contain?
8383

@@ -159,15 +159,13 @@ Then you can invoke the chaincode via this command.
159159
$ peer chaincode invoke --orderer localhost:7050 --channelID mychannel -c '{"Args":["UpdateValuesContract:getAssetValue"]}' -n mycontract4
160160
```
161161

162-
163162
## Additional support provided by the SmartContract class
164163

165164
In case you ask for a function to be executed, it could be that this doesn't exist.
166165
If so, you can provide you own function to be executed, the default is to throw and error but you're able to customise this if you wish.
167166

168167
For example
169168

170-
171169
```
172170
/**
173171
* Sets a name so that the functions in this particular class can
@@ -206,14 +204,14 @@ async aroundTransaction(ctx, fn, parameters) {
206204

207205
### Structure of the Transaction Context
208206

209-
In Fabric, there is a *stub* api that provides chaincode with functionality.
207+
In Fabric, there is a _stub_ api that provides chaincode with functionality.
210208
No functionality has been removed, but a new approach to providing abstractions on this to facilitate programming.
211209

212-
*user additions*: additional properties can be added to the object to support for example common handling of the data serialization.
210+
_user additions_: additional properties can be added to the object to support for example common handling of the data serialization.
213211

214212
The context object contains
215213

216-
- `ctx.stub` the same stub instance as in earlier versions for compatibility
214+
- `ctx.stub` the same stub instance as in earlier versions for compatibility
217215
- `ctx.identity` and instance of the Client Identity object
218216

219217
You are at liberty to create a subclass of the Context to provide additional functions, or per-transaction context storage. For example
@@ -249,29 +247,29 @@ class ScenarioContext extends Context {
249247

250248
Definitions as per https://www.ietf.org/rfc/rfc2119.txt
251249

252-
- All the functions that are present in the prototype of a class that extends *Contract* will be invokable
253-
- The exports from the node module *MUST* include *contracts* that is an array of constructors (1 or more)
254-
- Each class *MAY* call in it's constructor pass a name. This is prefixed to each of the function names by an _ (underscore)
255-
- Each class *MAY* define functions that are executed before and functions that are executed after the invoked function.
250+
- All the functions that are present in the prototype of a class that extends _Contract_ will be invokable
251+
- The exports from the node module _MUST_ include _contracts_ that is an array of constructors (1 or more)
252+
- Each class _MAY_ call in it's constructor pass a name. This is prefixed to each of the function names by an \_ (underscore)
253+
- Each class _MAY_ define functions that are executed before and functions that are executed after the invoked function.
256254
- These are part of the same fabric transaction
257255
- They are scoped per name
258-
- Each class *MAY* define a function that would be executed if a matching function name does not exist; otherwise a 'no function exists' error will be thrown
256+
- Each class _MAY_ define a function that would be executed if a matching function name does not exist; otherwise a 'no function exists' error will be thrown
259257
- If too many parameters are passed, they will be discarded
260258
- If too few parameters are passed, the remainder will be set to undefined
261-
- as per node.js language standard
259+
- as per node.js language standard
262260
- Having duplicate function names in a single class is an error
263261
- Any function that is dynamically added will not be registered as an invokable function
264-
- There is no specific function that is invoked per Fabric's *init* chaincode spi. The instantiate flow can pass function name and parameters; therefore consider
265-
a dedicated function that will be called for new chaincode deployments, and for upgrade deployments.
262+
- There is no specific function that is invoked per Fabric's _init_ chaincode spi. The instantiate flow can pass function name and parameters; therefore consider
263+
a dedicated function that will be called for new chaincode deployments, and for upgrade deployments.
266264

267265
## Restrictions on programming in side a Contract function
268266

269267
Hyperledger Fabric's consensus algorithm permits the ability to use general purpose languages; rather than a more restrictive language. But the following restrictions apply
270268

271269
- Functions should not create random variables, or use any function whose return values are functions of the current time or location of execution
272-
- i.e. the function will be executed in another context (i.e. peer process). This could potentially be in a different time zone in a different locale.
270+
- i.e. the function will be executed in another context (i.e. peer process). This could potentially be in a different time zone in a different locale.
273271
- Functions should be aware that they may read state, and write state. But they are producing a set of changes that will be applied to the state. The implication is that updates to the state
274-
may not be read back.
272+
may not be read back.
275273

276274
```
277275
let v1 = getState("key");

apis/fabric-contract-api/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"Fabric Shim"
2323
],
2424
"engines": {
25-
"node": ">=18"
25+
"node": ">=20"
2626
},
2727
"license": "Apache-2.0",
2828
"types": "./types/index.d.ts",
@@ -70,6 +70,6 @@
7070
"typescript": "~5.8.3",
7171
"typescript-eslint": "^8.46.0",
7272
"@eslint/js": "^9.37.0",
73-
"@tsconfig/node18": "~18.2.4"
73+
"@tsconfig/node20": "~20.1.6"
7474
}
7575
}

apis/fabric-contract-api/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66
{
77
"$schema": "https://json.schemastore.org/tsconfig",
8-
"extends": "@tsconfig/node18/tsconfig.json",
8+
"extends": "@tsconfig/node20/tsconfig.json",
99
"compilerOptions": {
1010
"types": ["./types/"],
1111
"declaration": true,

apis/fabric-shim-api/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
"Fabric Shim"
1919
],
2020
"engines": {
21-
"node": ">=18"
21+
"node": ">=20"
2222
},
2323
"types": "./types/index.d.ts",
2424
"license": "Apache-2.0",
2525
"devDependencies": {
2626
"@types/long": "^4.0.1",
2727
"eslint": "^9.37.0",
28-
"@eslint/js": "^9.37.0"
28+
"@eslint/js": "^9.37.0",
29+
"@tsconfig/node20": "~20.1.6"
2930
}
3031
}

apis/fabric-shim-api/tsconfig.json

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,17 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66
{
7-
"compilerOptions": {
8-
"types": ["./types/"],
9-
"alwaysStrict": true,
10-
"module": "commonjs",
11-
"declaration": true,
12-
"sourceMap": true,
13-
"strict": true,
14-
"target": "es2017",
15-
"lib": [
16-
"esnext",
17-
]
18-
},
19-
"files": [
20-
"types/index.d.ts"
21-
],
22-
"exclude": [
23-
"node_modules/**/*"
24-
]
7+
"$schema": "https://json.schemastore.org/tsconfig",
8+
"extends": "@tsconfig/node20/tsconfig.json",
9+
"compilerOptions": {
10+
"types": ["./types/"],
11+
"declaration": true,
12+
"declarationMap": true,
13+
"erasableSyntaxOnly": true,
14+
"isolatedModules": true,
15+
"sourceMap": true,
16+
"strict": true
17+
},
18+
"files": ["types/index.d.ts"],
19+
"exclude": ["node_modules/**/*"]
2520
}

0 commit comments

Comments
 (0)