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

Make styling more consistent in validator quick start and add password prompt to account:unlock #1731

Merged
merged 13 commits into from
Nov 15, 2019
Merged
9 changes: 6 additions & 3 deletions packages/cli/src/commands/account/unlock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { flags } from '@oclif/command'
import { cli } from 'cli-ux'
import { BaseCommand } from '../../base'
import { Flags } from '../../utils/command'

Expand All @@ -8,16 +9,18 @@ export default class Unlock extends BaseCommand {
static flags = {
...BaseCommand.flags,
account: Flags.address({ required: true }),
password: flags.string({ required: true }),
password: flags.string({ required: false }),
}

static examples = ['unlock --account 0x5409ed021d9299bf6814279a6a1411a7e866a631 --password 1234']
static examples = ['unlock --account 0x5409ed021d9299bf6814279a6a1411a7e866a631']

async run() {
const res = this.parse(Unlock)
// Unlock till geth exits
// Source: https://github.com/ethereum/go-ethereum/wiki/Management-APIs#personal_unlockaccount
const unlockDurationInMs = 0
this.web3.eth.personal.unlockAccount(res.flags.account, res.flags.password, unlockDurationInMs)
const password = res.flags.password || (await cli.prompt('Password', { type: 'hide' }))

this.web3.eth.personal.unlockAccount(res.flags.account, password, unlockDurationInMs)
}
}
13 changes: 12 additions & 1 deletion packages/cli/src/commands/node/synced.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { flags } from '@oclif/command'
import { BaseCommand } from '../../base'
import { nodeIsSynced } from '../../utils/helpers'

Expand All @@ -6,12 +7,22 @@ export default class NodeSynced extends BaseCommand {

static flags = {
...BaseCommand.flags,
verbose: flags.boolean({
description: 'output the full status if syncing',
}),
}

requireSynced = false

async run() {
this.parse(NodeSynced)
const res = this.parse(NodeSynced)

if (res.flags.verbose) {
const status = await this.web3.eth.isSyncing()
if (typeof status !== 'boolean') {
console.log(status)
}
}
console.log(await nodeIsSynced(this.web3))
}
}
4 changes: 2 additions & 2 deletions packages/docs/command-line-interface/account.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,10 @@ USAGE

OPTIONS
--account=0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d (required) Account Address
--password=password (required)
--password=password

EXAMPLE
unlock --account 0x5409ed021d9299bf6814279a6a1411a7e866a631 --password 1234
unlock --account 0x5409ed021d9299bf6814279a6a1411a7e866a631
```

_See code: [packages/cli/src/commands/account/unlock.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/account/unlock.ts)_
3 changes: 3 additions & 0 deletions packages/docs/command-line-interface/node.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ Check if the node is synced
```
USAGE
$ celocli node:synced

OPTIONS
--verbose output the full status if syncing
```

_See code: [packages/cli/src/commands/node/synced.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/node/synced.ts)_
2 changes: 1 addition & 1 deletion packages/docs/getting-started/running-a-full-node.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ Save this address to an environment variables, so that you can reference it belo

`$ export CELO_ACCOUNT_ADDRESS=<YOUR-ACCOUNT-ADDRESS>`

_Note: this environment variable will only persist while you have this terminal window open. If you want this environment variable to be available in the future, you can add it to your `~/.bash_profile_`
_Note: this environment variable will only persist while you have this terminal window open. If you want this environment variable to be available in the future, you can add it to your `~/.bash_profile_

## **Configure the node**

Expand Down
97 changes: 61 additions & 36 deletions packages/docs/getting-started/running-a-validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ It is recommended to run the validator node in an environment that facilitates a
A note about conventions:
The code you'll see on this page is bash commands and their output.

A $ signifies the bash prompt. Everything following it is the command you should run in a terminal. The $ isn't part of the command, so don't copy it.

When you see text in angle brackets &lt;&gt;, replace them and the text inside with your own value of what it refers to. Don't include the &lt;&gt; in the command.
{% endhint %}

Expand All @@ -56,128 +54,155 @@ If you are re-running these instructions, the Celo Docker image may have been up

Run:

