0.39->0.40 CLI `migrate` command (#6839)

* WIP on BaseAccount protobuf pub_key

* WIP on BaseAccount.PubKey

* Migrate supply

* Change validator_slash_event

* Add evidence

* Add evidence to genutil migrate

* Fix lint

* Add println

* No _ in package name

* Add slashing migrate

* Add tests for slashing

* Add capacity to array

* stray fmt.Prinlnt

* WIP on BaseAccount pub key

* Put current types in v0_40

* Add evidence old types

* Remove useless impl

* Add RegisterInterface

* Add clientCtx to argument

* Register evidence interfaces

* Update PubKey

* Update Account

* Docs

* WIP on protobuf keys

* Use Type() and Bytes() in sr25519 pub key Equals

* Add tests

* Add few more tests

* Update other pub/priv key types Equals

* Fix PrivKey's Sign method

* Rename variables in tests

* Fix infinite recursive calls

* Use tm ed25519 keys

* Add Sign and VerifySignature tests

* Remove ed25519 and sr25519 references

* proto linting

* Add proto crypto file

* Implement some of the new multisig proto type methods

* Add tests for MultisigThresholdPubKey

* Add tests for pubkey pb/amino conversion functions

* Move crypto types.go and register new proto pubkeys

* Add missing pointer ref

* Address review comments

* panic in MultisigThresholdPubKey VerifySignature

* Fix compile errors

* Remove pk conversion in ante handler

* Use internal crypto.PubKey in multisig

* Add tests for MultisigThresholdPubKey VerifyMultisignature

* Only keep LegacyAminoMultisigThresholdPubKey and move to proto keys to v1

* Remove conversion functions and introduce internal PubKey type

* Override Amino marshaling for proto pubkeys

* Merge master

* Make proto-gen

* Start removal of old PubKeyMultisigThreshold references

* Fix tests

* Fix solomachine

* Fix ante handler tests

* Pull latest go-amino

* Remove ed25519

* Remove old secp256k1 PubKey and PrivKey

* Uncomment test case

* Fix linting issues

* More linting

* Revert tests keys values

* Add Amino overrides to proto keys

* Add pubkey test

* Fix tests

* Use threshold isntead of K

* Standardize Type

* Revert standardize types commit

* Fix build

* Fix lint

* Fix lint

* Add comment

* Register crypto.PubKey

* Add empty key in BuildSimTx

* Simplify proto names

* Unpack interfaces for signing desc

* Fix IBC tests?

* Format proto

* Use secp256k1 in ibc

* Fixed merge issues

* Uncomment tests

* Update x/ibc/testing/solomachine.go

* UnpackInterfaces for solomachine types

* Remove old multisig

* Add amino marshal for multisig

* Fix lint

* Correctly register amino

* One test left!

* Remove old struct

* Fix test

* Fix test

* Unpack into tmcrypto

* Remove old threshold pubkey tests

* Fix register amino

* Fix lint

* Use sdk crypto PubKey in multisig UnpackInterfaces

* Potential fix?

* Register LegacyAminoPubKey

* Register our own PubKey

* Register tmcrypto PubKey

* Register both PubKeys

* Register interfaces in test

* Refactor fiels

* Add comments

* Remove old cosmos-sdk/crypto/keys reference

* Use anil's suggestion

* Add norace back

* Use our own ed25519

* Fix pubkey types

* Fix network tests

* Fix more tests

* Make ibc work?

* Use TM pubkey in NewValidator

* Fix lint

* Put interface in tpyes

* rerun CI

* Better name register

* Remove stray code

* Add ed25519 tests

* Check nil

* Correct interface impl assert

* rerun CI

* Add fix for Bech32

* Address comments

* FIx lint

* Add tests for solomachine unpack interfaces

* Fix query tx by hash

* Better name in amino register

* Fix lint

* Add back ed25519 test (fixes #7352)

* go mod tidy

* Fix merge issues

* Sort import

* Add test for backwards-compatibility

* Fix tests

* Fix merge issue

* Fix merge issues

* Fix tests build

* Fix tests

* Marshal to proto

* Fix 040 marshalling

* Remove dontcover

* Fix equivocation

* Add vesting

* Fix vesting

* Fix slashing test

* Fix evidence test

* Remove pb.go files

* Fix legacy auth tests

* deterministic tests help

* Fix auth tests

* Remove useless code

* Small cleanups

* Add comment

* Fix migrate hub

* fmt.Println

* No need to marshal indent

* Update proto comment

* Fix merge issues

* Support nil pubkey

* Use protobuf empty

* Address comments

* Fix tests

* Unify legacy package names

Co-authored-by: Aaron Craelius <aaronc@users.noreply.github.com>
Co-authored-by: Aaron Craelius <aaron@regen.network>
Co-authored-by: blushi <marie.gauthier63@gmail.com>
Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
Co-authored-by: Zaki Manian <zaki@manian.org>
Co-authored-by: Alessio Treglia <alessio@tendermint.com>
This commit is contained in:
Amaury Martiny 2020-10-05 23:28:14 +02:00 committed by GitHub
parent 6fa8330c31
commit d9ede6551a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
64 changed files with 1269 additions and 520 deletions

View File

@ -107,8 +107,8 @@ message ValidatorSlashEventRecord {
uint64 height = 2;
// period is the period of the slash event.
uint64 period = 3;
// event describes the slash event.
ValidatorSlashEvent event = 4 [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"event\""];
// validator_slash_event describes the slash event.
ValidatorSlashEvent validator_slash_event = 4 [(gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"event\""];
}
// GenesisState defines the distribution module's genesis state.

View File

@ -1,6 +1,6 @@
// DONTCOVER
// nolint
package v0_34
package v034
import (
sdk "github.com/cosmos/cosmos-sdk/types"

View File

@ -1,9 +1,9 @@
// DONTCOVER
// nolint
package v0_36
package v036
import (
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_34"
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v034"
)
// Migrate accepts exported genesis state from v0.34 and migrates it to v0.36

View File

@ -1,10 +1,10 @@
package v0_36
package v036
import (
"testing"
"github.com/cosmos/cosmos-sdk/types"
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_34"
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v034"
"github.com/stretchr/testify/require"
)

View File

@ -1,8 +1,8 @@
// DONTCOVER
// nolint
package v0_36
package v036
import v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_34"
import v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v034"
const (
ModuleName = "auth"

View File

@ -1,8 +1,8 @@
package v038
import (
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_36"
v036genaccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v0_36"
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v036"
v036genaccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v036"
)
// Migrate accepts exported genesis state from v0.34 and migrates it to v0.38

View File

@ -5,9 +5,9 @@ import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_34"
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_36"
v036genaccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v0_36"
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v034"
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v036"
v036genaccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v036"
"github.com/stretchr/testify/require"
)
@ -102,30 +102,6 @@ func TestMigrateInvalid(t *testing.T) {
name string
acc v036genaccounts.GenesisAccount
}{
{
"vesting account with no base coins",
v036genaccounts.GenesisAccount{
Address: accAddressFromBech32(t, "cosmos17n9sztlhx32tfy0tg0zc2ttmkeeth50yyuv9he"),
Coins: sdk.Coins{},
OriginalVesting: sdk.NewCoins(sdk.NewInt64Coin("stake", 10000205)),
StartTime: time.Now().Unix(),
EndTime: time.Now().Add(48 * time.Hour).Unix(),
Sequence: 5,
AccountNumber: 3,
},
},
{
"vesting account with base coins <= original vesting",
v036genaccounts.GenesisAccount{
Address: accAddressFromBech32(t, "cosmos17n9sztlhx32tfy0tg0zc2ttmkeeth50yyuv9he"),
Coins: sdk.NewCoins(sdk.NewInt64Coin("stake", 10000205)),
OriginalVesting: sdk.NewCoins(sdk.NewInt64Coin("stake", 50000205)),
StartTime: time.Now().Unix(),
EndTime: time.Now().Add(48 * time.Hour).Unix(),
Sequence: 5,
AccountNumber: 3,
},
},
{
"module account with invalid name",
v036genaccounts.GenesisAccount{

View File

@ -15,7 +15,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_34"
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v034"
)
const (
@ -223,11 +223,6 @@ func NewBaseVestingAccount(
}
func (bva BaseVestingAccount) Validate() error {
if (bva.Coins.IsZero() && !bva.OriginalVesting.IsZero()) ||
bva.OriginalVesting.IsAnyGT(bva.Coins) {
return errors.New("vesting amount cannot be greater than total amount")
}
return bva.BaseAccount.Validate()
}

View File

@ -3,7 +3,7 @@ package v039
import (
"fmt"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_38"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v038"
)
// Migrate accepts exported genesis state from v0.38 and migrates it to v0.39

View File

@ -14,8 +14,8 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/legacy"
sdk "github.com/cosmos/cosmos-sdk/types"
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_34"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_38"
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v034"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v038"
)
const (
@ -204,11 +204,6 @@ func (bva BaseVestingAccount) GetEndTime() int64 {
}
func (bva BaseVestingAccount) Validate() error {
if (bva.Coins.IsZero() && !bva.OriginalVesting.IsZero()) ||
bva.OriginalVesting.IsAnyGT(bva.Coins) {
return errors.New("vesting amount cannot be greater than total amount")
}
return bva.BaseAccount.Validate()
}

View File

@ -0,0 +1,133 @@
package v040
import (
pt "github.com/gogo/protobuf/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v039"
"github.com/cosmos/cosmos-sdk/x/auth/tx"
v040auth "github.com/cosmos/cosmos-sdk/x/auth/types"
v040vesting "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
)
// convertBaseAccount converts a 0.39 BaseAccount to a 0.40 BaseAccount.
func convertBaseAccount(old *v039auth.BaseAccount) *v040auth.BaseAccount {
// In `x/auth/legacy/v038/migrate.go`, when creating a BaseAccount, we
// explicitly set the PublicKey field to nil. This propagates until 0.40,
// and we don't know the PubKey for those accounts, so we just put an empty
// string inside the Any.
var any *codectypes.Any
var err error
if old.PubKey != nil {
any, err = tx.PubKeyToAny(old.PubKey)
} else {
s := pt.Empty{}
any, err = codectypes.NewAnyWithValue(&s)
}
if err != nil {
panic(err)
}
return &v040auth.BaseAccount{
Address: old.Address.String(),
PubKey: any,
AccountNumber: old.AccountNumber,
Sequence: old.Sequence,
}
}
// convertBaseVestingAccount converts a 0.39 BaseVestingAccount to a 0.40 BaseVestingAccount.
func convertBaseVestingAccount(old *v039auth.BaseVestingAccount) *v040vesting.BaseVestingAccount {
baseAccount := convertBaseAccount(old.BaseAccount)
return &v040vesting.BaseVestingAccount{
BaseAccount: baseAccount,
OriginalVesting: old.OriginalVesting,
DelegatedFree: old.DelegatedFree,
DelegatedVesting: old.DelegatedVesting,
EndTime: old.EndTime,
}
}
// Migrate accepts exported x/auth genesis state from v0.38/v0.39 and migrates
// it to v0.40 x/auth genesis state. The migration includes:
//
// - Removing coins from account encoding.
func Migrate(authGenState v039auth.GenesisState) *v040auth.GenesisState {
// Convert v0.39 accounts to v0.40 ones.
var v040Accounts = make([]v040auth.GenesisAccount, len(authGenState.Accounts))
for i, v039Account := range authGenState.Accounts {
switch v039Account := v039Account.(type) {
case *v039auth.BaseAccount:
{
v040Accounts[i] = convertBaseAccount(v039Account)
}
case *v039auth.ModuleAccount:
{
v040Accounts[i] = &v040auth.ModuleAccount{
BaseAccount: convertBaseAccount(v039Account.BaseAccount),
Name: v039Account.Name,
Permissions: v039Account.Permissions,
}
}
case *v039auth.BaseVestingAccount:
{
v040Accounts[i] = convertBaseVestingAccount(v039Account)
}
case *v039auth.ContinuousVestingAccount:
{
v040Accounts[i] = &v040vesting.ContinuousVestingAccount{
BaseVestingAccount: convertBaseVestingAccount(v039Account.BaseVestingAccount),
StartTime: v039Account.StartTime,
}
}
case *v039auth.DelayedVestingAccount:
{
v040Accounts[i] = &v040vesting.DelayedVestingAccount{
BaseVestingAccount: convertBaseVestingAccount(v039Account.BaseVestingAccount),
}
}
case *v039auth.PeriodicVestingAccount:
{
vestingPeriods := make([]v040vesting.Period, len(v039Account.VestingPeriods))
for j, period := range v039Account.VestingPeriods {
vestingPeriods[j] = v040vesting.Period{
Length: period.Length,
Amount: period.Amount,
}
}
v040Accounts[i] = &v040vesting.PeriodicVestingAccount{
BaseVestingAccount: convertBaseVestingAccount(v039Account.BaseVestingAccount),
StartTime: v039Account.StartTime,
VestingPeriods: vestingPeriods,
}
}
default:
panic(sdkerrors.Wrapf(sdkerrors.ErrInvalidType, "got invalid type %T", v039Account))
}
}
// Convert v0.40 accounts into Anys.
anys := make([]*codectypes.Any, len(v040Accounts))
for i, v040Account := range v040Accounts {
any, err := codectypes.NewAnyWithValue(v040Account)
if err != nil {
panic(err)
}
anys[i] = any
}
return &v040auth.GenesisState{
Params: v040auth.Params{
MaxMemoCharacters: authGenState.Params.MaxMemoCharacters,
TxSigLimit: authGenState.Params.TxSigLimit,
TxSizeCostPerByte: authGenState.Params.TxSizeCostPerByte,
SigVerifyCostED25519: authGenState.Params.SigVerifyCostED25519,
SigVerifyCostSecp256k1: authGenState.Params.SigVerifyCostSecp256k1,
},
Accounts: anys,
}
}

View File

@ -0,0 +1,258 @@
package v040_test
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
v034 "github.com/cosmos/cosmos-sdk/x/auth/legacy/v034"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v038"
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v039"
v040auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v040"
)
func TestMigrate(t *testing.T) {
encodingConfig := simapp.MakeEncodingConfig()
clientCtx := client.Context{}.
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TxConfig).
WithLegacyAmino(encodingConfig.Amino).
WithJSONMarshaler(encodingConfig.Marshaler)
coins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50))
// BaseAccount
pk1 := secp256k1.GenPrivKeyFromSecret([]byte("acc1")).PubKey()
acc1 := v039auth.NewBaseAccount(sdk.AccAddress(pk1.Address()), coins, pk1, 1, 0)
// ModuleAccount
pk2 := secp256k1.GenPrivKeyFromSecret([]byte("acc2")).PubKey()
acc2 := v039auth.NewModuleAccount(
v039auth.NewBaseAccount(sdk.AccAddress(pk2.Address()), coins, pk2, 1, 0),
"module2",
"permission2",
)
// BaseVestingAccount
pk3 := secp256k1.GenPrivKeyFromSecret([]byte("acc3")).PubKey()
acc3 := v039auth.NewBaseVestingAccount(
v039auth.NewBaseAccount(sdk.AccAddress(pk3.Address()), coins, pk3, 1, 0),
coins, coins, coins,
1580309973,
)
// ContinuousVestingAccount
pk4 := secp256k1.GenPrivKeyFromSecret([]byte("acc4")).PubKey()
acc4 := v039auth.NewContinuousVestingAccountRaw(
v039auth.NewBaseVestingAccount(v039auth.NewBaseAccount(sdk.AccAddress(pk4.Address()), coins, pk4, 1, 0), coins, nil, nil, 3160620846),
1580309974,
)
// PeriodicVestingAccount
pk5 := secp256k1.GenPrivKeyFromSecret([]byte("acc5")).PubKey()
acc5 := &v039auth.PeriodicVestingAccount{
BaseVestingAccount: v039auth.NewBaseVestingAccount(v039auth.NewBaseAccount(sdk.AccAddress(pk5.Address()), coins, pk5, 1, 0), coins, nil, nil, 3160620846),
StartTime: 1580309975,
VestingPeriods: v039auth.Periods{v039auth.Period{Length: 32, Amount: coins}},
}
// DelayedVestingAccount
pk6 := secp256k1.GenPrivKeyFromSecret([]byte("acc6")).PubKey()
acc6 := &v039auth.DelayedVestingAccount{
BaseVestingAccount: v039auth.NewBaseVestingAccount(v039auth.NewBaseAccount(sdk.AccAddress(pk6.Address()), coins, pk6, 1, 0), coins, nil, nil, 3160620846),
}
// BaseAccount with nil pubkey (coming from older genesis).
pk7 := secp256k1.GenPrivKeyFromSecret([]byte("acc7")).PubKey()
acc7 := v039auth.NewBaseAccount(sdk.AccAddress(pk7.Address()), coins, nil, 1, 0)
gs := v039auth.GenesisState{
Params: v034.Params{
MaxMemoCharacters: 10,
TxSigLimit: 20,
TxSizeCostPerByte: 30,
SigVerifyCostED25519: 40,
SigVerifyCostSecp256k1: 50,
},
Accounts: v038auth.GenesisAccounts{acc1, acc2, acc3, acc4, acc5, acc6, acc7},
}
migrated := v040auth.Migrate(gs)
expected := `{
"accounts": [
{
"@type": "/cosmos.auth.v1beta1.BaseAccount",
"account_number": "1",
"address": "cosmos13syh7de9xndv9wmklccpfvc0d8dcyvay4s6z6l",
"pub_key": {
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "A8oWyJkohwy8XZ0Df92jFMBTtTPMvYJplYIrlEHTKPYk"
},
"sequence": "0"
},
{
"@type": "/cosmos.auth.v1beta1.ModuleAccount",
"base_account": {
"account_number": "1",
"address": "cosmos1v57fx2l2rt6ehujuu99u2fw05779m5e2ux4z2h",
"pub_key": {
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "AruDygh5HprMOpHOEato85dLgAsybMJVyxBGUa3KuWCr"
},
"sequence": "0"
},
"name": "module2",
"permissions": [
"permission2"
]
},
{
"@type": "/cosmos.vesting.v1beta1.BaseVestingAccount",
"base_account": {
"account_number": "1",
"address": "cosmos18hnp9fjflrkeeqn4gmhjhzljusxzmjeartdckw",
"pub_key": {
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "A5aEFDIdQHh0OYmNXNv1sHBNURDWWgVkXC2IALcWLLwJ"
},
"sequence": "0"
},
"delegated_free": [
{
"amount": "50",
"denom": "stake"
}
],
"delegated_vesting": [
{
"amount": "50",
"denom": "stake"
}
],
"end_time": "1580309973",
"original_vesting": [
{
"amount": "50",
"denom": "stake"
}
]
},
{
"@type": "/cosmos.vesting.v1beta1.ContinuousVestingAccount",
"base_vesting_account": {
"base_account": {
"account_number": "1",
"address": "cosmos1t9kvvejvk6hjtddx6antck39s206csqduq3ke3",
"pub_key": {
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "AoXDzxwTnljemHxfnJcwrKqODBP6Q2l3K3U3UhVDzyah"
},
"sequence": "0"
},
"delegated_free": [],
"delegated_vesting": [],
"end_time": "3160620846",
"original_vesting": [
{
"amount": "50",
"denom": "stake"
}
]
},
"start_time": "1580309974"
},
{
"@type": "/cosmos.vesting.v1beta1.PeriodicVestingAccount",
"base_vesting_account": {
"base_account": {
"account_number": "1",
"address": "cosmos1s4ss9zquz7skvguechzlk3na635jdrecl0sgy2",
"pub_key": {
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "A2a4P4TQ1OKzpfu0eKnCoEtmTvoiclSx0G9higenUGws"
},
"sequence": "0"
},
"delegated_free": [],
"delegated_vesting": [],
"end_time": "3160620846",
"original_vesting": [
{
"amount": "50",
"denom": "stake"
}
]
},
"start_time": "1580309975",
"vesting_periods": [
{
"amount": [
{
"amount": "50",
"denom": "stake"
}
],
"length": "32"
}
]
},
{
"@type": "/cosmos.vesting.v1beta1.DelayedVestingAccount",
"base_vesting_account": {
"base_account": {
"account_number": "1",
"address": "cosmos1mcc6rwrj4hswf8p9ct82c7lmf77w9tuk07rha4",
"pub_key": {
"@type": "/cosmos.crypto.secp256k1.PubKey",
"key": "A4tuAfmZlhjK5cjp6ImR704miybHnITVNOyJORdDPFu3"
},
"sequence": "0"
},
"delegated_free": [],
"delegated_vesting": [],
"end_time": "3160620846",
"original_vesting": [
{
"amount": "50",
"denom": "stake"
}
]
}
},
{
"@type": "/cosmos.auth.v1beta1.BaseAccount",
"account_number": "1",
"address": "cosmos16ydaqh0fcnh4qt7a3jme4mmztm2qel5axcpw00",
"pub_key": {
"@type": "/google.protobuf.Empty",
"value": {}
},
"sequence": "0"
}
],
"params": {
"max_memo_characters": "10",
"sig_verify_cost_ed25519": "40",
"sig_verify_cost_secp256k1": "50",
"tx_sig_limit": "20",
"tx_size_cost_per_byte": "30"
}
}`
bz, err := clientCtx.JSONMarshaler.MarshalJSON(migrated)
require.NoError(t, err)
// Indent the JSON bz correctly.
var jsonObj map[string]interface{}
err = json.Unmarshal(bz, &jsonObj)
require.NoError(t, err)
indentedBz, err := json.MarshalIndent(jsonObj, "", " ")
require.NoError(t, err)
require.Equal(t, expected, string(indentedBz))
}

View File

@ -1,8 +1,5 @@
package v040
// DONTCOVER
// nolint
const (
ModuleName = "auth"
)

View File

@ -1,24 +0,0 @@
package v040
import (
"fmt"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_38"
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_39"
)
// Migrate accepts exported x/auth genesis state from v0.38/v0.39 and migrates
// it to v0.40 x/auth genesis state. The migration includes:
//
// - Removing coins from account encoding.
func Migrate(authGenState v039auth.GenesisState) v039auth.GenesisState {
for _, account := range authGenState.Accounts {
// set coins to nil and allow the JSON encoding to omit coins
if err := account.SetCoins(nil); err != nil {
panic(fmt.Sprintf("failed to set account coins to nil: %s", err))
}
}
authGenState.Accounts = v038auth.SanitizeGenesisAccounts(authGenState.Accounts)
return authGenState
}

View File

@ -1,87 +0,0 @@
package v040_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_34"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_38"
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_39"
v040 "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_40"
)
func TestMigrate(t *testing.T) {
v039Codec := codec.NewLegacyAmino()
cryptocodec.RegisterCrypto(v039Codec)
v039auth.RegisterLegacyAminoCodec(v039Codec)
coins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50))
addr1, _ := sdk.AccAddressFromBech32("cosmos1xxkueklal9vejv9unqu80w9vptyepfa95pd53u")
acc1 := v039auth.NewBaseAccount(addr1, coins, nil, 1, 0)
addr2, _ := sdk.AccAddressFromBech32("cosmos15v50ymp6n5dn73erkqtmq0u8adpl8d3ujv2e74")
vaac := v039auth.NewContinuousVestingAccountRaw(
v039auth.NewBaseVestingAccount(v039auth.NewBaseAccount(addr2, coins, nil, 1, 0), coins, nil, nil, 3160620846),
1580309972,
)
gs := v039auth.GenesisState{
Params: v0_34.Params{
MaxMemoCharacters: 10,
TxSigLimit: 10,
TxSizeCostPerByte: 10,
SigVerifyCostED25519: 10,
SigVerifyCostSecp256k1: 10,
},
Accounts: v038auth.GenesisAccounts{acc1, vaac},
}
migrated := v040.Migrate(gs)
expected := `{
"params": {
"max_memo_characters": "10",
"tx_sig_limit": "10",
"tx_size_cost_per_byte": "10",
"sig_verify_cost_ed25519": "10",
"sig_verify_cost_secp256k1": "10"
},
"accounts": [
{
"type": "cosmos-sdk/Account",
"value": {
"address": "cosmos1xxkueklal9vejv9unqu80w9vptyepfa95pd53u",
"public_key": null,
"account_number": "1",
"sequence": "0"
}
},
{
"type": "cosmos-sdk/ContinuousVestingAccount",
"value": {
"address": "cosmos15v50ymp6n5dn73erkqtmq0u8adpl8d3ujv2e74",
"public_key": null,
"account_number": "1",
"sequence": "0",
"original_vesting": [
{
"denom": "stake",
"amount": "50"
}
],
"delegated_free": [],
"delegated_vesting": [],
"end_time": "3160620846",
"start_time": "1580309972"
}
}
]
}`
bz, err := v039Codec.MarshalJSONIndent(migrated, "", " ")
require.NoError(t, err)
require.Equal(t, expected, string(bz))
}

