Skip to content

Commit

Permalink
Merge branch 'master' into aaronmgdr/static
Browse files Browse the repository at this point in the history
* master: (26 commits)
  Added new lint rule (#2349)
  [Slashing] Slash locked gold (#2317)
  [Slashing] Allow voting gold to be slashable (#2302)
  1666 precompiles assembly rewrite (#2324)
  Small fixes to deploy web (#2343)
  Governance, downtime and double signing slasher contracts (#2267)
  Added daily limit for reserve spending (#2303)
  Fixing multisig tests (#2342)
  [Wallet] Implement new send & import flow (#2332)
  Limechain/16xx (#1982)
  Add infinite pagination to Leaderboard (#2339)
  cli: Add rewards:show (#2160)
  Correct broken link formatting
  Celotool command for deploying hotfixes (#2142)
  Governance ContractKit + CLI changes (#2139)
  Complete codependent slashing precompile PRs (#2333)
  Add new and modified precompiles to UsingPrecompiles.sol (#2318)
  Adding error messages to contracts (#1182)
  Upgrade i18next and react-i18next to latest across monorepo (#2311)
  [Wallet] Fix exchange input on iOS and feed item display (#2319)
  ...

# Conflicts:
#	yarn.lock
  • Loading branch information
aaronmgdr committed Jan 2, 2020
2 parents 8bd268b + 53a6cf1 commit dd1f8b3
Show file tree
Hide file tree
Showing 332 changed files with 8,078 additions and 2,967 deletions.
18 changes: 0 additions & 18 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,6 @@ jobs:
name: Run Tests
command: yarn --cwd=packages/contractkit test

- run:
name: Install and test the npm package
command: |
set -euo pipefail
cd packages/contractkit
yarn pack
cd /tmp
npm install ~/app/packages/contractkit/*.tgz
walletkit-test:
<<: *defaults
steps:
Expand All @@ -436,15 +427,6 @@ jobs:
yarn --cwd=packages/walletkit build alfajoresstaging
yarn --cwd=packages/walletkit test
- run:
name: Install and test the npm package
command: |
set -euo pipefail
cd packages/walletkit
yarn pack
cd /tmp
npm install ~/app/packages/walletkit/*.tgz
cli-test:
<<: *defaults
steps:
Expand Down
3 changes: 2 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ BLOCKSCOUT_WEB_REPLICAS=3
BLOCKSCOUT_DB_SUFFIX=

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

FAUCET_GENESIS_ACCOUNTS=2

Expand Down
3 changes: 2 additions & 1 deletion .env.baklava
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ BLOCKSCOUT_DB_SUFFIX="0"
BLOCKSCOUT_SUBNETWORK_NAME="Baklava"

ETHSTATS_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet/ethstats"
ETHSTATS_DOCKER_IMAGE_TAG="efe7d0887c37bf308c5a5154be282cac34226a73"
ETHSTATS_DOCKER_IMAGE_TAG="150e7758ec3bde70e68dead7867360a254f90d84"
ETHSTATS_TRUSTED_ADDRESSES=""
ETHSTATS_BANNED_ADDRESSES=""
ETHSTATS_RESERVED_ADDRESSES=""

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
Expand Down
3 changes: 2 additions & 1 deletion .env.baklavastaging
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ BLOCKSCOUT_DB_SUFFIX="0"
BLOCKSCOUT_SUBNETWORK_NAME="Baklava Staging"

ETHSTATS_DOCKER_IMAGE_REPOSITORY="gcr.io/celo-testnet/ethstats"
ETHSTATS_DOCKER_IMAGE_TAG="bbc89603d872af1c6b37cf00e8220ed26237fc91"
ETHSTATS_DOCKER_IMAGE_TAG="150e7758ec3bde70e68dead7867360a254f90d84"
ETHSTATS_TRUSTED_ADDRESSES=""
ETHSTATS_BANNED_ADDRESSES=""
ETHSTATS_RESERVED_ADDRESSES=""

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
Expand Down
52 changes: 35 additions & 17 deletions README-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Many packages depend on other packages within the monorepo. When this happens, f
3. To differentiate published vs unpublished version. Master version (in package.json) must end with suffix `-dev` and should not be published.
4. If a developer want to publish a version; then after publishing it needs to set master version to next `-dev` version and change all package.json that require on it.

To check which pakages need amending, you can run (in the root pkg):
To check which packages need amending, you can run (in the root pkg):

yarn check:packages

Expand All @@ -23,29 +23,44 @@ A practical example:

## How to publish a new npm package

First checkout the alfajores branch.
> Note: Packages with mainline versions (i.e. without a `-foo` suffix) should be published from the `master` branch.
```
celo-monorepo $ git checkout alfajores
celo-monorepo $ yarn
```
> Note: All packages are prefixed with "@celo/" and only members of the [Celo NPM organization](https://www.npmjs.com/settings/celo/members) can publish new packages or update the existing ones.
### Update the version numbers to an unpublished version

It is important to ensure that the `master` branch is ahead of the published package on NPM, otherwise `yarn` may use the published version of the package rather than the local development version.

In order to maintain this, create and merge a PR to the `master` branch bumping the package version to the next number that will be published. (i.e. If you are about to publish `x.y.z`, set the package version to `x.y.z+1`)
Update all references to that package in the monorepo to the new version (i.e. `x.y.z+1`)
Prefer appending a `-dev` suffix to the version number to ensure an internal dependency will never be mistaken for a published one.

> Note: Services deployed to App Engine must only depend on published NPM packages. These packages are `verification-pool-api`, `blockchain-api` and `notification-service`.
### Checkout the commit to be published and verify version numbers

Checkout the commit that will become the new published version (i.e. `git checkout HEAD~1` assuming that the commit for bumping the version number is `HEAD`)

Before publishing a new celocli package, test in isolation using Docker. This confirms that it is locally installable and does not have implict dependency on rest of the celo-monorepo or have an implicit dependency which is an explicit dependency of another celo-monorepo package.
Check the `package.json` file and remove the `-dev` suffix if present. Additionally remove the `-dev` suffix from any internal dependencies and use ensure they are published (e.g. `@celo/utils`)

### Verify installation in Docker

Test installation in isolation using Docker.
This confirms that it is locally installable and does not have implicit dependency on rest of the `celo-monorepo` or have an implicit dependency which is an explicit dependency of another `celo-monorepo` package.

```
# To test utils package, change $PWD/packages/cli to $PWD/packages/utils
# To test contractkit package, change $PWD/packages/cli to $PWD/packages/contractkit
celo-monorepo $ docker run -v $PWD/packages/cli:/tmp/npm_package -it --entrypoint bash node:10
# Specify the package to test. e.g. celocli, contractkit, utils
celo-monorepo $ PACKAGE=cli
celo-monorepo $ docker run --rm -v $PWD/packages/${PACKAGE}:/tmp/npm_package -it --entrypoint bash node:10
root@e0d56700584f:/# mkdir /tmp/tmp1 && cd /tmp/tmp1
root@e0d56700584f:/tmp/tmp1# npm install /tmp/npm_package/
```

After testing, exit the docker container, and publish the package. Do note that all our packages are prefixed with "@celo/" and only members listed [here](https://www.npmjs.com/settings/celo/members) can publish new packages or update the existing ones.
### Publish the package

```
# Publish the package publicly
celo-monorepo/packages/cli $ yarn publish --access=public
# Increment the version number, after testing, we will push that commit to GitHub
```

Let's say the published package version number 0.0.20, verify that it is installable
Expand All @@ -57,14 +72,20 @@ Let's say the published package version number 0.0.20, verify that it is install
Add a tag with the most recent git commit of the published branch. Note that this commit comes before package.json is updated with the new package version.

```
$ npm dist-tag add <package-name>@<version> [<tag>]
$ npm dist-tag add <package-name>@<version> <tag>
```

Additionally, if this version is intended to be used on a deployed network (e.g. `baklava` or `alfajores`), tag the version with all appropriate network names.

```
$ npm dist-tag add <package-name>@<version> <network>
```

Once you publish do some manual tests, for example, after publishing `celocli`

```
# Docker for an isolated environment again
celo-monorepo $ docker run -it --entrypoint bash node:10
celo-monorepo $ docker run --rm -it --entrypoint bash node:10
root@e0d56700584f:/# mkdir /tmp/tmp1 && cd /tmp/tmp1
root@e0d56700584f:/tmp/tmp1# npm install @celo/celocli@0.0.20
/tmp/tmp1# ./node_modules/.bin/celocli
Expand Down Expand Up @@ -93,6 +114,3 @@ mnemonic: wall school patrol also peasant enroll build merit health reduce junio
privateKey: a9531609ca3d1c224e0742a4bb9b9e2fae67cc9d872797869092804e1500d67c
publicKey: 0429b83753806f2b61ddab2e8a139214c3c8a5dfd0557557830b13342f2490bad6f61767e1b0707be51685e5e13683e6fa276333cbdb06f07768a09b8070e27259accountAddress: 0xf63e0F60DFcd84090D2863e0Dfa452B871fdC6d7
```

Now push your changes `git push origin alfajores`.
If you don't have access to the repo, you might have to open a PR.
2 changes: 1 addition & 1 deletion packages/attestation-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"dependencies": {
"@celo/contractkit": "0.2.8-dev",
"@celo/utils": "^0.1.0",
"@celo/utils": "0.1.5-dev",
"bignumber.js": "^7.2.0",
"body-parser": "1.19.0",
"bunyan": "1.8.12",
Expand Down
2 changes: 1 addition & 1 deletion packages/celotool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "Apache-2.0",
"dependencies": {
"@celo/verification-pool-api": "^1.0.0",
"@celo/utils": "^0.1.0",
"@celo/utils": "0.1.5-dev",
"@celo/walletkit": "^0.0.15",
"@celo/contractkit": "0.2.8-dev",
"@google-cloud/monitoring": "0.7.1",
Expand Down
157 changes: 157 additions & 0 deletions packages/celotool/src/cmds/deploy/upgrade/hotfix.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// This is a more unusual Celotool command. It basically helps you to execute Hotfixes on testnets. Because constructing proposals is difficult to do via a CLI, you should define them here in code. There are two examples below that you can start from.

import { newKit } from '@celo/contractkit'
import {
ProposalBuilder,
proposalToHash,
proposalToJSON,
} from '@celo/contractkit/lib/governance/proposals'
import { privateKeyToAddress } from '@celo/utils/lib/address'
import { concurrentMap } from '@celo/utils/lib/async'
import { getFornoUrl } from 'src/lib/endpoints'
import { envVar, fetchEnv } from 'src/lib/env-utils'
import { AccountType, getPrivateKeysFor } from 'src/lib/generate_utils'
import yargs from 'yargs'
import { UpgradeArgv } from '../../deploy/upgrade'

export const command = 'hotfix'

export const describe = 'runs a hotfix'

type EthstatsArgv = UpgradeArgv & {}

export const builder = (argv: yargs.Argv) => {
return argv
}

export const handler = async (argv: EthstatsArgv) => {
try {
const kit = newKit(getFornoUrl(argv.celoEnv))
const governance = await kit.contracts.getGovernance()
const keys = getPrivateKeysFor(
AccountType.VALIDATOR,
fetchEnv(envVar.MNEMONIC),
parseInt(fetchEnv(envVar.VALIDATORS), 10)
)
const addresses = keys.map(privateKeyToAddress)

console.info('Add keys to ContractKit')
for (const key of keys) {
kit.addAccount(key)
}

// Here you'll want to assert the current state
// Example A: Update a var on a Celo Core Contract
// const attestations = await kit.contracts.getAttestations()
// const currentNumber = await attestations.attestationExpiryBlocks()
// if (currentNumber !== 727) {
// throw new Error(`Expected current number to be 727, but was ${currentNumber}`)
// }

// Example B: Repoint a Celo Core Contract proxy
// const validatorsProxyAddress = await kit.registry.addressFor(CeloContract.Validators)
// const currentValidatorsImplementationAddress = await getImplementationOfProxy(
// kit.web3,
// validatorsProxyAddress
// )
// const desiredImplementationAddress = '0xd18620a5eBE0235023602bB4d490E1e96703EddD'
// console.info('Current Implementation Address: ', currentValidatorsImplementationAddress)

// console.info('\nBuild Proposal')

const proposalBuilder = new ProposalBuilder(kit)

// Example A
// proposalBuilder.addJsonTx({
// contract: CeloContract.Attestations,
// function: 'setAttestationExpiryBlocks',
// // @ts-ignore
// args: [728],
// value: '0',
// })

// Example B
// proposalBuilder.addProxyRepointingTx(validatorsProxyAddress, desiredImplementationAddress)

const proposal = await proposalBuilder.build()
if (proposal.length === 0) {
console.error('\nPlease see examples in hotfix.ts and add transactions')
process.exit(1)
}
const proposalHash = proposalToHash(kit, proposal)

// If your proposal is just made of Celo Registry contract methods, you can print it out
console.info('Proposal: ', await proposalToJSON(kit, proposal))
console.info(`Proposal Hash: ${proposalHash.toString('hex')}`)

console.info('\nWhitelist the hotfix')
await concurrentMap(25, addresses, async (address, index) => {
try {
await governance.whitelistHotfix(proposalHash).sendAndWaitForReceipt({ from: address })
} catch (error) {
console.error(`Error whitelisting for validator ${index} (${address}): ${error}`)
}
})

let hotfixRecord = await governance.getHotfixRecord(proposalHash)
console.info('Hotfix Record: ', hotfixRecord)

console.info('\nApprove the hotfix')
await governance.approveHotfix(proposalHash).sendAndWaitForReceipt({ from: addresses[0] })
hotfixRecord = await governance.getHotfixRecord(proposalHash)
console.info('Hotfix Record: ', hotfixRecord)

// This is on master, but not on baklava yet
const canPass = await governance.isHotfixPassing(proposalHash)
const tally = await governance.hotfixWhitelistValidatorTally(proposalHash)

if (!canPass) {
throw new Error(`Hotfix cannot pass. Currently tally is ${tally}`)
}

console.info('\nPrepare the hotfix')
await governance.prepareHotfix(proposalHash).sendAndWaitForReceipt({ from: addresses[0] })
hotfixRecord = await governance.getHotfixRecord(proposalHash)
console.info('\nHotfix Record: ', hotfixRecord)

if (hotfixRecord.preparedEpoch.toNumber() === 0) {
console.error('Hotfix could not be prepared')
throw new Error()
}
console.info('\nExecute the hotfix')
await governance.executeHotfix(proposal).sendAndWaitForReceipt({ from: addresses[0] })

hotfixRecord = await governance.getHotfixRecord(proposalHash)
console.info('\nHotfix Record: ', hotfixRecord)

if (!hotfixRecord.executed) {
console.error('Hotfix could somehow not be executed')
throw new Error()
}

// Assert any state to be sure it worked

// Example A
// const newNumber = await attestations.attestationExpiryBlocks()
// if (newNumber !== 728) {
// throw new Error(`Expected current number to be 728, but was ${newNumber}`)
// }

// Example B
// const newValidatorsImplementationAddress = await getImplementationOfProxy(
// kit.web3,
// validatorsProxyAddress
// )
// if (!eqAddress(newValidatorsImplementationAddress, desiredImplementationAddress)) {
// throw new Error(
// `Expected new implementation address to be ${desiredImplementationAddress}, but was ${newValidatorsImplementationAddress}`
// )
// }

console.info('Hotfix successfully executed!')
process.exit(0)
} catch (error) {
console.error(error)
process.exit(1)
}
}
2 changes: 1 addition & 1 deletion packages/celotool/src/cmds/transactions/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async function fetchTx(
console.info(
`${parsedTransaction.callDetails.contract}#${
parsedTransaction.callDetails.function
}(${JSON.stringify(parsedTransaction.callDetails.parameters)}) ${parsedTransaction.tx.hash}`
}(${JSON.stringify(parsedTransaction.callDetails.paramMap)}) ${parsedTransaction.tx.hash}`
)

if (receipt.logs) {
Expand Down
4 changes: 2 additions & 2 deletions packages/celotool/src/e2e-tests/transfer_tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ describe('Transfer tests', function(this: any) {
})

describe('Transfer CeloDollars', () => {
const evmGasCost = 20303
const evmGasCost = 20325
describe('feeCurrency = CeloDollars >', () => {
testTransferToken({
expectedGas: evmGasCost + INTRINSIC_TX_GAS_COST + ADDITIONAL_INTRINSIC_TX_GAS_COST,
Expand Down Expand Up @@ -660,7 +660,7 @@ describe('Transfer tests', function(this: any) {
describe('Transfer CeloDollars', () => {
describe('feeCurrency = CeloDollars >', () => {
testTransferToken({
expectedGas: 75303,
expectedGas: 75325,
transferToken: CeloContract.StableToken,
feeToken: CeloContract.StableToken,
})
Expand Down
1 change: 1 addition & 0 deletions packages/celotool/src/lib/env-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export enum envVar {
ETHSTATS_DOCKER_IMAGE_TAG = 'ETHSTATS_DOCKER_IMAGE_TAG',
ETHSTATS_TRUSTED_ADDRESSES = 'ETHSTATS_TRUSTED_ADDRESSES',
ETHSTATS_BANNED_ADDRESSES = 'ETHSTATS_BANNED_ADDRESSES',
ETHSTATS_RESERVED_ADDRESSES = 'ETHSTATS_RESERVED_ADDRESSES',
FAUCET_GENESIS_ACCOUNTS = 'FAUCET_GENESIS_ACCOUNTS',
FAUCET_GENESIS_BALANCE = 'FAUCET_GENESIS_BALANCE',
ORACLE_GENESIS_BALANCE = 'ORACLE_GENESIS_BALANCE',
Expand Down
Loading

0 comments on commit dd1f8b3

Please sign in to comment.