Merge PR #2040: Refactor Validator Account Types/Bech32 Prefixing

* Add new account bech32 prefixes with godocs

* Restructure spacing of existing account code

* Update account godocs

* More account godoc updates + new tm pub/addr helpers

* Update validator type to use new account types/bech32 prefixes

* Fix account documentation errors

* Update Bech32 prefix for consensus nodes

* Update Bech32 spec doc

* Fix account type tests

* Add missing account consensus functions, clear up godocs, and fix tests

* Add to TestRandBech32PubkeyConsistency check

* Update initialization of validator public keys

* Update query signing info command

* Implement new ConsAddress type with associated unit tests

* [WIP] Update stake and slashing parameters

* Update all calls to MustBech32ifyValPub

* [WIP] Validator operator API updates

* [WIP] Fix and update unit tests

* Fix gov logs (helping to debug failing tests)

* Fix gov tally

* Fix all broken x/ unit tests

* Update gaia app genesis address logic

* Fix linting errors

* Fix broken LCD tests

* Fix broken CLI tests

* Implement command to get validator address and pubkey from key name

* Add support for getting validator key information via REST endpoint

* Update PENDING log

* Update docs

* Revert GaiaGenTx.PubKey bech32 prefix

* Fix broken docs and cli tests

* Update genesis to use correct Bech32 (cons) prefix for pubkeys

* Update docs and unit tests to reflect new cosmos account bech32 prefix