View File

@ -18,10 +18,11 @@ import (
)
var (
_ AccountI = (*BaseAccount)(nil)
_ GenesisAccount = (*BaseAccount)(nil)
_ GenesisAccount = (*ModuleAccount)(nil)
_ ModuleAccountI = (*ModuleAccount)(nil)
_ AccountI = (*BaseAccount)(nil)
_ GenesisAccount = (*BaseAccount)(nil)
_ codectypes.UnpackInterfacesMessage = (*BaseAccount)(nil)
_ GenesisAccount = (*ModuleAccount)(nil)
_ ModuleAccountI = (*ModuleAccount)(nil)
)
// NewBaseAccount creates a new BaseAccount object

View File

@ -1,6 +1,6 @@
// DONTCOVER
// nolint
package v0_36
package v036
import (
sdk "github.com/cosmos/cosmos-sdk/types"

View File

@ -0,0 +1,37 @@
package v040
import (
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v039"
v036supply "github.com/cosmos/cosmos-sdk/x/bank/legacy/v036"
v038bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v038"
v040bank "github.com/cosmos/cosmos-sdk/x/bank/types"
)
// Migrate accepts exported v0.39 x/auth and v0.38 x/bank genesis state and
// migrates it to v0.40 x/bank genesis state. The migration includes:
//
// - Moving balances from x/auth to x/bank genesis state.
// - Moving supply from x/supply to x/bank genesis state.
func Migrate(
bankGenState v038bank.GenesisState,
authGenState v039auth.GenesisState,
supplyGenState v036supply.GenesisState,
) *v040bank.GenesisState {
balances := make([]v040bank.Balance, len(authGenState.Accounts))
for i, acc := range authGenState.Accounts {
balances[i] = v040bank.Balance{
Address: acc.GetAddress().String(),
Coins: acc.GetCoins(),
}
}
return &v040bank.GenesisState{
Params: v040bank.Params{
SendEnabled: []*v040bank.SendEnabled{},
DefaultSendEnabled: bankGenState.SendEnabled,
},
Balances: balances,
Supply: supplyGenState.Supply,
DenomMetadata: []v040bank.Metadata{},
}
}

View File

@ -0,0 +1,56 @@
package v040_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v038"
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v039"
v036supply "github.com/cosmos/cosmos-sdk/x/bank/legacy/v036"
v038bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v038"
v040bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v040"
)
func TestMigrate(t *testing.T) {
encodingConfig := simapp.MakeEncodingConfig()
clientCtx := client.Context{}.
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TxConfig).
WithLegacyAmino(encodingConfig.Amino).
WithJSONMarshaler(encodingConfig.Marshaler)
coins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50))
addr1, _ := sdk.AccAddressFromBech32("cosmos1xxkueklal9vejv9unqu80w9vptyepfa95pd53u")
acc1 := v038auth.NewBaseAccount(addr1, coins, nil, 1, 0)
addr2, _ := sdk.AccAddressFromBech32("cosmos15v50ymp6n5dn73erkqtmq0u8adpl8d3ujv2e74")
vaac := v038auth.NewContinuousVestingAccountRaw(
v038auth.NewBaseVestingAccount(
v038auth.NewBaseAccount(addr2, coins, nil, 1, 0), coins, nil, nil, 3160620846,
),
1580309972,
)
supply := sdk.NewCoins(sdk.NewInt64Coin("stake", 1000))
bankGenState := v038bank.GenesisState{
SendEnabled: true,
}
authGenState := v039auth.GenesisState{
Accounts: v038auth.GenesisAccounts{acc1, vaac},
}
supplyGenState := v036supply.GenesisState{
Supply: supply,
}
migrated := v040bank.Migrate(bankGenState, authGenState, supplyGenState)
expected := `{"params":{"send_enabled":[],"default_send_enabled":true},"balances":[{"address":"cosmos1xxkueklal9vejv9unqu80w9vptyepfa95pd53u","coins":[{"denom":"stake","amount":"50"}]},{"address":"cosmos15v50ymp6n5dn73erkqtmq0u8adpl8d3ujv2e74","coins":[{"denom":"stake","amount":"50"}]}],"supply":[{"denom":"stake","amount":"1000"}],"denom_metadata":[]}`
bz, err := clientCtx.JSONMarshaler.MarshalJSON(migrated)
require.NoError(t, err)
require.Equal(t, expected, string(bz))
}

