Skip to content

Commit 63bb228

Browse files
authored
test-network: Add support for using BFT consensus with CA (#1301)
Signed-off-by: Tatsuya Sato <tatsuya.sato.so@hitachi.com>
1 parent 5e91d36 commit 63bb228

File tree

7 files changed

+48
-41
lines changed

7 files changed

+48
-41
lines changed

.github/workflows/test-network-bft-orderer.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jobs:
2525
- javascript
2626
- typescript
2727
- java
28+
crypto:
29+
- cryptogen
30+
- ca
2831

2932
steps:
3033
- name: Checkout
@@ -43,3 +46,4 @@ jobs:
4346
env:
4447
CHAINCODE_LANGUAGE: ${{ matrix.chaincode-language }}
4548
ORDERER_TYPE: bft
49+
CRYPTO: ${{ matrix.crypto }}

ci/scripts/run-test-network-basic.sh

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ set -euo pipefail
55
CHAINCODE_LANGUAGE=${CHAINCODE_LANGUAGE:-go}
66
CHAINCODE_PATH=${CHAINCODE_PATH:-../asset-transfer-basic}
77
ORDERER_TYPE=${ORDERER_TYPE:-raft}
8+
CRYPTO=${CRYPTO:-ca}
9+
10+
CRYPTO_OPTION=""
11+
if [ "$CRYPTO" == "ca" ]; then
12+
CRYPTO_OPTION="-ca"
13+
fi
814

915
function print() {
1016
GREEN='\033[0;32m'
@@ -15,15 +21,15 @@ function print() {
1521

1622
function createNetworkWithRaft() {
1723
print "Creating 3 Org network with Raft Orderers"
18-
./network.sh up createChannel -ca -s couchdb
24+
./network.sh up createChannel ${CRYPTO_OPTION} -s couchdb
1925
cd addOrg3
20-
./addOrg3.sh up -ca -s couchdb
26+
./addOrg3.sh up ${CRYPTO_OPTION} -s couchdb
2127
cd ..
2228
}
2329

2430
function createNetworkWithBFT() {
2531
print "Creating 2 Org network with BFT Orderers"
26-
./network.sh up createChannel -bft
32+
./network.sh up createChannel -bft ${CRYPTO_OPTION}
2733
}
2834

2935
function createNetwork() {

test-network/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
organizations/fabric-ca/ordererOrg/*
99
organizations/fabric-ca/org1/*
1010
organizations/fabric-ca/org2/*
11+
addOrg3/fabric-ca/org3/*
1112
organizations/ordererOrganizations/*
1213
organizations/peerOrganizations/*
1314
system-genesis-block/*

test-network/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
You can use the `./network.sh` script to stand up a simple Fabric test network. The test network has two peer organizations with one peer each and a single node raft ordering service. You can also use the `./network.sh` script to create channels and deploy chaincode. For more information, see [Using the Fabric test network](https://hyperledger-fabric.readthedocs.io/en/latest/test_network.html). The test network is being introduced in Fabric v2.0 as the long term replacement for the `first-network` sample.
44

5-
If you are planning to run the test network with consensus type BFT then please pass `-bft` flag as input to the `network.sh` script when creating the channel. Note that currently this sample does not yet support the use of consensus type BFT and CA together.
5+
If you are planning to run the test network with consensus type BFT then please pass `-bft` flag as input to the `network.sh` script when creating the channel. This sample also supports the use of consensus type BFT and CA together.
66
That is to create a network use:
77
```bash
88
./network.sh up -bft

test-network/network.sh

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -619,11 +619,6 @@ while [[ $# -ge 1 ]] ; do
619619
shift
620620
done
621621

622-
## Check if user attempts to use BFT orderer and CA together
623-
if [[ $BFT -eq 1 && "$CRYPTO" == "Certificate Authorities" ]]; then
624-
fatalln "This sample does not yet support the use of consensus type BFT and CA together."
625-
fi
626-
627622
if [ $BFT -eq 1 ]; then
628623
export FABRIC_CFG_PATH=${PWD}/bft-config
629624
COMPOSE_FILE_BASE=compose-bft-test-net.yaml

test-network/organizations/fabric-ca/registerEnroll.sh

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -207,37 +207,44 @@ function createOrderer() {
207207
mkdir -p "${PWD}/organizations/ordererOrganizations/example.com/tlsca"
208208
cp "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem" "${PWD}/organizations/ordererOrganizations/example.com/tlsca/tlsca.example.com-cert.pem"
209209

210-
infoln "Registering orderer"
211-
set -x
212-
fabric-ca-client register --caname ca-orderer --id.name orderer --id.secret ordererpw --id.type orderer --tls.certfiles "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem"
213-
{ set +x; } 2>/dev/null
214-
210+
# Loop through each orderer (orderer, orderer2, orderer3, orderer4) to register and generate artifacts
211+
for ORDERER in orderer orderer2 orderer3 orderer4; do
212+
infoln "Registering ${ORDERER}"
213+
set -x
214+
fabric-ca-client register --caname ca-orderer --id.name ${ORDERER} --id.secret ${ORDERER}pw --id.type orderer --tls.certfiles "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem"
215+
{ set +x; } 2>/dev/null
216+
217+
infoln "Generating the ${ORDERER} MSP"
218+
set -x
219+
fabric-ca-client enroll -u https://${ORDERER}:${ORDERER}pw@localhost:9054 --caname ca-orderer -M "${PWD}/organizations/ordererOrganizations/example.com/orderers/${ORDERER}.example.com/msp" --tls.certfiles "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem"
220+
{ set +x; } 2>/dev/null
221+
222+
cp "${PWD}/organizations/ordererOrganizations/example.com/msp/config.yaml" "${PWD}/organizations/ordererOrganizations/example.com/orderers/${ORDERER}.example.com/msp/config.yaml"
223+
224+
# Workaround: Rename the signcert file to ensure consistency with Cryptogen generated artifacts
225+
mv "${PWD}/organizations/ordererOrganizations/example.com/orderers/${ORDERER}.example.com/msp/signcerts/cert.pem" "${PWD}/organizations/ordererOrganizations/example.com/orderers/${ORDERER}.example.com/msp/signcerts/${ORDERER}.example.com-cert.pem"
226+
227+
infoln "Generating the ${ORDERER} TLS certificates, use --csr.hosts to specify Subject Alternative Names"
228+
set -x
229+
fabric-ca-client enroll -u https://${ORDERER}:${ORDERER}pw@localhost:9054 --caname ca-orderer -M "${PWD}/organizations/ordererOrganizations/example.com/orderers/${ORDERER}.example.com/tls" --enrollment.profile tls --csr.hosts ${ORDERER}.example.com --csr.hosts localhost --tls.certfiles "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem"
230+
{ set +x; } 2>/dev/null
231+
232+
# Copy the tls CA cert, server cert, server keystore to well known file names in the orderer's tls directory that are referenced by orderer startup config
233+
cp "${PWD}/organizations/ordererOrganizations/example.com/orderers/${ORDERER}.example.com/tls/tlscacerts/"* "${PWD}/organizations/ordererOrganizations/example.com/orderers/${ORDERER}.example.com/tls/ca.crt"
234+
cp "${PWD}/organizations/ordererOrganizations/example.com/orderers/${ORDERER}.example.com/tls/signcerts/"* "${PWD}/organizations/ordererOrganizations/example.com/orderers/${ORDERER}.example.com/tls/server.crt"
235+
cp "${PWD}/organizations/ordererOrganizations/example.com/orderers/${ORDERER}.example.com/tls/keystore/"* "${PWD}/organizations/ordererOrganizations/example.com/orderers/${ORDERER}.example.com/tls/server.key"
236+
237+
# Copy orderer org's CA cert to orderer's /msp/tlscacerts directory (for use in the orderer MSP definition)
238+
mkdir -p "${PWD}/organizations/ordererOrganizations/example.com/orderers/${ORDERER}.example.com/msp/tlscacerts"
239+
cp "${PWD}/organizations/ordererOrganizations/example.com/orderers/${ORDERER}.example.com/tls/tlscacerts/"* "${PWD}/organizations/ordererOrganizations/example.com/orderers/${ORDERER}.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
240+
done
241+
242+
# Register and generate artifacts for the orderer admin
215243
infoln "Registering the orderer admin"
216244
set -x
217245
fabric-ca-client register --caname ca-orderer --id.name ordererAdmin --id.secret ordererAdminpw --id.type admin --tls.certfiles "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem"
218246
{ set +x; } 2>/dev/null
219247

220-
infoln "Generating the orderer msp"
221-
set -x
222-
fabric-ca-client enroll -u https://orderer:ordererpw@localhost:9054 --caname ca-orderer -M "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp" --tls.certfiles "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem"
223-
{ set +x; } 2>/dev/null
224-
225-
cp "${PWD}/organizations/ordererOrganizations/example.com/msp/config.yaml" "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/config.yaml"
226-
227-
infoln "Generating the orderer-tls certificates, use --csr.hosts to specify Subject Alternative Names"
228-
set -x
229-
fabric-ca-client enroll -u https://orderer:ordererpw@localhost:9054 --caname ca-orderer -M "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls" --enrollment.profile tls --csr.hosts orderer.example.com --csr.hosts localhost --tls.certfiles "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem"
230-
{ set +x; } 2>/dev/null
231-
232-
# Copy the tls CA cert, server cert, server keystore to well known file names in the orderer's tls directory that are referenced by orderer startup config
233-
cp "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/tlscacerts/"* "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/ca.crt"
234-
cp "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/signcerts/"* "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.crt"
235-
cp "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/keystore/"* "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/server.key"
236-
237-
# Copy orderer org's CA cert to orderer's /msp/tlscacerts directory (for use in the orderer MSP definition)
238-
mkdir -p "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts"
239-
cp "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/tls/tlscacerts/"* "${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem"
240-
241248
infoln "Generating the admin msp"
242249
set -x
243250
fabric-ca-client enroll -u https://ordererAdmin:ordererAdminpw@localhost:9054 --caname ca-orderer -M "${PWD}/organizations/ordererOrganizations/example.com/users/Admin@example.com/msp" --tls.certfiles "${PWD}/organizations/fabric-ca/ordererOrg/ca-cert.pem"

test-network/scripts/createChannel.sh

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,6 @@ setAnchorPeer() {
9595
. scripts/setAnchorPeer.sh $ORG $CHANNEL_NAME
9696
}
9797

98-
99-
## User attempts to use BFT orderer in Fabric network with CA
100-
if [ $BFT -eq 1 ] && [ -d "organizations/fabric-ca/ordererOrg/msp" ]; then
101-
fatalln "Fabric network seems to be using CA. This sample does not yet support the use of consensus type BFT and CA together."
102-
fi
103-
10498
## Create channel genesis block
10599
FABRIC_CFG_PATH=$PWD/../config/
106100
BLOCKFILE="./channel-artifacts/${CHANNEL_NAME}.block"

0 commit comments

Comments
 (0)