Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy paste slashing module from LSM #7

Open
wants to merge 3 commits into
base: v0.45.16-ics
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC
}

if app.initChainer == nil {
return
return abci.ResponseInitChain{}
}

// add block gas meter for any genesis transactions (allow infinite gas)
Expand Down
3 changes: 3 additions & 0 deletions core/appconfig/debug_container.dot
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
digraph "" {
}

37 changes: 37 additions & 0 deletions docs/core/proto-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -473,11 +473,13 @@
- [Description](#cosmos.staking.v1beta1.Description)
- [HistoricalInfo](#cosmos.staking.v1beta1.HistoricalInfo)
- [Params](#cosmos.staking.v1beta1.Params)
- [PendingTokenizeShareAuthorizations](#cosmos.staking.v1beta1.PendingTokenizeShareAuthorizations)
- [Pool](#cosmos.staking.v1beta1.Pool)
- [Redelegation](#cosmos.staking.v1beta1.Redelegation)
- [RedelegationEntry](#cosmos.staking.v1beta1.RedelegationEntry)
- [RedelegationEntryResponse](#cosmos.staking.v1beta1.RedelegationEntryResponse)
- [RedelegationResponse](#cosmos.staking.v1beta1.RedelegationResponse)
- [TokenizeShareRecord](#cosmos.staking.v1beta1.TokenizeShareRecord)
- [UnbondingDelegation](#cosmos.staking.v1beta1.UnbondingDelegation)
- [UnbondingDelegationEntry](#cosmos.staking.v1beta1.UnbondingDelegationEntry)
- [ValAddresses](#cosmos.staking.v1beta1.ValAddresses)
Expand Down Expand Up @@ -6656,6 +6658,7 @@ validator.
| `delegator_address` | [string](#string) | | delegator_address is the bech32-encoded address of the delegator. |
| `validator_address` | [string](#string) | | validator_address is the bech32-encoded address of the validator. |
| `shares` | [string](#string) | | shares define the delegation shares received. |
| `validator_bond` | [bool](#bool) | | has this delegation been marked as a validator self bond. |



Expand Down Expand Up @@ -6736,6 +6739,22 @@ Params defines the parameters for the staking module.



<a name="cosmos.staking.v1beta1.PendingTokenizeShareAuthorizations"></a>

### PendingTokenizeShareAuthorizations
PendingTokenizeShareAuthorizations stores a list of addresses that have their
tokenize share enablement in progress


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `addresses` | [string](#string) | repeated | |






<a name="cosmos.staking.v1beta1.Pool"></a>

### Pool
Expand Down Expand Up @@ -6830,6 +6849,24 @@ responses.



<a name="cosmos.staking.v1beta1.TokenizeShareRecord"></a>

### TokenizeShareRecord
TokenizeShareRecord represents a tokenized delegation


| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| `id` | [uint64](#uint64) | | |
| `owner` | [string](#string) | | |
| `module_account` | [string](#string) | | module account take the role of delegator |
| `validator` | [string](#string) | | validator delegated to for tokenize share record creation |






<a name="cosmos.staking.v1beta1.UnbondingDelegation"></a>

### UnbondingDelegation
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ require (
gopkg.in/yaml.v2 v2.4.0
)

require cosmossdk.io/errors v1.0.0-beta.7

require (
cosmossdk.io/api v0.2.6 // indirect
cosmossdk.io/depinject v1.0.0-alpha.3 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ cosmossdk.io/core v0.5.1 h1:vQVtFrIYOQJDV3f7rw4pjjVqc1id4+mE0L9hHP66pyI=
cosmossdk.io/core v0.5.1/go.mod h1:KZtwHCLjcFuo0nmDc24Xy6CRNEL9Vl/MeimQ2aC7NLE=
cosmossdk.io/depinject v1.0.0-alpha.3 h1:6evFIgj//Y3w09bqOUOzEpFj5tsxBqdc5CfkO7z+zfw=
cosmossdk.io/depinject v1.0.0-alpha.3/go.mod h1:eRbcdQ7MRpIPEM5YUJh8k97nxHpYbc3sMUnEtt8HPWU=
cosmossdk.io/errors v1.0.0-beta.7 h1:gypHW76pTQGVnHKo6QBkb4yFOJjC+sUGRc5Al3Odj1w=
cosmossdk.io/errors v1.0.0-beta.7/go.mod h1:mz6FQMJRku4bY7aqS/Gwfcmr/ue91roMEKAmDUDpBfE=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
filippo.io/edwards25519 v1.0.0-rc.1 h1:m0VOOB23frXZvAOK44usCgLWvtsxIoMCTBGJZlpmGfU=
filippo.io/edwards25519 v1.0.0-rc.1/go.mod h1:N1IkdkCkiLB6tki+MYJoSx2JTY9NUlxZE7eHn5EwJns=
Expand Down
18 changes: 18 additions & 0 deletions proto/cosmos/staking/v1beta1/staking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ message Delegation {
string validator_address = 2 [(gogoproto.moretags) = "yaml:\"validator_address\""];
// shares define the delegation shares received.
string shares = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec", (gogoproto.nullable) = false];
// has this delegation been marked as a validator self bond.
bool validator_bond = 4;
}

// UnbondingDelegation stores all of a single delegator's unbonding bonds
Expand Down Expand Up @@ -367,4 +369,20 @@ enum InfractionType {
// ValidatorUpdates defines an array of abci.ValidatorUpdate objects.
message ValidatorUpdates {
repeated tendermint.abci.ValidatorUpdate updates = 1 [(gogoproto.nullable) = false];
}

// TokenizeShareRecord represents a tokenized delegation
message TokenizeShareRecord {
option (gogoproto.equal) = true;

uint64 id = 1;
string owner = 2;
string module_account = 3; // module account take the role of delegator
string validator = 4; // validator delegated to for tokenize share record creation
}

// PendingTokenizeShareAuthorizations stores a list of addresses that have their
// tokenize share enablement in progress
message PendingTokenizeShareAuthorizations {
repeated string addresses = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];
}
2 changes: 1 addition & 1 deletion simapp/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []

for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(stakingtypes.AddressFromValidatorsKey(iter.Key()))
validator, found := app.StakingKeeper.GetValidator(ctx, addr)
validator, found := app.StakingKeeper.GetLiquidValidator(ctx, addr)
if !found {
panic("expected validator, not found")
}
Expand Down
44 changes: 43 additions & 1 deletion simapp/test_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
"github.com/cosmos/cosmos-sdk/crypto/keys/ed25519"
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
"github.com/cosmos/cosmos-sdk/simapp/helpers"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -85,6 +86,31 @@ func Setup(isCheckTx bool) *SimApp {
return app
}

// For LSM replaced module usage
func SetupLSM(t *testing.T, _ bool) *SimApp {
t.Helper()

pk := ed25519.GenPrivKey().PubKey()
pubKey, err := cryptocodec.ToTmPubKeyInterface(pk)
require.NoError(t, err)

// create validator set with single validator
validator := tmtypes.NewValidator(pubKey, 1)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})

// generate genesis account
senderPrivKey := secp256k1.GenPrivKey()
acc := authtypes.NewBaseAccount(senderPrivKey.PubKey().Address().Bytes(), senderPrivKey.PubKey(), 0, 0)
balance := banktypes.Balance{
Address: acc.GetAddress().String(),
Coins: sdk.NewCoins(sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(100000000000000))),
}

app := SetupWithGenesisValSet(t, valSet, []authtypes.GenesisAccount{acc}, balance)

return app
}

// SetupWithGenesisValSet initializes a new SimApp with a validator set and genesis accounts
// that also act as delegators. For simplicity, each validator is bonded with a delegation
// of one consensus engine unit (10^6) in the default token of the simapp from first genesis
Expand Down Expand Up @@ -119,7 +145,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
MinSelfDelegation: sdk.ZeroInt(),
}
validators = append(validators, validator)
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec()))
delegations = append(delegations, stakingtypes.NewDelegation(genAccs[0].GetAddress(), val.Address.Bytes(), sdk.OneDec(), false))

}
// set validators and delegations
Expand Down Expand Up @@ -200,6 +226,22 @@ func SetupWithGenesisAccounts(genAccs []authtypes.GenesisAccount, balances ...ba
return app
}

// SetupWithGenesisAccounts initializes a new SimApp with the provided genesis
// accounts and possible balances.
// For LSM replaced module usage
func SetupWithGenesisAccountsLSM(t *testing.T, genAccs []authtypes.GenesisAccount, balances ...banktypes.Balance) *SimApp {
t.Helper()
pk := ed25519.GenPrivKey().PubKey()
pubKey, err := cryptocodec.ToTmPubKeyInterface(pk)
require.NoError(t, err)

// create validator set with single validator
validator := tmtypes.NewValidator(pubKey, 1)
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{validator})

return SetupWithGenesisValSet(t, valSet, genAccs, balances...)
}

type GenerateAccountStrategy func(int) []sdk.AccAddress

// createRandomAccounts is a strategy used by addTestAddrs() in order to generated addresses in random order.
Expand Down
Loading