Skip to content

Commit

Permalink
Adjust migrations for Testnet contract deploys (#5795)
Browse files Browse the repository at this point in the history
### Description

Over time, our migrationsConfig have become out of sync and thus the current state does not yield a satisfactory experience for deploying contracts on a real testnet (i.e. not ganache). As I've been working more on env-test, I also adjusted the default migration overrides to make some special keys more accessible on these testnets.

As a result, testnet contract deploys should work out of the box, and an upcoming PR for env-tests will make running these tests work out of the box as well.

### Tested

- On my own testnets

Fixes #5727
  • Loading branch information
nambrot authored Nov 12, 2020
1 parent b5811a7 commit e8cbbd8
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 122 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ EKSPORTISTO_DOCKER_IMAGE_TAG="12f9f9e822ea35db2f965be616abef126f1724fb"
EKSPORTISTO_SUFFIX='1'

ATTESTATION_SERVICE_DOCKER_IMAGE_REPOSITORY="us.gcr.io/celo-testnet/celo-monorepo"
ATTESTATION_SERVICE_DOCKER_IMAGE_TAG="attestation-service-dc5e5dfa07231a4ff4664816a95eae606293eae9"
ATTESTATION_SERVICE_DOCKER_IMAGE_TAG="attestation-service-v1.1.0"

GETH_EXPORTER_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet-production/geth-exporter"
GETH_EXPORTER_DOCKER_IMAGE_TAG="ed7d21bd50592709173368cd697ef73c1774a261"

# Genesis Vars
NETWORK_ID=1101
CONSENSUS_TYPE="istanbul"
BLOCK_TIME=5
BLOCK_TIME=1
EPOCH=1000
LOOKBACK=12
ISTANBUL_REQUEST_TIMEOUT_MS=3000
Expand Down
2 changes: 1 addition & 1 deletion packages/celotool/src/cmds/deploy/initial/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const handler = async (argv: ContractsArgv) => {
await execCmd(
`yarn --cwd ../protocol run init-network -n ${argv.celoEnv} -c '${JSON.stringify(
truffleOverrides()
)}' -m '${JSON.stringify(migrationOverrides(!argv.skipFaucetting))}'`
)}' -m '${JSON.stringify(await migrationOverrides(!argv.skipFaucetting))}'`
)