`$ docker pull us.gcr.io/celo-testnet/celo-node:alfajores`
```bash
docker pull us.gcr.io/celo-testnet/celo-node:alfajores`
```

## **Create accounts**

Create and cd into the directory where you want to store the data and any other files needed to run your node. You can name this whatever you’d like, but here’s a default you can use:

```
$ mkdir celo-data-dir
$ cd celo-data-dir
```bash
mkdir celo-data-dir
cd celo-data-dir
```

Create two accounts, one for the Validator and one for Validator Group, and get their addresses if you don’t already have them. If you already have your accounts, you can skip this step.

To create your two accounts, run this command twice:

`` $ docker run -v `pwd`:/root/.celo --entrypoint /bin/sh -it us.gcr.io/celo-testnet/celo-node:alfajores -c "geth account new" ``
```bash
docker run -v $PWD:/root/.celo --entrypoint /bin/sh -it us.gcr.io/celo-testnet/celo-node:alfajores -c "geth account new"
```

It will prompt you for a passphrase, ask you to confirm it, and then will output your account address: `Address: {<YOUR-ACCOUNT-ADDRESS>}`

Let's save these addresses to environment variables, so that you can reference it later (don't include the braces):

```
$ export CELO_VALIDATOR_GROUP_ADDRESS=<YOUR-VALIDATOR-GROUP-ADDRESS>
$ export CELO_VALIDATOR_ADDRESS=<YOUR-VALIDATOR-ADDRESS>
```bash
export CELO_VALIDATOR_GROUP_ADDRESS=<YOUR-VALIDATOR-GROUP-ADDRESS>
export CELO_VALIDATOR_ADDRESS=<YOUR-VALIDATOR-ADDRESS>
```

In order to register the validator later on, generate a "proof of possession" - a signature proving you know your validator's BLS private key. Run this command:

`` $ docker run -v `pwd`:/root/.celo --entrypoint /bin/sh -it us.gcr.io/celo-testnet/celo-node:alfajores -c "geth account proof-of-possession $CELO_VALIDATOR_ADDRESS" ``
```bash
docker run -v $PWD:/root/.celo --entrypoint /bin/sh -it us.gcr.io/celo-testnet/celo-node:alfajores -c "geth account proof-of-possession $CELO_VALIDATOR_ADDRESS"
```

It will prompt you for the passphrase you've chosen for the validator account. Let's save the resulting proof-of-possession to an environment variable:

```
$ export CELO_VALIDATOR_POP=<YOUR-VALIDATOR-PROOF-OF-POSSESSION>
```bash
export CELO_VALIDATOR_POP=<YOUR-VALIDATOR-PROOF-OF-POSSESSION>
```

## Deploy the validator node

Initialize the docker container, building from an image for the network and initializing Celo with the genesis block:

`` $ docker run -v `pwd`:/root/.celo us.gcr.io/celo-testnet/celo-node:alfajores init /celo/genesis.json ``
```bash
docker run -v $PWD:/root/.celo us.gcr.io/celo-testnet/celo-node:alfajores init /celo/genesis.json
```

To participate in consensus, we need to set up our nodekey for our account. We can do so via the following command \(it will prompt you for your passphrase\):

`` $ docker run -v `pwd`:/root/.celo --entrypoint /bin/sh -it us.gcr.io/celo-testnet/celo-node:alfajores -c "geth account set-node-key $CELO_VALIDATOR_ADDRESS" ``
```bash
docker run -v $PWD:/root/.celo --entrypoint /bin/sh -it us.gcr.io/celo-testnet/celo-node:alfajores -c "geth account set-node-key $CELO_VALIDATOR_ADDRESS"
```

In order to allow the node to sync with the network, give it the address of existing nodes in the network:

`` $ docker run -v `pwd`:/root/.celo --entrypoint cp us.gcr.io/celo-testnet/celo-node:alfajores /celo/static-nodes.json /root/.celo/ ``
```bash
docker run -v $PWD:/root/.celo --entrypoint cp us.gcr.io/celo-testnet/celo-node:alfajores /celo/static-nodes.json /root/.celo/
```

Start up the node:

