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 elect validators migration, deploy integration #1847

Merged
merged 12 commits into from
Nov 25, 2019
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
6 changes: 3 additions & 3 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ CLUSTER_DOMAIN_NAME="celo-networks-dev"
TESTNET_PROJECT_NAME="celo-testnet"

BLOCKSCOUT_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet/blockscout"
BLOCKSCOUT_DOCKER_IMAGE_TAG="8be64adeccbb8f67dea3b6653600021577e544c5"
BLOCKSCOUT_DOCKER_IMAGE_TAG="909682b7435fc3e05849211d96fb1dfbf76306f2"
BLOCKSCOUT_WEB_REPLICAS=3
BLOCKSCOUT_DB_SUFFIX=

ETHSTATS_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet/ethstats"
ETHSTATS_DOCKER_IMAGE_TAG="cd037ea1e18848466452ba9890c1f1bcd3f61009"
ETHSTATS_TRUSTED_ADDRESSES="0x480b0e0A641AE45521377d4984d085a003934561,0xF523976B9FB2160e9a43D8Aee016b98ea8f57837"
ETHSTATS_BANNED_ADDRESSES="0xFd24A0699288E141A855bC8c0dd0400C5E89D5e5"
ETHSTATS_TRUSTED_ADDRESSES=""
ETHSTATS_BANNED_ADDRESSES=""

FAUCET_GENESIS_ACCOUNTS=2

Expand Down
23 changes: 13 additions & 10 deletions .env.integration
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,36 @@ CLUSTER_DOMAIN_NAME="celo-testnet"
TESTNET_PROJECT_NAME="celo-testnet"

BLOCKSCOUT_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet/blockscout"
BLOCKSCOUT_DOCKER_IMAGE_TAG="ad86714d629c01272e0651dec1fb6a968c3cec71"
BLOCKSCOUT_DOCKER_IMAGE_TAG="909682b7435fc3e05849211d96fb1dfbf76306f2"
BLOCKSCOUT_WEB_REPLICAS=3
BLOCKSCOUT_DB_SUFFIX="25"
BLOCKSCOUT_DB_SUFFIX="29"
BLOCKSCOUT_SUBNETWORK_NAME="Integration"

ETHSTATS_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet/ethstats"
ETHSTATS_DOCKER_IMAGE_TAG="cd037ea1e18848466452ba9890c1f1bcd3f61009"
ETHSTATS_TRUSTED_ADDRESSES=""
ETHSTATS_BANNED_ADDRESSES=""

FAUCET_GENESIS_ACCOUNTS=2

GETH_NODE_DOCKER_IMAGE_REPOSITORY="us.gcr.io/celo-testnet/geth"
# When upgrading change this to latest commit hash from the master of the geth repo
# `geth $ git show | head -n 1`
GETH_NODE_DOCKER_IMAGE_TAG="c1ae452c707f8bee91a9a0bf49193e78e9c8512e"
GETH_NODE_DOCKER_IMAGE_TAG="09a217ff58a95214cbc5189c933359707f4fdaf2"

GETH_BOOTNODE_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet/geth-all"
# When upgrading change this to latest commit hash from the master of the geth repo
# `geth $ git show | head -n 1`
GETH_BOOTNODE_DOCKER_IMAGE_TAG="c1ae452c707f8bee91a9a0bf49193e78e9c8512e"
GETH_BOOTNODE_DOCKER_IMAGE_TAG="09a217ff58a95214cbc5189c933359707f4fdaf2"

CELOTOOL_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet/celo-monorepo"
CELOTOOL_DOCKER_IMAGE_TAG="celotool-2cb725c36b69e7ae608875610af080f4f3fa79bd"
CELOTOOL_DOCKER_IMAGE_TAG="celotool-5bea6d30cbe6aa4272b32a4d2cfed5567f422ea9"

