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

R4R: Auth Module Param Store #2998

Merged
merged 28 commits into from
Dec 20, 2018
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
436930c
Move auth types to new types package with params
Dec 4, 2018
0975772
Slight cleanup of account keeper
Dec 4, 2018
70d127c
Cleanup and update unit tests
Dec 4, 2018
762982a
Update auth module to use params
Dec 5, 2018
d84ce10
Update consumeSignatureVerificationGas panic
Dec 5, 2018
2ee7a46
Update genesis logic
Dec 5, 2018
d24232e
Update existing app param keeper init
Dec 5, 2018
b2a5b70
Update unit tests account keeper usage
Dec 5, 2018
58a72cb
Merge branch 'develop' into bez/2996-auth-param-store
jackzampolin Dec 6, 2018
bc3427b
Reduce number of changes
Dec 6, 2018
7169d16
Merge branch 'develop' into bez/2996-auth-param-store
Dec 6, 2018
c805972
Make countSubKeys private
Dec 6, 2018
75fbce8
Add PENDING log
Dec 6, 2018
6c182a5
Merge branch 'develop' into bez/2996-auth-param-store
Dec 10, 2018
6e42e60
Remove gasPerUnitCost from auth params
Dec 10, 2018
077c623
Merge branch 'develop' into bez/2996-auth-param-store
Dec 10, 2018
7fb1389
Merge branch 'develop' into bez/2996-auth-param-store
Dec 11, 2018
73d2601
Remove auth context
Dec 13, 2018
3d6fc31
Add ref TODO
Dec 13, 2018
8ab1704
Merge branch 'develop' into bez/2996-auth-param-store
Dec 13, 2018
a200051
Add auth genesis validation
Dec 13, 2018
5276247
Add auth sim params
Dec 13, 2018
d50889f
Fix sim auth params
Dec 13, 2018
0b47963
Merge branch 'develop' into bez/2996-auth-param-store
Dec 18, 2018
bc5c147
Merge branch 'develop' into bez/2996-auth-param-store
Dec 19, 2018
301ee4e
Minor cleanup
Dec 19, 2018
039e7eb
Merge branch 'develop' into bez/2996-auth-param-store
Dec 20, 2018
77b9d23
Update GaiaValidateGenesisState
Dec 20, 2018
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: 2 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ FEATURES
* Gaia

* SDK
* \#2996 Update the `AccountKeeper` to contain params used in the context of
the ante handler.

* Tendermint

Expand Down
11 changes: 5 additions & 6 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
tkeyParams: sdk.NewTransientStoreKey("transient_params"),
}

app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams)

// define the accountKeeper
app.accountKeeper = auth.NewAccountKeeper(
app.cdc,
app.keyAccount, // target store
app.keyAccount, // target store
app.paramsKeeper.Subspace(auth.DefaultParamspace),
auth.ProtoBaseAccount, // prototype
)

