fablo icon indicating copy to clipboard operation
fablo copied to clipboard

chore: Refactor extendChaincodesConfig.ts to allow private data in chaincode

Open SkySingh04 opened this issue 1 year ago • 1 comments

References

  • Original Issue: #415

Issue Details

The default configuration for requiredPeerCount causes the following error:

error in simulation: failed to distribute private collection, txID 123, channel 123: could not build private data dissemination plan for chaincode 123 and collection 123: required to disseminate to at least 1 peers, but know of only 0 eligible peers.

Solution

The solution is to allow requiredPeerCount to be set to 0. This can be achieved by modifying the logic in the code that generates this property. Specifically, removing the || 1 part from the following lines of code:

const anchorPeerCountsInChannel = channel.orgs.map((o) => (o.anchorPeers || []).length);
const maxPeerCount = anchorPeerCountsInChannel.reduce((a, b) => a + b, 0);
const requiredPeerCount = anchorPeerCountsInChannel.reduce((a, b) => Math.min(a, b), maxPeerCount) || 1;

Changes Made

  • Removed the || 1 from the calculation of requiredPeerCount to allow it to be set to 0 if necessary.

SkySingh04 avatar Jul 01 '24 01:07 SkySingh04

Thanks, I've approved the CI run and we'll see how it goes. I'm 90% sure you'll need to also update snapshots locally (see: https://github.com/hyperledger-labs/fablo/blob/main/CONTRIBUTING.md#making-changes), but after that it will be good to go.

dzikowski avatar Jul 01 '24 13:07 dzikowski

@dzikowski I am having some problems in updating the snapshot.


> [email protected] test:e2e-update
> ./fablo-build.sh && jest e2e --runInBand --updateSnapshot && ./lint.sh

allexport       off
braceexpand     on
emacs           off
errexit         on
errtrace        off
functrace       off
hashall         on
histexpand      off
history         off
ignoreeof       off
interactive-comments    on
keyword         off
monitor         off
noclobber       off
noexec          off
noglob          off
nolog           off
notify          off
nounset         on
onecmd          off
physical        off
pipefail        off
posix           off
privileged      off
verbose         off
vi              off
xtrace          off
Building new image...
   FABLO_HOME:    /home/akash/Desktop/fablo
   FABLO_VERSION: 1.2.1-unstable.0
   VERSION_DETAILS: 2024-07-04-10:18:10-ddbca51
Found '/home/akash/Desktop/fablo/.nvmrc' with version <18>
v18.20.3 is already installed.
Now using node v18.20.3 (npm v10.7.0)
/home/akash/.nvm/nvm.sh: line 3319: [: -ne: unary operator expected
/home/akash/.nvm/nvm.sh: line 3323: [: -ne: unary operator expected
/home/akash/.nvm/nvm.sh: line 3335: [: -ne: unary operator expected

up to date, audited 1173 packages in 2s

145 packages are looking for funding
  run `npm fund` for details

2 moderate severity vulnerabilities

To address all issues (including breaking changes), run:
  npm audit fix --force

Run `npm audit` for details.

> [email protected] build:dist
> npm run clean && tsc -p tsconfig-dist.json && npm run copydeps


> [email protected] clean
> rimraf generators


> [email protected] copydeps
> copyfiles --all --up 1 'src/*/templates/**' generators

[+] Building 2.5s (24/24) FINISHED                                                              docker:desktop-linux
 => [internal] load build definition from Dockerfile                                                            0.0s
 => => transferring dockerfile: 1.51kB                                                                          0.0s
 => [internal] load metadata for docker.io/library/node:18-alpine3.16                                           2.0s
 => [auth] library/node:pull token for registry-1.docker.io                                                     0.0s
 => [internal] load .dockerignore                                                                               0.0s
 => => transferring context: 339B                                                                               0.0s
 => [internal] load build context                                                                               0.0s
 => => transferring context: 1.29MB                                                                             0.0s
 => [ 1/18] FROM docker.io/library/node:18-alpine3.16@sha256:1eabdb1aa3f6e68558c08501572731db560d10c2194a67d34  0.0s
 => CACHED [ 2/18] RUN apk add --no-cache sudo shfmt                                                            0.0s
 => CACHED [ 3/18] RUN npm install --global --silent yo                                                         0.0s
 => CACHED [ 4/18] COPY generators /fablo/generators                                                            0.0s
 => CACHED [ 5/18] COPY package.json /fablo/package.json                                                        0.0s
 => CACHED [ 6/18] COPY package-lock.json /fablo/package-lock.json                                              0.0s
 => CACHED [ 7/18] COPY samples/fablo-config-hlf2-1org-1chaincode.json /fablo/generators/init/templates/fablo-  0.0s
 => CACHED [ 8/18] COPY samples/chaincodes/chaincode-kv-node /fablo/generators/init/templates/chaincodes/chain  0.0s
 => CACHED [ 9/18] WORKDIR /fablo                                                                               0.0s
 => CACHED [10/18] RUN npm install --silent --only=prod                                                         0.0s
 => CACHED [11/18] RUN npm link                                                                                 0.0s
 => CACHED [12/18] RUN adduser -D -u 501 yeoman &&   echo "yeoman ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers       0.0s
 => CACHED [13/18] COPY docker-entrypoint.sh /fablo/docker-entrypoint.sh                                        0.0s
 => CACHED [14/18] COPY docs /fablo/docs                                                                        0.0s
 => CACHED [15/18] COPY README.md /fablo/README.md                                                              0.0s
 => CACHED [16/18] COPY samples /fablo/samples/                                                                 0.0s
 => [17/18] RUN echo "{ "buildInfo": "2024-07-04-10:18:10-ddbca51" }" > /fablo/version.json                     0.1s
 => [18/18] RUN cat /fablo/version.json                                                                         0.2s
 => exporting to image                                                                                          0.0s
 => => exporting layers                                                                                         0.0s
 => => writing image sha256:12dd3e45b31f059ba9cb947a2369d547a51cc206e8204e43887987c4c9b799ae                    0.0s
 => => naming to docker.io/softwaremill/fablo:1.2.1-unstable.0                                                  0.0s

What's Next?
  View a summary of image vulnerabilities and recommendations → docker scout quickview
 PASS  e2e/schema.test.ts

 RUNS  e2e/fabloCommands.test.ts```
 
 The second test never completes, nor the snapshots get updated. Am i missing something?

SkySingh04 avatar Jul 04 '24 05:07 SkySingh04

Are you sure it never ends? It should take a lot of time, even a couple of minutes. And eventually, if there is an error with Fablo, the test engine (Jest) should terminate the test with an error.

dzikowski avatar Jul 05 '24 15:07 dzikowski

@Akash-Singh04 After merging changes from main branch everything seems working. Approving and merging.

dzikowski avatar Aug 09 '24 15:08 dzikowski