TRANSACTION_METRICS_EXPORTER_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet/celo-monorepo"
TRANSACTION_METRICS_EXPORTER_DOCKER_IMAGE_TAG="transaction-metrics-exporter-2cb725c36b69e7ae608875610af080f4f3fa79bd"
TRANSACTION_METRICS_EXPORTER_DOCKER_IMAGE_TAG="transaction-metrics-exporter-5bea6d30cbe6aa4272b32a4d2cfed5567f422ea9"

ATTESTATION_SERVICE_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet/celo-monorepo"
ATTESTATION_SERVICE_DOCKER_IMAGE_TAG="attestation-service-2cb725c36b69e7ae608875610af080f4f3fa79bd"
ATTESTATION_SERVICE_DOCKER_IMAGE_REPOSITORY="us.gcr.io/celo-testnet/celo-monorepo"
ATTESTATION_SERVICE_DOCKER_IMAGE_TAG="attestation-service-c8e3392aa2ca44ff83b4035700ece5fd12ed2b84"

GETH_EXPORTER_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet-production/geth-exporter"
GETH_EXPORTER_DOCKER_IMAGE_TAG="ed7d21bd50592709173368cd697ef73c1774a261"
Expand All @@ -47,7 +52,6 @@ BLOCK_TIME=3
EPOCH=1000
ISTANBUL_REQUEST_TIMEOUT_MS=3000

# "og" -> our original 4 tx nodes, "${n}" -> for deriving n tx nodes from the MNEMONIC
# NOTE: we only create static IPs when TX_NODES is set to "og"
VALIDATORS=20
TX_NODES=2
Expand All @@ -61,7 +65,6 @@ GETH_NODES_BACKUP_CRONJOB_ENABLED=true
CONTRACT_CRONJOBS_ENABLED=true
CLUSTER_CREATION_FLAGS="--enable-autoscaling --min-nodes 3 --max-nodes 8 --machine-type=n1-standard-4"


GETH_NODE_CPU_REQUEST=400m
GETH_NODE_MEMORY_REQUEST=2.5G