Expand All @@ -103,10 +106,6 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
app.cdc,
app.keyFeeCollection,
)
app.paramsKeeper = params.NewKeeper(
app.cdc,
app.keyParams, app.tkeyParams,
)
stakeKeeper := stake.NewKeeper(
app.cdc,
app.keyStake, app.tkeyStake,
Expand Down Expand Up @@ -244,7 +243,7 @@ func (app *GaiaApp) initFromGenesisState(ctx sdk.Context, genesisState GenesisSt
}

// initialize module-specific stores
auth.InitGenesis(ctx, app.feeCollectionKeeper, genesisState.AuthData)
auth.InitGenesis(ctx, app.accountKeeper, app.feeCollectionKeeper, genesisState.AuthData)
slashing.InitGenesis(ctx, app.slashingKeeper, genesisState.SlashingData, genesisState.StakeData)
gov.InitGenesis(ctx, app.govKeeper, genesisState.GovData)
mint.InitGenesis(ctx, app.mintKeeper, genesisState.MintData)
Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func (app *GaiaApp) ExportAppStateAndValidators(forZeroHeight bool) (

genState := NewGenesisState(
accounts,
auth.ExportGenesis(ctx, app.feeCollectionKeeper),
auth.ExportGenesis(ctx, app.accountKeeper, app.feeCollectionKeeper),
stake.ExportGenesis(ctx, app.stakeKeeper),
mint.ExportGenesis(ctx, app.mintKeeper),
distr.ExportGenesis(ctx, app.distrKeeper),
Expand Down
1 change: 1 addition & 0 deletions cmd/gaia/app/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func GaiaAppGenState(cdc *codec.Codec, genDoc tmtypes.GenesisDoc, appGenTxs []js
func NewDefaultGenesisState() GenesisState {
return GenesisState{
Accounts: nil,
AuthData: auth.DefaultGenesisState(),
StakeData: stake.DefaultGenesisState(),
MintData: mint.DefaultGenesisState(),
DistrData: distr.DefaultGenesisState(),
Expand Down
6 changes: 4 additions & 2 deletions cmd/gaia/cmd/gaiadebug/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,18 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp
tkeyParams: sdk.NewTransientStoreKey("transient_params"),
}

app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams)

// define the accountKeeper
app.accountKeeper = auth.NewAccountKeeper(
app.cdc,
app.keyAccount, // target store
app.keyAccount, // target store
app.paramsKeeper.Subspace(auth.DefaultParamspace),
auth.ProtoBaseAccount, // prototype
)

// add handlers
app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper)
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams)
app.stakeKeeper = stake.NewKeeper(app.cdc, app.keyStake, app.tkeyStake, app.bankKeeper, app.paramsKeeper.Subspace(stake.DefaultParamspace), stake.DefaultCodespace)
app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, app.stakeKeeper, app.paramsKeeper.Subspace(slashing.DefaultParamspace), slashing.DefaultCodespace)

Expand Down
9 changes: 9 additions & 0 deletions docs/examples/basecoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/ibc"
"github.com/cosmos/cosmos-sdk/x/params"
abci "github.com/tendermint/tendermint/abci/types"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
Expand Down Expand Up @@ -40,12 +41,15 @@ type BasecoinApp struct {
keyMain *sdk.KVStoreKey
keyAccount *sdk.KVStoreKey
keyIBC *sdk.KVStoreKey
keyParams *sdk.KVStoreKey
tkeyParams *sdk.TransientStoreKey

// manage getting and setting accounts
accountKeeper auth.AccountKeeper
feeCollectionKeeper auth.FeeCollectionKeeper
bankKeeper bank.Keeper
ibcMapper ibc.Mapper
paramsKeeper params.Keeper
}

// NewBasecoinApp returns a reference to a new BasecoinApp given a logger and
Expand All @@ -64,12 +68,17 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba
keyMain: sdk.NewKVStoreKey("main"),
keyAccount: sdk.NewKVStoreKey("acc"),
keyIBC: sdk.NewKVStoreKey("ibc"),
keyParams: sdk.NewKVStoreKey("params"),
tkeyParams: sdk.NewTransientStoreKey("transient_params"),
}

app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams)

// define and attach the mappers and keepers
app.accountKeeper = auth.NewAccountKeeper(
cdc,
app.keyAccount, // target store
app.paramsKeeper.Subspace(auth.DefaultParamspace),
func() auth.Account {
return &types.AppAccount{}
},
Expand Down
11 changes: 10 additions & 1 deletion docs/examples/democoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/ibc"
"github.com/cosmos/cosmos-sdk/x/params"

"github.com/cosmos/cosmos-sdk/docs/examples/democoin/types"
"github.com/cosmos/cosmos-sdk/docs/examples/democoin/x/cool"
Expand Down Expand Up @@ -45,8 +46,11 @@ type DemocoinApp struct {
capKeyPowStore *sdk.KVStoreKey
capKeyIBCStore *sdk.KVStoreKey
capKeyStakingStore *sdk.KVStoreKey
keyParams *sdk.KVStoreKey
tkeyParams *sdk.TransientStoreKey

// keepers
paramsKeeper params.Keeper
feeCollectionKeeper auth.FeeCollectionKeeper
bankKeeper bank.Keeper
coolKeeper cool.Keeper
Expand All @@ -72,13 +76,18 @@ func NewDemocoinApp(logger log.Logger, db dbm.DB) *DemocoinApp {
capKeyPowStore: sdk.NewKVStoreKey("pow"),
capKeyIBCStore: sdk.NewKVStoreKey("ibc"),
capKeyStakingStore: sdk.NewKVStoreKey("stake"),
keyParams: sdk.NewKVStoreKey("params"),
tkeyParams: sdk.NewTransientStoreKey("transient_params"),
}

app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams)

// Define the accountKeeper.
app.accountKeeper = auth.NewAccountKeeper(
cdc,
app.capKeyAccountStore, // target store
types.ProtoAppAccount, // prototype
app.paramsKeeper.Subspace(auth.DefaultParamspace),
types.ProtoAppAccount, // prototype
)

// Add handlers.
Expand Down
38 changes: 28 additions & 10 deletions docs/examples/democoin/x/cool/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,44 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
auth "github.com/cosmos/cosmos-sdk/x/auth"
bank "github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/params"
)