* minor formatting
This commit is contained in:
Alexander Bezobchuk
2018-08-31 00:06:44 -04:00
committed by Rigel
parent dc0f13214d
commit 2d92803b9f
66 changed files with 1315 additions and 835 deletions
+3 -3
View File
@@ -710,15 +710,15 @@ definitions:
Address:
type: string
description: bech32 encoded addres
example: cosmosaccaddr:zgnkwr7eyyv643dllwfpdwensmgdtz89yu73zq
example: cosmos:zgnkwr7eyyv643dllwfpdwensmgdtz89yu73zq
ValidatorAddress:
type: string
description: bech32 encoded addres
example: cosmosvaladdr:zgnkwr7eyyv643dllwfpdwensmgdtz89yu73zq
example: cosmosval:zgnkwr7eyyv643dllwfpdwensmgdtz89yu73zq
PubKey:
type: string
description: bech32 encoded public key
example: cosmosaccpub:zgnkwr7eyyv643dllwfpdwensmgdtz89yu73zq
example: cosmospub:zgnkwr7eyyv643dllwfpdwensmgdtz89yu73zq
ValidatorPubKey:
type: string
description: bech32 encoded public key
+1 -1
View File
@@ -17,7 +17,7 @@ Once you have the Cosmos app installed on your Ledger, and the Ledger is accessi
```bash
$ gaiacli keys add {{ .Key.Name }} --ledger
NAME: TYPE: ADDRESS: PUBKEY:
{{ .Key.Name }} ledger cosmosaccaddr1aw64xxr80lwqqdk8u2xhlrkxqaxamkr3e2g943 cosmosaccpub1addwnpepqvhs678gh9aqrjc2tg2vezw86csnvgzqq530ujkunt5tkuc7lhjkz5mj629
{{ .Key.Name }} ledger cosmos1aw64xxr80lwqqdk8u2xhlrkxqaxamkr3e2g943 cosmospub1addwnpepqvhs678gh9aqrjc2tg2vezw86csnvgzqq530ujkunt5tkuc7lhjkz5mj629
```
This key will only be accessible while the Ledger is plugged in and unlocked. To send some coins with this key, run the following:
+1 -1
View File
@@ -186,7 +186,7 @@ data = {
"text": "I hereby claim I am ABC on Keybase!"
}
cosmosSignBytes(data, "cosmosaccaddr1pvsch6cddahhrn5e8ekw0us50dpnugwnlfngt3")
cosmosSignBytes(data, "cosmos1pvsch6cddahhrn5e8ekw0us50dpnugwnlfngt3")
> "0x7fc4a495473045022100dec81a9820df0102381cdbf7e8b0f1e2cb64c58e0ecda1324543742e0388e41a02200df37905a6505c1b56a404e23b7473d2c0bc5bcda96771d2dda59df6ed2b98f8"
```
+12 -12
View File
@@ -71,13 +71,13 @@ This API exposes all functionality needed for key creation, signing and manageme
"account":[
{
"name":"monkey",
"address":"cosmosaccaddr1fedh326uxqlxs8ph9ej7cf854gz7fd5zlym5pd",
"pub_key":"cosmosaccpub1zcjduc3q8s8ha96ry4xc5xvjp9tr9w9p0e5lk5y0rpjs5epsfxs4wmf72x3shvus0t"
"address":"cosmos1fedh326uxqlxs8ph9ej7cf854gz7fd5zlym5pd",
"pub_key":"cosmospub1zcjduc3q8s8ha96ry4xc5xvjp9tr9w9p0e5lk5y0rpjs5epsfxs4wmf72x3shvus0t"
},
{
"name":"test",
"address":"cosmosaccaddr1thlqhjqw78zvcy0ua4ldj9gnazqzavyw4eske2",
"pub_key":"cosmosaccpub1zcjduc3qyx6hlf825jcnj39adpkaxjer95q7yvy25yhfj3dmqy2ctev0rxmse9cuak"
"address":"cosmos1thlqhjqw78zvcy0ua4ldj9gnazqzavyw4eske2",
"pub_key":"cosmospub1zcjduc3qyx6hlf825jcnj39adpkaxjer95q7yvy25yhfj3dmqy2ctev0rxmse9cuak"
}
],
"block_height":5241
@@ -125,8 +125,8 @@ Returns on success:
"error":"",
"result":{
"name":"test",
"address":"cosmosaccaddr1thlqhjqw78zvcy0ua4ldj9gnazqzavyw4eske2",
"pub_key":"cosmosaccpub1zcjduc3qyx6hlf825jcnj39adpkaxjer95q7yvy25yhfj3dmqy2ctev0rxmse9cuak"
"address":"cosmos1thlqhjqw78zvcy0ua4ldj9gnazqzavyw4eske2",
"pub_key":"cosmospub1zcjduc3qyx6hlf825jcnj39adpkaxjer95q7yvy25yhfj3dmqy2ctev0rxmse9cuak"
}
}
```
@@ -588,7 +588,7 @@ The GovernanceAPI exposes all functionality needed for casting votes on plain te
"description": "string",
// PlainTextProposal supported now. SoftwareUpgradeProposal and other types may be supported soon
"proposal_type": "string",
// A cosmosaccaddr address
// A cosmos address
"proposer": "string",
"initial_deposit": [
{
@@ -689,7 +689,7 @@ The GovernanceAPI exposes all functionality needed for casting votes on plain te
"error":"",
"result":{
"amount": {"atom": 150},
"depositer": "cosmosaccaddr1fedh326uxqlxs8ph9ej7cf854gz7fd5zlym5pd",
"depositer": "cosmos1fedh326uxqlxs8ph9ej7cf854gz7fd5zlym5pd",
"proposal-id": 16
}
}
@@ -731,12 +731,12 @@ The GovernanceAPI exposes all functionality needed for casting votes on plain te
"result": [
{
"proposal-id": 1,
"voter": "cosmosaccaddr1fedh326uxqlxs8ph9ej7cf854gz7fd5zlym5pd",
"voter": "cosmos1fedh326uxqlxs8ph9ej7cf854gz7fd5zlym5pd",
"option": "no_with_veto"
},
{
"proposal-id": 1,
"voter": "cosmosaccaddr1849m9wncrqp6v4tkss6a3j8uzvuv0cp7f75lrq",
"voter": "cosmos1849m9wncrqp6v4tkss6a3j8uzvuv0cp7f75lrq",
"option": "yes"
},
]
@@ -761,7 +761,7 @@ The GovernanceAPI exposes all functionality needed for casting votes on plain te
"sequence": 0,
"gas": 0
},
// A cosmosaccaddr address
// A cosmos address
"voter": "string",
// Value of the vote option `Yes`, `No` `Abstain`, `NoWithVeto`
"option": "string",
@@ -794,7 +794,7 @@ The GovernanceAPI exposes all functionality needed for casting votes on plain te
"error":"",
"result":{
"proposal-id": 1,
"voter": "cosmosaccaddr1fedh326uxqlxs8ph9ej7cf854gz7fd5zlym5pd",
"voter": "cosmos1fedh326uxqlxs8ph9ej7cf854gz7fd5zlym5pd",
"option": "no_with_veto"
}
}
+43 -33
View File
@@ -18,17 +18,21 @@
There are three types of key representations that are used:
- `cosmosaccaddr`
- `cosmos`
- Derived from account keys generated by `gaiacli keys add`
- Used to receive funds
- e.g. `cosmosaccaddr15h6vd5f0wqps26zjlwrc6chah08ryu4hzzdwhc`
- `cosmosaccpub`
- e.g. `cosmos15h6vd5f0wqps26zjlwrc6chah08ryu4hzzdwhc`
* `cosmosval`
* Used to associate a validator to it's operator
* Used to invoke staking commands
* e.g. `cosmosval1carzvgq3e6y3z5kz5y6gxp3wpy3qdrv928vyah`
- `cosmospub`
- Derived from account keys generated by `gaiacli keys add`
- e.g. `cosmosaccpub1zcjduc3q7fu03jnlu2xpl75s2nkt7krm6grh4cc5aqth73v0zwmea25wj2hsqhlqzm`
- `cosmosvalpub`
- e.g. `cosmospub1zcjduc3q7fu03jnlu2xpl75s2nkt7krm6grh4cc5aqth73v0zwmea25wj2hsqhlqzm`
- `cosmosconspub`
- Generated when the node is created with `gaiad init`.
- Get this value with `gaiad tendermint show-validator`
- e.g. `cosmosvalpub1zcjduc3qcyj09qc03elte23zwshdx92jm6ce88fgc90rtqhjx8v0608qh5ssp0w94c`
- e.g. `cosmosconspub1zcjduepq0ms2738680y72v44tfyqm3c9ppduku8fs6sr73fx7m666sjztznqzp2emf`
#### Generate Keys
@@ -48,6 +52,12 @@ If you check your private keys, you'll now see `<account_name>`:
gaiacli keys show <account_name>
```
View the validator operator's address via:
```shell
gaiacli keys show <account_name> --bech=val
```
You can see all your available keys by typing:
```bash
@@ -68,18 +78,18 @@ We strongly recommend _NOT_ using the same passphrase for multiple keys. The Ten
#### Get Tokens
The best way to get tokens is from the [Cosmos Testnet Faucet](https://faucetcosmos.network). If the faucet is not working for you, try asking [#cosmos-validators](https://riot.im/app/#/room/#cosmos-validators:matrix.org). The faucet needs the `cosmosaccaddr` from the account you wish to use for staking.
The best way to get tokens is from the [Cosmos Testnet Faucet](https://faucetcosmos.network). If the faucet is not working for you, try asking [#cosmos-validators](https://riot.im/app/#/room/#cosmos-validators:matrix.org). The faucet needs the `cosmos` from the account you wish to use for staking.
#### Query Account balance
After receiving tokens to your address, you can view your account's balance by typing:
```bash
gaiacli account <account_cosmosaccaddr>
gaiacli account <account_cosmos>
```
::: warning Note
When you query an account balance with zero tokens, you will get this error: `No account with address <account_cosmosaccaddr> was found in the state.` This can also happen if you fund the account before your node has fully synced with the chain. These are both normal.
When you query an account balance with zero tokens, you will get this error: `No account with address <account_cosmos> was found in the state.` This can also happen if you fund the account before your node has fully synced with the chain. These are both normal.
:::
@@ -90,7 +100,7 @@ gaiacli send \
--amount=10faucetToken \
--chain-id=<chain_id> \
--name=<key_name> \
--to=<destination_cosmosaccaddr>
--to=<destination_cosmos>
```
::: warning Note
@@ -106,14 +116,14 @@ Gas estimate might be inaccurate as state changes could occur in between the end
Now, view the updated balances of the origin and destination accounts:
```bash
gaiacli account <account_cosmosaccaddr>
gaiacli account <destination_cosmosaccaddr>
gaiacli account <account_cosmos>
gaiacli account <destination_cosmos>
```
You can also check your balance at a given block by using the `--block` flag:
```bash
gaiacli account <account_cosmosaccaddr> --block=<block_height>
gaiacli account <account_cosmos> --block=<block_height>
```
### Staking
@@ -137,7 +147,7 @@ gaiacli stake validators
If you want to get the information of a single validator you can check it with:
```bash
gaiacli stake validator <account_cosmosaccaddr>
gaiacli stake validator <account_cosmosval>
```
#### Bond Tokens
@@ -164,14 +174,14 @@ Once submitted a delegation to a validator, you can see it's information by usin
```bash
gaiacli stake delegation \
--address-delegator=<account_cosmosaccaddr> \
--address-validator=$(gaiad tendermint show-validator)
--address-delegator=<account_cosmos> \
--validator=<account_cosmosval>
```
Or if you want to check all your current delegations with disctinct validators:
```bash
gaiacli stake delegations <account_cosmosaccaddr>
gaiacli stake delegations <account_cosmos>
```
You can also get previous delegation(s) status by adding the `--height` flag.
@@ -182,7 +192,7 @@ If for any reason the validator misbehaves, or you just want to unbond a certain
```bash
gaiacli stake unbond begin \
--address-validator=$(gaiad tendermint show-validator) \
--validator=<account_cosmosval> \
--shares-percent=100 \
--from=<key_name> \
--chain-id=<chain_id>
@@ -192,7 +202,7 @@ Later you must complete the unbonding process by using the `gaiacli stake unbond
```bash
gaiacli stake unbond complete \
--address-validator=$(gaiad tendermint show-validator) \
--validator=<account_cosmosval> \
--from=<key_name> \
--chain-id=<chain_id>
```
@@ -203,14 +213,14 @@ Once you begin an unbonding-delegation, you can see it's information by using th
```bash
gaiacli stake unbonding-delegation \
--address-delegator=<account_cosmosaccaddr> \
--address-validator=$(gaiad tendermint show-validator) \
--address-delegator=<account_cosmos> \
--validator=<account_cosmosval> \
```
Or if you want to check all your current unbonding-delegations with disctinct validators:
```bash
gaiacli stake unbonding-delegations <account_cosmosaccaddr>
gaiacli stake unbonding-delegations <account_cosmos>
```
You can also get previous unbonding-delegation(s) status by adding the `--height` flag.
@@ -221,8 +231,8 @@ A redelegation is a type delegation that allows you to bond illiquid tokens from
```bash
gaiacli stake redelegate begin \
--address-validator-source=$(gaiad tendermint show-validator) \
--address-validator-dest=<account_cosmosaccaddr> \
--address-validator-source=<account_cosmosval> \
--address-validator-dest=<account_cosmosval> \
--shares-percent=50 \
--from=<key_name> \
--chain-id=<chain_id>
@@ -234,7 +244,7 @@ Later you must complete the redelegation process by using the `gaiacli stake red
```bash
gaiacli stake unbond complete \
--address-validator=$(gaiad tendermint show-validator) \
--validator=<account_cosmosval> \
--from=<key_name> \
--chain-id=<chain_id>
```
@@ -245,15 +255,15 @@ Once you begin an redelegation, you can see it's information by using the follow
```bash
gaiacli stake redelegation \
--address-delegator=<account_cosmosaccaddr> \
--address-validator-source=$(gaiad tendermint show-validator) \
--address-validator-dest=<account_cosmosaccaddr> \
--address-delegator=<account_cosmos> \
--address-validator-source=<account_cosmosval> \
--address-validator-dest=<account_cosmosval> \
```
Or if you want to check all your current unbonding-delegations with disctinct validators:
```bash
gaiacli stake redelegations <account_cosmosaccaddr>
gaiacli stake redelegations <account_cosmos>
```
You can also get previous redelegation(s) status by adding the `--height` flag.
@@ -286,7 +296,7 @@ gaiacli gov submit-proposal \
--title=<title> \
--description=<description> \
--type=<Text/ParameterChange/SoftwareUpgrade> \
--proposer=<account_cosmosaccaddr> \
--proposer=<account_cosmos> \
--deposit=<40steak> \
--from=<name> \
--chain-id=<chain_id>
@@ -316,7 +326,7 @@ In order for a proposal to be broadcasted to the network, the amount deposited m
```bash
gaiacli gov deposit \
--proposal-id=<proposal_id> \
--depositer=<account_cosmosaccaddr> \
--depositer=<account_cosmos> \
--deposit=<200steak> \
--from=<name> \
--chain-id=<chain_id>
@@ -331,7 +341,7 @@ After a proposal's deposit reaches the `MinDeposit` value, the voting period ope
```bash
gaiacli gov vote \
--proposal-id=<proposal_id> \
--voter=<account_cosmosaccaddr> \
--voter=<account_cosmos> \
--option=<Yes/No/NoWithVeto/Abstain> \
--from=<name> \
--chain-id=<chain_id>
@@ -344,7 +354,7 @@ Check the vote with the option you just submitted:
```bash
gaiacli gov query-vote \
--proposal-id=<proposal_id> \
--voter=<account_cosmosaccaddr>
--voter=<account_cosmos>
```
#### Query Parameters
+13 -14
View File
@@ -1,25 +1,24 @@
# Bech32 on Cosmos
The Cosmos network prefers to use the Bech32 address format whereever users must handle binary data. Bech32 encoding provides robust integrity checks on data and the human readable part(HRP) provides contextual hints that can assist UI developers with providing informative error messages.
The Cosmos network prefers to use the Bech32 address format wherever users must handle binary data. Bech32 encoding provides robust integrity checks on data and the human readable part(HRP) provides contextual hints that can assist UI developers with providing informative error messages.
In the Cosmos network, keys and addresses may refer to a number of different roles in the network like accounts, validators etc.
## HRP table
## HRP table
| HRP | Definition |
| ------------- |:-------------:|
| `cosmos` | Cosmos Account Address |
| `cosmospub` | Cosmos Account Public Key |
| `cosmosval` | Cosmos Validator Consensus Address |
| `cosmosvalpub`| Cosmos Validator Consensus Public Key|
| HRP | Definition |
|---------------|--------------------------------------|
| cosmos | Cosmos Account Address |
| cosmospub | Cosmos Account Public Key |
| cosmoscons | Cosmos Consensus Address |
| cosmosconspub | Cosmos Consensus Public Key |
| cosmosval | Cosmos Validator Operator Address |
| cosmosvalpub | Cosmos Validator Operator Public Key |
## Encoding
While all user facing interfaces to Cosmos software should exposed bech32 interfaces, many internal interfaces encode binary value in hex or base64 encoded form.
While all user facing interfaces to Cosmos software should exposed Bech32 interfaces, many internal interfaces encode binary value in hex or base64 encoded form.
To covert between other binary reprsentation of addresses and keys, it is important to first apply the Amino enocoding process before bech32 encoding.
To covert between other binary representation of addresses and keys, it is important to first apply the Amino encoding process before bech32 encoding.
A complete implementation of the Amino serialization format is unncessary in most cases. Simply prepending bytes from this [table](https://github.com/tendermint/tendermint/blob/master/docs/spec/blockchain/encoding.md#public-key-cryptography) to the bytestring payload before bech32 encoding will sufficient for compatible representation.
 
A complete implementation of the Amino serialization format is unnecessary in most cases. Simply prepending bytes from this [table](https://github.com/tendermint/tendermint/blob/master/docs/spec/blockchain/encoding.md#public-key-cryptography) to the byte string payload before bech32 encoding will sufficient for compatible representation.
+7 -6
View File
@@ -77,13 +77,14 @@ We view testnet participation as a great way to signal to the community that you
In short, there are two types of keys:
- **Tendermint Key**: This is a unique key used to sign block hashes. It is associated with a public key `cosmosvalpub`.
+ Generated when the node is created with gaiad init.
+ Get this value with gaiad tendermint show_validator
+M e.g. cosmosvalpub1zcjduc3qcyj09qc03elte23zwshdx92jm6ce88fgc90rtqhjx8v0608qh5ssp0w94c
- **Application keys**: These keys are created from the application and used to sign transactions. As a validator, you will probably use one key to sign staking-related transactions, and another key to sign governance-related transactions. Application keys are associated with a public key `cosmosaccpub` and an address `cosmosaccaddr`. Both are derived from account keys generated by `gaiacli keys add`.
* **Tendermint Key**: This is a unique key used to sign block hashes. It is associated with a public key `cosmosconspub`.
* Generated when the node is created with gaiad init.
* Get this value with `gaiad tendermint show-validator`
e.g. `cosmosconspub1zcjduc3qcyj09qc03elte23zwshdx92jm6ce88fgc90rtqhjx8v0608qh5ssp0w94c`
* **Application keys**: These keys are created from the application and used to sign transactions. As a validator, you will probably use one key to sign staking-related transactions, and another key to sign governance-related transactions. Application keys are associated with a public key `cosmospub` and an address `cosmos`. Both are derived from account keys generated by `gaiacli keys add`.
* Note: A validator's operator key is directly tied to an application key, but
uses reserved prefixes solely for this purpose: `cosmosval` and `cosmosvalpub`
### What are the different states a validator can be in?
+7 -7
View File
@@ -16,7 +16,7 @@ If you want to become a validator for the Hub's `mainnet`, you should [research
### Create Your Validator
Your `cosmosvalpub` can be used to create a new validator by staking tokens. You can find your validator pubkey by running:
Your `cosmosconspub` can be used to create a new validator by staking tokens. You can find your validator pubkey by running:
```bash
gaiad tendermint show-validator
@@ -32,7 +32,7 @@ Don't use more `steak` thank you have! You can always get more by using the [Fau
gaiacli stake create-validator \
--amount=5steak \
--pubkey=$(gaiad tendermint show-validator) \
--address-validator=<account_cosmosaccaddr>
--address-validator=<account_cosmosval>
--moniker="choose a moniker" \
--chain-id=<chain_id> \
--name=<key_name>
@@ -46,7 +46,7 @@ The `--identity` can be used as to verify identity with systems like Keybase or
```bash
gaiacli stake edit-validator
--validator=<account_cosmosaccaddr>
--validator=<account_cosmos>
--moniker="choose a moniker" \
--website="https://cosmos.network" \
--identity=6A0D65E29A4CBC8E
@@ -60,7 +60,7 @@ gaiacli stake edit-validator
View the validator's information with this command:
```bash
gaiacli stake validator <account_cosmosaccaddr>
gaiacli stake validator <account_cosmos>
```
### Track Validator Signing Information
@@ -80,7 +80,7 @@ When a validator is "jailed" for downtime, you must submit an `Unjail` transacti
gaiacli stake unjail \
--from=<key_name> \
--chain-id=<chain_id>
--validator=<account_cosmosaccaddr> \
--validator=<account_cosmosval> \
--chain-id=gaia-6002
```
@@ -110,10 +110,10 @@ Here's how you can return the voting power back to your validator. First, if `ga
gaiad start
```
Wait for your full node to catch up to the latest block. Next, run the following command. Note that `<cosmosaccaddr>` is the address of your validator account, and `<name>` is the name of the validator account. You can find this info by running `gaiacli keys list`.
Wait for your full node to catch up to the latest block. Next, run the following command. Note that `<cosmos>` is the address of your validator account, and `<name>` is the name of the validator account. You can find this info by running `gaiacli keys list`.
```bash
gaiacli stake unjail <cosmosaccaddr> --chain-id=<chain_id> --name=<name>
gaiacli stake unjail <cosmos> --chain-id=<chain_id> --name=<name>
```
::: danger Warning