`` $ docker run -p 127.0.0.1:8545:8545 -p 127.0.0.1:8546:8546 -p 30303:30303 -p 30303:30303/udp -v `pwd`:/root/.celo us.gcr.io/celo-testnet/celo-node:alfajores --verbosity 3 --networkid 44785 --syncmode full --rpc --rpcaddr 0.0.0.0 --rpcapi eth,net,web3,debug,admin,personal --maxpeers 1100 --mine --miner.verificationpool=https://us-central1-celo-testnet-production.cloudfunctions.net/handleVerificationRequestalfajores/v0.1/sms/ --etherbase $CELO_VALIDATOR_ADDRESS ``
```bash
docker run -p 127.0.0.1:8545:8545 -p 127.0.0.1:8546:8546 -p 30303:30303 -p 30303:30303/udp -v $PWD:/root/.celo us.gcr.io/celo-testnet/celo-node:alfajores --verbosity 3 --networkid 44785 --syncmode full --rpc --rpcaddr 0.0.0.0 --rpcapi eth,net,web3,debug,admin,personal --maxpeers 1100 --mine --miner.verificationpool=https://us-central1-celo-testnet-production.cloudfunctions.net/handleVerificationRequestalfajores/v0.1/sms/ --etherbase $CELO_VALIDATOR_ADDRESS
```

