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

Constellation Using Pivate Transactions in Alastria T

Alejandro Alfonso Fernández edited this page Jan 25, 2021 · 1 revision

Requirements to deploy private smartcontracts in Alastria network

Constellation

Ensure constellation is enabled.

$ ENABLE_CONSTELLATION=true ./start.sh

Also you need to enable https in constellation conf for the hosts whom will process the private transaction.

Ensure all nodes in ~/alastria/data/constellation-nodes.json are https compliant. If not, please update your repo to get last constellation-nodes.json with https active.

Please restart your node with ~/alastria-node/scripts/restart.sh. Latest versión should enable https in constellation that was disabled before.

Once Constellation is running with https you need a few more checks.

It will use port 9000, so ensure your nodes have visible TCP/9000 to the internet in order to comunicate between them.

Check Geth version

Alastria works with geth version 1.7.2-stable, make sure you're on the same version. Quorum version has to be v2.0.2 or higher.

jaci@alastriatest:~/alastria/logs$ geth version
Geth
Version: 1.7.2-stable
Git Commit: 94e1e31eb6a97e08dff4e44a8695dab1252ca3bc
Quorum Version: 2.0.2-Alastria
Architecture: amd64
Network Id: 1
Go Version: go1.9.5
Operating System: linux
GOPATH=/home/jaci/alastria/workspace
GOROOT=/usr/local/go

private-contract.js

We use Private contract in https://github.com/jpmorganchase/quorum-examples/blob/master/examples/7nodes/private-contract.js for our test. It needs some modifications in order to work properly in Alastria network.

2 nodes

Private transactions must be done within 2 different nodes, using the node.key from receiver in the sender node when doing the transaction.

Deploying with truffle, migrations file should look like this.

// File: `./migrations/2_deploy_simplestorage.js`

var SimpleStorage = artifacts.require("SimpleStorage");

module.exports = function(deployer) {
  // Pass 42 to the contract as the first constructor parameter
  deployer.deploy(SimpleStorage, 42, {privateFor: ["YHpqeYn1ELzTC6ryM0UEv/XwipbQUa68PE/Hy3DIABc="]})
};

PrivateFor is the public key from the node you want to send the private transaction to

Yoy can find it at https://github.com/alastria/alastria-node/blob/develop/DIRECTORY_REGULAR.md

REMEMBER that you can't send private transactions from and to your selfnode.

Lets Go

Check your truflle.js to connect your regular node

jaci@alastriatest:~/quorum-test$ cat truffle.js

module.exports = {
  // See <http://truffleframework.com/docs/advanced/configuration>
  // to customize your Truffle configuration!

 networks: {
    development: {
      host: "127.0.0.1",
      port: 22000,
      network_id: "82584648528", // Match Alastria network id
      gas: 4500000,
      gasPrice:0
    }
  }
};

Compile your project with truffle compile.

Unlock the account on the node you'll use to send the transaction

web3.personal.unlockAccount("0xe2af1c06db3d33fa7c65015eb536f338fe87e3aa", "Passw0rd", 15000)

Run truffle migrate and you should see a process like this

jaci@alastriatest:~/quorum-test$ truffle migrate
Using network 'development'.

Running migration: 1_initial_migration.js
  Deploying Migrations...
  ... 0xfb24d195b71af3ec527c5f0522a61f98034557993100289214e3ea689ccda45b
  Migrations: 0xd0637a53e1ac06045b43bf8adce7c67a06bb35cb
Saving successful migration to network...
  ... 0xec4f2932b1edb4aacb5bd0b2d59c8fe5c6aad010eff913df24b3eb7e7e1e0a47
Saving artifacts...
Running migration: 2_deploy_simplestorage.js
  Deploying SimpleStorage...
  ... 0xe9851df7bedf52e68002d59f44721adb5ffdd7ca466a0f91496eaf95ac15a2df
  SimpleStorage: 0x88889e2031389090b4b08081a378bcae678ae52c
