Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Fix) Add keeping of RewardByBlock and VotingToManageEmissionFunds addresses to ProxyStorage #143

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 30 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,55 @@ Select `0.4.24` Solidity compiler version. Set `Optimize` to `true`.

Compile and deploy contracts in the next sequence:

- `ProxyStorage_flat.sol` - Select contract `ProxyStorage`.
- `EternalStorageProxy_flat.sol` - Select contract `EternalStorageProxy` with constructor parameters: <br />
- `ProxyStorage_flat.sol` - Deploy `ProxyStorage` contract.
- `EternalStorageProxy_flat.sol` - Deploy `EternalStorageProxy` contract with constructor parameters: <br />
`_proxyStorage` - equal to zero,
`_implementationAddress` - address of ProxyStorage contract.
- Make a call to `ProxyStorage init` with `_poaConsensus` parameter equal to the address of poaConsensus contract, using the address of `EternalStorageProxy` and ABI of `ProxyStorage`.
- Select `poaNetworkConsensus` contract and send transaction `setProxyStorage` with the address of ProxyStorage contract.
- `KeysManager_flat.sol` - Select contract `KeysManager`.
- `EternalStorageProxy_flat.sol` - Select contract `EternalStorageProxy` with constructor parameters: <br />
- Make a call to `ProxyStorage init` with `_poaConsensus` parameter equal to the address of PoaNetworkConsensus contract, using the address of `EternalStorageProxy` and ABI of `ProxyStorage`.
- Select `PoaNetworkConsensus` contract and call `setProxyStorage` with the address of ProxyStorage contract.
- `KeysManager_flat.sol` - Deploy `KeysManager` contract.
- `EternalStorageProxy_flat.sol` - Deploy `EternalStorageProxy` contract with constructor parameters: <br />
`_proxyStorage` - address of ProxyStorage contract,
`_implementationAddress` - address of KeysManager contract.
- Make a call to `KeysManager init` with `_previousKeysManager` parameter equal to 0x0000000000000000000000000000000000000000, using the address of `EternalStorageProxy` and ABI of `KeysManager`.
- `BallotsStorage_flat.sol` - Select contract `BallotsStorage`.
- `EternalStorageProxy_flat.sol` - Select contract `EternalStorageProxy` with constructor parameters: <br />
- `BallotsStorage_flat.sol` - Deploy `BallotsStorage` contract.
- `EternalStorageProxy_flat.sol` - Deploy `EternalStorageProxy` contract with constructor parameters: <br />
`_proxyStorage` - address of ProxyStorage contract,
`_implementationAddress` - address of BallotsStorage contract.
- Make a call to `BallotsStorage init` with `_thresholds` parameter equal to [3, 2], using the address of `EternalStorageProxy` and ABI of `BallotsStorage`.
- `VotingToChangeKeys_flat.sol` - Select contract `VotingToChangeKeys`.
- `EternalStorageProxy_flat.sol` - Select contract `EternalStorageProxy` with constructor parameters: <br />
- `VotingToChangeKeys_flat.sol` - Deploy `VotingToChangeKeys` contract.
- `EternalStorageProxy_flat.sol` - Deploy `EternalStorageProxy` contract with constructor parameters: <br />
`_proxyStorage` - address of ProxyStorage contract,
`_implementationAddress` - address of VotingToChangeKeys contract.
- Make a call to `VotingToChangeKeys init` with `_minBallotDuration` parameter equal to `172800`, using the address of `EternalStorageProxy` and ABI of `VotingToChangeKeys`.
- `VotingToChangeMinThreshold_flat.sol` - Select contract `VotingToChangeMinThreshold`.
- `EternalStorageProxy_flat.sol` - Select contract `EternalStorageProxy` with constructor parameters: <br />
- `VotingToChangeMinThreshold_flat.sol` - Deploy `VotingToChangeMinThreshold` contract.
- `EternalStorageProxy_flat.sol` - Deploy `EternalStorageProxy` contract with constructor parameters: <br />
`_proxyStorage` - address of ProxyStorage contract,
`_implementationAddress` - address of VotingToChangeMinThreshold contract.
- Make a call to `VotingToChangeMinThreshold init` with `_minBallotDuration` parameter equal to `172800` and `_minPossibleThreshold` parameter equal to `3`, using the address of `EternalStorageProxy` and ABI of `VotingToChangeMinThreshold`.
- `VotingToChangeProxyAddress_flat.sol` - Select contract `VotingToChangeProxyAddress`.
- `EternalStorageProxy_flat.sol` - Select contract `EternalStorageProxy` with constructor parameters: <br />
- `VotingToChangeProxyAddress_flat.sol` - Deploy `VotingToChangeProxyAddress` contract.
- `EternalStorageProxy_flat.sol` - Deploy `EternalStorageProxy` contract with constructor parameters: <br />
`_proxyStorage` - address of ProxyStorage contract,
`_implementationAddress` - address of VotingToChangeProxyAddress contract.
- Make a call to `VotingToChangeProxyAddress init` with `_minBallotDuration` parameter equal to `172800`, using the address of `EternalStorageProxy` and ABI of `VotingToChangeProxyAddress`.
- `ValidatorMetadata_flat.sol` - Select contract `ValidatorMetadata`.
- `EternalStorageProxy_flat.sol` - Select contract `EternalStorageProxy` with constructor parameters: <br />
- `ValidatorMetadata_flat.sol` - Deploy `ValidatorMetadata` contract.
- `EternalStorageProxy_flat.sol` - Deploy `EternalStorageProxy` contract with constructor parameters: <br />
`_proxyStorage` - address of ProxyStorage contract,
`_implementationAddress` - address of ValidatorMetadata contract.
- `VotingToManageEmissionFunds_flat.sol` - Deploy `VotingToManageEmissionFunds` contract.
- `EternalStorageProxy_flat.sol` - Deploy `EternalStorageProxy` contract with constructor parameters: <br />
`_proxyStorage` - address of ProxyStorage contract,
`_implementationAddress` - address of VotingToManageEmissionFunds contract.
- `EmissionFunds_flat.sol` - Deploy `EmissionFunds` contract with constructor parameter `_votingToManageEmissionFunds` equal to `EternalStorageProxy` address of `VotingToManageEmissionFunds` contract.
- `RewardByBlock_flat.sol` - Deploy `RewardByBlock` contract and replace `emissionFunds` constant value `0x00...` inside it with the address of deployed `EmissionFunds`. Then deploy `RewardByBlock`.
- `EternalStorageProxy_flat.sol` - Deploy `EternalStorageProxy` contract with constructor parameters: <br />
`_proxyStorage` - address of ProxyStorage contract,
`_implementationAddress` - address of RewardByBlock contract.
- Make a call to `VotingToManageEmissionFunds init`, using the address of `EternalStorageProxy` and ABI of `VotingToManageEmissionFunds`, with the next parameters: <br />
`_emissionFunds` - address of EmissionFunds contract,
`_emissionReleaseTime` - your emission release unix timestamp,
`_emissionReleaseThreshold` - your emission release threshold in seconds,
`_distributionThreshold` - your distribution threshold in seconds.
- Select deployed `ProxyStorage` contract and make a call from MoC address to `initializeAddresses` with relevant addresses.

