Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Upgrading to newest version of quorum & constellation
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasvo committed Jan 5, 2018
1 parent c76fcaa commit de63e94
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 93 deletions.
18 changes: 8 additions & 10 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@ RUN apt-get update && \
wrk \
zlib1g-dev

RUN wget -q https://github.com/jpmorganchase/constellation/releases/download/v0.0.1-alpha/ubuntu1604.zip && \
unzip ubuntu1604.zip && \
cp ubuntu1604/constellation-node /usr/local/bin && \
RUN wget -q https://github.com/jpmorganchase/constellation/releases/download/v0.2.0/constellation-0.2.0-ubuntu1604.tar.xz && \
tar xfJ constellation-0.2.0-ubuntu1604.tar.xz && \
cp constellation-0.2.0-ubuntu1604/constellation-node /usr/local/bin && \
chmod 0755 /usr/local/bin/constellation-node && \
cp ubuntu1604/constellation-enclave-keygen /usr/local/bin/ && \
chmod 0755 /usr/local/bin/constellation-enclave-keygen && \
rm -rf ubuntu1604.zip ubuntu1604
rm -rf constellation*

ENV GOREL go1.7.3.linux-amd64.tar.gz
ENV PATH $PATH:/usr/local/go/bin
Expand All @@ -33,7 +31,7 @@ RUN wget -q https://storage.googleapis.com/golang/$GOREL && \