View File

@ -0,0 +1,5 @@
package v040
const (
ModuleName = "bank"
)

View File

@ -1,22 +0,0 @@
package v040
import (
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_39"
v038bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v0_38"
)
// Migrate accepts exported v0.39 x/auth and v0.38 x/bank genesis state and
// migrates it to v0.40 x/bank genesis state. The migration includes:
//
// - Moving balances from x/auth to x/bank genesis state.
func Migrate(bankGenState v038bank.GenesisState, authGenState v039auth.GenesisState) GenesisState {
balances := make([]Balance, len(authGenState.Accounts))
for i, acc := range authGenState.Accounts {
balances[i] = Balance{
Address: acc.GetAddress(),
Coins: acc.GetCoins(),
}
}
return NewGenesisState(bankGenState.SendEnabled, balances)
}

View File

@ -1,69 +0,0 @@
package v040_test
import (
"testing"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_38"
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_39"
v038bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v0_38"
v040bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v0_40"
"github.com/stretchr/testify/require"
)
func TestMigrate(t *testing.T) {
v040Codec := codec.NewLegacyAmino()
cryptocodec.RegisterCrypto(v040Codec)
v039auth.RegisterLegacyAminoCodec(v040Codec)
coins := sdk.NewCoins(sdk.NewInt64Coin("stake", 50))
addr1, _ := sdk.AccAddressFromBech32("cosmos1xxkueklal9vejv9unqu80w9vptyepfa95pd53u")
acc1 := v038auth.NewBaseAccount(addr1, coins, nil, 1, 0)
addr2, _ := sdk.AccAddressFromBech32("cosmos15v50ymp6n5dn73erkqtmq0u8adpl8d3ujv2e74")
vaac := v038auth.NewContinuousVestingAccountRaw(
v038auth.NewBaseVestingAccount(
v038auth.NewBaseAccount(addr2, coins, nil, 1, 0), coins, nil, nil, 3160620846,
),
1580309972,
)
bankGenState := v038bank.GenesisState{
SendEnabled: true,
}
authGenState := v039auth.GenesisState{
Accounts: v038auth.GenesisAccounts{acc1, vaac},
}
migrated := v040bank.Migrate(bankGenState, authGenState)
expected := `{
"send_enabled": true,
"balances": [
{
"address": "cosmos1xxkueklal9vejv9unqu80w9vptyepfa95pd53u",
"coins": [
{
"denom": "stake",
"amount": "50"
}
]
},
{
"address": "cosmos15v50ymp6n5dn73erkqtmq0u8adpl8d3ujv2e74",
"coins": [
{
"denom": "stake",
"amount": "50"
}
]
}
]
}`
bz, err := v040Codec.MarshalJSONIndent(migrated, "", " ")
require.NoError(t, err)
require.Equal(t, expected, string(bz))
}

