Merge branch 'develop' into cwgoes/update-tendermint-upstream
This commit is contained in:
commit
1d55673f1f
29
PENDING.md
29
PENDING.md
|
@ -13,10 +13,10 @@ BREAKING CHANGES
|
||||||
* [cli] [\#2061](https://github.com/cosmos/cosmos-sdk/issues/2061) changed proposalID in governance REST endpoints to proposal-id
|
* [cli] [\#2061](https://github.com/cosmos/cosmos-sdk/issues/2061) changed proposalID in governance REST endpoints to proposal-id
|
||||||
* [cli] [\#2014](https://github.com/cosmos/cosmos-sdk/issues/2014) `gaiacli advanced` no longer exists - to access `ibc`, `rest-server`, and `validator-set` commands use `gaiacli ibc`, `gaiacli rest-server`, and `gaiacli tendermint`, respectively
|
* [cli] [\#2014](https://github.com/cosmos/cosmos-sdk/issues/2014) `gaiacli advanced` no longer exists - to access `ibc`, `rest-server`, and `validator-set` commands use `gaiacli ibc`, `gaiacli rest-server`, and `gaiacli tendermint`, respectively
|
||||||
* [makefile] `get_vendor_deps` no longer updates lock file it just updates vendor directory. Use `update_vendor_deps` to update the lock file. [#2152](https://github.com/cosmos/cosmos-sdk/pull/2152)
|
* [makefile] `get_vendor_deps` no longer updates lock file it just updates vendor directory. Use `update_vendor_deps` to update the lock file. [#2152](https://github.com/cosmos/cosmos-sdk/pull/2152)
|
||||||
|
* [cli] [\#2221](https://github.com/cosmos/cosmos-sdk/issues/2221) All commands that
|
||||||
|
utilize a validator's operator address must now use the new Bech32 prefix,
|
||||||
|
`cosmosvaloper`.
|
||||||
* [cli] [\#2190](https://github.com/cosmos/cosmos-sdk/issues/2190) `gaiacli init --gen-txs` is now `gaiacli init --with-txs` to reduce confusion
|
* [cli] [\#2190](https://github.com/cosmos/cosmos-sdk/issues/2190) `gaiacli init --gen-txs` is now `gaiacli init --with-txs` to reduce confusion
|
||||||
* [\#2040](https://github.com/cosmos/cosmos-sdk/issues/2040) All commands that utilize a validator's address must now use the new
|
|
||||||
bech32 prefix, `cosmosval`. A validator's Tendermint signing key and address
|
|
||||||
now use a new bech32 prefix, `cosmoscons`.
|
|
||||||
|
|
||||||
* Gaia
|
* Gaia
|
||||||
* Make the transient store key use a distinct store key. [#2013](https://github.com/cosmos/cosmos-sdk/pull/2013)
|
* Make the transient store key use a distinct store key. [#2013](https://github.com/cosmos/cosmos-sdk/pull/2013)
|
||||||
|
@ -25,10 +25,14 @@ BREAKING CHANGES
|
||||||
* [x/stake, x/slashing] [#1305](https://github.com/cosmos/cosmos-sdk/issues/1305) - Rename "revoked" to "jailed"
|
* [x/stake, x/slashing] [#1305](https://github.com/cosmos/cosmos-sdk/issues/1305) - Rename "revoked" to "jailed"
|
||||||
* [x/stake] [#1676] Revoked and jailed validators put into the unbonding state
|
* [x/stake] [#1676] Revoked and jailed validators put into the unbonding state
|
||||||
* [x/stake] [#1877] Redelegations/unbonding-delegation from unbonding validator have reduced time
|
* [x/stake] [#1877] Redelegations/unbonding-delegation from unbonding validator have reduced time
|
||||||
* [x/stake] [\#2040](https://github.com/cosmos/cosmos-sdk/issues/2040) Validator operator type has now changed to `sdk.ValAddress`
|
* [x/stake] [\#2040](https://github.com/cosmos/cosmos-sdk/issues/2040) Validator
|
||||||
* A new bech32 prefix has been introduced for Tendermint signing keys and
|
operator type has now changed to `sdk.ValAddress`
|
||||||
addresses, `cosmosconspub` and `cosmoscons` respectively.
|
* [x/stake] [\#2221](https://github.com/cosmos/cosmos-sdk/issues/2221) New
|
||||||
* [x/gov] \#2195 Made governance use BFT Time instead of Block Heights for deposit and voting periods.
|
Bech32 prefixes have been introduced for a validator's consensus address and
|
||||||
|
public key: `cosmosvalcons` and `cosmosvalconspub` respectively. Also, existing Bech32 prefixes have been
|
||||||
|
renamed for accounts and validator operators:
|
||||||
|
* `cosmosaccaddr` / `cosmosaccpub` => `cosmos` / `cosmospub`
|
||||||
|
* `cosmosvaladdr` / `cosmosvalpub` => `cosmosvaloper` / `cosmosvaloperpub`
|
||||||
|
|
||||||
* SDK
|
* SDK
|
||||||
* [core] \#2219 Update to Tendermint 0.24.0
|
* [core] \#2219 Update to Tendermint 0.24.0
|
||||||
|
@ -49,10 +53,11 @@ BREAKING CHANGES
|
||||||
FEATURES
|
FEATURES
|
||||||
|
|
||||||
* Gaia REST API (`gaiacli advanced rest-server`)
|
* Gaia REST API (`gaiacli advanced rest-server`)
|
||||||
* [lcd] Endpoints to query staking pool and params
|
* [gaia-lite] Endpoints to query staking pool and params
|
||||||
* [lcd] [\#2110](https://github.com/cosmos/cosmos-sdk/issues/2110) Add support for `simulate=true` requests query argument to endpoints that send txs to run simulations of transactions
|
* [gaia-lite] [\#2110](https://github.com/cosmos/cosmos-sdk/issues/2110) Add support for `simulate=true` requests query argument to endpoints that send txs to run simulations of transactions
|
||||||
* [lcd] [\#966](https://github.com/cosmos/cosmos-sdk/issues/966) Add support for `generate_only=true` query argument to generate offline unsigned transactions
|
* [gaia-lite] [\#966](https://github.com/cosmos/cosmos-sdk/issues/966) Add support for `generate_only=true` query argument to generate offline unsigned transactions
|
||||||
* [lcd] [\#1953](https://github.com/cosmos/cosmos-sdk/issues/1953) Add /sign endpoint to sign transactions generated with `generate_only=true`.
|
* [gaia-lite] [\#1953](https://github.com/cosmos/cosmos-sdk/issues/1953) Add /sign endpoint to sign transactions generated with `generate_only=true`.
|
||||||
|
* [gaia-lite] [\#1954](https://github.com/cosmos/cosmos-sdk/issues/1954) Add /broadcast endpoint to broadcast transactions signed by the /sign endpoint.
|
||||||
|
|
||||||
* Gaia CLI (`gaiacli`)
|
* Gaia CLI (`gaiacli`)
|
||||||
* [cli] Cmds to query staking pool and params
|
* [cli] Cmds to query staking pool and params
|
||||||
|
@ -65,6 +70,7 @@ FEATURES
|
||||||
* [cli] [\#2204](https://github.com/cosmos/cosmos-sdk/issues/2204) Support generating and broadcasting messages with multiple signatures via command line:
|
* [cli] [\#2204](https://github.com/cosmos/cosmos-sdk/issues/2204) Support generating and broadcasting messages with multiple signatures via command line:
|
||||||
* [\#966](https://github.com/cosmos/cosmos-sdk/issues/966) Add --generate-only flag to build an unsigned transaction and write it to STDOUT.
|
* [\#966](https://github.com/cosmos/cosmos-sdk/issues/966) Add --generate-only flag to build an unsigned transaction and write it to STDOUT.
|
||||||
* [\#1953](https://github.com/cosmos/cosmos-sdk/issues/1953) New `sign` command to sign transactions generated with the --generate-only flag.
|
* [\#1953](https://github.com/cosmos/cosmos-sdk/issues/1953) New `sign` command to sign transactions generated with the --generate-only flag.
|
||||||
|
* [\#1954](https://github.com/cosmos/cosmos-sdk/issues/1954) New `broadcast` command to broadcast transactions generated offline and signed with the `sign` command.
|
||||||
|
|
||||||
* Gaia
|
* Gaia
|
||||||
* [cli] #2170 added ability to show the node's address via `gaiad tendermint show-address`
|
* [cli] #2170 added ability to show the node's address via `gaiad tendermint show-address`
|
||||||
|
@ -93,6 +99,7 @@ IMPROVEMENTS
|
||||||
* [x/auth] Signature verification's gas cost now accounts for pubkey type. [#2046](https://github.com/tendermint/tendermint/pull/2046)
|
* [x/auth] Signature verification's gas cost now accounts for pubkey type. [#2046](https://github.com/tendermint/tendermint/pull/2046)
|
||||||
* [x/stake] [x/slashing] Ensure delegation invariants to jailed validators [#1883](https://github.com/cosmos/cosmos-sdk/issues/1883).
|
* [x/stake] [x/slashing] Ensure delegation invariants to jailed validators [#1883](https://github.com/cosmos/cosmos-sdk/issues/1883).
|
||||||
* [x/stake] Improve speed of GetValidator, which was shown to be a performance bottleneck. [#2046](https://github.com/tendermint/tendermint/pull/2200)
|
* [x/stake] Improve speed of GetValidator, which was shown to be a performance bottleneck. [#2046](https://github.com/tendermint/tendermint/pull/2200)
|
||||||
|
* [genesis] \#2229 Ensure that there are no duplicate accounts in the genesis state.
|
||||||
* SDK
|
* SDK
|
||||||
* [tools] Make get_vendor_deps deletes `.vendor-new` directories, in case scratch files are present.
|
* [tools] Make get_vendor_deps deletes `.vendor-new` directories, in case scratch files are present.
|
||||||
* [spec] Added simple piggy bank distribution spec
|
* [spec] Added simple piggy bank distribution spec
|
||||||
|
|
|
@ -206,8 +206,8 @@ func TestValidators(t *testing.T) {
|
||||||
|
|
||||||
require.NotEqual(t, rpc.ResultValidatorsOutput{}, resultVals)
|
require.NotEqual(t, rpc.ResultValidatorsOutput{}, resultVals)
|
||||||
|
|
||||||
require.Contains(t, resultVals.Validators[0].Address.String(), "cosmosval")
|
require.Contains(t, resultVals.Validators[0].Address.String(), "cosmosvaloper")
|
||||||
require.Contains(t, resultVals.Validators[0].PubKey, "cosmosconspub")
|
require.Contains(t, resultVals.Validators[0].PubKey, "cosmosvalconspub")
|
||||||
|
|
||||||
// --
|
// --
|
||||||
|
|
||||||
|
@ -314,11 +314,12 @@ func TestIBCTransfer(t *testing.T) {
|
||||||
// TODO: query ibc egress packet state
|
// TODO: query ibc egress packet state
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCoinSendGenerateAndSign(t *testing.T) {
|
func TestCoinSendGenerateSignAndBroadcast(t *testing.T) {
|
||||||
name, password := "test", "1234567890"
|
name, password := "test", "1234567890"
|
||||||
addr, seed := CreateAddr(t, "test", password, GetKeyBase(t))
|
addr, seed := CreateAddr(t, "test", password, GetKeyBase(t))
|
||||||
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr})
|
cleanup, _, port := InitializeTestLCD(t, 1, []sdk.AccAddress{addr})
|
||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
acc := getAccount(t, port, addr)
|
||||||
|
|
||||||
// generate TX
|
// generate TX
|
||||||
res, body, _ := doSendWithGas(t, port, seed, name, password, addr, 0, 0, "?generate_only=true")
|
res, body, _ := doSendWithGas(t, port, seed, name, password, addr, 0, 0, "?generate_only=true")
|
||||||
|
@ -329,10 +330,10 @@ func TestCoinSendGenerateAndSign(t *testing.T) {
|
||||||
require.Equal(t, msg.Msgs[0].Type(), "bank")
|
require.Equal(t, msg.Msgs[0].Type(), "bank")
|
||||||
require.Equal(t, msg.Msgs[0].GetSigners(), []sdk.AccAddress{addr})
|
require.Equal(t, msg.Msgs[0].GetSigners(), []sdk.AccAddress{addr})
|
||||||
require.Equal(t, 0, len(msg.Signatures))
|
require.Equal(t, 0, len(msg.Signatures))
|
||||||
|
gasEstimate := msg.Fee.Gas
|
||||||
|
|
||||||
// sign tx
|
// sign tx
|
||||||
var signedMsg auth.StdTx
|
var signedMsg auth.StdTx
|
||||||
acc := getAccount(t, port, addr)
|
|
||||||
accnum := acc.GetAccountNumber()
|
accnum := acc.GetAccountNumber()
|
||||||
sequence := acc.GetSequence()
|
sequence := acc.GetSequence()
|
||||||
|
|
||||||
|
@ -346,13 +347,30 @@ func TestCoinSendGenerateAndSign(t *testing.T) {
|
||||||
}
|
}
|
||||||
json, err := cdc.MarshalJSON(payload)
|
json, err := cdc.MarshalJSON(payload)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
res, body = Request(t, port, "POST", "/sign", json)
|
res, body = Request(t, port, "POST", "/tx/sign", json)
|
||||||
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||||
require.Nil(t, cdc.UnmarshalJSON([]byte(body), &signedMsg))
|
require.Nil(t, cdc.UnmarshalJSON([]byte(body), &signedMsg))
|
||||||
require.Equal(t, len(msg.Msgs), len(signedMsg.Msgs))
|
require.Equal(t, len(msg.Msgs), len(signedMsg.Msgs))
|
||||||
require.Equal(t, msg.Msgs[0].Type(), signedMsg.Msgs[0].Type())
|
require.Equal(t, msg.Msgs[0].Type(), signedMsg.Msgs[0].Type())
|
||||||
require.Equal(t, msg.Msgs[0].GetSigners(), signedMsg.Msgs[0].GetSigners())
|
require.Equal(t, msg.Msgs[0].GetSigners(), signedMsg.Msgs[0].GetSigners())
|
||||||
require.Equal(t, 1, len(signedMsg.Signatures))
|
require.Equal(t, 1, len(signedMsg.Signatures))
|
||||||
|
|
||||||
|
// broadcast tx
|
||||||
|
broadcastPayload := struct {
|
||||||
|
Tx auth.StdTx `json:"tx"`
|
||||||
|
}{Tx: signedMsg}
|
||||||
|
json, err = cdc.MarshalJSON(broadcastPayload)
|
||||||
|
require.Nil(t, err)
|
||||||
|
res, body = Request(t, port, "POST", "/tx/broadcast", json)
|
||||||
|
require.Equal(t, http.StatusOK, res.StatusCode, body)
|
||||||
|
|
||||||
|
// check if tx was committed
|
||||||
|
var resultTx ctypes.ResultBroadcastTxCommit
|
||||||
|
require.Nil(t, cdc.UnmarshalJSON([]byte(body), &resultTx))
|
||||||
|
require.Equal(t, uint32(0), resultTx.CheckTx.Code)
|
||||||
|
require.Equal(t, uint32(0), resultTx.DeliverTx.Code)
|
||||||
|
require.Equal(t, gasEstimate, resultTx.DeliverTx.GasWanted)
|
||||||
|
require.Equal(t, gasEstimate, resultTx.DeliverTx.GasUsed)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestTxs(t *testing.T) {
|
func TestTxs(t *testing.T) {
|
||||||
|
@ -461,10 +479,11 @@ func TestValidatorsQuery(t *testing.T) {
|
||||||
// make sure all the validators were found (order unknown because sorted by operator addr)
|
// make sure all the validators were found (order unknown because sorted by operator addr)
|
||||||
foundVal := false
|
foundVal := false
|
||||||
pkBech := sdk.MustBech32ifyConsPub(pks[0])
|
pkBech := sdk.MustBech32ifyConsPub(pks[0])
|
||||||
if validators[0].PubKey == pkBech {
|
if validators[0].ConsPubKey == pkBech {
|
||||||
foundVal = true
|
foundVal = true
|
||||||
}
|
}
|
||||||
require.True(t, foundVal, "pkBech %v, operator %v", pkBech, validators[0].Operator)
|
|
||||||
|
require.True(t, foundVal, "pkBech %v, operator %v", pkBech, validators[0].OperatorAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidatorQuery(t *testing.T) {
|
func TestValidatorQuery(t *testing.T) {
|
||||||
|
@ -474,7 +493,7 @@ func TestValidatorQuery(t *testing.T) {
|
||||||
|
|
||||||
validator1Operator := sdk.ValAddress(pks[0].Address())
|
validator1Operator := sdk.ValAddress(pks[0].Address())
|
||||||
validator := getValidator(t, port, validator1Operator)
|
validator := getValidator(t, port, validator1Operator)
|
||||||
assert.Equal(t, validator.Operator, validator1Operator, "The returned validator does not hold the correct data")
|
assert.Equal(t, validator.OperatorAddr, validator1Operator, "The returned validator does not hold the correct data")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBonding(t *testing.T) {
|
func TestBonding(t *testing.T) {
|
||||||
|
@ -510,11 +529,11 @@ func TestBonding(t *testing.T) {
|
||||||
|
|
||||||
bondedValidators := getDelegatorValidators(t, port, addr)
|
bondedValidators := getDelegatorValidators(t, port, addr)
|
||||||
require.Len(t, bondedValidators, 1)
|
require.Len(t, bondedValidators, 1)
|
||||||
require.Equal(t, validator1Operator, bondedValidators[0].Operator)
|
require.Equal(t, validator1Operator, bondedValidators[0].OperatorAddr)
|
||||||
require.Equal(t, validator.DelegatorShares.Add(sdk.NewDec(60)).String(), bondedValidators[0].DelegatorShares.String())
|
require.Equal(t, validator.DelegatorShares.Add(sdk.NewDec(60)).String(), bondedValidators[0].DelegatorShares.String())
|
||||||
|
|
||||||
bondedValidator := getDelegatorValidator(t, port, addr, validator1Operator)
|
bondedValidator := getDelegatorValidator(t, port, addr, validator1Operator)
|
||||||
require.Equal(t, validator1Operator, bondedValidator.Operator)
|
require.Equal(t, validator1Operator, bondedValidator.OperatorAddr)
|
||||||
|
|
||||||
//////////////////////
|
//////////////////////
|
||||||
// testing unbonding
|
// testing unbonding
|
||||||
|
|
|
@ -152,7 +152,7 @@ func InitializeTestLCD(t *testing.T, nValidators int, initAddrs []sdk.AccAddress
|
||||||
|
|
||||||
var validatorsPKs []crypto.PubKey
|
var validatorsPKs []crypto.PubKey
|
||||||
|
|
||||||
// NOTE: It's bad practice to reuse public key address for the owner
|
// NOTE: It's bad practice to reuse public key address for the operator
|
||||||
// address but doing in the test for simplicity.
|
// address but doing in the test for simplicity.
|
||||||
var appGenTxs []json.RawMessage
|
var appGenTxs []json.RawMessage
|
||||||
for _, gdValidator := range genDoc.Validators {
|
for _, gdValidator := range genDoc.Validators {
|
||||||
|
|
|
@ -190,6 +190,11 @@ func (app *GaiaApp) initChainer(ctx sdk.Context, req abci.RequestInitChain) abci
|
||||||
slashing.InitGenesis(ctx, app.slashingKeeper, genesisState.StakeData)
|
slashing.InitGenesis(ctx, app.slashingKeeper, genesisState.StakeData)
|
||||||
|
|
||||||
gov.InitGenesis(ctx, app.govKeeper, genesisState.GovData)
|
gov.InitGenesis(ctx, app.govKeeper, genesisState.GovData)
|
||||||
|
err = GaiaValidateGenesisState(genesisState)
|
||||||
|
if err != nil {
|
||||||
|
// TODO find a way to do this w/o panics
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
return abci.ResponseInitChain{
|
return abci.ResponseInitChain{
|
||||||
Validators: validators,
|
Validators: validators,
|
||||||
|
|
|
@ -180,17 +180,25 @@ func GaiaAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (genesisState
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the genesis account, give'm few steaks and a buncha token with there name
|
// create the genesis account, give'm few steaks and a buncha token with there name
|
||||||
accAuth := auth.NewBaseAccountWithAddress(genTx.Address)
|
genaccs[i] = genesisAccountFromGenTx(genTx)
|
||||||
accAuth.Coins = sdk.Coins{
|
|
||||||
{genTx.Name + "Token", sdk.NewInt(1000)},
|
|
||||||
{"steak", freeFermionsAcc},
|
|
||||||
}
|
|
||||||
acc := NewGenesisAccount(&accAuth)
|
|
||||||
genaccs[i] = acc
|
|
||||||
stakeData.Pool.LooseTokens = stakeData.Pool.LooseTokens.Add(sdk.NewDecFromInt(freeFermionsAcc)) // increase the supply
|
stakeData.Pool.LooseTokens = stakeData.Pool.LooseTokens.Add(sdk.NewDecFromInt(freeFermionsAcc)) // increase the supply
|
||||||
|
|
||||||
// add the validator
|
// add the validator
|
||||||
if len(genTx.Name) > 0 {
|
if len(genTx.Name) > 0 {
|
||||||
|
stakeData = addValidatorToStakeData(genTx, stakeData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// create the final app state
|
||||||
|
genesisState = GenesisState{
|
||||||
|
Accounts: genaccs,
|
||||||
|
StakeData: stakeData,
|
||||||
|
GovData: gov.DefaultGenesisState(),
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func addValidatorToStakeData(genTx GaiaGenTx, stakeData stake.GenesisState) stake.GenesisState {
|
||||||
desc := stake.NewDescription(genTx.Name, "", "", "")
|
desc := stake.NewDescription(genTx.Name, "", "", "")
|
||||||
validator := stake.NewValidator(
|
validator := stake.NewValidator(
|
||||||
sdk.ValAddress(genTx.Address), sdk.MustGetConsPubKeyBech32(genTx.PubKey), desc,
|
sdk.ValAddress(genTx.Address), sdk.MustGetConsPubKeyBech32(genTx.PubKey), desc,
|
||||||
|
@ -205,21 +213,47 @@ func GaiaAppGenState(cdc *wire.Codec, appGenTxs []json.RawMessage) (genesisState
|
||||||
|
|
||||||
// create the self-delegation from the issuedDelShares
|
// create the self-delegation from the issuedDelShares
|
||||||
delegation := stake.Delegation{
|
delegation := stake.Delegation{
|
||||||
DelegatorAddr: sdk.AccAddress(validator.Operator),
|
DelegatorAddr: sdk.AccAddress(validator.OperatorAddr),
|
||||||
ValidatorAddr: validator.Operator,
|
ValidatorAddr: validator.OperatorAddr,
|
||||||
Shares: issuedDelShares,
|
Shares: issuedDelShares,
|
||||||
Height: 0,
|
Height: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
stakeData.Bonds = append(stakeData.Bonds, delegation)
|
stakeData.Bonds = append(stakeData.Bonds, delegation)
|
||||||
}
|
return stakeData
|
||||||
}
|
}
|
||||||
|
|
||||||
// create the final app state
|
func genesisAccountFromGenTx(genTx GaiaGenTx) GenesisAccount {
|
||||||
genesisState = GenesisState{
|
accAuth := auth.NewBaseAccountWithAddress(genTx.Address)
|
||||||
Accounts: genaccs,
|
accAuth.Coins = sdk.Coins{
|
||||||
StakeData: stakeData,
|
{genTx.Name + "Token", sdk.NewInt(1000)},
|
||||||
GovData: gov.DefaultGenesisState(),
|
{"steak", freeFermionsAcc},
|
||||||
|
}
|
||||||
|
return NewGenesisAccount(&accAuth)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GaiaValidateGenesisState ensures that the genesis state obeys the expected invariants
|
||||||
|
// TODO: No validators are both bonded and revoked (#2088)
|
||||||
|
// TODO: Error if there is a duplicate validator (#1708)
|
||||||
|
// TODO: Ensure all state machine parameters are in genesis (#1704)
|
||||||
|
func GaiaValidateGenesisState(genesisState GenesisState) (err error) {
|
||||||
|
err = validateGenesisStateAccounts(genesisState.Accounts)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensures that there are no duplicate accounts in the genesis state,
|
||||||
|
func validateGenesisStateAccounts(accs []GenesisAccount) (err error) {
|
||||||
|
addrMap := make(map[string]bool, len(accs))
|
||||||
|
for i := 0; i < len(accs); i++ {
|
||||||
|
acc := accs[i]
|
||||||
|
strAddr := string(acc.Address)
|
||||||
|
if _, ok := addrMap[strAddr]; ok {
|
||||||
|
return fmt.Errorf("Duplicate account in genesis state: Address %v", acc.Address)
|
||||||
|
}
|
||||||
|
addrMap[strAddr] = true
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,36 @@ import (
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/gov"
|
||||||
|
stake "github.com/cosmos/cosmos-sdk/x/stake"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func makeGenesisState(genTxs []GaiaGenTx) GenesisState {
|
||||||
|
// start with the default staking genesis state
|
||||||
|
stakeData := stake.DefaultGenesisState()
|
||||||
|
|
||||||
|
// get genesis flag account information
|
||||||
|
genaccs := make([]GenesisAccount, len(genTxs))
|
||||||
|
for i, genTx := range genTxs {
|
||||||
|
genaccs[i] = genesisAccountFromGenTx(genTx)
|
||||||
|
stakeData.Pool.LooseTokens = stakeData.Pool.LooseTokens.Add(sdk.NewDecFromInt(freeFermionsAcc)) // increase the supply
|
||||||
|
|
||||||
|
// add the validator
|
||||||
|
if len(genTx.Name) > 0 {
|
||||||
|
stakeData = addValidatorToStakeData(genTx, stakeData)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// create the final app state
|
||||||
|
return GenesisState{
|
||||||
|
Accounts: genaccs,
|
||||||
|
StakeData: stakeData,
|
||||||
|
GovData: gov.DefaultGenesisState(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestToAccount(t *testing.T) {
|
func TestToAccount(t *testing.T) {
|
||||||
priv := ed25519.GenPrivKey()
|
priv := ed25519.GenPrivKey()
|
||||||
addr := sdk.AccAddress(priv.PubKey().Address())
|
addr := sdk.AccAddress(priv.PubKey().Address())
|
||||||
|
@ -34,3 +60,16 @@ func TestGaiaAppGenState(t *testing.T) {
|
||||||
// TODO test with both one and two genesis transactions:
|
// TODO test with both one and two genesis transactions:
|
||||||
// TODO correct: genesis account created, canididates created, pool token variance
|
// TODO correct: genesis account created, canididates created, pool token variance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGaiaGenesisValidation(t *testing.T) {
|
||||||
|
genTxs := make([]GaiaGenTx, 2)
|
||||||
|
privKey := ed25519.GenPrivKey()
|
||||||
|
pubKey := privKey.PubKey()
|
||||||
|
addr := pubKey.Address()
|
||||||
|
// Test duplicate accounts fails
|
||||||
|
genTxs[0] = GaiaGenTx{"", sdk.AccAddress(addr), ""}
|
||||||
|
genTxs[1] = GaiaGenTx{"", sdk.AccAddress(addr), ""}
|
||||||
|
genesisState := makeGenesisState(genTxs)
|
||||||
|
err := GaiaValidateGenesisState(genesisState)
|
||||||
|
require.NotNil(t, err)
|
||||||
|
}
|
||||||
|
|
|
@ -188,7 +188,7 @@ func TestGaiaCLICreateValidator(t *testing.T) {
|
||||||
require.Equal(t, int64(8), barAcc.GetCoins().AmountOf("steak").Int64(), "%v", barAcc)
|
require.Equal(t, int64(8), barAcc.GetCoins().AmountOf("steak").Int64(), "%v", barAcc)
|
||||||
|
|
||||||
validator := executeGetValidator(t, fmt.Sprintf("gaiacli stake validator %s --output=json %v", sdk.ValAddress(barAddr), flags))
|
validator := executeGetValidator(t, fmt.Sprintf("gaiacli stake validator %s --output=json %v", sdk.ValAddress(barAddr), flags))
|
||||||
require.Equal(t, validator.Operator, sdk.ValAddress(barAddr))
|
require.Equal(t, validator.OperatorAddr, sdk.ValAddress(barAddr))
|
||||||
require.True(sdk.DecEq(t, sdk.NewDec(2), validator.Tokens))
|
require.True(sdk.DecEq(t, sdk.NewDec(2), validator.Tokens))
|
||||||
|
|
||||||
// unbond a single share
|
// unbond a single share
|
||||||
|
@ -343,7 +343,7 @@ func TestGaiaCLISubmitProposal(t *testing.T) {
|
||||||
require.Equal(t, " 2 - Apples", proposalsQuery)
|
require.Equal(t, " 2 - Apples", proposalsQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGaiaCLISendGenerateAndSign(t *testing.T) {
|
func TestGaiaCLISendGenerateSignAndBroadcast(t *testing.T) {
|
||||||
chainID, servAddr, port := initializeFixtures(t)
|
chainID, servAddr, port := initializeFixtures(t)
|
||||||
flags := fmt.Sprintf("--home=%s --node=%v --chain-id=%v", gaiacliHome, servAddr, chainID)
|
flags := fmt.Sprintf("--home=%s --node=%v --chain-id=%v", gaiacliHome, servAddr, chainID)
|
||||||
|
|
||||||
|
@ -368,16 +368,6 @@ func TestGaiaCLISendGenerateAndSign(t *testing.T) {
|
||||||
require.Equal(t, len(msg.Msgs), 1)
|
require.Equal(t, len(msg.Msgs), 1)
|
||||||
require.Equal(t, 0, len(msg.GetSignatures()))
|
require.Equal(t, 0, len(msg.GetSignatures()))
|
||||||
|
|
||||||
// Test generate sendTx, estimate gas
|
|
||||||
success, stdout, stderr = executeWriteRetStdStreams(t, fmt.Sprintf(
|
|
||||||
"gaiacli send %v --amount=10steak --to=%s --from=foo --gas=0 --generate-only",
|
|
||||||
flags, barAddr), []string{}...)
|
|
||||||
require.True(t, success)
|
|
||||||
require.NotEmpty(t, stderr)
|
|
||||||
msg = unmarshalStdTx(t, stdout)
|
|
||||||
require.NotZero(t, msg.Fee.Gas)
|
|
||||||
require.Equal(t, len(msg.Msgs), 1)
|
|
||||||
|
|
||||||
// Test generate sendTx with --gas=$amount
|
// Test generate sendTx with --gas=$amount
|
||||||
success, stdout, stderr = executeWriteRetStdStreams(t, fmt.Sprintf(
|
success, stdout, stderr = executeWriteRetStdStreams(t, fmt.Sprintf(
|
||||||
"gaiacli send %v --amount=10steak --to=%s --from=foo --gas=100 --generate-only",
|
"gaiacli send %v --amount=10steak --to=%s --from=foo --gas=100 --generate-only",
|
||||||
|
@ -389,6 +379,16 @@ func TestGaiaCLISendGenerateAndSign(t *testing.T) {
|
||||||
require.Equal(t, len(msg.Msgs), 1)
|
require.Equal(t, len(msg.Msgs), 1)
|
||||||
require.Equal(t, 0, len(msg.GetSignatures()))
|
require.Equal(t, 0, len(msg.GetSignatures()))
|
||||||
|
|
||||||
|
// Test generate sendTx, estimate gas
|
||||||
|
success, stdout, stderr = executeWriteRetStdStreams(t, fmt.Sprintf(
|
||||||
|
"gaiacli send %v --amount=10steak --to=%s --from=foo --gas=0 --generate-only",
|
||||||
|
flags, barAddr), []string{}...)
|
||||||
|
require.True(t, success)
|
||||||
|
require.NotEmpty(t, stderr)
|
||||||
|
msg = unmarshalStdTx(t, stdout)
|
||||||
|
require.True(t, msg.Fee.Gas > 0)
|
||||||
|
require.Equal(t, len(msg.Msgs), 1)
|
||||||
|
|
||||||
// Write the output to disk
|
// Write the output to disk
|
||||||
unsignedTxFile := writeToNewTempFile(t, stdout)
|
unsignedTxFile := writeToNewTempFile(t, stdout)
|
||||||
defer os.Remove(unsignedTxFile.Name())
|
defer os.Remove(unsignedTxFile.Name())
|
||||||
|
@ -417,6 +417,25 @@ func TestGaiaCLISendGenerateAndSign(t *testing.T) {
|
||||||
"gaiacli sign %v --print-sigs %v", flags, signedTxFile.Name()))
|
"gaiacli sign %v --print-sigs %v", flags, signedTxFile.Name()))
|
||||||
require.True(t, success)
|
require.True(t, success)
|
||||||
require.Equal(t, fmt.Sprintf("Signers:\n 0: %v\n\nSignatures:\n 0: %v\n", fooAddr.String(), fooAddr.String()), stdout)
|
require.Equal(t, fmt.Sprintf("Signers:\n 0: %v\n\nSignatures:\n 0: %v\n", fooAddr.String(), fooAddr.String()), stdout)
|
||||||
|
|
||||||
|
// Test broadcast
|
||||||
|
fooAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %s %v", fooAddr, flags))
|
||||||
|
require.Equal(t, int64(50), fooAcc.GetCoins().AmountOf("steak").Int64())
|
||||||
|
|
||||||
|
success, stdout, _ = executeWriteRetStdStreams(t, fmt.Sprintf("gaiacli broadcast %v --json %v", flags, signedTxFile.Name()))
|
||||||
|
require.True(t, success)
|
||||||
|
var result struct {
|
||||||
|
Response abci.ResponseDeliverTx
|
||||||
|
}
|
||||||
|
require.Nil(t, app.MakeCodec().UnmarshalJSON([]byte(stdout), &result))
|
||||||
|
require.Equal(t, msg.Fee.Gas, result.Response.GasUsed)
|
||||||
|
require.Equal(t, msg.Fee.Gas, result.Response.GasWanted)
|
||||||
|
tests.WaitForNextNBlocksTM(2, port)
|
||||||
|
|
||||||
|
barAcc := executeGetAccount(t, fmt.Sprintf("gaiacli account %s %v", barAddr, flags))
|
||||||
|
require.Equal(t, int64(10), barAcc.GetCoins().AmountOf("steak").Int64())
|
||||||
|
fooAcc = executeGetAccount(t, fmt.Sprintf("gaiacli account %s %v", fooAddr, flags))
|
||||||
|
require.Equal(t, int64(40), fooAcc.GetCoins().AmountOf("steak").Int64())
|
||||||
}
|
}
|
||||||
|
|
||||||
//___________________________________________________________________________________
|
//___________________________________________________________________________________
|
||||||
|
|
|
@ -132,6 +132,7 @@ func main() {
|
||||||
rootCmd.AddCommand(
|
rootCmd.AddCommand(
|
||||||
client.PostCommands(
|
client.PostCommands(
|
||||||
bankcmd.SendTxCmd(cdc),
|
bankcmd.SendTxCmd(cdc),
|
||||||
|
bankcmd.GetBroadcastCommand(cdc),
|
||||||
)...)
|
)...)
|
||||||
|
|
||||||
// add proxy, version and key info
|
// add proxy, version and key info
|
||||||
|
|
|
@ -65,7 +65,7 @@ func runHackCmd(cmd *cobra.Command, args []string) error {
|
||||||
// The following powerKey was there, but the corresponding "trouble" validator did not exist.
|
// The following powerKey was there, but the corresponding "trouble" validator did not exist.
|
||||||
// So here we do a binary search on the past states to find when the powerKey first showed up ...
|
// So here we do a binary search on the past states to find when the powerKey first showed up ...
|
||||||
|
|
||||||
// owner of the validator the bonds, gets revoked, later unbonds, and then later is still found in the bypower store
|
// operator of the validator the bonds, gets revoked, later unbonds, and then later is still found in the bypower store
|
||||||
trouble := hexToBytes("D3DC0FF59F7C3B548B7AFA365561B87FD0208AF8")
|
trouble := hexToBytes("D3DC0FF59F7C3B548B7AFA365561B87FD0208AF8")
|
||||||
// this is his "bypower" key
|
// this is his "bypower" key
|
||||||
powerKey := hexToBytes("05303030303030303030303033FFFFFFFFFFFF4C0C0000FFFED3DC0FF59F7C3B548B7AFA365561B87FD0208AF8")
|
powerKey := hexToBytes("05303030303030303030303033FFFFFFFFFFFF4C0C0000FFFED3DC0FF59F7C3B548B7AFA365561B87FD0208AF8")
|
||||||
|
|
|
@ -213,7 +213,7 @@ Note that the distribution scenario structures are found in `state.md`.
|
||||||
#### Delegation's entitlement to Global.Pool
|
#### Delegation's entitlement to Global.Pool
|
||||||
|
|
||||||
For delegations (including validator's self-delegation) all fees from fee pool
|
For delegations (including validator's self-delegation) all fees from fee pool
|
||||||
are subject to commission rate from the owner of the validator. The global
|
are subject to commission rate from the operator of the validator. The global
|
||||||
shares should be taken as true number of global bonded shares. The recipients
|
shares should be taken as true number of global bonded shares. The recipients
|
||||||
shares should be taken as the bonded tokens less the validator's commission.
|
shares should be taken as the bonded tokens less the validator's commission.
|
||||||
|
|
||||||
|
|
|
@ -714,7 +714,7 @@ definitions:
|
||||||
ValidatorAddress:
|
ValidatorAddress:
|
||||||
type: string
|
type: string
|
||||||
description: bech32 encoded addres
|
description: bech32 encoded addres
|
||||||
example: cosmosval:zgnkwr7eyyv643dllwfpdwensmgdtz89yu73zq
|
example: cosmosvaloper:zgnkwr7eyyv643dllwfpdwensmgdtz89yu73zq
|
||||||
PubKey:
|
PubKey:
|
||||||
type: string
|
type: string
|
||||||
description: bech32 encoded public key
|
description: bech32 encoded public key
|
||||||
|
@ -722,7 +722,7 @@ definitions:
|
||||||
ValidatorPubKey:
|
ValidatorPubKey:
|
||||||
type: string
|
type: string
|
||||||
description: bech32 encoded public key
|
description: bech32 encoded public key
|
||||||
example: cosmosvalpub:zgnkwr7eyyv643dllwfpdwensmgdtz89yu73zq
|
example: cosmosvalconspub:zgnkwr7eyyv643dllwfpdwensmgdtz89yu73zq
|
||||||
Coins:
|
Coins:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
|
|
@ -226,12 +226,11 @@ Returns on success:
|
||||||
"sequence": 7
|
"sequence": 7
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### POST /auth/accounts/sign
|
### POST /auth/tx/sign
|
||||||
|
|
||||||
- **URL**: `/auth/sign`
|
- **URL**: `/auth/tx/sign`
|
||||||
- **Functionality**: Sign a transaction without broadcasting it.
|
- **Functionality**: Sign a transaction without broadcasting it.
|
||||||
- Returns on success:
|
- Returns on success:
|
||||||
|
|
||||||
|
@ -298,6 +297,45 @@ Returns on success:
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### POST /auth/tx/broadcast
|
||||||
|
|
||||||
|
- **URL**: `/auth/broadcast`
|
||||||
|
- **Functionality**: Broadcast a transaction.
|
||||||
|
- Returns on success:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"rest api": "1.0",
|
||||||
|
"code": 200,
|
||||||
|
"error": "",
|
||||||
|
"result":
|
||||||
|
{
|
||||||
|
"check_tx": {
|
||||||
|
"log": "Msg 0: ",
|
||||||
|
"gasWanted": "2742",
|
||||||
|
"gasUsed": "1002"
|
||||||
|
},
|
||||||
|
"deliver_tx": {
|
||||||
|
"log": "Msg 0: ",
|
||||||
|
"gasWanted": "2742",
|
||||||
|
"gasUsed": "2742",
|
||||||
|
"tags": [
|
||||||
|
{
|
||||||
|
"key": "c2VuZGVy",
|
||||||
|
"value": "Y29zbW9zMXdjNTl6ZXU3MmNjdnp5ZWR6ZGE1N3pzcXh2eXZ2Y3poaHBhdDI4"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "cmVjaXBpZW50",
|
||||||
|
"value": "Y29zbW9zMTJ4OTNmY3V2azg3M3o1ejZnejRlNTl2dnlxcXp1eDdzdDcwNWd5"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"hash": "784314784503582AC885BD6FB0D2A5B79FF703A7",
|
||||||
|
"height": "5"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## ICS20 - TokenAPI
|
## ICS20 - TokenAPI
|
||||||
|
|
||||||
The TokenAPI exposes all functionality needed to query account balances and send transactions.
|
The TokenAPI exposes all functionality needed to query account balances and send transactions.
|
||||||
|
|
|
@ -22,17 +22,17 @@ There are three types of key representations that are used:
|
||||||
- Derived from account keys generated by `gaiacli keys add`
|
- Derived from account keys generated by `gaiacli keys add`
|
||||||
- Used to receive funds
|
- Used to receive funds
|
||||||
- e.g. `cosmos15h6vd5f0wqps26zjlwrc6chah08ryu4hzzdwhc`
|
- e.g. `cosmos15h6vd5f0wqps26zjlwrc6chah08ryu4hzzdwhc`
|
||||||
* `cosmosval`
|
* `cosmosvaloper`
|
||||||
* Used to associate a validator to it's operator
|
* Used to associate a validator to it's operator
|
||||||
* Used to invoke staking commands
|
* Used to invoke staking commands
|
||||||
* e.g. `cosmosval1carzvgq3e6y3z5kz5y6gxp3wpy3qdrv928vyah`
|
* e.g. `cosmosvaloper1carzvgq3e6y3z5kz5y6gxp3wpy3qdrv928vyah`
|
||||||
- `cosmospub`
|
- `cosmospub`
|
||||||
- Derived from account keys generated by `gaiacli keys add`
|
- Derived from account keys generated by `gaiacli keys add`
|
||||||
- e.g. `cosmospub1zcjduc3q7fu03jnlu2xpl75s2nkt7krm6grh4cc5aqth73v0zwmea25wj2hsqhlqzm`
|
- e.g. `cosmospub1zcjduc3q7fu03jnlu2xpl75s2nkt7krm6grh4cc5aqth73v0zwmea25wj2hsqhlqzm`
|
||||||
- `cosmosconspub`
|
- `cosmosvalconspub`
|
||||||
- Generated when the node is created with `gaiad init`.
|
- Generated when the node is created with `gaiad init`.
|
||||||
- Get this value with `gaiad tendermint show-validator`
|
- Get this value with `gaiad tendermint show-validator`
|
||||||
- e.g. `cosmosconspub1zcjduepq0ms2738680y72v44tfyqm3c9ppduku8fs6sr73fx7m666sjztznqzp2emf`
|
- e.g. `cosmosvalconspub1zcjduepq0ms2738680y72v44tfyqm3c9ppduku8fs6sr73fx7m666sjztznqzp2emf`
|
||||||
|
|
||||||
#### Generate Keys
|
#### Generate Keys
|
||||||
|
|
||||||
|
@ -159,6 +159,12 @@ gaiacli sign \
|
||||||
unsignedSendTx.json > signedSendTx.json
|
unsignedSendTx.json > signedSendTx.json
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can broadcast the signed transaction to a node by providing the JSON file to the following command:
|
||||||
|
|
||||||
|
```
|
||||||
|
gaiacli broadcast --node=<node> signedSendTx.json
|
||||||
|
```
|
||||||
|
|
||||||
### Staking
|
### Staking
|
||||||
|
|
||||||
#### Set up a Validator
|
#### Set up a Validator
|
||||||
|
|
|
@ -7,13 +7,13 @@ In the Cosmos network, keys and addresses may refer to a number of different rol
|
||||||
## HRP table
|
## HRP table
|
||||||
|
|
||||||
| HRP | Definition |
|
| HRP | Definition |
|
||||||
|---------------|--------------------------------------|
|
|-------------------|---------------------------------------|
|
||||||
| cosmos | Cosmos Account Address |
|
| cosmos | Cosmos Account Address |
|
||||||
| cosmospub | Cosmos Account Public Key |
|
| cosmospub | Cosmos Account Public Key |
|
||||||
| cosmoscons | Cosmos Consensus Address |
|
| cosmosvalcons | Cosmos Validator Consensus Address |
|
||||||
| cosmosconspub | Cosmos Consensus Public Key |
|
| cosmosvalconspub | Cosmos Validator Consensus Public Key |
|
||||||
| cosmosval | Cosmos Validator Operator Address |
|
| cosmosvaloper | Cosmos Validator Operator Address |
|
||||||
| cosmosvalpub | Cosmos Validator Operator Public Key |
|
| cosmosvaloperpub | Cosmos Validator Operator Public Key |
|
||||||
|
|
||||||
## Encoding
|
## Encoding
|
||||||
|
|
||||||
|
|
|
@ -40,26 +40,25 @@ type Params struct {
|
||||||
|
|
||||||
### Validator
|
### Validator
|
||||||
|
|
||||||
Validators are identified according to the `ValOwnerAddr`,
|
Validators are identified according to the `OperatorAddr`, an SDK validator
|
||||||
an SDK account address for the owner of the validator.
|
address for the operator of the validator.
|
||||||
|
|
||||||
Validators also have a `ValTendermintAddr`, the address
|
Validators also have a `ConsPubKey`, the public key of the validator.
|
||||||
of the public key of the validator.
|
|
||||||
|
|
||||||
Validators are indexed in the store using the following maps:
|
Validators are indexed in the store using the following maps:
|
||||||
|
|
||||||
- Validators: `0x02 | ValOwnerAddr -> amino(validator)`
|
- Validators: `0x02 | OperatorAddr -> amino(validator)`
|
||||||
- ValidatorsByPubKey: `0x03 | ValTendermintAddr -> ValOwnerAddr`
|
- ValidatorsByPubKey: `0x03 | ConsPubKey -> OperatorAddr`
|
||||||
- ValidatorsByPower: `0x05 | power | blockHeight | blockTx -> ValOwnerAddr`
|
- ValidatorsByPower: `0x05 | power | blockHeight | blockTx -> OperatorAddr`
|
||||||
|
|
||||||
`Validators` is the primary index - it ensures that each owner can have only one
|
`Validators` is the primary index - it ensures that each operator can have only one
|
||||||
associated validator, where the public key of that validator can change in the
|
associated validator, where the public key of that validator can change in the
|
||||||
future. Delegators can refer to the immutable owner of the validator, without
|
future. Delegators can refer to the immutable operator of the validator, without
|
||||||
concern for the changing public key.
|
concern for the changing public key.
|
||||||
|
|
||||||
`ValidatorsByPubKey` is a secondary index that enables lookups for slashing.
|
`ValidatorsByPubKey` is a secondary index that enables lookups for slashing.
|
||||||
When Tendermint reports evidence, it provides the validator address, so this
|
When Tendermint reports evidence, it provides the validator address, so this
|
||||||
map is needed to find the owner.
|
map is needed to find the operator.
|
||||||
|
|
||||||
`ValidatorsByPower` is a secondary index that provides a sorted list of
|
`ValidatorsByPower` is a secondary index that provides a sorted list of
|
||||||
potential validators to quickly determine the current active set. For instance,
|
potential validators to quickly determine the current active set. For instance,
|
||||||
|
@ -105,10 +104,10 @@ type Description struct {
|
||||||
|
|
||||||
### Delegation
|
### Delegation
|
||||||
|
|
||||||
Delegations are identified by combining `DelegatorAddr` (the address of the delegator) with the ValOwnerAddr
|
Delegations are identified by combining `DelegatorAddr` (the address of the delegator)
|
||||||
Delegators are indexed in the store as follows:
|
with the `OperatorAddr` Delegators are indexed in the store as follows:
|
||||||
|
|
||||||
- Delegation: ` 0x0A | DelegatorAddr | ValOwnerAddr -> amino(delegation)`
|
- Delegation: ` 0x0A | DelegatorAddr | OperatorAddr -> amino(delegation)`
|
||||||
|
|
||||||
Atom holders may delegate coins to validators; under this circumstance their
|
Atom holders may delegate coins to validators; under this circumstance their
|
||||||
funds are held in a `Delegation` data structure. It is owned by one
|
funds are held in a `Delegation` data structure. It is owned by one
|
||||||
|
@ -117,21 +116,20 @@ the transaction is the owner of the bond.
|
||||||
|
|
||||||
```golang
|
```golang
|
||||||
type Delegation struct {
|
type Delegation struct {
|
||||||
Shares sdk.Dec // delegation shares recieved
|
Shares sdk.Dec // delegation shares received
|
||||||
Height int64 // last height bond updated
|
Height int64 // last height bond updated
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### UnbondingDelegation
|
### UnbondingDelegation
|
||||||
|
|
||||||
Shares in a `Delegation` can be unbonded, but they must for some time exist as an `UnbondingDelegation`,
|
Shares in a `Delegation` can be unbonded, but they must for some time exist as an `UnbondingDelegation`, where shares can be reduced if Byzantine behavior is detected.
|
||||||
where shares can be reduced if Byzantine behaviour is detected.
|
|
||||||
|
|
||||||
`UnbondingDelegation` are indexed in the store as:
|
`UnbondingDelegation` are indexed in the store as:
|
||||||
|
|
||||||
- UnbondingDelegationByDelegator: ` 0x0B | DelegatorAddr | ValOwnerAddr ->
|
- UnbondingDelegationByDelegator: ` 0x0B | DelegatorAddr | OperatorAddr ->
|
||||||
amino(unbondingDelegation)`
|
amino(unbondingDelegation)`
|
||||||
- UnbondingDelegationByValOwner: ` 0x0C | ValOwnerAddr | DelegatorAddr | ValOwnerAddr ->
|
- UnbondingDelegationByValOwner: ` 0x0C | OperatorAddr | DelegatorAddr | OperatorAddr ->
|
||||||
nil`
|
nil`
|
||||||
|
|
||||||
The first map here is used in queries, to lookup all unbonding delegations for
|
The first map here is used in queries, to lookup all unbonding delegations for
|
||||||
|
@ -152,22 +150,22 @@ type UnbondingDelegation struct {
|
||||||
|
|
||||||
### Redelegation
|
### Redelegation
|
||||||
|
|
||||||
Shares in a `Delegation` can be rebonded to a different validator, but they must for some time exist as a `Redelegation`,
|
Shares in a `Delegation` can be rebonded to a different validator, but they must
|
||||||
where shares can be reduced if Byzantine behaviour is detected. This is tracked
|
for some time exist as a `Redelegation`, where shares can be reduced if Byzantine
|
||||||
as moving a delegation from a `FromValOwnerAddr` to a `ToValOwnerAddr`.
|
behavior is detected. This is tracked as moving a delegation from a `FromOperatorAddr`
|
||||||
|
to a `ToOperatorAddr`.
|
||||||
|
|
||||||
`Redelegation` are indexed in the store as:
|
`Redelegation` are indexed in the store as:
|
||||||
|
|
||||||
- Redelegations: `0x0D | DelegatorAddr | FromValOwnerAddr | ToValOwnerAddr ->
|
- Redelegations: `0x0D | DelegatorAddr | FromOperatorAddr | ToOperatorAddr ->
|
||||||
amino(redelegation)`
|
amino(redelegation)`
|
||||||
- RedelegationsBySrc: `0x0E | FromValOwnerAddr | ToValOwnerAddr |
|
- RedelegationsBySrc: `0x0E | FromOperatorAddr | ToOperatorAddr |
|
||||||
DelegatorAddr -> nil`
|
DelegatorAddr -> nil`
|
||||||
- RedelegationsByDst: `0x0F | ToValOwnerAddr | FromValOwnerAddr | DelegatorAddr
|
- RedelegationsByDst: `0x0F | ToOperatorAddr | FromOperatorAddr | DelegatorAddr
|
||||||
-> nil`
|
-> nil`
|
||||||
|
|
||||||
|
|
||||||
The first map here is used for queries, to lookup all redelegations for a given
|
The first map here is used for queries, to lookup all redelegations for a given
|
||||||
delegator. The second map is used for slashing based on the FromValOwnerAddr,
|
delegator. The second map is used for slashing based on the `FromOperatorAddr`,
|
||||||
while the third map is for slashing based on the ToValOwnerAddr.
|
while the third map is for slashing based on the ToValOwnerAddr.
|
||||||
|
|
||||||
A redelegation object is created every time a redelegation occurs. The
|
A redelegation object is created every time a redelegation occurs. The
|
||||||
|
|
|
@ -77,14 +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:
|
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 `cosmosconspub`.
|
* **Tendermint Key**: This is a unique key used to sign block hashes. It is associated with a public key `cosmosvalconspub`.
|
||||||
* Generated when the node is created with gaiad init.
|
* Generated when the node is created with gaiad init.
|
||||||
* Get this value with `gaiad tendermint show-validator`
|
* Get this value with `gaiad tendermint show-validator`
|
||||||
e.g. `cosmosconspub1zcjduc3qcyj09qc03elte23zwshdx92jm6ce88fgc90rtqhjx8v0608qh5ssp0w94c`
|
e.g. `cosmosvalconspub1zcjduc3qcyj09qc03elte23zwshdx92jm6ce88fgc90rtqhjx8v0608qh5ssp0w94c`
|
||||||
|
|
||||||
* **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`.
|
* **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
|
* Note: A validator's operator key is directly tied to an application key, but
|
||||||
uses reserved prefixes solely for this purpose: `cosmosval` and `cosmosvalpub`
|
uses reserved prefixes solely for this purpose: `cosmosvaloper` and `cosmosvaloperpub`
|
||||||
|
|
||||||
### What are the different states a validator can be in?
|
### What are the different states a validator can be in?
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ If you want to become a validator for the Hub's `mainnet`, you should [research
|
||||||
|
|
||||||
### Create Your Validator
|
### Create Your Validator
|
||||||
|
|
||||||
Your `cosmosconspub` can be used to create a new validator by staking tokens. You can find your validator pubkey by running:
|
Your `cosmosvalconspub` can be used to create a new validator by staking tokens. You can find your validator pubkey by running:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
gaiad tendermint show-validator
|
gaiad tendermint show-validator
|
||||||
|
|
|
@ -22,13 +22,13 @@ const (
|
||||||
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
|
// Bech32PrefixAccPub defines the Bech32 prefix of an account's public key
|
||||||
Bech32PrefixAccPub = "cosmospub"
|
Bech32PrefixAccPub = "cosmospub"
|
||||||
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
|
// Bech32PrefixValAddr defines the Bech32 prefix of a validator's operator address
|
||||||
Bech32PrefixValAddr = "cosmosval"
|
Bech32PrefixValAddr = "cosmosvaloper"
|
||||||
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
|
// Bech32PrefixValPub defines the Bech32 prefix of a validator's operator public key
|
||||||
Bech32PrefixValPub = "cosmosvalpub"
|
Bech32PrefixValPub = "cosmosvaloperpub"
|
||||||
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
|
// Bech32PrefixConsAddr defines the Bech32 prefix of a consensus node address
|
||||||
Bech32PrefixConsAddr = "cosmoscons"
|
Bech32PrefixConsAddr = "cosmosvalcons"
|
||||||
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
|
// Bech32PrefixConsPub defines the Bech32 prefix of a consensus node public key
|
||||||
Bech32PrefixConsPub = "cosmosconspub"
|
Bech32PrefixConsPub = "cosmosvalconspub"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -146,7 +146,7 @@ func (aa AccAddress) Format(s fmt.State, verb rune) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// validator owner
|
// validator operator
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
// ValAddress defines a wrapper around bytes meant to present a validator's
|
// ValAddress defines a wrapper around bytes meant to present a validator's
|
||||||
|
|
|
@ -38,7 +38,7 @@ type Validator interface {
|
||||||
GetJailed() bool // whether the validator is jailed
|
GetJailed() bool // whether the validator is jailed
|
||||||
GetMoniker() string // moniker of the validator
|
GetMoniker() string // moniker of the validator
|
||||||
GetStatus() BondStatus // status of the validator
|
GetStatus() BondStatus // status of the validator
|
||||||
GetOperator() ValAddress // owner address to receive/return validators coins
|
GetOperator() ValAddress // operator address to receive/return validators coins
|
||||||
GetPubKey() crypto.PubKey // validation pubkey
|
GetPubKey() crypto.PubKey // validation pubkey
|
||||||
GetPower() Dec // validation power
|
GetPower() Dec // validation power
|
||||||
GetTokens() Dec // validation tokens
|
GetTokens() Dec // validation tokens
|
||||||
|
@ -48,11 +48,11 @@ type Validator interface {
|
||||||
|
|
||||||
// properties for the set of all validators
|
// properties for the set of all validators
|
||||||
type ValidatorSet interface {
|
type ValidatorSet interface {
|
||||||
// iterate through validator by owner-AccAddress, execute func for each validator
|
// iterate through validators by operator address, execute func for each validator
|
||||||
IterateValidators(Context,
|
IterateValidators(Context,
|
||||||
func(index int64, validator Validator) (stop bool))
|
func(index int64, validator Validator) (stop bool))
|
||||||
|
|
||||||
// iterate through bonded validator by pubkey-AccAddress, execute func for each validator
|
// iterate through bonded validators by operator address, execute func for each validator
|
||||||
IterateValidatorsBonded(Context,
|
IterateValidatorsBonded(Context,
|
||||||
func(index int64, validator Validator) (stop bool))
|
func(index int64, validator Validator) (stop bool))
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package auth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
@ -190,6 +191,13 @@ func processSig(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dummySecp256k1Pubkey secp256k1.PubKeySecp256k1
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
bz, _ := hex.DecodeString("035AD6810A47F073553FF30D2FCC7E0D3B1C0B74B61A1AAA2582344037151E143A")
|
||||||
|
copy(dummySecp256k1Pubkey[:], bz)
|
||||||
|
}
|
||||||
|
|
||||||
func processPubKey(acc Account, sig StdSignature, simulate bool) (crypto.PubKey, sdk.Result) {
|
func processPubKey(acc Account, sig StdSignature, simulate bool) (crypto.PubKey, sdk.Result) {
|
||||||
// If pubkey is not known for account,
|
// If pubkey is not known for account,
|
||||||
// set it from the StdSignature.
|
// set it from the StdSignature.
|
||||||
|
@ -200,7 +208,7 @@ func processPubKey(acc Account, sig StdSignature, simulate bool) (crypto.PubKey,
|
||||||
// and gasKVStore.Set() shall consume the largest amount, i.e.
|
// and gasKVStore.Set() shall consume the largest amount, i.e.
|
||||||
// it takes more gas to verifiy secp256k1 keys than ed25519 ones.
|
// it takes more gas to verifiy secp256k1 keys than ed25519 ones.
|
||||||
if pubKey == nil {
|
if pubKey == nil {
|
||||||
return secp256k1.GenPrivKey().PubKey(), sdk.Result{}
|
return dummySecp256k1Pubkey, sdk.Result{}
|
||||||
}
|
}
|
||||||
return pubKey, sdk.Result{}
|
return pubKey, sdk.Result{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, s
|
||||||
QueryAccountRequestHandlerFn(storeName, cdc, authcmd.GetAccountDecoder(cdc), cliCtx),
|
QueryAccountRequestHandlerFn(storeName, cdc, authcmd.GetAccountDecoder(cdc), cliCtx),
|
||||||
).Methods("GET")
|
).Methods("GET")
|
||||||
r.HandleFunc(
|
r.HandleFunc(
|
||||||
"/sign",
|
"/tx/sign",
|
||||||
SignTxRequestHandlerFn(cdc, cliCtx),
|
SignTxRequestHandlerFn(cdc, cliCtx),
|
||||||
).Methods("POST")
|
).Methods("POST")
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
package cli
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/context"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
amino "github.com/tendermint/go-amino"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetSignCommand returns the sign command
|
||||||
|
func GetBroadcastCommand(codec *amino.Codec) *cobra.Command {
|
||||||
|
cmd := &cobra.Command{
|
||||||
|
Use: "broadcast <file>",
|
||||||
|
Short: "Broadcast transactions generated offline",
|
||||||
|
Long: `Broadcast transactions created with the --generate-only flag and signed with the sign command.
|
||||||
|
Read a transaction from <file> and broadcast it to a node. If you supply a dash (-) argument
|
||||||
|
in place of an input filename, the command reads from standard input.`,
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
|
RunE: func(cmd *cobra.Command, args []string) (err error) {
|
||||||
|
cliCtx := context.NewCLIContext().WithCodec(codec).WithLogger(os.Stdout)
|
||||||
|
stdTx, err := readAndUnmarshalStdTx(cliCtx.Codec, args[0])
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
txBytes, err := cliCtx.Codec.MarshalBinary(stdTx)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return cliCtx.EnsureBroadcastTx(txBytes)
|
||||||
|
},
|
||||||
|
}
|
||||||
|
return cmd
|
||||||
|
}
|
||||||
|
|
||||||
|
func readAndUnmarshalStdTx(cdc *amino.Codec, filename string) (stdTx auth.StdTx, err error) {
|
||||||
|
var bytes []byte
|
||||||
|
if filename == "-" {
|
||||||
|
bytes, err = ioutil.ReadAll(os.Stdin)
|
||||||
|
} else {
|
||||||
|
bytes, err = ioutil.ReadFile(filename)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = cdc.UnmarshalJSON(bytes, &stdTx); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
|
@ -0,0 +1,57 @@
|
||||||
|
package rest
|
||||||
|
|
||||||
|
import (
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/context"
|
||||||
|
"github.com/cosmos/cosmos-sdk/client/utils"
|
||||||
|
"github.com/cosmos/cosmos-sdk/wire"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
|
)
|
||||||
|
|
||||||
|
type broadcastBody struct {
|
||||||
|
Tx auth.StdTx `json:"tx"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// BroadcastTxRequestHandlerFn returns the broadcast tx REST handler
|
||||||
|
func BroadcastTxRequestHandlerFn(cdc *wire.Codec, cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var m broadcastBody
|
||||||
|
if ok := unmarshalBodyOrReturnBadRequest(cliCtx, w, r, &m); !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
txBytes, err := cliCtx.Codec.MarshalBinary(m.Tx)
|
||||||
|
if err != nil {
|
||||||
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
res, err := cliCtx.BroadcastTx(txBytes)
|
||||||
|
if err != nil {
|
||||||
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err := wire.MarshalJSONIndent(cdc, res)
|
||||||
|
if err != nil {
|
||||||
|
utils.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
w.Write(output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func unmarshalBodyOrReturnBadRequest(cliCtx context.CLIContext, w http.ResponseWriter, r *http.Request, m *broadcastBody) bool {
|
||||||
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
|
if err != nil {
|
||||||
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
err = cliCtx.Codec.UnmarshalJSON(body, m)
|
||||||
|
if err != nil {
|
||||||
|
utils.WriteErrorResponse(w, http.StatusBadRequest, err.Error())
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ import (
|
||||||
// RegisterRoutes - Central function to define routes that get registered by the main application
|
// RegisterRoutes - Central function to define routes that get registered by the main application
|
||||||
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
|
func RegisterRoutes(cliCtx context.CLIContext, r *mux.Router, cdc *wire.Codec, kb keys.Keybase) {
|
||||||
r.HandleFunc("/accounts/{address}/send", SendRequestHandlerFn(cdc, kb, cliCtx)).Methods("POST")
|
r.HandleFunc("/accounts/{address}/send", SendRequestHandlerFn(cdc, kb, cliCtx)).Methods("POST")
|
||||||
|
r.HandleFunc("/tx/broadcast", BroadcastTxRequestHandlerFn(cdc, cliCtx)).Methods("POST")
|
||||||
}
|
}
|
||||||
|
|
||||||
type sendBody struct {
|
type sendBody struct {
|
||||||
|
|
|
@ -440,7 +440,7 @@ func TestTallyJailedValidator(t *testing.T) {
|
||||||
|
|
||||||
val2, found := sk.GetValidator(ctx, sdk.ValAddress(addrs[1]))
|
val2, found := sk.GetValidator(ctx, sdk.ValAddress(addrs[1]))
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
sk.Jail(ctx, val2.PubKey)
|
sk.Jail(ctx, val2.ConsPubKey)
|
||||||
|
|
||||||
proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
|
proposal := keeper.NewTextProposal(ctx, "Test", "description", ProposalTypeText)
|
||||||
proposalID := proposal.GetProposalID()
|
proposalID := proposal.GetProposalID()
|
||||||
|
|
|
@ -107,10 +107,10 @@ func TestSlashingMsgs(t *testing.T) {
|
||||||
mapp.BeginBlock(abci.RequestBeginBlock{})
|
mapp.BeginBlock(abci.RequestBeginBlock{})
|
||||||
|
|
||||||
validator := checkValidator(t, mapp, stakeKeeper, addr1, true)
|
validator := checkValidator(t, mapp, stakeKeeper, addr1, true)
|
||||||
require.Equal(t, sdk.ValAddress(addr1), validator.Operator)
|
require.Equal(t, sdk.ValAddress(addr1), validator.OperatorAddr)
|
||||||
require.Equal(t, sdk.Bonded, validator.Status)
|
require.Equal(t, sdk.Bonded, validator.Status)
|
||||||
require.True(sdk.DecEq(t, sdk.NewDec(10), validator.BondedTokens()))
|
require.True(sdk.DecEq(t, sdk.NewDec(10), validator.BondedTokens()))
|
||||||
unjailMsg := MsgUnjail{ValidatorAddr: sdk.ValAddress(validator.PubKey.Address())}
|
unjailMsg := MsgUnjail{ValidatorAddr: sdk.ValAddress(validator.ConsPubKey.Address())}
|
||||||
|
|
||||||
// no signing info yet
|
// no signing info yet
|
||||||
checkValidatorSigningInfo(t, mapp, keeper, sdk.ConsAddress(addr1), false)
|
checkValidatorSigningInfo(t, mapp, keeper, sdk.ConsAddress(addr1), false)
|
||||||
|
|
|
@ -14,24 +14,24 @@ var (
|
||||||
AddrPubkeyRelationKey = []byte{0x04} // Prefix for address-pubkey relation
|
AddrPubkeyRelationKey = []byte{0x04} // Prefix for address-pubkey relation
|
||||||
)
|
)
|
||||||
|
|
||||||
// stored by *Tendermint* address (not owner address)
|
// stored by *Tendermint* address (not operator address)
|
||||||
func GetValidatorSigningInfoKey(v sdk.ConsAddress) []byte {
|
func GetValidatorSigningInfoKey(v sdk.ConsAddress) []byte {
|
||||||
return append(ValidatorSigningInfoKey, v.Bytes()...)
|
return append(ValidatorSigningInfoKey, v.Bytes()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// stored by *Tendermint* address (not owner address)
|
// stored by *Tendermint* address (not operator address)
|
||||||
func GetValidatorSigningBitArrayKey(v sdk.ConsAddress, i int64) []byte {
|
func GetValidatorSigningBitArrayKey(v sdk.ConsAddress, i int64) []byte {
|
||||||
b := make([]byte, 8)
|
b := make([]byte, 8)
|
||||||
binary.LittleEndian.PutUint64(b, uint64(i))
|
binary.LittleEndian.PutUint64(b, uint64(i))
|
||||||
return append(ValidatorSigningBitArrayKey, append(v.Bytes(), b...)...)
|
return append(ValidatorSigningBitArrayKey, append(v.Bytes(), b...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// stored by *Tendermint* address (not owner address)
|
// stored by *Tendermint* address (not operator address)
|
||||||
func GetValidatorSlashingPeriodPrefix(v sdk.ConsAddress) []byte {
|
func GetValidatorSlashingPeriodPrefix(v sdk.ConsAddress) []byte {
|
||||||
return append(ValidatorSlashingPeriodKey, v.Bytes()...)
|
return append(ValidatorSlashingPeriodKey, v.Bytes()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// stored by *Tendermint* address (not owner address) followed by start height
|
// stored by *Tendermint* address (not operator address) followed by start height
|
||||||
func GetValidatorSlashingPeriodKey(v sdk.ConsAddress, startHeight int64) []byte {
|
func GetValidatorSlashingPeriodKey(v sdk.ConsAddress, startHeight int64) []byte {
|
||||||
b := make([]byte, 8)
|
b := make([]byte, 8)
|
||||||
binary.LittleEndian.PutUint64(b, uint64(startHeight))
|
binary.LittleEndian.PutUint64(b, uint64(startHeight))
|
||||||
|
|
|
@ -15,7 +15,7 @@ var _ sdk.Msg = &MsgUnjail{}
|
||||||
|
|
||||||
// MsgUnjail - struct for unjailing jailed validator
|
// MsgUnjail - struct for unjailing jailed validator
|
||||||
type MsgUnjail struct {
|
type MsgUnjail struct {
|
||||||
ValidatorAddr sdk.ValAddress `json:"address"` // address of the validator owner
|
ValidatorAddr sdk.ValAddress `json:"address"` // address of the validator operator
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail {
|
func NewMsgUnjail(validatorAddr sdk.ValAddress) MsgUnjail {
|
||||||
|
|
|
@ -12,5 +12,5 @@ func TestMsgUnjailGetSignBytes(t *testing.T) {
|
||||||
addr := sdk.AccAddress("abcd")
|
addr := sdk.AccAddress("abcd")
|
||||||
msg := NewMsgUnjail(sdk.ValAddress(addr))
|
msg := NewMsgUnjail(sdk.ValAddress(addr))
|
||||||
bytes := msg.GetSignBytes()
|
bytes := msg.GetSignBytes()
|
||||||
require.Equal(t, string(bytes), `{"address":"cosmosval1v93xxeq7xkcrf"}`)
|
require.Equal(t, string(bytes), `{"address":"cosmosvaloper1v93xxeqhg9nn6"}`)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Stored by *validator* address (not owner address)
|
// Stored by *validator* address (not operator address)
|
||||||
func (k Keeper) getValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress) (info ValidatorSigningInfo, found bool) {
|
func (k Keeper) getValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress) (info ValidatorSigningInfo, found bool) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
bz := store.Get(GetValidatorSigningInfoKey(address))
|
bz := store.Get(GetValidatorSigningInfoKey(address))
|
||||||
|
@ -20,14 +20,14 @@ func (k Keeper) getValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stored by *validator* address (not owner address)
|
// Stored by *validator* address (not operator address)
|
||||||
func (k Keeper) setValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress, info ValidatorSigningInfo) {
|
func (k Keeper) setValidatorSigningInfo(ctx sdk.Context, address sdk.ConsAddress, info ValidatorSigningInfo) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
bz := k.cdc.MustMarshalBinary(info)
|
bz := k.cdc.MustMarshalBinary(info)
|
||||||
store.Set(GetValidatorSigningInfoKey(address), bz)
|
store.Set(GetValidatorSigningInfoKey(address), bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stored by *validator* address (not owner address)
|
// Stored by *validator* address (not operator address)
|
||||||
func (k Keeper) getValidatorSigningBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64) (signed bool) {
|
func (k Keeper) getValidatorSigningBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64) (signed bool) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
bz := store.Get(GetValidatorSigningBitArrayKey(address, index))
|
bz := store.Get(GetValidatorSigningBitArrayKey(address, index))
|
||||||
|
@ -40,7 +40,7 @@ func (k Keeper) getValidatorSigningBitArray(ctx sdk.Context, address sdk.ConsAdd
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stored by *validator* address (not owner address)
|
// Stored by *validator* address (not operator address)
|
||||||
func (k Keeper) setValidatorSigningBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64, signed bool) {
|
func (k Keeper) setValidatorSigningBitArray(ctx sdk.Context, address sdk.ConsAddress, index int64, signed bool) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
bz := k.cdc.MustMarshalBinary(signed)
|
bz := k.cdc.MustMarshalBinary(signed)
|
||||||
|
|
|
@ -32,7 +32,7 @@ func (k Keeper) capBySlashingPeriod(ctx sdk.Context, address sdk.ConsAddress, fr
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stored by validator Tendermint address (not owner address)
|
// Stored by validator Tendermint address (not operator address)
|
||||||
// This function retrieves the most recent slashing period starting
|
// This function retrieves the most recent slashing period starting
|
||||||
// before a particular height - so the slashing period that was "in effect"
|
// before a particular height - so the slashing period that was "in effect"
|
||||||
// at the time of an infraction committed at that height.
|
// at the time of an infraction committed at that height.
|
||||||
|
@ -49,7 +49,7 @@ func (k Keeper) getValidatorSlashingPeriodForHeight(ctx sdk.Context, address sdk
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stored by validator Tendermint address (not owner address)
|
// Stored by validator Tendermint address (not operator address)
|
||||||
// This function sets a validator slashing period for a particular validator,
|
// This function sets a validator slashing period for a particular validator,
|
||||||
// start height, end height, and current slashed-so-far total, or updates
|
// start height, end height, and current slashed-so-far total, or updates
|
||||||
// an existing slashing period for the same validator and start height.
|
// an existing slashing period for the same validator and start height.
|
||||||
|
|
|
@ -136,7 +136,7 @@ func TestStakeMsgs(t *testing.T) {
|
||||||
mApp.BeginBlock(abci.RequestBeginBlock{})
|
mApp.BeginBlock(abci.RequestBeginBlock{})
|
||||||
|
|
||||||
validator := checkValidator(t, mApp, keeper, sdk.ValAddress(addr1), true)
|
validator := checkValidator(t, mApp, keeper, sdk.ValAddress(addr1), true)
|
||||||
require.Equal(t, sdk.ValAddress(addr1), validator.Operator)
|
require.Equal(t, sdk.ValAddress(addr1), validator.OperatorAddr)
|
||||||
require.Equal(t, sdk.Bonded, validator.Status)
|
require.Equal(t, sdk.Bonded, validator.Status)
|
||||||
require.True(sdk.DecEq(t, sdk.NewDec(10), validator.BondedTokens()))
|
require.True(sdk.DecEq(t, sdk.NewDec(10), validator.BondedTokens()))
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ func TestStakeMsgs(t *testing.T) {
|
||||||
mApp.BeginBlock(abci.RequestBeginBlock{})
|
mApp.BeginBlock(abci.RequestBeginBlock{})
|
||||||
|
|
||||||
validator = checkValidator(t, mApp, keeper, sdk.ValAddress(addr2), true)
|
validator = checkValidator(t, mApp, keeper, sdk.ValAddress(addr2), true)
|
||||||
require.Equal(t, sdk.ValAddress(addr2), validator.Operator)
|
require.Equal(t, sdk.ValAddress(addr2), validator.OperatorAddr)
|
||||||
require.Equal(t, sdk.Bonded, validator.Status)
|
require.Equal(t, sdk.Bonded, validator.Status)
|
||||||
require.True(sdk.DecEq(t, sdk.NewDec(10), validator.Tokens))
|
require.True(sdk.DecEq(t, sdk.NewDec(10), validator.Tokens))
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ func delegatorHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) http.Handler
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, validator := range validators {
|
for _, validator := range validators {
|
||||||
valAddr = validator.Operator
|
valAddr = validator.OperatorAddr
|
||||||
|
|
||||||
// Delegations
|
// Delegations
|
||||||
delegations, statusCode, errMsg, err := getDelegatorDelegations(cliCtx, cdc, delAddr, valAddr)
|
delegations, statusCode, errMsg, err := getDelegatorDelegations(cliCtx, cdc, delAddr, valAddr)
|
||||||
|
@ -410,7 +410,7 @@ func delegatorValidatorsHandlerFn(cliCtx context.CLIContext, cdc *wire.Codec) ht
|
||||||
|
|
||||||
for _, validator := range validators {
|
for _, validator := range validators {
|
||||||
// get all transactions from the delegator to val and append
|
// get all transactions from the delegator to val and append
|
||||||
valAddr = validator.Operator
|
valAddr = validator.OperatorAddr
|
||||||
|
|
||||||
validator, statusCode, errMsg, errRes := getDelegatorValidator(cliCtx, cdc, delegatorAddr, valAddr)
|
validator, statusCode, errMsg, errRes := getDelegatorValidator(cliCtx, cdc, delegatorAddr, valAddr)
|
||||||
if errRes != nil {
|
if errRes != nil {
|
||||||
|
|
|
@ -138,7 +138,7 @@ func handleMsgDelegate(ctx sdk.Context, msg types.MsgDelegate, k keeper.Keeper)
|
||||||
return ErrBadDenom(k.Codespace()).Result()
|
return ErrBadDenom(k.Codespace()).Result()
|
||||||
}
|
}
|
||||||
|
|
||||||
if validator.Jailed && !bytes.Equal(validator.Operator, msg.DelegatorAddr) {
|
if validator.Jailed && !bytes.Equal(validator.OperatorAddr, msg.DelegatorAddr) {
|
||||||
return ErrValidatorJailed(k.Codespace()).Result()
|
return ErrValidatorJailed(k.Codespace()).Result()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,8 +136,8 @@ func TestDuplicatesMsgCreateValidator(t *testing.T) {
|
||||||
|
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
assert.Equal(t, sdk.Bonded, validator.Status)
|
assert.Equal(t, sdk.Bonded, validator.Status)
|
||||||
assert.Equal(t, addr1, validator.Operator)
|
assert.Equal(t, addr1, validator.OperatorAddr)
|
||||||
assert.Equal(t, pk1, validator.PubKey)
|
assert.Equal(t, pk1, validator.ConsPubKey)
|
||||||
assert.Equal(t, sdk.NewDec(10), validator.BondedTokens())
|
assert.Equal(t, sdk.NewDec(10), validator.BondedTokens())
|
||||||
assert.Equal(t, sdk.NewDec(10), validator.DelegatorShares)
|
assert.Equal(t, sdk.NewDec(10), validator.DelegatorShares)
|
||||||
assert.Equal(t, Description{}, validator.Description)
|
assert.Equal(t, Description{}, validator.Description)
|
||||||
|
@ -160,8 +160,8 @@ func TestDuplicatesMsgCreateValidator(t *testing.T) {
|
||||||
|
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
assert.Equal(t, sdk.Bonded, validator.Status)
|
assert.Equal(t, sdk.Bonded, validator.Status)
|
||||||
assert.Equal(t, addr2, validator.Operator)
|
assert.Equal(t, addr2, validator.OperatorAddr)
|
||||||
assert.Equal(t, pk2, validator.PubKey)
|
assert.Equal(t, pk2, validator.ConsPubKey)
|
||||||
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.Tokens))
|
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.Tokens))
|
||||||
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.DelegatorShares))
|
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.DelegatorShares))
|
||||||
assert.Equal(t, Description{}, validator.Description)
|
assert.Equal(t, Description{}, validator.Description)
|
||||||
|
@ -180,8 +180,8 @@ func TestDuplicatesMsgCreateValidatorOnBehalfOf(t *testing.T) {
|
||||||
|
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
assert.Equal(t, sdk.Bonded, validator.Status)
|
assert.Equal(t, sdk.Bonded, validator.Status)
|
||||||
assert.Equal(t, validatorAddr, validator.Operator)
|
assert.Equal(t, validatorAddr, validator.OperatorAddr)
|
||||||
assert.Equal(t, pk, validator.PubKey)
|
assert.Equal(t, pk, validator.ConsPubKey)
|
||||||
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.Tokens))
|
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.Tokens))
|
||||||
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.DelegatorShares))
|
assert.True(sdk.DecEq(t, sdk.NewDec(10), validator.DelegatorShares))
|
||||||
assert.Equal(t, Description{}, validator.Description)
|
assert.Equal(t, Description{}, validator.Description)
|
||||||
|
|
|
@ -223,11 +223,11 @@ func (k Keeper) Delegate(ctx sdk.Context, delAddr sdk.AccAddress, bondAmt sdk.Co
|
||||||
validator types.Validator, subtractAccount bool) (newShares sdk.Dec, err sdk.Error) {
|
validator types.Validator, subtractAccount bool) (newShares sdk.Dec, err sdk.Error) {
|
||||||
|
|
||||||
// Get or create the delegator delegation
|
// Get or create the delegator delegation
|
||||||
delegation, found := k.GetDelegation(ctx, delAddr, validator.Operator)
|
delegation, found := k.GetDelegation(ctx, delAddr, validator.OperatorAddr)
|
||||||
if !found {
|
if !found {
|
||||||
delegation = types.Delegation{
|
delegation = types.Delegation{
|
||||||
DelegatorAddr: delAddr,
|
DelegatorAddr: delAddr,
|
||||||
ValidatorAddr: validator.Operator,
|
ValidatorAddr: validator.OperatorAddr,
|
||||||
Shares: sdk.ZeroDec(),
|
Shares: sdk.ZeroDec(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -286,7 +286,7 @@ func (k Keeper) unbond(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValA
|
||||||
|
|
||||||
// if the delegation is the operator of the validator then
|
// if the delegation is the operator of the validator then
|
||||||
// trigger a jail validator
|
// trigger a jail validator
|
||||||
if bytes.Equal(delegation.DelegatorAddr, validator.Operator) && validator.Jailed == false {
|
if bytes.Equal(delegation.DelegatorAddr, validator.OperatorAddr) && validator.Jailed == false {
|
||||||
validator.Jailed = true
|
validator.Jailed = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -306,7 +306,7 @@ func (k Keeper) unbond(ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValA
|
||||||
// update then remove validator if necessary
|
// update then remove validator if necessary
|
||||||
validator = k.UpdateValidator(ctx, validator)
|
validator = k.UpdateValidator(ctx, validator)
|
||||||
if validator.DelegatorShares.IsZero() {
|
if validator.DelegatorShares.IsZero() {
|
||||||
k.RemoveValidator(ctx, validator.Operator)
|
k.RemoveValidator(ctx, validator.OperatorAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return amount, nil
|
return amount, nil
|
||||||
|
|
|
@ -26,10 +26,10 @@ var (
|
||||||
IntraTxCounterKey = []byte{0x09} // key for intra-block tx index
|
IntraTxCounterKey = []byte{0x09} // key for intra-block tx index
|
||||||
DelegationKey = []byte{0x0A} // key for a delegation
|
DelegationKey = []byte{0x0A} // key for a delegation
|
||||||
UnbondingDelegationKey = []byte{0x0B} // key for an unbonding-delegation
|
UnbondingDelegationKey = []byte{0x0B} // key for an unbonding-delegation
|
||||||
UnbondingDelegationByValIndexKey = []byte{0x0C} // prefix for each key for an unbonding-delegation, by validator owner
|
UnbondingDelegationByValIndexKey = []byte{0x0C} // prefix for each key for an unbonding-delegation, by validator operator
|
||||||
RedelegationKey = []byte{0x0D} // key for a redelegation
|
RedelegationKey = []byte{0x0D} // key for a redelegation
|
||||||
RedelegationByValSrcIndexKey = []byte{0x0E} // prefix for each key for an redelegation, by source validator owner
|
RedelegationByValSrcIndexKey = []byte{0x0E} // prefix for each key for an redelegation, by source validator operator
|
||||||
RedelegationByValDstIndexKey = []byte{0x0F} // prefix for each key for an redelegation, by destination validator owner
|
RedelegationByValDstIndexKey = []byte{0x0F} // prefix for each key for an redelegation, by destination validator operator
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxDigitsForAccount = 12 // ~220,000,000 atoms created at launch
|
const maxDigitsForAccount = 12 // ~220,000,000 atoms created at launch
|
||||||
|
@ -41,7 +41,7 @@ func GetValidatorKey(operatorAddr sdk.ValAddress) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
// gets the key for the validator with pubkey
|
// gets the key for the validator with pubkey
|
||||||
// VALUE: validator owner address ([]byte)
|
// VALUE: validator operator address ([]byte)
|
||||||
func GetValidatorByPubKeyIndexKey(pubkey crypto.PubKey) []byte {
|
func GetValidatorByPubKeyIndexKey(pubkey crypto.PubKey) []byte {
|
||||||
return append(ValidatorsByPubKeyIndexKey, pubkey.Bytes()...)
|
return append(ValidatorsByPubKeyIndexKey, pubkey.Bytes()...)
|
||||||
}
|
}
|
||||||
|
@ -52,7 +52,7 @@ func GetValidatorsBondedIndexKey(operatorAddr sdk.ValAddress) []byte {
|
||||||
return append(ValidatorsBondedIndexKey, operatorAddr.Bytes()...)
|
return append(ValidatorsBondedIndexKey, operatorAddr.Bytes()...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the validator owner address from ValBondedIndexKey
|
// Get the validator operator address from ValBondedIndexKey
|
||||||
func GetAddressFromValBondedIndexKey(IndexKey []byte) []byte {
|
func GetAddressFromValBondedIndexKey(IndexKey []byte) []byte {
|
||||||
return IndexKey[1:] // remove prefix bytes
|
return IndexKey[1:] // remove prefix bytes
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,7 @@ func GetAddressFromValBondedIndexKey(IndexKey []byte) []byte {
|
||||||
// get the validator by power index.
|
// get the validator by power index.
|
||||||
// Power index is the key used in the power-store, and represents the relative
|
// Power index is the key used in the power-store, and represents the relative
|
||||||
// power ranking of the validator.
|
// power ranking of the validator.
|
||||||
// VALUE: validator owner address ([]byte)
|
// VALUE: validator operator address ([]byte)
|
||||||
func GetValidatorsByPowerIndexKey(validator types.Validator, pool types.Pool) []byte {
|
func GetValidatorsByPowerIndexKey(validator types.Validator, pool types.Pool) []byte {
|
||||||
// NOTE the address doesn't need to be stored because counter bytes must always be different
|
// NOTE the address doesn't need to be stored because counter bytes must always be different
|
||||||
return getValidatorPowerRank(validator, pool)
|
return getValidatorPowerRank(validator, pool)
|
||||||
|
|
|
@ -112,7 +112,7 @@ func (k Keeper) Slash(ctx sdk.Context, pubkey crypto.PubKey, infractionHeight in
|
||||||
|
|
||||||
// remove validator if it has no more tokens
|
// remove validator if it has no more tokens
|
||||||
if validator.Tokens.IsZero() {
|
if validator.Tokens.IsZero() {
|
||||||
k.RemoveValidator(ctx, validator.Operator)
|
k.RemoveValidator(ctx, validator.OperatorAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Log that a slash occurred!
|
// Log that a slash occurred!
|
||||||
|
|
|
@ -38,7 +38,7 @@ func (k Keeper) GetValidator(ctx sdk.Context, addr sdk.ValAddress) (validator ty
|
||||||
if val, ok := validatorCache[strValue]; ok {
|
if val, ok := validatorCache[strValue]; ok {
|
||||||
valToReturn := val.val
|
valToReturn := val.val
|
||||||
// Doesn't mutate the cache's value
|
// Doesn't mutate the cache's value
|
||||||
valToReturn.Operator = addr
|
valToReturn.OperatorAddr = addr
|
||||||
return valToReturn, true
|
return valToReturn, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,25 +72,25 @@ func (k Keeper) GetValidatorByPubKey(ctx sdk.Context, pubkey crypto.PubKey) (val
|
||||||
func (k Keeper) SetValidator(ctx sdk.Context, validator types.Validator) {
|
func (k Keeper) SetValidator(ctx sdk.Context, validator types.Validator) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
bz := types.MustMarshalValidator(k.cdc, validator)
|
bz := types.MustMarshalValidator(k.cdc, validator)
|
||||||
store.Set(GetValidatorKey(validator.Operator), bz)
|
store.Set(GetValidatorKey(validator.OperatorAddr), bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
// validator index
|
// validator index
|
||||||
func (k Keeper) SetValidatorByPubKeyIndex(ctx sdk.Context, validator types.Validator) {
|
func (k Keeper) SetValidatorByPubKeyIndex(ctx sdk.Context, validator types.Validator) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
store.Set(GetValidatorByPubKeyIndexKey(validator.PubKey), validator.Operator)
|
store.Set(GetValidatorByPubKeyIndexKey(validator.ConsPubKey), validator.OperatorAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// validator index
|
// validator index
|
||||||
func (k Keeper) SetValidatorByPowerIndex(ctx sdk.Context, validator types.Validator, pool types.Pool) {
|
func (k Keeper) SetValidatorByPowerIndex(ctx sdk.Context, validator types.Validator, pool types.Pool) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
store.Set(GetValidatorsByPowerIndexKey(validator, pool), validator.Operator)
|
store.Set(GetValidatorsByPowerIndexKey(validator, pool), validator.OperatorAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// validator index
|
// validator index
|
||||||
func (k Keeper) SetValidatorBondedIndex(ctx sdk.Context, validator types.Validator) {
|
func (k Keeper) SetValidatorBondedIndex(ctx sdk.Context, validator types.Validator) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
store.Set(GetValidatorsBondedIndexKey(validator.Operator), []byte{})
|
store.Set(GetValidatorsBondedIndexKey(validator.OperatorAddr), []byte{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// used in testing
|
// used in testing
|
||||||
|
@ -239,7 +239,7 @@ func (k Keeper) ClearTendermintUpdates(ctx sdk.Context) {
|
||||||
func (k Keeper) UpdateValidator(ctx sdk.Context, validator types.Validator) types.Validator {
|
func (k Keeper) UpdateValidator(ctx sdk.Context, validator types.Validator) types.Validator {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
pool := k.GetPool(ctx)
|
pool := k.GetPool(ctx)
|
||||||
oldValidator, oldFound := k.GetValidator(ctx, validator.Operator)
|
oldValidator, oldFound := k.GetValidator(ctx, validator.OperatorAddr)
|
||||||
|
|
||||||
validator = k.updateForJailing(ctx, oldFound, oldValidator, validator)
|
validator = k.updateForJailing(ctx, oldFound, oldValidator, validator)
|
||||||
powerIncreasing := k.getPowerIncreasing(ctx, oldFound, oldValidator, validator)
|
powerIncreasing := k.getPowerIncreasing(ctx, oldFound, oldValidator, validator)
|
||||||
|
@ -257,11 +257,11 @@ func (k Keeper) UpdateValidator(ctx sdk.Context, validator types.Validator) type
|
||||||
(oldFound && oldValidator.Status == sdk.Bonded):
|
(oldFound && oldValidator.Status == sdk.Bonded):
|
||||||
|
|
||||||
bz := k.cdc.MustMarshalBinary(validator.ABCIValidatorUpdate())
|
bz := k.cdc.MustMarshalBinary(validator.ABCIValidatorUpdate())
|
||||||
store.Set(GetTendermintUpdatesKey(validator.Operator), bz)
|
store.Set(GetTendermintUpdatesKey(validator.OperatorAddr), bz)
|
||||||
|
|
||||||
if cliffPower != nil {
|
if cliffPower != nil {
|
||||||
cliffAddr := sdk.ValAddress(k.GetCliffValidator(ctx))
|
cliffAddr := sdk.ValAddress(k.GetCliffValidator(ctx))
|
||||||
if bytes.Equal(cliffAddr, validator.Operator) {
|
if bytes.Equal(cliffAddr, validator.OperatorAddr) {
|
||||||
k.updateCliffValidator(ctx, validator)
|
k.updateCliffValidator(ctx, validator)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,7 @@ func (k Keeper) UpdateValidator(ctx sdk.Context, validator types.Validator) type
|
||||||
// if decreased in power but still bonded, update Tendermint validator
|
// if decreased in power but still bonded, update Tendermint validator
|
||||||
if oldFound && oldValidator.BondedTokens().GT(validator.BondedTokens()) {
|
if oldFound && oldValidator.BondedTokens().GT(validator.BondedTokens()) {
|
||||||
bz := k.cdc.MustMarshalBinary(validator.ABCIValidatorUpdate())
|
bz := k.cdc.MustMarshalBinary(validator.ABCIValidatorUpdate())
|
||||||
store.Set(GetTendermintUpdatesKey(validator.Operator), bz)
|
store.Set(GetTendermintUpdatesKey(validator.OperatorAddr), bz)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -344,7 +344,7 @@ func (k Keeper) updateCliffValidator(ctx sdk.Context, affectedVal types.Validato
|
||||||
affectedValRank := GetValidatorsByPowerIndexKey(affectedVal, pool)
|
affectedValRank := GetValidatorsByPowerIndexKey(affectedVal, pool)
|
||||||
newCliffValRank := GetValidatorsByPowerIndexKey(newCliffVal, pool)
|
newCliffValRank := GetValidatorsByPowerIndexKey(newCliffVal, pool)
|
||||||
|
|
||||||
if bytes.Equal(affectedVal.Operator, newCliffVal.Operator) {
|
if bytes.Equal(affectedVal.OperatorAddr, newCliffVal.OperatorAddr) {
|
||||||
|
|
||||||
// The affected validator remains the cliff validator, however, since
|
// The affected validator remains the cliff validator, however, since
|
||||||
// the store does not contain the new power, update the new power rank.
|
// the store does not contain the new power, update the new power rank.
|
||||||
|
@ -407,7 +407,7 @@ func (k Keeper) updateValidatorPower(ctx sdk.Context, oldFound bool, oldValidato
|
||||||
store.Delete(GetValidatorsByPowerIndexKey(oldValidator, pool))
|
store.Delete(GetValidatorsByPowerIndexKey(oldValidator, pool))
|
||||||
}
|
}
|
||||||
valPower = GetValidatorsByPowerIndexKey(newValidator, pool)
|
valPower = GetValidatorsByPowerIndexKey(newValidator, pool)
|
||||||
store.Set(valPower, newValidator.Operator)
|
store.Set(valPower, newValidator.OperatorAddr)
|
||||||
|
|
||||||
return valPower
|
return valPower
|
||||||
}
|
}
|
||||||
|
@ -449,7 +449,7 @@ func (k Keeper) UpdateBondedValidators(
|
||||||
// situation that this is the "affected validator" just use the
|
// situation that this is the "affected validator" just use the
|
||||||
// validator provided because it has not yet been updated in the store
|
// validator provided because it has not yet been updated in the store
|
||||||
ownerAddr := iterator.Value()
|
ownerAddr := iterator.Value()
|
||||||
if bytes.Equal(ownerAddr, affectedValidator.Operator) {
|
if bytes.Equal(ownerAddr, affectedValidator.OperatorAddr) {
|
||||||
validator = affectedValidator
|
validator = affectedValidator
|
||||||
} else {
|
} else {
|
||||||
var found bool
|
var found bool
|
||||||
|
@ -486,7 +486,7 @@ func (k Keeper) UpdateBondedValidators(
|
||||||
|
|
||||||
iterator.Close()
|
iterator.Close()
|
||||||
|
|
||||||
if newValidatorBonded && bytes.Equal(oldCliffValidatorAddr, validator.Operator) {
|
if newValidatorBonded && bytes.Equal(oldCliffValidatorAddr, validator.OperatorAddr) {
|
||||||
panic("cliff validator has not been changed, yet we bonded a new validator")
|
panic("cliff validator has not been changed, yet we bonded a new validator")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,7 +506,7 @@ func (k Keeper) UpdateBondedValidators(
|
||||||
panic(fmt.Sprintf("validator record not found for address: %v\n", oldCliffValidatorAddr))
|
panic(fmt.Sprintf("validator record not found for address: %v\n", oldCliffValidatorAddr))
|
||||||
}
|
}
|
||||||
|
|
||||||
if bytes.Equal(validatorToBond.Operator, affectedValidator.Operator) {
|
if bytes.Equal(validatorToBond.OperatorAddr, affectedValidator.OperatorAddr) {
|
||||||
|
|
||||||
// begin unbonding the old cliff validator iff the affected
|
// begin unbonding the old cliff validator iff the affected
|
||||||
// validator was newly bonded and has greater power
|
// validator was newly bonded and has greater power
|
||||||
|
@ -520,7 +520,7 @@ func (k Keeper) UpdateBondedValidators(
|
||||||
}
|
}
|
||||||
|
|
||||||
validator = k.bondValidator(ctx, validatorToBond)
|
validator = k.bondValidator(ctx, validatorToBond)
|
||||||
if bytes.Equal(validator.Operator, affectedValidator.Operator) {
|
if bytes.Equal(validator.OperatorAddr, affectedValidator.OperatorAddr) {
|
||||||
return validator, true
|
return validator, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -637,10 +637,10 @@ func (k Keeper) beginUnbondingValidator(ctx sdk.Context, validator types.Validat
|
||||||
|
|
||||||
// add to accumulated changes for tendermint
|
// add to accumulated changes for tendermint
|
||||||
bzABCI := k.cdc.MustMarshalBinary(validator.ABCIValidatorUpdateZero())
|
bzABCI := k.cdc.MustMarshalBinary(validator.ABCIValidatorUpdateZero())
|
||||||
store.Set(GetTendermintUpdatesKey(validator.Operator), bzABCI)
|
store.Set(GetTendermintUpdatesKey(validator.OperatorAddr), bzABCI)
|
||||||
|
|
||||||
// also remove from the Bonded types.Validators Store
|
// also remove from the Bonded types.Validators Store
|
||||||
store.Delete(GetValidatorsBondedIndexKey(validator.Operator))
|
store.Delete(GetValidatorsBondedIndexKey(validator.OperatorAddr))
|
||||||
|
|
||||||
// call the unbond hook if present
|
// call the unbond hook if present
|
||||||
if k.validatorHooks != nil {
|
if k.validatorHooks != nil {
|
||||||
|
@ -668,11 +668,11 @@ func (k Keeper) bondValidator(ctx sdk.Context, validator types.Validator) types.
|
||||||
|
|
||||||
// save the now bonded validator record to the three referenced stores
|
// save the now bonded validator record to the three referenced stores
|
||||||
k.SetValidator(ctx, validator)
|
k.SetValidator(ctx, validator)
|
||||||
store.Set(GetValidatorsBondedIndexKey(validator.Operator), []byte{})
|
store.Set(GetValidatorsBondedIndexKey(validator.OperatorAddr), []byte{})
|
||||||
|
|
||||||
// add to accumulated changes for tendermint
|
// add to accumulated changes for tendermint
|
||||||
bzABCI := k.cdc.MustMarshalBinary(validator.ABCIValidatorUpdate())
|
bzABCI := k.cdc.MustMarshalBinary(validator.ABCIValidatorUpdate())
|
||||||
store.Set(GetTendermintUpdatesKey(validator.Operator), bzABCI)
|
store.Set(GetTendermintUpdatesKey(validator.OperatorAddr), bzABCI)
|
||||||
|
|
||||||
// call the bond hook if present
|
// call the bond hook if present
|
||||||
if k.validatorHooks != nil {
|
if k.validatorHooks != nil {
|
||||||
|
@ -696,15 +696,15 @@ func (k Keeper) RemoveValidator(ctx sdk.Context, address sdk.ValAddress) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
pool := k.GetPool(ctx)
|
pool := k.GetPool(ctx)
|
||||||
store.Delete(GetValidatorKey(address))
|
store.Delete(GetValidatorKey(address))
|
||||||
store.Delete(GetValidatorByPubKeyIndexKey(validator.PubKey))
|
store.Delete(GetValidatorByPubKeyIndexKey(validator.ConsPubKey))
|
||||||
store.Delete(GetValidatorsByPowerIndexKey(validator, pool))
|
store.Delete(GetValidatorsByPowerIndexKey(validator, pool))
|
||||||
|
|
||||||
// delete from the current and power weighted validator groups if the validator
|
// delete from the current and power weighted validator groups if the validator
|
||||||
// is bonded - and add validator with zero power to the validator updates
|
// is bonded - and add validator with zero power to the validator updates
|
||||||
if store.Get(GetValidatorsBondedIndexKey(validator.Operator)) == nil {
|
if store.Get(GetValidatorsBondedIndexKey(validator.OperatorAddr)) == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
store.Delete(GetValidatorsBondedIndexKey(validator.Operator))
|
store.Delete(GetValidatorsBondedIndexKey(validator.OperatorAddr))
|
||||||
|
|
||||||
bz := k.cdc.MustMarshalBinary(validator.ABCIValidatorUpdateZero())
|
bz := k.cdc.MustMarshalBinary(validator.ABCIValidatorUpdateZero())
|
||||||
store.Set(GetTendermintUpdatesKey(address), bz)
|
store.Set(GetTendermintUpdatesKey(address), bz)
|
||||||
|
@ -729,7 +729,7 @@ func (k Keeper) setCliffValidator(ctx sdk.Context, validator types.Validator, po
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
bz := GetValidatorsByPowerIndexKey(validator, pool)
|
bz := GetValidatorsByPowerIndexKey(validator, pool)
|
||||||
store.Set(ValidatorPowerCliffKey, bz)
|
store.Set(ValidatorPowerCliffKey, bz)
|
||||||
store.Set(ValidatorCliffIndexKey, validator.Operator)
|
store.Set(ValidatorCliffIndexKey, validator.OperatorAddr)
|
||||||
}
|
}
|
||||||
|
|
||||||
// clear the current validator and power of the validator on the cliff
|
// clear the current validator and power of the validator on the cliff
|
||||||
|
|
|
@ -129,7 +129,7 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
|
||||||
|
|
||||||
// require the cliff validator has changed
|
// require the cliff validator has changed
|
||||||
cliffVal := validators[numVals-maxVals-1]
|
cliffVal := validators[numVals-maxVals-1]
|
||||||
require.Equal(t, cliffVal.Operator, sdk.ValAddress(keeper.GetCliffValidator(ctx)))
|
require.Equal(t, cliffVal.OperatorAddr, sdk.ValAddress(keeper.GetCliffValidator(ctx)))
|
||||||
|
|
||||||
// require the cliff validator power has changed
|
// require the cliff validator power has changed
|
||||||
cliffPower := keeper.GetCliffValidatorPower(ctx)
|
cliffPower := keeper.GetCliffValidatorPower(ctx)
|
||||||
|
@ -142,7 +142,7 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
|
||||||
|
|
||||||
// require all the validators have their respective statuses
|
// require all the validators have their respective statuses
|
||||||
for valIdx, status := range expectedValStatus {
|
for valIdx, status := range expectedValStatus {
|
||||||
valAddr := validators[valIdx].Operator
|
valAddr := validators[valIdx].OperatorAddr
|
||||||
val, _ := keeper.GetValidator(ctx, valAddr)
|
val, _ := keeper.GetValidator(ctx, valAddr)
|
||||||
|
|
||||||
assert.Equal(
|
assert.Equal(
|
||||||
|
@ -192,7 +192,7 @@ func TestCliffValidatorChange(t *testing.T) {
|
||||||
|
|
||||||
// assert new cliff validator to be set to the second lowest bonded validator by power
|
// assert new cliff validator to be set to the second lowest bonded validator by power
|
||||||
newCliffVal := validators[numVals-maxVals+1]
|
newCliffVal := validators[numVals-maxVals+1]
|
||||||
require.Equal(t, newCliffVal.Operator, sdk.ValAddress(keeper.GetCliffValidator(ctx)))
|
require.Equal(t, newCliffVal.OperatorAddr, sdk.ValAddress(keeper.GetCliffValidator(ctx)))
|
||||||
|
|
||||||
// assert cliff validator power should have been updated
|
// assert cliff validator power should have been updated
|
||||||
cliffPower := keeper.GetCliffValidatorPower(ctx)
|
cliffPower := keeper.GetCliffValidatorPower(ctx)
|
||||||
|
@ -205,7 +205,7 @@ func TestCliffValidatorChange(t *testing.T) {
|
||||||
|
|
||||||
// assert cliff validator has not change but increased in power
|
// assert cliff validator has not change but increased in power
|
||||||
cliffPower = keeper.GetCliffValidatorPower(ctx)
|
cliffPower = keeper.GetCliffValidatorPower(ctx)
|
||||||
require.Equal(t, newCliffVal.Operator, sdk.ValAddress(keeper.GetCliffValidator(ctx)))
|
require.Equal(t, newCliffVal.OperatorAddr, sdk.ValAddress(keeper.GetCliffValidator(ctx)))
|
||||||
require.Equal(t, GetValidatorsByPowerIndexKey(newCliffVal, pool), cliffPower)
|
require.Equal(t, GetValidatorsByPowerIndexKey(newCliffVal, pool), cliffPower)
|
||||||
|
|
||||||
// add enough power to cliff validator to be equal in rank to next validator
|
// add enough power to cliff validator to be equal in rank to next validator
|
||||||
|
@ -215,7 +215,7 @@ func TestCliffValidatorChange(t *testing.T) {
|
||||||
|
|
||||||
// assert new cliff validator due to power rank construction
|
// assert new cliff validator due to power rank construction
|
||||||
newCliffVal = validators[numVals-maxVals+2]
|
newCliffVal = validators[numVals-maxVals+2]
|
||||||
require.Equal(t, newCliffVal.Operator, sdk.ValAddress(keeper.GetCliffValidator(ctx)))
|
require.Equal(t, newCliffVal.OperatorAddr, sdk.ValAddress(keeper.GetCliffValidator(ctx)))
|
||||||
|
|
||||||
// assert cliff validator power should have been updated
|
// assert cliff validator power should have been updated
|
||||||
cliffPower = keeper.GetCliffValidatorPower(ctx)
|
cliffPower = keeper.GetCliffValidatorPower(ctx)
|
||||||
|
@ -317,7 +317,7 @@ func TestValidatorBasics(t *testing.T) {
|
||||||
assert.True(ValEq(t, validators[2], resVals[2]))
|
assert.True(ValEq(t, validators[2], resVals[2]))
|
||||||
|
|
||||||
// remove a record
|
// remove a record
|
||||||
keeper.RemoveValidator(ctx, validators[1].Operator)
|
keeper.RemoveValidator(ctx, validators[1].OperatorAddr)
|
||||||
_, found = keeper.GetValidator(ctx, addrVals[1])
|
_, found = keeper.GetValidator(ctx, addrVals[1])
|
||||||
require.False(t, found)
|
require.False(t, found)
|
||||||
}
|
}
|
||||||
|
@ -346,11 +346,11 @@ func GetValidatorSortingUnmixed(t *testing.T) {
|
||||||
assert.Equal(t, sdk.NewDec(100), resValidators[2].BondedTokens(), "%v", resValidators)
|
assert.Equal(t, sdk.NewDec(100), resValidators[2].BondedTokens(), "%v", resValidators)
|
||||||
assert.Equal(t, sdk.NewDec(1), resValidators[3].BondedTokens(), "%v", resValidators)
|
assert.Equal(t, sdk.NewDec(1), resValidators[3].BondedTokens(), "%v", resValidators)
|
||||||
assert.Equal(t, sdk.NewDec(0), resValidators[4].BondedTokens(), "%v", resValidators)
|
assert.Equal(t, sdk.NewDec(0), resValidators[4].BondedTokens(), "%v", resValidators)
|
||||||
assert.Equal(t, validators[3].Operator, resValidators[0].Operator, "%v", resValidators)
|
assert.Equal(t, validators[3].OperatorAddr, resValidators[0].OperatorAddr, "%v", resValidators)
|
||||||
assert.Equal(t, validators[4].Operator, resValidators[1].Operator, "%v", resValidators)
|
assert.Equal(t, validators[4].OperatorAddr, resValidators[1].OperatorAddr, "%v", resValidators)
|
||||||
assert.Equal(t, validators[1].Operator, resValidators[2].Operator, "%v", resValidators)
|
assert.Equal(t, validators[1].OperatorAddr, resValidators[2].OperatorAddr, "%v", resValidators)
|
||||||
assert.Equal(t, validators[2].Operator, resValidators[3].Operator, "%v", resValidators)
|
assert.Equal(t, validators[2].OperatorAddr, resValidators[3].OperatorAddr, "%v", resValidators)
|
||||||
assert.Equal(t, validators[0].Operator, resValidators[4].Operator, "%v", resValidators)
|
assert.Equal(t, validators[0].OperatorAddr, resValidators[4].OperatorAddr, "%v", resValidators)
|
||||||
|
|
||||||
// test a basic increase in voting power
|
// test a basic increase in voting power
|
||||||
validators[3].Tokens = sdk.NewDec(500)
|
validators[3].Tokens = sdk.NewDec(500)
|
||||||
|
@ -457,11 +457,11 @@ func GetValidatorSortingMixed(t *testing.T) {
|
||||||
assert.Equal(t, sdk.NewDec(100), resValidators[2].BondedTokens(), "%v", resValidators)
|
assert.Equal(t, sdk.NewDec(100), resValidators[2].BondedTokens(), "%v", resValidators)
|
||||||
assert.Equal(t, sdk.NewDec(1), resValidators[3].BondedTokens(), "%v", resValidators)
|
assert.Equal(t, sdk.NewDec(1), resValidators[3].BondedTokens(), "%v", resValidators)
|
||||||
assert.Equal(t, sdk.NewDec(0), resValidators[4].BondedTokens(), "%v", resValidators)
|
assert.Equal(t, sdk.NewDec(0), resValidators[4].BondedTokens(), "%v", resValidators)
|
||||||
assert.Equal(t, validators[3].Operator, resValidators[0].Operator, "%v", resValidators)
|
assert.Equal(t, validators[3].OperatorAddr, resValidators[0].OperatorAddr, "%v", resValidators)
|
||||||
assert.Equal(t, validators[4].Operator, resValidators[1].Operator, "%v", resValidators)
|
assert.Equal(t, validators[4].OperatorAddr, resValidators[1].OperatorAddr, "%v", resValidators)
|
||||||
assert.Equal(t, validators[1].Operator, resValidators[2].Operator, "%v", resValidators)
|
assert.Equal(t, validators[1].OperatorAddr, resValidators[2].OperatorAddr, "%v", resValidators)
|
||||||
assert.Equal(t, validators[2].Operator, resValidators[3].Operator, "%v", resValidators)
|
assert.Equal(t, validators[2].OperatorAddr, resValidators[3].OperatorAddr, "%v", resValidators)
|
||||||
assert.Equal(t, validators[0].Operator, resValidators[4].Operator, "%v", resValidators)
|
assert.Equal(t, validators[0].OperatorAddr, resValidators[4].OperatorAddr, "%v", resValidators)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO separate out into multiple tests
|
// TODO separate out into multiple tests
|
||||||
|
@ -488,7 +488,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range amts {
|
for i := range amts {
|
||||||
validators[i], found = keeper.GetValidator(ctx, validators[i].Operator)
|
validators[i], found = keeper.GetValidator(ctx, validators[i].OperatorAddr)
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
}
|
}
|
||||||
resValidators := keeper.GetValidatorsByPower(ctx)
|
resValidators := keeper.GetValidatorsByPower(ctx)
|
||||||
|
@ -512,7 +512,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
|
||||||
// validator 3 enters bonded validator set
|
// validator 3 enters bonded validator set
|
||||||
ctx = ctx.WithBlockHeight(40)
|
ctx = ctx.WithBlockHeight(40)
|
||||||
|
|
||||||
validators[3], found = keeper.GetValidator(ctx, validators[3].Operator)
|
validators[3], found = keeper.GetValidator(ctx, validators[3].OperatorAddr)
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
validators[3], pool, _ = validators[3].AddTokensFromDel(pool, sdk.NewInt(1))
|
validators[3], pool, _ = validators[3].AddTokensFromDel(pool, sdk.NewInt(1))
|
||||||
keeper.SetPool(ctx, pool)
|
keeper.SetPool(ctx, pool)
|
||||||
|
@ -539,7 +539,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
|
||||||
require.Equal(t, nMax, uint16(len(resValidators)))
|
require.Equal(t, nMax, uint16(len(resValidators)))
|
||||||
assert.True(ValEq(t, validators[0], resValidators[0]))
|
assert.True(ValEq(t, validators[0], resValidators[0]))
|
||||||
assert.True(ValEq(t, validators[2], resValidators[1]))
|
assert.True(ValEq(t, validators[2], resValidators[1]))
|
||||||
validator, exists := keeper.GetValidator(ctx, validators[3].Operator)
|
validator, exists := keeper.GetValidator(ctx, validators[3].OperatorAddr)
|
||||||
require.Equal(t, exists, true)
|
require.Equal(t, exists, true)
|
||||||
require.Equal(t, int64(40), validator.BondHeight)
|
require.Equal(t, int64(40), validator.BondHeight)
|
||||||
}
|
}
|
||||||
|
@ -609,7 +609,7 @@ func TestFullValidatorSetPowerChange(t *testing.T) {
|
||||||
}
|
}
|
||||||
for i := range amts {
|
for i := range amts {
|
||||||
var found bool
|
var found bool
|
||||||
validators[i], found = keeper.GetValidator(ctx, validators[i].Operator)
|
validators[i], found = keeper.GetValidator(ctx, validators[i].OperatorAddr)
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
}
|
}
|
||||||
assert.Equal(t, sdk.Unbonding, validators[0].Status)
|
assert.Equal(t, sdk.Unbonding, validators[0].Status)
|
||||||
|
@ -682,13 +682,13 @@ func TestGetTendermintUpdatesAllNone(t *testing.T) {
|
||||||
keeper.ClearTendermintUpdates(ctx)
|
keeper.ClearTendermintUpdates(ctx)
|
||||||
require.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx)))
|
require.Equal(t, 0, len(keeper.GetTendermintUpdates(ctx)))
|
||||||
|
|
||||||
keeper.RemoveValidator(ctx, validators[0].Operator)
|
keeper.RemoveValidator(ctx, validators[0].OperatorAddr)
|
||||||
keeper.RemoveValidator(ctx, validators[1].Operator)
|
keeper.RemoveValidator(ctx, validators[1].OperatorAddr)
|
||||||
|
|
||||||
updates = keeper.GetTendermintUpdates(ctx)
|
updates = keeper.GetTendermintUpdates(ctx)
|
||||||
assert.Equal(t, 2, len(updates))
|
assert.Equal(t, 2, len(updates))
|
||||||
assert.Equal(t, tmtypes.TM2PB.PubKey(validators[0].PubKey), updates[0].PubKey)
|
assert.Equal(t, tmtypes.TM2PB.PubKey(validators[0].ConsPubKey), updates[0].PubKey)
|
||||||
assert.Equal(t, tmtypes.TM2PB.PubKey(validators[1].PubKey), updates[1].PubKey)
|
assert.Equal(t, tmtypes.TM2PB.PubKey(validators[1].ConsPubKey), updates[1].PubKey)
|
||||||
assert.Equal(t, int64(0), updates[0].Power)
|
assert.Equal(t, int64(0), updates[0].Power)
|
||||||
assert.Equal(t, int64(0), updates[1].Power)
|
assert.Equal(t, int64(0), updates[1].Power)
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ func ErrNoValidatorFound(codespace sdk.CodespaceType) sdk.Error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrValidatorOwnerExists(codespace sdk.CodespaceType) sdk.Error {
|
func ErrValidatorOwnerExists(codespace sdk.CodespaceType) sdk.Error {
|
||||||
return sdk.NewError(codespace, CodeInvalidValidator, "validator already exist for this owner-address, must use new validator-owner address")
|
return sdk.NewError(codespace, CodeInvalidValidator, "validator already exist for this operator address, must use new validator operator address")
|
||||||
}
|
}
|
||||||
|
|
||||||
func ErrValidatorPubKeyExists(codespace sdk.CodespaceType) sdk.Error {
|
func ErrValidatorPubKeyExists(codespace sdk.CodespaceType) sdk.Error {
|
||||||
|
|
|
@ -21,8 +21,8 @@ import (
|
||||||
// exchange rate. Voting power can be calculated as total bonds multiplied by
|
// exchange rate. Voting power can be calculated as total bonds multiplied by
|
||||||
// exchange rate.
|
// exchange rate.
|
||||||
type Validator struct {
|
type Validator struct {
|
||||||
Operator sdk.ValAddress `json:"operator"` // sender of BondTx - UnbondTx returns here
|
OperatorAddr sdk.ValAddress `json:"operator_address"` // address of the validator's operator
|
||||||
PubKey crypto.PubKey `json:"pub_key"` // pubkey of validator
|
ConsPubKey crypto.PubKey `json:"consensus_pubkey"` // the consensus public key of the validator
|
||||||
Jailed bool `json:"jailed"` // has the validator been jailed from bonded status?
|
Jailed bool `json:"jailed"` // has the validator been jailed from bonded status?
|
||||||
|
|
||||||
Status sdk.BondStatus `json:"status"` // validator status (bonded/unbonding/unbonded)
|
Status sdk.BondStatus `json:"status"` // validator status (bonded/unbonding/unbonded)
|
||||||
|
@ -45,8 +45,8 @@ type Validator struct {
|
||||||
// NewValidator - initialize a new validator
|
// NewValidator - initialize a new validator
|
||||||
func NewValidator(operator sdk.ValAddress, pubKey crypto.PubKey, description Description) Validator {
|
func NewValidator(operator sdk.ValAddress, pubKey crypto.PubKey, description Description) Validator {
|
||||||
return Validator{
|
return Validator{
|
||||||
Operator: operator,
|
OperatorAddr: operator,
|
||||||
PubKey: pubKey,
|
ConsPubKey: pubKey,
|
||||||
Jailed: false,
|
Jailed: false,
|
||||||
Status: sdk.Unbonded,
|
Status: sdk.Unbonded,
|
||||||
Tokens: sdk.ZeroDec(),
|
Tokens: sdk.ZeroDec(),
|
||||||
|
@ -65,7 +65,7 @@ func NewValidator(operator sdk.ValAddress, pubKey crypto.PubKey, description Des
|
||||||
|
|
||||||
// what's kept in the store value
|
// what's kept in the store value
|
||||||
type validatorValue struct {
|
type validatorValue struct {
|
||||||
PubKey crypto.PubKey
|
ConsPubKey crypto.PubKey
|
||||||
Jailed bool
|
Jailed bool
|
||||||
Status sdk.BondStatus
|
Status sdk.BondStatus
|
||||||
Tokens sdk.Dec
|
Tokens sdk.Dec
|
||||||
|
@ -84,7 +84,7 @@ type validatorValue struct {
|
||||||
// return the redelegation without fields contained within the key for the store
|
// return the redelegation without fields contained within the key for the store
|
||||||
func MustMarshalValidator(cdc *wire.Codec, validator Validator) []byte {
|
func MustMarshalValidator(cdc *wire.Codec, validator Validator) []byte {
|
||||||
val := validatorValue{
|
val := validatorValue{
|
||||||
PubKey: validator.PubKey,
|
ConsPubKey: validator.ConsPubKey,
|
||||||
Jailed: validator.Jailed,
|
Jailed: validator.Jailed,
|
||||||
Status: validator.Status,
|
Status: validator.Status,
|
||||||
Tokens: validator.Tokens,
|
Tokens: validator.Tokens,
|
||||||
|
@ -124,8 +124,8 @@ func UnmarshalValidator(cdc *wire.Codec, operatorAddr, value []byte) (validator
|
||||||
}
|
}
|
||||||
|
|
||||||
return Validator{
|
return Validator{
|
||||||
Operator: operatorAddr,
|
OperatorAddr: operatorAddr,
|
||||||
PubKey: storeValue.PubKey,
|
ConsPubKey: storeValue.ConsPubKey,
|
||||||
Jailed: storeValue.Jailed,
|
Jailed: storeValue.Jailed,
|
||||||
Tokens: storeValue.Tokens,
|
Tokens: storeValue.Tokens,
|
||||||
Status: storeValue.Status,
|
Status: storeValue.Status,
|
||||||
|
@ -146,14 +146,14 @@ func UnmarshalValidator(cdc *wire.Codec, operatorAddr, value []byte) (validator
|
||||||
// validator. An error is returned if the operator or the operator's public key
|
// validator. An error is returned if the operator or the operator's public key
|
||||||
// cannot be converted to Bech32 format.
|
// cannot be converted to Bech32 format.
|
||||||
func (v Validator) HumanReadableString() (string, error) {
|
func (v Validator) HumanReadableString() (string, error) {
|
||||||
bechConsPubKey, err := sdk.Bech32ifyConsPub(v.PubKey)
|
bechConsPubKey, err := sdk.Bech32ifyConsPub(v.ConsPubKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
resp := "Validator \n"
|
resp := "Validator \n"
|
||||||
resp += fmt.Sprintf("Operator: %s\n", v.Operator)
|
resp += fmt.Sprintf("Operator Address: %s\n", v.OperatorAddr)
|
||||||
resp += fmt.Sprintf("Validator: %s\n", bechConsPubKey)
|
resp += fmt.Sprintf("Validator Consensus Pubkey: %s\n", bechConsPubKey)
|
||||||
resp += fmt.Sprintf("Jailed: %v\n", v.Jailed)
|
resp += fmt.Sprintf("Jailed: %v\n", v.Jailed)
|
||||||
resp += fmt.Sprintf("Status: %s\n", sdk.BondStatusToString(v.Status))
|
resp += fmt.Sprintf("Status: %s\n", sdk.BondStatusToString(v.Status))
|
||||||
resp += fmt.Sprintf("Tokens: %s\n", v.Tokens.String())
|
resp += fmt.Sprintf("Tokens: %s\n", v.Tokens.String())
|
||||||
|
@ -174,8 +174,8 @@ func (v Validator) HumanReadableString() (string, error) {
|
||||||
|
|
||||||
// validator struct for bech output
|
// validator struct for bech output
|
||||||
type BechValidator struct {
|
type BechValidator struct {
|
||||||
Operator sdk.ValAddress `json:"operator"` // in bech32
|
OperatorAddr sdk.ValAddress `json:"operator_address"` // the bech32 address of the validator's operator
|
||||||
PubKey string `json:"pub_key"` // in bech32
|
ConsPubKey string `json:"consensus_pubkey"` // the bech32 consensus public key of the validator
|
||||||
Jailed bool `json:"jailed"` // has the validator been jailed from bonded status?
|
Jailed bool `json:"jailed"` // has the validator been jailed from bonded status?
|
||||||
|
|
||||||
Status sdk.BondStatus `json:"status"` // validator status (bonded/unbonding/unbonded)
|
Status sdk.BondStatus `json:"status"` // validator status (bonded/unbonding/unbonded)
|
||||||
|
@ -197,14 +197,14 @@ type BechValidator struct {
|
||||||
|
|
||||||
// get the bech validator from the the regular validator
|
// get the bech validator from the the regular validator
|
||||||
func (v Validator) Bech32Validator() (BechValidator, error) {
|
func (v Validator) Bech32Validator() (BechValidator, error) {
|
||||||
bechConsPubKey, err := sdk.Bech32ifyConsPub(v.PubKey)
|
bechConsPubKey, err := sdk.Bech32ifyConsPub(v.ConsPubKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return BechValidator{}, err
|
return BechValidator{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return BechValidator{
|
return BechValidator{
|
||||||
Operator: v.Operator,
|
OperatorAddr: v.OperatorAddr,
|
||||||
PubKey: bechConsPubKey,
|
ConsPubKey: bechConsPubKey,
|
||||||
Jailed: v.Jailed,
|
Jailed: v.Jailed,
|
||||||
|
|
||||||
Status: v.Status,
|
Status: v.Status,
|
||||||
|
@ -229,8 +229,8 @@ func (v Validator) Bech32Validator() (BechValidator, error) {
|
||||||
// only the vitals - does not check bond height of IntraTxCounter
|
// only the vitals - does not check bond height of IntraTxCounter
|
||||||
// nolint gocyclo - why dis fail?
|
// nolint gocyclo - why dis fail?
|
||||||
func (v Validator) Equal(c2 Validator) bool {
|
func (v Validator) Equal(c2 Validator) bool {
|
||||||
return v.PubKey.Equals(c2.PubKey) &&
|
return v.ConsPubKey.Equals(c2.ConsPubKey) &&
|
||||||
bytes.Equal(v.Operator, c2.Operator) &&
|
bytes.Equal(v.OperatorAddr, c2.OperatorAddr) &&
|
||||||
v.Status.Equal(c2.Status) &&
|
v.Status.Equal(c2.Status) &&
|
||||||
v.Tokens.Equal(c2.Tokens) &&
|
v.Tokens.Equal(c2.Tokens) &&
|
||||||
v.DelegatorShares.Equal(c2.DelegatorShares) &&
|
v.DelegatorShares.Equal(c2.DelegatorShares) &&
|
||||||
|
@ -243,7 +243,7 @@ func (v Validator) Equal(c2 Validator) bool {
|
||||||
|
|
||||||
// return the TM validator address
|
// return the TM validator address
|
||||||
func (v Validator) ConsAddress() sdk.ConsAddress {
|
func (v Validator) ConsAddress() sdk.ConsAddress {
|
||||||
return sdk.ConsAddress(v.PubKey.Address())
|
return sdk.ConsAddress(v.ConsPubKey.Address())
|
||||||
}
|
}
|
||||||
|
|
||||||
// constant used in flags to indicate that description field should not be updated
|
// constant used in flags to indicate that description field should not be updated
|
||||||
|
@ -313,7 +313,7 @@ func (d Description) EnsureLength() (Description, sdk.Error) {
|
||||||
// with the full validator power
|
// with the full validator power
|
||||||
func (v Validator) ABCIValidatorUpdate() abci.ValidatorUpdate {
|
func (v Validator) ABCIValidatorUpdate() abci.ValidatorUpdate {
|
||||||
return abci.ValidatorUpdate{
|
return abci.ValidatorUpdate{
|
||||||
PubKey: tmtypes.TM2PB.PubKey(v.PubKey),
|
PubKey: tmtypes.TM2PB.PubKey(v.ConsPubKey),
|
||||||
Power: v.BondedTokens().RoundInt64(),
|
Power: v.BondedTokens().RoundInt64(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -322,7 +322,7 @@ func (v Validator) ABCIValidatorUpdate() abci.ValidatorUpdate {
|
||||||
// with zero power used for validator updates.
|
// with zero power used for validator updates.
|
||||||
func (v Validator) ABCIValidatorUpdateZero() abci.ValidatorUpdate {
|
func (v Validator) ABCIValidatorUpdateZero() abci.ValidatorUpdate {
|
||||||
return abci.ValidatorUpdate{
|
return abci.ValidatorUpdate{
|
||||||
PubKey: tmtypes.TM2PB.PubKey(v.PubKey),
|
PubKey: tmtypes.TM2PB.PubKey(v.ConsPubKey),
|
||||||
Power: 0,
|
Power: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -445,8 +445,8 @@ var _ sdk.Validator = Validator{}
|
||||||
func (v Validator) GetJailed() bool { return v.Jailed }
|
func (v Validator) GetJailed() bool { return v.Jailed }
|
||||||
func (v Validator) GetMoniker() string { return v.Description.Moniker }
|
func (v Validator) GetMoniker() string { return v.Description.Moniker }
|
||||||
func (v Validator) GetStatus() sdk.BondStatus { return v.Status }
|
func (v Validator) GetStatus() sdk.BondStatus { return v.Status }
|
||||||
func (v Validator) GetOperator() sdk.ValAddress { return v.Operator }
|
func (v Validator) GetOperator() sdk.ValAddress { return v.OperatorAddr }
|
||||||
func (v Validator) GetPubKey() crypto.PubKey { return v.PubKey }
|
func (v Validator) GetPubKey() crypto.PubKey { return v.ConsPubKey }
|
||||||
func (v Validator) GetPower() sdk.Dec { return v.BondedTokens() }
|
func (v Validator) GetPower() sdk.Dec { return v.BondedTokens() }
|
||||||
func (v Validator) GetTokens() sdk.Dec { return v.Tokens }
|
func (v Validator) GetTokens() sdk.Dec { return v.Tokens }
|
||||||
func (v Validator) GetDelegatorShares() sdk.Dec { return v.DelegatorShares }
|
func (v Validator) GetDelegatorShares() sdk.Dec { return v.DelegatorShares }
|
||||||
|
|
|
@ -57,23 +57,24 @@ func TestABCIValidatorUpdate(t *testing.T) {
|
||||||
validator := NewValidator(addr1, pk1, Description{})
|
validator := NewValidator(addr1, pk1, Description{})
|
||||||
|
|
||||||
abciVal := validator.ABCIValidatorUpdate()
|
abciVal := validator.ABCIValidatorUpdate()
|
||||||
require.Equal(t, tmtypes.TM2PB.PubKey(pk1), abciVal.PubKey)
|
require.Equal(t, tmtypes.TM2PB.PubKey(validator.ConsPubKey), abciVal.PubKey)
|
||||||
require.Equal(t, validator.BondedTokens().RoundInt64(), abciVal.Power)
|
require.Equal(t, validator.BondedTokens().RoundInt64(), abciVal.Power)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestABCIValidatorUpdateZero(t *testing.T) {
|
func TestABCIValidatorUpdateZero(t *testing.T) {
|
||||||
validator := NewValidator(addr1, pk1, Description{})
|
validator := NewValidator(addr1, pk1, Description{})
|
||||||
|
|
||||||
|
|
||||||
abciVal := validator.ABCIValidatorUpdateZero()
|
abciVal := validator.ABCIValidatorUpdateZero()
|
||||||
require.Equal(t, tmtypes.TM2PB.PubKey(validator.PubKey), abciVal.PubKey)
|
require.Equal(t, tmtypes.TM2PB.PubKey(validator.ConsPubKey), abciVal.PubKey)
|
||||||
require.Equal(t, int64(0), abciVal.Power)
|
require.Equal(t, int64(0), abciVal.Power)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRemoveTokens(t *testing.T) {
|
func TestRemoveTokens(t *testing.T) {
|
||||||
|
|
||||||
validator := Validator{
|
validator := Validator{
|
||||||
Operator: addr1,
|
OperatorAddr: addr1,
|
||||||
PubKey: pk1,
|
ConsPubKey: pk1,
|
||||||
Status: sdk.Bonded,
|
Status: sdk.Bonded,
|
||||||
Tokens: sdk.NewDec(100),
|
Tokens: sdk.NewDec(100),
|
||||||
DelegatorShares: sdk.NewDec(100),
|
DelegatorShares: sdk.NewDec(100),
|
||||||
|
@ -148,8 +149,8 @@ func TestAddTokensValidatorUnbonded(t *testing.T) {
|
||||||
// TODO refactor to make simpler like the AddToken tests above
|
// TODO refactor to make simpler like the AddToken tests above
|
||||||
func TestRemoveDelShares(t *testing.T) {
|
func TestRemoveDelShares(t *testing.T) {
|
||||||
valA := Validator{
|
valA := Validator{
|
||||||
Operator: addr1,
|
OperatorAddr: addr1,
|
||||||
PubKey: pk1,
|
ConsPubKey: pk1,
|
||||||
Status: sdk.Bonded,
|
Status: sdk.Bonded,
|
||||||
Tokens: sdk.NewDec(100),
|
Tokens: sdk.NewDec(100),
|
||||||
DelegatorShares: sdk.NewDec(100),
|
DelegatorShares: sdk.NewDec(100),
|
||||||
|
@ -176,8 +177,8 @@ func TestRemoveDelShares(t *testing.T) {
|
||||||
poolTokens := sdk.NewDec(5102)
|
poolTokens := sdk.NewDec(5102)
|
||||||
delShares := sdk.NewDec(115)
|
delShares := sdk.NewDec(115)
|
||||||
validator := Validator{
|
validator := Validator{
|
||||||
Operator: addr1,
|
OperatorAddr: addr1,
|
||||||
PubKey: pk1,
|
ConsPubKey: pk1,
|
||||||
Status: sdk.Bonded,
|
Status: sdk.Bonded,
|
||||||
Tokens: poolTokens,
|
Tokens: poolTokens,
|
||||||
DelegatorShares: delShares,
|
DelegatorShares: delShares,
|
||||||
|
@ -229,8 +230,8 @@ func TestPossibleOverflow(t *testing.T) {
|
||||||
poolTokens := sdk.NewDec(2159)
|
poolTokens := sdk.NewDec(2159)
|
||||||
delShares := sdk.NewDec(391432570689183511).Quo(sdk.NewDec(40113011844664))
|
delShares := sdk.NewDec(391432570689183511).Quo(sdk.NewDec(40113011844664))
|
||||||
validator := Validator{
|
validator := Validator{
|
||||||
Operator: addr1,
|
OperatorAddr: addr1,
|
||||||
PubKey: pk1,
|
ConsPubKey: pk1,
|
||||||
Status: sdk.Bonded,
|
Status: sdk.Bonded,
|
||||||
Tokens: poolTokens,
|
Tokens: poolTokens,
|
||||||
DelegatorShares: delShares,
|
DelegatorShares: delShares,
|
||||||
|
|
Loading…
Reference in New Issue