diff --git a/app/app.go b/app/app.go index 8cb0de71..fe7c3910 100644 --- a/app/app.go +++ b/app/app.go @@ -269,7 +269,7 @@ func NewTgradeApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest // Create IBC Keeper app.ibcKeeper = ibckeeper.NewKeeper( - appCodec, keys[ibchost.StoreKey], app.getSubspace(ibchost.ModuleName), stakingKeeper, scopedIBCKeeper, + appCodec, keys[ibchost.StoreKey], app.getSubspace(ibchost.ModuleName), &app.poeKeeper, scopedIBCKeeper, ) twasmConfig, err := twasm.ReadWasmConfig(appOpts) @@ -349,7 +349,7 @@ func NewTgradeApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest govRouter, ) - app.poeKeeper = poekeeper.NewKeeper(appCodec, keys[poe.StoreKey]) + app.poeKeeper = poekeeper.NewKeeper(appCodec, keys[poe.StoreKey], app.getSubspace(poe.ModuleName), app.twasmKeeper) /**** Module Options ****/ // NOTE: we may consider parsing `appOpts` inside module constructors. For the moment @@ -381,6 +381,7 @@ func NewTgradeApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLatest // CanWithdrawInvariant invariant. // NOTE: staking module is required if HistoricalEntries param > 0 app.mm.SetOrderBeginBlockers( + poe.ModuleName, upgradetypes.ModuleName, evidencetypes.ModuleName, ibchost.ModuleName, twasm.ModuleName, @@ -600,6 +601,7 @@ func initParamsKeeper(appCodec codec.BinaryMarshaler, legacyAmino *codec.LegacyA paramsKeeper.Subspace(ibchost.ModuleName) paramsKeeper.Subspace(twasm.ModuleName) paramsKeeper.Subspace(globalfee.ModuleName) + paramsKeeper.Subspace(poe.ModuleName) return paramsKeeper } diff --git a/app/app_test.go b/app/app_test.go index 02ab4f7a..63c0d51f 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -6,7 +6,10 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + ibcclienttypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" + "github.com/stretchr/testify/assert" "github.com/tendermint/tendermint/libs/rand" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" "os" "testing" "time" @@ -22,7 +25,6 @@ import ( var emptyWasmOpts []wasm.Option = nil func TestTgradeExport(t *testing.T) { - t.Skip("Alex, this is not implemented") db := db.NewMemDB() gapp := NewTgradeApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, EmptyBaseAppOptions{}, emptyWasmOpts) genesisState := NewDefaultGenesisState() @@ -44,6 +46,8 @@ func TestTgradeExport(t *testing.T) { // Making a new app object with the db, so that initchain hasn't been called newGapp := NewTgradeApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, EmptyBaseAppOptions{}, emptyWasmOpts) + + t.Skip("Alex, export is not implemented") _, err = newGapp.ExportAppStateAndValidators(false, []string{}) require.NoError(t, err, "ExportAppStateAndValidators should not have an error") } @@ -119,3 +123,40 @@ func setGenesis(gapp *TgradeApp) error { gapp.Commit() return nil } + +func TestIBCKeeperLazyInitialization(t *testing.T) { + db := db.NewMemDB() + gapp := NewTgradeApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, DefaultNodeHome, 0, EmptyBaseAppOptions{}, emptyWasmOpts) + genesisState := NewDefaultGenesisState() + + setupWithSingleValidatorGenTX(t, genesisState) + + stateBytes, err := json.MarshalIndent(genesisState, "", " ") + require.NoError(t, err) + + // Initialize the chain + now := time.Now().UTC() + gapp.InitChain( + abci.RequestInitChain{ + Time: now, + Validators: []abci.ValidatorUpdate{}, + AppStateBytes: stateBytes, + }, + ) + gapp.Commit() + // store some historic information + header := tmproto.Header{ChainID: "testing-1", Height: 2, Time: now, AppHash: []byte("myAppHash")} + gapp.BaseApp.BeginBlock(abci.RequestBeginBlock{Header: header}) + gapp.Commit() + + ctx := gapp.BaseApp.NewContext(true, header) + height := ibcclienttypes.Height{RevisionNumber: 1, RevisionHeight: 2} + + // when + // https://github.com/cosmos/cosmos-sdk/blob/v0.42.9/x/ibc/core/02-client/keeper/keeper.go#L252 + state, found := gapp.ibcKeeper.ClientKeeper.GetSelfConsensusState(ctx, height) + // then + require.True(t, found) + assert.Equal(t, []byte("myAppHash"), state.GetRoot().GetHash()) + assert.Equal(t, uint64(now.UnixNano()), state.GetTimestamp()) +} diff --git a/docs/proto/proto-docs.md b/docs/proto/proto-docs.md index 79870bfc..0af3247d 100644 --- a/docs/proto/proto-docs.md +++ b/docs/proto/proto-docs.md @@ -15,6 +15,8 @@ - [Query](#confio.globalfee.v1beta1.Query) - [confio/poe/v1beta1/poe.proto](#confio/poe/v1beta1/poe.proto) + - [Params](#confio.poe.v1beta1.Params) + - [PoEContractType](#confio.poe.v1beta1.PoEContractType) - [confio/poe/v1beta1/genesis.proto](#confio/poe/v1beta1/genesis.proto) @@ -166,6 +168,21 @@ Query defines the gRPC querier service. ## confio/poe/v1beta1/poe.proto + + + +### Params +Params defines the parameters for the PoE module. + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| `historical_entries` | [uint32](#uint32) | | historical_entries is the number of historical entries to persist. | + + + + + @@ -206,6 +223,7 @@ GenesisState - initial state of module | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | +| `params` | [Params](#confio.poe.v1beta1.Params) | | params defines all the parameter of the module | | `seed_contracts` | [bool](#bool) | | SeedContracts when enabled stores and instantiates the Proof of Engagement contracts on the chain. | | `gen_txs` | [bytes](#bytes) | repeated | GenTxs defines the genesis transactions to create a validator. | | `system_admin_address` | [string](#string) | | SystemAdminAddress single address that is set as admin for the PoE contracts in seed mode. | diff --git a/proto/confio/poe/v1beta1/genesis.proto b/proto/confio/poe/v1beta1/genesis.proto index ded49f18..d438aa8b 100644 --- a/proto/confio/poe/v1beta1/genesis.proto +++ b/proto/confio/poe/v1beta1/genesis.proto @@ -10,12 +10,16 @@ option go_package = "github.com/confio/tgrade/x/poe/types"; // GenesisState - initial state of module message GenesisState { + + // params defines all the parameter of the module + Params params = 1 [ (gogoproto.nullable) = false ]; + // SeedContracts when enabled stores and instantiates the Proof of Engagement // contracts on the chain. - bool seed_contracts = 1; + bool seed_contracts = 2; // GenTxs defines the genesis transactions to create a validator. - repeated bytes gen_txs = 2 [ + repeated bytes gen_txs = 3 [ (gogoproto.casttype) = "encoding/json.RawMessage", (gogoproto.jsontag) = "gentxs", (gogoproto.moretags) = "yaml:\"gentxs\"" @@ -23,24 +27,24 @@ message GenesisState { // SystemAdminAddress single address that is set as admin for the PoE // contracts in seed mode. - string system_admin_address = 3; + string system_admin_address = 4; // Contracts Poe contract addresses and types when used with state dump in non // seed mode. - repeated PoEContract contracts = 4 [ + repeated PoEContract contracts = 5 [ (gogoproto.nullable) = false, (gogoproto.jsontag) = "contracts,omitempty" ]; // Engagement weighted members of the engagement group. Validators should be // in here. - repeated TG4Member engagement = 5 [ + repeated TG4Member engagement = 6 [ (gogoproto.nullable) = false, (gogoproto.jsontag) = "engagement,omitempty" ]; // BondDenom defines the bondable coin denomination. - string bond_denom = 6 [ (gogoproto.moretags) = "yaml:\"bond_denom\"" ]; + string bond_denom = 7 [ (gogoproto.moretags) = "yaml:\"bond_denom\"" ]; } // PoEContract address and type information diff --git a/proto/confio/poe/v1beta1/poe.proto b/proto/confio/poe/v1beta1/poe.proto index c8474aed..1fac26f8 100644 --- a/proto/confio/poe/v1beta1/poe.proto +++ b/proto/confio/poe/v1beta1/poe.proto @@ -24,3 +24,12 @@ enum PoEContractType { [ (gogoproto.enumvalue_customname) = "PoEContractTypeEngagement" ]; MIXER = 4 [ (gogoproto.enumvalue_customname) = "PoEContractTypeMixer" ]; } + +// Params defines the parameters for the PoE module. +message Params { + option (gogoproto.equal) = true; + option (gogoproto.goproto_stringer) = false; + // historical_entries is the number of historical entries to persist. + uint32 historical_entries = 4 + [ (gogoproto.moretags) = "yaml:\"historical_entries\"" ]; +} \ No newline at end of file diff --git a/x/poe/abci.go b/x/poe/abci.go index 9f231cf0..09766aa2 100644 --- a/x/poe/abci.go +++ b/x/poe/abci.go @@ -11,13 +11,13 @@ import ( "time" ) -type abciKeeper interface { +type endBlockKeeper interface { types.Sudoer IteratePrivilegedContractsByType(ctx sdk.Context, privilegeType twasmtypes.PrivilegeType, cb func(prio uint8, contractAddr sdk.AccAddress) bool) } // EndBlocker calls the Valset contract for the validator diff. -func EndBlocker(parentCtx sdk.Context, k abciKeeper) []abci.ValidatorUpdate { +func EndBlocker(parentCtx sdk.Context, k endBlockKeeper) []abci.ValidatorUpdate { defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) logger := keeper.ModuleLogger(parentCtx) @@ -40,3 +40,9 @@ func EndBlocker(parentCtx sdk.Context, k abciKeeper) []abci.ValidatorUpdate { }) return diff } + +func BeginBlocker(ctx sdk.Context, k interface{ TrackHistoricalInfo(ctx sdk.Context) }) { + defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyBeginBlocker) + + k.TrackHistoricalInfo(ctx) +} diff --git a/x/poe/keeper/genesis.go b/x/poe/keeper/genesis.go index 6054f9f8..fa96797c 100644 --- a/x/poe/keeper/genesis.go +++ b/x/poe/keeper/genesis.go @@ -15,6 +15,7 @@ type DeliverTxFn func(abci.RequestDeliverTx) abci.ResponseDeliverTx type initer interface { SetPoEContractAddress(ctx sdk.Context, ctype types.PoEContractType, contractAddr sdk.AccAddress) setPoESystemAdminAddress(ctx sdk.Context, admin sdk.AccAddress) + setParams(ctx sdk.Context, params types.Params) } // InitGenesis - initialize accounts and deliver genesis transactions @@ -30,6 +31,7 @@ func InitGenesis( // addr, _ := sdk.AccAddressFromBech32(v.Address) // keeper.SetPoEContractAddress(ctx, v.ContractType, addr) //} + keeper.setParams(ctx, genesisState.Params) admin, err := sdk.AccAddressFromBech32(genesisState.SystemAdminAddress) if err != nil { return sdkerrors.Wrap(err, "admin") diff --git a/x/poe/keeper/genesis_test.go b/x/poe/keeper/genesis_test.go index 440df647..c28f99be 100644 --- a/x/poe/keeper/genesis_test.go +++ b/x/poe/keeper/genesis_test.go @@ -22,6 +22,7 @@ func TestInitGenesis(t *testing.T) { expErr bool expDeliveredGenTxCount int expContracts []CapturedPoEContractAddress + expParams types.Params }{ "all good": { src: types.GenesisStateFixture(func(m *types.GenesisState) { @@ -30,6 +31,7 @@ func TestInitGenesis(t *testing.T) { }, ), expDeliveredGenTxCount: 1, + expParams: types.DefaultParams(), }, "deliver genTX failed": { src: types.GenesisStateFixture(func(m *types.GenesisState) { @@ -50,11 +52,15 @@ func TestInitGenesis(t *testing.T) { ctx := sdk.Context{} cFn, capAddrs := CaptureSetPoEContractAddressFn() var capturedAdminAddr sdk.AccAddress + var capaturedParams types.Params m := PoEKeeperMock{ SetPoEContractAddressFn: cFn, setPoESystemAdminAddressFn: func(ctx sdk.Context, admin sdk.AccAddress) { capturedAdminAddr = admin }, + setParamsFn: func(ctx sdk.Context, params types.Params) { + capaturedParams = params + }, } gotErr := InitGenesis(ctx, m, captureTx, spec.src, txConfig) if spec.expErr { @@ -65,6 +71,7 @@ func TestInitGenesis(t *testing.T) { assert.Len(t, capturedTxs, spec.expDeliveredGenTxCount) assert.Equal(t, spec.expContracts, *capAddrs) assert.Equal(t, spec.src.SystemAdminAddress, capturedAdminAddr.String()) + assert.Equal(t, spec.expParams, capaturedParams) }) } } diff --git a/x/poe/keeper/historical_info.go b/x/poe/keeper/historical_info.go new file mode 100644 index 00000000..5dacc9e5 --- /dev/null +++ b/x/poe/keeper/historical_info.go @@ -0,0 +1,110 @@ +package keeper + +import ( + "fmt" + "github.com/confio/tgrade/x/poe/types" + sdk "github.com/cosmos/cosmos-sdk/types" + ibccoretypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + "strconv" +) + +var _ ibccoretypes.StakingKeeper = &Keeper{} + +// GetHistoricalInfo gets the historical info at a given height +func (k Keeper) GetHistoricalInfo(ctx sdk.Context, height int64) (stakingtypes.HistoricalInfo, bool) { + store := ctx.KVStore(k.storeKey) + key := getHistoricalInfoKey(height) + + value := store.Get(key) + if value == nil { + return stakingtypes.HistoricalInfo{}, false + } + + return stakingtypes.MustUnmarshalHistoricalInfo(k.marshaler, value), true +} + +// SetHistoricalInfo sets the historical info at a given height +func (k Keeper) SetHistoricalInfo(ctx sdk.Context, height int64, hi *stakingtypes.HistoricalInfo) { + store := ctx.KVStore(k.storeKey) + key := getHistoricalInfoKey(height) + value := k.marshaler.MustMarshalBinaryBare(hi) + store.Set(key, value) +} + +// DeleteHistoricalInfo deletes the historical info at a given height +func (k Keeper) DeleteHistoricalInfo(ctx sdk.Context, height int64) { + store := ctx.KVStore(k.storeKey) + key := getHistoricalInfoKey(height) + + store.Delete(key) +} + +// iterateHistoricalInfo provides an interator over all stored HistoricalInfo +// objects. For each HistoricalInfo object, cb will be called. If the cb returns +// true, the iterator will close and stop. +func (k Keeper) iterateHistoricalInfo(ctx sdk.Context, cb func(stakingtypes.HistoricalInfo) bool) { + store := ctx.KVStore(k.storeKey) + + iterator := sdk.KVStorePrefixIterator(store, types.HistoricalInfoKey) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + histInfo := stakingtypes.MustUnmarshalHistoricalInfo(k.marshaler, iterator.Value()) + if cb(histInfo) { + break + } + } +} + +// getAllHistoricalInfo returns all stored HistoricalInfo objects. +func (k Keeper) getAllHistoricalInfo(ctx sdk.Context) []stakingtypes.HistoricalInfo { + var infos []stakingtypes.HistoricalInfo + + k.iterateHistoricalInfo(ctx, func(histInfo stakingtypes.HistoricalInfo) bool { + infos = append(infos, histInfo) + return false + }) + + return infos +} + +// TrackHistoricalInfo saves the latest historical-info and deletes the oldest +// heights that are below pruning height +func (k Keeper) TrackHistoricalInfo(ctx sdk.Context) { + entryNum := k.HistoricalEntries(ctx) + + // Prune store to ensure we only have parameter-defined historical entries. + // In most cases, this will involve removing a single historical entry. + // In the rare scenario when the historical entries gets reduced to a lower value k' + // from the original value k. k - k' entries must be deleted from the store. + // Since the entries to be deleted are always in a continuous range, we can iterate + // over the historical entries starting from the most recent version to be pruned + // and then return at the first empty entry. + fmt.Printf("++ height: %d", ctx.BlockHeight()) + for i := ctx.BlockHeight() - int64(entryNum); i >= 0; i-- { + _, found := k.GetHistoricalInfo(ctx, i) + if found { + k.DeleteHistoricalInfo(ctx, i) + } else { + break + } + } + + // if there is no need to persist historicalInfo, return + if entryNum == 0 { + return + } + + // Create HistoricalInfo struct + var valSet stakingtypes.Validators // not used by IBC so we keep it empty + historicalEntry := stakingtypes.NewHistoricalInfo(ctx.BlockHeader(), valSet) + + // Set latest HistoricalInfo at current height + k.SetHistoricalInfo(ctx, ctx.BlockHeight(), &historicalEntry) +} + +// getHistoricalInfoKey returns a key prefix for indexing HistoricalInfo objects. +func getHistoricalInfoKey(height int64) []byte { + return append(types.HistoricalInfoKey, []byte(strconv.FormatInt(height, 10))...) +} diff --git a/x/poe/keeper/historical_info_test.go b/x/poe/keeper/historical_info_test.go new file mode 100644 index 00000000..5e27cca7 --- /dev/null +++ b/x/poe/keeper/historical_info_test.go @@ -0,0 +1,66 @@ +package keeper + +import ( + "github.com/confio/tgrade/x/poe/types" + fuzz "github.com/google/gofuzz" + "github.com/stretchr/testify/assert" + "testing" + "time" + + "github.com/stretchr/testify/require" + tmproto "github.com/tendermint/tendermint/proto/tendermint/types" + + stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" +) + +func TestGetSetHistoricalInfo(t *testing.T) { + ctx, example := CreateDefaultTestInput(t) + keeper := example.PoEKeeper + var header tmproto.Header + f := fuzz.New() + f.Fuzz(&header) + + ctx = ctx.WithBlockHeight(1).WithBlockHeader(header) + exp := stakingtypes.NewHistoricalInfo(ctx.BlockHeader(), nil) + keeper.SetHistoricalInfo(ctx, 1, &exp) + + // when + got, exists := keeper.GetHistoricalInfo(ctx, 1) + + // then + require.True(t, exists) + assert.Equal(t, exp, got) +} + +func TestTrackHistoricalInfo(t *testing.T) { + ctx, example := CreateDefaultTestInput(t) + keeper := example.PoEKeeper + const maxEntries = 2 + keeper.setParams(ctx, types.Params{HistoricalEntries: maxEntries}) + + // fill all slots + expEntries := make([]stakingtypes.HistoricalInfo, 0, maxEntries+1) + for i := 0; i < maxEntries; i++ { + var header tmproto.Header + f := fuzz.New() + f.Fuzz(&header) + header.Height = int64(1 + i) + header.Time = time.Now().UTC() + keeper.TrackHistoricalInfo(ctx.WithBlockHeader(header)) + expEntries = append(expEntries, stakingtypes.NewHistoricalInfo(header, nil)) + } + + // when new element added + var header tmproto.Header + f := fuzz.New() + f.Fuzz(&header) + header.Height = int64(1 + maxEntries) + header.Time = time.Now().UTC() + keeper.TrackHistoricalInfo(ctx.WithBlockHeader(header)) + + // then only last max entries stored + _, exists := keeper.GetHistoricalInfo(ctx, 1) + require.False(t, exists) + expEntries = append(expEntries, stakingtypes.NewHistoricalInfo(header, nil)) + assert.Equal(t, expEntries[1:], keeper.getAllHistoricalInfo(ctx)) +} diff --git a/x/poe/keeper/keeper.go b/x/poe/keeper/keeper.go index 49c7398b..96533b99 100644 --- a/x/poe/keeper/keeper.go +++ b/x/poe/keeper/keeper.go @@ -3,23 +3,36 @@ package keeper import ( "fmt" wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" + "github.com/confio/tgrade/x/poe/contract" "github.com/confio/tgrade/x/poe/types" "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" "github.com/tendermint/tendermint/libs/log" + "time" ) type Keeper struct { - marshaler codec.Marshaler - storeKey sdk.StoreKey + marshaler codec.Marshaler + storeKey sdk.StoreKey + paramStore paramtypes.Subspace + contractQuerier types.SmartQuerier } // NewKeeper constructor -func NewKeeper(marshaler codec.Marshaler, key sdk.StoreKey) Keeper { - return Keeper{marshaler: marshaler, storeKey: key} +func NewKeeper(marshaler codec.Marshaler, key sdk.StoreKey, paramSpace paramtypes.Subspace, contractQuerier types.SmartQuerier) Keeper { + // set KeyTable if it has not already been set + if !paramSpace.HasKeyTable() { + paramSpace = paramSpace.WithKeyTable(types.ParamKeyTable()) + } + return Keeper{ + marshaler: marshaler, + storeKey: key, + paramStore: paramSpace, + contractQuerier: contractQuerier, + } } func (k Keeper) SetPoEContractAddress(ctx sdk.Context, ctype types.PoEContractType, contractAddr sdk.AccAddress) { @@ -64,9 +77,18 @@ func (k Keeper) GetPoESystemAdminAddress(ctx sdk.Context) sdk.AccAddress { return store.Get(types.SystemAdminPrefix) } -func (k Keeper) GetLastValidators(ctx sdk.Context) []stakingtypes.Validator { - panic("implement") - return nil +// UnbondingTime returns the unbonding period from the staking contract +func (k Keeper) UnbondingTime(ctx sdk.Context) time.Duration { + contractAddr, err := k.GetPoEContractAddress(ctx, types.PoEContractTypeStaking) + if err != nil { + panic(fmt.Sprintf("get contract address: %s", err)) + } + + rsp, err := contract.QueryStakingUnbondingPeriod(ctx, k.contractQuerier, contractAddr) + if err != nil { + panic(fmt.Sprintf("query unponding period from %s: %s", contractAddr.String(), err)) + } + return time.Duration(rsp.Time) * time.Second } func ModuleLogger(ctx sdk.Context) log.Logger { diff --git a/x/poe/keeper/keeper_test.go b/x/poe/keeper/keeper_test.go index da676e17..3f169a26 100644 --- a/x/poe/keeper/keeper_test.go +++ b/x/poe/keeper/keeper_test.go @@ -1,12 +1,15 @@ package keeper import ( + "encoding/json" + "github.com/confio/tgrade/x/poe/contract" "github.com/confio/tgrade/x/poe/types" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/tendermint/tendermint/libs/rand" "testing" + "time" ) func TestSetGetPoEContractAddress(t *testing.T) { @@ -66,6 +69,7 @@ func TestSetGetPoESystemAdmin(t *testing.T) { k.setPoESystemAdminAddress(ctx, myAddr) assert.Equal(t, myAddr, k.GetPoESystemAdminAddress(ctx)) } + func TestIteratePoEContracts(t *testing.T) { ctx, _, k := createMinTestInput(t) storedTypes := make(map[types.PoEContractType]sdk.AccAddress) @@ -86,3 +90,17 @@ func TestIteratePoEContracts(t *testing.T) { }) assert.Equal(t, storedTypes, readTypes) } + +func TestUnbondingTime(t *testing.T) { + ctx, _, k := createMinTestInput(t) + var myAddr sdk.AccAddress = rand.Bytes(sdk.AddrLen) + k.SetPoEContractAddress(ctx, types.PoEContractTypeStaking, myAddr) + + k.contractQuerier = SmartQuerierMock{QuerySmartFn: func(ctx sdk.Context, contractAddr sdk.AccAddress, req []byte) ([]byte, error) { + require.Equal(t, myAddr, contractAddr) + return json.Marshal(contract.UnbondingPeriodResponse{ + UnbondingPeriod: contract.Duration{Time: 60, Height: 2}, + }) + }} + assert.Equal(t, time.Minute, k.UnbondingTime(ctx)) +} diff --git a/x/poe/keeper/params.go b/x/poe/keeper/params.go new file mode 100644 index 00000000..a647d10b --- /dev/null +++ b/x/poe/keeper/params.go @@ -0,0 +1,25 @@ +package keeper + +import ( + "github.com/confio/tgrade/x/poe/types" + sdk "github.com/cosmos/cosmos-sdk/types" +) + +// HistoricalEntries = number of historical info entries +// to persist in store +func (k Keeper) HistoricalEntries(ctx sdk.Context) (res uint32) { + k.paramStore.Get(ctx, types.KeyHistoricalEntries, &res) + return +} + +// GetParams returns all parameters as types.Params +func (k Keeper) GetParams(ctx sdk.Context) types.Params { + return types.NewParams( + k.HistoricalEntries(ctx), + ) +} + +// SetParams set the params +func (k Keeper) setParams(ctx sdk.Context, params types.Params) { + k.paramStore.SetParamSet(ctx, ¶ms) +} diff --git a/x/poe/keeper/test_common.go b/x/poe/keeper/test_common.go index 8c67ea90..957fe6f5 100644 --- a/x/poe/keeper/test_common.go +++ b/x/poe/keeper/test_common.go @@ -147,6 +147,7 @@ func createTestInput( paramsKeeper.Subspace(ibctransfertypes.ModuleName) paramsKeeper.Subspace(capabilitytypes.ModuleName) paramsKeeper.Subspace(ibchost.ModuleName) + paramsKeeper.Subspace(types.ModuleName) maccPerms := map[string][]string{ // module account permissions authtypes.FeeCollectorName: nil, @@ -223,7 +224,8 @@ func createTestInput( defaultParams := twasmtypes.DefaultParams() twasmSubspace.SetParamSet(ctx, &defaultParams) - poeKeeper := NewKeeper(appCodec, keyPoE) + poeSubsp, _ := paramsKeeper.GetSubspace(types.ModuleName) + poeKeeper := NewKeeper(appCodec, keyPoE, poeSubsp, twasmKeeper) router.AddRoute(sdk.NewRoute(twasmtypes.RouterKey, wasm.NewHandler(twasmKeeper.GetContractKeeper()))) keepers := TestKeepers{ @@ -270,6 +272,6 @@ func createMinTestInput(t *testing.T) (sdk.Context, simappparams.EncodingConfig, }, false, log.NewNopLogger()) encodingConfig := types.MakeEncodingConfig(t) - k := NewKeeper(encodingConfig.Marshaler, keyPoe) + k := NewKeeper(encodingConfig.Marshaler, keyPoe, paramstypes.NewSubspace(nil, nil, nil, nil, types.ModuleName), nil) return ctx, encodingConfig, k } diff --git a/x/poe/keeper/test_mocks.go b/x/poe/keeper/test_mocks.go index 693ee4bb..7b52ddfe 100644 --- a/x/poe/keeper/test_mocks.go +++ b/x/poe/keeper/test_mocks.go @@ -28,6 +28,14 @@ type PoEKeeperMock struct { ContractSourceMock SetPoEContractAddressFn func(ctx sdk.Context, ctype types.PoEContractType, contractAddr sdk.AccAddress) setPoESystemAdminAddressFn func(ctx sdk.Context, admin sdk.AccAddress) + setParamsFn func(ctx sdk.Context, params types.Params) +} + +func (m PoEKeeperMock) setParams(ctx sdk.Context, params types.Params) { + if m.setParamsFn == nil { + panic("not expected to be called") + } + m.setParamsFn(ctx, params) } func (m PoEKeeperMock) GetPoEContractAddress(ctx sdk.Context, ctype types.PoEContractType) (sdk.AccAddress, error) { diff --git a/x/poe/module.go b/x/poe/module.go index 0239047e..72e157be 100644 --- a/x/poe/module.go +++ b/x/poe/module.go @@ -100,7 +100,7 @@ type AppModule struct { // twasmKeeper subset of keeper to decouple from twasm module type twasmKeeper interface { - abciKeeper + endBlockKeeper types.SmartQuerier types.Sudoer SetPrivileged(ctx sdk.Context, contractAddr sdk.AccAddress) error @@ -145,12 +145,13 @@ func (am AppModule) RegisterServices(cfg module.Configurator) { types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.poeKeeper, am.contractKeeper, am.twasmKeeper)) } -func (am AppModule) BeginBlock(context sdk.Context, block abci.RequestBeginBlock) { +func (am AppModule) BeginBlock(ctx sdk.Context, block abci.RequestBeginBlock) { + BeginBlocker(ctx, am.poeKeeper) } -func (am AppModule) EndBlock(context sdk.Context, block abci.RequestEndBlock) []abci.ValidatorUpdate { +func (am AppModule) EndBlock(ctx sdk.Context, block abci.RequestEndBlock) []abci.ValidatorUpdate { am.doOnce.Do(ClearEmbeddedContracts) // release memory - return EndBlocker(context, am.twasmKeeper) + return EndBlocker(ctx, am.twasmKeeper) } // InitGenesis performs genesis initialization for the genutil module. It returns diff --git a/x/poe/stakingadapter/keeper.go b/x/poe/stakingadapter/keeper.go index 6d4ab9cb..f10f2feb 100644 --- a/x/poe/stakingadapter/keeper.go +++ b/x/poe/stakingadapter/keeper.go @@ -8,12 +8,9 @@ import ( "github.com/cosmos/cosmos-sdk/x/distribution/types" evidencetypes "github.com/cosmos/cosmos-sdk/x/evidence/types" govtypes "github.com/cosmos/cosmos-sdk/x/gov/types" - ibccoretypes "github.com/cosmos/cosmos-sdk/x/ibc/core/02-client/types" minttypes "github.com/cosmos/cosmos-sdk/x/mint/types" - slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" abci "github.com/tendermint/tendermint/abci/types" - "time" ) // StakingAdapter connect to POE contract @@ -21,9 +18,11 @@ import ( var _ wasmtypes.StakingKeeper = &StakingAdapter{} var _ wasmtypes.DistributionKeeper = &StakingAdapter{} var _ wasmkeeper.ValidatorSetSource = &StakingAdapter{} -var _ ibccoretypes.StakingKeeper = &StakingAdapter{} + +//var _ ibccoretypes.StakingKeeper = &StakingAdapter{} var _ evidencetypes.StakingKeeper = &StakingAdapter{} -var _ slashingtypes.StakingKeeper = &StakingAdapter{} + +//var _ slashingtypes.StakingKeeper = &StakingAdapter{} var _ minttypes.StakingKeeper = &StakingAdapter{} var _ govtypes.StakingKeeper = &StakingAdapter{} @@ -67,14 +66,6 @@ func (s StakingAdapter) DelegationRewards(c context.Context, req *types.QueryDel return nil, nil } -func (s StakingAdapter) GetHistoricalInfo(ctx sdk.Context, height int64) (stakingtypes.HistoricalInfo, bool) { - panic("implement me") -} - -func (s StakingAdapter) UnbondingTime(ctx sdk.Context) time.Duration { - panic("implement me") -} - func (s StakingAdapter) ValidatorByConsAddr(ctx sdk.Context, address sdk.ConsAddress) stakingtypes.ValidatorI { panic("implement me") } diff --git a/x/poe/types/errors.go b/x/poe/types/errors.go index 22ec5278..88a9bba7 100644 --- a/x/poe/types/errors.go +++ b/x/poe/types/errors.go @@ -5,4 +5,5 @@ import sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" var ( ErrDeliverGenTXFailed = sdkerrors.Register(ModuleName, 2, "tx failed") ErrValidatorPubKeyTypeNotSupported = sdkerrors.Register(ModuleName, 3, "validator pubkey type is not supported") + ErrInvalidHistoricalInfo = sdkerrors.Register(ModuleName, 4, "invalid historical info") ) diff --git a/x/poe/types/genesis.go b/x/poe/types/genesis.go index 220cc90a..5e974974 100644 --- a/x/poe/types/genesis.go +++ b/x/poe/types/genesis.go @@ -16,6 +16,7 @@ func DefaultGenesisState() GenesisState { SeedContracts: true, BondDenom: DefaultBondDenom, SystemAdminAddress: sdk.AccAddress(rand.Bytes(sdk.AddrLen)).String(), + Params: DefaultParams(), } } diff --git a/x/poe/types/genesis.pb.go b/x/poe/types/genesis.pb.go index c69d7318..c4d89399 100644 --- a/x/poe/types/genesis.pb.go +++ b/x/poe/types/genesis.pb.go @@ -28,22 +28,24 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState - initial state of module type GenesisState struct { + // params defines all the parameter of the module + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` // SeedContracts when enabled stores and instantiates the Proof of Engagement // contracts on the chain. - SeedContracts bool `protobuf:"varint,1,opt,name=seed_contracts,json=seedContracts,proto3" json:"seed_contracts,omitempty"` + SeedContracts bool `protobuf:"varint,2,opt,name=seed_contracts,json=seedContracts,proto3" json:"seed_contracts,omitempty"` // GenTxs defines the genesis transactions to create a validator. - GenTxs []encoding_json.RawMessage `protobuf:"bytes,2,rep,name=gen_txs,json=genTxs,proto3,casttype=encoding/json.RawMessage" json:"gentxs" yaml:"gentxs"` + GenTxs []encoding_json.RawMessage `protobuf:"bytes,3,rep,name=gen_txs,json=genTxs,proto3,casttype=encoding/json.RawMessage" json:"gentxs" yaml:"gentxs"` // SystemAdminAddress single address that is set as admin for the PoE // contracts in seed mode. - SystemAdminAddress string `protobuf:"bytes,3,opt,name=system_admin_address,json=systemAdminAddress,proto3" json:"system_admin_address,omitempty"` + SystemAdminAddress string `protobuf:"bytes,4,opt,name=system_admin_address,json=systemAdminAddress,proto3" json:"system_admin_address,omitempty"` // Contracts Poe contract addresses and types when used with state dump in non // seed mode. - Contracts []PoEContract `protobuf:"bytes,4,rep,name=contracts,proto3" json:"contracts,omitempty"` + Contracts []PoEContract `protobuf:"bytes,5,rep,name=contracts,proto3" json:"contracts,omitempty"` // Engagement weighted members of the engagement group. Validators should be // in here. - Engagement []TG4Member `protobuf:"bytes,5,rep,name=engagement,proto3" json:"engagement,omitempty"` + Engagement []TG4Member `protobuf:"bytes,6,rep,name=engagement,proto3" json:"engagement,omitempty"` // BondDenom defines the bondable coin denomination. - BondDenom string `protobuf:"bytes,6,opt,name=bond_denom,json=bondDenom,proto3" json:"bond_denom,omitempty" yaml:"bond_denom"` + BondDenom string `protobuf:"bytes,7,opt,name=bond_denom,json=bondDenom,proto3" json:"bond_denom,omitempty" yaml:"bond_denom"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -79,6 +81,13 @@ func (m *GenesisState) XXX_DiscardUnknown() { var xxx_messageInfo_GenesisState proto.InternalMessageInfo +func (m *GenesisState) GetParams() Params { + if m != nil { + return m.Params + } + return Params{} +} + func (m *GenesisState) GetSeedContracts() bool { if m != nil { return m.SeedContracts @@ -239,40 +248,42 @@ func init() { func init() { proto.RegisterFile("confio/poe/v1beta1/genesis.proto", fileDescriptor_a165193bab811d9d) } var fileDescriptor_a165193bab811d9d = []byte{ - // 528 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x52, 0x41, 0x6f, 0xd3, 0x4c, - 0x10, 0x8d, 0x9b, 0x7c, 0x69, 0xb3, 0x4d, 0x2a, 0x7d, 0x4b, 0x90, 0xac, 0x50, 0xec, 0xc8, 0x05, - 0x29, 0x07, 0x64, 0xd3, 0x52, 0x09, 0x89, 0x03, 0x52, 0x0d, 0xa8, 0x5c, 0x2a, 0x55, 0x6e, 0x4e, - 0xe5, 0x60, 0xad, 0xed, 0x61, 0x6b, 0x84, 0x77, 0x4d, 0x76, 0x21, 0xc9, 0xbf, 0xe0, 0x67, 0xf0, - 0x53, 0x7a, 0xec, 0x91, 0x93, 0x85, 0x92, 0x5b, 0x8e, 0x3d, 0x72, 0x42, 0xbb, 0x4e, 0xe2, 0x48, - 0x44, 0xe2, 0x62, 0xef, 0xcc, 0x9b, 0x79, 0xfb, 0xe6, 0xed, 0xa0, 0x7e, 0xcc, 0xd9, 0xc7, 0x94, - 0x7b, 0x39, 0x07, 0xef, 0xdb, 0x71, 0x04, 0x92, 0x1c, 0x7b, 0x14, 0x18, 0x88, 0x54, 0xb8, 0xf9, - 0x88, 0x4b, 0x8e, 0x71, 0x59, 0xe1, 0xe6, 0x1c, 0xdc, 0x65, 0x45, 0xaf, 0x4b, 0x39, 0xe5, 0x1a, - 0xf6, 0xd4, 0xa9, 0xac, 0xec, 0x59, 0x31, 0x17, 0x19, 0x17, 0x5e, 0x44, 0x44, 0x45, 0x16, 0xf3, - 0x94, 0x2d, 0xf1, 0x23, 0x85, 0x8f, 0x89, 0xc8, 0x3c, 0xfd, 0xd9, 0x7a, 0x5d, 0xef, 0x70, 0x8b, - 0x20, 0x75, 0xb5, 0x46, 0x9d, 0x1f, 0x75, 0xd4, 0x3e, 0x2f, 0xeb, 0xaf, 0x24, 0x91, 0x80, 0x9f, - 0xa2, 0x03, 0x01, 0x90, 0x84, 0x31, 0x67, 0x72, 0x44, 0x62, 0x29, 0x4c, 0xa3, 0x6f, 0x0c, 0xf6, - 0x82, 0x8e, 0xca, 0xbe, 0x59, 0x25, 0xf1, 0x25, 0xda, 0xa5, 0xc0, 0x42, 0x39, 0x11, 0xe6, 0x4e, - 0xbf, 0x3e, 0x68, 0xfb, 0x2f, 0x17, 0x85, 0xdd, 0xa4, 0xc0, 0xe4, 0x44, 0xdc, 0x17, 0x76, 0x67, - 0x4a, 0xb2, 0xcf, 0xaf, 0x9c, 0x32, 0x76, 0x7e, 0x17, 0xb6, 0x09, 0x2c, 0xe6, 0x49, 0xca, 0xa8, - 0xf7, 0x49, 0x70, 0xe6, 0x06, 0x64, 0x7c, 0x01, 0x42, 0x10, 0x0a, 0x81, 0x6a, 0x1a, 0x4e, 0x04, - 0x7e, 0x8e, 0xba, 0x62, 0x2a, 0x24, 0x64, 0x21, 0x49, 0xb2, 0x94, 0x85, 0x24, 0x49, 0x46, 0x20, - 0x84, 0x59, 0xef, 0x1b, 0x83, 0x56, 0x80, 0x4b, 0xec, 0x4c, 0x41, 0x67, 0x25, 0x82, 0xaf, 0x51, - 0xab, 0x52, 0xd9, 0xe8, 0xd7, 0x07, 0xfb, 0x27, 0xb6, 0xfb, 0xb7, 0xb9, 0xee, 0x25, 0x7f, 0xb7, - 0x12, 0xee, 0x3f, 0xba, 0x2d, 0xec, 0xda, 0xa2, 0xb0, 0x1f, 0xac, 0x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0x6e, 0xad, 0xa4, 0x23, 0x92, 0x80, 0x37, 0xd1, 0xeb, 0xab, 0xc6, 0x14, 0x51, 0x53, 0x6f, - 0xee, 0x8b, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x4f, 0x9d, 0x43, 0x68, 0x6a, 0x03, 0x00, 0x00, + // 550 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x52, 0x4f, 0x6f, 0xd3, 0x4e, + 0x10, 0x8d, 0x9b, 0xfc, 0xd2, 0x66, 0xfb, 0x47, 0xfa, 0x2d, 0x45, 0xb2, 0x42, 0xb1, 0x23, 0x17, + 0xa4, 0x1c, 0x90, 0x4d, 0x4b, 0x25, 0x10, 0x07, 0xa4, 0x1a, 0x50, 0xb9, 0x54, 0xaa, 0xdc, 0x9e, + 0xca, 0xc1, 0x5a, 0xdb, 0xc3, 0xd6, 0x88, 0xdd, 0x35, 0xde, 0x85, 0x26, 0xdf, 0x82, 0x8f, 0xd5, + 0x63, 0x8f, 0x9c, 0x2c, 0x94, 0xde, 0x7a, 0xec, 0x91, 0x13, 0xda, 0xb5, 0x53, 0x47, 0x22, 0x12, + 0x17, 0x7b, 0x67, 0xde, 0x9b, 0xb7, 0xf3, 0x66, 0x07, 0x8d, 0x52, 0xc1, 0x3f, 0xe5, 0x22, 0x28, + 0x04, 0x04, 0xdf, 0xf7, 0x12, 0x50, 0x64, 0x2f, 0xa0, 0xc0, 0x41, 0xe6, 0xd2, 0x2f, 0x4a, 0xa1, + 0x04, 0xc6, 0x35, 0xc3, 0x2f, 0x04, 0xf8, 0x0d, 0x63, 0xb8, 0x4d, 0x05, 0x15, 0x06, 0x0e, 0xf4, + 0xa9, 0x66, 0x0e, 0x9d, 0x54, 0x48, 0x26, 0x64, 0x90, 0x10, 0xd9, 0x8a, 0xa5, 0x22, 0xe7, 0x0d, + 0xbe, 0xab, 0xf1, 0x4b, 0x22, 0x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 0xcd, + 0xd5, 0xc5, 0xb7, 0xc4, 0x4f, 0x05, 0x0b, 0x9a, 0x7d, 0x57, 0xb4, 0x24, 0x19, 0x04, 0x13, 0xb3, + 0xf8, 0xda, 0xa6, 0x4c, 0xfa, 0x66, 0xe7, 0x5f, 0xfc, 0x09, 0x00, 0x00, 0xff, 0xff, 0x69, 0xfd, + 0xd8, 0xbc, 0xa4, 0x03, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -300,7 +311,7 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.BondDenom) i = encodeVarintGenesis(dAtA, i, uint64(len(m.BondDenom))) i-- - dAtA[i] = 0x32 + dAtA[i] = 0x3a } if len(m.Engagement) > 0 { for iNdEx := len(m.Engagement) - 1; iNdEx >= 0; iNdEx-- { @@ -313,7 +324,7 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x2a + dAtA[i] = 0x32 } } if len(m.Contracts) > 0 { @@ -327,7 +338,7 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { i = encodeVarintGenesis(dAtA, i, uint64(size)) } i-- - dAtA[i] = 0x22 + dAtA[i] = 0x2a } } if len(m.SystemAdminAddress) > 0 { @@ -335,7 +346,7 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.SystemAdminAddress) i = encodeVarintGenesis(dAtA, i, uint64(len(m.SystemAdminAddress))) i-- - dAtA[i] = 0x1a + dAtA[i] = 0x22 } if len(m.GenTxs) > 0 { for iNdEx := len(m.GenTxs) - 1; iNdEx >= 0; iNdEx-- { @@ -343,7 +354,7 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { copy(dAtA[i:], m.GenTxs[iNdEx]) i = encodeVarintGenesis(dAtA, i, uint64(len(m.GenTxs[iNdEx]))) i-- - dAtA[i] = 0x12 + dAtA[i] = 0x1a } } if m.SeedContracts { @@ -354,8 +365,18 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { dAtA[i] = 0 } i-- - dAtA[i] = 0x8 + dAtA[i] = 0x10 + } + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -446,6 +467,8 @@ func (m *GenesisState) Size() (n int) { } var l int _ = l + l = m.Params.Size() + n += 1 + l + sovGenesis(uint64(l)) if m.SeedContracts { n += 2 } @@ -546,6 +569,39 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field SeedContracts", wireType) } @@ -565,7 +621,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } } m.SeedContracts = bool(v != 0) - case 2: + case 3: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field GenTxs", wireType) } @@ -597,7 +653,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { m.GenTxs = append(m.GenTxs, make([]byte, postIndex-iNdEx)) copy(m.GenTxs[len(m.GenTxs)-1], dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 3: + case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field SystemAdminAddress", wireType) } @@ -629,7 +685,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { } m.SystemAdminAddress = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex - case 4: + case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Contracts", wireType) } @@ -663,7 +719,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 5: + case 6: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Engagement", wireType) } @@ -697,7 +753,7 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex - case 6: + case 7: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field BondDenom", wireType) } diff --git a/x/poe/types/keys.go b/x/poe/types/keys.go index daa09725..1b4dc8c0 100644 --- a/x/poe/types/keys.go +++ b/x/poe/types/keys.go @@ -18,4 +18,5 @@ const ( var ( SystemAdminPrefix = []byte{0x01} ContractPrefix = []byte{0x02} + HistoricalInfoKey = []byte{0x03} ) diff --git a/x/poe/types/params.go b/x/poe/types/params.go new file mode 100644 index 00000000..7391acef --- /dev/null +++ b/x/poe/types/params.go @@ -0,0 +1,69 @@ +package types + +import ( + "fmt" + yaml "gopkg.in/yaml.v2" + + paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" +) + +// PoE params default values +const ( + + // DefaultHistoricalEntries entries is 10000. Apps that don't use IBC can ignore this + // value by not adding the staking module to the application module manager's + // SetOrderBeginBlockers. + DefaultHistoricalEntries uint32 = 10000 +) + +var ( + KeyHistoricalEntries = []byte("HistoricalEntries") +) + +var _ paramtypes.ParamSet = (*Params)(nil) + +// ParamKeyTable for PoE module +func ParamKeyTable() paramtypes.KeyTable { + return paramtypes.NewKeyTable().RegisterParamSet(&Params{}) +} + +// NewParams creates a new Params instance +func NewParams(historicalEntries uint32) Params { + return Params{ + HistoricalEntries: historicalEntries, + } +} + +// ParamSetPairs Implements params.ParamSet +func (p *Params) ParamSetPairs() paramtypes.ParamSetPairs { + return paramtypes.ParamSetPairs{ + paramtypes.NewParamSetPair(KeyHistoricalEntries, &p.HistoricalEntries, validateHistoricalEntries), + } +} + +// DefaultParams returns a default set of parameters. +func DefaultParams() Params { + return NewParams( + DefaultHistoricalEntries, + ) +} + +// String returns a human readable string representation of the parameters. +func (p Params) String() string { + out, _ := yaml.Marshal(p) + return string(out) +} + +// Validate validate a set of params +func (p Params) Validate() error { + return nil +} + +func validateHistoricalEntries(i interface{}) error { + _, ok := i.(uint32) + if !ok { + return fmt.Errorf("invalid parameter type: %T", i) + } + + return nil +} diff --git a/x/poe/types/poe.pb.go b/x/poe/types/poe.pb.go index 50867892..4f15c2a8 100644 --- a/x/poe/types/poe.pb.go +++ b/x/poe/types/poe.pb.go @@ -14,7 +14,9 @@ import ( _ "github.com/tendermint/tendermint/proto/tendermint/types" _ "google.golang.org/protobuf/types/known/durationpb" _ "google.golang.org/protobuf/types/known/timestamppb" + io "io" math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -63,37 +65,323 @@ func (PoEContractType) EnumDescriptor() ([]byte, []int) { return fileDescriptor_df6d9ea68813554a, []int{0} } +// Params defines the parameters for the PoE module. +type Params struct { + // historical_entries is the number of historical entries to persist. + HistoricalEntries uint32 `protobuf:"varint,4,opt,name=historical_entries,json=historicalEntries,proto3" json:"historical_entries,omitempty" yaml:"historical_entries"` +} + +func (m *Params) Reset() { *m = Params{} } +func (*Params) ProtoMessage() {} +func (*Params) Descriptor() ([]byte, []int) { + return fileDescriptor_df6d9ea68813554a, []int{0} +} +func (m *Params) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *Params) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_Params.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 *Params) XXX_Merge(src proto.Message) { + xxx_messageInfo_Params.Merge(m, src) +} +func (m *Params) XXX_Size() int { + return m.Size() +} +func (m *Params) XXX_DiscardUnknown() { + xxx_messageInfo_Params.DiscardUnknown(m) +} + +var xxx_messageInfo_Params proto.InternalMessageInfo + +func (m *Params) GetHistoricalEntries() uint32 { + if m != nil { + return m.HistoricalEntries + } + return 0 +} + func init() { proto.RegisterEnum("confio.poe.v1beta1.PoEContractType", PoEContractType_name, PoEContractType_value) + proto.RegisterType((*Params)(nil), "confio.poe.v1beta1.Params") } func init() { proto.RegisterFile("confio/poe/v1beta1/poe.proto", fileDescriptor_df6d9ea68813554a) } var fileDescriptor_df6d9ea68813554a = []byte{ - // 397 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x5c, 0x92, 0x41, 0x8b, 0xd3, 0x40, - 0x14, 0xc7, 0x13, 0x5d, 0x57, 0x9c, 0x8b, 0x21, 0xac, 0xb2, 0x1d, 0xea, 0x18, 0x70, 0x45, 0x50, - 0xec, 0xb0, 0x78, 0x17, 0xaa, 0x3b, 0x96, 0xa2, 0x0d, 0x62, 0xd3, 0x22, 0x5e, 0x64, 0x92, 0x4c, - 0xc7, 0xc1, 0x66, 0x5e, 0x48, 0xa6, 0xd2, 0x7e, 0x03, 0xc9, 0xc9, 0x2f, 0x90, 0x93, 0x5f, 0xc6, - 0x63, 0x8f, 0x1e, 0xa5, 0xbd, 0xf8, 0x31, 0xa4, 0x99, 0xd4, 0x85, 0x5c, 0xc2, 0xfb, 0xe7, 0xf7, - 0xe3, 0xcd, 0xe3, 0xf1, 0x50, 0x3f, 0x01, 0xbd, 0x50, 0x40, 0x73, 0x10, 0xf4, 0xdb, 0x65, 0x2c, - 0x0c, 0xbf, 0x3c, 0xd4, 0x83, 0xbc, 0x00, 0x03, 0xbe, 0x6f, 0xe9, 0xe0, 0xf0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xb1, 0x09, 0x0b, 0x23, 0xef, 0x26, 0x7e, 0x50, 0xd5, 0x41, 0xaf, 0xa3, 0x32, 0x2d, - 0xb9, 0x14, 0x99, 0xd0, 0xc6, 0x7f, 0x84, 0x6e, 0x4d, 0xc6, 0x1f, 0xd9, 0x07, 0xef, 0x04, 0x9f, - 0x57, 0x75, 0x70, 0xd6, 0x31, 0x27, 0x6a, 0x2d, 0x0a, 0x7c, 0xf2, 0xfd, 0x27, 0x71, 0x5e, 0xbd, - 0xfc, 0xb5, 0x23, 0xee, 0x76, 0x47, 0xdc, 0x3f, 0x3b, 0xe2, 0xfe, 0xd8, 0x13, 0x67, 0xbb, 0x27, - 0xce, 0xef, 0x3d, 0x71, 0x3e, 0x5d, 0x48, 0x65, 0xbe, 0xac, 0xe2, 0x41, 0x02, 0x19, 0x6d, 0x4f, - 0xc6, 0xc8, 0x82, 0xa7, 0x82, 0xae, 0x9b, 0xdb, 0x69, 0x16, 0x16, 0x9f, 0x36, 0x1b, 0x7b, 0xf1, - 0x2f, 0x00, 0x00, 0xff, 0xff, 0x40, 0xba, 0x2a, 0x86, 0x56, 0x02, 0x00, 0x00, + // 465 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x64, 0x92, 0x41, 0x8b, 0xd3, 0x40, + 0x14, 0xc7, 0x13, 0xad, 0x55, 0x07, 0xc4, 0x18, 0x56, 0x69, 0x43, 0x37, 0x0d, 0x75, 0x45, 0x51, + 0x6c, 0x58, 0xbc, 0xed, 0x41, 0xe8, 0xba, 0x63, 0x29, 0x6e, 0xc3, 0xb2, 0xed, 0x2e, 0xe2, 0x65, + 0x9d, 0x24, 0xd3, 0xd9, 0xc1, 0x66, 0x26, 0xcc, 0x4c, 0x65, 0xfb, 0x0d, 0x24, 0x27, 0x8f, 0x5e, + 0x02, 0x0b, 0x7e, 0x19, 0x8f, 0x7b, 0xf4, 0x24, 0xd2, 0x5e, 0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, 0x40, 0x31, 0xf6, 0x2f, 0x8a, 0xeb, 0x2c, 0x56, 0x12, 0xd6, + 0x8b, 0x9d, 0xbc, 0xfa, 0x1b, 0x00, 0x00, 0xff, 0xff, 0x33, 0xbe, 0xb7, 0x0e, 0xb8, 0x02, 0x00, + 0x00, +} + +func (this *Params) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*Params) + if !ok { + that2, ok := that.(Params) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.HistoricalEntries != that1.HistoricalEntries { + return false + } + return true } +func (m *Params) 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 *Params) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *Params) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if m.HistoricalEntries != 0 { + i = encodeVarintPoe(dAtA, i, uint64(m.HistoricalEntries)) + i-- + dAtA[i] = 0x20 + } + return len(dAtA) - i, nil +} + +func encodeVarintPoe(dAtA []byte, offset int, v uint64) int { + offset -= sovPoe(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *Params) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.HistoricalEntries != 0 { + n += 1 + sovPoe(uint64(m.HistoricalEntries)) + } + return n +} + +func sovPoe(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozPoe(x uint64) (n int) { + return sovPoe(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *Params) 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 ErrIntOverflowPoe + } + 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: Params: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: Params: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field HistoricalEntries", wireType) + } + m.HistoricalEntries = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowPoe + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.HistoricalEntries |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + default: + iNdEx = preIndex + skippy, err := skipPoe(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthPoe + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipPoe(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPoe + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPoe + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowPoe + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthPoe + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupPoe + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthPoe + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthPoe = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowPoe = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupPoe = fmt.Errorf("proto: unexpected end of group") +)