Skip to content

Commit

Permalink
merged BFT support with version 3
Browse files Browse the repository at this point in the history
Signed-off-by: Sanket Teli <telisanket2002@gmail.com>
  • Loading branch information
Sanket-0510 committed Dec 3, 2024
2 parents b46833b + f953b52 commit 658e041
Show file tree
Hide file tree
Showing 10 changed files with 227 additions and 46 deletions.
3 changes: 2 additions & 1 deletion docs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
84 changes: 84 additions & 0 deletions e2e-network/docker/test-05-version3-BFT.sh
Original file line number Diff line number Diff line change
@@ -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/samples/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! 🎉"
2 changes: 1 addition & 1 deletion samples/fablo-config-hlf3-1orgs-1chaincode.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
{
"groupName": "group1",
"type": "raft",
"instances": 3
"instances": 4
}
]
},
Expand Down
60 changes: 60 additions & 0 deletions samples/fablo-config-hlf3-bft-1orgs-1chaincode.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,28 @@
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:
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 %>
Port: <%= orderer.port %>
MSPID: <%= orderer.orgMspName %>
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
<% })} -%>
12 changes: 6 additions & 6 deletions src/setup-docker/templates/fabric-docker/commands-generated.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>"
<% } %>
<%_ }) _%>
Expand Down Expand Up @@ -53,9 +51,11 @@ 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
<% 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) { -%>
Expand Down
36 changes: 23 additions & 13 deletions src/setup-docker/templates/fabric-docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -188,29 +188,39 @@ services:
- FABRIC_LOGGING_SPEC=${LOGGING_LEVEL}
- ORDERER_GENERAL_LISTENADDRESS=0.0.0.0
- ORDERER_GENERAL_LISTENPORT=<%= orderer.port %>
- ORDERER_GENERAL_GENESISMETHOD=file
<%_ 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_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]
- ORDERER_ADMIN_LISTENADDRESS=<%= orderer.address %>:7053
<%_ } _%>
<%_ if(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
- 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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +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 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_ADDRESS
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"
}

Expand Down
2 changes: 1 addition & 1 deletion src/types/FabloConfigExtended.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/types/FabloConfigJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface CAJson {
export interface OrdererJson {
groupName: string;
prefix: string;
type: "solo" | "raft";
type: "solo" | "raft" | "BFT";
instances: number;
}

Expand Down

0 comments on commit 658e041

Please sign in to comment.