## Unit tests
Expand Down
30 changes: 27 additions & 3 deletions contracts/ProxyStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ contract ProxyStorage is EternalStorage, IProxyStorage {

bytes32 internal constant POA_CONSENSUS =
keccak256("poaConsensus");

bytes32 internal constant REWARD_BY_BLOCK_ETERNAL_STORAGE =
keccak256("rewardByBlockEternalStorage");

bytes32 internal constant VALIDATOR_METADATA_ETERNAL_STORAGE =
keccak256("validatorMetadataEternalStorage");
Expand All @@ -37,6 +40,9 @@ contract ProxyStorage is EternalStorage, IProxyStorage {
bytes32 internal constant VOTING_TO_CHANGE_PROXY_ETERNAL_STORAGE =
keccak256("votingToChangeProxyEternalStorage");

bytes32 internal constant VOTING_TO_MANAGE_EMISSION_FUNDS_ETERNAL_STORAGE =
keccak256("votingToManageEmissionFundsEternalStorage");

enum ContractTypes {
Invalid,
KeysManager,
Expand All @@ -54,8 +60,10 @@ contract ProxyStorage is EternalStorage, IProxyStorage {
address votingToChangeKeysEternalStorage,
address votingToChangeMinThresholdEternalStorage,
address votingToChangeProxyEternalStorage,
address votingToManageEmissionFundsEternalStorage,
address ballotsStorageEternalStorage,
address validatorMetadataEternalStorage
address validatorMetadataEternalStorage,
address rewardByBlockEternalStorage
);

event AddressSet(uint256 contractType, address contractAddress);
Expand Down Expand Up @@ -102,6 +110,10 @@ contract ProxyStorage is EternalStorage, IProxyStorage {
return addressStorage[VOTING_TO_CHANGE_PROXY_ETERNAL_STORAGE];
}

function getVotingToManageEmissionFunds() public view returns(address) {
return addressStorage[VOTING_TO_MANAGE_EMISSION_FUNDS_ETERNAL_STORAGE];
}

function getPoaConsensus() public view returns(address) {
return addressStorage[POA_CONSENSUS];
}
Expand All @@ -114,13 +126,19 @@ contract ProxyStorage is EternalStorage, IProxyStorage {
return addressStorage[VALIDATOR_METADATA_ETERNAL_STORAGE];
}

function getRewardByBlock() public view returns(address) {
return addressStorage[REWARD_BY_BLOCK_ETERNAL_STORAGE];
}

function initializeAddresses(
address _keysManagerEternalStorage,
address _votingToChangeKeysEternalStorage,
address _votingToChangeMinThresholdEternalStorage,
address _votingToChangeProxyEternalStorage,
address _votingToManageEmissionFundsEternalStorage,
address _ballotsStorageEternalStorage,
address _validatorMetadataEternalStorage
address _validatorMetadataEternalStorage,
address _rewardByBlockEternalStorage
) public {
require(isValidator(msg.sender) || _isOwner(msg.sender));
require(!mocInitialized());
Expand All @@ -132,18 +150,24 @@ contract ProxyStorage is EternalStorage, IProxyStorage {
_votingToChangeMinThresholdEternalStorage;
addressStorage[VOTING_TO_CHANGE_PROXY_ETERNAL_STORAGE] =
_votingToChangeProxyEternalStorage;
addressStorage[VOTING_TO_MANAGE_EMISSION_FUNDS_ETERNAL_STORAGE] =
_votingToManageEmissionFundsEternalStorage;
addressStorage[BALLOTS_STORAGE_ETERNAL_STORAGE] =
_ballotsStorageEternalStorage;
addressStorage[VALIDATOR_METADATA_ETERNAL_STORAGE] =
_validatorMetadataEternalStorage;
addressStorage[REWARD_BY_BLOCK_ETERNAL_STORAGE] =
_rewardByBlockEternalStorage;
boolStorage[MOC_INITIALIZED] = true;
emit ProxyInitialized(
_keysManagerEternalStorage,
_votingToChangeKeysEternalStorage,
_votingToChangeMinThresholdEternalStorage,
_votingToChangeProxyEternalStorage,
_votingToManageEmissionFundsEternalStorage,
_ballotsStorageEternalStorage,
_validatorMetadataEternalStorage
_validatorMetadataEternalStorage,
_rewardByBlockEternalStorage
);
}

Expand Down
4 changes: 3 additions & 1 deletion contracts/interfaces/IProxyStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ pragma solidity ^0.4.24;


interface IProxyStorage {
function initializeAddresses(address, address, address, address, address, address) external;
function initializeAddresses(
address, address, address, address, address, address, address, address
) external;
function setContractAddress(uint256, address) external;
function isValidator(address) external view returns(bool);
function getBallotsStorage() external view returns(address);
Expand Down
85 changes: 67 additions & 18 deletions migrations/2_deploy_contract.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require('fs');
const moment = require('moment');
const PoaNetworkConsensus = artifacts.require("./PoaNetworkConsensus.sol");
const ProxyStorage = artifacts.require("./ProxyStorage.sol");
const KeysManager = artifacts.require("./KeysManager.sol");
Expand All @@ -7,6 +8,9 @@ const ValidatorMetadata = artifacts.require("./ValidatorMetadata.sol");
const VotingToChangeKeys = artifacts.require("./VotingToChangeKeys");
const VotingToChangeMinThreshold = artifacts.require("./VotingToChangeMinThreshold");
const VotingToChangeProxyAddress = artifacts.require("./VotingToChangeProxyAddress");
const VotingToManageEmissionFunds = artifacts.require("./VotingToManageEmissionFunds");
const RewardByBlock = artifacts.require("./RewardByBlock");
const EmissionFunds = artifacts.require("./EmissionFunds");
const EternalStorageProxy = artifacts.require("./eternal-storage/EternalStorageProxy.sol");

module.exports = function(deployer, network, accounts) {
Expand All @@ -15,14 +19,16 @@ module.exports = function(deployer, network, accounts) {
let poaNetworkConsensusAddress = process.env.POA_NETWORK_CONSENSUS_ADDRESS;
let previousKeysManager = process.env.OLD_KEYSMANAGER || "0x0000000000000000000000000000000000000000";
let demoMode = !!process.env.DEMO === true;
let poaNetworkConsensus;
let poaNetworkConsensus, emissionFunds;
let proxyStorage, proxyStorageImplAddress;
let keysManager, keysManagerImplAddress;
let ballotsStorage, ballotsStorageImplAddress;
let validatorMetadata, validatorMetadataImplAddress;
let votingToChangeKeys, votingToChangeKeysImplAddress;
let votingToChangeMinThreshold, votingToChangeMinThresholdImplAddress;
let votingToChangeProxyAddress, votingToChangeProxyAddressImplAddress;
let votingToManageEmissionFunds, votingToManageEmissionFundsImplAddress;
let rewardByBlock, rewardByBlockImplAddress;

const minBallotDuration = demoMode ? 0 : 172800;

Expand Down Expand Up @@ -119,26 +125,64 @@ module.exports = function(deployer, network, accounts) {
);
await votingToChangeProxyAddress.init(minBallotDuration);

// Deploy VotingToManageEmissionFunds
votingToManageEmissionFunds = await VotingToManageEmissionFunds.new();
votingToManageEmissionFundsImplAddress = votingToManageEmissionFunds.address;
votingToManageEmissionFunds = await EternalStorageProxy.new(
proxyStorage.address,
votingToManageEmissionFundsImplAddress
);
votingToManageEmissionFunds = VotingToManageEmissionFunds.at(
votingToManageEmissionFunds.address
);

// Deploy EmissionFunds
emissionFunds = await EmissionFunds.new(votingToManageEmissionFunds.address);

// Deploy RewardByBlock
rewardByBlock = await RewardByBlock.new();
rewardByBlockImplAddress = rewardByBlock.address;
rewardByBlock = await EternalStorageProxy.new(
proxyStorage.address,
rewardByBlockImplAddress
);
rewardByBlock = RewardByBlock.at(
rewardByBlock.address
);

// Initialize VotingToManageEmissionFunds
await votingToManageEmissionFunds.init(
emissionFunds.address,
moment.utc().add(3, 'months').unix(),
7776000,
604800
);

// Initialize ProxyStorage
await proxyStorage.initializeAddresses(
keysManager.address,
votingToChangeKeys.address,
votingToChangeMinThreshold.address,
votingToChangeProxyAddress.address,
votingToManageEmissionFunds.address,
ballotsStorage.address,
validatorMetadata.address
validatorMetadata.address,
rewardByBlock.address
);

if (!!process.env.SAVE_TO_FILE === true) {
const contracts = {
"VOTING_TO_CHANGE_KEYS_ADDRESS": votingToChangeKeys.address,
"VOTING_TO_CHANGE_MIN_THRESHOLD_ADDRESS": votingToChangeMinThreshold.address,
"VOTING_TO_CHANGE_PROXY_ADDRESS": votingToChangeProxyAddress.address,
"VOTING_TO_MANAGE_EMISSION_FUNDS_ADDRESS": votingToManageEmissionFunds.address,
"BALLOTS_STORAGE_ADDRESS": ballotsStorage.address,
"KEYS_MANAGER_ADDRESS": keysManager.address,
"METADATA_ADDRESS": validatorMetadata.address,
"PROXY_ADDRESS": proxyStorage.address,
"POA_ADDRESS": poaNetworkConsensusAddress
"POA_ADDRESS": poaNetworkConsensusAddress,
"EMISSION_FUNDS_ADDRESS": emissionFunds.address,
"REWARD_BY_BLOCK_ADDRESS": rewardByBlock.address
};

fs.writeFileSync('./contracts.json', JSON.stringify(contracts, null, 2));
Expand All @@ -147,21 +191,26 @@ module.exports = function(deployer, network, accounts) {
console.log(
'\nDone. ADDRESSES:',
`
VotingToChangeKeys.address (implementation) ....... ${votingToChangeKeysImplAddress}
VotingToChangeKeys.address (storage) .............. ${votingToChangeKeys.address}
VotingToChangeMinThreshold.address (implementation) ${votingToChangeMinThresholdImplAddress}
VotingToChangeMinThreshold.address (storage) ...... ${votingToChangeMinThreshold.address}
VotingToChangeProxyAddress.address (implementation) ${votingToChangeProxyAddressImplAddress}
VotingToChangeProxyAddress.address (storage) ...... ${votingToChangeProxyAddress.address}
BallotsStorage.address (implementation) ........... ${ballotsStorageImplAddress}
BallotsStorage.address (storage) .................. ${ballotsStorage.address}
KeysManager.address (implementation) .............. ${keysManagerImplAddress}
KeysManager.address (storage) ..................... ${keysManager.address}
ValidatorMetadata.address (implementation) ........ ${validatorMetadataImplAddress}
ValidatorMetadata.address (storage) ............... ${validatorMetadata.address}
ProxyStorage.address (implementation) ............. ${proxyStorageImplAddress}
ProxyStorage.address (storage) .................... ${proxyStorage.address}
PoaNetworkConsensus.address ....................... ${poaNetworkConsensusAddress}
VotingToChangeKeys.address (implementation) ........ ${votingToChangeKeysImplAddress}
VotingToChangeKeys.address (storage) ............... ${votingToChangeKeys.address}
VotingToChangeMinThreshold.address (implementation). ${votingToChangeMinThresholdImplAddress}
VotingToChangeMinThreshold.address (storage) ....... ${votingToChangeMinThreshold.address}
VotingToChangeProxyAddress.address (implementation). ${votingToChangeProxyAddressImplAddress}
VotingToChangeProxyAddress.address (storage) ....... ${votingToChangeProxyAddress.address}
VotingToManageEmissionFunds.address (implementation) ${votingToManageEmissionFundsImplAddress}
VotingToManageEmissionFunds.address (storage) ...... ${votingToManageEmissionFunds.address}
BallotsStorage.address (implementation) ............ ${ballotsStorageImplAddress}
BallotsStorage.address (storage) ................... ${ballotsStorage.address}
KeysManager.address (implementation) ............... ${keysManagerImplAddress}
KeysManager.address (storage) ...................... ${keysManager.address}
ValidatorMetadata.address (implementation) ......... ${validatorMetadataImplAddress}
ValidatorMetadata.address (storage) ................ ${validatorMetadata.address}
ProxyStorage.address (implementation) .............. ${proxyStorageImplAddress}
ProxyStorage.address (storage) ..................... ${proxyStorage.address}
PoaNetworkConsensus.address ........................ ${poaNetworkConsensusAddress}
EmissionFunds.address .............................. ${emissionFunds.address}
RewardByBlock.address (implementation) .............. ${rewardByBlockImplAddress}
RewardByBlock.address (storage) ..................... ${rewardByBlock.address}
`
);
}).catch(function(error) {
Expand Down
4 changes: 3 additions & 1 deletion scripts/migrate/migrateAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,10 @@ async function main() {
votingToChangeKeysNewAddress,
votingToChangeMinThresholdNewAddress,
votingToChangeProxyNewAddress,
votingToManageEmissionFundsAddress,
ballotsStorageNewAddress,
process.env.METADATA_NEW_ADDRESS
process.env.METADATA_NEW_ADDRESS,
rewardByBlockAddress
);
await utils.call(initializeAddresses, sender, process.env.PROXY_STORAGE_NEW_ADDRESS, key, chainId);
true.should.be.equal(
Expand Down
Loading