Skip to content

Commit

Permalink
feat(validator): elections powered by etcd leases
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Somogyvari <peter.somogyvari@accenture.com>
  • Loading branch information
petermetz committed Nov 14, 2019
1 parent 9b369e3 commit c99da7d
Show file tree
Hide file tree
Showing 11 changed files with 1,225 additions and 295 deletions.
7 changes: 2 additions & 5 deletions examples/simple-asset-transfer/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const Validator = require(`@hyperledger-labs/blockchain-integration-framework`).Validator;
const { Validator } = require(`@hyperledger-labs/blockchain-integration-framework`);
const { genKeyFile } = require(`@hyperledger-labs/blockchain-integration-framework`).cryptoUtils;
const ConnectorFabric = require(`./fabric/connector`);
const ConnectorQuorum = require(`./quorum/connector`);
Expand All @@ -7,14 +7,11 @@ const ConnectorCorda = require(`./corda/connector`);
(async () => {
const keypair = await genKeyFile(`/federation/keypair`);
const validatorOptions = {
etcdHosts: process.env.ETCD_HOSTS.split(','),
clientRepAddr: process.env.CLIENT_REP_ADDR,
pubAddr: process.env.PUB_ADDR,
repAddr: process.env.REP_ADDR,
leaderPubAddr: process.env.LEAD_PUB_ADDR,
leaderRepAddr: process.env.LEAD_REP_ADDR,
leaderClientRepAddr: process.env.LEAD_CLIENT_REP_ADDR,
dlType: process.env.DLT_TYPE,
type: process.env.TYPE,
pubKey: keypair.pk,
privKey: keypair.sk,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ services:
fabric_validator1:
image: "federation/validator"
environment:
ETCD_HOSTS: "http://etcd1:2379,http://etcd2:2379,http://etcd3:2379"
CLIENT_REP_ADDR: "tcp://172.20.0.5:7001"
PUB_ADDR: "tcp://172.20.0.5:3001"
REP_ADDR: "tcp://172.20.0.5:5001"
Expand All @@ -33,18 +34,20 @@ services:
- "3001:3001"
- "5001:5001"
- "9001:9001"

depends_on:
- etcd1
- etcd2
- etcd3

fabric_validator2:
image: "federation/validator"
environment:
ETCD_HOSTS: "http://etcd1:2379,http://etcd2:2379,http://etcd3:2379"
CLIENT_REP_ADDR: "tcp://172.20.0.6:7002"
PUB_ADDR: "tcp://172.20.0.6:3002"
REP_ADDR: "tcp://172.20.0.6:5002"
USER_NAME: "Mike"
ORG_NAME: "Org1"
LEAD_PUB_ADDR: "tcp://172.20.0.5:3001"
LEAD_REP_ADDR: "tcp://172.20.0.5:5001"
LEAD_CLIENT_REP_ADDR: "tcp://172.20.0.5:7001"
URL: "http://172.20.0.1:4000"
PEER_NAME: "peer1.org1.example.com"
DLT_TYPE: "FABRIC"
Expand All @@ -62,19 +65,19 @@ services:
fabric-network:
ipv4_address: 172.20.0.6
depends_on:
- "fabric_validator1"
- etcd1
- etcd2
- etcd3

fabric_validator3:
image: "federation/validator"
environment:
ETCD_HOSTS: "http://etcd1:2379,http://etcd2:2379,http://etcd3:2379"
CLIENT_REP_ADDR: "tcp://172.20.0.7:7003"
PUB_ADDR: "tcp://172.20.0.7:3003"
REP_ADDR: "tcp://172.20.0.7:5003"
USER_NAME: "Hugo"
ORG_NAME: "Org2"
LEAD_PUB_ADDR: "tcp://172.20.0.5:3001"
LEAD_REP_ADDR: "tcp://172.20.0.5:5001"
LEAD_CLIENT_REP_ADDR: "tcp://172.20.0.5:7001"
URL: "http://172.20.0.1:4000"
PEER_NAME: "peer0.org2.example.com"
TYPE: "FOLLOWER"
Expand All @@ -92,19 +95,19 @@ services:
fabric-network:
ipv4_address: 172.20.0.7
depends_on:
- "fabric_validator1"
- etcd1
- etcd2
- etcd3

fabric_validator4:
image: "federation/validator"
environment:
ETCD_HOSTS: "http://etcd1:2379,http://etcd2:2379,http://etcd3:2379"
CLIENT_REP_ADDR: "tcp://172.20.0.8:7004"
PUB_ADDR: "tcp://172.20.0.8:3004"
REP_ADDR: "tcp://172.20.0.8:5004"
USER_NAME: "Luca"
ORG_NAME: "Org2"
LEAD_PUB_ADDR: "tcp://172.20.0.5:3001"
LEAD_REP_ADDR: "tcp://172.20.0.5:5001"
LEAD_CLIENT_REP_ADDR: "tcp://172.20.0.5:7001"
URL: "http://172.20.0.1:4000"
PEER_NAME: "peer1.org2.example.com"
DLT_TYPE: "FABRIC"
Expand All @@ -122,4 +125,54 @@ services:
fabric-network:
ipv4_address: 172.20.0.8
depends_on:
- "fabric_validator1"
- etcd1
- etcd2
- etcd3

etcd1:
image: bitnami/etcd:3
environment:
- ALLOW_NONE_AUTHENTICATION=yes
- ETCD_NAME=etcd1
- ETCD_INITIAL_ADVERTISE_PEER_URLS=http://etcd1:2380
- ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380
- ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
- ETCD_ADVERTISE_CLIENT_URLS=http://etcd1:2379
- ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster
- ETCD_INITIAL_CLUSTER=etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380
- ETCD_INITIAL_CLUSTER_STATE=new
networks:
fabric-network:
ipv4_address: 172.20.0.50

etcd2:
image: bitnami/etcd:3
environment:
- ALLOW_NONE_AUTHENTICATION=yes
- ETCD_NAME=etcd2
- ETCD_INITIAL_ADVERTISE_PEER_URLS=http://etcd2:2380
- ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380
- ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
- ETCD_ADVERTISE_CLIENT_URLS=http://etcd2:2379
- ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster
- ETCD_INITIAL_CLUSTER=etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380
- ETCD_INITIAL_CLUSTER_STATE=new
networks:
fabric-network:
ipv4_address: 172.20.0.51

etcd3:
image: bitnami/etcd:3
environment:
- ALLOW_NONE_AUTHENTICATION=yes
- ETCD_NAME=etcd3
- ETCD_INITIAL_ADVERTISE_PEER_URLS=http://etcd3:2380
- ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380
- ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
- ETCD_ADVERTISE_CLIENT_URLS=http://etcd3:2379
- ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster
- ETCD_INITIAL_CLUSTER=etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380
- ETCD_INITIAL_CLUSTER_STATE=new
networks:
fabric-network:
ipv4_address: 172.20.0.52
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ services:
quorum_validator1:
image: "federation/validator"
environment:
ETCD_HOSTS: "http://etcd1:2379,http://etcd2:2379,http://etcd3:2379"
CLIENT_REP_ADDR: "tcp://192.20.0.2:7005"
PUB_ADDR: "tcp://192.20.0.2:3005"
REP_ADDR: "tcp://192.20.0.2:5005"
URL: "http://192.20.0.1:5050"
USER_NAME: "test"
PASSWORD: "A665A45920422F9D417E4867EFDC4FB8A04A1F3FFF1FA07E998E86F7F7A27AE3"
DLT_TYPE: "QUORUM"
TYPE: "LEADER"
API_PORT: 9005
mem_limit: 6g
networks:
Expand All @@ -32,21 +32,22 @@ services:
- "3005:3005"
- "5005:5005"
- "9005:9005"

depends_on:
- etcd1
- etcd2
- etcd3

quorum_validator2:
image: "federation/validator"
environment:
ETCD_HOSTS: "http://etcd1:2379,http://etcd2:2379,http://etcd3:2379"
CLIENT_REP_ADDR: "tcp://192.20.0.3:7006"
PUB_ADDR: "tcp://192.20.0.3:3006"
REP_ADDR: "tcp://192.20.0.3:5006"
LEAD_PUB_ADDR: "tcp://192.20.0.2:3005"
LEAD_REP_ADDR: "tcp://192.20.0.2:5005"
USER_NAME: "test"
PASSWORD: "A665A45920422F9D417E4867EFDC4FB8A04A1F3FFF1FA07E998E86F7F7A27AE3"
LEAD_CLIENT_REP_ADDR: "tcp://192.20.0.2:7005"
URL: "http://192.20.0.1:5051"
DLT_TYPE: "QUORUM"
TYPE: "FOLLOWER"
API_PORT: 9006
mem_limit: 6g
expose:
Expand All @@ -60,21 +61,20 @@ services:
quorum-network:
ipv4_address: 192.20.0.3
depends_on:
- "quorum_validator1"
- etcd1
- etcd2
- etcd3

quorum_validator3:
image: "federation/validator"
environment:
ETCD_HOSTS: "http://etcd1:2379,http://etcd2:2379,http://etcd3:2379"
CLIENT_REP_ADDR: "tcp://192.20.0.4:7007"
PUB_ADDR: "tcp://192.20.0.4:3007"
REP_ADDR: "tcp://192.20.0.4:5007"
LEAD_PUB_ADDR: "tcp://192.20.0.2:3005"
LEAD_REP_ADDR: "tcp://192.20.0.2:5005"
USER_NAME: "test"
PASSWORD: "A665A45920422F9D417E4867EFDC4FB8A04A1F3FFF1FA07E998E86F7F7A27AE3"
LEAD_CLIENT_REP_ADDR: "tcp://192.20.0.2:7005"
URL: "http://192.20.0.1:5052"
TYPE: "FOLLOWER"
DLT_TYPE: "QUORUM"
API_PORT: 9007
mem_limit: 6g
Expand All @@ -89,22 +89,21 @@ services:
quorum-network:
ipv4_address: 192.20.0.4
depends_on:
- "quorum_validator1"
- etcd1
- etcd2
- etcd3

quorum_validator4:
image: "federation/validator"
environment:
ETCD_HOSTS: "http://etcd1:2379,http://etcd2:2379,http://etcd3:2379"
CLIENT_REP_ADDR: "tcp://192.20.0.5:7008"
PUB_ADDR: "tcp://192.20.0.5:3008"
REP_ADDR: "tcp://192.20.0.5:5008"
LEAD_PUB_ADDR: "tcp://192.20.0.2:3005"
LEAD_REP_ADDR: "tcp://192.20.0.2:5005"
USER_NAME: "test"
PASSWORD: "A665A45920422F9D417E4867EFDC4FB8A04A1F3FFF1FA07E998E86F7F7A27AE3"
LEAD_CLIENT_REP_ADDR: "tcp://192.20.0.2:7005"
URL: "http://192.20.0.1:5053"
DLT_TYPE: "QUORUM"
TYPE: "FOLLOWER"
API_PORT: 9008
mem_limit: 6g
expose:
Expand All @@ -118,4 +117,54 @@ services:
quorum-network:
ipv4_address: 192.20.0.5
depends_on:
- "quorum_validator1"
- etcd1
- etcd2
- etcd3

etcd1:
image: bitnami/etcd:3
environment:
- ALLOW_NONE_AUTHENTICATION=yes
- ETCD_NAME=etcd1
- ETCD_INITIAL_ADVERTISE_PEER_URLS=http://etcd1:2380
- ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380
- ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
- ETCD_ADVERTISE_CLIENT_URLS=http://etcd1:2379
- ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster
- ETCD_INITIAL_CLUSTER=etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380
- ETCD_INITIAL_CLUSTER_STATE=new
networks:
fabric-network:
ipv4_address: 192.20.0.50

etcd2:
image: bitnami/etcd:3
environment:
- ALLOW_NONE_AUTHENTICATION=yes
- ETCD_NAME=etcd2
- ETCD_INITIAL_ADVERTISE_PEER_URLS=http://etcd2:2380
- ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380
- ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
- ETCD_ADVERTISE_CLIENT_URLS=http://etcd2:2379
- ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster
- ETCD_INITIAL_CLUSTER=etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380
- ETCD_INITIAL_CLUSTER_STATE=new
networks:
fabric-network:
ipv4_address: 192.20.0.51

etcd3:
image: bitnami/etcd:3
environment:
- ALLOW_NONE_AUTHENTICATION=yes
- ETCD_NAME=etcd3
- ETCD_INITIAL_ADVERTISE_PEER_URLS=http://etcd3:2380
- ETCD_LISTEN_PEER_URLS=http://0.0.0.0:2380
- ETCD_LISTEN_CLIENT_URLS=http://0.0.0.0:2379
- ETCD_ADVERTISE_CLIENT_URLS=http://etcd3:2379
- ETCD_INITIAL_CLUSTER_TOKEN=etcd-cluster
- ETCD_INITIAL_CLUSTER=etcd1=http://etcd1:2380,etcd2=http://etcd2:2380,etcd3=http://etcd3:2380
- ETCD_INITIAL_CLUSTER_STATE=new
networks:
fabric-network:
ipv4_address: 192.20.0.52
Loading

0 comments on commit c99da7d

Please sign in to comment.