Expand Down
14 changes: 3 additions & 11 deletions packages/celotool/src/e2e-tests/governance_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,16 +196,6 @@ describe('governance tests', () => {
return decryptedKeystore.privateKey
}

const activate = async (account: string, txOptions: any = {}) => {
const [group] = await validators.methods.getRegisteredValidatorGroups().call()
const tx = election.methods.activate(group)
let gas = txOptions.gas
if (!gas) {
gas = (await tx.estimateGas({ ...txOptions })) * 2
}
return tx.send({ from: account, ...txOptions, gas })
}

const isLastBlockOfEpoch = (blockNumber: number, epochSize: number) => {
return blockNumber % epochSize === 0
}
Expand Down Expand Up @@ -302,12 +292,14 @@ describe('governance tests', () => {
blockNumber = await web3.eth.getBlockNumber()
await sleep(0.1)
} while (blockNumber % epoch !== 1)
await activate(validatorAccounts[0])

// Prepare for member swapping.
const groupWeb3 = new Web3('ws://localhost:8555')
await waitToFinishSyncing(groupWeb3)
const groupKit = newKitFromWeb3(groupWeb3)
const group: string = (await groupWeb3.eth.getAccounts())[0]
await (await groupKit.contracts.getElection()).activate(group)

validators = await groupKit._web3Contracts.getValidators()
const membersToSwap = [validatorAccounts[0], validatorAccounts[1]]
const memberSwapper = await newMemberSwapper(groupKit, membersToSwap)
Expand Down
3 changes: 0 additions & 3 deletions packages/celotool/src/e2e-tests/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,9 +362,6 @@ export async function migrateContracts(
election: {
minElectableValidators: '1',
},
reserve: {
goldBalance: 100000,
},
stableToken: {
initialBalances: {
addresses: validators.map(ensure0x),
Expand Down
4 changes: 2 additions & 2 deletions packages/celotool/src/lib/ethstats.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { installGenericHelmChart, removeGenericHelmChart } from 'src/lib/helm_deploy'
import { execCmdWithExitOnFailure } from 'src/lib/utils'
import { envVar, fetchEnv } from './env-utils'
import { envVar, fetchEnv, fetchEnvOrFallback } from './env-utils'
import { AccountType, getAddressesFor } from './generate_utils'

const helmChartPath = '../helm-charts/ethstats'
Expand Down Expand Up @@ -50,6 +50,6 @@ function generateAuthorizedAddresses() {
publicKeys.push(getAddressesFor(AccountType.TX_NODE, mnemonic, txNodes))
publicKeys.push(getAddressesFor(AccountType.VALIDATOR, mnemonic, validatorNodes))

publicKeys.push(fetchEnv(envVar.ETHSTATS_TRUSTED_ADDRESSES).split(','))
publicKeys.push(fetchEnvOrFallback(envVar.ETHSTATS_TRUSTED_ADDRESSES, '').split(','))
return publicKeys.reduce((accumulator, value) => accumulator.concat(value), [])
}
8 changes: 4 additions & 4 deletions packages/celotool/src/lib/generate_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ export const privateKeyToStrippedAddress = (privateKey: string) =>

const validatorZeroBalance = fetchEnvOrFallback(
envVar.VALIDATOR_ZERO_GENESIS_BALANCE,
'100010011000000000000000000'
) // 100,010,011 CG
'103010030000000000000000000'
) // 103,010,030 CG
const validatorBalance = fetchEnvOrFallback(
envVar.VALIDATOR_GENESIS_BALANCE,
'10011000000000000000000'
Expand All @@ -109,12 +109,12 @@ export const getStrippedAddressesFor = (accountType: AccountType, mnemonic: stri
getAddressesFor(accountType, mnemonic, n).map(strip0x)

export const getValidators = (mnemonic: string, n: number) => {
return getPrivateKeysFor(AccountType.VALIDATOR, mnemonic, n).map((key) => {
return getPrivateKeysFor(AccountType.VALIDATOR, mnemonic, n).map((key, i) => {
const blsKeyBytes = blsPrivateKeyToProcessedPrivateKey(key)
return {
address: strip0x(privateKeyToAddress(key)),
blsPublicKey: bls12377js.BLS.privateToPublicBytes(blsKeyBytes).toString('hex'),
balance: n === 0 ? validatorZeroBalance : validatorBalance,
balance: i === 0 ? validatorZeroBalance : validatorBalance,
}
})
}
Expand Down
18 changes: 1 addition & 17 deletions packages/protocol/contracts/governance/Election.sol
Original file line number Diff line number Diff line change
Expand Up @@ -752,8 +752,7 @@ contract Election is
totalNumMembersElected = totalNumMembersElected.add(1);
}
}
// Shuffle the validator set using validator-supplied entropy
return shuffleArray(electedValidators);
return electedValidators;
}

/**
Expand Down Expand Up @@ -789,21 +788,6 @@ contract Election is
return (groupIndex, memberElected);
}

/**
* @notice Randomly permutes an array of addresses.
* @param array The array to permute.
* @return The permuted array.
*/
function shuffleArray(address[] memory array) private view returns (address[] memory) {
bytes32 r = getRandom().getBlockRandomness(block.number);
for (uint256 i = array.length - 1; i > 0; i = i.sub(1)) {
uint256 j = uint256(r) % (i + 1);
(array[i], array[j]) = (array[j], array[i]);
r = keccak256(abi.encodePacked(r));
}
return array;
}

/**
* @notice Returns get current validator signers using the precompiles.
* @return List of current validator signers.
Expand Down
2 changes: 2 additions & 0 deletions packages/protocol/migrations/19_governance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ module.exports = deploymentForCoreContract<GovernanceInstance>(
)

const proxyAndImplementationOwnedByGovernance = [
'Accounts',
'Attestations',
'BlockchainParameters',
'Election',
'EpochRewards',
'Escrow',
'Exchange',
'FeeCurrencyWhitelist',
Expand Down
Loading