Merge PR #5600: Migrate x/staking to Protobuf
This commit is contained in:
parent
b0c6c750df
commit
53bf2271d5
|
@ -46,6 +46,7 @@ ignore:
|
||||||
- "docs"
|
- "docs"
|
||||||
- "*.md"
|
- "*.md"
|
||||||
- "*.rst"
|
- "*.rst"
|
||||||
|
- "*.pb.go"
|
||||||
- "x/**/test_common.go"
|
- "x/**/test_common.go"
|
||||||
- "scripts/"
|
- "scripts/"
|
||||||
- "contrib"
|
- "contrib"
|
||||||
|
|
|
@ -47,7 +47,7 @@ issues:
|
||||||
- text: "ST1003:"
|
- text: "ST1003:"
|
||||||
linters:
|
linters:
|
||||||
- stylecheck
|
- stylecheck
|
||||||
# FIXME disabled until golangci-lint updates stylecheck with this fix:
|
# FIXME: Disabled until golangci-lint updates stylecheck with this fix:
|
||||||
# https://github.com/dominikh/go-tools/issues/389
|
# https://github.com/dominikh/go-tools/issues/389
|
||||||
- text: "ST1016:"
|
- text: "ST1016:"
|
||||||
linters:
|
linters:
|
||||||
|
|
|
@ -60,6 +60,14 @@ balances or a single balance by denom when the `denom` query parameter is presen
|
||||||
* Callers to `NewBaseVestingAccount` are responsible for verifying account balance in relation to
|
* Callers to `NewBaseVestingAccount` are responsible for verifying account balance in relation to
|
||||||
the original vesting amount.
|
the original vesting amount.
|
||||||
* The `SendKeeper` and `ViewKeeper` interfaces in `x/bank` have been modified to account for changes.
|
* The `SendKeeper` and `ViewKeeper` interfaces in `x/bank` have been modified to account for changes.
|
||||||
|
* (staking) [\#5600](https://github.com/cosmos/cosmos-sdk/pull/5600) Migrate the `x/staking` module to use Protocol Buffer for state
|
||||||
|
serialization instead of Amino. The exact codec used is `codec.HybridCodec` which utilizes Protobuf for binary encoding and Amino
|
||||||
|
for JSON encoding.
|
||||||
|
* `BondStatus` is now of type `int32` instead of `byte`.
|
||||||
|
* Types of `int16` in the `Params` type are now of type `int32`.
|
||||||
|
* Every reference of `crypto.Pubkey` in context of a `Validator` is now of type string. `GetPubKeyFromBech32` must be used to get the `crypto.Pubkey`.
|
||||||
|
* The `Keeper` constructor now takes a `codec.Marshaler` instead of a concrete Amino codec. This exact type
|
||||||
|
provided is specified by `ModuleCdc`.
|
||||||
|
|
||||||
### Improvements
|
### Improvements
|
||||||
|
|
||||||
|
|
|
@ -45,8 +45,8 @@ func RegisterEvidences(cdc *Codec) {
|
||||||
// MarshalJSONIndent provides a utility for indented JSON encoding of an object
|
// MarshalJSONIndent provides a utility for indented JSON encoding of an object
|
||||||
// via an Amino codec. It returns an error if it cannot serialize or indent as
|
// via an Amino codec. It returns an error if it cannot serialize or indent as
|
||||||
// JSON.
|
// JSON.
|
||||||
func MarshalJSONIndent(cdc *Codec, obj interface{}) ([]byte, error) {
|
func MarshalJSONIndent(m JSONMarshaler, obj interface{}) ([]byte, error) {
|
||||||
bz, err := cdc.MarshalJSON(obj)
|
bz, err := m.MarshalJSON(obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -60,8 +60,8 @@ func MarshalJSONIndent(cdc *Codec, obj interface{}) ([]byte, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustMarshalJSONIndent executes MarshalJSONIndent except it panics upon failure.
|
// MustMarshalJSONIndent executes MarshalJSONIndent except it panics upon failure.
|
||||||
func MustMarshalJSONIndent(cdc *Codec, obj interface{}) []byte {
|
func MustMarshalJSONIndent(m JSONMarshaler, obj interface{}) []byte {
|
||||||
bz, err := MarshalJSONIndent(cdc, obj)
|
bz, err := MarshalJSONIndent(m, obj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(fmt.Sprintf("failed to marshal JSON: %s", err))
|
panic(fmt.Sprintf("failed to marshal JSON: %s", err))
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,10 @@ type (
|
||||||
UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error
|
UnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler) error
|
||||||
MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler)
|
MustUnmarshalBinaryLengthPrefixed(bz []byte, ptr ProtoMarshaler)
|
||||||
|
|
||||||
|
JSONMarshaler
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONMarshaler interface {
|
||||||
MarshalJSON(o interface{}) ([]byte, error) // nolint: stdmethods
|
MarshalJSON(o interface{}) ([]byte, error) // nolint: stdmethods
|
||||||
MustMarshalJSON(o interface{}) []byte
|
MustMarshalJSON(o interface{}) []byte
|
||||||
|
|
||||||
|
|
1
go.mod
1
go.mod
|
@ -9,6 +9,7 @@ require (
|
||||||
github.com/cosmos/ledger-cosmos-go v0.11.1
|
github.com/cosmos/ledger-cosmos-go v0.11.1
|
||||||
github.com/gogo/protobuf v1.3.1
|
github.com/gogo/protobuf v1.3.1
|
||||||
github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129
|
github.com/golang/mock v1.3.1-0.20190508161146-9fa652df1129
|
||||||
|
github.com/golang/protobuf v1.3.2
|
||||||
github.com/gorilla/mux v1.7.3
|
github.com/gorilla/mux v1.7.3
|
||||||
github.com/hashicorp/golang-lru v0.5.4
|
github.com/hashicorp/golang-lru v0.5.4
|
||||||
github.com/mattn/go-isatty v0.0.12
|
github.com/mattn/go-isatty v0.0.12
|
||||||
|
|
|
@ -16,7 +16,6 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/version"
|
"github.com/cosmos/cosmos-sdk/version"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth"
|
"github.com/cosmos/cosmos-sdk/x/auth"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth/ante"
|
"github.com/cosmos/cosmos-sdk/x/auth/ante"
|
||||||
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
|
|
||||||
"github.com/cosmos/cosmos-sdk/x/bank"
|
"github.com/cosmos/cosmos-sdk/x/bank"
|
||||||
"github.com/cosmos/cosmos-sdk/x/crisis"
|
"github.com/cosmos/cosmos-sdk/x/crisis"
|
||||||
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
distr "github.com/cosmos/cosmos-sdk/x/distribution"
|
||||||
|
@ -79,16 +78,6 @@ var (
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// MakeCodec - custom tx codec
|
|
||||||
func MakeCodec() *codec.Codec {
|
|
||||||
var cdc = codec.New()
|
|
||||||
ModuleBasics.RegisterCodec(cdc)
|
|
||||||
vesting.RegisterCodec(cdc)
|
|
||||||
sdk.RegisterCodec(cdc)
|
|
||||||
codec.RegisterCrypto(cdc)
|
|
||||||
return cdc
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify app interface at compile time
|
// Verify app interface at compile time
|
||||||
var _ App = (*SimApp)(nil)
|
var _ App = (*SimApp)(nil)
|
||||||
|
|
||||||
|
@ -135,6 +124,9 @@ func NewSimApp(
|
||||||
invCheckPeriod uint, baseAppOptions ...func(*bam.BaseApp),
|
invCheckPeriod uint, baseAppOptions ...func(*bam.BaseApp),
|
||||||
) *SimApp {
|
) *SimApp {
|
||||||
|
|
||||||
|
appCodec := NewAppCodec()
|
||||||
|
|
||||||
|
// TODO: Remove cdc in favor of appCodec once all modules are migrated.
|
||||||
cdc := MakeCodec()
|
cdc := MakeCodec()
|
||||||
|
|
||||||
bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...)
|
bApp := bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...)
|
||||||
|
@ -180,7 +172,7 @@ func NewSimApp(
|
||||||
app.cdc, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms,
|
app.cdc, keys[supply.StoreKey], app.AccountKeeper, app.BankKeeper, maccPerms,
|
||||||
)
|
)
|
||||||
stakingKeeper := staking.NewKeeper(
|
stakingKeeper := staking.NewKeeper(
|
||||||
app.cdc, keys[staking.StoreKey], app.BankKeeper, app.SupplyKeeper, app.subspaces[staking.ModuleName],
|
appCodec.Staking, keys[staking.StoreKey], app.BankKeeper, app.SupplyKeeper, app.subspaces[staking.ModuleName],
|
||||||
)
|
)
|
||||||
app.MintKeeper = mint.NewKeeper(
|
app.MintKeeper = mint.NewKeeper(
|
||||||
app.cdc, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper,
|
app.cdc, keys[mint.StoreKey], app.subspaces[mint.ModuleName], &stakingKeeper,
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package simapp
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
|
||||||
|
"github.com/cosmos/cosmos-sdk/x/staking"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AppCodec defines the application-level codec. This codec contains all the
|
||||||
|
// required module-specific codecs that are to be provided upon initialization.
|
||||||
|
type AppCodec struct {
|
||||||
|
amino *codec.Codec
|
||||||
|
|
||||||
|
Staking *staking.Codec
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAppCodec() *AppCodec {
|
||||||
|
amino := MakeCodec()
|
||||||
|
|
||||||
|
return &AppCodec{
|
||||||
|
amino: amino,
|
||||||
|
Staking: staking.NewCodec(amino),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// MakeCodec creates and returns a reference to an Amino codec that has all the
|
||||||
|
// necessary types and interfaces registered. This codec is provided to all the
|
||||||
|
// modules the application depends on.
|
||||||
|
//
|
||||||
|
// NOTE: This codec will be deprecated in favor of AppCodec once all modules are
|
||||||
|
// migrated.
|
||||||
|
func MakeCodec() *codec.Codec {
|
||||||
|
var cdc = codec.New()
|
||||||
|
ModuleBasics.RegisterCodec(cdc)
|
||||||
|
vesting.RegisterCodec(cdc)
|
||||||
|
sdk.RegisterCodec(cdc)
|
||||||
|
codec.RegisterCrypto(cdc)
|
||||||
|
return cdc
|
||||||
|
}
|
|
@ -0,0 +1,350 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
package tendermint.abci.types;
|
||||||
|
option go_package = "github.com/tendermint/tendermint/abci/types";
|
||||||
|
|
||||||
|
// For more information on gogo.proto, see:
|
||||||
|
// https://github.com/gogo/protobuf/blob/master/extensions.md
|
||||||
|
import "third_party/proto/gogoproto/gogo.proto";
|
||||||
|
import "third_party/proto/tendermint/crypto/merkle/merkle.proto";
|
||||||
|
import "third_party/proto/tendermint/libs/kv/types.proto";
|
||||||
|
import "google/protobuf/timestamp.proto";
|
||||||
|
import "google/protobuf/duration.proto";
|
||||||
|
|
||||||
|
// This file is copied from http://github.com/tendermint/abci
|
||||||
|
// NOTE: When using custom types, mind the warnings.
|
||||||
|
// https://github.com/gogo/protobuf/blob/master/custom_types.md#warnings-and-issues
|
||||||
|
|
||||||
|
option (gogoproto.marshaler_all) = true;
|
||||||
|
option (gogoproto.unmarshaler_all) = true;
|
||||||
|
option (gogoproto.sizer_all) = true;
|
||||||
|
option (gogoproto.goproto_registration) = true;
|
||||||
|
|
||||||
|
// Generate tests
|
||||||
|
option (gogoproto.populate_all) = true;
|
||||||
|
option (gogoproto.equal_all) = true;
|
||||||
|
option (gogoproto.testgen_all) = true;
|
||||||
|
|
||||||
|
//----------------------------------------
|
||||||
|
// Request types
|
||||||
|
|
||||||
|
message Request {
|
||||||
|
oneof value {
|
||||||
|
RequestEcho echo = 2;
|
||||||
|
RequestFlush flush = 3;
|
||||||
|
RequestInfo info = 4;
|
||||||
|
RequestSetOption set_option = 5;
|
||||||
|
RequestInitChain init_chain = 6;
|
||||||
|
RequestQuery query = 7;
|
||||||
|
RequestBeginBlock begin_block = 8;
|
||||||
|
RequestCheckTx check_tx = 9;
|
||||||
|
RequestDeliverTx deliver_tx = 19;
|
||||||
|
RequestEndBlock end_block = 11;
|
||||||
|
RequestCommit commit = 12;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestEcho { string message = 1; }
|
||||||
|
|
||||||
|
message RequestFlush {}
|
||||||
|
|
||||||
|
message RequestInfo {
|
||||||
|
string version = 1;
|
||||||
|
uint64 block_version = 2;
|
||||||
|
uint64 p2p_version = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// nondeterministic
|
||||||
|
message RequestSetOption {
|
||||||
|
string key = 1;
|
||||||
|
string value = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestInitChain {
|
||||||
|
google.protobuf.Timestamp time = 1
|
||||||
|
[ (gogoproto.nullable) = false, (gogoproto.stdtime) = true ];
|
||||||
|
string chain_id = 2;
|
||||||
|
ConsensusParams consensus_params = 3;
|
||||||
|
repeated ValidatorUpdate validators = 4 [ (gogoproto.nullable) = false ];
|
||||||
|
bytes app_state_bytes = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestQuery {
|
||||||
|
bytes data = 1;
|
||||||
|
string path = 2;
|
||||||
|
int64 height = 3;
|
||||||
|
bool prove = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestBeginBlock {
|
||||||
|
bytes hash = 1;
|
||||||
|
Header header = 2 [ (gogoproto.nullable) = false ];
|
||||||
|
LastCommitInfo last_commit_info = 3 [ (gogoproto.nullable) = false ];
|
||||||
|
repeated Evidence byzantine_validators = 4 [ (gogoproto.nullable) = false ];
|
||||||
|
}
|
||||||
|
|
||||||
|
enum CheckTxType {
|
||||||
|
New = 0;
|
||||||
|
Recheck = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestCheckTx {
|
||||||
|
bytes tx = 1;
|
||||||
|
CheckTxType type = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message RequestDeliverTx { bytes tx = 1; }
|
||||||
|
|
||||||
|
message RequestEndBlock { int64 height = 1; }
|
||||||
|
|
||||||
|
message RequestCommit {}
|
||||||
|
|
||||||
|
//----------------------------------------
|
||||||
|
// Response types
|
||||||
|
|
||||||
|
message Response {
|
||||||
|
oneof value {
|
||||||
|
ResponseException exception = 1;
|
||||||
|
ResponseEcho echo = 2;
|
||||||
|
ResponseFlush flush = 3;
|
||||||
|
ResponseInfo info = 4;
|
||||||
|
ResponseSetOption set_option = 5;
|
||||||
|
ResponseInitChain init_chain = 6;
|
||||||
|
ResponseQuery query = 7;
|
||||||
|
ResponseBeginBlock begin_block = 8;
|
||||||
|
ResponseCheckTx check_tx = 9;
|
||||||
|
ResponseDeliverTx deliver_tx = 10;
|
||||||
|
ResponseEndBlock end_block = 11;
|
||||||
|
ResponseCommit commit = 12;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// nondeterministic
|
||||||
|
message ResponseException { string error = 1; }
|
||||||
|
|
||||||
|
message ResponseEcho { string message = 1; }
|
||||||
|
|
||||||
|
message ResponseFlush {}
|
||||||
|
|
||||||
|
message ResponseInfo {
|
||||||
|
string data = 1;
|
||||||
|
|
||||||
|
string version = 2;
|
||||||
|
uint64 app_version = 3;
|
||||||
|
|
||||||
|
int64 last_block_height = 4;
|
||||||
|
bytes last_block_app_hash = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// nondeterministic
|
||||||
|
message ResponseSetOption {
|
||||||
|
uint32 code = 1;
|
||||||
|
// bytes data = 2;
|
||||||
|
string log = 3;
|
||||||
|
string info = 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseInitChain {
|
||||||
|
ConsensusParams consensus_params = 1;
|
||||||
|
repeated ValidatorUpdate validators = 2 [ (gogoproto.nullable) = false ];
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseQuery {
|
||||||
|
uint32 code = 1;
|
||||||
|
// bytes data = 2; // use "value" instead.
|
||||||
|
string log = 3; // nondeterministic
|
||||||
|
string info = 4; // nondeterministic
|
||||||
|
int64 index = 5;
|
||||||
|
bytes key = 6;
|
||||||
|
bytes value = 7;
|
||||||
|
tendermint.crypto.merkle.Proof proof = 8;
|
||||||
|
int64 height = 9;
|
||||||
|
string codespace = 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseBeginBlock {
|
||||||
|
repeated Event events = 1 [
|
||||||
|
(gogoproto.nullable) = false,
|
||||||
|
(gogoproto.jsontag) = "events,omitempty"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseCheckTx {
|
||||||
|
uint32 code = 1;
|
||||||
|
bytes data = 2;
|
||||||
|
string log = 3; // nondeterministic
|
||||||
|
string info = 4; // nondeterministic
|
||||||
|
int64 gas_wanted = 5;
|
||||||
|
int64 gas_used = 6;
|
||||||
|
repeated Event events = 7 [
|
||||||
|
(gogoproto.nullable) = false,
|
||||||
|
(gogoproto.jsontag) = "events,omitempty"
|
||||||
|
];
|
||||||
|
string codespace = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseDeliverTx {
|
||||||
|
uint32 code = 1;
|
||||||
|
bytes data = 2;
|
||||||
|
string log = 3; // nondeterministic
|
||||||
|
string info = 4; // nondeterministic
|
||||||
|
int64 gas_wanted = 5;
|
||||||
|
int64 gas_used = 6;
|
||||||
|
repeated Event events = 7 [
|
||||||
|
(gogoproto.nullable) = false,
|
||||||
|
(gogoproto.jsontag) = "events,omitempty"
|
||||||
|
];
|
||||||
|
string codespace = 8;
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseEndBlock {
|
||||||
|
repeated ValidatorUpdate validator_updates = 1
|
||||||
|
[ (gogoproto.nullable) = false ];
|
||||||
|
ConsensusParams consensus_param_updates = 2;
|
||||||
|
repeated Event events = 3 [
|
||||||
|
(gogoproto.nullable) = false,
|
||||||
|
(gogoproto.jsontag) = "events,omitempty"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
message ResponseCommit {
|
||||||
|
// reserve 1
|
||||||
|
bytes data = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------
|
||||||
|
// Misc.
|
||||||
|
|
||||||
|
// ConsensusParams contains all consensus-relevant parameters
|
||||||
|
// that can be adjusted by the abci app
|
||||||
|
message ConsensusParams {
|
||||||
|
BlockParams block = 1;
|
||||||
|
EvidenceParams evidence = 2;
|
||||||
|
ValidatorParams validator = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// BlockParams contains limits on the block size.
|
||||||
|
message BlockParams {
|
||||||
|
// Note: must be greater than 0
|
||||||
|
int64 max_bytes = 1;
|
||||||
|
// Note: must be greater or equal to -1
|
||||||
|
int64 max_gas = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message EvidenceParams {
|
||||||
|
// Note: must be greater than 0
|
||||||
|
int64 max_age_num_blocks = 1;
|
||||||
|
google.protobuf.Duration max_age_duration = 2
|
||||||
|
[ (gogoproto.nullable) = false, (gogoproto.stdduration) = true ];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidatorParams contains limits on validators.
|
||||||
|
message ValidatorParams { repeated string pub_key_types = 1; }
|
||||||
|
|
||||||
|
message LastCommitInfo {
|
||||||
|
int32 round = 1;
|
||||||
|
repeated VoteInfo votes = 2 [ (gogoproto.nullable) = false ];
|
||||||
|
}
|
||||||
|
|
||||||
|
message Event {
|
||||||
|
string type = 1;
|
||||||
|
repeated tendermint.libs.kv.Pair attributes = 2 [
|
||||||
|
(gogoproto.nullable) = false,
|
||||||
|
(gogoproto.jsontag) = "attributes,omitempty"
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------
|
||||||
|
// Blockchain Types
|
||||||
|
|
||||||
|
message Header {
|
||||||
|
// basic block info
|
||||||
|
Version version = 1 [ (gogoproto.nullable) = false ];
|
||||||
|
string chain_id = 2 [ (gogoproto.customname) = "ChainID" ];
|
||||||
|
int64 height = 3;
|
||||||
|
google.protobuf.Timestamp time = 4
|
||||||
|
[ (gogoproto.nullable) = false, (gogoproto.stdtime) = true ];
|
||||||
|
|
||||||
|
// prev block info
|
||||||
|
BlockID last_block_id = 5 [ (gogoproto.nullable) = false ];
|
||||||
|
|
||||||
|
// hashes of block data
|
||||||
|
bytes last_commit_hash = 6; // commit from validators from the last block
|
||||||
|
bytes data_hash = 7; // transactions
|
||||||
|
|
||||||
|
// hashes from the app output from the prev block
|
||||||
|
bytes validators_hash = 8; // validators for the current block
|
||||||
|
bytes next_validators_hash = 9; // validators for the next block
|
||||||
|
bytes consensus_hash = 10; // consensus params for current block
|
||||||
|
bytes app_hash = 11; // state after txs from the previous block
|
||||||
|
bytes last_results_hash =
|
||||||
|
12; // root hash of all results from the txs from the previous block
|
||||||
|
|
||||||
|
// consensus info
|
||||||
|
bytes evidence_hash = 13; // evidence included in the block
|
||||||
|
bytes proposer_address = 14; // original proposer of the block
|
||||||
|
}
|
||||||
|
|
||||||
|
message Version {
|
||||||
|
uint64 Block = 1;
|
||||||
|
uint64 App = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message BlockID {
|
||||||
|
bytes hash = 1;
|
||||||
|
PartSetHeader parts_header = 2 [ (gogoproto.nullable) = false ];
|
||||||
|
}
|
||||||
|
|
||||||
|
message PartSetHeader {
|
||||||
|
int32 total = 1;
|
||||||
|
bytes hash = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validator
|
||||||
|
message Validator {
|
||||||
|
bytes address = 1;
|
||||||
|
// PubKey pub_key = 2 [(gogoproto.nullable)=false];
|
||||||
|
int64 power = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidatorUpdate
|
||||||
|
message ValidatorUpdate {
|
||||||
|
PubKey pub_key = 1 [ (gogoproto.nullable) = false ];
|
||||||
|
int64 power = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// VoteInfo
|
||||||
|
message VoteInfo {
|
||||||
|
Validator validator = 1 [ (gogoproto.nullable) = false ];
|
||||||
|
bool signed_last_block = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message PubKey {
|
||||||
|
string type = 1;
|
||||||
|
bytes data = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
message Evidence {
|
||||||
|
string type = 1;
|
||||||
|
Validator validator = 2 [ (gogoproto.nullable) = false ];
|
||||||
|
int64 height = 3;
|
||||||
|
google.protobuf.Timestamp time = 4
|
||||||
|
[ (gogoproto.nullable) = false, (gogoproto.stdtime) = true ];
|
||||||
|
int64 total_voting_power = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
//----------------------------------------
|
||||||
|
// Service Definition
|
||||||
|
|
||||||
|
service ABCIApplication {
|
||||||
|
rpc Echo(RequestEcho) returns (ResponseEcho);
|
||||||
|
rpc Flush(RequestFlush) returns (ResponseFlush);
|
||||||
|
rpc Info(RequestInfo) returns (ResponseInfo);
|
||||||
|
rpc SetOption(RequestSetOption) returns (ResponseSetOption);
|
||||||
|
rpc DeliverTx(RequestDeliverTx) returns (ResponseDeliverTx);
|
||||||
|
rpc CheckTx(RequestCheckTx) returns (ResponseCheckTx);
|
||||||
|
rpc Query(RequestQuery) returns (ResponseQuery);
|
||||||
|
rpc Commit(RequestCommit) returns (ResponseCommit);
|
||||||
|
rpc InitChain(RequestInitChain) returns (ResponseInitChain);
|
||||||
|
rpc BeginBlock(RequestBeginBlock) returns (ResponseBeginBlock);
|
||||||
|
rpc EndBlock(RequestEndBlock) returns (ResponseEndBlock);
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
package tendermint.crypto.merkle;
|
||||||
|
option go_package = "github.com/tendermint/tendermint/crypto/merkle";
|
||||||
|
|
||||||
|
// For more information on gogo.proto, see:
|
||||||
|
// https://github.com/gogo/protobuf/blob/master/extensions.md
|
||||||
|
import "third_party/proto/gogoproto/gogo.proto";
|
||||||
|
|
||||||
|
option (gogoproto.marshaler_all) = true;
|
||||||
|
option (gogoproto.unmarshaler_all) = true;
|
||||||
|
option (gogoproto.sizer_all) = true;
|
||||||
|
|
||||||
|
option (gogoproto.populate_all) = true;
|
||||||
|
option (gogoproto.equal_all) = true;
|
||||||
|
|
||||||
|
//----------------------------------------
|
||||||
|
// Message types
|
||||||
|
|
||||||
|
// ProofOp defines an operation used for calculating Merkle root
|
||||||
|
// The data could be arbitrary format, providing nessecary data
|
||||||
|
// for example neighbouring node hash
|
||||||
|
message ProofOp {
|
||||||
|
string type = 1;
|
||||||
|
bytes key = 2;
|
||||||
|
bytes data = 3;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Proof is Merkle proof defined by the list of ProofOps
|
||||||
|
message Proof {
|
||||||
|
repeated ProofOp ops = 1 [(gogoproto.nullable)=false];
|
||||||
|
}
|
|
@ -0,0 +1,29 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
package tendermint.libs.kv;
|
||||||
|
option go_package = "github.com/tendermint/tendermint/libs/kv";
|
||||||
|
|
||||||
|
import "third_party/proto/gogoproto/gogo.proto";
|
||||||
|
|
||||||
|
option (gogoproto.marshaler_all) = true;
|
||||||
|
option (gogoproto.unmarshaler_all) = true;
|
||||||
|
option (gogoproto.sizer_all) = true;
|
||||||
|
option (gogoproto.goproto_registration) = true;
|
||||||
|
// Generate tests
|
||||||
|
option (gogoproto.populate_all) = true;
|
||||||
|
option (gogoproto.equal_all) = true;
|
||||||
|
option (gogoproto.testgen_all) = true;
|
||||||
|
|
||||||
|
//----------------------------------------
|
||||||
|
// Abstract types
|
||||||
|
|
||||||
|
// Define these here for compatibility but use tmlibs/common.KVPair.
|
||||||
|
message Pair {
|
||||||
|
bytes key = 1;
|
||||||
|
bytes value = 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Define these here for compatibility but use tmlibs/common.KI64Pair.
|
||||||
|
message KI64Pair {
|
||||||
|
bytes key = 1;
|
||||||
|
int64 value = 2;
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
package types_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/cosmos/cosmos-sdk/types"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkBech32ifyPubKey(b *testing.B) {
|
||||||
|
var pk ed25519.PubKeyEd25519
|
||||||
|
rng := rand.New(rand.NewSource(time.Now().Unix()))
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
b.StopTimer()
|
||||||
|
rng.Read(pk[:])
|
||||||
|
b.StartTimer()
|
||||||
|
|
||||||
|
_, err := types.Bech32ifyPubKey(types.Bech32PubKeyTypeConsPub, pk)
|
||||||
|
require.NoError(b, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkGetPubKeyFromBech32(b *testing.B) {
|
||||||
|
var pk ed25519.PubKeyEd25519
|
||||||
|
rng := rand.New(rand.NewSource(time.Now().Unix()))
|
||||||
|
|
||||||
|
b.ResetTimer()
|
||||||
|
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
b.StopTimer()
|
||||||
|
rng.Read(pk[:])
|
||||||
|
|
||||||
|
pkStr, err := types.Bech32ifyPubKey(types.Bech32PubKeyTypeConsPub, pk)
|
||||||
|
require.NoError(b, err)
|
||||||
|
|
||||||
|
b.StartTimer()
|
||||||
|
pk2, err := types.GetPubKeyFromBech32(types.Bech32PubKeyTypeConsPub, pkStr)
|
||||||
|
require.NoError(b, err)
|
||||||
|
require.Equal(b, pk, pk2)
|
||||||
|
}
|
||||||
|
}
|
|
@ -750,6 +750,10 @@ func (d *Dec) Size() int {
|
||||||
func (d Dec) MarshalAmino() ([]byte, error) { return d.Marshal() }
|
func (d Dec) MarshalAmino() ([]byte, error) { return d.Marshal() }
|
||||||
func (d *Dec) UnmarshalAmino(bz []byte) error { return d.Unmarshal(bz) }
|
func (d *Dec) UnmarshalAmino(bz []byte) error { return d.Unmarshal(bz) }
|
||||||
|
|
||||||
|
func (dp DecProto) String() string {
|
||||||
|
return dp.Dec.String()
|
||||||
|
}
|
||||||
|
|
||||||
//___________________________________________________________________________________
|
//___________________________________________________________________________________
|
||||||
// helpers
|
// helpers
|
||||||
|
|
||||||
|
|
|
@ -417,3 +417,7 @@ func (i *Int) UnmarshalAmino(bz []byte) error { return i.Unmarshal(bz) }
|
||||||
func IntEq(t *testing.T, exp, got Int) (*testing.T, bool, string, string, string) {
|
func IntEq(t *testing.T, exp, got Int) (*testing.T, bool, string, string, string) {
|
||||||
return t, exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp.String(), got.String()
|
return t, exp.Equal(got), "expected:\t%v\ngot:\t\t%v", exp.String(), got.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ip IntProto) String() string {
|
||||||
|
return ip.Int.String()
|
||||||
|
}
|
||||||
|
|
|
@ -36,13 +36,13 @@ func TokensFromConsensusPower(power int64) Int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// BondStatus is the status of a validator
|
// BondStatus is the status of a validator
|
||||||
type BondStatus byte
|
type BondStatus int32
|
||||||
|
|
||||||
// staking constants
|
// staking constants
|
||||||
const (
|
const (
|
||||||
Unbonded BondStatus = 0x00
|
Unbonded BondStatus = 1
|
||||||
Unbonding BondStatus = 0x01
|
Unbonding BondStatus = 2
|
||||||
Bonded BondStatus = 0x02
|
Bonded BondStatus = 3
|
||||||
|
|
||||||
BondStatusUnbonded = "Unbonded"
|
BondStatusUnbonded = "Unbonded"
|
||||||
BondStatusUnbonding = "Unbonding"
|
BondStatusUnbonding = "Unbonding"
|
||||||
|
@ -57,12 +57,15 @@ func (b BondStatus) Equal(b2 BondStatus) bool {
|
||||||
// String implements the Stringer interface for BondStatus.
|
// String implements the Stringer interface for BondStatus.
|
||||||
func (b BondStatus) String() string {
|
func (b BondStatus) String() string {
|
||||||
switch b {
|
switch b {
|
||||||
case 0x00:
|
case Unbonded:
|
||||||
return BondStatusUnbonded
|
return BondStatusUnbonded
|
||||||
case 0x01:
|
|
||||||
|
case Unbonding:
|
||||||
return BondStatusUnbonding
|
return BondStatusUnbonding
|
||||||
case 0x02:
|
|
||||||
|
case Bonded:
|
||||||
return BondStatusBonded
|
return BondStatusBonded
|
||||||
|
|
||||||
default:
|
default:
|
||||||
panic("invalid bond status")
|
panic("invalid bond status")
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,6 +10,8 @@ import (
|
||||||
io "io"
|
io "io"
|
||||||
math "math"
|
math "math"
|
||||||
math_bits "math/bits"
|
math_bits "math/bits"
|
||||||
|
reflect "reflect"
|
||||||
|
strings "strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Reference imports to suppress errors if they are not otherwise used.
|
// Reference imports to suppress errors if they are not otherwise used.
|
||||||
|
@ -119,15 +121,136 @@ func (m *DecCoin) GetDenom() string {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IntProto defines a Protobuf wrapper around an Int object.
|
||||||
|
type IntProto struct {
|
||||||
|
Int Int `protobuf:"bytes,1,opt,name=int,proto3,customtype=Int" json:"int"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IntProto) Reset() { *m = IntProto{} }
|
||||||
|
func (*IntProto) ProtoMessage() {}
|
||||||
|
func (*IntProto) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_2c0f90c600ad7e2e, []int{2}
|
||||||
|
}
|
||||||
|
func (m *IntProto) XXX_Unmarshal(b []byte) error {
|
||||||
|
return m.Unmarshal(b)
|
||||||
|
}
|
||||||
|
func (m *IntProto) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
if deterministic {
|
||||||
|
return xxx_messageInfo_IntProto.Marshal(b, m, deterministic)
|
||||||
|
} else {
|
||||||
|
b = b[:cap(b)]
|
||||||
|
n, err := m.MarshalToSizedBuffer(b)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return b[:n], nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (m *IntProto) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_IntProto.Merge(m, src)
|
||||||
|
}
|
||||||
|
func (m *IntProto) XXX_Size() int {
|
||||||
|
return m.Size()
|
||||||
|
}
|
||||||
|
func (m *IntProto) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_IntProto.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_IntProto proto.InternalMessageInfo
|
||||||
|
|
||||||
|
// DecProto defines a Protobuf wrapper around a Dec object.
|
||||||
|
type DecProto struct {
|
||||||
|
Dec Dec `protobuf:"bytes,1,opt,name=dec,proto3,customtype=Dec" json:"dec"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *DecProto) Reset() { *m = DecProto{} }
|
||||||
|
func (*DecProto) ProtoMessage() {}
|
||||||
|
func (*DecProto) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_2c0f90c600ad7e2e, []int{3}
|
||||||
|
}
|
||||||
|
func (m *DecProto) XXX_Unmarshal(b []byte) error {
|
||||||
|
return m.Unmarshal(b)
|
||||||
|
}
|
||||||
|
func (m *DecProto) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
if deterministic {
|
||||||
|
return xxx_messageInfo_DecProto.Marshal(b, m, deterministic)
|
||||||
|
} else {
|
||||||
|
b = b[:cap(b)]
|
||||||
|
n, err := m.MarshalToSizedBuffer(b)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return b[:n], nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (m *DecProto) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_DecProto.Merge(m, src)
|
||||||
|
}
|
||||||
|
func (m *DecProto) XXX_Size() int {
|
||||||
|
return m.Size()
|
||||||
|
}
|
||||||
|
func (m *DecProto) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_DecProto.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_DecProto proto.InternalMessageInfo
|
||||||
|
|
||||||
|
// ValAddresses defines a repeated set of validator addresses.
|
||||||
|
type ValAddresses struct {
|
||||||
|
Addresses []ValAddress `protobuf:"bytes,1,rep,name=addresses,proto3,casttype=ValAddress" json:"addresses,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ValAddresses) Reset() { *m = ValAddresses{} }
|
||||||
|
func (*ValAddresses) ProtoMessage() {}
|
||||||
|
func (*ValAddresses) Descriptor() ([]byte, []int) {
|
||||||
|
return fileDescriptor_2c0f90c600ad7e2e, []int{4}
|
||||||
|
}
|
||||||
|
func (m *ValAddresses) XXX_Unmarshal(b []byte) error {
|
||||||
|
return m.Unmarshal(b)
|
||||||
|
}
|
||||||
|
func (m *ValAddresses) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
|
||||||
|
if deterministic {
|
||||||
|
return xxx_messageInfo_ValAddresses.Marshal(b, m, deterministic)
|
||||||
|
} else {
|
||||||
|
b = b[:cap(b)]
|
||||||
|
n, err := m.MarshalToSizedBuffer(b)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return b[:n], nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func (m *ValAddresses) XXX_Merge(src proto.Message) {
|
||||||
|
xxx_messageInfo_ValAddresses.Merge(m, src)
|
||||||
|
}
|
||||||
|
func (m *ValAddresses) XXX_Size() int {
|
||||||
|
return m.Size()
|
||||||
|
}
|
||||||
|
func (m *ValAddresses) XXX_DiscardUnknown() {
|
||||||
|
xxx_messageInfo_ValAddresses.DiscardUnknown(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
var xxx_messageInfo_ValAddresses proto.InternalMessageInfo
|
||||||
|
|
||||||
|
func (m *ValAddresses) GetAddresses() []ValAddress {
|
||||||
|
if m != nil {
|
||||||
|
return m.Addresses
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
proto.RegisterType((*Coin)(nil), "cosmos_sdk.v1.Coin")
|
proto.RegisterType((*Coin)(nil), "cosmos_sdk.v1.Coin")
|
||||||
proto.RegisterType((*DecCoin)(nil), "cosmos_sdk.v1.DecCoin")
|
proto.RegisterType((*DecCoin)(nil), "cosmos_sdk.v1.DecCoin")
|
||||||
|
proto.RegisterType((*IntProto)(nil), "cosmos_sdk.v1.IntProto")
|
||||||
|
proto.RegisterType((*DecProto)(nil), "cosmos_sdk.v1.DecProto")
|
||||||
|
proto.RegisterType((*ValAddresses)(nil), "cosmos_sdk.v1.ValAddresses")
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { proto.RegisterFile("types/types.proto", fileDescriptor_2c0f90c600ad7e2e) }
|
func init() { proto.RegisterFile("types/types.proto", fileDescriptor_2c0f90c600ad7e2e) }
|
||||||
|
|
||||||
var fileDescriptor_2c0f90c600ad7e2e = []byte{
|
var fileDescriptor_2c0f90c600ad7e2e = []byte{
|
||||||
// 214 bytes of a gzipped FileDescriptorProto
|
// 298 bytes of a gzipped FileDescriptorProto
|
||||||
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2c, 0xa9, 0x2c, 0x48,
|
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2c, 0xa9, 0x2c, 0x48,
|
||||||
0x2d, 0xd6, 0x07, 0x93, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xbc, 0xc9, 0xf9, 0xc5, 0xb9,
|
0x2d, 0xd6, 0x07, 0x93, 0x7a, 0x05, 0x45, 0xf9, 0x25, 0xf9, 0x42, 0xbc, 0xc9, 0xf9, 0xc5, 0xb9,
|
||||||
0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x65, 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29,
|
0xf9, 0xc5, 0xf1, 0xc5, 0x29, 0xd9, 0x7a, 0x65, 0x86, 0x52, 0x6a, 0x25, 0x19, 0x99, 0x45, 0x29,
|
||||||
|
@ -136,12 +259,17 @@ var fileDescriptor_2c0f90c600ad7e2e = []byte{
|
||||||
0x5e, 0x7e, 0xae, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x84, 0x23, 0xa4, 0xcc, 0xc5, 0x96,
|
0x5e, 0x7e, 0xae, 0x04, 0xa3, 0x02, 0xa3, 0x06, 0x67, 0x10, 0x84, 0x23, 0xa4, 0xcc, 0xc5, 0x96,
|
||||||
0x98, 0x9b, 0x5f, 0x9a, 0x57, 0x22, 0xc1, 0x04, 0x12, 0x76, 0xe2, 0x3e, 0x71, 0x4f, 0x9e, 0xe1,
|
0x98, 0x9b, 0x5f, 0x9a, 0x57, 0x22, 0xc1, 0x04, 0x12, 0x76, 0xe2, 0x3e, 0x71, 0x4f, 0x9e, 0xe1,
|
||||||
0xd6, 0x3d, 0x79, 0x66, 0xcf, 0xbc, 0x92, 0x20, 0xa8, 0x94, 0x92, 0x0b, 0x17, 0xbb, 0x4b, 0x6a,
|
0xd6, 0x3d, 0x79, 0x66, 0xcf, 0xbc, 0x92, 0x20, 0xa8, 0x94, 0x92, 0x0b, 0x17, 0xbb, 0x4b, 0x6a,
|
||||||
0x32, 0x39, 0xa6, 0xb8, 0xa4, 0x26, 0xc3, 0x4c, 0x71, 0x72, 0xb9, 0xf1, 0x50, 0x8e, 0xa1, 0xe1,
|
0x32, 0x39, 0xa6, 0xb8, 0xa4, 0x26, 0xc3, 0x4d, 0xd1, 0xe4, 0xe2, 0xf0, 0xcc, 0x2b, 0x09, 0x00,
|
||||||
0x91, 0x1c, 0xc3, 0x89, 0x47, 0x72, 0x8c, 0x17, 0x1e, 0xc9, 0x31, 0x3e, 0x78, 0x24, 0xc7, 0x38,
|
0xfb, 0x45, 0x96, 0x8b, 0x39, 0x33, 0xaf, 0x04, 0x62, 0x08, 0xaa, 0x9d, 0x20, 0x71, 0x90, 0x52,
|
||||||
0xe1, 0xb1, 0x1c, 0xc3, 0x85, 0xc7, 0x72, 0x0c, 0x37, 0x1e, 0xcb, 0x31, 0x44, 0x29, 0xa5, 0x67,
|
0x97, 0xd4, 0x64, 0xb8, 0xd2, 0x94, 0xd4, 0x64, 0x74, 0xa5, 0x20, 0x83, 0x41, 0xe2, 0x4a, 0x4e,
|
||||||
0x96, 0x64, 0x94, 0x26, 0xe9, 0x25, 0xe7, 0xe7, 0xea, 0x43, 0x3c, 0x0b, 0xa5, 0x74, 0x8b, 0x53,
|
0x5c, 0x3c, 0x61, 0x89, 0x39, 0x8e, 0x29, 0x29, 0x45, 0xa9, 0xc5, 0xc5, 0xa9, 0xc5, 0x42, 0x3a,
|
||||||
0xb2, 0x21, 0x61, 0x91, 0xc4, 0x06, 0xf6, 0x95, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0x8d, 0xc6,
|
0x5c, 0x9c, 0x89, 0x30, 0x8e, 0x04, 0xa3, 0x02, 0xb3, 0x06, 0x8f, 0x13, 0xdf, 0xaf, 0x7b, 0xf2,
|
||||||
0x8c, 0x7d, 0x21, 0x01, 0x00, 0x00,
|
0x5c, 0x08, 0x45, 0x41, 0x08, 0x05, 0x56, 0x2c, 0x0d, 0x77, 0x14, 0x18, 0x9d, 0x5c, 0x6e, 0x3c,
|
||||||
|
0x94, 0x63, 0x68, 0x78, 0x24, 0xc7, 0x70, 0xe2, 0x91, 0x1c, 0xe3, 0x85, 0x47, 0x72, 0x8c, 0x0f,
|
||||||
|
0x1e, 0xc9, 0x31, 0x4e, 0x78, 0x2c, 0xc7, 0x70, 0xe1, 0xb1, 0x1c, 0xc3, 0x8d, 0xc7, 0x72, 0x0c,
|
||||||
|
0x51, 0x4a, 0xe9, 0x99, 0x25, 0x19, 0xa5, 0x49, 0x7a, 0xc9, 0xf9, 0xb9, 0xfa, 0x90, 0x68, 0x80,
|
||||||
|
0x52, 0xba, 0xc5, 0x29, 0xd9, 0x90, 0x58, 0x4a, 0x62, 0x03, 0x87, 0xb7, 0x31, 0x20, 0x00, 0x00,
|
||||||
|
0xff, 0xff, 0xd6, 0x08, 0x09, 0x0f, 0xbb, 0x01, 0x00, 0x00,
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *Coin) Marshal() (dAtA []byte, err error) {
|
func (m *Coin) Marshal() (dAtA []byte, err error) {
|
||||||
|
@ -224,6 +352,104 @@ func (m *DecCoin) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||||
return len(dAtA) - i, nil
|
return len(dAtA) - i, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *IntProto) Marshal() (dAtA []byte, err error) {
|
||||||
|
size := m.Size()
|
||||||
|
dAtA = make([]byte, size)
|
||||||
|
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return dAtA[:n], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IntProto) MarshalTo(dAtA []byte) (int, error) {
|
||||||
|
size := m.Size()
|
||||||
|
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *IntProto) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||||
|
i := len(dAtA)
|
||||||
|
_ = i
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
{
|
||||||
|
size := m.Int.Size()
|
||||||
|
i -= size
|
||||||
|
if _, err := m.Int.MarshalTo(dAtA[i:]); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
i = encodeVarintTypes(dAtA, i, uint64(size))
|
||||||
|
}
|
||||||
|
i--
|
||||||
|
dAtA[i] = 0xa
|
||||||
|
return len(dAtA) - i, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *DecProto) Marshal() (dAtA []byte, err error) {
|
||||||
|
size := m.Size()
|
||||||
|
dAtA = make([]byte, size)
|
||||||
|
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return dAtA[:n], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *DecProto) MarshalTo(dAtA []byte) (int, error) {
|
||||||
|
size := m.Size()
|
||||||
|
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *DecProto) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||||
|
i := len(dAtA)
|
||||||
|
_ = i
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
{
|
||||||
|
size := m.Dec.Size()
|
||||||
|
i -= size
|
||||||
|
if _, err := m.Dec.MarshalTo(dAtA[i:]); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
i = encodeVarintTypes(dAtA, i, uint64(size))
|
||||||
|
}
|
||||||
|
i--
|
||||||
|
dAtA[i] = 0xa
|
||||||
|
return len(dAtA) - i, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ValAddresses) Marshal() (dAtA []byte, err error) {
|
||||||
|
size := m.Size()
|
||||||
|
dAtA = make([]byte, size)
|
||||||
|
n, err := m.MarshalToSizedBuffer(dAtA[:size])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return dAtA[:n], nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ValAddresses) MarshalTo(dAtA []byte) (int, error) {
|
||||||
|
size := m.Size()
|
||||||
|
return m.MarshalToSizedBuffer(dAtA[:size])
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ValAddresses) MarshalToSizedBuffer(dAtA []byte) (int, error) {
|
||||||
|
i := len(dAtA)
|
||||||
|
_ = i
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
if len(m.Addresses) > 0 {
|
||||||
|
for iNdEx := len(m.Addresses) - 1; iNdEx >= 0; iNdEx-- {
|
||||||
|
i -= len(m.Addresses[iNdEx])
|
||||||
|
copy(dAtA[i:], m.Addresses[iNdEx])
|
||||||
|
i = encodeVarintTypes(dAtA, i, uint64(len(m.Addresses[iNdEx])))
|
||||||
|
i--
|
||||||
|
dAtA[i] = 0xa
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return len(dAtA) - i, nil
|
||||||
|
}
|
||||||
|
|
||||||
func encodeVarintTypes(dAtA []byte, offset int, v uint64) int {
|
func encodeVarintTypes(dAtA []byte, offset int, v uint64) int {
|
||||||
offset -= sovTypes(v)
|
offset -= sovTypes(v)
|
||||||
base := offset
|
base := offset
|
||||||
|
@ -265,12 +491,67 @@ func (m *DecCoin) Size() (n int) {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *IntProto) Size() (n int) {
|
||||||
|
if m == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
l = m.Int.Size()
|
||||||
|
n += 1 + l + sovTypes(uint64(l))
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *DecProto) Size() (n int) {
|
||||||
|
if m == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
l = m.Dec.Size()
|
||||||
|
n += 1 + l + sovTypes(uint64(l))
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *ValAddresses) Size() (n int) {
|
||||||
|
if m == nil {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
var l int
|
||||||
|
_ = l
|
||||||
|
if len(m.Addresses) > 0 {
|
||||||
|
for _, b := range m.Addresses {
|
||||||
|
l = len(b)
|
||||||
|
n += 1 + l + sovTypes(uint64(l))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
|
||||||
func sovTypes(x uint64) (n int) {
|
func sovTypes(x uint64) (n int) {
|
||||||
return (math_bits.Len64(x|1) + 6) / 7
|
return (math_bits.Len64(x|1) + 6) / 7
|
||||||
}
|
}
|
||||||
func sozTypes(x uint64) (n int) {
|
func sozTypes(x uint64) (n int) {
|
||||||
return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
return sovTypes(uint64((x << 1) ^ uint64((int64(x) >> 63))))
|
||||||
}
|
}
|
||||||
|
func (this *ValAddresses) String() string {
|
||||||
|
if this == nil {
|
||||||
|
return "nil"
|
||||||
|
}
|
||||||
|
s := strings.Join([]string{`&ValAddresses{`,
|
||||||
|
`Addresses:` + fmt.Sprintf("%v", this.Addresses) + `,`,
|
||||||
|
`}`,
|
||||||
|
}, "")
|
||||||
|
return s
|
||||||
|
}
|
||||||
|
func valueToStringTypes(v interface{}) string {
|
||||||
|
rv := reflect.ValueOf(v)
|
||||||
|
if rv.IsNil() {
|
||||||
|
return "nil"
|
||||||
|
}
|
||||||
|
pv := reflect.Indirect(rv).Interface()
|
||||||
|
return fmt.Sprintf("*%v", pv)
|
||||||
|
}
|
||||||
func (m *Coin) Unmarshal(dAtA []byte) error {
|
func (m *Coin) Unmarshal(dAtA []byte) error {
|
||||||
l := len(dAtA)
|
l := len(dAtA)
|
||||||
iNdEx := 0
|
iNdEx := 0
|
||||||
|
@ -509,6 +790,265 @@ func (m *DecCoin) Unmarshal(dAtA []byte) error {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
func (m *IntProto) Unmarshal(dAtA []byte) error {
|
||||||
|
l := len(dAtA)
|
||||||
|
iNdEx := 0
|
||||||
|
for iNdEx < l {
|
||||||
|
preIndex := iNdEx
|
||||||
|
var wire uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
wire |= uint64(b&0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldNum := int32(wire >> 3)
|
||||||
|
wireType := int(wire & 0x7)
|
||||||
|
if wireType == 4 {
|
||||||
|
return fmt.Errorf("proto: IntProto: wiretype end group for non-group")
|
||||||
|
}
|
||||||
|
if fieldNum <= 0 {
|
||||||
|
return fmt.Errorf("proto: IntProto: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||||
|
}
|
||||||
|
switch fieldNum {
|
||||||
|
case 1:
|
||||||
|
if wireType != 2 {
|
||||||
|
return fmt.Errorf("proto: wrong wireType = %d for field Int", wireType)
|
||||||
|
}
|
||||||
|
var stringLen uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
stringLen |= uint64(b&0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
intStringLen := int(stringLen)
|
||||||
|
if intStringLen < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
postIndex := iNdEx + intStringLen
|
||||||
|
if postIndex < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
if postIndex > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
if err := m.Int.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
iNdEx = postIndex
|
||||||
|
default:
|
||||||
|
iNdEx = preIndex
|
||||||
|
skippy, err := skipTypes(dAtA[iNdEx:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if skippy < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
if (iNdEx + skippy) < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
if (iNdEx + skippy) > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
iNdEx += skippy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if iNdEx > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (m *DecProto) Unmarshal(dAtA []byte) error {
|
||||||
|
l := len(dAtA)
|
||||||
|
iNdEx := 0
|
||||||
|
for iNdEx < l {
|
||||||
|
preIndex := iNdEx
|
||||||
|
var wire uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
wire |= uint64(b&0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldNum := int32(wire >> 3)
|
||||||
|
wireType := int(wire & 0x7)
|
||||||
|
if wireType == 4 {
|
||||||
|
return fmt.Errorf("proto: DecProto: wiretype end group for non-group")
|
||||||
|
}
|
||||||
|
if fieldNum <= 0 {
|
||||||
|
return fmt.Errorf("proto: DecProto: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||||
|
}
|
||||||
|
switch fieldNum {
|
||||||
|
case 1:
|
||||||
|
if wireType != 2 {
|
||||||
|
return fmt.Errorf("proto: wrong wireType = %d for field Dec", wireType)
|
||||||
|
}
|
||||||
|
var stringLen uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
stringLen |= uint64(b&0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
intStringLen := int(stringLen)
|
||||||
|
if intStringLen < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
postIndex := iNdEx + intStringLen
|
||||||
|
if postIndex < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
if postIndex > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
if err := m.Dec.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
iNdEx = postIndex
|
||||||
|
default:
|
||||||
|
iNdEx = preIndex
|
||||||
|
skippy, err := skipTypes(dAtA[iNdEx:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if skippy < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
if (iNdEx + skippy) < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
if (iNdEx + skippy) > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
iNdEx += skippy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if iNdEx > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
func (m *ValAddresses) Unmarshal(dAtA []byte) error {
|
||||||
|
l := len(dAtA)
|
||||||
|
iNdEx := 0
|
||||||
|
for iNdEx < l {
|
||||||
|
preIndex := iNdEx
|
||||||
|
var wire uint64
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
wire |= uint64(b&0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fieldNum := int32(wire >> 3)
|
||||||
|
wireType := int(wire & 0x7)
|
||||||
|
if wireType == 4 {
|
||||||
|
return fmt.Errorf("proto: ValAddresses: wiretype end group for non-group")
|
||||||
|
}
|
||||||
|
if fieldNum <= 0 {
|
||||||
|
return fmt.Errorf("proto: ValAddresses: illegal tag %d (wire type %d)", fieldNum, wire)
|
||||||
|
}
|
||||||
|
switch fieldNum {
|
||||||
|
case 1:
|
||||||
|
if wireType != 2 {
|
||||||
|
return fmt.Errorf("proto: wrong wireType = %d for field Addresses", wireType)
|
||||||
|
}
|
||||||
|
var byteLen int
|
||||||
|
for shift := uint(0); ; shift += 7 {
|
||||||
|
if shift >= 64 {
|
||||||
|
return ErrIntOverflowTypes
|
||||||
|
}
|
||||||
|
if iNdEx >= l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
b := dAtA[iNdEx]
|
||||||
|
iNdEx++
|
||||||
|
byteLen |= int(b&0x7F) << shift
|
||||||
|
if b < 0x80 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if byteLen < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
postIndex := iNdEx + byteLen
|
||||||
|
if postIndex < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
if postIndex > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
m.Addresses = append(m.Addresses, make([]byte, postIndex-iNdEx))
|
||||||
|
copy(m.Addresses[len(m.Addresses)-1], dAtA[iNdEx:postIndex])
|
||||||
|
iNdEx = postIndex
|
||||||
|
default:
|
||||||
|
iNdEx = preIndex
|
||||||
|
skippy, err := skipTypes(dAtA[iNdEx:])
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if skippy < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
if (iNdEx + skippy) < 0 {
|
||||||
|
return ErrInvalidLengthTypes
|
||||||
|
}
|
||||||
|
if (iNdEx + skippy) > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
iNdEx += skippy
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if iNdEx > l {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
func skipTypes(dAtA []byte) (n int, err error) {
|
func skipTypes(dAtA []byte) (n int, err error) {
|
||||||
l := len(dAtA)
|
l := len(dAtA)
|
||||||
iNdEx := 0
|
iNdEx := 0
|
||||||
|
|
|
@ -13,7 +13,8 @@ option (gogoproto.stringer_all) = false;
|
||||||
// signatures required by gogoproto.
|
// signatures required by gogoproto.
|
||||||
message Coin {
|
message Coin {
|
||||||
string denom = 1;
|
string denom = 1;
|
||||||
string amount = 2 [ (gogoproto.customtype) = "Int", (gogoproto.nullable) = false ];
|
string amount = 2
|
||||||
|
[ (gogoproto.customtype) = "Int", (gogoproto.nullable) = false ];
|
||||||
}
|
}
|
||||||
|
|
||||||
// DecCoin defines a token with a denomination and a decimal amount.
|
// DecCoin defines a token with a denomination and a decimal amount.
|
||||||
|
@ -22,5 +23,25 @@ message Coin {
|
||||||
// signatures required by gogoproto.
|
// signatures required by gogoproto.
|
||||||
message DecCoin {
|
message DecCoin {
|
||||||
string denom = 1;
|
string denom = 1;
|
||||||
string amount = 2 [ (gogoproto.customtype) = "Dec", (gogoproto.nullable) = false ];
|
string amount = 2
|
||||||
|
[ (gogoproto.customtype) = "Dec", (gogoproto.nullable) = false ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IntProto defines a Protobuf wrapper around an Int object.
|
||||||
|
message IntProto {
|
||||||
|
string int = 1
|
||||||
|
[ (gogoproto.customtype) = "Int", (gogoproto.nullable) = false ];
|
||||||
|
}
|
||||||
|
|
||||||
|
// DecProto defines a Protobuf wrapper around a Dec object.
|
||||||
|
message DecProto {
|
||||||
|
string dec = 1
|
||||||
|
[ (gogoproto.customtype) = "Dec", (gogoproto.nullable) = false ];
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValAddresses defines a repeated set of validator addresses.
|
||||||
|
message ValAddresses {
|
||||||
|
option (gogoproto.stringer) = true;
|
||||||
|
|
||||||
|
repeated bytes addresses = 1 [ (gogoproto.casttype) = "ValAddress" ];
|
||||||
|
}
|
|
@ -139,7 +139,7 @@ func CreateTestInputAdvanced(
|
||||||
}
|
}
|
||||||
supplyKeeper := supply.NewKeeper(cdc, keySupply, accountKeeper, bankKeeper, maccPerms)
|
supplyKeeper := supply.NewKeeper(cdc, keySupply, accountKeeper, bankKeeper, maccPerms)
|
||||||
|
|
||||||
sk := staking.NewKeeper(cdc, keyStaking, bankKeeper, supplyKeeper, pk.Subspace(staking.DefaultParamspace))
|
sk := staking.NewKeeper(staking.ModuleCdc, keyStaking, bankKeeper, supplyKeeper, pk.Subspace(staking.DefaultParamspace))
|
||||||
sk.SetParams(ctx, staking.DefaultParams())
|
sk.SetParams(ctx, staking.DefaultParams())
|
||||||
|
|
||||||
keeper := NewKeeper(cdc, keyDistr, pk.Subspace(types.DefaultParamspace), bankKeeper, sk, supplyKeeper, auth.FeeCollectorName, blacklistedAddrs)
|
keeper := NewKeeper(cdc, keyDistr, pk.Subspace(types.DefaultParamspace), bankKeeper, sk, supplyKeeper, auth.FeeCollectorName, blacklistedAddrs)
|
||||||
|
|
|
@ -49,7 +49,7 @@ type StakingKeeper interface {
|
||||||
Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) stakingexported.DelegationI
|
Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) stakingexported.DelegationI
|
||||||
|
|
||||||
// MaxValidators returns the maximum amount of bonded validators
|
// MaxValidators returns the maximum amount of bonded validators
|
||||||
MaxValidators(sdk.Context) uint16
|
MaxValidators(sdk.Context) uint32
|
||||||
|
|
||||||
IterateDelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
IterateDelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
||||||
fn func(index int64, delegation stakingexported.DelegationI) (stop bool))
|
fn func(index int64, delegation stakingexported.DelegationI) (stop bool))
|
||||||
|
|
|
@ -375,7 +375,7 @@ func TestTallyJailedValidator(t *testing.T) {
|
||||||
|
|
||||||
_ = staking.EndBlocker(ctx, sk)
|
_ = staking.EndBlocker(ctx, sk)
|
||||||
|
|
||||||
sk.Jail(ctx, sdk.ConsAddress(val2.ConsPubKey.Address()))
|
sk.Jail(ctx, sdk.ConsAddress(val2.GetConsPubKey().Address()))
|
||||||
|
|
||||||
tp := TestProposal
|
tp := TestProposal
|
||||||
proposal, err := keeper.SubmitProposal(ctx, tp)
|
proposal, err := keeper.SubmitProposal(ctx, tp)
|
||||||
|
|
|
@ -151,7 +151,7 @@ func createTestInput(
|
||||||
bankKeeper := bank.NewBaseKeeper(cdc, keyBank, accountKeeper, pk.Subspace(bank.DefaultParamspace), blacklistedAddrs)
|
bankKeeper := bank.NewBaseKeeper(cdc, keyBank, accountKeeper, pk.Subspace(bank.DefaultParamspace), blacklistedAddrs)
|
||||||
supplyKeeper := supply.NewKeeper(cdc, keySupply, accountKeeper, bankKeeper, maccPerms)
|
supplyKeeper := supply.NewKeeper(cdc, keySupply, accountKeeper, bankKeeper, maccPerms)
|
||||||
|
|
||||||
sk := staking.NewKeeper(cdc, keyStaking, bankKeeper, supplyKeeper, pk.Subspace(staking.DefaultParamspace))
|
sk := staking.NewKeeper(staking.ModuleCdc, keyStaking, bankKeeper, supplyKeeper, pk.Subspace(staking.DefaultParamspace))
|
||||||
sk.SetParams(ctx, staking.DefaultParams())
|
sk.SetParams(ctx, staking.DefaultParams())
|
||||||
|
|
||||||
rtr := types.NewRouter().
|
rtr := types.NewRouter().
|
||||||
|
|
|
@ -81,7 +81,7 @@ func getMockApp(
|
||||||
bk := mApp.BankKeeper
|
bk := mApp.BankKeeper
|
||||||
supplyKeeper := supply.NewKeeper(mApp.Cdc, keySupply, mApp.AccountKeeper, bk, maccPerms)
|
supplyKeeper := supply.NewKeeper(mApp.Cdc, keySupply, mApp.AccountKeeper, bk, maccPerms)
|
||||||
sk := staking.NewKeeper(
|
sk := staking.NewKeeper(
|
||||||
mApp.Cdc, keyStaking, bk, supplyKeeper, pk.Subspace(staking.DefaultParamspace),
|
staking.ModuleCdc, keyStaking, bk, supplyKeeper, pk.Subspace(staking.DefaultParamspace),
|
||||||
)
|
)
|
||||||
|
|
||||||
keeper := keep.NewKeeper(
|
keeper := keep.NewKeeper(
|
||||||
|
|
|
@ -55,7 +55,7 @@ func getMockApp(t *testing.T) (*mock.App, staking.Keeper, Keeper) {
|
||||||
staking.BondedPoolName: {supply.Burner, supply.Staking},
|
staking.BondedPoolName: {supply.Burner, supply.Staking},
|
||||||
}
|
}
|
||||||
supplyKeeper := supply.NewKeeper(mapp.Cdc, keySupply, mapp.AccountKeeper, mapp.BankKeeper, maccPerms)
|
supplyKeeper := supply.NewKeeper(mapp.Cdc, keySupply, mapp.AccountKeeper, mapp.BankKeeper, maccPerms)
|
||||||
stakingKeeper := staking.NewKeeper(mapp.Cdc, keyStaking, mapp.BankKeeper, supplyKeeper, mapp.ParamsKeeper.Subspace(staking.DefaultParamspace))
|
stakingKeeper := staking.NewKeeper(staking.ModuleCdc, keyStaking, mapp.BankKeeper, supplyKeeper, mapp.ParamsKeeper.Subspace(staking.DefaultParamspace))
|
||||||
keeper := NewKeeper(mapp.Cdc, keySlashing, stakingKeeper, mapp.ParamsKeeper.Subspace(DefaultParamspace))
|
keeper := NewKeeper(mapp.Cdc, keySlashing, stakingKeeper, mapp.ParamsKeeper.Subspace(DefaultParamspace))
|
||||||
mapp.Router().AddRoute(staking.RouterKey, staking.NewHandler(stakingKeeper))
|
mapp.Router().AddRoute(staking.RouterKey, staking.NewHandler(stakingKeeper))
|
||||||
mapp.Router().AddRoute(RouterKey, NewHandler(keeper))
|
mapp.Router().AddRoute(RouterKey, NewHandler(keeper))
|
||||||
|
@ -158,7 +158,7 @@ func TestSlashingMsgs(t *testing.T) {
|
||||||
require.Equal(t, sdk.ValAddress(addr1), validator.OperatorAddress)
|
require.Equal(t, sdk.ValAddress(addr1), validator.OperatorAddress)
|
||||||
require.Equal(t, sdk.Bonded, validator.Status)
|
require.Equal(t, sdk.Bonded, validator.Status)
|
||||||
require.True(sdk.IntEq(t, bondTokens, validator.BondedTokens()))
|
require.True(sdk.IntEq(t, bondTokens, validator.BondedTokens()))
|
||||||
unjailMsg := MsgUnjail{ValidatorAddr: sdk.ValAddress(validator.ConsPubKey.Address())}
|
unjailMsg := MsgUnjail{ValidatorAddr: sdk.ValAddress(validator.GetConsPubKey().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)
|
||||||
|
|
|
@ -104,7 +104,7 @@ func CreateTestInput(t *testing.T, defaults types.Params) (sdk.Context, bank.Kee
|
||||||
totalSupply := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, InitTokens.MulRaw(int64(len(Addrs)))))
|
totalSupply := sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, InitTokens.MulRaw(int64(len(Addrs)))))
|
||||||
supplyKeeper.SetSupply(ctx, supply.NewSupply(totalSupply))
|
supplyKeeper.SetSupply(ctx, supply.NewSupply(totalSupply))
|
||||||
|
|
||||||
sk := staking.NewKeeper(cdc, keyStaking, bk, supplyKeeper, paramsKeeper.Subspace(staking.DefaultParamspace))
|
sk := staking.NewKeeper(staking.ModuleCdc, keyStaking, bk, supplyKeeper, paramsKeeper.Subspace(staking.DefaultParamspace))
|
||||||
genesis := staking.DefaultGenesisState()
|
genesis := staking.DefaultGenesisState()
|
||||||
|
|
||||||
// set module accounts
|
// set module accounts
|
||||||
|
|
|
@ -51,7 +51,7 @@ type StakingKeeper interface {
|
||||||
Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) stakingexported.DelegationI
|
Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) stakingexported.DelegationI
|
||||||
|
|
||||||
// MaxValidators returns the maximum amount of bonded validators
|
// MaxValidators returns the maximum amount of bonded validators
|
||||||
MaxValidators(sdk.Context) uint16
|
MaxValidators(sdk.Context) uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// StakingHooks event hooks for staking validator object (noalias)
|
// StakingHooks event hooks for staking validator object (noalias)
|
||||||
|
|
|
@ -123,6 +123,7 @@ var (
|
||||||
ErrNeitherShareMsgsGiven = types.ErrNeitherShareMsgsGiven
|
ErrNeitherShareMsgsGiven = types.ErrNeitherShareMsgsGiven
|
||||||
ErrInvalidHistoricalInfo = types.ErrInvalidHistoricalInfo
|
ErrInvalidHistoricalInfo = types.ErrInvalidHistoricalInfo
|
||||||
ErrNoHistoricalInfo = types.ErrNoHistoricalInfo
|
ErrNoHistoricalInfo = types.ErrNoHistoricalInfo
|
||||||
|
ErrEmptyValidatorPubKey = types.ErrEmptyValidatorPubKey
|
||||||
NewGenesisState = types.NewGenesisState
|
NewGenesisState = types.NewGenesisState
|
||||||
DefaultGenesisState = types.DefaultGenesisState
|
DefaultGenesisState = types.DefaultGenesisState
|
||||||
NewMultiStakingHooks = types.NewMultiStakingHooks
|
NewMultiStakingHooks = types.NewMultiStakingHooks
|
||||||
|
@ -175,6 +176,7 @@ var (
|
||||||
NewDescription = types.NewDescription
|
NewDescription = types.NewDescription
|
||||||
|
|
||||||
// variable aliases
|
// variable aliases
|
||||||
|
NewCodec = types.NewCodec
|
||||||
ModuleCdc = types.ModuleCdc
|
ModuleCdc = types.ModuleCdc
|
||||||
LastValidatorPowerKey = types.LastValidatorPowerKey
|
LastValidatorPowerKey = types.LastValidatorPowerKey
|
||||||
LastTotalPowerKey = types.LastTotalPowerKey
|
LastTotalPowerKey = types.LastTotalPowerKey
|
||||||
|
@ -199,6 +201,7 @@ var (
|
||||||
|
|
||||||
type (
|
type (
|
||||||
Keeper = keeper.Keeper
|
Keeper = keeper.Keeper
|
||||||
|
Codec = types.Codec
|
||||||
Commission = types.Commission
|
Commission = types.Commission
|
||||||
CommissionRates = types.CommissionRates
|
CommissionRates = types.CommissionRates
|
||||||
DVPair = types.DVPair
|
DVPair = types.DVPair
|
||||||
|
|
|
@ -42,7 +42,7 @@ func getMockApp(t *testing.T) (*mock.App, Keeper) {
|
||||||
types.BondedPoolName: {supply.Burner, supply.Staking},
|
types.BondedPoolName: {supply.Burner, supply.Staking},
|
||||||
}
|
}
|
||||||
supplyKeeper := supply.NewKeeper(mApp.Cdc, keySupply, mApp.AccountKeeper, mApp.BankKeeper, maccPerms)
|
supplyKeeper := supply.NewKeeper(mApp.Cdc, keySupply, mApp.AccountKeeper, mApp.BankKeeper, maccPerms)
|
||||||
keeper := NewKeeper(mApp.Cdc, keyStaking, mApp.BankKeeper, supplyKeeper, mApp.ParamsKeeper.Subspace(DefaultParamspace))
|
keeper := NewKeeper(ModuleCdc, keyStaking, mApp.BankKeeper, supplyKeeper, mApp.ParamsKeeper.Subspace(DefaultParamspace))
|
||||||
|
|
||||||
mApp.Router().AddRoute(RouterKey, NewHandler(keeper))
|
mApp.Router().AddRoute(RouterKey, NewHandler(keeper))
|
||||||
mApp.SetEndBlocker(getEndBlocker(keeper))
|
mApp.SetEndBlocker(getEndBlocker(keeper))
|
||||||
|
|
|
@ -77,7 +77,12 @@ $ %s query staking validator cosmosvaloper1gghjut3ccd8ay0zduzj64hwre2fxs9ldmqhff
|
||||||
return fmt.Errorf("no validator found with address %s", addr)
|
return fmt.Errorf("no validator found with address %s", addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
return cliCtx.PrintOutput(types.MustUnmarshalValidator(cdc, res))
|
validator, err := types.UnmarshalValidator(types.ModuleCdc, res)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return cliCtx.PrintOutput(validator)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,7 +112,12 @@ $ %s query staking validators
|
||||||
|
|
||||||
var validators types.Validators
|
var validators types.Validators
|
||||||
for _, kv := range resKVs {
|
for _, kv := range resKVs {
|
||||||
validators = append(validators, types.MustUnmarshalValidator(cdc, kv.Value))
|
validator, err := types.UnmarshalValidator(types.ModuleCdc, kv.Value)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
validators = append(validators, validator)
|
||||||
}
|
}
|
||||||
|
|
||||||
return cliCtx.PrintOutput(validators)
|
return cliCtx.PrintOutput(validators)
|
||||||
|
@ -380,7 +390,12 @@ $ %s query staking unbonding-delegation cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld7
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return cliCtx.PrintOutput(types.MustUnmarshalUBD(cdc, res))
|
ubd, err := types.UnmarshalUBD(types.ModuleCdc, res)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return cliCtx.PrintOutput(ubd)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -210,17 +210,20 @@ func validateGenesisStateValidators(validators []types.Validator) (err error) {
|
||||||
addrMap := make(map[string]bool, len(validators))
|
addrMap := make(map[string]bool, len(validators))
|
||||||
for i := 0; i < len(validators); i++ {
|
for i := 0; i < len(validators); i++ {
|
||||||
val := validators[i]
|
val := validators[i]
|
||||||
strKey := string(val.ConsPubKey.Bytes())
|
strKey := string(val.GetConsPubKey().Bytes())
|
||||||
|
|
||||||
if _, ok := addrMap[strKey]; ok {
|
if _, ok := addrMap[strKey]; ok {
|
||||||
return fmt.Errorf("duplicate validator in genesis state: moniker %v, address %v", val.Description.Moniker, val.ConsAddress())
|
return fmt.Errorf("duplicate validator in genesis state: moniker %v, address %v", val.Description.Moniker, val.GetConsAddr())
|
||||||
}
|
}
|
||||||
if val.Jailed && val.IsBonded() {
|
if val.Jailed && val.IsBonded() {
|
||||||
return fmt.Errorf("validator is bonded and jailed in genesis state: moniker %v, address %v", val.Description.Moniker, val.ConsAddress())
|
return fmt.Errorf("validator is bonded and jailed in genesis state: moniker %v, address %v", val.Description.Moniker, val.GetConsAddr())
|
||||||
}
|
}
|
||||||
if val.DelegatorShares.IsZero() && !val.IsUnbonding() {
|
if val.DelegatorShares.IsZero() && !val.IsUnbonding() {
|
||||||
return fmt.Errorf("bonded/unbonded genesis validator cannot have zero delegator shares, validator: %v", val)
|
return fmt.Errorf("bonded/unbonded genesis validator cannot have zero delegator shares, validator: %v", val)
|
||||||
}
|
}
|
||||||
|
|
||||||
addrMap[strKey] = true
|
addrMap[strKey] = true
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,21 @@ func TestInitGenesis(t *testing.T) {
|
||||||
validators := make([]Validator, 2)
|
validators := make([]Validator, 2)
|
||||||
var delegations []Delegation
|
var delegations []Delegation
|
||||||
|
|
||||||
|
pk0, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, keep.PKs[0])
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
pk1, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, keep.PKs[1])
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
// initialize the validators
|
// initialize the validators
|
||||||
validators[0].OperatorAddress = sdk.ValAddress(keep.Addrs[0])
|
validators[0].OperatorAddress = sdk.ValAddress(keep.Addrs[0])
|
||||||
validators[0].ConsPubKey = keep.PKs[0]
|
validators[0].ConsensusPubkey = pk0
|
||||||
validators[0].Description = NewDescription("hoop", "", "", "", "")
|
validators[0].Description = NewDescription("hoop", "", "", "", "")
|
||||||
validators[0].Status = sdk.Bonded
|
validators[0].Status = sdk.Bonded
|
||||||
validators[0].Tokens = valTokens
|
validators[0].Tokens = valTokens
|
||||||
validators[0].DelegatorShares = valTokens.ToDec()
|
validators[0].DelegatorShares = valTokens.ToDec()
|
||||||
validators[1].OperatorAddress = sdk.ValAddress(keep.Addrs[1])
|
validators[1].OperatorAddress = sdk.ValAddress(keep.Addrs[1])
|
||||||
validators[1].ConsPubKey = keep.PKs[1]
|
validators[1].ConsensusPubkey = pk1
|
||||||
validators[1].Description = NewDescription("bloop", "", "", "", "")
|
validators[1].Description = NewDescription("bloop", "", "", "", "")
|
||||||
validators[1].Status = sdk.Bonded
|
validators[1].Status = sdk.Bonded
|
||||||
validators[1].Tokens = valTokens
|
validators[1].Tokens = valTokens
|
||||||
|
|
|
@ -3,6 +3,7 @@ package staking
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
gogotypes "github.com/gogo/protobuf/types"
|
||||||
tmstrings "github.com/tendermint/tendermint/libs/strings"
|
tmstrings "github.com/tendermint/tendermint/libs/strings"
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
tmtypes "github.com/tendermint/tendermint/types"
|
||||||
|
|
||||||
|
@ -47,7 +48,12 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k
|
||||||
return nil, ErrValidatorOwnerExists
|
return nil, ErrValidatorOwnerExists
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, found := k.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(msg.PubKey)); found {
|
pk, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, msg.Pubkey)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, found := k.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(pk)); found {
|
||||||
return nil, ErrValidatorPubKeyExists
|
return nil, ErrValidatorPubKeyExists
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,21 +66,22 @@ func handleMsgCreateValidator(ctx sdk.Context, msg types.MsgCreateValidator, k k
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.ConsensusParams() != nil {
|
if ctx.ConsensusParams() != nil {
|
||||||
tmPubKey := tmtypes.TM2PB.PubKey(msg.PubKey)
|
tmPubKey := tmtypes.TM2PB.PubKey(pk)
|
||||||
if !tmstrings.StringInSlice(tmPubKey.Type, ctx.ConsensusParams().Validator.PubKeyTypes) {
|
if !tmstrings.StringInSlice(tmPubKey.Type, ctx.ConsensusParams().Validator.PubKeyTypes) {
|
||||||
return nil, sdkerrors.Wrapf(
|
return nil, sdkerrors.Wrapf(
|
||||||
ErrValidatorPubKeyTypeNotSupported,
|
ErrValidatorPubKeyTypeNotSupported,
|
||||||
"got: %s, valid: %s", tmPubKey.Type, ctx.ConsensusParams().Validator.PubKeyTypes,
|
"got: %s, expected: %s", tmPubKey.Type, ctx.ConsensusParams().Validator.PubKeyTypes,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
validator := NewValidator(msg.ValidatorAddress, msg.PubKey, msg.Description)
|
validator := NewValidator(msg.ValidatorAddress, pk, msg.Description)
|
||||||
commission := NewCommissionWithTime(
|
commission := NewCommissionWithTime(
|
||||||
msg.Commission.Rate, msg.Commission.MaxRate,
|
msg.Commission.Rate, msg.Commission.MaxRate,
|
||||||
msg.Commission.MaxChangeRate, ctx.BlockHeader().Time,
|
msg.Commission.MaxChangeRate, ctx.BlockHeader().Time,
|
||||||
)
|
)
|
||||||
validator, err := validator.SetInitialCommission(commission)
|
|
||||||
|
validator, err = validator.SetInitialCommission(commission)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -217,7 +224,12 @@ func handleMsgUndelegate(ctx sdk.Context, msg types.MsgUndelegate, k keeper.Keep
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
completionTimeBz := types.ModuleCdc.MustMarshalBinaryLengthPrefixed(completionTime)
|
ts, err := gogotypes.TimestampProto(completionTime)
|
||||||
|
if err != nil {
|
||||||
|
return nil, ErrBadRedelegationAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
completionTimeBz := types.ModuleCdc.MustMarshalBinaryLengthPrefixed(ts)
|
||||||
ctx.EventManager().EmitEvents(sdk.Events{
|
ctx.EventManager().EmitEvents(sdk.Events{
|
||||||
sdk.NewEvent(
|
sdk.NewEvent(
|
||||||
types.EventTypeUnbond,
|
types.EventTypeUnbond,
|
||||||
|
@ -254,7 +266,12 @@ func handleMsgBeginRedelegate(ctx sdk.Context, msg types.MsgBeginRedelegate, k k
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
completionTimeBz := types.ModuleCdc.MustMarshalBinaryLengthPrefixed(completionTime)
|
ts, err := gogotypes.TimestampProto(completionTime)
|
||||||
|
if err != nil {
|
||||||
|
return nil, ErrBadRedelegationAddr
|
||||||
|
}
|
||||||
|
|
||||||
|
completionTimeBz := types.ModuleCdc.MustMarshalBinaryLengthPrefixed(ts)
|
||||||
ctx.EventManager().EmitEvents(sdk.Events{
|
ctx.EventManager().EmitEvents(sdk.Events{
|
||||||
sdk.NewEvent(
|
sdk.NewEvent(
|
||||||
types.EventTypeRedelegate,
|
types.EventTypeRedelegate,
|
||||||
|
|
|
@ -5,9 +5,9 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
gogotypes "github.com/gogo/protobuf/types"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
"github.com/tendermint/tendermint/crypto/secp256k1"
|
"github.com/tendermint/tendermint/crypto/secp256k1"
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
tmtypes "github.com/tendermint/tendermint/types"
|
||||||
|
@ -90,8 +90,11 @@ func TestValidatorByPowerIndex(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
|
|
||||||
var finishTime time.Time
|
ts := &gogotypes.Timestamp{}
|
||||||
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, &finishTime)
|
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, ts)
|
||||||
|
|
||||||
|
finishTime, err := gogotypes.TimestampFromProto(ts)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx = ctx.WithBlockTime(finishTime)
|
ctx = ctx.WithBlockTime(finishTime)
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
|
@ -121,7 +124,7 @@ 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.OperatorAddress)
|
assert.Equal(t, addr1, validator.OperatorAddress)
|
||||||
assert.Equal(t, pk1, validator.ConsPubKey)
|
assert.Equal(t, pk1, validator.GetConsPubKey())
|
||||||
assert.Equal(t, valTokens, validator.BondedTokens())
|
assert.Equal(t, valTokens, validator.BondedTokens())
|
||||||
assert.Equal(t, valTokens.ToDec(), validator.DelegatorShares)
|
assert.Equal(t, valTokens.ToDec(), validator.DelegatorShares)
|
||||||
assert.Equal(t, Description{}, validator.Description)
|
assert.Equal(t, Description{}, validator.Description)
|
||||||
|
@ -153,7 +156,7 @@ 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.OperatorAddress)
|
assert.Equal(t, addr2, validator.OperatorAddress)
|
||||||
assert.Equal(t, pk2, validator.ConsPubKey)
|
assert.Equal(t, pk2, validator.GetConsPubKey())
|
||||||
assert.True(sdk.IntEq(t, valTokens, validator.Tokens))
|
assert.True(sdk.IntEq(t, valTokens, validator.Tokens))
|
||||||
assert.True(sdk.DecEq(t, valTokens.ToDec(), validator.DelegatorShares))
|
assert.True(sdk.DecEq(t, valTokens.ToDec(), validator.DelegatorShares))
|
||||||
assert.Equal(t, Description{}, validator.Description)
|
assert.Equal(t, Description{}, validator.Description)
|
||||||
|
@ -225,8 +228,12 @@ func TestLegacyValidatorDelegations(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
|
|
||||||
var finishTime time.Time
|
ts := &gogotypes.Timestamp{}
|
||||||
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, &finishTime)
|
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, ts)
|
||||||
|
|
||||||
|
finishTime, err := gogotypes.TimestampFromProto(ts)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx = ctx.WithBlockTime(finishTime)
|
ctx = ctx.WithBlockTime(finishTime)
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
|
|
||||||
|
@ -459,8 +466,11 @@ func TestIncrementsMsgUnbond(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
|
|
||||||
var finishTime time.Time
|
ts := &gogotypes.Timestamp{}
|
||||||
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, &finishTime)
|
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, ts)
|
||||||
|
|
||||||
|
finishTime, err := gogotypes.TimestampFromProto(ts)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx = ctx.WithBlockTime(finishTime)
|
ctx = ctx.WithBlockTime(finishTime)
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
|
@ -572,8 +582,11 @@ func TestMultipleMsgCreateValidator(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
|
|
||||||
var finishTime time.Time
|
ts := &gogotypes.Timestamp{}
|
||||||
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, &finishTime)
|
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, ts)
|
||||||
|
|
||||||
|
_, err = gogotypes.TimestampFromProto(ts)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
// adds validator into unbonding queue
|
// adds validator into unbonding queue
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
|
@ -626,8 +639,11 @@ func TestMultipleMsgDelegate(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
|
|
||||||
var finishTime time.Time
|
ts := &gogotypes.Timestamp{}
|
||||||
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, &finishTime)
|
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, ts)
|
||||||
|
|
||||||
|
finishTime, err := gogotypes.TimestampFromProto(ts)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx = ctx.WithBlockTime(finishTime)
|
ctx = ctx.WithBlockTime(finishTime)
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
|
@ -661,8 +677,11 @@ func TestJailValidator(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
|
|
||||||
var finishTime time.Time
|
ts := &gogotypes.Timestamp{}
|
||||||
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, &finishTime)
|
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, ts)
|
||||||
|
|
||||||
|
finishTime, err := gogotypes.TimestampFromProto(ts)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx = ctx.WithBlockTime(finishTime)
|
ctx = ctx.WithBlockTime(finishTime)
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
|
@ -677,7 +696,12 @@ func TestJailValidator(t *testing.T) {
|
||||||
res, err = handleMsgUndelegate(ctx, msgUndelegateDelegator, keeper)
|
res, err = handleMsgUndelegate(ctx, msgUndelegateDelegator, keeper)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, &finishTime)
|
|
||||||
|
ts = &gogotypes.Timestamp{}
|
||||||
|
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, ts)
|
||||||
|
|
||||||
|
finishTime, err = gogotypes.TimestampFromProto(ts)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx = ctx.WithBlockTime(finishTime)
|
ctx = ctx.WithBlockTime(finishTime)
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
|
@ -720,8 +744,11 @@ func TestValidatorQueue(t *testing.T) {
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
|
|
||||||
var finishTime time.Time
|
ts := &gogotypes.Timestamp{}
|
||||||
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, &finishTime)
|
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, ts)
|
||||||
|
|
||||||
|
finishTime, err := gogotypes.TimestampFromProto(ts)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx = ctx.WithBlockTime(finishTime)
|
ctx = ctx.WithBlockTime(finishTime)
|
||||||
EndBlocker(ctx, keeper)
|
EndBlocker(ctx, keeper)
|
||||||
|
@ -821,8 +848,12 @@ func TestUnbondingFromUnbondingValidator(t *testing.T) {
|
||||||
require.NotNil(t, res)
|
require.NotNil(t, res)
|
||||||
|
|
||||||
// change the ctx to Block Time one second before the validator would have unbonded
|
// change the ctx to Block Time one second before the validator would have unbonded
|
||||||
var finishTime time.Time
|
ts := &gogotypes.Timestamp{}
|
||||||
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, &finishTime)
|
types.ModuleCdc.MustUnmarshalBinaryLengthPrefixed(res.Data, ts)
|
||||||
|
|
||||||
|
finishTime, err := gogotypes.TimestampFromProto(ts)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
ctx = ctx.WithBlockTime(finishTime.Add(time.Second * -1))
|
ctx = ctx.WithBlockTime(finishTime.Add(time.Second * -1))
|
||||||
|
|
||||||
// unbond the delegator from the validator
|
// unbond the delegator from the validator
|
||||||
|
|
|
@ -120,8 +120,9 @@ func (k Keeper) GetUnbondingDelegations(ctx sdk.Context, delegator sdk.AccAddres
|
||||||
}
|
}
|
||||||
|
|
||||||
// return a unbonding delegation
|
// return a unbonding delegation
|
||||||
func (k Keeper) GetUnbondingDelegation(ctx sdk.Context,
|
func (k Keeper) GetUnbondingDelegation(
|
||||||
delAddr sdk.AccAddress, valAddr sdk.ValAddress) (ubd types.UnbondingDelegation, found bool) {
|
ctx sdk.Context, delAddr sdk.AccAddress, valAddr sdk.ValAddress,
|
||||||
|
) (ubd types.UnbondingDelegation, found bool) {
|
||||||
|
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
key := types.GetUBDKey(delAddr, valAddr)
|
key := types.GetUBDKey(delAddr, valAddr)
|
||||||
|
@ -194,9 +195,10 @@ func (k Keeper) RemoveUnbondingDelegation(ctx sdk.Context, ubd types.UnbondingDe
|
||||||
|
|
||||||
// SetUnbondingDelegationEntry adds an entry to the unbonding delegation at
|
// SetUnbondingDelegationEntry adds an entry to the unbonding delegation at
|
||||||
// the given addresses. It creates the unbonding delegation if it does not exist
|
// the given addresses. It creates the unbonding delegation if it does not exist
|
||||||
func (k Keeper) SetUnbondingDelegationEntry(ctx sdk.Context,
|
func (k Keeper) SetUnbondingDelegationEntry(
|
||||||
delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress,
|
ctx sdk.Context, delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress,
|
||||||
creationHeight int64, minTime time.Time, balance sdk.Int) types.UnbondingDelegation {
|
creationHeight int64, minTime time.Time, balance sdk.Int,
|
||||||
|
) types.UnbondingDelegation {
|
||||||
|
|
||||||
ubd, found := k.GetUnbondingDelegation(ctx, delegatorAddr, validatorAddr)
|
ubd, found := k.GetUnbondingDelegation(ctx, delegatorAddr, validatorAddr)
|
||||||
if found {
|
if found {
|
||||||
|
@ -204,6 +206,7 @@ func (k Keeper) SetUnbondingDelegationEntry(ctx sdk.Context,
|
||||||
} else {
|
} else {
|
||||||
ubd = types.NewUnbondingDelegation(delegatorAddr, validatorAddr, creationHeight, minTime, balance)
|
ubd = types.NewUnbondingDelegation(delegatorAddr, validatorAddr, creationHeight, minTime, balance)
|
||||||
}
|
}
|
||||||
|
|
||||||
k.SetUnbondingDelegation(ctx, ubd)
|
k.SetUnbondingDelegation(ctx, ubd)
|
||||||
return ubd
|
return ubd
|
||||||
}
|
}
|
||||||
|
@ -218,14 +221,16 @@ func (k Keeper) GetUBDQueueTimeSlice(ctx sdk.Context, timestamp time.Time) (dvPa
|
||||||
if bz == nil {
|
if bz == nil {
|
||||||
return []types.DVPair{}
|
return []types.DVPair{}
|
||||||
}
|
}
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &dvPairs)
|
|
||||||
return dvPairs
|
pairs := types.DVPairs{}
|
||||||
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &pairs)
|
||||||
|
return pairs.Pairs
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets a specific unbonding queue timeslice.
|
// Sets a specific unbonding queue timeslice.
|
||||||
func (k Keeper) SetUBDQueueTimeSlice(ctx sdk.Context, timestamp time.Time, keys []types.DVPair) {
|
func (k Keeper) SetUBDQueueTimeSlice(ctx sdk.Context, timestamp time.Time, keys []types.DVPair) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
bz := k.cdc.MustMarshalBinaryLengthPrefixed(keys)
|
bz := k.cdc.MustMarshalBinaryLengthPrefixed(&types.DVPairs{Pairs: keys})
|
||||||
store.Set(types.GetUnbondingDelegationTimeKey(timestamp), bz)
|
store.Set(types.GetUnbondingDelegationTimeKey(timestamp), bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,19 +257,20 @@ func (k Keeper) UBDQueueIterator(ctx sdk.Context, endTime time.Time) sdk.Iterato
|
||||||
|
|
||||||
// Returns a concatenated list of all the timeslices inclusively previous to
|
// Returns a concatenated list of all the timeslices inclusively previous to
|
||||||
// currTime, and deletes the timeslices from the queue
|
// currTime, and deletes the timeslices from the queue
|
||||||
func (k Keeper) DequeueAllMatureUBDQueue(ctx sdk.Context,
|
func (k Keeper) DequeueAllMatureUBDQueue(ctx sdk.Context, currTime time.Time) (matureUnbonds []types.DVPair) {
|
||||||
currTime time.Time) (matureUnbonds []types.DVPair) {
|
|
||||||
|
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
|
|
||||||
// gets an iterator for all timeslices from time 0 until the current Blockheader time
|
// gets an iterator for all timeslices from time 0 until the current Blockheader time
|
||||||
unbondingTimesliceIterator := k.UBDQueueIterator(ctx, ctx.BlockHeader().Time)
|
unbondingTimesliceIterator := k.UBDQueueIterator(ctx, ctx.BlockHeader().Time)
|
||||||
for ; unbondingTimesliceIterator.Valid(); unbondingTimesliceIterator.Next() {
|
for ; unbondingTimesliceIterator.Valid(); unbondingTimesliceIterator.Next() {
|
||||||
timeslice := []types.DVPair{}
|
timeslice := types.DVPairs{}
|
||||||
value := unbondingTimesliceIterator.Value()
|
value := unbondingTimesliceIterator.Value()
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(value, ×lice)
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(value, ×lice)
|
||||||
matureUnbonds = append(matureUnbonds, timeslice...)
|
|
||||||
|
matureUnbonds = append(matureUnbonds, timeslice.Pairs...)
|
||||||
store.Delete(unbondingTimesliceIterator.Key())
|
store.Delete(unbondingTimesliceIterator.Key())
|
||||||
}
|
}
|
||||||
|
|
||||||
return matureUnbonds
|
return matureUnbonds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -404,14 +410,16 @@ func (k Keeper) GetRedelegationQueueTimeSlice(ctx sdk.Context, timestamp time.Ti
|
||||||
if bz == nil {
|
if bz == nil {
|
||||||
return []types.DVVTriplet{}
|
return []types.DVVTriplet{}
|
||||||
}
|
}
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &dvvTriplets)
|
|
||||||
return dvvTriplets
|
triplets := types.DVVTriplets{}
|
||||||
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &triplets)
|
||||||
|
return triplets.Triplets
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets a specific redelegation queue timeslice.
|
// Sets a specific redelegation queue timeslice.
|
||||||
func (k Keeper) SetRedelegationQueueTimeSlice(ctx sdk.Context, timestamp time.Time, keys []types.DVVTriplet) {
|
func (k Keeper) SetRedelegationQueueTimeSlice(ctx sdk.Context, timestamp time.Time, keys []types.DVVTriplet) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
bz := k.cdc.MustMarshalBinaryLengthPrefixed(keys)
|
bz := k.cdc.MustMarshalBinaryLengthPrefixed(&types.DVVTriplets{Triplets: keys})
|
||||||
store.Set(types.GetRedelegationTimeKey(timestamp), bz)
|
store.Set(types.GetRedelegationTimeKey(timestamp), bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,15 +451,18 @@ func (k Keeper) RedelegationQueueIterator(ctx sdk.Context, endTime time.Time) sd
|
||||||
// currTime, and deletes the timeslices from the queue
|
// currTime, and deletes the timeslices from the queue
|
||||||
func (k Keeper) DequeueAllMatureRedelegationQueue(ctx sdk.Context, currTime time.Time) (matureRedelegations []types.DVVTriplet) {
|
func (k Keeper) DequeueAllMatureRedelegationQueue(ctx sdk.Context, currTime time.Time) (matureRedelegations []types.DVVTriplet) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
|
|
||||||
// gets an iterator for all timeslices from time 0 until the current Blockheader time
|
// gets an iterator for all timeslices from time 0 until the current Blockheader time
|
||||||
redelegationTimesliceIterator := k.RedelegationQueueIterator(ctx, ctx.BlockHeader().Time)
|
redelegationTimesliceIterator := k.RedelegationQueueIterator(ctx, ctx.BlockHeader().Time)
|
||||||
for ; redelegationTimesliceIterator.Valid(); redelegationTimesliceIterator.Next() {
|
for ; redelegationTimesliceIterator.Valid(); redelegationTimesliceIterator.Next() {
|
||||||
timeslice := []types.DVVTriplet{}
|
timeslice := types.DVVTriplets{}
|
||||||
value := redelegationTimesliceIterator.Value()
|
value := redelegationTimesliceIterator.Value()
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(value, ×lice)
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(value, ×lice)
|
||||||
matureRedelegations = append(matureRedelegations, timeslice...)
|
|
||||||
|
matureRedelegations = append(matureRedelegations, timeslice.Triplets...)
|
||||||
store.Delete(redelegationTimesliceIterator.Key())
|
store.Delete(redelegationTimesliceIterator.Key())
|
||||||
}
|
}
|
||||||
|
|
||||||
return matureRedelegations
|
return matureRedelegations
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,7 +629,7 @@ func (k Keeper) getBeginInfo(
|
||||||
return completionTime, height, true
|
return completionTime, height, true
|
||||||
|
|
||||||
case validator.IsUnbonding():
|
case validator.IsUnbonding():
|
||||||
return validator.UnbondingCompletionTime, validator.UnbondingHeight, false
|
return validator.UnbondingTime, validator.UnbondingHeight, false
|
||||||
|
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unknown validator status: %s", validator.Status))
|
panic(fmt.Sprintf("unknown validator status: %s", validator.Status))
|
||||||
|
|
|
@ -233,7 +233,7 @@ func TestUnbondingDelegationsMaxEntries(t *testing.T) {
|
||||||
|
|
||||||
// should all pass
|
// should all pass
|
||||||
var completionTime time.Time
|
var completionTime time.Time
|
||||||
for i := uint16(0); i < maxEntries; i++ {
|
for i := uint32(0); i < maxEntries; i++ {
|
||||||
var err error
|
var err error
|
||||||
completionTime, err = keeper.Undelegate(ctx, addrDels[0], addrVals[0], sdk.NewDec(1))
|
completionTime, err = keeper.Undelegate(ctx, addrDels[0], addrVals[0], sdk.NewDec(1))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -414,7 +414,7 @@ func TestUndelegateFromUnbondingValidator(t *testing.T) {
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
require.Equal(t, blockHeight, validator.UnbondingHeight)
|
require.Equal(t, blockHeight, validator.UnbondingHeight)
|
||||||
params := keeper.GetParams(ctx)
|
params := keeper.GetParams(ctx)
|
||||||
require.True(t, blockTime.Add(params.UnbondingTime).Equal(validator.UnbondingCompletionTime))
|
require.True(t, blockTime.Add(params.UnbondingTime).Equal(validator.UnbondingTime))
|
||||||
|
|
||||||
blockHeight2 := int64(20)
|
blockHeight2 := int64(20)
|
||||||
blockTime2 := time.Unix(444, 0).UTC()
|
blockTime2 := time.Unix(444, 0).UTC()
|
||||||
|
@ -489,10 +489,10 @@ func TestUndelegateFromUnbondedValidator(t *testing.T) {
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
require.Equal(t, ctx.BlockHeight(), validator.UnbondingHeight)
|
require.Equal(t, ctx.BlockHeight(), validator.UnbondingHeight)
|
||||||
params := keeper.GetParams(ctx)
|
params := keeper.GetParams(ctx)
|
||||||
require.True(t, ctx.BlockHeader().Time.Add(params.UnbondingTime).Equal(validator.UnbondingCompletionTime))
|
require.True(t, ctx.BlockHeader().Time.Add(params.UnbondingTime).Equal(validator.UnbondingTime))
|
||||||
|
|
||||||
// unbond the validator
|
// unbond the validator
|
||||||
ctx = ctx.WithBlockTime(validator.UnbondingCompletionTime)
|
ctx = ctx.WithBlockTime(validator.UnbondingTime)
|
||||||
keeper.UnbondAllMatureValidatorQueue(ctx)
|
keeper.UnbondAllMatureValidatorQueue(ctx)
|
||||||
|
|
||||||
// Make sure validator is still in state because there is still an outstanding delegation
|
// Make sure validator is still in state because there is still an outstanding delegation
|
||||||
|
@ -579,7 +579,7 @@ func TestUnbondingAllDelegationFromValidator(t *testing.T) {
|
||||||
require.Equal(t, validator.Status, sdk.Unbonding)
|
require.Equal(t, validator.Status, sdk.Unbonding)
|
||||||
|
|
||||||
// unbond the validator
|
// unbond the validator
|
||||||
ctx = ctx.WithBlockTime(validator.UnbondingCompletionTime)
|
ctx = ctx.WithBlockTime(validator.UnbondingTime)
|
||||||
keeper.UnbondAllMatureValidatorQueue(ctx)
|
keeper.UnbondAllMatureValidatorQueue(ctx)
|
||||||
|
|
||||||
// validator should now be deleted from state
|
// validator should now be deleted from state
|
||||||
|
@ -733,7 +733,7 @@ func TestRedelegationMaxEntries(t *testing.T) {
|
||||||
|
|
||||||
// redelegations should pass
|
// redelegations should pass
|
||||||
var completionTime time.Time
|
var completionTime time.Time
|
||||||
for i := uint16(0); i < maxEntries; i++ {
|
for i := uint32(0); i < maxEntries; i++ {
|
||||||
var err error
|
var err error
|
||||||
completionTime, err = keeper.BeginRedelegation(ctx, val0AccAddr, addrVals[0], addrVals[1], sdk.NewDec(1))
|
completionTime, err = keeper.BeginRedelegation(ctx, val0AccAddr, addrVals[0], addrVals[1], sdk.NewDec(1))
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -863,7 +863,7 @@ func TestRedelegateFromUnbondingValidator(t *testing.T) {
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
require.Equal(t, blockHeight, validator.UnbondingHeight)
|
require.Equal(t, blockHeight, validator.UnbondingHeight)
|
||||||
params := keeper.GetParams(ctx)
|
params := keeper.GetParams(ctx)
|
||||||
require.True(t, blockTime.Add(params.UnbondingTime).Equal(validator.UnbondingCompletionTime))
|
require.True(t, blockTime.Add(params.UnbondingTime).Equal(validator.UnbondingTime))
|
||||||
|
|
||||||
//change the context
|
//change the context
|
||||||
header = ctx.BlockHeader()
|
header = ctx.BlockHeader()
|
||||||
|
@ -940,7 +940,7 @@ func TestRedelegateFromUnbondedValidator(t *testing.T) {
|
||||||
require.True(t, found)
|
require.True(t, found)
|
||||||
require.Equal(t, ctx.BlockHeight(), validator.UnbondingHeight)
|
require.Equal(t, ctx.BlockHeight(), validator.UnbondingHeight)
|
||||||
params := keeper.GetParams(ctx)
|
params := keeper.GetParams(ctx)
|
||||||
require.True(t, ctx.BlockHeader().Time.Add(params.UnbondingTime).Equal(validator.UnbondingCompletionTime))
|
require.True(t, ctx.BlockHeader().Time.Add(params.UnbondingTime).Equal(validator.UnbondingTime))
|
||||||
|
|
||||||
// unbond the validator
|
// unbond the validator
|
||||||
keeper.unbondingToUnbonded(ctx, validator)
|
keeper.unbondingToUnbonded(ctx, validator)
|
||||||
|
|
|
@ -4,12 +4,11 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHistoricalInfo(t *testing.T) {
|
func TestHistoricalInfo(t *testing.T) {
|
||||||
|
@ -27,7 +26,7 @@ func TestHistoricalInfo(t *testing.T) {
|
||||||
recv, found := keeper.GetHistoricalInfo(ctx, 2)
|
recv, found := keeper.GetHistoricalInfo(ctx, 2)
|
||||||
require.True(t, found, "HistoricalInfo not found after set")
|
require.True(t, found, "HistoricalInfo not found after set")
|
||||||
require.Equal(t, hi, recv, "HistoricalInfo not equal")
|
require.Equal(t, hi, recv, "HistoricalInfo not equal")
|
||||||
require.True(t, sort.IsSorted(recv.ValSet), "HistoricalInfo validators is not sorted")
|
require.True(t, sort.IsSorted(types.Validators(recv.Valset)), "HistoricalInfo validators is not sorted")
|
||||||
|
|
||||||
keeper.DeleteHistoricalInfo(ctx, 2)
|
keeper.DeleteHistoricalInfo(ctx, 2)
|
||||||
|
|
||||||
|
@ -91,7 +90,7 @@ func TestTrackHistoricalInfo(t *testing.T) {
|
||||||
// Check HistoricalInfo at height 10 is persisted
|
// Check HistoricalInfo at height 10 is persisted
|
||||||
expected := types.HistoricalInfo{
|
expected := types.HistoricalInfo{
|
||||||
Header: header,
|
Header: header,
|
||||||
ValSet: vals,
|
Valset: vals,
|
||||||
}
|
}
|
||||||
recv, found = k.GetHistoricalInfo(ctx, 10)
|
recv, found = k.GetHistoricalInfo(ctx, 10)
|
||||||
require.True(t, found, "GetHistoricalInfo failed after BeginBlock")
|
require.True(t, found, "GetHistoricalInfo failed after BeginBlock")
|
||||||
|
|
|
@ -23,7 +23,7 @@ var _ types.DelegationSet = Keeper{}
|
||||||
// keeper of the staking store
|
// keeper of the staking store
|
||||||
type Keeper struct {
|
type Keeper struct {
|
||||||
storeKey sdk.StoreKey
|
storeKey sdk.StoreKey
|
||||||
cdc *codec.Codec
|
cdc codec.Marshaler
|
||||||
bankKeeper types.BankKeeper
|
bankKeeper types.BankKeeper
|
||||||
supplyKeeper types.SupplyKeeper
|
supplyKeeper types.SupplyKeeper
|
||||||
hooks types.StakingHooks
|
hooks types.StakingHooks
|
||||||
|
@ -34,7 +34,7 @@ type Keeper struct {
|
||||||
|
|
||||||
// NewKeeper creates a new staking Keeper instance
|
// NewKeeper creates a new staking Keeper instance
|
||||||
func NewKeeper(
|
func NewKeeper(
|
||||||
cdc *codec.Codec, key sdk.StoreKey, bk types.BankKeeper, sk types.SupplyKeeper, ps params.Subspace,
|
cdc codec.Marshaler, key sdk.StoreKey, bk types.BankKeeper, sk types.SupplyKeeper, ps params.Subspace,
|
||||||
) Keeper {
|
) Keeper {
|
||||||
|
|
||||||
// ensure bonded and not bonded module accounts are set
|
// ensure bonded and not bonded module accounts are set
|
||||||
|
@ -73,19 +73,21 @@ func (k *Keeper) SetHooks(sh types.StakingHooks) *Keeper {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load the last total validator power.
|
// Load the last total validator power.
|
||||||
func (k Keeper) GetLastTotalPower(ctx sdk.Context) (power sdk.Int) {
|
func (k Keeper) GetLastTotalPower(ctx sdk.Context) sdk.Int {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := store.Get(types.LastTotalPowerKey)
|
bz := store.Get(types.LastTotalPowerKey)
|
||||||
if b == nil {
|
if bz == nil {
|
||||||
return sdk.ZeroInt()
|
return sdk.ZeroInt()
|
||||||
}
|
}
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(b, &power)
|
|
||||||
return
|
ip := sdk.IntProto{}
|
||||||
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &ip)
|
||||||
|
return ip.Int
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the last total validator power.
|
// Set the last total validator power.
|
||||||
func (k Keeper) SetLastTotalPower(ctx sdk.Context, power sdk.Int) {
|
func (k Keeper) SetLastTotalPower(ctx sdk.Context, power sdk.Int) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
b := k.cdc.MustMarshalBinaryLengthPrefixed(power)
|
bz := k.cdc.MustMarshalBinaryLengthPrefixed(&sdk.IntProto{Int: power})
|
||||||
store.Set(types.LastTotalPowerKey, b)
|
store.Set(types.LastTotalPowerKey, bz)
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,21 +25,21 @@ func (k Keeper) UnbondingTime(ctx sdk.Context) (res time.Duration) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxValidators - Maximum number of validators
|
// MaxValidators - Maximum number of validators
|
||||||
func (k Keeper) MaxValidators(ctx sdk.Context) (res uint16) {
|
func (k Keeper) MaxValidators(ctx sdk.Context) (res uint32) {
|
||||||
k.paramstore.Get(ctx, types.KeyMaxValidators, &res)
|
k.paramstore.Get(ctx, types.KeyMaxValidators, &res)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// MaxEntries - Maximum number of simultaneous unbonding
|
// MaxEntries - Maximum number of simultaneous unbonding
|
||||||
// delegations or redelegations (per pair/trio)
|
// delegations or redelegations (per pair/trio)
|
||||||
func (k Keeper) MaxEntries(ctx sdk.Context) (res uint16) {
|
func (k Keeper) MaxEntries(ctx sdk.Context) (res uint32) {
|
||||||
k.paramstore.Get(ctx, types.KeyMaxEntries, &res)
|
k.paramstore.Get(ctx, types.KeyMaxEntries, &res)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// HistoricalEntries = number of historical info entries
|
// HistoricalEntries = number of historical info entries
|
||||||
// to persist in store
|
// to persist in store
|
||||||
func (k Keeper) HistoricalEntries(ctx sdk.Context) (res uint16) {
|
func (k Keeper) HistoricalEntries(ctx sdk.Context) (res uint32) {
|
||||||
k.paramstore.Get(ctx, types.KeyHistoricalEntries, &res)
|
k.paramstore.Get(ctx, types.KeyHistoricalEntries, &res)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Return all validators that a delegator is bonded to. If maxRetrieve is supplied, the respective amount will be returned.
|
// Return all validators that a delegator is bonded to. If maxRetrieve is supplied, the respective amount will be returned.
|
||||||
func (k Keeper) GetDelegatorValidators(ctx sdk.Context, delegatorAddr sdk.AccAddress,
|
func (k Keeper) GetDelegatorValidators(
|
||||||
maxRetrieve uint16) (validators []types.Validator) {
|
ctx sdk.Context, delegatorAddr sdk.AccAddress, maxRetrieve uint32,
|
||||||
validators = make([]types.Validator, maxRetrieve)
|
) []types.Validator {
|
||||||
|
|
||||||
|
validators := make([]types.Validator, maxRetrieve)
|
||||||
|
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
delegatorPrefixKey := types.GetDelegationsKey(delegatorAddr)
|
delegatorPrefixKey := types.GetDelegationsKey(delegatorAddr)
|
||||||
|
@ -23,15 +25,18 @@ func (k Keeper) GetDelegatorValidators(ctx sdk.Context, delegatorAddr sdk.AccAdd
|
||||||
if !found {
|
if !found {
|
||||||
panic(types.ErrNoValidatorFound)
|
panic(types.ErrNoValidatorFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
validators[i] = validator
|
validators[i] = validator
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
return validators[:i] // trim
|
return validators[:i] // trim
|
||||||
}
|
}
|
||||||
|
|
||||||
// return a validator that a delegator is bonded to
|
// return a validator that a delegator is bonded to
|
||||||
func (k Keeper) GetDelegatorValidator(ctx sdk.Context, delegatorAddr sdk.AccAddress,
|
func (k Keeper) GetDelegatorValidator(
|
||||||
validatorAddr sdk.ValAddress) (validator types.Validator, err error) {
|
ctx sdk.Context, delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress,
|
||||||
|
) (validator types.Validator, err error) {
|
||||||
|
|
||||||
delegation, found := k.GetDelegation(ctx, delegatorAddr, validatorAddr)
|
delegation, found := k.GetDelegation(ctx, delegatorAddr, validatorAddr)
|
||||||
if !found {
|
if !found {
|
||||||
|
@ -42,7 +47,8 @@ func (k Keeper) GetDelegatorValidator(ctx sdk.Context, delegatorAddr sdk.AccAddr
|
||||||
if !found {
|
if !found {
|
||||||
panic(types.ErrNoValidatorFound)
|
panic(types.ErrNoValidatorFound)
|
||||||
}
|
}
|
||||||
return
|
|
||||||
|
return validator, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//_____________________________________________________________________________________
|
//_____________________________________________________________________________________
|
||||||
|
@ -85,9 +91,9 @@ func (k Keeper) GetAllUnbondingDelegations(ctx sdk.Context, delegator sdk.AccAdd
|
||||||
}
|
}
|
||||||
|
|
||||||
// return all redelegations for a delegator
|
// return all redelegations for a delegator
|
||||||
func (k Keeper) GetAllRedelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
func (k Keeper) GetAllRedelegations(
|
||||||
srcValAddress, dstValAddress sdk.ValAddress) (
|
ctx sdk.Context, delegator sdk.AccAddress, srcValAddress, dstValAddress sdk.ValAddress,
|
||||||
redelegations []types.Redelegation) {
|
) []types.Redelegation {
|
||||||
|
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
delegatorPrefixKey := types.GetREDsKey(delegator)
|
delegatorPrefixKey := types.GetREDsKey(delegator)
|
||||||
|
@ -97,6 +103,8 @@ func (k Keeper) GetAllRedelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
||||||
srcValFilter := !(srcValAddress.Empty())
|
srcValFilter := !(srcValAddress.Empty())
|
||||||
dstValFilter := !(dstValAddress.Empty())
|
dstValFilter := !(dstValAddress.Empty())
|
||||||
|
|
||||||
|
redelegations := []types.Redelegation{}
|
||||||
|
|
||||||
for ; iterator.Valid(); iterator.Next() {
|
for ; iterator.Valid(); iterator.Next() {
|
||||||
redelegation := types.MustUnmarshalRED(k.cdc, iterator.Value())
|
redelegation := types.MustUnmarshalRED(k.cdc, iterator.Value())
|
||||||
if srcValFilter && !(srcValAddress.Equals(redelegation.ValidatorSrcAddress)) {
|
if srcValFilter && !(srcValAddress.Equals(redelegation.ValidatorSrcAddress)) {
|
||||||
|
@ -105,7 +113,9 @@ func (k Keeper) GetAllRedelegations(ctx sdk.Context, delegator sdk.AccAddress,
|
||||||
if dstValFilter && !(dstValAddress.Equals(redelegation.ValidatorDstAddress)) {
|
if dstValFilter && !(dstValAddress.Equals(redelegation.ValidatorDstAddress)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
redelegations = append(redelegations, redelegation)
|
redelegations = append(redelegations, redelegation)
|
||||||
}
|
}
|
||||||
|
|
||||||
return redelegations
|
return redelegations
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,7 +8,6 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
|
@ -50,7 +49,7 @@ var (
|
||||||
|
|
||||||
// intended to be used with require/assert: require.True(ValEq(...))
|
// intended to be used with require/assert: require.True(ValEq(...))
|
||||||
func ValEq(t *testing.T, exp, got types.Validator) (*testing.T, bool, string, types.Validator, types.Validator) {
|
func ValEq(t *testing.T, exp, got types.Validator) (*testing.T, bool, string, types.Validator, types.Validator) {
|
||||||
return t, exp.TestEquivalent(got), "expected:\t%v\ngot:\t\t%v", exp, got
|
return t, exp.MinEqual(got), "expected:\n%v\ngot:\n%v", exp, got
|
||||||
}
|
}
|
||||||
|
|
||||||
//_______________________________________________________________________________________
|
//_______________________________________________________________________________________
|
||||||
|
@ -147,7 +146,7 @@ func CreateTestInput(t *testing.T, isCheckTx bool, initPower int64) (sdk.Context
|
||||||
|
|
||||||
supplyKeeper.SetSupply(ctx, supply.NewSupply(totalSupply))
|
supplyKeeper.SetSupply(ctx, supply.NewSupply(totalSupply))
|
||||||
|
|
||||||
keeper := NewKeeper(cdc, keyStaking, bk, supplyKeeper, pk.Subspace(DefaultParamspace))
|
keeper := NewKeeper(types.ModuleCdc, keyStaking, bk, supplyKeeper, pk.Subspace(DefaultParamspace))
|
||||||
keeper.SetParams(ctx, types.DefaultParams())
|
keeper.SetParams(ctx, types.DefaultParams())
|
||||||
|
|
||||||
// set module accounts
|
// set module accounts
|
||||||
|
@ -273,12 +272,15 @@ func TestingUpdateValidator(keeper Keeper, ctx sdk.Context, validator types.Vali
|
||||||
}
|
}
|
||||||
return validator
|
return validator
|
||||||
}
|
}
|
||||||
|
|
||||||
cachectx, _ := ctx.CacheContext()
|
cachectx, _ := ctx.CacheContext()
|
||||||
keeper.ApplyAndReturnValidatorSetUpdates(cachectx)
|
keeper.ApplyAndReturnValidatorSetUpdates(cachectx)
|
||||||
|
|
||||||
validator, found := keeper.GetValidator(cachectx, validator.OperatorAddress)
|
validator, found := keeper.GetValidator(cachectx, validator.OperatorAddress)
|
||||||
if !found {
|
if !found {
|
||||||
panic("validator expected but not found")
|
panic("validator expected but not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
return validator
|
return validator
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
|
gogotypes "github.com/gogo/protobuf/types"
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
@ -137,7 +138,7 @@ func (k Keeper) ApplyAndReturnValidatorSetUpdates(ctx sdk.Context) (updates []ab
|
||||||
oldPowerBytes, found := last[valAddrBytes]
|
oldPowerBytes, found := last[valAddrBytes]
|
||||||
|
|
||||||
newPower := validator.ConsensusPower()
|
newPower := validator.ConsensusPower()
|
||||||
newPowerBytes := k.cdc.MustMarshalBinaryLengthPrefixed(newPower)
|
newPowerBytes := k.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.Int64Value{Value: newPower})
|
||||||
|
|
||||||
// update the validator set if power has changed
|
// update the validator set if power has changed
|
||||||
if !found || !bytes.Equal(oldPowerBytes, newPowerBytes) {
|
if !found || !bytes.Equal(oldPowerBytes, newPowerBytes) {
|
||||||
|
@ -240,7 +241,6 @@ func (k Keeper) unjailValidator(ctx sdk.Context, validator types.Validator) {
|
||||||
|
|
||||||
// perform all the store operations for when a validator status becomes bonded
|
// perform all the store operations for when a validator status becomes bonded
|
||||||
func (k Keeper) bondValidator(ctx sdk.Context, validator types.Validator) types.Validator {
|
func (k Keeper) bondValidator(ctx sdk.Context, validator types.Validator) types.Validator {
|
||||||
|
|
||||||
// delete the validator by power index, as the key will change
|
// delete the validator by power index, as the key will change
|
||||||
k.DeleteValidatorByPowerIndex(ctx, validator)
|
k.DeleteValidatorByPowerIndex(ctx, validator)
|
||||||
|
|
||||||
|
@ -254,14 +254,13 @@ func (k Keeper) bondValidator(ctx sdk.Context, validator types.Validator) types.
|
||||||
k.DeleteValidatorQueue(ctx, validator)
|
k.DeleteValidatorQueue(ctx, validator)
|
||||||
|
|
||||||
// trigger hook
|
// trigger hook
|
||||||
k.AfterValidatorBonded(ctx, validator.ConsAddress(), validator.OperatorAddress)
|
k.AfterValidatorBonded(ctx, validator.GetConsAddr(), validator.OperatorAddress)
|
||||||
|
|
||||||
return validator
|
return validator
|
||||||
}
|
}
|
||||||
|
|
||||||
// perform all the store operations for when a validator begins unbonding
|
// perform all the store operations for when a validator begins unbonding
|
||||||
func (k Keeper) beginUnbondingValidator(ctx sdk.Context, validator types.Validator) types.Validator {
|
func (k Keeper) beginUnbondingValidator(ctx sdk.Context, validator types.Validator) types.Validator {
|
||||||
|
|
||||||
params := k.GetParams(ctx)
|
params := k.GetParams(ctx)
|
||||||
|
|
||||||
// delete the validator by power index, as the key will change
|
// delete the validator by power index, as the key will change
|
||||||
|
@ -275,7 +274,7 @@ func (k Keeper) beginUnbondingValidator(ctx sdk.Context, validator types.Validat
|
||||||
validator = validator.UpdateStatus(sdk.Unbonding)
|
validator = validator.UpdateStatus(sdk.Unbonding)
|
||||||
|
|
||||||
// set the unbonding completion time and completion height appropriately
|
// set the unbonding completion time and completion height appropriately
|
||||||
validator.UnbondingCompletionTime = ctx.BlockHeader().Time.Add(params.UnbondingTime)
|
validator.UnbondingTime = ctx.BlockHeader().Time.Add(params.UnbondingTime)
|
||||||
validator.UnbondingHeight = ctx.BlockHeader().Height
|
validator.UnbondingHeight = ctx.BlockHeader().Height
|
||||||
|
|
||||||
// save the now unbonded validator record and power index
|
// save the now unbonded validator record and power index
|
||||||
|
@ -286,7 +285,7 @@ func (k Keeper) beginUnbondingValidator(ctx sdk.Context, validator types.Validat
|
||||||
k.InsertValidatorQueue(ctx, validator)
|
k.InsertValidatorQueue(ctx, validator)
|
||||||
|
|
||||||
// trigger hook
|
// trigger hook
|
||||||
k.AfterValidatorBeginUnbonding(ctx, validator.ConsAddress(), validator.OperatorAddress)
|
k.AfterValidatorBeginUnbonding(ctx, validator.GetConsAddr(), validator.OperatorAddress)
|
||||||
|
|
||||||
return validator
|
return validator
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
gogotypes "github.com/gogo/protobuf/types"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
)
|
)
|
||||||
|
@ -94,8 +96,7 @@ func (k Keeper) SetValidator(ctx sdk.Context, validator types.Validator) {
|
||||||
// validator index
|
// validator index
|
||||||
func (k Keeper) SetValidatorByConsAddr(ctx sdk.Context, validator types.Validator) {
|
func (k Keeper) SetValidatorByConsAddr(ctx sdk.Context, validator types.Validator) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
consAddr := sdk.ConsAddress(validator.ConsPubKey.Address())
|
store.Set(types.GetValidatorByConsAddrKey(validator.GetConsAddr()), validator.OperatorAddress)
|
||||||
store.Set(types.GetValidatorByConsAddrKey(consAddr), validator.OperatorAddress)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// validator index
|
// validator index
|
||||||
|
@ -191,14 +192,16 @@ func (k Keeper) RemoveValidator(ctx sdk.Context, address sdk.ValAddress) {
|
||||||
panic("validator being removed should never have positive tokens")
|
panic("validator being removed should never have positive tokens")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
valConsAddr := validator.GetConsAddr()
|
||||||
|
|
||||||
// delete the old validator record
|
// delete the old validator record
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
store.Delete(types.GetValidatorKey(address))
|
store.Delete(types.GetValidatorKey(address))
|
||||||
store.Delete(types.GetValidatorByConsAddrKey(sdk.ConsAddress(validator.ConsPubKey.Address())))
|
store.Delete(types.GetValidatorByConsAddrKey(valConsAddr))
|
||||||
store.Delete(types.GetValidatorsByPowerIndexKey(validator))
|
store.Delete(types.GetValidatorsByPowerIndexKey(validator))
|
||||||
|
|
||||||
// call hooks
|
// call hooks
|
||||||
k.AfterValidatorRemoved(ctx, validator.ConsAddress(), validator.OperatorAddress)
|
k.AfterValidatorRemoved(ctx, valConsAddr, validator.OperatorAddress)
|
||||||
}
|
}
|
||||||
|
|
||||||
// get groups of validators
|
// get groups of validators
|
||||||
|
@ -213,11 +216,12 @@ func (k Keeper) GetAllValidators(ctx sdk.Context) (validators []types.Validator)
|
||||||
validator := types.MustUnmarshalValidator(k.cdc, iterator.Value())
|
validator := types.MustUnmarshalValidator(k.cdc, iterator.Value())
|
||||||
validators = append(validators, validator)
|
validators = append(validators, validator)
|
||||||
}
|
}
|
||||||
|
|
||||||
return validators
|
return validators
|
||||||
}
|
}
|
||||||
|
|
||||||
// return a given amount of all the validators
|
// return a given amount of all the validators
|
||||||
func (k Keeper) GetValidators(ctx sdk.Context, maxRetrieve uint16) (validators []types.Validator) {
|
func (k Keeper) GetValidators(ctx sdk.Context, maxRetrieve uint32) (validators []types.Validator) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
validators = make([]types.Validator, maxRetrieve)
|
validators = make([]types.Validator, maxRetrieve)
|
||||||
|
|
||||||
|
@ -230,6 +234,7 @@ func (k Keeper) GetValidators(ctx sdk.Context, maxRetrieve uint16) (validators [
|
||||||
validators[i] = validator
|
validators[i] = validator
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
|
||||||
return validators[:i] // trim if the array length < maxRetrieve
|
return validators[:i] // trim if the array length < maxRetrieve
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,14 +276,16 @@ func (k Keeper) GetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress)
|
||||||
if bz == nil {
|
if bz == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &power)
|
|
||||||
return
|
intV := gogotypes.Int64Value{}
|
||||||
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &intV)
|
||||||
|
return intV.GetValue()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set the last validator power.
|
// Set the last validator power.
|
||||||
func (k Keeper) SetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress, power int64) {
|
func (k Keeper) SetLastValidatorPower(ctx sdk.Context, operator sdk.ValAddress, power int64) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
bz := k.cdc.MustMarshalBinaryLengthPrefixed(power)
|
bz := k.cdc.MustMarshalBinaryLengthPrefixed(&gogotypes.Int64Value{Value: power})
|
||||||
store.Set(types.GetLastValidatorPowerKey(operator), bz)
|
store.Set(types.GetLastValidatorPowerKey(operator), bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -302,9 +309,10 @@ func (k Keeper) IterateLastValidatorPowers(ctx sdk.Context, handler func(operato
|
||||||
defer iter.Close()
|
defer iter.Close()
|
||||||
for ; iter.Valid(); iter.Next() {
|
for ; iter.Valid(); iter.Next() {
|
||||||
addr := sdk.ValAddress(iter.Key()[len(types.LastValidatorPowerKey):])
|
addr := sdk.ValAddress(iter.Key()[len(types.LastValidatorPowerKey):])
|
||||||
var power int64
|
intV := &gogotypes.Int64Value{}
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), &power)
|
|
||||||
if handler(addr, power) {
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(iter.Value(), intV)
|
||||||
|
if handler(addr, intV.GetValue()) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -342,20 +350,22 @@ func (k Keeper) GetLastValidators(ctx sdk.Context) (validators []types.Validator
|
||||||
|
|
||||||
// gets a specific validator queue timeslice. A timeslice is a slice of ValAddresses corresponding to unbonding validators
|
// gets a specific validator queue timeslice. A timeslice is a slice of ValAddresses corresponding to unbonding validators
|
||||||
// that expire at a certain time.
|
// that expire at a certain time.
|
||||||
func (k Keeper) GetValidatorQueueTimeSlice(ctx sdk.Context, timestamp time.Time) (valAddrs []sdk.ValAddress) {
|
func (k Keeper) GetValidatorQueueTimeSlice(ctx sdk.Context, timestamp time.Time) []sdk.ValAddress {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
bz := store.Get(types.GetValidatorQueueTimeKey(timestamp))
|
bz := store.Get(types.GetValidatorQueueTimeKey(timestamp))
|
||||||
if bz == nil {
|
if bz == nil {
|
||||||
return []sdk.ValAddress{}
|
return []sdk.ValAddress{}
|
||||||
}
|
}
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &valAddrs)
|
|
||||||
return valAddrs
|
va := sdk.ValAddresses{}
|
||||||
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(bz, &va)
|
||||||
|
return va.Addresses
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets a specific validator queue timeslice.
|
// Sets a specific validator queue timeslice.
|
||||||
func (k Keeper) SetValidatorQueueTimeSlice(ctx sdk.Context, timestamp time.Time, keys []sdk.ValAddress) {
|
func (k Keeper) SetValidatorQueueTimeSlice(ctx sdk.Context, timestamp time.Time, keys []sdk.ValAddress) {
|
||||||
store := ctx.KVStore(k.storeKey)
|
store := ctx.KVStore(k.storeKey)
|
||||||
bz := k.cdc.MustMarshalBinaryLengthPrefixed(keys)
|
bz := k.cdc.MustMarshalBinaryLengthPrefixed(&sdk.ValAddresses{Addresses: keys})
|
||||||
store.Set(types.GetValidatorQueueTimeKey(timestamp), bz)
|
store.Set(types.GetValidatorQueueTimeKey(timestamp), bz)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,24 +377,25 @@ func (k Keeper) DeleteValidatorQueueTimeSlice(ctx sdk.Context, timestamp time.Ti
|
||||||
|
|
||||||
// Insert an validator address to the appropriate timeslice in the validator queue
|
// Insert an validator address to the appropriate timeslice in the validator queue
|
||||||
func (k Keeper) InsertValidatorQueue(ctx sdk.Context, val types.Validator) {
|
func (k Keeper) InsertValidatorQueue(ctx sdk.Context, val types.Validator) {
|
||||||
timeSlice := k.GetValidatorQueueTimeSlice(ctx, val.UnbondingCompletionTime)
|
timeSlice := k.GetValidatorQueueTimeSlice(ctx, val.UnbondingTime)
|
||||||
timeSlice = append(timeSlice, val.OperatorAddress)
|
timeSlice = append(timeSlice, val.OperatorAddress)
|
||||||
k.SetValidatorQueueTimeSlice(ctx, val.UnbondingCompletionTime, timeSlice)
|
k.SetValidatorQueueTimeSlice(ctx, val.UnbondingTime, timeSlice)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete a validator address from the validator queue
|
// Delete a validator address from the validator queue
|
||||||
func (k Keeper) DeleteValidatorQueue(ctx sdk.Context, val types.Validator) {
|
func (k Keeper) DeleteValidatorQueue(ctx sdk.Context, val types.Validator) {
|
||||||
timeSlice := k.GetValidatorQueueTimeSlice(ctx, val.UnbondingCompletionTime)
|
timeSlice := k.GetValidatorQueueTimeSlice(ctx, val.UnbondingTime)
|
||||||
newTimeSlice := []sdk.ValAddress{}
|
newTimeSlice := []sdk.ValAddress{}
|
||||||
for _, addr := range timeSlice {
|
for _, addr := range timeSlice {
|
||||||
if !bytes.Equal(addr, val.OperatorAddress) {
|
if !bytes.Equal(addr, val.OperatorAddress) {
|
||||||
newTimeSlice = append(newTimeSlice, addr)
|
newTimeSlice = append(newTimeSlice, addr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(newTimeSlice) == 0 {
|
if len(newTimeSlice) == 0 {
|
||||||
k.DeleteValidatorQueueTimeSlice(ctx, val.UnbondingCompletionTime)
|
k.DeleteValidatorQueueTimeSlice(ctx, val.UnbondingTime)
|
||||||
} else {
|
} else {
|
||||||
k.SetValidatorQueueTimeSlice(ctx, val.UnbondingCompletionTime, newTimeSlice)
|
k.SetValidatorQueueTimeSlice(ctx, val.UnbondingTime, newTimeSlice)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,9 +412,10 @@ func (k Keeper) GetAllMatureValidatorQueue(ctx sdk.Context, currTime time.Time)
|
||||||
defer validatorTimesliceIterator.Close()
|
defer validatorTimesliceIterator.Close()
|
||||||
|
|
||||||
for ; validatorTimesliceIterator.Valid(); validatorTimesliceIterator.Next() {
|
for ; validatorTimesliceIterator.Valid(); validatorTimesliceIterator.Next() {
|
||||||
timeslice := []sdk.ValAddress{}
|
timeslice := sdk.ValAddresses{}
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(validatorTimesliceIterator.Value(), ×lice)
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(validatorTimesliceIterator.Value(), ×lice)
|
||||||
matureValsAddrs = append(matureValsAddrs, timeslice...)
|
|
||||||
|
matureValsAddrs = append(matureValsAddrs, timeslice.Addresses...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return matureValsAddrs
|
return matureValsAddrs
|
||||||
|
@ -416,10 +428,10 @@ func (k Keeper) UnbondAllMatureValidatorQueue(ctx sdk.Context) {
|
||||||
defer validatorTimesliceIterator.Close()
|
defer validatorTimesliceIterator.Close()
|
||||||
|
|
||||||
for ; validatorTimesliceIterator.Valid(); validatorTimesliceIterator.Next() {
|
for ; validatorTimesliceIterator.Valid(); validatorTimesliceIterator.Next() {
|
||||||
timeslice := []sdk.ValAddress{}
|
timeslice := sdk.ValAddresses{}
|
||||||
k.cdc.MustUnmarshalBinaryLengthPrefixed(validatorTimesliceIterator.Value(), ×lice)
|
k.cdc.MustUnmarshalBinaryLengthPrefixed(validatorTimesliceIterator.Value(), ×lice)
|
||||||
|
|
||||||
for _, valAddr := range timeslice {
|
for _, valAddr := range timeslice.Addresses {
|
||||||
val, found := k.GetValidator(ctx, valAddr)
|
val, found := k.GetValidator(ctx, valAddr)
|
||||||
if !found {
|
if !found {
|
||||||
panic("validator in the unbonding queue was not found")
|
panic("validator in the unbonding queue was not found")
|
||||||
|
@ -428,6 +440,7 @@ func (k Keeper) UnbondAllMatureValidatorQueue(ctx sdk.Context) {
|
||||||
if !val.IsUnbonding() {
|
if !val.IsUnbonding() {
|
||||||
panic("unexpected validator in unbonding queue; status was not unbonding")
|
panic("unexpected validator in unbonding queue; status was not unbonding")
|
||||||
}
|
}
|
||||||
|
|
||||||
val = k.unbondingToUnbonded(ctx, val)
|
val = k.unbondingToUnbonded(ctx, val)
|
||||||
if val.GetDelegatorShares().IsZero() {
|
if val.GetDelegatorShares().IsZero() {
|
||||||
k.RemoveValidator(ctx, val.OperatorAddress)
|
k.RemoveValidator(ctx, val.OperatorAddress)
|
||||||
|
|
|
@ -5,13 +5,12 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
abci "github.com/tendermint/tendermint/abci/types"
|
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
"github.com/cosmos/cosmos-sdk/x/staking/types"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
abci "github.com/tendermint/tendermint/abci/types"
|
||||||
)
|
)
|
||||||
|
|
||||||
//_______________________________________________________
|
//_______________________________________________________
|
||||||
|
@ -117,7 +116,7 @@ func TestUpdateBondedValidatorsDecreaseCliff(t *testing.T) {
|
||||||
|
|
||||||
// create keeper parameters
|
// create keeper parameters
|
||||||
params := keeper.GetParams(ctx)
|
params := keeper.GetParams(ctx)
|
||||||
params.MaxValidators = uint16(maxVals)
|
params.MaxValidators = uint32(maxVals)
|
||||||
keeper.SetParams(ctx, params)
|
keeper.SetParams(ctx, params)
|
||||||
|
|
||||||
// create a random pool
|
// create a random pool
|
||||||
|
@ -437,7 +436,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
|
||||||
|
|
||||||
// set max validators to 2
|
// set max validators to 2
|
||||||
params := keeper.GetParams(ctx)
|
params := keeper.GetParams(ctx)
|
||||||
nMax := uint16(2)
|
nMax := uint32(2)
|
||||||
params.MaxValidators = nMax
|
params.MaxValidators = nMax
|
||||||
keeper.SetParams(ctx, params)
|
keeper.SetParams(ctx, params)
|
||||||
|
|
||||||
|
@ -461,7 +460,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
|
||||||
|
|
||||||
// ensure that the first two bonded validators are the largest validators
|
// ensure that the first two bonded validators are the largest validators
|
||||||
resValidators := keeper.GetBondedValidatorsByPower(ctx)
|
resValidators := keeper.GetBondedValidatorsByPower(ctx)
|
||||||
require.Equal(t, nMax, uint16(len(resValidators)))
|
require.Equal(t, nMax, uint32(len(resValidators)))
|
||||||
assert.True(ValEq(t, validators[2], resValidators[0]))
|
assert.True(ValEq(t, validators[2], resValidators[0]))
|
||||||
assert.True(ValEq(t, validators[3], resValidators[1]))
|
assert.True(ValEq(t, validators[3], resValidators[1]))
|
||||||
|
|
||||||
|
@ -481,7 +480,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
|
||||||
// b) validator 2 with 400 tokens (delegated before validator 3)
|
// b) validator 2 with 400 tokens (delegated before validator 3)
|
||||||
validators[0] = TestingUpdateValidator(keeper, ctx, validators[0], true)
|
validators[0] = TestingUpdateValidator(keeper, ctx, validators[0], true)
|
||||||
resValidators = keeper.GetBondedValidatorsByPower(ctx)
|
resValidators = keeper.GetBondedValidatorsByPower(ctx)
|
||||||
require.Equal(t, nMax, uint16(len(resValidators)))
|
require.Equal(t, nMax, uint32(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]))
|
||||||
|
|
||||||
|
@ -509,7 +508,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
|
||||||
|
|
||||||
validators[3] = TestingUpdateValidator(keeper, ctx, validators[3], true)
|
validators[3] = TestingUpdateValidator(keeper, ctx, validators[3], true)
|
||||||
resValidators = keeper.GetBondedValidatorsByPower(ctx)
|
resValidators = keeper.GetBondedValidatorsByPower(ctx)
|
||||||
require.Equal(t, nMax, uint16(len(resValidators)))
|
require.Equal(t, nMax, uint32(len(resValidators)))
|
||||||
assert.True(ValEq(t, validators[0], resValidators[0]))
|
assert.True(ValEq(t, validators[0], resValidators[0]))
|
||||||
assert.True(ValEq(t, validators[3], resValidators[1]))
|
assert.True(ValEq(t, validators[3], resValidators[1]))
|
||||||
|
|
||||||
|
@ -525,7 +524,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
|
||||||
|
|
||||||
validators[3] = TestingUpdateValidator(keeper, ctx, validators[3], true)
|
validators[3] = TestingUpdateValidator(keeper, ctx, validators[3], true)
|
||||||
resValidators = keeper.GetBondedValidatorsByPower(ctx)
|
resValidators = keeper.GetBondedValidatorsByPower(ctx)
|
||||||
require.Equal(t, nMax, uint16(len(resValidators)))
|
require.Equal(t, nMax, uint32(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]))
|
||||||
|
|
||||||
|
@ -540,7 +539,7 @@ func TestGetValidatorsEdgeCases(t *testing.T) {
|
||||||
|
|
||||||
validators[3] = TestingUpdateValidator(keeper, ctx, validators[3], true)
|
validators[3] = TestingUpdateValidator(keeper, ctx, validators[3], true)
|
||||||
resValidators = keeper.GetBondedValidatorsByPower(ctx)
|
resValidators = keeper.GetBondedValidatorsByPower(ctx)
|
||||||
require.Equal(t, nMax, uint16(len(resValidators)))
|
require.Equal(t, nMax, uint32(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]))
|
||||||
_, exists := keeper.GetValidator(ctx, validators[3].OperatorAddress)
|
_, exists := keeper.GetValidator(ctx, validators[3].OperatorAddress)
|
||||||
|
@ -577,7 +576,7 @@ func TestValidatorBondHeight(t *testing.T) {
|
||||||
validators[2] = TestingUpdateValidator(keeper, ctx, validators[2], true)
|
validators[2] = TestingUpdateValidator(keeper, ctx, validators[2], true)
|
||||||
|
|
||||||
resValidators := keeper.GetBondedValidatorsByPower(ctx)
|
resValidators := keeper.GetBondedValidatorsByPower(ctx)
|
||||||
require.Equal(t, uint16(len(resValidators)), params.MaxValidators)
|
require.Equal(t, uint32(len(resValidators)), params.MaxValidators)
|
||||||
|
|
||||||
assert.True(ValEq(t, validators[0], resValidators[0]))
|
assert.True(ValEq(t, validators[0], resValidators[0]))
|
||||||
assert.True(ValEq(t, validators[1], resValidators[1]))
|
assert.True(ValEq(t, validators[1], resValidators[1]))
|
||||||
|
@ -588,7 +587,7 @@ func TestValidatorBondHeight(t *testing.T) {
|
||||||
validators[2], _ = validators[2].AddTokensFromDel(delTokens)
|
validators[2], _ = validators[2].AddTokensFromDel(delTokens)
|
||||||
validators[2] = TestingUpdateValidator(keeper, ctx, validators[2], true)
|
validators[2] = TestingUpdateValidator(keeper, ctx, validators[2], true)
|
||||||
resValidators = keeper.GetBondedValidatorsByPower(ctx)
|
resValidators = keeper.GetBondedValidatorsByPower(ctx)
|
||||||
require.Equal(t, params.MaxValidators, uint16(len(resValidators)))
|
require.Equal(t, params.MaxValidators, uint32(len(resValidators)))
|
||||||
validators[1] = TestingUpdateValidator(keeper, ctx, validators[1], true)
|
validators[1] = TestingUpdateValidator(keeper, ctx, validators[1], true)
|
||||||
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]))
|
||||||
|
@ -598,7 +597,7 @@ func TestFullValidatorSetPowerChange(t *testing.T) {
|
||||||
ctx, _, _, keeper, _ := CreateTestInput(t, false, 1000)
|
ctx, _, _, keeper, _ := CreateTestInput(t, false, 1000)
|
||||||
params := keeper.GetParams(ctx)
|
params := keeper.GetParams(ctx)
|
||||||
max := 2
|
max := 2
|
||||||
params.MaxValidators = uint16(2)
|
params.MaxValidators = uint32(2)
|
||||||
keeper.SetParams(ctx, params)
|
keeper.SetParams(ctx, params)
|
||||||
|
|
||||||
// initialize some validators into the state
|
// initialize some validators into the state
|
||||||
|
@ -881,7 +880,7 @@ func TestApplyAndReturnValidatorSetUpdatesPowerDecrease(t *testing.T) {
|
||||||
func TestApplyAndReturnValidatorSetUpdatesNewValidator(t *testing.T) {
|
func TestApplyAndReturnValidatorSetUpdatesNewValidator(t *testing.T) {
|
||||||
ctx, _, _, keeper, _ := CreateTestInput(t, false, 1000)
|
ctx, _, _, keeper, _ := CreateTestInput(t, false, 1000)
|
||||||
params := keeper.GetParams(ctx)
|
params := keeper.GetParams(ctx)
|
||||||
params.MaxValidators = uint16(3)
|
params.MaxValidators = uint32(3)
|
||||||
|
|
||||||
keeper.SetParams(ctx, params)
|
keeper.SetParams(ctx, params)
|
||||||
|
|
||||||
|
@ -962,7 +961,7 @@ func TestApplyAndReturnValidatorSetUpdatesNewValidator(t *testing.T) {
|
||||||
func TestApplyAndReturnValidatorSetUpdatesBondTransition(t *testing.T) {
|
func TestApplyAndReturnValidatorSetUpdatesBondTransition(t *testing.T) {
|
||||||
ctx, _, _, keeper, _ := CreateTestInput(t, false, 1000)
|
ctx, _, _, keeper, _ := CreateTestInput(t, false, 1000)
|
||||||
params := keeper.GetParams(ctx)
|
params := keeper.GetParams(ctx)
|
||||||
params.MaxValidators = uint16(2)
|
params.MaxValidators = uint32(2)
|
||||||
|
|
||||||
keeper.SetParams(ctx, params)
|
keeper.SetParams(ctx, params)
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,8 @@ func GenUnbondingTime(r *rand.Rand) (ubdTime time.Duration) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// GenMaxValidators randomized MaxValidators
|
// GenMaxValidators randomized MaxValidators
|
||||||
func GenMaxValidators(r *rand.Rand) (maxValidators uint16) {
|
func GenMaxValidators(r *rand.Rand) (maxValidators uint32) {
|
||||||
return uint16(r.Intn(250) + 1)
|
return uint32(r.Intn(250) + 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RandomizedGenState generates a random GenesisState for staking
|
// RandomizedGenState generates a random GenesisState for staking
|
||||||
|
@ -40,7 +40,7 @@ func RandomizedGenState(simState *module.SimulationState) {
|
||||||
func(r *rand.Rand) { unbondTime = GenUnbondingTime(r) },
|
func(r *rand.Rand) { unbondTime = GenUnbondingTime(r) },
|
||||||
)
|
)
|
||||||
|
|
||||||
var maxValidators uint16
|
var maxValidators uint32
|
||||||
simState.AppParams.GetOrGenerate(
|
simState.AppParams.GetOrGenerate(
|
||||||
simState.Cdc, MaxValidators, &maxValidators, simState.Rand,
|
simState.Cdc, MaxValidators, &maxValidators, simState.Rand,
|
||||||
func(r *rand.Rand) { maxValidators = GenMaxValidators(r) },
|
func(r *rand.Rand) { maxValidators = GenMaxValidators(r) },
|
||||||
|
@ -82,6 +82,6 @@ func RandomizedGenState(simState *module.SimulationState) {
|
||||||
|
|
||||||
stakingGenesis := types.NewGenesisState(params, validators, delegations)
|
stakingGenesis := types.NewGenesisState(params, validators, delegations)
|
||||||
|
|
||||||
fmt.Printf("Selected randomly generated staking parameters:\n%s\n", codec.MustMarshalJSONIndent(simState.Cdc, stakingGenesis.Params))
|
fmt.Printf("Selected randomly generated staking parameters:\n%s\n", codec.MustMarshalJSONIndent(types.ModuleCdc, stakingGenesis.Params))
|
||||||
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(stakingGenesis)
|
simState.GenState[types.ModuleName] = simState.Cdc.MustMarshalJSON(stakingGenesis)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,22 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Register concrete types on codec codec
|
type Codec struct {
|
||||||
|
codec.Marshaler
|
||||||
|
|
||||||
|
// Keep reference to the amino codec to allow backwards compatibility along
|
||||||
|
// with type, and interface registration.
|
||||||
|
amino *codec.Codec
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewCodec(amino *codec.Codec) *Codec {
|
||||||
|
return &Codec{Marshaler: codec.NewHybridCodec(amino), amino: amino}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// RegisterCodec registers all the necessary staking module concrete types and
|
||||||
|
// interfaces with the provided codec reference.
|
||||||
func RegisterCodec(cdc *codec.Codec) {
|
func RegisterCodec(cdc *codec.Codec) {
|
||||||
cdc.RegisterConcrete(MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator", nil)
|
cdc.RegisterConcrete(MsgCreateValidator{}, "cosmos-sdk/MsgCreateValidator", nil)
|
||||||
cdc.RegisterConcrete(MsgEditValidator{}, "cosmos-sdk/MsgEditValidator", nil)
|
cdc.RegisterConcrete(MsgEditValidator{}, "cosmos-sdk/MsgEditValidator", nil)
|
||||||
|
@ -13,12 +28,13 @@ func RegisterCodec(cdc *codec.Codec) {
|
||||||
cdc.RegisterConcrete(MsgBeginRedelegate{}, "cosmos-sdk/MsgBeginRedelegate", nil)
|
cdc.RegisterConcrete(MsgBeginRedelegate{}, "cosmos-sdk/MsgBeginRedelegate", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// generic sealed codec to be used throughout this module
|
// ModuleCdc defines a staking module global Amino codec.
|
||||||
var ModuleCdc *codec.Codec
|
var ModuleCdc *Codec
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
ModuleCdc = codec.New()
|
ModuleCdc = NewCodec(codec.New())
|
||||||
RegisterCodec(ModuleCdc)
|
|
||||||
codec.RegisterCrypto(ModuleCdc)
|
RegisterCodec(ModuleCdc.amino)
|
||||||
ModuleCdc.Seal()
|
codec.RegisterCrypto(ModuleCdc.amino)
|
||||||
|
ModuleCdc.amino.Seal()
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +1,10 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
)
|
yaml "gopkg.in/yaml.v2"
|
||||||
|
|
||||||
type (
|
|
||||||
// Commission defines a commission parameters for a given validator.
|
|
||||||
Commission struct {
|
|
||||||
CommissionRates `json:"commission_rates" yaml:"commission_rates"`
|
|
||||||
UpdateTime time.Time `json:"update_time" yaml:"update_time"` // the last time the commission rate was changed
|
|
||||||
}
|
|
||||||
|
|
||||||
// CommissionRates defines the initial commission rates to be used for creating a
|
|
||||||
// validator.
|
|
||||||
CommissionRates struct {
|
|
||||||
Rate sdk.Dec `json:"rate" yaml:"rate"` // the commission rate charged to delegators, as a fraction
|
|
||||||
MaxRate sdk.Dec `json:"max_rate" yaml:"max_rate"` // maximum commission rate which validator can ever charge, as a fraction
|
|
||||||
MaxChangeRate sdk.Dec `json:"max_change_rate" yaml:"max_change_rate"` // maximum daily increase of the validator commission, as a fraction
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCommissionRates returns an initialized validator commission rates.
|
// NewCommissionRates returns an initialized validator commission rates.
|
||||||
|
@ -49,47 +33,43 @@ func NewCommissionWithTime(rate, maxRate, maxChangeRate sdk.Dec, updatedAt time.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equal checks if the given Commission object is equal to the receiving
|
// String implements the Stringer interface for a Commission object.
|
||||||
// Commission object.
|
func (c Commission) String() string {
|
||||||
func (c Commission) Equal(c2 Commission) bool {
|
out, _ := yaml.Marshal(c)
|
||||||
return c.Rate.Equal(c2.Rate) &&
|
return string(out)
|
||||||
c.MaxRate.Equal(c2.MaxRate) &&
|
|
||||||
c.MaxChangeRate.Equal(c2.MaxChangeRate) &&
|
|
||||||
c.UpdateTime.Equal(c2.UpdateTime)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// String implements the Stringer interface for a Commission.
|
// String implements the Stringer interface for a CommissionRates object.
|
||||||
func (c Commission) String() string {
|
func (cr CommissionRates) String() string {
|
||||||
return fmt.Sprintf("rate: %s, maxRate: %s, maxChangeRate: %s, updateTime: %s",
|
out, _ := yaml.Marshal(cr)
|
||||||
c.Rate, c.MaxRate, c.MaxChangeRate, c.UpdateTime,
|
return string(out)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate performs basic sanity validation checks of initial commission
|
// Validate performs basic sanity validation checks of initial commission
|
||||||
// parameters. If validation fails, an SDK error is returned.
|
// parameters. If validation fails, an SDK error is returned.
|
||||||
func (c CommissionRates) Validate() error {
|
func (cr CommissionRates) Validate() error {
|
||||||
switch {
|
switch {
|
||||||
case c.MaxRate.IsNegative():
|
case cr.MaxRate.IsNegative():
|
||||||
// max rate cannot be negative
|
// max rate cannot be negative
|
||||||
return ErrCommissionNegative
|
return ErrCommissionNegative
|
||||||
|
|
||||||
case c.MaxRate.GT(sdk.OneDec()):
|
case cr.MaxRate.GT(sdk.OneDec()):
|
||||||
// max rate cannot be greater than 1
|
// max rate cannot be greater than 1
|
||||||
return ErrCommissionHuge
|
return ErrCommissionHuge
|
||||||
|
|
||||||
case c.Rate.IsNegative():
|
case cr.Rate.IsNegative():
|
||||||
// rate cannot be negative
|
// rate cannot be negative
|
||||||
return ErrCommissionNegative
|
return ErrCommissionNegative
|
||||||
|
|
||||||
case c.Rate.GT(c.MaxRate):
|
case cr.Rate.GT(cr.MaxRate):
|
||||||
// rate cannot be greater than the max rate
|
// rate cannot be greater than the max rate
|
||||||
return ErrCommissionGTMaxRate
|
return ErrCommissionGTMaxRate
|
||||||
|
|
||||||
case c.MaxChangeRate.IsNegative():
|
case cr.MaxChangeRate.IsNegative():
|
||||||
// change rate cannot be negative
|
// change rate cannot be negative
|
||||||
return ErrCommissionChangeRateNegative
|
return ErrCommissionChangeRateNegative
|
||||||
|
|
||||||
case c.MaxChangeRate.GT(c.MaxRate):
|
case cr.MaxChangeRate.GT(cr.MaxRate):
|
||||||
// change rate cannot be greater than the max rate
|
// change rate cannot be greater than the max rate
|
||||||
return ErrCommissionChangeRateGTMaxRate
|
return ErrCommissionChangeRateGTMaxRate
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -10,41 +9,26 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
"github.com/cosmos/cosmos-sdk/x/staking/exported"
|
||||||
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DVPair is struct that just has a delegator-validator pair with no other data.
|
|
||||||
// It is intended to be used as a marshalable pointer. For example, a DVPair can be used to construct the
|
|
||||||
// key to getting an UnbondingDelegation from state.
|
|
||||||
type DVPair struct {
|
|
||||||
DelegatorAddress sdk.AccAddress
|
|
||||||
ValidatorAddress sdk.ValAddress
|
|
||||||
}
|
|
||||||
|
|
||||||
// DVVTriplet is struct that just has a delegator-validator-validator triplet with no other data.
|
|
||||||
// It is intended to be used as a marshalable pointer. For example, a DVVTriplet can be used to construct the
|
|
||||||
// key to getting a Redelegation from state.
|
|
||||||
type DVVTriplet struct {
|
|
||||||
DelegatorAddress sdk.AccAddress
|
|
||||||
ValidatorSrcAddress sdk.ValAddress
|
|
||||||
ValidatorDstAddress sdk.ValAddress
|
|
||||||
}
|
|
||||||
|
|
||||||
// Implements Delegation interface
|
// Implements Delegation interface
|
||||||
var _ exported.DelegationI = Delegation{}
|
var _ exported.DelegationI = Delegation{}
|
||||||
|
|
||||||
// Delegation represents the bond with tokens held by an account. It is
|
// String implements the Stringer interface for a DVPair object.
|
||||||
// owned by one delegator, and is associated with the voting power of one
|
func (dv DVPair) String() string {
|
||||||
// validator.
|
out, _ := yaml.Marshal(dv)
|
||||||
type Delegation struct {
|
return string(out)
|
||||||
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
|
}
|
||||||
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
|
|
||||||
Shares sdk.Dec `json:"shares" yaml:"shares"`
|
// String implements the Stringer interface for a DVVTriplet object.
|
||||||
|
func (dvv DVVTriplet) String() string {
|
||||||
|
out, _ := yaml.Marshal(dvv)
|
||||||
|
return string(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDelegation creates a new delegation object
|
// NewDelegation creates a new delegation object
|
||||||
func NewDelegation(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress,
|
func NewDelegation(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress, shares sdk.Dec) Delegation {
|
||||||
shares sdk.Dec) Delegation {
|
|
||||||
|
|
||||||
return Delegation{
|
return Delegation{
|
||||||
DelegatorAddress: delegatorAddr,
|
DelegatorAddress: delegatorAddr,
|
||||||
ValidatorAddress: validatorAddr,
|
ValidatorAddress: validatorAddr,
|
||||||
|
@ -53,13 +37,13 @@ func NewDelegation(delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustMarshalDelegation returns the delegation bytes. Panics if fails
|
// MustMarshalDelegation returns the delegation bytes. Panics if fails
|
||||||
func MustMarshalDelegation(cdc *codec.Codec, delegation Delegation) []byte {
|
func MustMarshalDelegation(cdc codec.Marshaler, delegation Delegation) []byte {
|
||||||
return cdc.MustMarshalBinaryLengthPrefixed(delegation)
|
return cdc.MustMarshalBinaryLengthPrefixed(&delegation)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustUnmarshalDelegation return the unmarshaled delegation from bytes.
|
// MustUnmarshalDelegation return the unmarshaled delegation from bytes.
|
||||||
// Panics if fails.
|
// Panics if fails.
|
||||||
func MustUnmarshalDelegation(cdc *codec.Codec, value []byte) Delegation {
|
func MustUnmarshalDelegation(cdc codec.Marshaler, value []byte) Delegation {
|
||||||
delegation, err := UnmarshalDelegation(cdc, value)
|
delegation, err := UnmarshalDelegation(cdc, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -68,18 +52,11 @@ func MustUnmarshalDelegation(cdc *codec.Codec, value []byte) Delegation {
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the delegation
|
// return the delegation
|
||||||
func UnmarshalDelegation(cdc *codec.Codec, value []byte) (delegation Delegation, err error) {
|
func UnmarshalDelegation(cdc codec.Marshaler, value []byte) (delegation Delegation, err error) {
|
||||||
err = cdc.UnmarshalBinaryLengthPrefixed(value, &delegation)
|
err = cdc.UnmarshalBinaryLengthPrefixed(value, &delegation)
|
||||||
return delegation, err
|
return delegation, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint
|
|
||||||
func (d Delegation) Equal(d2 Delegation) bool {
|
|
||||||
return bytes.Equal(d.DelegatorAddress, d2.DelegatorAddress) &&
|
|
||||||
bytes.Equal(d.ValidatorAddress, d2.ValidatorAddress) &&
|
|
||||||
d.Shares.Equal(d2.Shares)
|
|
||||||
}
|
|
||||||
|
|
||||||
// nolint - for Delegation
|
// nolint - for Delegation
|
||||||
func (d Delegation) GetDelegatorAddr() sdk.AccAddress { return d.DelegatorAddress }
|
func (d Delegation) GetDelegatorAddr() sdk.AccAddress { return d.DelegatorAddress }
|
||||||
func (d Delegation) GetValidatorAddr() sdk.ValAddress { return d.ValidatorAddress }
|
func (d Delegation) GetValidatorAddr() sdk.ValAddress { return d.ValidatorAddress }
|
||||||
|
@ -87,11 +64,8 @@ func (d Delegation) GetShares() sdk.Dec { return d.Shares }
|
||||||
|
|
||||||
// String returns a human readable string representation of a Delegation.
|
// String returns a human readable string representation of a Delegation.
|
||||||
func (d Delegation) String() string {
|
func (d Delegation) String() string {
|
||||||
return fmt.Sprintf(`Delegation:
|
out, _ := yaml.Marshal(d)
|
||||||
Delegator: %s
|
return string(out)
|
||||||
Validator: %s
|
|
||||||
Shares: %s`, d.DelegatorAddress,
|
|
||||||
d.ValidatorAddress, d.Shares)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delegations is a collection of delegations
|
// Delegations is a collection of delegations
|
||||||
|
@ -104,44 +78,7 @@ func (d Delegations) String() (out string) {
|
||||||
return strings.TrimSpace(out)
|
return strings.TrimSpace(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnbondingDelegation stores all of a single delegator's unbonding bonds
|
func NewUnbondingDelegationEntry(creationHeight int64, completionTime time.Time, balance sdk.Int) UnbondingDelegationEntry {
|
||||||
// for a single validator in an time-ordered list
|
|
||||||
type UnbondingDelegation struct {
|
|
||||||
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"` // delegator
|
|
||||||
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"` // validator unbonding from operator addr
|
|
||||||
Entries []UnbondingDelegationEntry `json:"entries" yaml:"entries"` // unbonding delegation entries
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnbondingDelegationEntry - entry to an UnbondingDelegation
|
|
||||||
type UnbondingDelegationEntry struct {
|
|
||||||
CreationHeight int64 `json:"creation_height" yaml:"creation_height"` // height which the unbonding took place
|
|
||||||
CompletionTime time.Time `json:"completion_time" yaml:"completion_time"` // time at which the unbonding delegation will complete
|
|
||||||
InitialBalance sdk.Int `json:"initial_balance" yaml:"initial_balance"` // atoms initially scheduled to receive at completion
|
|
||||||
Balance sdk.Int `json:"balance" yaml:"balance"` // atoms to receive at completion
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsMature - is the current entry mature
|
|
||||||
func (e UnbondingDelegationEntry) IsMature(currentTime time.Time) bool {
|
|
||||||
return !e.CompletionTime.After(currentTime)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewUnbondingDelegation - create a new unbonding delegation object
|
|
||||||
func NewUnbondingDelegation(delegatorAddr sdk.AccAddress,
|
|
||||||
validatorAddr sdk.ValAddress, creationHeight int64, minTime time.Time,
|
|
||||||
balance sdk.Int) UnbondingDelegation {
|
|
||||||
|
|
||||||
entry := NewUnbondingDelegationEntry(creationHeight, minTime, balance)
|
|
||||||
return UnbondingDelegation{
|
|
||||||
DelegatorAddress: delegatorAddr,
|
|
||||||
ValidatorAddress: validatorAddr,
|
|
||||||
Entries: []UnbondingDelegationEntry{entry},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewUnbondingDelegationEntry - create a new unbonding delegation object
|
|
||||||
func NewUnbondingDelegationEntry(creationHeight int64, completionTime time.Time,
|
|
||||||
balance sdk.Int) UnbondingDelegationEntry {
|
|
||||||
|
|
||||||
return UnbondingDelegationEntry{
|
return UnbondingDelegationEntry{
|
||||||
CreationHeight: creationHeight,
|
CreationHeight: creationHeight,
|
||||||
CompletionTime: completionTime,
|
CompletionTime: completionTime,
|
||||||
|
@ -150,26 +87,50 @@ func NewUnbondingDelegationEntry(creationHeight int64, completionTime time.Time,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddEntry - append entry to the unbonding delegation
|
// String implements the stringer interface for a UnbondingDelegationEntry.
|
||||||
func (d *UnbondingDelegation) AddEntry(creationHeight int64,
|
func (e UnbondingDelegationEntry) String() string {
|
||||||
minTime time.Time, balance sdk.Int) {
|
out, _ := yaml.Marshal(e)
|
||||||
|
return string(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsMature - is the current entry mature
|
||||||
|
func (e UnbondingDelegationEntry) IsMature(currentTime time.Time) bool {
|
||||||
|
return !e.CompletionTime.After(currentTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUnbondingDelegation - create a new unbonding delegation object
|
||||||
|
func NewUnbondingDelegation(
|
||||||
|
delegatorAddr sdk.AccAddress, validatorAddr sdk.ValAddress,
|
||||||
|
creationHeight int64, minTime time.Time, balance sdk.Int,
|
||||||
|
) UnbondingDelegation {
|
||||||
|
|
||||||
|
return UnbondingDelegation{
|
||||||
|
DelegatorAddress: delegatorAddr,
|
||||||
|
ValidatorAddress: validatorAddr,
|
||||||
|
Entries: []UnbondingDelegationEntry{
|
||||||
|
NewUnbondingDelegationEntry(creationHeight, minTime, balance),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddEntry - append entry to the unbonding delegation
|
||||||
|
func (ubd *UnbondingDelegation) AddEntry(creationHeight int64, minTime time.Time, balance sdk.Int) {
|
||||||
entry := NewUnbondingDelegationEntry(creationHeight, minTime, balance)
|
entry := NewUnbondingDelegationEntry(creationHeight, minTime, balance)
|
||||||
d.Entries = append(d.Entries, entry)
|
ubd.Entries = append(ubd.Entries, entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveEntry - remove entry at index i to the unbonding delegation
|
// RemoveEntry - remove entry at index i to the unbonding delegation
|
||||||
func (d *UnbondingDelegation) RemoveEntry(i int64) {
|
func (ubd *UnbondingDelegation) RemoveEntry(i int64) {
|
||||||
d.Entries = append(d.Entries[:i], d.Entries[i+1:]...)
|
ubd.Entries = append(ubd.Entries[:i], ubd.Entries[i+1:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// return the unbonding delegation
|
// return the unbonding delegation
|
||||||
func MustMarshalUBD(cdc *codec.Codec, ubd UnbondingDelegation) []byte {
|
func MustMarshalUBD(cdc codec.Marshaler, ubd UnbondingDelegation) []byte {
|
||||||
return cdc.MustMarshalBinaryLengthPrefixed(ubd)
|
return cdc.MustMarshalBinaryLengthPrefixed(&ubd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// unmarshal a unbonding delegation from a store value
|
// unmarshal a unbonding delegation from a store value
|
||||||
func MustUnmarshalUBD(cdc *codec.Codec, value []byte) UnbondingDelegation {
|
func MustUnmarshalUBD(cdc codec.Marshaler, value []byte) UnbondingDelegation {
|
||||||
ubd, err := UnmarshalUBD(cdc, value)
|
ubd, err := UnmarshalUBD(cdc, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -178,26 +139,18 @@ func MustUnmarshalUBD(cdc *codec.Codec, value []byte) UnbondingDelegation {
|
||||||
}
|
}
|
||||||
|
|
||||||
// unmarshal a unbonding delegation from a store value
|
// unmarshal a unbonding delegation from a store value
|
||||||
func UnmarshalUBD(cdc *codec.Codec, value []byte) (ubd UnbondingDelegation, err error) {
|
func UnmarshalUBD(cdc codec.Marshaler, value []byte) (ubd UnbondingDelegation, err error) {
|
||||||
err = cdc.UnmarshalBinaryLengthPrefixed(value, &ubd)
|
err = cdc.UnmarshalBinaryLengthPrefixed(value, &ubd)
|
||||||
return ubd, err
|
return ubd, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint
|
|
||||||
// inefficient but only used in testing
|
|
||||||
func (d UnbondingDelegation) Equal(d2 UnbondingDelegation) bool {
|
|
||||||
bz1 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&d)
|
|
||||||
bz2 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&d2)
|
|
||||||
return bytes.Equal(bz1, bz2)
|
|
||||||
}
|
|
||||||
|
|
||||||
// String returns a human readable string representation of an UnbondingDelegation.
|
// String returns a human readable string representation of an UnbondingDelegation.
|
||||||
func (d UnbondingDelegation) String() string {
|
func (ubd UnbondingDelegation) String() string {
|
||||||
out := fmt.Sprintf(`Unbonding Delegations between:
|
out := fmt.Sprintf(`Unbonding Delegations between:
|
||||||
Delegator: %s
|
Delegator: %s
|
||||||
Validator: %s
|
Validator: %s
|
||||||
Entries:`, d.DelegatorAddress, d.ValidatorAddress)
|
Entries:`, ubd.DelegatorAddress, ubd.ValidatorAddress)
|
||||||
for i, entry := range d.Entries {
|
for i, entry := range ubd.Entries {
|
||||||
out += fmt.Sprintf(` Unbonding Delegation %d:
|
out += fmt.Sprintf(` Unbonding Delegation %d:
|
||||||
Creation Height: %v
|
Creation Height: %v
|
||||||
Min time to unbond (unix): %v
|
Min time to unbond (unix): %v
|
||||||
|
@ -217,46 +170,7 @@ func (ubds UnbondingDelegations) String() (out string) {
|
||||||
return strings.TrimSpace(out)
|
return strings.TrimSpace(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Redelegation contains the list of a particular delegator's
|
func NewRedelegationEntry(creationHeight int64, completionTime time.Time, balance sdk.Int, sharesDst sdk.Dec) RedelegationEntry {
|
||||||
// redelegating bonds from a particular source validator to a
|
|
||||||
// particular destination validator
|
|
||||||
type Redelegation struct {
|
|
||||||
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"` // delegator
|
|
||||||
ValidatorSrcAddress sdk.ValAddress `json:"validator_src_address" yaml:"validator_src_address"` // validator redelegation source operator addr
|
|
||||||
ValidatorDstAddress sdk.ValAddress `json:"validator_dst_address" yaml:"validator_dst_address"` // validator redelegation destination operator addr
|
|
||||||
Entries []RedelegationEntry `json:"entries" yaml:"entries"` // redelegation entries
|
|
||||||
}
|
|
||||||
|
|
||||||
// RedelegationEntry - entry to a Redelegation
|
|
||||||
type RedelegationEntry struct {
|
|
||||||
CreationHeight int64 `json:"creation_height" yaml:"creation_height"` // height at which the redelegation took place
|
|
||||||
CompletionTime time.Time `json:"completion_time" yaml:"completion_time"` // time at which the redelegation will complete
|
|
||||||
InitialBalance sdk.Int `json:"initial_balance" yaml:"initial_balance"` // initial balance when redelegation started
|
|
||||||
SharesDst sdk.Dec `json:"shares_dst" yaml:"shares_dst"` // amount of destination-validator shares created by redelegation
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRedelegation - create a new redelegation object
|
|
||||||
func NewRedelegation(delegatorAddr sdk.AccAddress, validatorSrcAddr,
|
|
||||||
validatorDstAddr sdk.ValAddress, creationHeight int64,
|
|
||||||
minTime time.Time, balance sdk.Int,
|
|
||||||
sharesDst sdk.Dec) Redelegation {
|
|
||||||
|
|
||||||
entry := NewRedelegationEntry(creationHeight,
|
|
||||||
minTime, balance, sharesDst)
|
|
||||||
|
|
||||||
return Redelegation{
|
|
||||||
DelegatorAddress: delegatorAddr,
|
|
||||||
ValidatorSrcAddress: validatorSrcAddr,
|
|
||||||
ValidatorDstAddress: validatorDstAddr,
|
|
||||||
Entries: []RedelegationEntry{entry},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewRedelegationEntry - create a new redelegation object
|
|
||||||
func NewRedelegationEntry(creationHeight int64,
|
|
||||||
completionTime time.Time, balance sdk.Int,
|
|
||||||
sharesDst sdk.Dec) RedelegationEntry {
|
|
||||||
|
|
||||||
return RedelegationEntry{
|
return RedelegationEntry{
|
||||||
CreationHeight: creationHeight,
|
CreationHeight: creationHeight,
|
||||||
CompletionTime: completionTime,
|
CompletionTime: completionTime,
|
||||||
|
@ -265,32 +179,50 @@ func NewRedelegationEntry(creationHeight int64,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String implements the Stringer interface for a RedelegationEntry object.
|
||||||
|
func (e RedelegationEntry) String() string {
|
||||||
|
out, _ := yaml.Marshal(e)
|
||||||
|
return string(out)
|
||||||
|
}
|
||||||
|
|
||||||
// IsMature - is the current entry mature
|
// IsMature - is the current entry mature
|
||||||
func (e RedelegationEntry) IsMature(currentTime time.Time) bool {
|
func (e RedelegationEntry) IsMature(currentTime time.Time) bool {
|
||||||
return !e.CompletionTime.After(currentTime)
|
return !e.CompletionTime.After(currentTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddEntry - append entry to the unbonding delegation
|
func NewRedelegation(
|
||||||
func (d *Redelegation) AddEntry(creationHeight int64,
|
delegatorAddr sdk.AccAddress, validatorSrcAddr, validatorDstAddr sdk.ValAddress,
|
||||||
minTime time.Time, balance sdk.Int,
|
creationHeight int64, minTime time.Time, balance sdk.Int, sharesDst sdk.Dec,
|
||||||
sharesDst sdk.Dec) {
|
) Redelegation {
|
||||||
|
|
||||||
|
return Redelegation{
|
||||||
|
DelegatorAddress: delegatorAddr,
|
||||||
|
ValidatorSrcAddress: validatorSrcAddr,
|
||||||
|
ValidatorDstAddress: validatorDstAddr,
|
||||||
|
Entries: []RedelegationEntry{
|
||||||
|
NewRedelegationEntry(creationHeight, minTime, balance, sharesDst),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddEntry - append entry to the unbonding delegation
|
||||||
|
func (red *Redelegation) AddEntry(creationHeight int64, minTime time.Time, balance sdk.Int, sharesDst sdk.Dec) {
|
||||||
entry := NewRedelegationEntry(creationHeight, minTime, balance, sharesDst)
|
entry := NewRedelegationEntry(creationHeight, minTime, balance, sharesDst)
|
||||||
d.Entries = append(d.Entries, entry)
|
red.Entries = append(red.Entries, entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoveEntry - remove entry at index i to the unbonding delegation
|
// RemoveEntry - remove entry at index i to the unbonding delegation
|
||||||
func (d *Redelegation) RemoveEntry(i int64) {
|
func (red *Redelegation) RemoveEntry(i int64) {
|
||||||
d.Entries = append(d.Entries[:i], d.Entries[i+1:]...)
|
red.Entries = append(red.Entries[:i], red.Entries[i+1:]...)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustMarshalRED returns the Redelegation bytes. Panics if fails.
|
// MustMarshalRED returns the Redelegation bytes. Panics if fails.
|
||||||
func MustMarshalRED(cdc *codec.Codec, red Redelegation) []byte {
|
func MustMarshalRED(cdc codec.Marshaler, red Redelegation) []byte {
|
||||||
return cdc.MustMarshalBinaryLengthPrefixed(red)
|
return cdc.MustMarshalBinaryLengthPrefixed(&red)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustUnmarshalRED unmarshals a redelegation from a store value. Panics if fails.
|
// MustUnmarshalRED unmarshals a redelegation from a store value. Panics if fails.
|
||||||
func MustUnmarshalRED(cdc *codec.Codec, value []byte) Redelegation {
|
func MustUnmarshalRED(cdc codec.Marshaler, value []byte) Redelegation {
|
||||||
red, err := UnmarshalRED(cdc, value)
|
red, err := UnmarshalRED(cdc, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -299,31 +231,23 @@ func MustUnmarshalRED(cdc *codec.Codec, value []byte) Redelegation {
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalRED unmarshals a redelegation from a store value
|
// UnmarshalRED unmarshals a redelegation from a store value
|
||||||
func UnmarshalRED(cdc *codec.Codec, value []byte) (red Redelegation, err error) {
|
func UnmarshalRED(cdc codec.Marshaler, value []byte) (red Redelegation, err error) {
|
||||||
err = cdc.UnmarshalBinaryLengthPrefixed(value, &red)
|
err = cdc.UnmarshalBinaryLengthPrefixed(value, &red)
|
||||||
return red, err
|
return red, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// nolint
|
|
||||||
// inefficient but only used in tests
|
|
||||||
func (d Redelegation) Equal(d2 Redelegation) bool {
|
|
||||||
bz1 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&d)
|
|
||||||
bz2 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&d2)
|
|
||||||
return bytes.Equal(bz1, bz2)
|
|
||||||
}
|
|
||||||
|
|
||||||
// String returns a human readable string representation of a Redelegation.
|
// String returns a human readable string representation of a Redelegation.
|
||||||
func (d Redelegation) String() string {
|
func (red Redelegation) String() string {
|
||||||
out := fmt.Sprintf(`Redelegations between:
|
out := fmt.Sprintf(`Redelegations between:
|
||||||
Delegator: %s
|
Delegator: %s
|
||||||
Source Validator: %s
|
Source Validator: %s
|
||||||
Destination Validator: %s
|
Destination Validator: %s
|
||||||
Entries:
|
Entries:
|
||||||
`,
|
`,
|
||||||
d.DelegatorAddress, d.ValidatorSrcAddress, d.ValidatorDstAddress,
|
red.DelegatorAddress, red.ValidatorSrcAddress, red.ValidatorDstAddress,
|
||||||
)
|
)
|
||||||
|
|
||||||
for i, entry := range d.Entries {
|
for i, entry := range red.Entries {
|
||||||
out += fmt.Sprintf(` Redelegation Entry #%d:
|
out += fmt.Sprintf(` Redelegation Entry #%d:
|
||||||
Creation height: %v
|
Creation height: %v
|
||||||
Min time to unbond (unix): %v
|
Min time to unbond (unix): %v
|
||||||
|
|
|
@ -56,4 +56,5 @@ var (
|
||||||
ErrNeitherShareMsgsGiven = sdkerrors.Register(ModuleName, 43, "neither shares amount nor shares percent provided")
|
ErrNeitherShareMsgsGiven = sdkerrors.Register(ModuleName, 43, "neither shares amount nor shares percent provided")
|
||||||
ErrInvalidHistoricalInfo = sdkerrors.Register(ModuleName, 44, "invalid historical info")
|
ErrInvalidHistoricalInfo = sdkerrors.Register(ModuleName, 44, "invalid historical info")
|
||||||
ErrNoHistoricalInfo = sdkerrors.Register(ModuleName, 45, "no historical info found")
|
ErrNoHistoricalInfo = sdkerrors.Register(ModuleName, 45, "no historical info found")
|
||||||
|
ErrEmptyValidatorPubKey = sdkerrors.Register(ModuleName, 46, "empty validator public key")
|
||||||
)
|
)
|
||||||
|
|
|
@ -74,7 +74,7 @@ type ValidatorSet interface {
|
||||||
Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) stakingexported.DelegationI
|
Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) stakingexported.DelegationI
|
||||||
|
|
||||||
// MaxValidators returns the maximum amount of bonded validators
|
// MaxValidators returns the maximum amount of bonded validators
|
||||||
MaxValidators(sdk.Context) uint16
|
MaxValidators(sdk.Context) uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// DelegationSet expected properties for the set of all delegations for a particular (noalias)
|
// DelegationSet expected properties for the set of all delegations for a particular (noalias)
|
||||||
|
|
|
@ -9,29 +9,23 @@ import (
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// HistoricalInfo contains the historical information that gets stored at each height
|
|
||||||
type HistoricalInfo struct {
|
|
||||||
Header abci.Header `json:"header" yaml:"header"`
|
|
||||||
ValSet Validators `json:"valset" yaml:"valset"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewHistoricalInfo will create a historical information struct from header and valset
|
// NewHistoricalInfo will create a historical information struct from header and valset
|
||||||
// it will first sort valset before inclusion into historical info
|
// it will first sort valset before inclusion into historical info
|
||||||
func NewHistoricalInfo(header abci.Header, valSet Validators) HistoricalInfo {
|
func NewHistoricalInfo(header abci.Header, valSet Validators) HistoricalInfo {
|
||||||
sort.Sort(valSet)
|
sort.Sort(valSet)
|
||||||
return HistoricalInfo{
|
return HistoricalInfo{
|
||||||
Header: header,
|
Header: header,
|
||||||
ValSet: valSet,
|
Valset: valSet,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustMarshalHistoricalInfo wll marshal historical info and panic on error
|
// MustMarshalHistoricalInfo wll marshal historical info and panic on error
|
||||||
func MustMarshalHistoricalInfo(cdc *codec.Codec, hi HistoricalInfo) []byte {
|
func MustMarshalHistoricalInfo(cdc codec.Marshaler, hi HistoricalInfo) []byte {
|
||||||
return cdc.MustMarshalBinaryLengthPrefixed(hi)
|
return cdc.MustMarshalBinaryLengthPrefixed(&hi)
|
||||||
}
|
}
|
||||||
|
|
||||||
// MustUnmarshalHistoricalInfo wll unmarshal historical info and panic on error
|
// MustUnmarshalHistoricalInfo wll unmarshal historical info and panic on error
|
||||||
func MustUnmarshalHistoricalInfo(cdc *codec.Codec, value []byte) HistoricalInfo {
|
func MustUnmarshalHistoricalInfo(cdc codec.Marshaler, value []byte) HistoricalInfo {
|
||||||
hi, err := UnmarshalHistoricalInfo(cdc, value)
|
hi, err := UnmarshalHistoricalInfo(cdc, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -40,18 +34,19 @@ func MustUnmarshalHistoricalInfo(cdc *codec.Codec, value []byte) HistoricalInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnmarshalHistoricalInfo will unmarshal historical info and return any error
|
// UnmarshalHistoricalInfo will unmarshal historical info and return any error
|
||||||
func UnmarshalHistoricalInfo(cdc *codec.Codec, value []byte) (hi HistoricalInfo, err error) {
|
func UnmarshalHistoricalInfo(cdc codec.Marshaler, value []byte) (hi HistoricalInfo, err error) {
|
||||||
err = cdc.UnmarshalBinaryLengthPrefixed(value, &hi)
|
err = cdc.UnmarshalBinaryLengthPrefixed(value, &hi)
|
||||||
return hi, err
|
return hi, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateBasic will ensure HistoricalInfo is not nil and sorted
|
// ValidateBasic will ensure HistoricalInfo is not nil and sorted
|
||||||
func ValidateBasic(hi HistoricalInfo) error {
|
func ValidateBasic(hi HistoricalInfo) error {
|
||||||
if len(hi.ValSet) == 0 {
|
if len(hi.Valset) == 0 {
|
||||||
return sdkerrors.Wrap(ErrInvalidHistoricalInfo, "validator set is empty")
|
return sdkerrors.Wrap(ErrInvalidHistoricalInfo, "validator set is empty")
|
||||||
}
|
}
|
||||||
if !sort.IsSorted(hi.ValSet) {
|
if !sort.IsSorted(Validators(hi.Valset)) {
|
||||||
return sdkerrors.Wrap(ErrInvalidHistoricalInfo, "validator set is not sorted by address")
|
return sdkerrors.Wrap(ErrInvalidHistoricalInfo, "validator set is not sorted by address")
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ var (
|
||||||
|
|
||||||
func TestHistoricalInfo(t *testing.T) {
|
func TestHistoricalInfo(t *testing.T) {
|
||||||
hi := NewHistoricalInfo(header, validators)
|
hi := NewHistoricalInfo(header, validators)
|
||||||
require.True(t, sort.IsSorted(hi.ValSet), "Validators are not sorted")
|
require.True(t, sort.IsSorted(Validators(hi.Valset)), "Validators are not sorted")
|
||||||
|
|
||||||
var value []byte
|
var value []byte
|
||||||
require.NotPanics(t, func() {
|
require.NotPanics(t, func() {
|
||||||
|
@ -35,7 +35,7 @@ func TestHistoricalInfo(t *testing.T) {
|
||||||
recv, err := UnmarshalHistoricalInfo(ModuleCdc, value)
|
recv, err := UnmarshalHistoricalInfo(ModuleCdc, value)
|
||||||
require.Nil(t, err, "Unmarshalling HistoricalInfo failed")
|
require.Nil(t, err, "Unmarshalling HistoricalInfo failed")
|
||||||
require.Equal(t, hi, recv, "Unmarshalled HistoricalInfo is different from original")
|
require.Equal(t, hi, recv, "Unmarshalled HistoricalInfo is different from original")
|
||||||
require.True(t, sort.IsSorted(hi.ValSet), "Validators are not sorted")
|
require.True(t, sort.IsSorted(Validators(hi.Valset)), "Validators are not sorted")
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateBasic(t *testing.T) {
|
func TestValidateBasic(t *testing.T) {
|
||||||
|
@ -56,7 +56,7 @@ func TestValidateBasic(t *testing.T) {
|
||||||
|
|
||||||
hi = HistoricalInfo{
|
hi = HistoricalInfo{
|
||||||
Header: header,
|
Header: header,
|
||||||
ValSet: validators,
|
Valset: validators,
|
||||||
}
|
}
|
||||||
err = ValidateBasic(hi)
|
err = ValidateBasic(hi)
|
||||||
require.Error(t, err, "ValidateBasic passed on unsorted ValSet")
|
require.Error(t, err, "ValidateBasic passed on unsorted ValSet")
|
||||||
|
|
|
@ -2,16 +2,13 @@ package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
yaml "gopkg.in/yaml.v2"
|
|
||||||
|
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ensure Msg interface compliance at compile time
|
|
||||||
var (
|
var (
|
||||||
_ sdk.Msg = &MsgCreateValidator{}
|
_ sdk.Msg = &MsgCreateValidator{}
|
||||||
_ sdk.Msg = &MsgEditValidator{}
|
_ sdk.Msg = &MsgEditValidator{}
|
||||||
|
@ -20,29 +17,6 @@ var (
|
||||||
_ sdk.Msg = &MsgBeginRedelegate{}
|
_ sdk.Msg = &MsgBeginRedelegate{}
|
||||||
)
|
)
|
||||||
|
|
||||||
//______________________________________________________________________
|
|
||||||
|
|
||||||
// MsgCreateValidator - struct for bonding transactions
|
|
||||||
type MsgCreateValidator struct {
|
|
||||||
Description Description `json:"description" yaml:"description"`
|
|
||||||
Commission CommissionRates `json:"commission" yaml:"commission"`
|
|
||||||
MinSelfDelegation sdk.Int `json:"min_self_delegation" yaml:"min_self_delegation"`
|
|
||||||
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
|
|
||||||
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
|
|
||||||
PubKey crypto.PubKey `json:"pubkey" yaml:"pubkey"`
|
|
||||||
Value sdk.Coin `json:"value" yaml:"value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type msgCreateValidatorJSON struct {
|
|
||||||
Description Description `json:"description" yaml:"description"`
|
|
||||||
Commission CommissionRates `json:"commission" yaml:"commission"`
|
|
||||||
MinSelfDelegation sdk.Int `json:"min_self_delegation" yaml:"min_self_delegation"`
|
|
||||||
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
|
|
||||||
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
|
|
||||||
PubKey string `json:"pubkey" yaml:"pubkey"`
|
|
||||||
Value sdk.Coin `json:"value" yaml:"value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMsgCreateValidator creates a new MsgCreateValidator instance.
|
// NewMsgCreateValidator creates a new MsgCreateValidator instance.
|
||||||
// Delegator address and validator address are the same.
|
// Delegator address and validator address are the same.
|
||||||
func NewMsgCreateValidator(
|
func NewMsgCreateValidator(
|
||||||
|
@ -50,11 +24,16 @@ func NewMsgCreateValidator(
|
||||||
description Description, commission CommissionRates, minSelfDelegation sdk.Int,
|
description Description, commission CommissionRates, minSelfDelegation sdk.Int,
|
||||||
) MsgCreateValidator {
|
) MsgCreateValidator {
|
||||||
|
|
||||||
|
var pkStr string
|
||||||
|
if pubKey != nil {
|
||||||
|
pkStr = sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pubKey)
|
||||||
|
}
|
||||||
|
|
||||||
return MsgCreateValidator{
|
return MsgCreateValidator{
|
||||||
Description: description,
|
Description: description,
|
||||||
DelegatorAddress: sdk.AccAddress(valAddr),
|
DelegatorAddress: sdk.AccAddress(valAddr),
|
||||||
ValidatorAddress: valAddr,
|
ValidatorAddress: valAddr,
|
||||||
PubKey: pubKey,
|
Pubkey: pkStr,
|
||||||
Value: selfDelegation,
|
Value: selfDelegation,
|
||||||
Commission: commission,
|
Commission: commission,
|
||||||
MinSelfDelegation: minSelfDelegation,
|
MinSelfDelegation: minSelfDelegation,
|
||||||
|
@ -81,70 +60,6 @@ func (msg MsgCreateValidator) GetSigners() []sdk.AccAddress {
|
||||||
return addrs
|
return addrs
|
||||||
}
|
}
|
||||||
|
|
||||||
// MarshalJSON implements the json.Marshaler interface to provide custom JSON
|
|
||||||
// serialization of the MsgCreateValidator type.
|
|
||||||
func (msg MsgCreateValidator) MarshalJSON() ([]byte, error) {
|
|
||||||
return json.Marshal(msgCreateValidatorJSON{
|
|
||||||
Description: msg.Description,
|
|
||||||
Commission: msg.Commission,
|
|
||||||
DelegatorAddress: msg.DelegatorAddress,
|
|
||||||
ValidatorAddress: msg.ValidatorAddress,
|
|
||||||
PubKey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, msg.PubKey),
|
|
||||||
Value: msg.Value,
|
|
||||||
MinSelfDelegation: msg.MinSelfDelegation,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON implements the json.Unmarshaler interface to provide custom
|
|
||||||
// JSON deserialization of the MsgCreateValidator type.
|
|
||||||
func (msg *MsgCreateValidator) UnmarshalJSON(bz []byte) error {
|
|
||||||
var msgCreateValJSON msgCreateValidatorJSON
|
|
||||||
if err := json.Unmarshal(bz, &msgCreateValJSON); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
msg.Description = msgCreateValJSON.Description
|
|
||||||
msg.Commission = msgCreateValJSON.Commission
|
|
||||||
msg.DelegatorAddress = msgCreateValJSON.DelegatorAddress
|
|
||||||
msg.ValidatorAddress = msgCreateValJSON.ValidatorAddress
|
|
||||||
var err error
|
|
||||||
msg.PubKey, err = sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, msgCreateValJSON.PubKey)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
msg.Value = msgCreateValJSON.Value
|
|
||||||
msg.MinSelfDelegation = msgCreateValJSON.MinSelfDelegation
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalYAML implements a custom marshal yaml function due to consensus pubkey.
|
|
||||||
func (msg MsgCreateValidator) MarshalYAML() (interface{}, error) {
|
|
||||||
bs, err := yaml.Marshal(struct {
|
|
||||||
Description Description
|
|
||||||
Commission CommissionRates
|
|
||||||
MinSelfDelegation sdk.Int
|
|
||||||
DelegatorAddress sdk.AccAddress
|
|
||||||
ValidatorAddress sdk.ValAddress
|
|
||||||
PubKey string
|
|
||||||
Value sdk.Coin
|
|
||||||
}{
|
|
||||||
Description: msg.Description,
|
|
||||||
Commission: msg.Commission,
|
|
||||||
MinSelfDelegation: msg.MinSelfDelegation,
|
|
||||||
DelegatorAddress: msg.DelegatorAddress,
|
|
||||||
ValidatorAddress: msg.ValidatorAddress,
|
|
||||||
PubKey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, msg.PubKey),
|
|
||||||
Value: msg.Value,
|
|
||||||
})
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return string(bs), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetSignBytes returns the message bytes to sign over.
|
// GetSignBytes returns the message bytes to sign over.
|
||||||
func (msg MsgCreateValidator) GetSignBytes() []byte {
|
func (msg MsgCreateValidator) GetSignBytes() []byte {
|
||||||
bz := ModuleCdc.MustMarshalJSON(msg)
|
bz := ModuleCdc.MustMarshalJSON(msg)
|
||||||
|
@ -163,6 +78,9 @@ func (msg MsgCreateValidator) ValidateBasic() error {
|
||||||
if !sdk.AccAddress(msg.ValidatorAddress).Equals(msg.DelegatorAddress) {
|
if !sdk.AccAddress(msg.ValidatorAddress).Equals(msg.DelegatorAddress) {
|
||||||
return ErrBadValidatorAddr
|
return ErrBadValidatorAddr
|
||||||
}
|
}
|
||||||
|
if msg.Pubkey == "" {
|
||||||
|
return ErrEmptyValidatorPubKey
|
||||||
|
}
|
||||||
if !msg.Value.Amount.IsPositive() {
|
if !msg.Value.Amount.IsPositive() {
|
||||||
return ErrBadDelegationAmount
|
return ErrBadDelegationAmount
|
||||||
}
|
}
|
||||||
|
@ -185,20 +103,6 @@ func (msg MsgCreateValidator) ValidateBasic() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgEditValidator - struct for editing a validator
|
|
||||||
type MsgEditValidator struct {
|
|
||||||
Description Description `json:"description" yaml:"description"`
|
|
||||||
ValidatorAddress sdk.ValAddress `json:"address" yaml:"address"`
|
|
||||||
|
|
||||||
// We pass a reference to the new commission rate and min self delegation as it's not mandatory to
|
|
||||||
// update. If not updated, the deserialized rate will be zero with no way to
|
|
||||||
// distinguish if an update was intended.
|
|
||||||
//
|
|
||||||
// REF: #2373
|
|
||||||
CommissionRate *sdk.Dec `json:"commission_rate" yaml:"commission_rate"`
|
|
||||||
MinSelfDelegation *sdk.Int `json:"min_self_delegation" yaml:"min_self_delegation"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMsgEditValidator creates a new MsgEditValidator instance
|
// NewMsgEditValidator creates a new MsgEditValidator instance
|
||||||
func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, newRate *sdk.Dec, newMinSelfDelegation *sdk.Int) MsgEditValidator {
|
func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, newRate *sdk.Dec, newMinSelfDelegation *sdk.Int) MsgEditValidator {
|
||||||
return MsgEditValidator{
|
return MsgEditValidator{
|
||||||
|
@ -246,13 +150,6 @@ func (msg MsgEditValidator) ValidateBasic() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgDelegate - struct for bonding transactions
|
|
||||||
type MsgDelegate struct {
|
|
||||||
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
|
|
||||||
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
|
|
||||||
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMsgDelegate creates a new MsgDelegate instance.
|
// NewMsgDelegate creates a new MsgDelegate instance.
|
||||||
func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) MsgDelegate {
|
func NewMsgDelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) MsgDelegate {
|
||||||
return MsgDelegate{
|
return MsgDelegate{
|
||||||
|
@ -293,16 +190,6 @@ func (msg MsgDelegate) ValidateBasic() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//______________________________________________________________________
|
|
||||||
|
|
||||||
// MsgBeginRedelegate defines the attributes of a bonding transaction.
|
|
||||||
type MsgBeginRedelegate struct {
|
|
||||||
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
|
|
||||||
ValidatorSrcAddress sdk.ValAddress `json:"validator_src_address" yaml:"validator_src_address"`
|
|
||||||
ValidatorDstAddress sdk.ValAddress `json:"validator_dst_address" yaml:"validator_dst_address"`
|
|
||||||
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMsgBeginRedelegate creates a new MsgBeginRedelegate instance.
|
// NewMsgBeginRedelegate creates a new MsgBeginRedelegate instance.
|
||||||
func NewMsgBeginRedelegate(
|
func NewMsgBeginRedelegate(
|
||||||
delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress, amount sdk.Coin,
|
delAddr sdk.AccAddress, valSrcAddr, valDstAddr sdk.ValAddress, amount sdk.Coin,
|
||||||
|
@ -349,13 +236,6 @@ func (msg MsgBeginRedelegate) ValidateBasic() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgUndelegate - struct for unbonding transactions
|
|
||||||
type MsgUndelegate struct {
|
|
||||||
DelegatorAddress sdk.AccAddress `json:"delegator_address" yaml:"delegator_address"`
|
|
||||||
ValidatorAddress sdk.ValAddress `json:"validator_address" yaml:"validator_address"`
|
|
||||||
Amount sdk.Coin `json:"amount" yaml:"amount"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewMsgUndelegate creates a new MsgUndelegate instance.
|
// NewMsgUndelegate creates a new MsgUndelegate instance.
|
||||||
func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) MsgUndelegate {
|
func NewMsgUndelegate(delAddr sdk.AccAddress, valAddr sdk.ValAddress, amount sdk.Coin) MsgUndelegate {
|
||||||
return MsgUndelegate{
|
return MsgUndelegate{
|
||||||
|
|
|
@ -1,11 +1,8 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
yaml "gopkg.in/yaml.v2"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/tendermint/tendermint/crypto"
|
"github.com/tendermint/tendermint/crypto"
|
||||||
|
|
||||||
|
@ -35,7 +32,7 @@ func TestMsgCreateValidator(t *testing.T) {
|
||||||
{"partial description", "", "", "c", "", "", commission1, sdk.OneInt(), valAddr1, pk1, coinPos, true},
|
{"partial description", "", "", "c", "", "", commission1, sdk.OneInt(), valAddr1, pk1, coinPos, true},
|
||||||
{"empty description", "", "", "", "", "", commission2, sdk.OneInt(), valAddr1, pk1, coinPos, false},
|
{"empty description", "", "", "", "", "", commission2, sdk.OneInt(), valAddr1, pk1, coinPos, false},
|
||||||
{"empty address", "a", "b", "c", "d", "e", commission2, sdk.OneInt(), emptyAddr, pk1, coinPos, false},
|
{"empty address", "a", "b", "c", "d", "e", commission2, sdk.OneInt(), emptyAddr, pk1, coinPos, false},
|
||||||
{"empty pubkey", "a", "b", "c", "d", "e", commission1, sdk.OneInt(), valAddr1, emptyPubkey, coinPos, true},
|
{"empty pubkey", "a", "b", "c", "d", "e", commission1, sdk.OneInt(), valAddr1, emptyPubkey, coinPos, false},
|
||||||
{"empty bond", "a", "b", "c", "d", "e", commission2, sdk.OneInt(), valAddr1, pk1, coinZero, false},
|
{"empty bond", "a", "b", "c", "d", "e", commission2, sdk.OneInt(), valAddr1, pk1, coinZero, false},
|
||||||
{"zero min self delegation", "a", "b", "c", "d", "e", commission1, sdk.ZeroInt(), valAddr1, pk1, coinPos, false},
|
{"zero min self delegation", "a", "b", "c", "d", "e", commission1, sdk.ZeroInt(), valAddr1, pk1, coinPos, false},
|
||||||
{"negative min self delegation", "a", "b", "c", "d", "e", commission1, sdk.NewInt(-1), valAddr1, pk1, coinPos, false},
|
{"negative min self delegation", "a", "b", "c", "d", "e", commission1, sdk.NewInt(-1), valAddr1, pk1, coinPos, false},
|
||||||
|
@ -157,47 +154,3 @@ func TestMsgUndelegate(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//test to validate if NewMsgCreateValidator implements yaml marshaller
|
|
||||||
func TestMsgMarshalYAML(t *testing.T) {
|
|
||||||
commission1 := NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec())
|
|
||||||
tc := struct {
|
|
||||||
name, moniker, identity, website, securityContact, details string
|
|
||||||
CommissionRates CommissionRates
|
|
||||||
minSelfDelegation sdk.Int
|
|
||||||
validatorAddr sdk.ValAddress
|
|
||||||
pubkey crypto.PubKey
|
|
||||||
bond sdk.Coin
|
|
||||||
expectPass bool
|
|
||||||
}{"basic good", "a", "b", "c", "d", "e", commission1, sdk.OneInt(), valAddr1, pk1, coinPos, true}
|
|
||||||
|
|
||||||
description := NewDescription(tc.moniker, tc.identity, tc.website, tc.securityContact, tc.details)
|
|
||||||
msg := NewMsgCreateValidator(tc.validatorAddr, tc.pubkey, tc.bond, description, tc.CommissionRates, tc.minSelfDelegation)
|
|
||||||
bs, err := yaml.Marshal(msg)
|
|
||||||
require.NoError(t, err)
|
|
||||||
bechifiedPub, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, msg.PubKey)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
want := fmt.Sprintf(`|
|
|
||||||
description:
|
|
||||||
moniker: a
|
|
||||||
identity: b
|
|
||||||
website: c
|
|
||||||
security_contact: d
|
|
||||||
details: e
|
|
||||||
commission:
|
|
||||||
rate: "0.000000000000000000"
|
|
||||||
max_rate: "0.000000000000000000"
|
|
||||||
max_change_rate: "0.000000000000000000"
|
|
||||||
minselfdelegation: "1"
|
|
||||||
delegatoraddress: %s
|
|
||||||
validatoraddress: %s
|
|
||||||
pubkey: %s
|
|
||||||
value:
|
|
||||||
denom: stake
|
|
||||||
amount: "1000"
|
|
||||||
`, msg.DelegatorAddress, msg.ValidatorAddress, bechifiedPub)
|
|
||||||
|
|
||||||
require.Equal(t, want, string(bs))
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -10,6 +9,7 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
"github.com/cosmos/cosmos-sdk/x/params"
|
"github.com/cosmos/cosmos-sdk/x/params"
|
||||||
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Staking params default values
|
// Staking params default values
|
||||||
|
@ -20,14 +20,14 @@ const (
|
||||||
DefaultUnbondingTime time.Duration = time.Hour * 24 * 7 * 3
|
DefaultUnbondingTime time.Duration = time.Hour * 24 * 7 * 3
|
||||||
|
|
||||||
// Default maximum number of bonded validators
|
// Default maximum number of bonded validators
|
||||||
DefaultMaxValidators uint16 = 100
|
DefaultMaxValidators uint32 = 100
|
||||||
|
|
||||||
// Default maximum entries in a UBD/RED pair
|
// Default maximum entries in a UBD/RED pair
|
||||||
DefaultMaxEntries uint16 = 7
|
DefaultMaxEntries uint32 = 7
|
||||||
|
|
||||||
// DefaultHistorical entries is 0 since it must only be non-zero for
|
// DefaultHistorical entries is 0 since it must only be non-zero for
|
||||||
// IBC connected chains
|
// IBC connected chains
|
||||||
DefaultHistoricalEntries uint16 = 0
|
DefaultHistoricalEntries uint32 = 0
|
||||||
)
|
)
|
||||||
|
|
||||||
// nolint - Keys for parameter access
|
// nolint - Keys for parameter access
|
||||||
|
@ -41,18 +41,10 @@ var (
|
||||||
|
|
||||||
var _ params.ParamSet = (*Params)(nil)
|
var _ params.ParamSet = (*Params)(nil)
|
||||||
|
|
||||||
// Params defines the high level settings for staking
|
|
||||||
type Params struct {
|
|
||||||
UnbondingTime time.Duration `json:"unbonding_time" yaml:"unbonding_time"` // time duration of unbonding
|
|
||||||
MaxValidators uint16 `json:"max_validators" yaml:"max_validators"` // maximum number of validators (max uint16 = 65535)
|
|
||||||
MaxEntries uint16 `json:"max_entries" yaml:"max_entries"` // max entries for either unbonding delegation or redelegation (per pair/trio)
|
|
||||||
HistoricalEntries uint16 `json:"historical_entries" yaml:"historical_entries"` // number of historical entries to persist
|
|
||||||
BondDenom string `json:"bond_denom" yaml:"bond_denom"` // bondable coin denomination
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewParams creates a new Params instance
|
// NewParams creates a new Params instance
|
||||||
func NewParams(unbondingTime time.Duration, maxValidators, maxEntries, historicalEntries uint16,
|
func NewParams(
|
||||||
bondDenom string) Params {
|
unbondingTime time.Duration, maxValidators, maxEntries, historicalEntries uint32, bondDenom string,
|
||||||
|
) Params {
|
||||||
|
|
||||||
return Params{
|
return Params{
|
||||||
UnbondingTime: unbondingTime,
|
UnbondingTime: unbondingTime,
|
||||||
|
@ -74,28 +66,21 @@ func (p *Params) ParamSetPairs() params.ParamSetPairs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Equal returns a boolean determining if two Param types are identical.
|
|
||||||
// TODO: This is slower than comparing struct fields directly
|
|
||||||
func (p Params) Equal(p2 Params) bool {
|
|
||||||
bz1 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&p)
|
|
||||||
bz2 := ModuleCdc.MustMarshalBinaryLengthPrefixed(&p2)
|
|
||||||
return bytes.Equal(bz1, bz2)
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultParams returns a default set of parameters.
|
// DefaultParams returns a default set of parameters.
|
||||||
func DefaultParams() Params {
|
func DefaultParams() Params {
|
||||||
return NewParams(DefaultUnbondingTime, DefaultMaxValidators, DefaultMaxEntries, DefaultHistoricalEntries, sdk.DefaultBondDenom)
|
return NewParams(
|
||||||
|
DefaultUnbondingTime,
|
||||||
|
DefaultMaxValidators,
|
||||||
|
DefaultMaxEntries,
|
||||||
|
DefaultHistoricalEntries,
|
||||||
|
sdk.DefaultBondDenom,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns a human readable string representation of the parameters.
|
// String returns a human readable string representation of the parameters.
|
||||||
func (p Params) String() string {
|
func (p Params) String() string {
|
||||||
return fmt.Sprintf(`Params:
|
out, _ := yaml.Marshal(p)
|
||||||
Unbonding Time: %s
|
return string(out)
|
||||||
Max Validators: %d
|
|
||||||
Max Entries: %d
|
|
||||||
Historical Entries: %d
|
|
||||||
Bonded Coin Denom: %s`, p.UnbondingTime,
|
|
||||||
p.MaxValidators, p.MaxEntries, p.HistoricalEntries, p.BondDenom)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// unmarshal the current staking params value from store key or panic
|
// unmarshal the current staking params value from store key or panic
|
||||||
|
@ -148,7 +133,7 @@ func validateUnbondingTime(i interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateMaxValidators(i interface{}) error {
|
func validateMaxValidators(i interface{}) error {
|
||||||
v, ok := i.(uint16)
|
v, ok := i.(uint32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("invalid parameter type: %T", i)
|
return fmt.Errorf("invalid parameter type: %T", i)
|
||||||
}
|
}
|
||||||
|
@ -161,7 +146,7 @@ func validateMaxValidators(i interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateMaxEntries(i interface{}) error {
|
func validateMaxEntries(i interface{}) error {
|
||||||
v, ok := i.(uint16)
|
v, ok := i.(uint32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("invalid parameter type: %T", i)
|
return fmt.Errorf("invalid parameter type: %T", i)
|
||||||
}
|
}
|
||||||
|
@ -174,7 +159,7 @@ func validateMaxEntries(i interface{}) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateHistoricalEntries(i interface{}) error {
|
func validateHistoricalEntries(i interface{}) error {
|
||||||
_, ok := i.(uint16)
|
_, ok := i.(uint32)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("invalid parameter type: %T", i)
|
return fmt.Errorf("invalid parameter type: %T", i)
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,368 @@
|
||||||
|
syntax = "proto3";
|
||||||
|
package cosmos_sdk.x.staking.v1;
|
||||||
|
|
||||||
|
import "third_party/proto/gogoproto/gogo.proto";
|
||||||
|
import "third_party/proto/tendermint/abci/types/types.proto";
|
||||||
|
import "google/protobuf/timestamp.proto";
|
||||||
|
import "google/protobuf/duration.proto";
|
||||||
|
import "types/types.proto";
|
||||||
|
|
||||||
|
option go_package = "github.com/cosmos/cosmos-sdk/x/staking/types";
|
||||||
|
|
||||||
|
// MsgCreateValidator defines an SDK message for creating a new validator.
|
||||||
|
message MsgCreateValidator {
|
||||||
|
Description description = 1 [(gogoproto.nullable) = false];
|
||||||
|
CommissionRates commission = 2 [(gogoproto.nullable) = false];
|
||||||
|
string min_self_delegation = 3 [
|
||||||
|
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||||
|
(gogoproto.moretags) = "yaml:\"min_self_delegation\"",
|
||||||
|
(gogoproto.nullable) = false
|
||||||
|
];
|
||||||
|
bytes delegator_address = 4 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"delegator_address\""
|
||||||
|
];
|
||||||
|
bytes validator_address = 5 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"validator_address\""
|
||||||
|
];
|
||||||
|
string pubkey = 6;
|
||||||
|
cosmos_sdk.v1.Coin value = 7 [(gogoproto.nullable) = false];
|
||||||
|
}
|
||||||
|
|
||||||
|
// MsgEditValidator defines an SDK message for editing an existing validator.
|
||||||
|
message MsgEditValidator {
|
||||||
|
Description description = 1 [(gogoproto.nullable) = false];
|
||||||
|
bytes validator_address = 2 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"address\""
|
||||||
|
];
|
||||||
|
|
||||||
|
// We pass a reference to the new commission rate and min self delegation as
|
||||||
|
// it's not mandatory to update. If not updated, the deserialized rate will be
|
||||||
|
// zero with no way to distinguish if an update was intended.
|
||||||
|
//
|
||||||
|
// REF: #2373
|
||||||
|
string commission_rate = 3 [
|
||||||
|
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
|
||||||
|
(gogoproto.moretags) = "yaml:\"commission_rate\""
|
||||||
|
];
|
||||||
|
string min_self_delegation = 4 [
|
||||||
|
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||||
|
(gogoproto.moretags) = "yaml:\"min_self_delegation\""
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// MsgDelegate defines an SDK message for performing a delegation from a
|
||||||
|
// delegate to a validator.
|
||||||
|
message MsgDelegate {
|
||||||
|
bytes delegator_address = 1 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"delegator_address\""
|
||||||
|
];
|
||||||
|
bytes validator_address = 2 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"validator_address\""
|
||||||
|
];
|
||||||
|
cosmos_sdk.v1.Coin amount = 3 [(gogoproto.nullable) = false];
|
||||||
|
}
|
||||||
|
|
||||||
|
// MsgBeginRedelegate defines an SDK message for performing a redelegation from
|
||||||
|
// a delegate and source validator to a destination validator.
|
||||||
|
message MsgBeginRedelegate {
|
||||||
|
bytes delegator_address = 1 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"delegator_address\""
|
||||||
|
];
|
||||||
|
bytes validator_src_address = 2 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"validator_src_address\""
|
||||||
|
];
|
||||||
|
bytes validator_dst_address = 3 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"validator_dst_address\""
|
||||||
|
];
|
||||||
|
cosmos_sdk.v1.Coin amount = 4 [(gogoproto.nullable) = false];
|
||||||
|
}
|
||||||
|
|
||||||
|
// MsgUndelegate defines an SDK message for performing an undelegation from a
|
||||||
|
// delegate and a validator.
|
||||||
|
message MsgUndelegate {
|
||||||
|
bytes delegator_address = 1 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"delegator_address\""
|
||||||
|
];
|
||||||
|
bytes validator_address = 2 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"validator_address\""
|
||||||
|
];
|
||||||
|
cosmos_sdk.v1.Coin amount = 3 [(gogoproto.nullable) = false];
|
||||||
|
}
|
||||||
|
|
||||||
|
// HistoricalInfo contains the historical information that gets stored at
|
||||||
|
// each height.
|
||||||
|
message HistoricalInfo {
|
||||||
|
option (gogoproto.equal) = true;
|
||||||
|
|
||||||
|
tendermint.abci.types.Header header = 1 [(gogoproto.nullable) = false];
|
||||||
|
repeated Validator valset = 2 [(gogoproto.nullable) = false];
|
||||||
|
}
|
||||||
|
|
||||||
|
// CommissionRates defines the initial commission rates to be used for creating
|
||||||
|
// a validator.
|
||||||
|
message CommissionRates {
|
||||||
|
option (gogoproto.equal) = true;
|
||||||
|
option (gogoproto.goproto_stringer) = false;
|
||||||
|
|
||||||
|
string rate = 1 [
|
||||||
|
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
|
||||||
|
(gogoproto.nullable) = false
|
||||||
|
];
|
||||||
|
string max_rate = 2 [
|
||||||
|
(gogoproto.moretags) = "yaml:\"max_rate\"",
|
||||||
|
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
|
||||||
|
(gogoproto.nullable) = false
|
||||||
|
];
|
||||||
|
string max_change_rate = 3 [
|
||||||
|
(gogoproto.moretags) = "yaml:\"max_change_rate\"",
|
||||||
|
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
|
||||||
|
(gogoproto.nullable) = false
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commission defines a commission parameters for a given validator.
|
||||||
|
message Commission {
|
||||||
|
option (gogoproto.equal) = true;
|
||||||
|
option (gogoproto.goproto_stringer) = false;
|
||||||
|
|
||||||
|
CommissionRates commission_rates = 1 [(gogoproto.embed) = true, (gogoproto.nullable) = false];
|
||||||
|
google.protobuf.Timestamp update_time = 2 [
|
||||||
|
(gogoproto.nullable) = false,
|
||||||
|
(gogoproto.stdtime) = true,
|
||||||
|
(gogoproto.moretags) = "yaml:\"update_time\""
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Description defines a validator description.
|
||||||
|
message Description {
|
||||||
|
option (gogoproto.equal) = true;
|
||||||
|
option (gogoproto.goproto_stringer) = false;
|
||||||
|
|
||||||
|
string moniker = 1;
|
||||||
|
string identity = 2;
|
||||||
|
string website = 3;
|
||||||
|
string security_contact = 4 [(gogoproto.moretags) = "yaml:\"security_contact\""];
|
||||||
|
string details = 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validator defines the total amount of bond shares and their exchange rate to
|
||||||
|
// coins. Slashing results in a decrease in the exchange rate, allowing correct
|
||||||
|
// calculation of future undelegations without iterating over delegators.
|
||||||
|
// When coins are delegated to this validator, the validator is credited with a
|
||||||
|
// delegation whose number of bond shares is based on the amount of coins
|
||||||
|
// delegated divided by the current exchange rate. Voting power can be
|
||||||
|
// calculated as total bonded shares multiplied by exchange rate.
|
||||||
|
message Validator {
|
||||||
|
option (gogoproto.equal) = true;
|
||||||
|
option (gogoproto.goproto_stringer) = false;
|
||||||
|
option (gogoproto.goproto_getters) = false;
|
||||||
|
|
||||||
|
bytes operator_address = 1 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"operator_address\""
|
||||||
|
];
|
||||||
|
string consensus_pubkey = 2 [(gogoproto.moretags) = "yaml:\"consensus_pubkey\""];
|
||||||
|
bool jailed = 3;
|
||||||
|
int32 status = 4 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.BondStatus"];
|
||||||
|
string tokens = 5 [
|
||||||
|
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||||
|
(gogoproto.nullable) = false
|
||||||
|
];
|
||||||
|
string delegator_shares = 6 [
|
||||||
|
(gogoproto.moretags) = "yaml:\"delegator_shares\"",
|
||||||
|
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
|
||||||
|
(gogoproto.nullable) = false
|
||||||
|
];
|
||||||
|
Description description = 7 [(gogoproto.nullable) = false];
|
||||||
|
int64 unbonding_height = 8 [(gogoproto.moretags) = "yaml:\"unbonding_height\""];
|
||||||
|
google.protobuf.Timestamp unbonding_time = 9 [
|
||||||
|
(gogoproto.nullable) = false,
|
||||||
|
(gogoproto.stdtime) = true,
|
||||||
|
(gogoproto.moretags) = "yaml:\"unbonding_time\""
|
||||||
|
];
|
||||||
|
Commission commission = 10 [(gogoproto.nullable) = false];
|
||||||
|
string min_self_delegation = 11 [
|
||||||
|
(gogoproto.moretags) = "yaml:\"min_self_delegation\"",
|
||||||
|
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||||
|
(gogoproto.nullable) = false
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// DVPair is struct that just has a delegator-validator pair with no other data.
|
||||||
|
// It is intended to be used as a marshalable pointer. For example, a DVPair can
|
||||||
|
// be used to construct the key to getting an UnbondingDelegation from state.
|
||||||
|
message DVPair {
|
||||||
|
option (gogoproto.equal) = true;
|
||||||
|
option (gogoproto.goproto_stringer) = false;
|
||||||
|
|
||||||
|
bytes delegator_address = 1 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"delegator_address\""
|
||||||
|
];
|
||||||
|
bytes validator_address = 2 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"validator_address\""
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// DVPairs defines an array of DVPair objects.
|
||||||
|
message DVPairs {
|
||||||
|
repeated DVPair pairs = 1 [(gogoproto.nullable) = false];
|
||||||
|
}
|
||||||
|
|
||||||
|
// DVVTriplet is struct that just has a delegator-validator-validator triplet
|
||||||
|
// with no other data. It is intended to be used as a marshalable pointer. For
|
||||||
|
// example, a DVVTriplet can be used to construct the key to getting a
|
||||||
|
// Redelegation from state.
|
||||||
|
message DVVTriplet {
|
||||||
|
option (gogoproto.equal) = true;
|
||||||
|
option (gogoproto.goproto_stringer) = false;
|
||||||
|
|
||||||
|
bytes delegator_address = 1 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"delegator_address\""
|
||||||
|
];
|
||||||
|
bytes validator_src_address = 2 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"validator_src_address\""
|
||||||
|
];
|
||||||
|
bytes validator_dst_address = 3 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"validator_dst_address\""
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// DVVTriplets defines an array of DVVTriplet objects.
|
||||||
|
message DVVTriplets {
|
||||||
|
repeated DVVTriplet triplets = 1 [(gogoproto.nullable) = false];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delegation represents the bond with tokens held by an account. It is
|
||||||
|
// owned by one delegator, and is associated with the voting power of one
|
||||||
|
// validator.
|
||||||
|
message Delegation {
|
||||||
|
option (gogoproto.equal) = true;
|
||||||
|
option (gogoproto.goproto_stringer) = false;
|
||||||
|
|
||||||
|
bytes delegator_address = 1 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"delegator_address\""
|
||||||
|
];
|
||||||
|
bytes validator_address = 2 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"validator_address\""
|
||||||
|
];
|
||||||
|
string shares = 3 [
|
||||||
|
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
|
||||||
|
(gogoproto.nullable) = false
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnbondingDelegation stores all of a single delegator's unbonding bonds
|
||||||
|
// for a single validator in an time-ordered list
|
||||||
|
message UnbondingDelegation {
|
||||||
|
option (gogoproto.equal) = true;
|
||||||
|
option (gogoproto.goproto_stringer) = false;
|
||||||
|
|
||||||
|
bytes delegator_address = 1 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"delegator_address\""
|
||||||
|
];
|
||||||
|
bytes validator_address = 2 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"validator_address\""
|
||||||
|
];
|
||||||
|
repeated UnbondingDelegationEntry entries = 3
|
||||||
|
[(gogoproto.nullable) = false]; // unbonding delegation entries
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnbondingDelegationEntry defines an unbonding object with relevant metadata.
|
||||||
|
message UnbondingDelegationEntry {
|
||||||
|
option (gogoproto.equal) = true;
|
||||||
|
option (gogoproto.goproto_stringer) = false;
|
||||||
|
|
||||||
|
int64 creation_height = 1 [(gogoproto.moretags) = "yaml:\"creation_height\""];
|
||||||
|
google.protobuf.Timestamp completion_time = 2 [
|
||||||
|
(gogoproto.nullable) = false,
|
||||||
|
(gogoproto.stdtime) = true,
|
||||||
|
(gogoproto.moretags) = "yaml:\"completion_time\""
|
||||||
|
];
|
||||||
|
string initial_balance = 3 [
|
||||||
|
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||||
|
(gogoproto.nullable) = false,
|
||||||
|
(gogoproto.moretags) = "yaml:\"initial_balance\""
|
||||||
|
];
|
||||||
|
string balance = 4 [
|
||||||
|
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||||
|
(gogoproto.nullable) = false
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// RedelegationEntry defines a redelegation object with relevant metadata.
|
||||||
|
message RedelegationEntry {
|
||||||
|
option (gogoproto.equal) = true;
|
||||||
|
option (gogoproto.goproto_stringer) = false;
|
||||||
|
|
||||||
|
int64 creation_height = 1 [(gogoproto.moretags) = "yaml:\"creation_height\""];
|
||||||
|
google.protobuf.Timestamp completion_time = 2 [
|
||||||
|
(gogoproto.nullable) = false,
|
||||||
|
(gogoproto.stdtime) = true,
|
||||||
|
(gogoproto.moretags) = "yaml:\"completion_time\""
|
||||||
|
];
|
||||||
|
string initial_balance = 3 [
|
||||||
|
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
|
||||||
|
(gogoproto.nullable) = false,
|
||||||
|
(gogoproto.moretags) = "yaml:\"initial_balance\""
|
||||||
|
];
|
||||||
|
string shares_dst = 4 [
|
||||||
|
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
|
||||||
|
(gogoproto.nullable) = false
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redelegation contains the list of a particular delegator's redelegating bonds
|
||||||
|
// from a particular source validator to a particular destination validator.
|
||||||
|
message Redelegation {
|
||||||
|
option (gogoproto.equal) = true;
|
||||||
|
option (gogoproto.goproto_stringer) = false;
|
||||||
|
|
||||||
|
bytes delegator_address = 1 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.AccAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"delegator_address\""
|
||||||
|
];
|
||||||
|
bytes validator_src_address = 2 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"validator_src_address\""
|
||||||
|
];
|
||||||
|
bytes validator_dst_address = 3 [
|
||||||
|
(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.ValAddress",
|
||||||
|
(gogoproto.moretags) = "yaml:\"validator_dst_address\""
|
||||||
|
];
|
||||||
|
repeated RedelegationEntry entries = 4 [(gogoproto.nullable) = false]; // redelegation entries
|
||||||
|
}
|
||||||
|
|
||||||
|
// Params defines the parameters for the staking module.
|
||||||
|
message Params {
|
||||||
|
option (gogoproto.equal) = true;
|
||||||
|
option (gogoproto.goproto_stringer) = false;
|
||||||
|
|
||||||
|
google.protobuf.Duration unbonding_time = 1 [
|
||||||
|
(gogoproto.nullable) = false,
|
||||||
|
(gogoproto.stdduration) = true,
|
||||||
|
(gogoproto.moretags) = "yaml:\"unbonding_time\""
|
||||||
|
];
|
||||||
|
uint32 max_validators = 2 [(gogoproto.moretags) = "yaml:\"max_validators\""];
|
||||||
|
uint32 max_entries = 3 [(gogoproto.moretags) = "yaml:\"max_entries\""];
|
||||||
|
uint32 historical_entries = 4 [(gogoproto.moretags) = "yaml:\"historical_entries\""];
|
||||||
|
string bond_denom = 5 [(gogoproto.moretags) = "yaml:\"bond_denom\""];
|
||||||
|
}
|
|
@ -28,62 +28,33 @@ const (
|
||||||
MaxDetailsLength = 280
|
MaxDetailsLength = 280
|
||||||
)
|
)
|
||||||
|
|
||||||
// Implements Validator interface
|
|
||||||
var _ exported.ValidatorI = Validator{}
|
var _ exported.ValidatorI = Validator{}
|
||||||
|
|
||||||
// Validator defines the total amount of bond shares and their exchange rate to
|
func NewValidator(operator sdk.ValAddress, pubKey crypto.PubKey, description Description) Validator {
|
||||||
// coins. Slashing results in a decrease in the exchange rate, allowing correct
|
var pkStr string
|
||||||
// calculation of future undelegations without iterating over delegators.
|
if pubKey != nil {
|
||||||
// When coins are delegated to this validator, the validator is credited with a
|
pkStr = sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pubKey)
|
||||||
// delegation whose number of bond shares is based on the amount of coins delegated
|
|
||||||
// divided by the current exchange rate. Voting power can be calculated as total
|
|
||||||
// bonded shares multiplied by exchange rate.
|
|
||||||
type Validator struct {
|
|
||||||
OperatorAddress sdk.ValAddress `json:"operator_address" yaml:"operator_address"` // address of the validator's operator; bech encoded in JSON
|
|
||||||
ConsPubKey crypto.PubKey `json:"consensus_pubkey" yaml:"consensus_pubkey"` // the consensus public key of the validator; bech encoded in JSON
|
|
||||||
Jailed bool `json:"jailed" yaml:"jailed"` // has the validator been jailed from bonded status?
|
|
||||||
Status sdk.BondStatus `json:"status" yaml:"status"` // validator status (bonded/unbonding/unbonded)
|
|
||||||
Tokens sdk.Int `json:"tokens" yaml:"tokens"` // delegated tokens (incl. self-delegation)
|
|
||||||
DelegatorShares sdk.Dec `json:"delegator_shares" yaml:"delegator_shares"` // total shares issued to a validator's delegators
|
|
||||||
Description Description `json:"description" yaml:"description"` // description terms for the validator
|
|
||||||
UnbondingHeight int64 `json:"unbonding_height" yaml:"unbonding_height"` // if unbonding, height at which this validator has begun unbonding
|
|
||||||
UnbondingCompletionTime time.Time `json:"unbonding_time" yaml:"unbonding_time"` // if unbonding, min time for the validator to complete unbonding
|
|
||||||
Commission Commission `json:"commission" yaml:"commission"` // commission parameters
|
|
||||||
MinSelfDelegation sdk.Int `json:"min_self_delegation" yaml:"min_self_delegation"` // validator's self declared minimum self delegation
|
|
||||||
}
|
|
||||||
|
|
||||||
// custom marshal yaml function due to consensus pubkey
|
|
||||||
func (v Validator) MarshalYAML() (interface{}, error) {
|
|
||||||
bs, err := yaml.Marshal(struct {
|
|
||||||
OperatorAddress sdk.ValAddress
|
|
||||||
ConsPubKey string
|
|
||||||
Jailed bool
|
|
||||||
Status sdk.BondStatus
|
|
||||||
Tokens sdk.Int
|
|
||||||
DelegatorShares sdk.Dec
|
|
||||||
Description Description
|
|
||||||
UnbondingHeight int64
|
|
||||||
UnbondingCompletionTime time.Time
|
|
||||||
Commission Commission
|
|
||||||
MinSelfDelegation sdk.Int
|
|
||||||
}{
|
|
||||||
OperatorAddress: v.OperatorAddress,
|
|
||||||
ConsPubKey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, v.ConsPubKey),
|
|
||||||
Jailed: v.Jailed,
|
|
||||||
Status: v.Status,
|
|
||||||
Tokens: v.Tokens,
|
|
||||||
DelegatorShares: v.DelegatorShares,
|
|
||||||
Description: v.Description,
|
|
||||||
UnbondingHeight: v.UnbondingHeight,
|
|
||||||
UnbondingCompletionTime: v.UnbondingCompletionTime,
|
|
||||||
Commission: v.Commission,
|
|
||||||
MinSelfDelegation: v.MinSelfDelegation,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(bs), nil
|
return Validator{
|
||||||
|
OperatorAddress: operator,
|
||||||
|
ConsensusPubkey: pkStr,
|
||||||
|
Jailed: false,
|
||||||
|
Status: sdk.Unbonded,
|
||||||
|
Tokens: sdk.ZeroInt(),
|
||||||
|
DelegatorShares: sdk.ZeroDec(),
|
||||||
|
Description: description,
|
||||||
|
UnbondingHeight: int64(0),
|
||||||
|
UnbondingTime: time.Unix(0, 0).UTC(),
|
||||||
|
Commission: NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
|
||||||
|
MinSelfDelegation: sdk.OneInt(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// String implements the Stringer interface for a Validator object.
|
||||||
|
func (v Validator) String() string {
|
||||||
|
out, _ := yaml.Marshal(v)
|
||||||
|
return string(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validators is a collection of Validator
|
// Validators is a collection of Validator
|
||||||
|
@ -135,30 +106,13 @@ func (v Validators) Swap(i, j int) {
|
||||||
v[j] = it
|
v[j] = it
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewValidator - initialize a new validator
|
|
||||||
func NewValidator(operator sdk.ValAddress, pubKey crypto.PubKey, description Description) Validator {
|
|
||||||
return Validator{
|
|
||||||
OperatorAddress: operator,
|
|
||||||
ConsPubKey: pubKey,
|
|
||||||
Jailed: false,
|
|
||||||
Status: sdk.Unbonded,
|
|
||||||
Tokens: sdk.ZeroInt(),
|
|
||||||
DelegatorShares: sdk.ZeroDec(),
|
|
||||||
Description: description,
|
|
||||||
UnbondingHeight: int64(0),
|
|
||||||
UnbondingCompletionTime: time.Unix(0, 0).UTC(),
|
|
||||||
Commission: NewCommission(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()),
|
|
||||||
MinSelfDelegation: sdk.OneInt(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the redelegation
|
// return the redelegation
|
||||||
func MustMarshalValidator(cdc *codec.Codec, validator Validator) []byte {
|
func MustMarshalValidator(cdc codec.Marshaler, validator Validator) []byte {
|
||||||
return cdc.MustMarshalBinaryLengthPrefixed(validator)
|
return cdc.MustMarshalBinaryLengthPrefixed(&validator)
|
||||||
}
|
}
|
||||||
|
|
||||||
// unmarshal a redelegation from a store value
|
// unmarshal a redelegation from a store value
|
||||||
func MustUnmarshalValidator(cdc *codec.Codec, value []byte) Validator {
|
func MustUnmarshalValidator(cdc codec.Marshaler, value []byte) Validator {
|
||||||
validator, err := UnmarshalValidator(cdc, value)
|
validator, err := UnmarshalValidator(cdc, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -167,111 +121,9 @@ func MustUnmarshalValidator(cdc *codec.Codec, value []byte) Validator {
|
||||||
}
|
}
|
||||||
|
|
||||||
// unmarshal a redelegation from a store value
|
// unmarshal a redelegation from a store value
|
||||||
func UnmarshalValidator(cdc *codec.Codec, value []byte) (validator Validator, err error) {
|
func UnmarshalValidator(cdc codec.Marshaler, value []byte) (v Validator, err error) {
|
||||||
err = cdc.UnmarshalBinaryLengthPrefixed(value, &validator)
|
err = cdc.UnmarshalBinaryLengthPrefixed(value, &v)
|
||||||
return validator, err
|
return v, err
|
||||||
}
|
|
||||||
|
|
||||||
// String returns a human readable string representation of a validator.
|
|
||||||
func (v Validator) String() string {
|
|
||||||
bechConsPubKey, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, v.ConsPubKey)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return fmt.Sprintf(`Validator
|
|
||||||
Operator Address: %s
|
|
||||||
Validator Consensus Pubkey: %s
|
|
||||||
Jailed: %v
|
|
||||||
Status: %s
|
|
||||||
Tokens: %s
|
|
||||||
Delegator Shares: %s
|
|
||||||
Description: %s
|
|
||||||
Unbonding Height: %d
|
|
||||||
Unbonding Completion Time: %v
|
|
||||||
Minimum Self Delegation: %v
|
|
||||||
Commission: %s`, v.OperatorAddress, bechConsPubKey,
|
|
||||||
v.Jailed, v.Status, v.Tokens,
|
|
||||||
v.DelegatorShares, v.Description,
|
|
||||||
v.UnbondingHeight, v.UnbondingCompletionTime, v.MinSelfDelegation, v.Commission)
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is a helper struct used for JSON de- and encoding only
|
|
||||||
type bechValidator struct {
|
|
||||||
OperatorAddress sdk.ValAddress `json:"operator_address" yaml:"operator_address"` // the bech32 address of the validator's operator
|
|
||||||
ConsPubKey string `json:"consensus_pubkey" yaml:"consensus_pubkey"` // the bech32 consensus public key of the validator
|
|
||||||
Jailed bool `json:"jailed" yaml:"jailed"` // has the validator been jailed from bonded status?
|
|
||||||
Status sdk.BondStatus `json:"status" yaml:"status"` // validator status (bonded/unbonding/unbonded)
|
|
||||||
Tokens sdk.Int `json:"tokens" yaml:"tokens"` // delegated tokens (incl. self-delegation)
|
|
||||||
DelegatorShares sdk.Dec `json:"delegator_shares" yaml:"delegator_shares"` // total shares issued to a validator's delegators
|
|
||||||
Description Description `json:"description" yaml:"description"` // description terms for the validator
|
|
||||||
UnbondingHeight int64 `json:"unbonding_height" yaml:"unbonding_height"` // if unbonding, height at which this validator has begun unbonding
|
|
||||||
UnbondingCompletionTime time.Time `json:"unbonding_time" yaml:"unbonding_time"` // if unbonding, min time for the validator to complete unbonding
|
|
||||||
Commission Commission `json:"commission" yaml:"commission"` // commission parameters
|
|
||||||
MinSelfDelegation sdk.Int `json:"min_self_delegation" yaml:"min_self_delegation"` // minimum self delegation
|
|
||||||
}
|
|
||||||
|
|
||||||
// MarshalJSON marshals the validator to JSON using Bech32
|
|
||||||
func (v Validator) MarshalJSON() ([]byte, error) {
|
|
||||||
bechConsPubKey, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, v.ConsPubKey)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return codec.Cdc.MarshalJSON(bechValidator{
|
|
||||||
OperatorAddress: v.OperatorAddress,
|
|
||||||
ConsPubKey: bechConsPubKey,
|
|
||||||
Jailed: v.Jailed,
|
|
||||||
Status: v.Status,
|
|
||||||
Tokens: v.Tokens,
|
|
||||||
DelegatorShares: v.DelegatorShares,
|
|
||||||
Description: v.Description,
|
|
||||||
UnbondingHeight: v.UnbondingHeight,
|
|
||||||
UnbondingCompletionTime: v.UnbondingCompletionTime,
|
|
||||||
MinSelfDelegation: v.MinSelfDelegation,
|
|
||||||
Commission: v.Commission,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// UnmarshalJSON unmarshals the validator from JSON using Bech32
|
|
||||||
func (v *Validator) UnmarshalJSON(data []byte) error {
|
|
||||||
bv := &bechValidator{}
|
|
||||||
if err := codec.Cdc.UnmarshalJSON(data, bv); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
consPubKey, err := sdk.GetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, bv.ConsPubKey)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
*v = Validator{
|
|
||||||
OperatorAddress: bv.OperatorAddress,
|
|
||||||
ConsPubKey: consPubKey,
|
|
||||||
Jailed: bv.Jailed,
|
|
||||||
Tokens: bv.Tokens,
|
|
||||||
Status: bv.Status,
|
|
||||||
DelegatorShares: bv.DelegatorShares,
|
|
||||||
Description: bv.Description,
|
|
||||||
UnbondingHeight: bv.UnbondingHeight,
|
|
||||||
UnbondingCompletionTime: bv.UnbondingCompletionTime,
|
|
||||||
Commission: bv.Commission,
|
|
||||||
MinSelfDelegation: bv.MinSelfDelegation,
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// only the vitals
|
|
||||||
func (v Validator) TestEquivalent(v2 Validator) bool {
|
|
||||||
return v.ConsPubKey.Equals(v2.ConsPubKey) &&
|
|
||||||
bytes.Equal(v.OperatorAddress, v2.OperatorAddress) &&
|
|
||||||
v.Status.Equal(v2.Status) &&
|
|
||||||
v.Tokens.Equal(v2.Tokens) &&
|
|
||||||
v.DelegatorShares.Equal(v2.DelegatorShares) &&
|
|
||||||
v.Description == v2.Description &&
|
|
||||||
v.Commission.Equal(v2.Commission)
|
|
||||||
}
|
|
||||||
|
|
||||||
// return the TM validator address
|
|
||||||
func (v Validator) ConsAddress() sdk.ConsAddress {
|
|
||||||
return sdk.ConsAddress(v.ConsPubKey.Address())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsBonded checks if the validator status equals Bonded
|
// IsBonded checks if the validator status equals Bonded
|
||||||
|
@ -292,16 +144,6 @@ func (v Validator) IsUnbonding() bool {
|
||||||
// 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
|
||||||
const DoNotModifyDesc = "[do-not-modify]"
|
const DoNotModifyDesc = "[do-not-modify]"
|
||||||
|
|
||||||
// Description - description fields for a validator
|
|
||||||
type Description struct {
|
|
||||||
Moniker string `json:"moniker" yaml:"moniker"` // name
|
|
||||||
Identity string `json:"identity" yaml:"identity"` // optional identity signature (ex. UPort or Keybase)
|
|
||||||
Website string `json:"website" yaml:"website"` // optional website link
|
|
||||||
SecurityContact string `json:"security_contact" yaml:"security_contact"` // optional security contact info
|
|
||||||
Details string `json:"details" yaml:"details"` // optional details
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewDescription returns a new Description with the provided values.
|
|
||||||
func NewDescription(moniker, identity, website, securityContact, details string) Description {
|
func NewDescription(moniker, identity, website, securityContact, details string) Description {
|
||||||
return Description{
|
return Description{
|
||||||
Moniker: moniker,
|
Moniker: moniker,
|
||||||
|
@ -312,6 +154,12 @@ func NewDescription(moniker, identity, website, securityContact, details string)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String implements the Stringer interface for a Description object.
|
||||||
|
func (d Description) String() string {
|
||||||
|
out, _ := yaml.Marshal(d)
|
||||||
|
return string(out)
|
||||||
|
}
|
||||||
|
|
||||||
// UpdateDescription updates the fields of a given description. An error is
|
// UpdateDescription updates the fields of a given description. An error is
|
||||||
// returned if the resulting description contains an invalid length.
|
// returned if the resulting description contains an invalid length.
|
||||||
func (d Description) UpdateDescription(d2 Description) (Description, error) {
|
func (d Description) UpdateDescription(d2 Description) (Description, error) {
|
||||||
|
@ -365,7 +213,7 @@ func (d Description) EnsureLength() (Description, 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.ConsPubKey),
|
PubKey: tmtypes.TM2PB.PubKey(v.GetConsPubKey()),
|
||||||
Power: v.ConsensusPower(),
|
Power: v.ConsensusPower(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -374,14 +222,14 @@ 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.ConsPubKey),
|
PubKey: tmtypes.TM2PB.PubKey(v.GetConsPubKey()),
|
||||||
Power: 0,
|
Power: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToTmValidator casts an SDK validator to a tendermint type Validator.
|
// ToTmValidator casts an SDK validator to a tendermint type Validator.
|
||||||
func (v Validator) ToTmValidator() *tmtypes.Validator {
|
func (v Validator) ToTmValidator() *tmtypes.Validator {
|
||||||
return tmtypes.NewValidator(v.ConsPubKey, v.ConsensusPower())
|
return tmtypes.NewValidator(v.GetConsPubKey(), v.ConsensusPower())
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetInitialCommission attempts to set a validator's initial commission. An
|
// SetInitialCommission attempts to set a validator's initial commission. An
|
||||||
|
@ -506,20 +354,19 @@ func (v Validator) RemoveTokens(tokens sdk.Int) Validator {
|
||||||
// NOTE: because token fractions are left in the valiadator,
|
// NOTE: because token fractions are left in the valiadator,
|
||||||
// the exchange rate of future shares of this validator can increase.
|
// the exchange rate of future shares of this validator can increase.
|
||||||
func (v Validator) RemoveDelShares(delShares sdk.Dec) (Validator, sdk.Int) {
|
func (v Validator) RemoveDelShares(delShares sdk.Dec) (Validator, sdk.Int) {
|
||||||
|
|
||||||
remainingShares := v.DelegatorShares.Sub(delShares)
|
remainingShares := v.DelegatorShares.Sub(delShares)
|
||||||
|
|
||||||
var issuedTokens sdk.Int
|
var issuedTokens sdk.Int
|
||||||
if remainingShares.IsZero() {
|
if remainingShares.IsZero() {
|
||||||
|
|
||||||
// last delegation share gets any trimmings
|
// last delegation share gets any trimmings
|
||||||
issuedTokens = v.Tokens
|
issuedTokens = v.Tokens
|
||||||
v.Tokens = sdk.ZeroInt()
|
v.Tokens = sdk.ZeroInt()
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// leave excess tokens in the validator
|
// leave excess tokens in the validator
|
||||||
// however fully use all the delegator shares
|
// however fully use all the delegator shares
|
||||||
issuedTokens = v.TokensFromShares(delShares).TruncateInt()
|
issuedTokens = v.TokensFromShares(delShares).TruncateInt()
|
||||||
v.Tokens = v.Tokens.Sub(issuedTokens)
|
v.Tokens = v.Tokens.Sub(issuedTokens)
|
||||||
|
|
||||||
if v.Tokens.IsNegative() {
|
if v.Tokens.IsNegative() {
|
||||||
panic("attempting to remove more tokens than available in validator")
|
panic("attempting to remove more tokens than available in validator")
|
||||||
}
|
}
|
||||||
|
@ -529,13 +376,27 @@ func (v Validator) RemoveDelShares(delShares sdk.Dec) (Validator, sdk.Int) {
|
||||||
return v, issuedTokens
|
return v, issuedTokens
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MinEqual defines a more minimum set of equality conditions when comparing two
|
||||||
|
// validators.
|
||||||
|
func (v Validator) MinEqual(other Validator) bool {
|
||||||
|
return v.ConsensusPubkey == other.ConsensusPubkey &&
|
||||||
|
bytes.Equal(v.OperatorAddress, other.OperatorAddress) &&
|
||||||
|
v.Status.Equal(other.Status) &&
|
||||||
|
v.Tokens.Equal(other.Tokens) &&
|
||||||
|
v.DelegatorShares.Equal(other.DelegatorShares) &&
|
||||||
|
v.Description == other.Description &&
|
||||||
|
v.Commission.Equal(other.Commission)
|
||||||
|
}
|
||||||
|
|
||||||
// nolint - for ValidatorI
|
// nolint - for ValidatorI
|
||||||
func (v Validator) IsJailed() bool { return v.Jailed }
|
func (v Validator) IsJailed() 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.OperatorAddress }
|
func (v Validator) GetOperator() sdk.ValAddress { return v.OperatorAddress }
|
||||||
func (v Validator) GetConsPubKey() crypto.PubKey { return v.ConsPubKey }
|
func (v Validator) GetConsPubKey() crypto.PubKey {
|
||||||
func (v Validator) GetConsAddr() sdk.ConsAddress { return sdk.ConsAddress(v.ConsPubKey.Address()) }
|
return sdk.MustGetPubKeyFromBech32(sdk.Bech32PubKeyTypeConsPub, v.ConsensusPubkey)
|
||||||
|
}
|
||||||
|
func (v Validator) GetConsAddr() sdk.ConsAddress { return sdk.ConsAddress(v.GetConsPubKey().Address()) }
|
||||||
func (v Validator) GetTokens() sdk.Int { return v.Tokens }
|
func (v Validator) GetTokens() sdk.Int { return v.Tokens }
|
||||||
func (v Validator) GetBondedTokens() sdk.Int { return v.BondedTokens() }
|
func (v Validator) GetBondedTokens() sdk.Int { return v.BondedTokens() }
|
||||||
func (v Validator) GetConsensusPower() int64 { return v.ConsensusPower() }
|
func (v Validator) GetConsensusPower() int64 { return v.ConsensusPower() }
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package types
|
package types
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"reflect"
|
"reflect"
|
||||||
"sort"
|
"sort"
|
||||||
|
@ -11,7 +10,6 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
"github.com/tendermint/tendermint/crypto/ed25519"
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
||||||
tmtypes "github.com/tendermint/tendermint/types"
|
tmtypes "github.com/tendermint/tendermint/types"
|
||||||
yaml "gopkg.in/yaml.v2"
|
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||||
|
@ -21,12 +19,12 @@ func TestValidatorTestEquivalent(t *testing.T) {
|
||||||
val1 := NewValidator(valAddr1, pk1, Description{})
|
val1 := NewValidator(valAddr1, pk1, Description{})
|
||||||
val2 := NewValidator(valAddr1, pk1, Description{})
|
val2 := NewValidator(valAddr1, pk1, Description{})
|
||||||
|
|
||||||
ok := val1.TestEquivalent(val2)
|
ok := val1.Equal(val2)
|
||||||
require.True(t, ok)
|
require.True(t, ok)
|
||||||
|
|
||||||
val2 = NewValidator(valAddr2, pk2, Description{})
|
val2 = NewValidator(valAddr2, pk2, Description{})
|
||||||
|
|
||||||
ok = val1.TestEquivalent(val2)
|
ok = val1.Equal(val2)
|
||||||
require.False(t, ok)
|
require.False(t, ok)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +61,7 @@ func TestABCIValidatorUpdate(t *testing.T) {
|
||||||
validator := NewValidator(valAddr1, pk1, Description{})
|
validator := NewValidator(valAddr1, pk1, Description{})
|
||||||
|
|
||||||
abciVal := validator.ABCIValidatorUpdate()
|
abciVal := validator.ABCIValidatorUpdate()
|
||||||
require.Equal(t, tmtypes.TM2PB.PubKey(validator.ConsPubKey), abciVal.PubKey)
|
require.Equal(t, tmtypes.TM2PB.PubKey(validator.GetConsPubKey()), abciVal.PubKey)
|
||||||
require.Equal(t, validator.BondedTokens().Int64(), abciVal.Power)
|
require.Equal(t, validator.BondedTokens().Int64(), abciVal.Power)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,14 +69,14 @@ func TestABCIValidatorUpdateZero(t *testing.T) {
|
||||||
validator := NewValidator(valAddr1, pk1, Description{})
|
validator := NewValidator(valAddr1, pk1, Description{})
|
||||||
|
|
||||||
abciVal := validator.ABCIValidatorUpdateZero()
|
abciVal := validator.ABCIValidatorUpdateZero()
|
||||||
require.Equal(t, tmtypes.TM2PB.PubKey(validator.ConsPubKey), abciVal.PubKey)
|
require.Equal(t, tmtypes.TM2PB.PubKey(validator.GetConsPubKey()), abciVal.PubKey)
|
||||||
require.Equal(t, int64(0), abciVal.Power)
|
require.Equal(t, int64(0), abciVal.Power)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShareTokens(t *testing.T) {
|
func TestShareTokens(t *testing.T) {
|
||||||
validator := Validator{
|
validator := Validator{
|
||||||
OperatorAddress: valAddr1,
|
OperatorAddress: valAddr1,
|
||||||
ConsPubKey: pk1,
|
ConsensusPubkey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pk1),
|
||||||
Status: sdk.Bonded,
|
Status: sdk.Bonded,
|
||||||
Tokens: sdk.NewInt(100),
|
Tokens: sdk.NewInt(100),
|
||||||
DelegatorShares: sdk.NewDec(100),
|
DelegatorShares: sdk.NewDec(100),
|
||||||
|
@ -96,7 +94,7 @@ func TestRemoveTokens(t *testing.T) {
|
||||||
|
|
||||||
validator := Validator{
|
validator := Validator{
|
||||||
OperatorAddress: valAddr,
|
OperatorAddress: valAddr,
|
||||||
ConsPubKey: valPubKey,
|
ConsensusPubkey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, valPubKey),
|
||||||
Status: sdk.Bonded,
|
Status: sdk.Bonded,
|
||||||
Tokens: sdk.NewInt(100),
|
Tokens: sdk.NewInt(100),
|
||||||
DelegatorShares: sdk.NewDec(100),
|
DelegatorShares: sdk.NewDec(100),
|
||||||
|
@ -152,7 +150,7 @@ func TestAddTokensValidatorUnbonded(t *testing.T) {
|
||||||
func TestRemoveDelShares(t *testing.T) {
|
func TestRemoveDelShares(t *testing.T) {
|
||||||
valA := Validator{
|
valA := Validator{
|
||||||
OperatorAddress: sdk.ValAddress(pk1.Address().Bytes()),
|
OperatorAddress: sdk.ValAddress(pk1.Address().Bytes()),
|
||||||
ConsPubKey: pk1,
|
ConsensusPubkey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pk1),
|
||||||
Status: sdk.Bonded,
|
Status: sdk.Bonded,
|
||||||
Tokens: sdk.NewInt(100),
|
Tokens: sdk.NewInt(100),
|
||||||
DelegatorShares: sdk.NewDec(100),
|
DelegatorShares: sdk.NewDec(100),
|
||||||
|
@ -169,7 +167,7 @@ func TestRemoveDelShares(t *testing.T) {
|
||||||
delShares := sdk.NewDec(115)
|
delShares := sdk.NewDec(115)
|
||||||
validator := Validator{
|
validator := Validator{
|
||||||
OperatorAddress: sdk.ValAddress(pk1.Address().Bytes()),
|
OperatorAddress: sdk.ValAddress(pk1.Address().Bytes()),
|
||||||
ConsPubKey: pk1,
|
ConsensusPubkey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pk1),
|
||||||
Status: sdk.Bonded,
|
Status: sdk.Bonded,
|
||||||
Tokens: poolTokens,
|
Tokens: poolTokens,
|
||||||
DelegatorShares: delShares,
|
DelegatorShares: delShares,
|
||||||
|
@ -218,7 +216,7 @@ func TestPossibleOverflow(t *testing.T) {
|
||||||
delShares := sdk.NewDec(391432570689183511).Quo(sdk.NewDec(40113011844664))
|
delShares := sdk.NewDec(391432570689183511).Quo(sdk.NewDec(40113011844664))
|
||||||
validator := Validator{
|
validator := Validator{
|
||||||
OperatorAddress: sdk.ValAddress(pk1.Address().Bytes()),
|
OperatorAddress: sdk.ValAddress(pk1.Address().Bytes()),
|
||||||
ConsPubKey: pk1,
|
ConsensusPubkey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, pk1),
|
||||||
Status: sdk.Bonded,
|
Status: sdk.Bonded,
|
||||||
Tokens: sdk.NewInt(2159),
|
Tokens: sdk.NewInt(2159),
|
||||||
DelegatorShares: delShares,
|
DelegatorShares: delShares,
|
||||||
|
@ -276,38 +274,6 @@ func TestValidatorSetInitialCommission(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidatorMarshalYAML(t *testing.T) {
|
|
||||||
validator := NewValidator(valAddr1, pk1, Description{})
|
|
||||||
bechifiedPub, err := sdk.Bech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, validator.ConsPubKey)
|
|
||||||
require.NoError(t, err)
|
|
||||||
bs, err := yaml.Marshal(validator)
|
|
||||||
require.NoError(t, err)
|
|
||||||
want := fmt.Sprintf(`|
|
|
||||||
operatoraddress: %s
|
|
||||||
conspubkey: %s
|
|
||||||
jailed: false
|
|
||||||
status: 0
|
|
||||||
tokens: "0"
|
|
||||||
delegatorshares: "0.000000000000000000"
|
|
||||||
description:
|
|
||||||
moniker: ""
|
|
||||||
identity: ""
|
|
||||||
website: ""
|
|
||||||
security_contact: ""
|
|
||||||
details: ""
|
|
||||||
unbondingheight: 0
|
|
||||||
unbondingcompletiontime: 1970-01-01T00:00:00Z
|
|
||||||
commission:
|
|
||||||
commission_rates:
|
|
||||||
rate: "0.000000000000000000"
|
|
||||||
max_rate: "0.000000000000000000"
|
|
||||||
max_change_rate: "0.000000000000000000"
|
|
||||||
update_time: 1970-01-01T00:00:00Z
|
|
||||||
minselfdelegation: "1"
|
|
||||||
`, validator.OperatorAddress.String(), bechifiedPub)
|
|
||||||
require.Equal(t, want, string(bs))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check that sort will create deterministic ordering of validators
|
// Check that sort will create deterministic ordering of validators
|
||||||
func TestValidatorsSortDeterminism(t *testing.T) {
|
func TestValidatorsSortDeterminism(t *testing.T) {
|
||||||
vals := make([]Validator, 10)
|
vals := make([]Validator, 10)
|
||||||
|
|
Loading…
Reference in New Issue