console.info('Register Metadata for Clabs validators')
Expand Down
2 changes: 1 addition & 1 deletion packages/celotool/src/cmds/deploy/upgrade/contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const handler = async (argv: ContractsArgv) => {
await execCmd(
`yarn --cwd ../protocol run migrate -n ${argv.celoEnv} -c '${JSON.stringify(
truffleOverrides()
)}' -m '${JSON.stringify(migrationOverrides(!argv.skipFaucetting))}'`
)}' -m '${JSON.stringify(await migrationOverrides(!argv.skipFaucetting))}'`
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('Blockchain parameters tests', function(this: any) {
it('block limit should have been set using governance', async () => {
this.timeout(0)
const res = await parameters.getBlockGasLimit()
assert.equal(0, res.comparedTo(10000000))
assert.equal(0, res.comparedTo(13000000))
})
it('changing the block gas limit', async () => {
this.timeout(0)
Expand Down
2 changes: 1 addition & 1 deletion packages/celotool/src/lib/attestation-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function helmParameters(celoEnv: string) {
`--set attestation_service.twilio.addressSid="${fetchEnv(envVar.TWILIO_ADDRESS_SID)}"`,
`--set attestation_service.nexmo.apiKey="${fetchEnv(envVar.NEXMO_KEY)}"`,
`--set attestation_service.nexmo.apiSecret="${fetchEnv(envVar.NEXMO_SECRET)}"`,
...setHelmArray('attestation_service.nexmo.applications', fetchEnv(envVar.NEXMO_APPLICATIONS).split(',')),
...setHelmArray('attestation_service.nexmo.applications', fetchEnvOrFallback(envVar.NEXMO_APPLICATIONS, '').split(',')),
`--set geth.validators="${fetchEnv(envVar.VALIDATORS)}"`,
`--set domain.name=${fetchEnv(envVar.CLUSTER_DOMAIN_NAME)}`,
`--set global.postgresql.postgresqlDatabase=AttestationService`,
Expand Down
55 changes: 50 additions & 5 deletions packages/celotool/src/lib/migration-utils.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,34 @@
import { generateKeys } from '@celo/utils/lib/account'
import { envVar, fetchEnv, fetchEnvOrFallback } from './env-utils'
import {
AccountType,
generatePrivateKey,
getAddressesFor,
getFaucetedAccounts,
getPrivateKeysFor,
privateKeyToAddress,
privateKeyToAddress
} from './generate_utils'
import { ensure0x } from './utils'

const DEFAULT_FAUCET_CUSD_WEI = '60000000000000000000000' /* 60k Celo Dollars */

export async function getKey(mnemonic: string, account: TestAccounts) {
const key = await generateKeys(mnemonic, undefined, 0, account)
return { ...key, address: privateKeyToAddress(key.privateKey) }
}

// From env-tests package
export enum TestAccounts {
Root,
TransferFrom,
TransferTo,
Exchange,
Oracle,
GovernanceApprover,
ReserveSpender,
ReserveCustodian
}

export function minerForEnv() {
return privateKeyToAddress(
generatePrivateKey(fetchEnv(envVar.MNEMONIC), AccountType.VALIDATOR, 0)
Expand All @@ -33,13 +51,19 @@ function getAttestationKeys() {
).map(ensure0x)
}

export function migrationOverrides(faucet: boolean) {
export async function migrationOverrides(faucet: boolean) {
let overrides = {}
if (faucet) {
const mnemonic = fetchEnv(envVar.MNEMONIC)
const faucetedAccountAddresses = getFaucetedAccounts(mnemonic).map((account) => account.address)
const attestationBotAddresses = getAddressesFor(AccountType.ATTESTATION_BOT, mnemonic, 10)
const initialAddresses = [...faucetedAccountAddresses, ...attestationBotAddresses]
const validatorAddresses = getAddressesFor(AccountType.VALIDATOR, mnemonic, 1)
const envTestRoot = await getKey(mnemonic, TestAccounts.Root)
const envTestReserveCustodian = await getKey(mnemonic, TestAccounts.ReserveCustodian)
const envTestOracle = await getKey(mnemonic, TestAccounts.Oracle)
const envTestGovernanceApprover = await getKey(mnemonic, TestAccounts.GovernanceApprover)
const envTestReserveSpender = await getKey(mnemonic, TestAccounts.ReserveSpender)
const initialAddresses = [...faucetedAccountAddresses, ...attestationBotAddresses, ...validatorAddresses, envTestRoot.address, envTestOracle.address]

const initialBalance = fetchEnvOrFallback(envVar.FAUCET_CUSD_WEI, DEFAULT_FAUCET_CUSD_WEI)

Expand All @@ -50,8 +74,29 @@ export function migrationOverrides(faucet: boolean) {
addresses: initialAddresses,
values: initialAddresses.map(() => initialBalance),
},
oracles: [...getAddressesFor(AccountType.PRICE_ORACLE, mnemonic, 1), minerForEnv()],
}
oracles: [...getAddressesFor(AccountType.PRICE_ORACLE, mnemonic, 1), minerForEnv(), envTestOracle.address],
},
// from migrationsConfig
governanceApproverMultiSig: {
signatories: [minerForEnv(), envTestGovernanceApprover.address],
numRequiredConfirmations: 1,
numInternalRequiredConfirmations: 1,
},
// from migrationsConfig:
reserve: {
initialBalance: 100000000, // CELO
frozenAssetsStartBalance: 80000000, // Matches Mainnet after CGP-6
frozenAssetsDays: 182, // 3x Mainnet thawing rate
otherAddresses: [
envTestReserveCustodian.address
],
},
// from migrationsConfig
reserveSpenderMultiSig: {
signatories: [minerForEnv(), envTestReserveSpender.address],
numRequiredConfirmations: 1,
numInternalRequiredConfirmations: 1,
},
}
}

Expand Down
Loading

0 comments on commit e8cbbd8

Please sign in to comment.