func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey) {
type testInput struct {
cdc *codec.Codec
ctx sdk.Context
capKey *sdk.KVStoreKey
bk bank.BaseKeeper
}

func setupTestInput() testInput {
db := dbm.NewMemDB()

cdc := codec.New()
auth.RegisterBaseAccount(cdc)

capKey := sdk.NewKVStoreKey("capkey")
keyParams := sdk.NewKVStoreKey("params")
tkeyParams := sdk.NewTransientStoreKey("transient_params")

ms := store.NewCommitMultiStore(db)
ms.MountStoreWithDB(capKey, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyParams, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(tkeyParams, sdk.StoreTypeTransient, db)
ms.LoadLatestVersion()
return ms, capKey

pk := params.NewKeeper(cdc, keyParams, tkeyParams)
ak := auth.NewAccountKeeper(cdc, capKey, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount)
bk := bank.NewBaseKeeper(ak)
ctx := sdk.NewContext(ms, abci.Header{}, false, nil)

return testInput{cdc: cdc, ctx: ctx, capKey: capKey, bk: bk}
}

func TestCoolKeeper(t *testing.T) {
ms, capKey := setupMultiStore()
cdc := codec.New()
auth.RegisterBaseAccount(cdc)

am := auth.NewAccountKeeper(cdc, capKey, auth.ProtoBaseAccount)
ctx := sdk.NewContext(ms, abci.Header{}, false, nil)
ck := bank.NewBaseKeeper(am)
keeper := NewKeeper(capKey, ck, DefaultCodespace)
input := setupTestInput()
keeper := NewKeeper(input.capKey, input.bk, DefaultCodespace)
ctx := input.ctx

err := InitGenesis(ctx, keeper, Genesis{"icy"})
require.Nil(t, err)
Expand Down
16 changes: 3 additions & 13 deletions docs/examples/democoin/x/pow/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,15 @@ import (

"github.com/stretchr/testify/require"

abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/libs/log"

codec "github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
auth "github.com/cosmos/cosmos-sdk/x/auth"
bank "github.com/cosmos/cosmos-sdk/x/bank"
)

func TestPowHandler(t *testing.T) {
ms, capKey := setupMultiStore()
cdc := codec.New()
auth.RegisterBaseAccount(cdc)
input := setupTestInput()
ctx := input.ctx

am := auth.NewAccountKeeper(cdc, capKey, auth.ProtoBaseAccount)
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger())
config := NewConfig("pow", int64(1))
ck := bank.NewBaseKeeper(am)
keeper := NewKeeper(capKey, config, ck, DefaultCodespace)
keeper := NewKeeper(input.capKey, config, input.bk, DefaultCodespace)

handler := keeper.Handler

Expand Down
38 changes: 27 additions & 11 deletions docs/examples/democoin/x/pow/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,52 @@ import (

abci "github.com/tendermint/tendermint/abci/types"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
auth "github.com/cosmos/cosmos-sdk/x/auth"
bank "github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/params"
)

// possibly share this kind of setup functionality between module testsuites?
func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey) {
type testInput struct {
cdc *codec.Codec
ctx sdk.Context
capKey *sdk.KVStoreKey
bk bank.BaseKeeper
}

func setupTestInput() testInput {
db := dbm.NewMemDB()

cdc := codec.New()
auth.RegisterBaseAccount(cdc)

capKey := sdk.NewKVStoreKey("capkey")
keyParams := sdk.NewKVStoreKey("params")
tkeyParams := sdk.NewTransientStoreKey("transient_params")

ms := store.NewCommitMultiStore(db)
ms.MountStoreWithDB(capKey, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyParams, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(tkeyParams, sdk.StoreTypeTransient, db)
ms.LoadLatestVersion()

return ms, capKey
pk := params.NewKeeper(cdc, keyParams, tkeyParams)
ak := auth.NewAccountKeeper(cdc, capKey, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount)
bk := bank.NewBaseKeeper(ak)
ctx := sdk.NewContext(ms, abci.Header{}, false, nil)

return testInput{cdc: cdc, ctx: ctx, capKey: capKey, bk: bk}
}

func TestPowKeeperGetSet(t *testing.T) {
ms, capKey := setupMultiStore()
cdc := codec.New()
auth.RegisterBaseAccount(cdc)
input := setupTestInput()
ctx := input.ctx

am := auth.NewAccountKeeper(cdc, capKey, auth.ProtoBaseAccount)
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger())
config := NewConfig("pow", int64(1))
ck := bank.NewBaseKeeper(am)
keeper := NewKeeper(capKey, config, ck, DefaultCodespace)
keeper := NewKeeper(input.capKey, config, input.bk, DefaultCodespace)

err := InitGenesis(ctx, keeper, Genesis{uint64(1), uint64(0)})
require.Nil(t, err)
Expand Down
50 changes: 31 additions & 19 deletions docs/examples/democoin/x/simplestake/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,51 @@ import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/tendermint/tendermint/crypto/ed25519"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/libs/log"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/auth"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/params"
)

func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey, *sdk.KVStoreKey) {
type testInput struct {
cdc *codec.Codec
ctx sdk.Context
capKey *sdk.KVStoreKey
bk bank.BaseKeeper
}

func setupTestInput() testInput {
db := dbm.NewMemDB()
authKey := sdk.NewKVStoreKey("authkey")

cdc := codec.New()
auth.RegisterBaseAccount(cdc)

capKey := sdk.NewKVStoreKey("capkey")
keyParams := sdk.NewKVStoreKey("params")
tkeyParams := sdk.NewTransientStoreKey("transient_params")

ms := store.NewCommitMultiStore(db)
ms.MountStoreWithDB(capKey, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(authKey, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(keyParams, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(tkeyParams, sdk.StoreTypeTransient, db)
ms.LoadLatestVersion()
return ms, authKey, capKey

pk := params.NewKeeper(cdc, keyParams, tkeyParams)
ak := auth.NewAccountKeeper(cdc, capKey, pk.Subspace(auth.DefaultParamspace), auth.ProtoBaseAccount)
bk := bank.NewBaseKeeper(ak)
ctx := sdk.NewContext(ms, abci.Header{}, false, nil)

return testInput{cdc: cdc, ctx: ctx, capKey: capKey, bk: bk}
}

func TestKeeperGetSet(t *testing.T) {
ms, authKey, capKey := setupMultiStore()
cdc := codec.New()
auth.RegisterBaseAccount(cdc)
input := setupTestInput()
ctx := input.ctx

accountKeeper := auth.NewAccountKeeper(cdc, authKey, auth.ProtoBaseAccount)
stakeKeeper := NewKeeper(capKey, bank.NewBaseKeeper(accountKeeper), DefaultCodespace)
ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger())
stakeKeeper := NewKeeper(input.capKey, input.bk, DefaultCodespace)
addr := sdk.AccAddress([]byte("some-address"))

bi := stakeKeeper.getBondInfo(ctx, addr)
Expand All @@ -59,15 +76,10 @@ func TestKeeperGetSet(t *testing.T) {
}

func TestBonding(t *testing.T) {
ms, authKey, capKey := setupMultiStore()
cdc := codec.New()
auth.RegisterBaseAccount(cdc)

ctx := sdk.NewContext(ms, abci.Header{}, false, log.NewNopLogger())
input := setupTestInput()
ctx := input.ctx

accountKeeper := auth.NewAccountKeeper(cdc, authKey, auth.ProtoBaseAccount)
bankKeeper := bank.NewBaseKeeper(accountKeeper)
stakeKeeper := NewKeeper(capKey, bankKeeper, DefaultCodespace)
stakeKeeper := NewKeeper(input.capKey, input.bk, DefaultCodespace)
addr := sdk.AccAddress([]byte("some-address"))
privKey := ed25519.GenPrivKey()
pubKey := privKey.PubKey()
Expand Down
Loading