Saving successful migration to network...
  ... 0xb1124cb20f85cf8989a77697ef715272ed48cf158275ab5216ddaab6d9064541
Saving artifacts...

On quorum_2018XXXXX.log in your node, you should see a transaction processed with the following information

INFO [11-19|14:48:40] Submitted contract creation              fullhash=0xfb24d195b71af3ec527c5f0522a61f98034557993100289214e3ea689ccda45b to=0xd0637a53e1AC06045B43bf8adCE7c67A06Bb35cb
INFO [11-19|14:48:40] QUORUM-CHECKPOINT                        name=TX-CREATED tx=0xfb24d195b71af3ec527c5f0522a61f98034557993100289214e3ea689ccda45b to=0xd0637a53e1AC06045B43bf8adCE7c67A06Bb35cb
INFO [11-19|14:48:42] Submitted transaction                    fullhash=0xec4f2932b1edb4aacb5bd0b2d59c8fe5c6aad010eff913df24b3eb7e7e1e0a47 recipient=0xd0637a53e1AC06045B43bf8adCE7c67A06Bb35cb
INFO [11-19|14:48:42] QUORUM-CHECKPOINT                        name=TX-CREATED tx=0xec4f2932b1edb4aacb5bd0b2d59c8fe5c6aad010eff913df24b3eb7e7e1e0a47 to=0xd0637a53e1AC06045B43bf8adCE7c67A06Bb35cb
INFO [11-19|14:48:45] sending private tx                       data=608060405234801561001057600080fd5b506040516020806101618339810180604052810190808051906020019092919050505080600081905550506101178061004a6000396000f3006080604052600436106053576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680632a1afcd914605857806360fe47b11460805780636d4ce63c1460aa575b600080fd5b348015606357600080fd5b50606a60d2565b6040518082815260200191505060405180910390f35b348015608b57600080fd5b5060a86004803603810190808035906020019092919050505060d8565b005b34801560b557600080fd5b5060bc60e2565b6040518082815260200191505060405180910390f35b60005481565b8060008190555050565b600080549050905600a165627a7a72305820449a911c4463477d325dfb2b052c224f7a3ab93a5768b2a4c892bc2acfee4a760029000000000000000000000000000000000000000000000000000000000000002a privatefrom= privatefor="[YHpqeYn1ELzTC6ryM0UEv/XwipbQUa68PE/Hy3DIABc=]"
INFO [11-19|14:48:45] sent private tx                          data=d8820eb0caea624026af4892b868328c3ae138da5b913c9c8ceaa5444134f22117f39af9f5e9e4148eaca26df499b1a0286ab9d693a9aeda525846ff5ef5a590                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   privatefrom= privatefor="[YHpqeYn1ELzTC6ryM0UEv/XwipbQUa68PE/Hy3DIABc=]"
INFO [11-19|14:48:45] Submitted contract creation              fullhash=0xe9851df7bedf52e68002d59f44721adb5ffdd7ca466a0f91496eaf95ac15a2df to=0x88889e2031389090b4B08081a378BCae678aE52C
INFO [11-19|14:48:45] QUORUM-CHECKPOINT                        name=TX-CREATED tx=0xe9851df7bedf52e68002d59f44721adb5ffdd7ca466a0f91496eaf95ac15a2df to=0x88889e2031389090b4B08081a378BCae678aE52C
INFO [11-19|14:48:47] Submitted transaction                    fullhash=0xb1124cb20f85cf8989a77697ef715272ed48cf158275ab5216ddaab6d9064541 recipient=0xd0637a53e1AC06045B43bf8adCE7c67A06Bb35cb
INFO [11-19|14:48:47] QUORUM-CHECKPOINT                        name=TX-CREATED tx=0xb1124cb20f85cf8989a77697ef715272ed48cf158275ab5216ddaab6d9064541 to=0xd0637a53e1AC06045B43bf8adCE7c67A06Bb35cb

To check if your transaction was correct, you can verify that the value of the gasUsed in the transaction has to be 0 and v: must be equal to v:37

You can look at the logs in quorum or in blockexplorer