Allow separate deployments (#183)

* allow setting of environment vars to determine whether rules contracts are redeployed

Signed-off-by: Sally MacFarlane <sally.macfarlane@consensys.net>
pull/184/head
Sally MacFarlane 4 years ago committed by GitHub
parent ab01084a55
commit b66c431719
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      README.md
  2. 6
      migrations/2_deploy_admin_contract.js
  3. 6
      migrations/3_deploy_node_ingress_rules_contract.js
  4. 6
      migrations/4_deploy_account_ingress_rules_contract.js
  5. 31
      scripts/allowlist_utils.js

@ -62,18 +62,21 @@ This is the easiest way to get started for development with the permissioning Da
### Deploying the contracts
1. The [Besu documentation](https://besu.hyperledger.org/en/stable/Tutorials/Permissioning/Getting-Started-Onchain-Permissioning/)
describes how to use the contracts for onchain permissioning with Besu, including setting environment variables.
2. The following additional environment variables are optional and can be used to permit accounts and nodes during initial contract deployment
1. The following additional environment variables are optional and can be used to prevent redeployment of rules contracts. If set to true, that contract will not be redeployed and current list data will be preserved. If absent or not set to `true`, the specified contract will be redeployed. This allows you, for instance, to retain the Admin contract while redeploying NodeRules and AccountRules, or any other combination.
- `RETAIN_ADMIN_CONTRACT=true`
- `RETAIN_NODE_RULES_CONTRACT=true`
- `RETAIN_ACCOUNT_RULES_CONTRACT=true`
1. The following additional environment variables are optional and can be used to permit accounts and nodes during initial contract deployment
- `INITIAL_ADMIN_ACCOUNTS`: The admin account addresses. Comma-separated multiple addresses can be specified
- `INITIAL_ALLOWLISTED_ACCOUNTS`: The permitted account addresses. Comma-separated multiple addresses can be specified
- `INITIAL_ALLOWLISTED_NODES`: The enode URLs of permitted nodes. Comma-separated multiple nodes can be specified
3. If this is the first time setting up the project, run `yarn install` to initialize project dependencies, otherwise skip this step
4. With these environment variables provided run `truffle migrate --reset` to deploy the contracts
1. If this is the first time setting up the project, run `yarn install` to initialize project dependencies, otherwise skip this step
1. With these environment variables provided run `truffle migrate --reset` to deploy the contracts
### Deploying the Dapp
1. Obtain the most recent release (tarball or zip) from the [projects release page](https://github.com/PegaSysEng/permissioning-smart-contracts/releases/latest)
2. Unpack the distribution into a folder that will be available to your webserver
3. Add to the root of that folder a file `config.json` with the following contents
1. Unpack the distribution into a folder that will be available to your webserver
1. Add to the root of that folder a file `config.json` with the following contents
_Note: The `networkID` is defined as the `chainID` in the genesis file._
```
@ -83,4 +86,4 @@ _Note: The `networkID` is defined as the `chainID` in the genesis file._
"networkId": "<ID of your ethereum network>"
}
```
4. Use a webserver of your choice to host the contents of the folder as static files directing root requests to `index.html`
1. Use a webserver of your choice to host the contents of the folder as static files directing root requests to `index.html`

@ -3,6 +3,12 @@ const AllowlistUtils = require('../scripts/allowlist_utils');
const Admin = artifacts.require("./Admin.sol");
module.exports = async(deployer, network) => {
// exit early if we are NOT redeploying this contract
let retainCurrentRulesContract = AllowlistUtils.getRetainAdminContract();
if (retainCurrentRulesContract) {
console.log("not deploying Admin Rules because retain=" + retainCurrentRulesContract);
return;
}
await deployer.deploy(Admin);
console.log(" > Admin contract deployed with address = " + Admin.address);

@ -10,8 +10,14 @@ const rulesContractName = Web3Utils.utf8ToHex("rules");
/* The address of the node ingress contract if pre deployed */
let nodeIngress = process.env.NODE_INGRESS_CONTRACT_ADDRESS;
let retainCurrentRulesContract = AllowlistUtils.getRetainNodeRulesContract();
module.exports = async(deployer, network) => {
// exit early if we are NOT redeploying this contract
if (retainCurrentRulesContract) {
console.log("not deploying NodeRules because retain=" + retainCurrentRulesContract);
return;
}
if (! nodeIngress) {
// Only deploy if we haven't been provided a predeployed address
await deployer.deploy(NodeIngress);

@ -10,8 +10,14 @@ const rulesContractName = Web3Utils.utf8ToHex("rules");
/* The address of the account ingress contract if pre deployed */
let accountIngress = process.env.ACCOUNT_INGRESS_CONTRACT_ADDRESS;
let retainCurrentRulesContract = AllowlistUtils.getRetainAccountRulesContract();
module.exports = async(deployer, network) => {
// exit early if we are NOT redeploying this contract
if (retainCurrentRulesContract) {
console.log("not deploying AccountRules because retain=" + retainCurrentRulesContract);
return;
}
if (! accountIngress) {
// Only deploy if we haven't been provided a predeployed address
await deployer.deploy(AccountIngress);

@ -135,6 +135,32 @@ function getAccounts(accounts) {
return [];
}
function getRetainAdminContract() {
if (process.env.RETAIN_ADMIN_CONTRACT) {
return process.env.RETAIN_ADMIN_CONTRACT.toLowerCase === 'true';
} else {
return false;
}
}
function getRetainNodeRulesContract() {
if (process.env.RETAIN_NODE_RULES_CONTRACT) {
return process.env.RETAIN_NODE_RULES_CONTRACT.toLowerCase === 'true';
} else {
return false;
}
}
function getRetainAccountRulesContract() {
if (process.env.RETAIN_ACCOUNT_RULES_CONTRACT) {
return process.env.RETAIN_ACCOUNT_RULES_CONTRACT.toLowerCase === 'true';
} else {
return false;
}
}
function getHexIpv4(stringIp) {
const splitIp = stringIp.split(".");
@ -155,5 +181,8 @@ module.exports = {
isInitialAllowlistedNodesAvailable,
getInitialAdminAccounts,
getInitialAllowlistedAccounts,
getInitialAllowlistedNodes
getInitialAllowlistedNodes,
getRetainAdminContract,
getRetainNodeRulesContract,
getRetainAccountRulesContract
}
Loading…
Cancel
Save