From e98306f7bc088d5f0fc874ceea8725c90a0ad2ac Mon Sep 17 00:00:00 2001 From: Sanket Date: Wed, 13 Nov 2024 16:06:48 +0530 Subject: [PATCH 01/11] done with initial configuration for BFT, updated the templates for the same Signed-off-by: Sanket --- docs/schema.json | 3 +- e2e-network/docker/test-05-version3-BFT.sh | 84 +++++++++++++++++++ .../fablo-config-hlf3-1orgs-1chaincode.json | 4 +- ...ablo-config-hlf3-bft-1orgs-1chaincode.json | 60 +++++++++++++ .../configtx-raft-template.yaml.ejs | 12 +++ src/types/FabloConfigExtended.ts | 2 +- src/types/FabloConfigJson.ts | 2 +- 7 files changed, 162 insertions(+), 5 deletions(-) create mode 100644 e2e-network/docker/test-05-version3-BFT.sh create mode 100644 samples/fablo-config-hlf3-bft-1orgs-1chaincode.json diff --git a/docs/schema.json b/docs/schema.json index fd598100..2f411465 100644 --- a/docs/schema.json +++ b/docs/schema.json @@ -224,7 +224,8 @@ "description": "The 'solo' consensus type may be used in development environment only. Use 'raft' in production.", "enum": [ "solo", - "raft" + "raft", + "BFT" ] }, "instances": { diff --git a/e2e-network/docker/test-05-version3-BFT.sh b/e2e-network/docker/test-05-version3-BFT.sh new file mode 100644 index 00000000..b5d566dd --- /dev/null +++ b/e2e-network/docker/test-05-version3-BFT.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash + +set -eux + +TEST_TMP="$(rm -rf "$0.tmpdir" && mkdir -p "$0.tmpdir" && (cd "$0.tmpdir" && pwd))" +TEST_LOGS="$(mkdir -p "$0.logs" && (cd "$0.logs" && pwd))" +FABLO_HOME="$TEST_TMP/../../.." + +export FABLO_HOME + +CONFIG="$FABLO_HOME/fablo-config-hlf3-bft-1orgs-1chaincode.json" + +networkUp() { + "$FABLO_HOME/fablo-build.sh" + (cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" generate "$CONFIG") + (cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" up) +} + +dumpLogs() { + echo "Saving logs of $1 to $TEST_LOGS/$1.log" + mkdir -p "$TEST_LOGS" + docker logs "$1" >"$TEST_LOGS/$1.log" 2>&1 +} + +networkDown() { + rm -rf "$TEST_LOGS" + (for name in $(docker ps --format '{{.Names}}'); do dumpLogs "$name"; done) + dumpLogs orderer0.group1.orderer.example.com + (cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" down) +} + +waitForContainer() { + sh "$TEST_TMP/../wait-for-container.sh" "$1" "$2" +} + +waitForChaincode() { + (cd "$TEST_TMP" && sh ../wait-for-chaincode.sh "$1" "$2" "$3" "$4") +} + +expectInvoke() { + (cd "$TEST_TMP" && sh ../expect-invoke-cli.sh "$1" "$2" "$3" "$4" "$5" "") +} + +expectCommand() { + sh "$TEST_TMP/../expect-command.sh" "$1" "$2" +} + +trap networkDown EXIT +trap 'networkDown ; echo "Test failed" ; exit 1' ERR SIGINT + +# start the network +networkUp + +waitForContainer "orderer0.group1.orderer.example.com" "Starting raft node as part of a new channel channel=my-channel1" +waitForContainer "ca.org1.example.com" "Listening on https://0.0.0.0:7054" +waitForContainer "peer0.org1.example.com" "Joining gossip network of channel my-channel1 with 1 organizations" +waitForContainer "peer1.org1.example.com" "Joining gossip network of channel my-channel1 with 1 organizations" +waitForContainer "peer0.org1.example.com" "Learning about the configured anchor peers of Org1MSP for channel my-channel1" +waitForContainer "peer0.org1.example.com" "Anchor peer.*with same endpoint, skipping connecting to myself" +waitForContainer "peer0.org1.example.com" "Membership view has changed. peers went online:.*peer1.org1.example.com:7042" +waitForContainer "peer1.org1.example.com" "Learning about the configured anchor peers of Org1MSP for channel my-channel1" +waitForContainer "peer1.org1.example.com" "Membership view has changed. peers went online:.*peer0.org1.example.com:7041" + +# Test simple chaincode +expectInvoke "peer0.org1.example.com" "my-channel1" "chaincode1" \ + '{"Args":["KVContract:put", "name", "Willy Wonka"]}' \ + '{\"success\":\"OK\"}' +expectInvoke "peer1.org1.example.com" "my-channel1" "chaincode1" \ + '{"Args":["KVContract:get", "name"]}' \ + '{\"success\":\"Willy Wonka\"}' + +# Verify channel query scripts +(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch newest my-channel1 org1 peer1) +expectCommand "cat \"$TEST_TMP/newest.block\"" "KVContract:get" + +(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch 3 my-channel1 org1 peer1 "another.block") +expectCommand "cat \"$TEST_TMP/another.block\"" "KVContract:put" + +(cd "$TEST_TMP" && "$FABLO_HOME/fablo.sh" channel fetch config my-channel1 org1 peer1 "channel-config.json") +expectCommand "cat \"$TEST_TMP/channel-config.json\"" "\"mod_policy\": \"Admins\"," + +expectCommand "(cd \"$TEST_TMP\" && \"$FABLO_HOME/fablo.sh\" channel getinfo my-channel1 org1 peer1)" "\"height\":5" + +echo "🎉 Test passed! 🎉" \ No newline at end of file diff --git a/samples/fablo-config-hlf3-1orgs-1chaincode.json b/samples/fablo-config-hlf3-1orgs-1chaincode.json index f20b46de..c56c53c1 100644 --- a/samples/fablo-config-hlf3-1orgs-1chaincode.json +++ b/samples/fablo-config-hlf3-1orgs-1chaincode.json @@ -16,8 +16,8 @@ "orderers": [ { "groupName": "group1", - "type": "raft", - "instances": 1 + "type": "BFT", + "instances": 4 } ] }, diff --git a/samples/fablo-config-hlf3-bft-1orgs-1chaincode.json b/samples/fablo-config-hlf3-bft-1orgs-1chaincode.json new file mode 100644 index 00000000..8f90718a --- /dev/null +++ b/samples/fablo-config-hlf3-bft-1orgs-1chaincode.json @@ -0,0 +1,60 @@ +{ + "$schema": "https://github.com/hyperledger-labs/fablo/releases/download/2.0.0/schema.json", + "global": { + "fabricVersion": "3.0.0-beta", + "tls": true, + "monitoring": { + "loglevel": "debug" + } + }, + "orgs": [ + { + "organization": { + "name": "Orderer", + "domain": "orderer.example.com" + }, + "orderers": [ + { + "groupName": "group1", + "type": "BFT", + "instances": 4 + } + + ] + }, + { + "organization": { + "name": "Org1", + "domain": "org1.example.com" + }, + "peer": { + "instances": 2, + "db": "LevelDb" + } + } + ], + "channels": [ + { + "name": "my-channel1", + "orgs": [ + { + "name": "Org1", + "peers": [ + "peer0", + "peer1" + ] + } + ] + } + ], + "chaincodes": [ + { + "name": "chaincode1", + "version": "0.0.1", + "lang": "node", + "channel": "my-channel1", + "directory": "./chaincodes/chaincode-kv-node" + } + ] + } + \ No newline at end of file diff --git a/src/setup-docker/templates/fabric-config/configtx-raft-template.yaml.ejs b/src/setup-docker/templates/fabric-config/configtx-raft-template.yaml.ejs index 8f7ddc6f..ef7ad0fe 100755 --- a/src/setup-docker/templates/fabric-config/configtx-raft-template.yaml.ejs +++ b/src/setup-docker/templates/fabric-config/configtx-raft-template.yaml.ejs @@ -6,3 +6,15 @@ ClientTLSCert: crypto-config/peerOrganizations/<%= orderer.domain %>/peers/<%= orderer.address %>/tls/server.crt ServerTLSCert: crypto-config/peerOrganizations/<%= orderer.domain %>/peers/<%= orderer.address %>/tls/server.crt <% })} -%> + +<% if (ordererGroup.consensus == "BFT") { %> + smartBFT: + ConsenterMapping:<% ordererGroup.orderers.forEach(function(orderer, index) { %> + - ID: <%= index+1 %> + Host: <%= orderer.address %> + Port: <%= orderer.port %> + MSPID: <%= orderer.orgMspName %> + Identity: crypto-config/peerOrganizations/<%= orderer.domain %>/peers/<%= orderer.address %>/msp/tlscacerts/tlsca.orderer.example.com-cert.pem + ClientTLSCert: crypto-config/peerOrganizations/<%= orderer.domain %>/peers/<%= orderer.address %>/tls/server.crt + ServerTLSCert: crypto-config/peerOrganizations/<%= orderer.domain %>/peers/<%= orderer.address %>/tls/server.crt +<% })} -%> diff --git a/src/types/FabloConfigExtended.ts b/src/types/FabloConfigExtended.ts index 266f433a..3a20c75d 100644 --- a/src/types/FabloConfigExtended.ts +++ b/src/types/FabloConfigExtended.ts @@ -160,7 +160,7 @@ export interface ChaincodeConfig { export interface OrdererGroup { name: string; - consensus: "solo" | "etcdraft"; + consensus: "solo" | "etcdraft" | "BFT"; profileName: string; genesisBlockName: string; configtxOrdererDefaults: string; diff --git a/src/types/FabloConfigJson.ts b/src/types/FabloConfigJson.ts index b2bb11ee..bc50f916 100644 --- a/src/types/FabloConfigJson.ts +++ b/src/types/FabloConfigJson.ts @@ -21,7 +21,7 @@ export interface CAJson { export interface OrdererJson { groupName: string; prefix: string; - type: "solo" | "raft"; + type: "solo" | "raft" | "BFT"; instances: number; } From 4b3e7850426e2ea0cd3b5964892c94d44c4e11d4 Mon Sep 17 00:00:00 2001 From: Sanket Date: Fri, 22 Nov 2024 09:23:28 +0530 Subject: [PATCH 02/11] updated the permission Signed-off-by: Sanket --- e2e-network/docker/test-05-version3-BFT.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 e2e-network/docker/test-05-version3-BFT.sh diff --git a/e2e-network/docker/test-05-version3-BFT.sh b/e2e-network/docker/test-05-version3-BFT.sh old mode 100644 new mode 100755 From a711deb104668f2e22f67aebaf07fdfa32d5c0e7 Mon Sep 17 00:00:00 2001 From: Sanket Date: Fri, 22 Nov 2024 18:15:10 +0530 Subject: [PATCH 03/11] version 3 completed heading towards adding BFT support Signed-off-by: Sanket --- e2e-network/docker/test-05-version3-BFT.sh | 2 +- .../fablo-config-hlf3-1orgs-1chaincode.json | 2 +- .../configtx-raft-template.yaml.ejs | 15 +++++++++- .../fabric-docker/commands-generated.sh | 15 +++++----- .../scripts/cli/channel_fns-v3.sh | 28 +++++++++---------- 5 files changed, 38 insertions(+), 24 deletions(-) diff --git a/e2e-network/docker/test-05-version3-BFT.sh b/e2e-network/docker/test-05-version3-BFT.sh index b5d566dd..179d2c53 100755 --- a/e2e-network/docker/test-05-version3-BFT.sh +++ b/e2e-network/docker/test-05-version3-BFT.sh @@ -8,7 +8,7 @@ FABLO_HOME="$TEST_TMP/../../.." export FABLO_HOME -CONFIG="$FABLO_HOME/fablo-config-hlf3-bft-1orgs-1chaincode.json" +CONFIG="$FABLO_HOME/samples/fablo-config-hlf3-bft-1orgs-1chaincode.json" networkUp() { "$FABLO_HOME/fablo-build.sh" diff --git a/samples/fablo-config-hlf3-1orgs-1chaincode.json b/samples/fablo-config-hlf3-1orgs-1chaincode.json index c56c53c1..467c2920 100644 --- a/samples/fablo-config-hlf3-1orgs-1chaincode.json +++ b/samples/fablo-config-hlf3-1orgs-1chaincode.json @@ -16,7 +16,7 @@ "orderers": [ { "groupName": "group1", - "type": "BFT", + "type": "raft", "instances": 4 } ] diff --git a/src/setup-docker/templates/fabric-config/configtx-raft-template.yaml.ejs b/src/setup-docker/templates/fabric-config/configtx-raft-template.yaml.ejs index ef7ad0fe..8218b70b 100755 --- a/src/setup-docker/templates/fabric-config/configtx-raft-template.yaml.ejs +++ b/src/setup-docker/templates/fabric-config/configtx-raft-template.yaml.ejs @@ -8,7 +8,20 @@ <% })} -%> <% if (ordererGroup.consensus == "BFT") { %> - smartBFT: + SmartBFT: + RequestBatchMaxCount: 100 + RequestBatchMaxInterval: 50ms + RequestForwardTimeout: 2s + RequestComplainTimeout: 20s + RequestAutoRemoveTimeout: 3m0s + ViewChangeResendInterval: 5s + ViewChangeTimeout: 20s + LeaderHeartbeatTimeout: 1m0s + CollectTimeout: 1s + RequestBatchMaxBytes: 10485760 + IncomingMessageBufferSize: 200 + RequestPoolSize: 100000 + LeaderHeartbeatCount: 10 ConsenterMapping:<% ordererGroup.orderers.forEach(function(orderer, index) { %> - ID: <%= index+1 %> Host: <%= orderer.address %> diff --git a/src/setup-docker/templates/fabric-docker/commands-generated.sh b/src/setup-docker/templates/fabric-docker/commands-generated.sh index 8d1f81fe..7e3d1717 100644 --- a/src/setup-docker/templates/fabric-docker/commands-generated.sh +++ b/src/setup-docker/templates/fabric-docker/commands-generated.sh @@ -44,24 +44,26 @@ generateChannelsArtifacts() { } installChannels() { + set -x <% if (!channels || !channels.length) { -%> + echo "No channels" <% } else if (global.capabilities.isV3) { -%> <% channels.forEach((channel) => { -%> + <% channel.ordererGroup.orderers.forEach((orderer) => { -%> + <% const org = orgs.find((org) => org.name === orderer.orgName); -%> + docker exec -i <%= org.cli.address %> bash -c <% -%> + "source scripts/channel_fns.sh; createChannelAndJoinTls '<%= channel.name %>' '<%= orderer.orgMspName %>' 'example.com' 'crypto/users/Admin@test/msp' '<%= orderer.address %>:<%= orderer.adminPort %>';" + <% }) -%> + sleep 8 <% channel.orgs.forEach((org, orgNo) => { -%> <% org.peers.forEach((peer, peerNo) => { -%> <% if (orgNo == 0 && peerNo == 0) { -%> printHeadline "Creating '<%= channel.name %>' on <%= org.name %>/<%= peer.name %>" "U1F63B" <% if (!global.tls) { -%> - docker exec -i <%= org.cli.address %> bash -c <% -%> - "source scripts/channel_fns.sh; createChannelAndJoin '<%= channel.name %>' '<%= org.mspName %>' '<%= peer.fullAddress %>' 'crypto/users/Admin@<%= org.domain %>/msp' '<%= channel.ordererHead.address %>:<%= channel.ordererHead.adminPort %>';" - sleep 5 docker exec -i <%= org.cli.address %> bash -c <% -%> "source scripts/channel_fns.sh; fetchChannelAndJoin '<%= channel.name %>' '<%= org.mspName %>' '<%= peer.fullAddress %>' 'crypto/users/Admin@<%= org.domain %>/msp' '<%= channel.ordererHead.fullAddress %>';" <% } else { -%> - docker exec -i <%= org.cli.address %> bash -c <% -%> - "source scripts/channel_fns.sh; createChannelAndJoinTls '<%= channel.name %>' '<%= org.mspName %>' '<%= peer.fullAddress %>' 'crypto/users/Admin@<%= org.domain %>/msp' 'crypto/users/Admin@<%= org.domain %>/tls' 'crypto-orderer/tlsca.<%= channel.ordererHead.domain %>-cert.pem' '<%= channel.ordererHead.address %>:<%= channel.ordererHead.adminPort %>';" - sleep 5 docker exec -i <%= org.cli.address %> bash -c <% -%> "source scripts/channel_fns.sh; fetchChannelAndJoinTls '<%= channel.name %>' '<%= org.mspName %>' '<%= peer.fullAddress %>' 'crypto/users/Admin@<%= org.domain %>/msp' 'crypto/users/Admin@<%= org.domain %>/tls' 'crypto-orderer/tlsca.<%= channel.ordererHead.domain %>-cert.pem' '<%= channel.ordererHead.fullAddress %>';" <% } %> @@ -107,7 +109,6 @@ installChannels() { <% } -%> } - installChaincodes() { <% if (!chaincodes || !chaincodes.length) { -%> echo "No chaincodes" diff --git a/src/setup-docker/templates/fabric-docker/scripts/cli/channel_fns-v3.sh b/src/setup-docker/templates/fabric-docker/scripts/cli/channel_fns-v3.sh index 88be1167..6eaf90ce 100644 --- a/src/setup-docker/templates/fabric-docker/scripts/cli/channel_fns-v3.sh +++ b/src/setup-docker/templates/fabric-docker/scripts/cli/channel_fns-v3.sh @@ -33,26 +33,26 @@ createChannelAndJoinTls() { local CORE_PEER_LOCALMSPID=$2 local CORE_PEER_ADDRESS=$3 - local CORE_PEER_MSPCONFIGPATH=$(realpath "$4") - local CORE_PEER_TLS_MSPCONFIGPATH=$(realpath "$5") - local TLS_CA_CERT_PATH=$(realpath "$6") - local ORDERER_URL=$7 + # local CORE_PEER_MSPCONFIGPATH=$(realpath "$4") + # local CORE_PEER_TLS_MSPCONFIGPATH=$(realpath "$5") + # local TLS_CA_CERT_PATH=$(realpath "$6") + local ORDERER_URL=$5 - local CORE_PEER_TLS_CERT_FILE=$CORE_PEER_TLS_MSPCONFIGPATH/client.crt - local CORE_PEER_TLS_KEY_FILE=$CORE_PEER_TLS_MSPCONFIGPATH/client.key - local CORE_PEER_TLS_ROOTCERT_FILE=$CORE_PEER_TLS_MSPCONFIGPATH/ca.crt + # local CORE_PEER_TLS_CERT_FILE=$CORE_PEER_TLS_MSPCONFIGPATH/client.crt + # local CORE_PEER_TLS_KEY_FILE=$CORE_PEER_TLS_MSPCONFIGPATH/client.key + # local CORE_PEER_TLS_ROOTCERT_FILE=$CORE_PEER_TLS_MSPCONFIGPATH/ca.crt - local DIR_NAME=step-createChannelAndJoinTls-$CHANNEL_NAME-$CORE_PEER_ADDRESS + local DIR_NAME=step-createChannelAndJoinTls-$CHANNEL_NAME-$CORE_PEER_LOCALMSPID echo "Creating channel with name (TLS): ${CHANNEL_NAME}" echo " Orderer: $ORDERER_URL" echo " CORE_PEER_LOCALMSPID: $CORE_PEER_LOCALMSPID" - echo " CORE_PEER_ADDRESS: $CORE_PEER_ADDRESS" - echo " CORE_PEER_MSPCONFIGPATH: $CORE_PEER_MSPCONFIGPATH" - echo " TLS_CA_CERT_PATH is: $TLS_CA_CERT_PATH" - echo " CORE_PEER_TLS_CERT_FILE: $CORE_PEER_TLS_CERT_FILE" - echo " CORE_PEER_TLS_KEY_FILE: $CORE_PEER_TLS_KEY_FILE" - echo " CORE_PEER_TLS_ROOTCERT_FILE: $CORE_PEER_TLS_ROOTCERT_FILE" + # echo " CORE_PEER_ADDRESS: $CORE_PEER_ADDRESS" + # echo " CORE_PEER_MSPCONFIGPATH: $CORE_PEER_MSPCONFIGPATH" + # echo " TLS_CA_CERT_PATH is: $TLS_CA_CERT_PATH" + # echo " CORE_PEER_TLS_CERT_FILE: $CORE_PEER_TLS_CERT_FILE" + # echo " CORE_PEER_TLS_KEY_FILE: $CORE_PEER_TLS_KEY_FILE" + # echo " CORE_PEER_TLS_ROOTCERT_FILE: $CORE_PEER_TLS_ROOTCERT_FILE" mkdir "$DIR_NAME" && cd "$DIR_NAME" From e0aefc25aa4f281619f1b304bc5f1594d628c3cf Mon Sep 17 00:00:00 2001 From: Jakub Dzikowski Date: Sat, 30 Nov 2024 10:10:34 +0100 Subject: [PATCH 04/11] Use proper createChannelAndJoinTls with certs Signed-off-by: Jakub Dzikowski --- .../fabric-docker/commands-generated.sh | 4 +- .../scripts/cli/channel_fns-v3.sh | 50 +++++++++---------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/src/setup-docker/templates/fabric-docker/commands-generated.sh b/src/setup-docker/templates/fabric-docker/commands-generated.sh index 7e3d1717..7644abc3 100644 --- a/src/setup-docker/templates/fabric-docker/commands-generated.sh +++ b/src/setup-docker/templates/fabric-docker/commands-generated.sh @@ -53,9 +53,9 @@ installChannels() { <% channel.ordererGroup.orderers.forEach((orderer) => { -%> <% const org = orgs.find((org) => org.name === orderer.orgName); -%> docker exec -i <%= org.cli.address %> bash -c <% -%> - "source scripts/channel_fns.sh; createChannelAndJoinTls '<%= channel.name %>' '<%= orderer.orgMspName %>' 'example.com' 'crypto/users/Admin@test/msp' '<%= orderer.address %>:<%= orderer.adminPort %>';" + "source scripts/channel_fns.sh; createChannelAndJoinTls '<%= channel.name %>' '<%= orderer.orgMspName %>' '<%= orderer.address %>:<%= orderer.adminPort %>' 'crypto/users/Admin@<%= orderer.domain %>/tls/client.crt' 'crypto/users/Admin@<%= orderer.domain %>/tls/client.key' 'crypto-orderer/tlsca.<%= orderer.domain %>-cert.pem';" <% }) -%> - sleep 8 + sleep 8 # TODO: remove sleep <% channel.orgs.forEach((org, orgNo) => { -%> <% org.peers.forEach((peer, peerNo) => { -%> <% if (orgNo == 0 && peerNo == 0) { -%> diff --git a/src/setup-docker/templates/fabric-docker/scripts/cli/channel_fns-v3.sh b/src/setup-docker/templates/fabric-docker/scripts/cli/channel_fns-v3.sh index 6eaf90ce..1b51468a 100644 --- a/src/setup-docker/templates/fabric-docker/scripts/cli/channel_fns-v3.sh +++ b/src/setup-docker/templates/fabric-docker/scripts/cli/channel_fns-v3.sh @@ -30,36 +30,34 @@ createChannelAndJoin() { createChannelAndJoinTls() { local CHANNEL_NAME=$1 + local ORDERER_MSP_NAME=$2 + local ORDERER_ADMIN_ADDRESS=$3 + local ADMIN_TLS_SIGN_CERT=$(realpath "$4") + local ADMIN_TLS_PRIVATE_KEY=$(realpath "$5") + local TLS_CA_CERT_PATH=$(realpath "$6") - local CORE_PEER_LOCALMSPID=$2 - local CORE_PEER_ADDRESS=$3 - # local CORE_PEER_MSPCONFIGPATH=$(realpath "$4") - # local CORE_PEER_TLS_MSPCONFIGPATH=$(realpath "$5") - # local TLS_CA_CERT_PATH=$(realpath "$6") - local ORDERER_URL=$5 - - # local CORE_PEER_TLS_CERT_FILE=$CORE_PEER_TLS_MSPCONFIGPATH/client.crt - # local CORE_PEER_TLS_KEY_FILE=$CORE_PEER_TLS_MSPCONFIGPATH/client.key - # local CORE_PEER_TLS_ROOTCERT_FILE=$CORE_PEER_TLS_MSPCONFIGPATH/ca.crt - - local DIR_NAME=step-createChannelAndJoinTls-$CHANNEL_NAME-$CORE_PEER_LOCALMSPID + local DIR_NAME=step-createChannelAndJoinTls-$CHANNEL_NAME-$ORDERER_MSP_NAME echo "Creating channel with name (TLS): ${CHANNEL_NAME}" - echo " Orderer: $ORDERER_URL" - echo " CORE_PEER_LOCALMSPID: $CORE_PEER_LOCALMSPID" - # echo " CORE_PEER_ADDRESS: $CORE_PEER_ADDRESS" - # echo " CORE_PEER_MSPCONFIGPATH: $CORE_PEER_MSPCONFIGPATH" - # echo " TLS_CA_CERT_PATH is: $TLS_CA_CERT_PATH" - # echo " CORE_PEER_TLS_CERT_FILE: $CORE_PEER_TLS_CERT_FILE" - # echo " CORE_PEER_TLS_KEY_FILE: $CORE_PEER_TLS_KEY_FILE" - # echo " CORE_PEER_TLS_ROOTCERT_FILE: $CORE_PEER_TLS_ROOTCERT_FILE" + echo " ORDERER_MSP_NAME: $ORDERER_MSP_NAME" + echo " ORDERER_ADMIN_ADDRESS: $ORDERER_ADMIN_ADDRESS" + echo " ADMIN_TLS_SIGN_CERT: $ADMIN_TLS_SIGN_CERT" + echo " ADMIN_TLS_PRIVATE_KEY: $ADMIN_TLS_PRIVATE_KEY" + echo " TLS_CA_CERT_PATH: $TLS_CA_CERT_PATH" + + if [ ! -d "$DIR_NAME" ]; then + mkdir "$DIR_NAME" + cp /var/hyperledger/cli/config/"$CHANNEL_NAME".pb "$DIR_NAME" + fi + + osnadmin channel join \ + --channelID "${CHANNEL_NAME}" \ + --config-block "$DIR_NAME/$CHANNEL_NAME.pb" \ + -o "${ORDERER_ADMIN_ADDRESS}" \ + --client-cert "${ADMIN_TLS_SIGN_CERT}" \ + --client-key "${ADMIN_TLS_PRIVATE_KEY}" \ + --ca-file "${TLS_CA_CERT_PATH}" - mkdir "$DIR_NAME" && cd "$DIR_NAME" - - - cp /var/hyperledger/cli/config/"$CHANNEL_NAME".pb . - osnadmin channel join --channelID "${CHANNEL_NAME}" --config-block ./"$CHANNEL_NAME".pb -o "${ORDERER_URL}" # --ca-file "${TLS_CA_CERT_PATH}" --client-cert "${ADMIN_SIGN_CERT}" --client-key "${ADMIN_PRIVATE_KEY}" - rm -rf "$DIR_NAME" } From cdb3203d51e51a284d8fd7bdafa17846fff33b7b Mon Sep 17 00:00:00 2001 From: Jakub Dzikowski Date: Sat, 30 Nov 2024 10:19:48 +0100 Subject: [PATCH 05/11] Enable TLS for admin endpoints Signed-off-by: Jakub Dzikowski --- .../templates/fabric-docker/docker-compose.yaml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/setup-docker/templates/fabric-docker/docker-compose.yaml b/src/setup-docker/templates/fabric-docker/docker-compose.yaml index 08413f72..1552ba3a 100755 --- a/src/setup-docker/templates/fabric-docker/docker-compose.yaml +++ b/src/setup-docker/templates/fabric-docker/docker-compose.yaml @@ -189,6 +189,7 @@ services: - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 - ORDERER_GENERAL_LISTENPORT=<%= orderer.port %> - ORDERER_GENERAL_GENESISMETHOD=file + - ORDERER_ADMIN_LISTENADDRESS=<%= orderer.address %>:7053 <%_ if(global.capabilities.isV2) { _%> - ORDERER_GENERAL_BOOTSTRAPFILE=/var/hyperledger/config/<%= ordererGroup.genesisBlockName %> <%_ } else { _%> @@ -203,13 +204,17 @@ services: - ORDERER_METRICS_PROVIDER=prometheus # enabled TLS - ORDERER_GENERAL_TLS_ENABLED=true - - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt + - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] - - ORDERER_ADMIN_LISTENADDRESS=<%= orderer.address %>:7053 + - ORDERER_ADMIN_TLS_ENABLED=true + - ORDERER_ADMIN_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt + - ORDERER_ADMIN_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key + - ORDERER_ADMIN_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] + - ORDERER_ADMIN_TLS_CLIENTROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] <%_ } _%> working_dir: /var/hyperledger/orderer command: orderer From d788ef8fffeab4b874871d7e42223c92e54383ca Mon Sep 17 00:00:00 2001 From: Jakub Dzikowski Date: Sat, 30 Nov 2024 11:14:17 +0100 Subject: [PATCH 06/11] Reorder and fix docker compose variable for orderer Signed-off-by: Jakub Dzikowski --- .../fabric-docker/docker-compose.yaml | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/setup-docker/templates/fabric-docker/docker-compose.yaml b/src/setup-docker/templates/fabric-docker/docker-compose.yaml index 1552ba3a..3b93c52d 100755 --- a/src/setup-docker/templates/fabric-docker/docker-compose.yaml +++ b/src/setup-docker/templates/fabric-docker/docker-compose.yaml @@ -188,34 +188,34 @@ services: - FABRIC_LOGGING_SPEC=${LOGGING_LEVEL} - ORDERER_GENERAL_LISTENADDRESS=0.0.0.0 - ORDERER_GENERAL_LISTENPORT=<%= orderer.port %> - - ORDERER_GENERAL_GENESISMETHOD=file - - ORDERER_ADMIN_LISTENADDRESS=<%= orderer.address %>:7053 - <%_ if(global.capabilities.isV2) { _%> - - ORDERER_GENERAL_BOOTSTRAPFILE=/var/hyperledger/config/<%= ordererGroup.genesisBlockName %> - <%_ } else { _%> - - ORDERER_GENERAL_GENESISFILE=/var/hyperledger/config/<%= ordererGroup.genesisBlockName %> - <%_ } _%> - - ORDERER_GENERAL_LOCALMSPID=<%= org.mspName %> + - ORDERER_GENERAL_LOCALMSPID=<%= orderer.orgMspName %> - ORDERER_GENERAL_LOCALMSPDIR=/var/hyperledger/orderer/msp - - GODEBUG=netdns=go <%_ if(global.tls) { _%> - # metrics - - ORDERER_OPERATIONS_LISTENADDRESS=<%= orderer.address %>:9440 - - ORDERER_METRICS_PROVIDER=prometheus - # enabled TLS + # TLS Configuration - ORDERER_GENERAL_TLS_ENABLED=true - - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt - ORDERER_GENERAL_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key + - ORDERER_GENERAL_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt - ORDERER_GENERAL_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] + # Cluster TLS Configuration - ORDERER_GENERAL_CLUSTER_CLIENTCERTIFICATE=/var/hyperledger/orderer/tls/server.crt - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] + <%_ } _%> + <%_ if(global.capabilities.isV3) { _%> + # V3 specific settings + - ORDERER_GENERAL_BOOTSTRAPMETHOD=none + - ORDERER_CHANNELPARTICIPATION_ENABLED=true + # Admin endpoint configuration - ORDERER_ADMIN_TLS_ENABLED=true - ORDERER_ADMIN_TLS_CERTIFICATE=/var/hyperledger/orderer/tls/server.crt - ORDERER_ADMIN_TLS_PRIVATEKEY=/var/hyperledger/orderer/tls/server.key - ORDERER_ADMIN_TLS_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] - ORDERER_ADMIN_TLS_CLIENTROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] + - ORDERER_ADMIN_LISTENADDRESS=0.0.0.0:<%= orderer.adminPort %> <%_ } _%> + # Metrics configuration + - ORDERER_OPERATIONS_LISTENADDRESS=<%= orderer.address %>:9443 + - ORDERER_METRICS_PROVIDER=prometheus working_dir: /var/hyperledger/orderer command: orderer ports: From f2add14fa8ad7d21cb77addc675f6f9eee24e31b Mon Sep 17 00:00:00 2001 From: Jakub Dzikowski Date: Sat, 30 Nov 2024 11:14:39 +0100 Subject: [PATCH 07/11] Fix identity which remove NOT_FOUND error while fetching the channel Signed-off-by: Jakub Dzikowski --- .../templates/fabric-config/configtx-raft-template.yaml.ejs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup-docker/templates/fabric-config/configtx-raft-template.yaml.ejs b/src/setup-docker/templates/fabric-config/configtx-raft-template.yaml.ejs index 8218b70b..73a4334f 100755 --- a/src/setup-docker/templates/fabric-config/configtx-raft-template.yaml.ejs +++ b/src/setup-docker/templates/fabric-config/configtx-raft-template.yaml.ejs @@ -27,7 +27,7 @@ Host: <%= orderer.address %> Port: <%= orderer.port %> MSPID: <%= orderer.orgMspName %> - Identity: crypto-config/peerOrganizations/<%= orderer.domain %>/peers/<%= orderer.address %>/msp/tlscacerts/tlsca.orderer.example.com-cert.pem + Identity: crypto-config/peerOrganizations/<%= orderer.domain %>/peers/<%= orderer.address %>/msp/signcerts/<%= orderer.address %>-cert.pem ClientTLSCert: crypto-config/peerOrganizations/<%= orderer.domain %>/peers/<%= orderer.address %>/tls/server.crt ServerTLSCert: crypto-config/peerOrganizations/<%= orderer.domain %>/peers/<%= orderer.address %>/tls/server.crt <% })} -%> From 5c8f780a84da828211181ca8079dc25ec9e50013 Mon Sep 17 00:00:00 2001 From: Jakub Dzikowski Date: Sat, 30 Nov 2024 11:15:24 +0100 Subject: [PATCH 08/11] Remove unnecessary sleep Signed-off-by: Jakub Dzikowski --- src/setup-docker/templates/fabric-docker/commands-generated.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/setup-docker/templates/fabric-docker/commands-generated.sh b/src/setup-docker/templates/fabric-docker/commands-generated.sh index 7644abc3..cf717aa6 100644 --- a/src/setup-docker/templates/fabric-docker/commands-generated.sh +++ b/src/setup-docker/templates/fabric-docker/commands-generated.sh @@ -55,7 +55,6 @@ installChannels() { docker exec -i <%= org.cli.address %> bash -c <% -%> "source scripts/channel_fns.sh; createChannelAndJoinTls '<%= channel.name %>' '<%= orderer.orgMspName %>' '<%= orderer.address %>:<%= orderer.adminPort %>' 'crypto/users/Admin@<%= orderer.domain %>/tls/client.crt' 'crypto/users/Admin@<%= orderer.domain %>/tls/client.key' 'crypto-orderer/tlsca.<%= orderer.domain %>-cert.pem';" <% }) -%> - sleep 8 # TODO: remove sleep <% channel.orgs.forEach((org, orgNo) => { -%> <% org.peers.forEach((peer, peerNo) => { -%> <% if (orgNo == 0 && peerNo == 0) { -%> From a7315ce2bcdf3df3ec5ec84f6e3ba9ec97c97cd9 Mon Sep 17 00:00:00 2001 From: Jakub Dzikowski Date: Sat, 30 Nov 2024 11:50:01 +0100 Subject: [PATCH 09/11] Fix docker compose variables for RAFT Signed-off-by: Jakub Dzikowski --- src/setup-docker/templates/fabric-docker/docker-compose.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/setup-docker/templates/fabric-docker/docker-compose.yaml b/src/setup-docker/templates/fabric-docker/docker-compose.yaml index 3b93c52d..405052de 100755 --- a/src/setup-docker/templates/fabric-docker/docker-compose.yaml +++ b/src/setup-docker/templates/fabric-docker/docker-compose.yaml @@ -201,6 +201,11 @@ services: - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] <%_ } _%> + <%_ if(ordererGroup.consensus !== "BFT" && global.capabilities.isV2) { _%> + # Genesis file configuration (for solo and raft) + - ORDERER_GENERAL_GENESISMETHOD=file + - ORDERER_GENERAL_BOOTSTRAPFILE=/var/hyperledger/config/<%= ordererGroup.genesisBlockName %> + <%_ } _%> <%_ if(global.capabilities.isV3) { _%> # V3 specific settings - ORDERER_GENERAL_BOOTSTRAPMETHOD=none From 0b3828c6a5debee014a2b6139cc1e3388407acd0 Mon Sep 17 00:00:00 2001 From: Jakub Dzikowski Date: Sat, 30 Nov 2024 11:50:20 +0100 Subject: [PATCH 10/11] Some polishing and cleanup Signed-off-by: Jakub Dzikowski --- .../templates/fabric-docker/commands-generated.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/setup-docker/templates/fabric-docker/commands-generated.sh b/src/setup-docker/templates/fabric-docker/commands-generated.sh index cf717aa6..15a12d99 100644 --- a/src/setup-docker/templates/fabric-docker/commands-generated.sh +++ b/src/setup-docker/templates/fabric-docker/commands-generated.sh @@ -15,10 +15,8 @@ generateArtifacts() { <%_ ordererGroups.forEach((ordererGroup) => { _%> <% if(!global.capabilities.isV3) {%> - printItalics "Generating genesis block for group <%= ordererGroup.name %>" "U1F3E0" - genesisBlockCreate "$FABLO_NETWORK_ROOT/fabric-config" "$FABLO_NETWORK_ROOT/fabric-config/config" "<%= ordererGroup.profileName %>" - <% } else { %> - echo "System channel not supported for Fabric version 3" + printItalics "Generating genesis block for group <%= ordererGroup.name %>" "U1F3E0" + genesisBlockCreate "$FABLO_NETWORK_ROOT/fabric-config" "$FABLO_NETWORK_ROOT/fabric-config/config" "<%= ordererGroup.profileName %>" <% } %> <%_ }) _%> @@ -44,9 +42,7 @@ generateChannelsArtifacts() { } installChannels() { - set -x <% if (!channels || !channels.length) { -%> - echo "No channels" <% } else if (global.capabilities.isV3) { -%> <% channels.forEach((channel) => { -%> @@ -55,6 +51,9 @@ installChannels() { docker exec -i <%= org.cli.address %> bash -c <% -%> "source scripts/channel_fns.sh; createChannelAndJoinTls '<%= channel.name %>' '<%= orderer.orgMspName %>' '<%= orderer.address %>:<%= orderer.adminPort %>' 'crypto/users/Admin@<%= orderer.domain %>/tls/client.crt' 'crypto/users/Admin@<%= orderer.domain %>/tls/client.key' 'crypto-orderer/tlsca.<%= orderer.domain %>-cert.pem';" <% }) -%> + <% if (channel.ordererGroup.consensus !== "BFT") { -%> + sleep 4 # Wait for Raft cluster to establish consensus + <% } -%> <% channel.orgs.forEach((org, orgNo) => { -%> <% org.peers.forEach((peer, peerNo) => { -%> <% if (orgNo == 0 && peerNo == 0) { -%> From 6cfdd01ffb497a5e69b9735237ea29e2a4afdf69 Mon Sep 17 00:00:00 2001 From: Sanket Teli <104385297+Sanket-0510@users.noreply.github.com> Date: Tue, 3 Dec 2024 11:39:26 +0530 Subject: [PATCH 11/11] Update src/setup-docker/templates/fabric-docker/docker-compose.yaml Signed-off-by: Sanket Teli <104385297+Sanket-0510@users.noreply.github.com> --- src/setup-docker/templates/fabric-docker/docker-compose.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/setup-docker/templates/fabric-docker/docker-compose.yaml b/src/setup-docker/templates/fabric-docker/docker-compose.yaml index 405052de..e26060fd 100755 --- a/src/setup-docker/templates/fabric-docker/docker-compose.yaml +++ b/src/setup-docker/templates/fabric-docker/docker-compose.yaml @@ -201,7 +201,7 @@ services: - ORDERER_GENERAL_CLUSTER_CLIENTPRIVATEKEY=/var/hyperledger/orderer/tls/server.key - ORDERER_GENERAL_CLUSTER_ROOTCAS=[/var/hyperledger/orderer/tls/ca.crt] <%_ } _%> - <%_ if(ordererGroup.consensus !== "BFT" && global.capabilities.isV2) { _%> + <%_ if(global.capabilities.isV2) { _%> # Genesis file configuration (for solo and raft) - ORDERER_GENERAL_GENESISMETHOD=file - ORDERER_GENERAL_BOOTSTRAPFILE=/var/hyperledger/config/<%= ordererGroup.genesisBlockName %>