{% hint style="danger" %}
**Security**: The command line above includes the parameter `--rpcaddr 0.0.0.0` which makes the Celo Blockchain software listen for incoming RPC requests on all network adaptors. Exercise extreme caution in doing this when running outside Docker, as it means that any unlocked accounts and their funds may be accessed from other machines on the Internet. In the context of running a Docker container on your local machine, this together with the `docker -p` flags allows you to make RPC calls from outside the container, i.e from your local host, but not from outside your machine. Read more about [Docker Networking](https://docs.docker.com/network/network-tutorial-standalone/#use-user-defined-bridge-networks) here.
{% endhint %}

The `mine` flag does not mean the node starts mining blocks, but rather starts trying to participate in the BFT consensus protocol. It cannot do this until it gets elected -- so next we need to stand for election.
The `mine` flag will tell geth to try participating in the BFT consensus protocol, which is analogous to mining on the Ethereum PoW network. It will not be allowed to validate until it gets elected -- so next we need to stand for election.

The `networkid` parameter value of `44785` indicates we are connecting the Alfajores Testnet.

Now you may need to wait for your node to complete a full sync. You can check on the sync status with `celocli node:synced`. Your node will be fully synced when it has downloaded and processed the latest block, which you can see on the [Alfajores Testnet Stats](https://alfajores-ethstats.celo-testnet.org/) page.

## Obtain and lock up some Celo Gold for staking

Visit the [Alfajores Faucet](https://celo.org/build/faucet) to send **both** of your accounts some funds.

In a new tab, unlock your accounts so that you can send transactions. This only unlocks the accounts for the lifetime of the validator that's running, so be sure to unlock `$CELO_VALIDATOR_ADDRESS` again if your node gets restarted:

```
$ celocli account:unlock --account $CELO_VALIDATOR_GROUP_ADDRESS --password <YOUR_FIRST_PASSWORD>
$ celocli account:unlock --account $CELO_VALIDATOR_ADDRESS --password <YOUR_SECOND_PASSWORD>
```bash
# You will be prompted for your password.
celocli account:unlock --account $CELO_VALIDATOR_GROUP_ADDRESS
celocli account:unlock --account $CELO_VALIDATOR_ADDRESS
```

In a new tab, make a locked Gold account for both of your addresses by running the Celo CLI. This will allow you to stake Celo Gold, which is required to register a validator and validator groups:

```
$ celocli account:register --from $CELO_VALIDATOR_GROUP_ADDRESS --name <GROUP_NAME_OF_YOUR_CHOICE>
$ celocli account:register --from $CELO_VALIDATOR_ADDRESS --name <VALIDATOR_NAME_OF_YOUR_CHOICE>
```bash
celocli account:register --from $CELO_VALIDATOR_GROUP_ADDRESS --name <GROUP_NAME_OF_YOUR_CHOICE>
celocli account:register --from $CELO_VALIDATOR_ADDRESS --name <VALIDATOR_NAME_OF_YOUR_CHOICE>
```

Make a locked Gold commitment for both accounts in order to secure the right to register a validator and validator group. The current requirement is 1 Celo Gold with a notice period of 60 days. If you choose to stake more gold, or a longer notice period, be sure to use those values below:

```
$ celocli lockedgold:lockup --from $CELO_VALIDATOR_GROUP_ADDRESS --goldAmount 1000000000000000000 --noticePeriod 5184000
$ celocli lockedgold:lockup --from $CELO_VALIDATOR_ADDRESS --goldAmount 1000000000000000000 --noticePeriod 5184000
```bash
celocli lockedgold:lockup --from $CELO_VALIDATOR_GROUP_ADDRESS --goldAmount 1000000000000000000 --noticePeriod 5184000
celocli lockedgold:lockup --from $CELO_VALIDATOR_ADDRESS --goldAmount 1000000000000000000 --noticePeriod 5184000
```

## Run for election

In order to be elected as a validator, you will first need to register your group and validator and give them each an an ID, which people will know them by (e.g. `Awesome Validators Inc.` and `Alice's Awesome Validator`).

Register your validator group:

`$ celocli validatorgroup:register --id <GROUP_ID_OF_YOUR_CHOICE> --from $CELO_VALIDATOR_GROUP_ADDRESS --noticePeriod 5184000`
```bash
celocli validatorgroup:register --id <GROUP_ID_OF_YOUR_CHOICE> --from $CELO_VALIDATOR_GROUP_ADDRESS --noticePeriod 5184000
```

Register your validator:

`` $ celocli validator:register --id <VALIDATOR_ID_OF_YOUR_CHOICE> --from $CELO_VALIDATOR_ADDRESS --noticePeriod 5184000 --publicKey 0x`openssl rand -hex 64`$CELO_VALIDATOR_POP ``
```bash
celocli validator:register --id <VALIDATOR_ID_OF_YOUR_CHOICE> --from $CELO_VALIDATOR_ADDRESS --noticePeriod 5184000 --publicKey 0x`openssl rand -hex 64`$CELO_VALIDATOR_POP
```

{% hint style="info" %}
**Roadmap**: Note that the “publicKey” first part of the public key field is currently ignored, and thus can be set to any 128 character hex value. The rest is used for the BLS public key and proof-of-possession.
{% endhint %}

Affiliate your validator with your validator group. Note that you will not be a member of this group until the validator group accepts you:

`$ celocli validator:affiliation --set $CELO_VALIDATOR_GROUP_ADDRESS --from $CELO_VALIDATOR_ADDRESS`
```bash
celocli validator:affiliation --set $CELO_VALIDATOR_GROUP_ADDRESS --from $CELO_VALIDATOR_ADDRESS
```

Accept the affiliation:

`$ celocli validatorgroup:member --accept $CELO_VALIDATOR_ADDRESS --from $CELO_VALIDATOR_GROUP_ADDRESS`
```bash
celocli validatorgroup:member --accept $CELO_VALIDATOR_ADDRESS --from $CELO_VALIDATOR_GROUP_ADDRESS
```

Use both accounts to vote for your validator group:

```
$ celocli validatorgroup:vote --from $CELO_VALIDATOR_ADDRESS --for $CELO_VALIDATOR_GROUP_ADDRESS
$ celocli validatorgroup:vote --from $CELO_VALIDATOR_GROUP_ADDRESS --for $CELO_VALIDATOR_GROUP_ADDRESS
```bash
celocli validatorgroup:vote --from $CELO_VALIDATOR_ADDRESS --for $CELO_VALIDATOR_GROUP_ADDRESS
celocli validatorgroup:vote --from $CELO_VALIDATOR_GROUP_ADDRESS --for $CELO_VALIDATOR_GROUP_ADDRESS
```

You’re all set! Note that elections are finalized at the end of each epoch, roughly once an hour in the Alfajores Testnet. After that hour, if you get elected, your node will start participating BFT consensus and validating blocks.

You can inspect the current state of voting by running:

```text
$ celocli validatorgroup:list
```bash
celocli validatorgroup:list
```

If you find your validator still not getting elected you may need to faucet yourself more funds and bond a greater deposit to command more voting weight!
Expand Down