diff --git a/packages/cli/src/commands/account/unlock.ts b/packages/cli/src/commands/account/unlock.ts index 1544757fef0..5036b501811 100644 --- a/packages/cli/src/commands/account/unlock.ts +++ b/packages/cli/src/commands/account/unlock.ts @@ -1,4 +1,5 @@ import { flags } from '@oclif/command' +import { cli } from 'cli-ux' import { BaseCommand } from '../../base' import { Flags } from '../../utils/command' @@ -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) } } diff --git a/packages/cli/src/commands/node/synced.ts b/packages/cli/src/commands/node/synced.ts index f01e991f8f9..c66556f0cce 100644 --- a/packages/cli/src/commands/node/synced.ts +++ b/packages/cli/src/commands/node/synced.ts @@ -1,3 +1,4 @@ +import { flags } from '@oclif/command' import { BaseCommand } from '../../base' import { nodeIsSynced } from '../../utils/helpers' @@ -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)) } } diff --git a/packages/docs/command-line-interface/account.md b/packages/docs/command-line-interface/account.md index cedded67dd3..91f4cd511cf 100644 --- a/packages/docs/command-line-interface/account.md +++ b/packages/docs/command-line-interface/account.md @@ -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)_ diff --git a/packages/docs/command-line-interface/node.md b/packages/docs/command-line-interface/node.md index 6e5197f61c2..63a938881ca 100644 --- a/packages/docs/command-line-interface/node.md +++ b/packages/docs/command-line-interface/node.md @@ -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)_ diff --git a/packages/docs/getting-started/running-a-full-node.md b/packages/docs/getting-started/running-a-full-node.md index cf1c2c91292..95aae11f3b2 100644 --- a/packages/docs/getting-started/running-a-full-node.md +++ b/packages/docs/getting-started/running-a-full-node.md @@ -52,7 +52,7 @@ Save this address to an environment variables, so that you can reference it belo `$ export CELO_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** diff --git a/packages/docs/getting-started/running-a-validator.md b/packages/docs/getting-started/running-a-validator.md index ce3fafb0b91..7763df91187 100644 --- a/packages/docs/getting-started/running-a-validator.md +++ b/packages/docs/getting-started/running-a-validator.md @@ -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 <>, replace them and the text inside with your own value of what it refers to. Don't include the <> in the command. {% endhint %} @@ -56,102 +54,125 @@ 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: {}` 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= -$ export CELO_VALIDATOR_ADDRESS= +```bash +export CELO_VALIDATOR_GROUP_ADDRESS= +export CELO_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= +```bash +export CELO_VALIDATOR_POP= ``` ## 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 -$ celocli account:unlock --account $CELO_VALIDATOR_ADDRESS --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 -$ celocli account:register --from $CELO_VALIDATOR_ADDRESS --name +```bash +celocli account:register --from $CELO_VALIDATOR_GROUP_ADDRESS --name +celocli account:register --from $CELO_VALIDATOR_ADDRESS --name ``` 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 --from $CELO_VALIDATOR_GROUP_ADDRESS --noticePeriod 5184000` +```bash +celocli validatorgroup:register --id --from $CELO_VALIDATOR_GROUP_ADDRESS --noticePeriod 5184000 +``` Register your validator: -`` $ celocli validator:register --id --from $CELO_VALIDATOR_ADDRESS --noticePeriod 5184000 --publicKey 0x`openssl rand -hex 64`$CELO_VALIDATOR_POP `` +```bash +celocli validator:register --id --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. @@ -159,25 +180,29 @@ Register your validator: 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!