RUN git clone https://github.com/jpmorganchase/quorum.git && \
cd quorum && \
git checkout tags/v1.2.0 && \
git checkout tags/v2.0.0 && \
make all && \
cp build/bin/geth /usr/local/bin && \
cp build/bin/bootnode /usr/local/bin && \
Expand All @@ -51,18 +49,18 @@ RUN apt-get update && \
apt-get update && \
apt-get install -y --no-install-recommends \
libdb-dev \
libleveldb-dev \
libsodium-dev \
libtinfo-dev \
solc && \
rm -rf /var/lib/apt/lists/*

# Temporary useful tools
#RUN apt-get update && \
# apt-get install -y iputils-ping net-tools vim
# RUN apt-get update && \
# apt-get install -y iputils-ping net-tools vim

COPY --from=builder \
/usr/local/bin/constellation-node \
/usr/local/bin/constellation-enclave-keygen \
/usr/local/bin/geth \
/usr/local/bin/bootnode \
/usr/local/bin/
Expand Down
6 changes: 2 additions & 4 deletions Nnodes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ The final goal at the end of set-up is for each node to have its own directory t
│   ├── nodekey
│   └── static-nodes.json
├── keys/
│   ├── tma.key
│   ├── tma.pub
│   ├── tm.key
│   └── tm.pub
├── logs/
Expand Down Expand Up @@ -206,10 +204,10 @@ We copy into each node's directory the *genesis.json* and *static-nodes.json* fi
cp genesis.json $qd/genesis.json
cp static-nodes.json $qd/dd/static-nodes.json

Quorum's Constellation needs public/private keypairs to operate. The *tm.pub* key is the address to which "privateFor" transactions should be sent for a node. Quorum provides a utility for generating these keys, and again we use the instance in the Docker image. I believe the *tma.{pub,key}* files are being deprecated, but they are still needed for the time-being.
Quorum's Constellation needs public/private keypairs to operate. The *tm.pub* key is the address to which "privateFor" transactions should be sent for a node. Quorum provides a utility for generating these keys, and again we use the instance in the Docker image.

# Generate Quorum-related keys (used by Constellation)
docker run -u $uid:$gid -v $pwd/$qd:/qdata $image /usr/local/bin/constellation-enclave-keygen /qdata/keys/tm /qdata/keys/tma < /dev/null > /dev/null
docker run -u $uid:$gid -v $pwd/$qd:/qdata $image /usr/local/bin/constellation-node --generatekeys=/qdata/keys/tm < /dev/null > /dev/null
echo 'Node '$n' public key: '`cat $qd/keys/tm.pub`

cp templates/start-node.sh $qd/start-node.sh
Expand Down
2 changes: 1 addition & 1 deletion Nnodes/cleanup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

rm -rf qdata_[0-9] qdata_[0-9][0-9]
rm -f docker-compose.yml
rm -f contract_pri.js contract_pub.js
rm -r contract_pri.js contract_pub.js

# Shouldn't be needed, but just in case:
rm -f static-nodes.json genesis.json
90 changes: 79 additions & 11 deletions Nnodes/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ then
echo "ERROR: There must be more than one node IP address."
exit 1
fi

./cleanup.sh

uid=`id -u`
Expand Down Expand Up @@ -69,11 +69,11 @@ do
qd=qdata_$n

# Generate the node's Enode and key
enode=`docker run -u $uid:$gid -v $pwd/$qd:/qdata $image /usr/local/bin/bootnode -genkey /qdata/dd/nodekey -writeaddress`

docker run -u $uid:$gid -v $pwd/$qd:/qdata $image /usr/local/bin/bootnode -genkey /qdata/dd/nodekey
enode=`docker run -u $uid:$gid -v $pwd/$qd:/qdata $image /usr/local/bin/bootnode --nodekey /qdata/dd/nodekey -writeaddress`
# Add the enode to static-nodes.json
sep=`[[ $n < $nnodes ]] && echo ","`
echo ' "enode://'$enode'@'$ip':30303?discport=0"'$sep >> static-nodes.json
echo ' "enode://'$enode'@'$ip':30303?discport=0&raftport=50400"'$sep >> static-nodes.json

let n++
done
Expand Down Expand Up @@ -156,7 +156,7 @@ do
cp static-nodes.json $qd/dd/static-nodes.json

# Generate Quorum-related keys (used by Constellation)
docker run -u $uid:$gid -v $pwd/$qd:/qdata $image /usr/local/bin/constellation-enclave-keygen /qdata/keys/tm /qdata/keys/tma < /dev/null > /dev/null
docker run -u $uid:$gid -v $pwd/$qd:/qdata $image /usr/local/bin/constellation-node --generatekeys=qdata/keys/tm < /dev/null > /dev/null
echo 'Node '$n' public key: '`cat $qd/keys/tm.pub`

cp templates/start-node.sh $qd/start-node.sh
Expand Down Expand Up @@ -206,13 +206,81 @@ networks:
- subnet: $subnet
EOF


#### Create pre-populated contracts ####################################

echo '[5] Compiling example contracts'
# Private contract - insert Node 2 as the recipient
cat templates/contract_pri.js \
| sed s:_NODEKEY_:`cat qdata_2/keys/tm.pub`:g \
> contract_pri.js
cp templates/contract_pri.sol ./
docker run -u $uid:$gid --rm -v $pwd/:/data/ $image solc -o /data/contract_pri --bin --abi /data/contract_pri.sol < /dev/null > /dev/null
abi=$(<$pwd/contract_pri/simplestorage.abi)
binary=$(<$pwd/contract_pri/simplestorage.bin)
nodekey=$(<qdata_2/keys/tm.pub)
rm -rf contract_pri/ contract_pri.sol
cat > contract_pri.js <<EOF
//
// Create a contract private with the nodes with addresses in toKey
//
var toKeys=["$nodekey"];
a = eth.accounts[0]
web3.eth.defaultAccount = a;
var SimpleContract = eth.contract($abi);
var contract = SimpleContract.new(42, {
from: web3.eth.accounts[0],
data:'0x$binary',
gas: 1000000
},
function(e, contract) {
if (e) {
console.log("err creating contract", e);
} else {
if (!contract.address) {
console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined...");
} else {
console.log("Contract mined! Address: " + contract.address);
console.log(contract);
}
}
});
EOF


# Public contract - no change required
cp templates/contract_pub.js ./
cp templates/contract_pub.sol ./
docker run -u $uid:$gid --rm -v $pwd/:/data/ $image solc -o /data/contract_pub --bin --abi /data/contract_pub.sol < /dev/null > /dev/null
abi=$(<$pwd/contract_pub/simplestorage.abi)
binary=$(<$pwd/contract_pub/simplestorage.bin)
rm -rf contract_pub/ contract_pub.sol
cat > contract_pub.js <<EOF
//
// Create a public contract
//
a = eth.accounts[0]
web3.eth.defaultAccount = a;
var SimpleContract = eth.contract($abi);
var contract = SimpleContract.new(42, {
from: web3.eth.accounts[0],
data:'0x$binary',
gas: 1000000
},
function(e, contract) {
if (e) {
console.log("err creating contract", e);
} else {
if (!contract.address) {
console.log("Contract transaction send: TransactionHash: " + contract.transactionHash + " waiting to be mined...");
} else {
console.log("Contract mined! Address: " + contract.address);
console.log(contract);
}
}
});
EOF



25 changes: 0 additions & 25 deletions Nnodes/templates/contract_pri.js

This file was deleted.

15 changes: 15 additions & 0 deletions Nnodes/templates/contract_pri.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pragma solidity ^0.4.1;

contract simplestorage {
uint public storedData;
function simplestorage(uint initVal) public {
storedData = initVal;
}
function set(uint x) public {
storedData = x;
}
function get() public constant returns (uint retVal) {
return storedData;
}
}

23 changes: 0 additions & 23 deletions Nnodes/templates/contract_pub.js

This file was deleted.

17 changes: 17 additions & 0 deletions Nnodes/templates/contract_pub.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
pragma solidity ^0.4.1;

contract simplestorage {
uint public storedData;

function simplestorage(uint initVal) public {
storedData = initVal;
}

function set(uint x) public {
storedData = x;
}

function get() public constant returns (uint retVal) {
return storedData;
}
}
12 changes: 5 additions & 7 deletions Nnodes/templates/tm.conf
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
url = "http://_NODEIP_:9000/"
port = 9000
socketPath = "/qdata/tm.ipc"
otherNodeUrls = [_NODELIST_]
publicKeyPath = "/qdata/keys/tm.pub"
privateKeyPath = "/qdata/keys/tm.key"
archivalPublicKeyPath = "/qdata/keys/tma.pub"
archivalPrivateKeyPath = "/qdata/keys/tma.key"
storagePath = "/qdata/constellation"
socket = "/qdata/tm.ipc"
othernodes = [_NODELIST_]
publickeys= ["/qdata/keys/tm.pub"]
privatekeys = ["/qdata/keys/tm.key"]
storage = "/qdata/constellation"
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,13 @@ We will demo the following, from Node 1's console.
This is based on using the provided example *setup.sh* file as-is (three nodes).

#### Node 1 geth console

> var abi = [{"constant":true,"inputs":[],"name":"storedData","outputs":[{"name":"","type":"uint256"}],"payable":false,"type":"function"},{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"retVal","type":"uint256"}],"payable":false,"type":"function"},{"inputs":[{"name":"initVal","type":"uint256"}],"type":"constructor"}];
undefined

> loadScript("contract_pub.js")
Contract transaction send: TransactionHash: 0x0e7ff9b609c0ba3a11de9cd4f51389c29dceacbac2f91e294346df86792d8d8f waiting to be mined...
true
Contract mined! Address: 0x1932c48b2bf8102ba33b4a6b545c32236e342f34
[object Object]

> var public = eth.contract(abi).at("0x1932c48b2bf8102ba33b4a6b545c32236e342f34")
undefined
> public.get()
> contract.get()
42

> loadScript("contract_pri.js")
Expand All @@ -92,13 +86,11 @@ This is based on using the provided example *setup.sh* file as-is (three nodes).
Contract mined! Address: 0x1349f3e1b8d71effb47b840594ff27da7e603d17
[object Object]

> var private = eth.contract(abi).at("0x1349f3e1b8d71effb47b840594ff27da7e603d17")
undefined
> private.get()
> contract.get()
42
> private.set(65535, {privateFor: ["QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc="]})
> contract.set(65535, {privateFor: ["QfeDAys9MPDs2XHExtc84jKGHxZg/aj52DTh0vtA3Xc="]})
"0x0dc9c0b85b4c4e5f1e3ba2014b5f628f5153bc2588741a69626eb5a40d2b30d6"
> private.get()
> contract.get()
65535

#### Node 2 geth console
Expand Down

0 comments on commit de63e94

Please sign in to comment.