View File

@ -1,43 +0,0 @@
package v040
// DONTCOVER
// nolint
import (
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
ModuleName = "bank"
)
var _ GenesisBalance = (*Balance)(nil)
type (
GenesisBalance interface {
GetAddress() sdk.AccAddress
GetCoins() sdk.Coins
}
GenesisState struct {
SendEnabled bool `json:"send_enabled" yaml:"send_enabled"`
Balances []Balance `json:"balances" yaml:"balances"`
}
Balance struct {
Address sdk.AccAddress `json:"address" yaml:"address"`
Coins sdk.Coins `json:"coins" yaml:"coins"`
}
)
func NewGenesisState(sendEnabled bool, balances []Balance) GenesisState {
return GenesisState{SendEnabled: sendEnabled, Balances: balances}
}
func (b Balance) GetAddress() sdk.AccAddress {
return b.Address
}
func (b Balance) GetCoins() sdk.Coins {
return b.Coins
}

View File

@ -83,7 +83,7 @@ func (k Keeper) InitGenesis(ctx sdk.Context, data types.GenesisState) {
if err != nil {
panic(err)
}
k.SetValidatorSlashEvent(ctx, valAddr, evt.Height, evt.Period, evt.Event)
k.SetValidatorSlashEvent(ctx, valAddr, evt.Height, evt.Period, evt.ValidatorSlashEvent)
}
moduleHoldings = moduleHoldings.Add(data.FeePool.CommunityPool...)
@ -182,10 +182,10 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState {
k.IterateValidatorSlashEvents(ctx,
func(val sdk.ValAddress, height uint64, event types.ValidatorSlashEvent) (stop bool) {
slashes = append(slashes, types.ValidatorSlashEventRecord{
ValidatorAddress: val.String(),
Height: height,
Period: event.ValidatorPeriod,
Event: event,
ValidatorAddress: val.String(),
Height: height,
Period: event.ValidatorPeriod,
ValidatorSlashEvent: event,
})
return false
},

View File

@ -1,6 +1,6 @@
// DONTCOVER
// nolint
package v0_34
package v034
import (
sdk "github.com/cosmos/cosmos-sdk/types"

View File

@ -1,7 +1,7 @@
package v0_36
package v036
import (
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_34"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v034"
)
// Migrate accepts exported genesis state from v0.34 and migrates it to v0.36

View File

@ -1,11 +1,11 @@
package v0_36
package v036
import (
"testing"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/types"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_34"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v034"
"github.com/stretchr/testify/require"
)

View File

@ -1,10 +1,10 @@
// DONTCOVER
// nolint
package v0_36
package v036
import (
sdk "github.com/cosmos/cosmos-sdk/types"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_34"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v034"
)
// ----------------------------------------------------------------------------

View File

@ -1,10 +1,10 @@
package v0_38
package v038
// DONTCOVER
// nolint
import (
v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_36"
v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v036"
)
// Migrate accepts exported genesis state from v0.36 or v0.37 and migrates it to

View File

@ -1,9 +1,9 @@
package v0_38
package v038
import (
sdk "github.com/cosmos/cosmos-sdk/types"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_34"
v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_36"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v034"
v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v036"
)
// DONTCOVER

View File

@ -5,7 +5,6 @@ package types
import (
fmt "fmt"
github_com_cosmos_cosmos_sdk_types "github.com/cosmos/cosmos-sdk/types"
types "github.com/cosmos/cosmos-sdk/types"
_ "github.com/gogo/protobuf/gogoproto"
proto "github.com/gogo/protobuf/proto"
@ -73,7 +72,7 @@ type ValidatorOutstandingRewardsRecord struct {
// validator_address is the address of the validator.
ValidatorAddress string `protobuf:"bytes,1,opt,name=validator_address,json=validatorAddress,proto3" json:"validator_address,omitempty" yaml:"validator_address"`
// outstanding_rewards represents the oustanding rewards of a validator.
OutstandingRewards github_com_cosmos_cosmos_sdk_types.DecCoins `protobuf:"bytes,2,rep,name=outstanding_rewards,json=outstandingRewards,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.DecCoins" json:"outstanding_rewards" yaml:"outstanding_rewards"`
OutstandingRewards []types.DecCoin `protobuf:"bytes,2,rep,name=outstanding_rewards,json=outstandingRewards,proto3" json:"outstanding_rewards" yaml:"outstanding_rewards"`
}
func (m *ValidatorOutstandingRewardsRecord) Reset() { *m = ValidatorOutstandingRewardsRecord{} }
@ -287,8 +286,8 @@ type ValidatorSlashEventRecord struct {
Height uint64 `protobuf:"varint,2,opt,name=height,proto3" json:"height,omitempty"`
// period is the period of the slash event.
Period uint64 `protobuf:"varint,3,opt,name=period,proto3" json:"period,omitempty"`
// event describes the slash event.
Event ValidatorSlashEvent `protobuf:"bytes,4,opt,name=event,proto3" json:"event" yaml:"event"`
// validator_slash_event describes the slash event.
ValidatorSlashEvent ValidatorSlashEvent `protobuf:"bytes,4,opt,name=validator_slash_event,json=validatorSlashEvent,proto3" json:"validator_slash_event" yaml:"event"`
}
func (m *ValidatorSlashEventRecord) Reset() { *m = ValidatorSlashEventRecord{} }
@ -397,71 +396,71 @@ func init() {
}
var fileDescriptor_76eed0f9489db580 = []byte{
// 1022 bytes of a gzipped FileDescriptorProto
// 1024 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00,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bc,
0x79, 0x62, 0x83, 0x67, 0xa4, 0xf8, 0xf7, 0x2f, 0xb8, 0xb9, 0xb4, 0xf0, 0x7b, 0x5a, 0xf8, 0x9d,
0x41, 0xe1, 0xc3, 0x84, 0x10, 0x95, 0xfb, 0x23, 0xe1, 0xc2, 0x17, 0xb0, 0x9b, 0xc9, 0xd3, 0x9e,
0x5a, 0x23, 0xb1, 0xd6, 0x59, 0xa9, 0x75, 0xfb, 0x22, 0x3b, 0x48, 0x0b, 0xdd, 0xd0, 0x42, 0xd7,
0x07, 0x85, 0x0e, 0x50, 0x41, 0xb4, 0xd2, 0xcf, 0x07, 0x32, 0x9f, 0x64, 0x9a, 0x31, 0x33, 0x9f,
0x79, 0xe9, 0xaa, 0x54, 0xf8, 0xee, 0xf9, 0xe7, 0xbe, 0xd6, 0x37, 0xb2, 0x25, 0xb3, 0x3c, 0xe9,
0x96, 0x4c, 0xa3, 0xf0, 0xb0, 0x8f, 0x96, 0x73, 0x07, 0x2e, 0x2f, 0x01, 0xa9, 0xed, 0xed, 0xf3,
0x4e, 0x5c, 0xad, 0xec, 0x55, 0xad, 0xec, 0xd6, 0xa0, 0x73, 0x69, 0x0e, 0x88, 0x16, 0x73, 0x06,
0x71, 0x6a, 0xbf, 0x3b, 0x8f, 0x7f, 0x3a, 0xa9, 0x18, 0xcf, 0x4e, 0x2a, 0xc6, 0xf3, 0x93, 0x8a,
0xf1, 0xe7, 0x49, 0xc5, 0xf8, 0xee, 0xb4, 0x52, 0x78, 0x7e, 0x5a, 0x29, 0xfc, 0x76, 0x5a, 0x29,
0x7c, 0xb1, 0x39, 0xf6, 0xed, 0xf8, 0xab, 0xec, 0xef, 0x1d, 0xf9, 0xb2, 0x5c, 0x9f, 0x96, 0xbf,
0x70, 0xde, 0xfc, 0x37, 0x00, 0x00, 0xff, 0xff, 0xa8, 0xee, 0xfe, 0x4a, 0x91, 0x0d, 0x00, 0x00,
}
func (m *DelegatorWithdrawInfo) Marshal() (dAtA []byte, err error) {
@ -738,7 +737,7 @@ func (m *ValidatorSlashEventRecord) MarshalToSizedBuffer(dAtA []byte) (int, erro
var l int
_ = l
{
size, err := m.Event.MarshalToSizedBuffer(dAtA[:i])
size, err := m.ValidatorSlashEvent.MarshalToSizedBuffer(dAtA[:i])
if err != nil {
return 0, err
}
@ -1045,7 +1044,7 @@ func (m *ValidatorSlashEventRecord) Size() (n int) {
if m.Period != 0 {
n += 1 + sovGenesis(uint64(m.Period))
}
l = m.Event.Size()
l = m.ValidatorSlashEvent.Size()
n += 1 + l + sovGenesis(uint64(l))
return n
}
@ -1975,7 +1974,7 @@ func (m *ValidatorSlashEventRecord) Unmarshal(dAtA []byte) error {
}
case 4:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Event", wireType)
return fmt.Errorf("proto: wrong wireType = %d for field ValidatorSlashEvent", wireType)
}
var msglen int
for shift := uint(0); ; shift += 7 {
@ -2002,7 +2001,7 @@ func (m *ValidatorSlashEventRecord) Unmarshal(dAtA []byte) error {
if postIndex > l {
return io.ErrUnexpectedEOF
}
if err := m.Event.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
if err := m.ValidatorSlashEvent.Unmarshal(dAtA[iNdEx:postIndex]); err != nil {
return err
}
iNdEx = postIndex

View File

@ -1,9 +1,9 @@
package exported
import (
sdk "github.com/cosmos/cosmos-sdk/types"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Evidence defines the contract which concrete evidence types of misbehavior

View File

@ -0,0 +1,113 @@
package v038
import (
"fmt"
"time"
"github.com/tendermint/tendermint/crypto/tmhash"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
"gopkg.in/yaml.v2"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Default parameter values
const (
ModuleName = "evidence"
DefaultParamspace = ModuleName
DefaultMaxEvidenceAge = 60 * 2 * time.Second
)
// Evidence type constants
const (
RouteEquivocation = "equivocation"
TypeEquivocation = "equivocation"
)
var (
amino = codec.NewLegacyAmino()
// ModuleCdc references the global x/evidence module codec. Note, the codec should
// ONLY be used in certain instances of tests and for JSON encoding as Amino is
// still used for that purpose.
//
// The actual codec used for serialization should be provided to x/evidence and
// defined at the application level.
ModuleCdc = codec.NewAminoCodec(amino)
)
// Evidence defines the contract which concrete evidence types of misbehavior
// must implement.
type Evidence interface {
Route() string
Type() string
String() string
Hash() tmbytes.HexBytes
ValidateBasic() error
// Height at which the infraction occurred
GetHeight() int64
}
// Params defines the total set of parameters for the evidence module
type Params struct {
MaxEvidenceAge time.Duration `json:"max_evidence_age" yaml:"max_evidence_age"`
}
// GenesisState defines the evidence module's genesis state.
type GenesisState struct {
Params Params `json:"params" yaml:"params"`
Evidence []Evidence `json:"evidence" yaml:"evidence"`
}
// Assert interface implementation.
var _ Evidence = Equivocation{}
// Equivocation implements the Evidence interface and defines evidence of double
// signing misbehavior.
type Equivocation struct {
Height int64 `json:"height" yaml:"height"`
Time time.Time `json:"time" yaml:"time"`
Power int64 `json:"power" yaml:"power"`
ConsensusAddress sdk.ConsAddress `json:"consensus_address" yaml:"consensus_address"`
}
// Route returns the Evidence Handler route for an Equivocation type.
func (e Equivocation) Route() string { return RouteEquivocation }
// Type returns the Evidence Handler type for an Equivocation type.
func (e Equivocation) Type() string { return TypeEquivocation }
func (e Equivocation) String() string {
bz, _ := yaml.Marshal(e)
return string(bz)
}
// Hash returns the hash of an Equivocation object.
func (e Equivocation) Hash() tmbytes.HexBytes {
return tmhash.Sum(ModuleCdc.LegacyAmino.MustMarshalBinaryBare(e))
}
// ValidateBasic performs basic stateless validation checks on an Equivocation object.
func (e Equivocation) ValidateBasic() error {
if e.Time.IsZero() {
return fmt.Errorf("invalid equivocation time: %s", e.Time)
}
if e.Height < 1 {
return fmt.Errorf("invalid equivocation height: %d", e.Height)
}
if e.Power < 1 {
return fmt.Errorf("invalid equivocation validator power: %d", e.Power)
}
if e.ConsensusAddress.Empty() {
return fmt.Errorf("invalid equivocation validator consensus address: %s", e.ConsensusAddress)
}
return nil
}
// GetHeight returns the height at time of the Equivocation infraction.
func (e Equivocation) GetHeight() int64 {
return e.Height
}

View File

@ -0,0 +1,46 @@
package v040
import (
"github.com/cosmos/cosmos-sdk/client"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
v038evidence "github.com/cosmos/cosmos-sdk/x/evidence/legacy/v038"
v040evidence "github.com/cosmos/cosmos-sdk/x/evidence/types"
)
// Migrate accepts exported v0.38 x/evidence genesis state and migrates it to
// v0.40 x/evidence genesis state. The migration includes:
//
// - Removing the `Params` field.
// - Converting Equivocations into Anys.
func Migrate(evidenceState v038evidence.GenesisState, _ client.Context) *v040evidence.GenesisState {
var newEquivocations = make([]v040evidence.Equivocation, len(evidenceState.Evidence))
for i, evidence := range evidenceState.Evidence {
equivocation, ok := evidence.(v038evidence.Equivocation)
if !ok {
// There's only equivocation in 0.38.
continue
}
newEquivocations[i] = v040evidence.Equivocation{
Height: equivocation.Height,
Time: equivocation.Time,
Power: equivocation.Power,
ConsensusAddress: equivocation.ConsensusAddress.String(),
}
}
// Then convert the equivocations into Any.
newEvidence := make([]*codectypes.Any, len(newEquivocations))
for i := range newEquivocations {
any, err := codectypes.NewAnyWithValue(&newEquivocations[i])
if err != nil {
panic(err)
}
newEvidence[i] = any
}
return &v040evidence.GenesisState{
Evidence: newEvidence,
}
}

View File

@ -0,0 +1,40 @@
package v040_test
import (
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
v038evidence "github.com/cosmos/cosmos-sdk/x/evidence/legacy/v038"
v040evidence "github.com/cosmos/cosmos-sdk/x/evidence/legacy/v040"
)
func TestMigrate(t *testing.T) {
encodingConfig := simapp.MakeEncodingConfig()
clientCtx := client.Context{}.
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TxConfig).
WithLegacyAmino(encodingConfig.Amino).
WithJSONMarshaler(encodingConfig.Marshaler)
addr1, _ := sdk.AccAddressFromBech32("cosmos1xxkueklal9vejv9unqu80w9vptyepfa95pd53u")
evidenceGenState := v038evidence.GenesisState{
Params: v038evidence.Params{MaxEvidenceAge: v038evidence.DefaultMaxEvidenceAge},
Evidence: []v038evidence.Evidence{v038evidence.Equivocation{
Height: 20,
Power: 100,
ConsensusAddress: addr1.Bytes(),
}},
}
migrated := v040evidence.Migrate(evidenceGenState, clientCtx)
expected := `{"evidence":[{"@type":"/cosmos.evidence.v1beta1.Equivocation","height":"20","time":"0001-01-01T00:00:00Z","power":"100","consensus_address":"cosmosvalcons1xxkueklal9vejv9unqu80w9vptyepfa99x2a3w"}]}`
bz, err := clientCtx.JSONMarshaler.MarshalJSON(migrated)
require.NoError(t, err)
require.Equal(t, expected, string(bz))
}

View File

@ -0,0 +1,6 @@
package v040
// Default parameter values
const (
ModuleName = "evidence"
)

View File

@ -6,7 +6,7 @@ The ADR can be found here: https://github.com/cosmos/cosmos-sdk/blob/master/docs
Genesis accounts that existed in the genesis application state under `app_state.accounts`
now exists under the x/auth module's genesis state under the `app_state.auth.accounts` key.
Migration can be performed via x/auth/legacy/v0_38/migrate.go. In addition, because genesis
Migration can be performed via x/auth/legacy/v038/migrate.go. In addition, because genesis
accounts are now generalized via an interface, it is now up to the application to
define the concrete types and the respective client logic to add them to a genesis
state/file. For an example implementation of the `add-genesis-account` command please

View File

@ -1,6 +1,6 @@
// DONTCOVER
// nolint
package v0_34
package v034
import (
sdk "github.com/cosmos/cosmos-sdk/types"

View File

@ -1,15 +1,15 @@
// DONTCOVER
// nolint
package v0_36
package v036
import (
"fmt"
sdk "github.com/cosmos/cosmos-sdk/types"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_34"
v034accounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v0_34"
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v0_34"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v034"
v034accounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v034"
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v034"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v034"
"github.com/tendermint/tendermint/crypto"
)

View File

@ -1,4 +1,4 @@
package v0_36
package v036
import (
"testing"
@ -7,10 +7,10 @@ import (
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
"github.com/cosmos/cosmos-sdk/types"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_34"
v034accounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v0_34"
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v0_34"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v034"
v034accounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v034"
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v034"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v034"
"github.com/stretchr/testify/require"
)

View File

@ -1,6 +1,6 @@
// DONTCOVER
// nolint
package v0_36
package v036
import (
sdk "github.com/cosmos/cosmos-sdk/types"

View File

@ -8,15 +8,17 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
tmjson "github.com/tendermint/tendermint/libs/json"
tmtypes "github.com/tendermint/tendermint/types"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
v036 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v0_36"
v038 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v0_38"
v039 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v0_39"
v040 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v0_40"
v036 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v036"
v038 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v038"
v039 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v039"
v040 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v040"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
)
@ -65,6 +67,8 @@ $ %s migrate v0.36 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2
`, version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)
var err error
target := args[0]
@ -86,7 +90,7 @@ $ %s migrate v0.36 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2
}
// TODO: handler error from migrationFunc call
newGenState := migrationFunc(initialState)
newGenState := migrationFunc(initialState, clientCtx)
genDoc.AppState, err = json.Marshal(newGenState)
if err != nil {
@ -110,7 +114,7 @@ $ %s migrate v0.36 /path/to/genesis.json --chain-id=cosmoshub-3 --genesis-time=2
genDoc.ChainID = chainID
}
bz, err := json.MarshalIndent(genDoc, "", " ")
bz, err := tmjson.Marshal(genDoc)
if err != nil {
return errors.Wrap(err, "failed to marshal genesis doc")
}

View File

@ -1,24 +1,25 @@
package v036
import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_34"
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_36"
v036bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v0_36"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_34"
v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_36"
v034genAccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v0_34"
v036genAccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v0_36"
v034auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v034"
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v036"
v036bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v036"
v034distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v034"
v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v036"
v034genAccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v034"
v036genAccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v036"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v0_34"
v036gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v0_36"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_36"
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v034"
v036gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v036"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v034"
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v036"
)
// Migrate migrates exported state from v0.34 to a v0.36 genesis state.
func Migrate(appState types.AppMap) types.AppMap {
func Migrate(appState types.AppMap, _ client.Context) types.AppMap {
v034Codec := codec.NewLegacyAmino()
cryptocodec.RegisterCrypto(v034Codec)
v034gov.RegisterLegacyAminoCodec(v034Codec)

View File

@ -5,6 +5,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
)
@ -90,7 +91,7 @@ func TestDummyGenesis(t *testing.T) {
"foo": {},
"bar": []byte(`{"custom": "module"}`),
}
migratedDummy := Migrate(genesisDummy)
migratedDummy := Migrate(genesisDummy, client.Context{})
// We should not touch custom modules in the map
require.Equal(t, genesisDummy["foo"], migratedDummy["foo"])
@ -102,5 +103,5 @@ func TestGovGenesis(t *testing.T) {
"gov": basic034Gov,
}
require.NotPanics(t, func() { Migrate(genesis) })
require.NotPanics(t, func() { Migrate(genesis, client.Context{}) })
}

View File

@ -1,20 +1,21 @@
package v038
import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_36"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_38"
v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_36"
v038distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v0_38"
v036genaccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v0_36"
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v036"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v038"
v036distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v036"
v038distr "github.com/cosmos/cosmos-sdk/x/distribution/legacy/v038"
v036genaccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v036"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_36"
v038staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_38"
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v036"
v038staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v038"
)
// Migrate migrates exported state from v0.36/v0.37 to a v0.38 genesis state.
func Migrate(appState types.AppMap) types.AppMap {
func Migrate(appState types.AppMap, _ client.Context) types.AppMap {
v036Codec := codec.NewLegacyAmino()
cryptocodec.RegisterCrypto(v036Codec)

View File

@ -3,11 +3,12 @@ package v038_test
import (
"testing"
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_36"
v036genaccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v0_36"
v038 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v0_38"
"github.com/cosmos/cosmos-sdk/client"
v036auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v036"
v036genaccounts "github.com/cosmos/cosmos-sdk/x/genaccounts/legacy/v036"
v038 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v038"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_36"
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v036"
"github.com/stretchr/testify/require"
)
@ -138,5 +139,5 @@ func TestMigrate(t *testing.T) {
v036staking.ModuleName: genStakingState,
}
require.NotPanics(t, func() { v038.Migrate(genesis) })
require.NotPanics(t, func() { v038.Migrate(genesis, client.Context{}) })
}

View File

@ -1,10 +1,11 @@
package v039
import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_38"
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_39"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v038"
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v039"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
)
@ -12,7 +13,7 @@ import (
//
// NOTE: No actual migration occurs since the types do not change, but JSON
// serialization of accounts do change.
func Migrate(appState types.AppMap) types.AppMap {
func Migrate(appState types.AppMap, _ client.Context) types.AppMap {
v038Codec := codec.NewLegacyAmino()
cryptocodec.RegisterCrypto(v038Codec)
v038auth.RegisterLegacyAminoCodec(v038Codec)

View File

@ -5,9 +5,10 @@ import (
"github.com/stretchr/testify/require"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_38"
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_39"
v039 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v0_39"
"github.com/cosmos/cosmos-sdk/client"
v038auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v038"
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v039"
v039 "github.com/cosmos/cosmos-sdk/x/genutil/legacy/v039"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
)
@ -115,6 +116,6 @@ func TestMigrate(t *testing.T) {
}
var migrated types.AppMap
require.NotPanics(t, func() { migrated = v039.Migrate(genesis) })
require.NotPanics(t, func() { migrated = v039.Migrate(genesis, client.Context{}) })
require.Equal(t, string(expectedGenAuthState), string(migrated[v039auth.ModuleName]))
}

View File

@ -0,0 +1,94 @@
package v040
import (
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v039"
v040auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v040"
v036supply "github.com/cosmos/cosmos-sdk/x/bank/legacy/v036"
v038bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v038"
v040bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v040"
v038evidence "github.com/cosmos/cosmos-sdk/x/evidence/legacy/v038"
v040evidence "github.com/cosmos/cosmos-sdk/x/evidence/legacy/v040"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
v039slashing "github.com/cosmos/cosmos-sdk/x/slashing/legacy/v039"
v040slashing "github.com/cosmos/cosmos-sdk/x/slashing/legacy/v040"
)
// Migrate migrates exported state from v0.39 to a v0.40 genesis state.
func Migrate(appState types.AppMap, clientCtx client.Context) types.AppMap {
v039Codec := codec.NewLegacyAmino()
cryptocodec.RegisterCrypto(v039Codec)
v039auth.RegisterLegacyAminoCodec(v039Codec)
v040Codec := clientCtx.JSONMarshaler
if appState[v038bank.ModuleName] != nil {
// unmarshal relative source genesis application state
var bankGenState v038bank.GenesisState
v039Codec.MustUnmarshalJSON(appState[v038bank.ModuleName], &bankGenState)
// unmarshal x/auth genesis state to retrieve all account balances
var authGenState v039auth.GenesisState
v039Codec.MustUnmarshalJSON(appState[v039auth.ModuleName], &authGenState)
// unmarshal x/supply genesis state to retrieve total supply
var supplyGenState v036supply.GenesisState
v039Codec.MustUnmarshalJSON(appState[v036supply.ModuleName], &supplyGenState)
// delete deprecated x/bank genesis state
delete(appState, v038bank.ModuleName)
// delete deprecated x/supply genesis state
delete(appState, v036supply.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v040bank.ModuleName] = v040Codec.MustMarshalJSON(v040bank.Migrate(bankGenState, authGenState, supplyGenState))
}
// remove balances from existing accounts
if appState[v039auth.ModuleName] != nil {
// unmarshal relative source genesis application state
var authGenState v039auth.GenesisState
v039Codec.MustUnmarshalJSON(appState[v039auth.ModuleName], &authGenState)
// delete deprecated x/auth genesis state
delete(appState, v039auth.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v040auth.ModuleName] = v040Codec.MustMarshalJSON(v040auth.Migrate(authGenState))
}
// Migrate x/evidence.
if appState[v038evidence.ModuleName] != nil {
// unmarshal relative source genesis application state
var evidenceGenState v038evidence.GenesisState
v039Codec.MustUnmarshalJSON(appState[v038bank.ModuleName], &evidenceGenState)
// delete deprecated x/evidence genesis state
delete(appState, v038evidence.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v040evidence.ModuleName] = v040Codec.MustMarshalJSON(v040evidence.Migrate(evidenceGenState, clientCtx))
}
// Migrate x/slashing.
if appState[v039slashing.ModuleName] != nil {
// unmarshal relative source genesis application state
var slashingGenState v039slashing.GenesisState
v039Codec.MustUnmarshalJSON(appState[v039slashing.ModuleName], &slashingGenState)
// delete deprecated x/evidence genesis state
delete(appState, v039slashing.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v040slashing.ModuleName] = v040Codec.MustMarshalJSON(v040slashing.Migrate(slashingGenState))
}
return appState
}

View File

@ -1,55 +0,0 @@
package v040
import (
"github.com/cosmos/cosmos-sdk/codec"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
v039auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_39"
v040auth "github.com/cosmos/cosmos-sdk/x/auth/legacy/v0_40"
v038bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v0_38"
v040bank "github.com/cosmos/cosmos-sdk/x/bank/legacy/v0_40"
"github.com/cosmos/cosmos-sdk/x/genutil/types"
)
// Migrate migrates exported state from v0.39 to a v0.40 genesis state.
func Migrate(appState types.AppMap) types.AppMap {
v039Codec := codec.NewLegacyAmino()
cryptocodec.RegisterCrypto(v039Codec)
v039auth.RegisterLegacyAminoCodec(v039Codec)
v040Codec := codec.NewLegacyAmino()
cryptocodec.RegisterCrypto(v040Codec)
v039auth.RegisterLegacyAminoCodec(v040Codec)
// remove balances from existing accounts
if appState[v039auth.ModuleName] != nil {
// unmarshal relative source genesis application state
var authGenState v039auth.GenesisState
v039Codec.MustUnmarshalJSON(appState[v039auth.ModuleName], &authGenState)
// delete deprecated x/auth genesis state
delete(appState, v039auth.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v040auth.ModuleName] = v040Codec.MustMarshalJSON(v040auth.Migrate(authGenState))
}
if appState[v038bank.ModuleName] != nil {
// unmarshal relative source genesis application state
var bankGenState v038bank.GenesisState
v039Codec.MustUnmarshalJSON(appState[v038bank.ModuleName], &bankGenState)
// unmarshal x/auth genesis state to retrieve all account balances
var authGenState v039auth.GenesisState
v039Codec.MustUnmarshalJSON(appState[v039auth.ModuleName], &authGenState)
// delete deprecated x/bank genesis state
delete(appState, v038bank.ModuleName)
// Migrate relative source genesis application state and marshal it into
// the respective key.
appState[v040bank.ModuleName] = v040Codec.MustMarshalJSON(v040bank.Migrate(bankGenState, authGenState))
}
return appState
}

View File

@ -4,6 +4,8 @@ import (
"encoding/json"
"github.com/tendermint/tendermint/crypto"
"github.com/cosmos/cosmos-sdk/client"
)
// DONTCOVER
@ -16,7 +18,7 @@ type (
// targeted one.
//
// TODO: MigrationCallback should also return an error upon failure.
MigrationCallback func(AppMap) AppMap
MigrationCallback func(AppMap, client.Context) AppMap
// MigrationMap defines a mapping from a version to a MigrationCallback.
MigrationMap map[string]MigrationCallback

View File

@ -1,6 +1,6 @@
// DONTCOVER
// nolint
package v0_34
package v034
import (
"encoding/json"

View File

@ -1,7 +1,7 @@
package v0_36
package v036
import (
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v0_34"
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v034"
)
// Migrate accepts exported genesis state from v0.34 and migrates it to v0.36

View File

@ -1,6 +1,6 @@
// DONTCOVER
// nolint
package v0_36
package v036
import (
"fmt"
@ -9,7 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v0_34"
v034gov "github.com/cosmos/cosmos-sdk/x/gov/legacy/v034"
)
const (

View File

@ -0,0 +1,79 @@
package v039
import (
"time"
sdk "github.com/cosmos/cosmos-sdk/types"
)
const (
ModuleName = "slashing"
)
// Default parameter namespace
const (
DefaultParamspace = ModuleName
DefaultSignedBlocksWindow = int64(100)
DefaultDowntimeJailDuration = 60 * 10 * time.Second
)
var (
DefaultMinSignedPerWindow = sdk.NewDecWithPrec(5, 1)
DefaultSlashFractionDoubleSign = sdk.NewDec(1).Quo(sdk.NewDec(20))
DefaultSlashFractionDowntime = sdk.NewDec(1).Quo(sdk.NewDec(100))
)
// Params - used for initializing default parameter for slashing at genesis
type Params struct {
SignedBlocksWindow int64 `json:"signed_blocks_window" yaml:"signed_blocks_window"`
MinSignedPerWindow sdk.Dec `json:"min_signed_per_window" yaml:"min_signed_per_window"`
DowntimeJailDuration time.Duration `json:"downtime_jail_duration" yaml:"downtime_jail_duration"`
SlashFractionDoubleSign sdk.Dec `json:"slash_fraction_double_sign" yaml:"slash_fraction_double_sign"`
SlashFractionDowntime sdk.Dec `json:"slash_fraction_downtime" yaml:"slash_fraction_downtime"`
}
// NewParams creates a new Params object
func NewParams(
signedBlocksWindow int64, minSignedPerWindow sdk.Dec, downtimeJailDuration time.Duration,
slashFractionDoubleSign, slashFractionDowntime sdk.Dec,
) Params {
return Params{
SignedBlocksWindow: signedBlocksWindow,
MinSignedPerWindow: minSignedPerWindow,
DowntimeJailDuration: downtimeJailDuration,
SlashFractionDoubleSign: slashFractionDoubleSign,
SlashFractionDowntime: slashFractionDowntime,
}
}
// DefaultParams defines the parameters for this module
func DefaultParams() Params {
return NewParams(
DefaultSignedBlocksWindow, DefaultMinSignedPerWindow, DefaultDowntimeJailDuration,
DefaultSlashFractionDoubleSign, DefaultSlashFractionDowntime,
)
}
// ValidatorSigningInfo defines the signing info for a validator
type ValidatorSigningInfo struct {
Address sdk.ConsAddress `json:"address" yaml:"address"` // validator consensus address
StartHeight int64 `json:"start_height" yaml:"start_height"` // height at which validator was first a candidate OR was unjailed
IndexOffset int64 `json:"index_offset" yaml:"index_offset"` // index offset into signed block bit array
JailedUntil time.Time `json:"jailed_until" yaml:"jailed_until"` // timestamp validator cannot be unjailed until
Tombstoned bool `json:"tombstoned" yaml:"tombstoned"` // whether or not a validator has been tombstoned (killed out of validator set)
MissedBlocksCounter int64 `json:"missed_blocks_counter" yaml:"missed_blocks_counter"` // missed blocks counter (to avoid scanning the array every time)
}
// MissedBlock
type MissedBlock struct {
Index int64 `json:"index" yaml:"index"`
Missed bool `json:"missed" yaml:"missed"`
}
// GenesisState - all slashing state that must be provided at genesis
type GenesisState struct {
Params Params `json:"params" yaml:"params"`
SigningInfos map[string]ValidatorSigningInfo `json:"signing_infos" yaml:"signing_infos"`
MissedBlocks map[string][]MissedBlock `json:"missed_blocks" yaml:"missed_blocks"`
}

View File

@ -0,0 +1,62 @@
package v040
import (
"sort"
v039slashing "github.com/cosmos/cosmos-sdk/x/slashing/legacy/v039"
v040slashing "github.com/cosmos/cosmos-sdk/x/slashing/types"
)
// Migrate accepts exported x/slashing genesis state from v0.39 and migrates it
// to v0.40 x/slashing genesis state. The migration includes:
//
// - Chaning SigningInfos and MissedBlocks from map to array.
func Migrate(oldGenState v039slashing.GenesisState) *v040slashing.GenesisState {
// Note that the two following `for` loop over a map's keys, so are not
// deterministic.
var newSigningInfos = make([]v040slashing.SigningInfo, 0, len(oldGenState.SigningInfos))
for address, signingInfo := range oldGenState.SigningInfos {
newSigningInfos = append(newSigningInfos, v040slashing.SigningInfo{
Address: address,
ValidatorSigningInfo: v040slashing.ValidatorSigningInfo{
Address: signingInfo.Address.String(),
StartHeight: signingInfo.StartHeight,
IndexOffset: signingInfo.IndexOffset,
JailedUntil: signingInfo.JailedUntil,
Tombstoned: signingInfo.Tombstoned,
MissedBlocksCounter: signingInfo.MissedBlocksCounter,
},
})
}
var newValidatorMissedBlocks = make([]v040slashing.ValidatorMissedBlocks, 0, len(oldGenState.MissedBlocks))
for address, validatorMissedBlocks := range oldGenState.MissedBlocks {
var newMissedBlocks = make([]v040slashing.MissedBlock, len(validatorMissedBlocks))
for i, missedBlock := range validatorMissedBlocks {
newMissedBlocks[i] = v040slashing.MissedBlock{
Index: missedBlock.Index,
Missed: missedBlock.Missed,
}
}
newValidatorMissedBlocks = append(newValidatorMissedBlocks, v040slashing.ValidatorMissedBlocks{
Address: address,
MissedBlocks: newMissedBlocks,
})
}
// We sort these two arrays by address, so that we get determinstic states.
sort.Slice(newSigningInfos, func(i, j int) bool { return newSigningInfos[i].Address < newSigningInfos[j].Address })
sort.Slice(newValidatorMissedBlocks, func(i, j int) bool { return newValidatorMissedBlocks[i].Address < newValidatorMissedBlocks[j].Address })
return &v040slashing.GenesisState{
Params: v040slashing.Params{
SignedBlocksWindow: oldGenState.Params.SignedBlocksWindow,
MinSignedPerWindow: oldGenState.Params.MinSignedPerWindow,
DowntimeJailDuration: oldGenState.Params.DowntimeJailDuration,
SlashFractionDoubleSign: oldGenState.Params.SlashFractionDoubleSign,
SlashFractionDowntime: oldGenState.Params.SlashFractionDowntime,
},
SigningInfos: newSigningInfos,
MissedBlocks: newValidatorMissedBlocks,
}
}

View File

@ -0,0 +1,140 @@
package v040_test
import (
"encoding/json"
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/simapp"
sdk "github.com/cosmos/cosmos-sdk/types"
v039slashing "github.com/cosmos/cosmos-sdk/x/slashing/legacy/v039"
v040slashing "github.com/cosmos/cosmos-sdk/x/slashing/legacy/v040"
)
func TestMigrate(t *testing.T) {
encodingConfig := simapp.MakeEncodingConfig()
clientCtx := client.Context{}.
WithInterfaceRegistry(encodingConfig.InterfaceRegistry).
WithTxConfig(encodingConfig.TxConfig).
WithLegacyAmino(encodingConfig.Amino).
WithJSONMarshaler(encodingConfig.Marshaler)
addr1, err := sdk.ConsAddressFromBech32("cosmosvalcons104cjmxkrg8y8lmrp25de02e4zf00zle4mzs685")
require.NoError(t, err)
addr2, err := sdk.ConsAddressFromBech32("cosmosvalcons10e4c5p6qk0sycy9u6u43t7csmlx9fyadr9yxph")
require.NoError(t, err)
gs := v039slashing.GenesisState{
Params: v039slashing.DefaultParams(),
SigningInfos: map[string]v039slashing.ValidatorSigningInfo{
"cosmosvalcons10e4c5p6qk0sycy9u6u43t7csmlx9fyadr9yxph": {
Address: addr2,
IndexOffset: 615501,
MissedBlocksCounter: 1,
Tombstoned: false,
},
"cosmosvalcons104cjmxkrg8y8lmrp25de02e4zf00zle4mzs685": {
Address: addr1,
IndexOffset: 2,
MissedBlocksCounter: 2,
Tombstoned: false,
},
},
MissedBlocks: map[string][]v039slashing.MissedBlock{
"cosmosvalcons10e4c5p6qk0sycy9u6u43t7csmlx9fyadr9yxph": {
{
Index: 2,
Missed: true,
},
},
"cosmosvalcons104cjmxkrg8y8lmrp25de02e4zf00zle4mzs685": {
{
Index: 3,
Missed: true,
},
{
Index: 4,
Missed: true,
},
},
},
}
migrated := v040slashing.Migrate(gs)
// Check that in `signing_infos` and `missed_blocks`, the address
// cosmosvalcons104cjmxkrg8y8lmrp25de02e4zf00zle4mzs685
// should always come before the address
// cosmosvalcons10e4c5p6qk0sycy9u6u43t7csmlx9fyadr9yxph
// (in alphabetic order, basically).
expected := `{
"missed_blocks": [
{
"address": "cosmosvalcons104cjmxkrg8y8lmrp25de02e4zf00zle4mzs685",
"missed_blocks": [
{
"index": "3",
"missed": true
},
{
"index": "4",
"missed": true
}
]
},
{
"address": "cosmosvalcons10e4c5p6qk0sycy9u6u43t7csmlx9fyadr9yxph",
"missed_blocks": [
{
"index": "2",
"missed": true
}
]
}
],
"params": {
"downtime_jail_duration": "600s",
"min_signed_per_window": "0.500000000000000000",
"signed_blocks_window": "100",
"slash_fraction_double_sign": "0.050000000000000000",
"slash_fraction_downtime": "0.010000000000000000"
},
"signing_infos": [
{
"address": "cosmosvalcons104cjmxkrg8y8lmrp25de02e4zf00zle4mzs685",
"validator_signing_info": {
"address": "cosmosvalcons104cjmxkrg8y8lmrp25de02e4zf00zle4mzs685",
"index_offset": "2",
"jailed_until": "0001-01-01T00:00:00Z",
"missed_blocks_counter": "2",
"start_height": "0",
"tombstoned": false
}
},
{
"address": "cosmosvalcons10e4c5p6qk0sycy9u6u43t7csmlx9fyadr9yxph",
"validator_signing_info": {
"address": "cosmosvalcons10e4c5p6qk0sycy9u6u43t7csmlx9fyadr9yxph",
"index_offset": "615501",
"jailed_until": "0001-01-01T00:00:00Z",
"missed_blocks_counter": "1",
"start_height": "0",
"tombstoned": false
}
}
]
}`
bz, err := clientCtx.JSONMarshaler.MarshalJSON(migrated)
require.NoError(t, err)
// Indent the JSON bz correctly.
var jsonObj map[string]interface{}
err = json.Unmarshal(bz, &jsonObj)
require.NoError(t, err)
indentedBz, err := json.MarshalIndent(jsonObj, "", " ")
require.NoError(t, err)
require.Equal(t, expected, string(indentedBz))
}

View File

@ -0,0 +1,5 @@
package v040
const (
ModuleName = "slashing"
)

View File

@ -1,6 +1,6 @@
// DONTCOVER
// nolint
package v0_34
package v034
import (
"time"

View File

@ -1,9 +1,9 @@
// DONTCOVER
// nolint
package v0_36
package v036
import (
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v034"
)
// Migrate accepts exported genesis state from v0.34 and migrates it to v0.36

View File

@ -1,6 +1,6 @@
// DONTCOVER
// nolint
package v0_36
package v036
import (
"time"
@ -9,7 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec/legacy"
sdk "github.com/cosmos/cosmos-sdk/types"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v034"
)
const (

View File

@ -1,9 +1,9 @@
// DONTCOVER
// nolint
package v0_38
package v038
import (
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_36"
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v036"
)
// Migrate accepts exported genesis state from v0.36 or v0.37 and migrates it to

View File

@ -1,6 +1,6 @@
// DONTCOVER
// nolint
package v0_38
package v038
import (
"time"
@ -9,8 +9,8 @@ import (
"github.com/cosmos/cosmos-sdk/codec/legacy"
sdk "github.com/cosmos/cosmos-sdk/types"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_34"
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v0_36"
v034staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v034"
v036staking "github.com/cosmos/cosmos-sdk/x/staking/legacy/v036"
)
const (