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: Added bank module's total supply feature #2939

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from 22 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
6 changes: 4 additions & 2 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type GaiaApp struct {
// keys to access the substores
keyMain *sdk.KVStoreKey
keyAccount *sdk.KVStoreKey
keyBank *sdk.KVStoreKey
keyStake *sdk.KVStoreKey
tkeyStake *sdk.TransientStoreKey
keySlashing *sdk.KVStoreKey
Expand Down Expand Up @@ -78,6 +79,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
cdc: cdc,
keyMain: sdk.NewKVStoreKey("main"),
keyAccount: sdk.NewKVStoreKey("acc"),
keyBank: sdk.NewKVStoreKey("bank"),
keyStake: sdk.NewKVStoreKey("stake"),
tkeyStake: sdk.NewTransientStoreKey("transient_stake"),
keyMint: sdk.NewKVStoreKey("mint"),
Expand All @@ -98,7 +100,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
)

// add handlers
app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper)
app.bankKeeper = bank.NewBaseKeeper(app.cdc, app.accountKeeper, app.keyBank)
app.feeCollectionKeeper = auth.NewFeeCollectionKeeper(
app.cdc,
app.keyFeeCollection,
Expand Down Expand Up @@ -157,7 +159,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, traceStore io.Writer, baseAppOptio
AddRoute("stake", stake.NewQuerier(app.stakeKeeper, app.cdc))

// initialize BaseApp
app.MountStores(app.keyMain, app.keyAccount, app.keyStake, app.keyMint, app.keyDistr,
app.MountStores(app.keyMain, app.keyAccount, app.keyBank, app.keyStake, app.keyMint, app.keyDistr,
app.keySlashing, app.keyGov, app.keyFeeCollection, app.keyParams)
app.SetInitChainer(app.initChainer)
app.SetBeginBlocker(app.BeginBlocker)
Expand Down
3 changes: 1 addition & 2 deletions cmd/gaia/app/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ func (app *GaiaApp) runtimeInvariants() []simulation.Invariant {
return []simulation.Invariant{
banksim.NonnegativeBalanceInvariant(app.accountKeeper),
distrsim.ValAccumInvariants(app.distrKeeper, app.stakeKeeper),
stakesim.SupplyInvariants(app.bankKeeper, app.stakeKeeper,
app.feeCollectionKeeper, app.distrKeeper, app.accountKeeper),
stakesim.BondedAmountInvariants(app.stakeKeeper),
stakesim.NonNegativePowerInvariant(app.stakeKeeper),
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/gaia/cli_test/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func TestGaiaCLICreateValidator(t *testing.T) {
params := executeGetParams(t, fmt.Sprintf("gaiacli query stake parameters %v", flags))
require.True(t, defaultParams.Equal(params))

pool := executeGetPool(t, fmt.Sprintf("gaiacli query stake pool %v", flags))
pool := executeGetPool(t, fmt.Sprintf("gaiacli query stake pool %v --output=json", flags))
require.Equal(t, initialPool.BondedTokens, pool.BondedTokens)
cleanupDirs(gaiadHome, gaiacliHome)
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/gaia/cmd/gaiadebug/hack.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ type GaiaApp struct {
// keys to access the substores
keyMain *sdk.KVStoreKey
keyAccount *sdk.KVStoreKey
keyBank *sdk.KVStoreKey
keyStake *sdk.KVStoreKey
tkeyStake *sdk.TransientStoreKey
keySlashing *sdk.KVStoreKey
Expand Down Expand Up @@ -158,6 +159,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp
cdc: cdc,
keyMain: sdk.NewKVStoreKey("main"),
keyAccount: sdk.NewKVStoreKey("acc"),
keyBank: sdk.NewKVStoreKey("bank"),
keyStake: sdk.NewKVStoreKey("stake"),
tkeyStake: sdk.NewTransientStoreKey("transient_stake"),
keySlashing: sdk.NewKVStoreKey("slashing"),
Expand All @@ -173,7 +175,7 @@ func NewGaiaApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.BaseAp
)

// add handlers
app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper)
app.bankKeeper = bank.NewBaseKeeper(app.cdc, app.accountKeeper, app.keyBank)
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
2 changes: 1 addition & 1 deletion cmd/gaia/cmd/gaiareplay/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func run(rootDir string) {
_ = proxyApp.Stop()
}()

var state tmsm.State = tmsm.LoadState(tmDB)
state := tmsm.LoadState(tmDB)
if state.LastBlockHeight == 0 {
// Send InitChain msg
fmt.Println("Sending InitChain msg")
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/basecoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type BasecoinApp struct {

// keys to access the multistore
keyMain *sdk.KVStoreKey
keyBank *sdk.KVStoreKey
keyAccount *sdk.KVStoreKey
keyIBC *sdk.KVStoreKey

Expand All @@ -62,6 +63,7 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba
cdc: cdc,
BaseApp: bam.NewBaseApp(appName, logger, db, auth.DefaultTxDecoder(cdc), baseAppOptions...),
keyMain: sdk.NewKVStoreKey("main"),
keyBank: sdk.NewKVStoreKey("bank"),
keyAccount: sdk.NewKVStoreKey("acc"),
keyIBC: sdk.NewKVStoreKey("ibc"),
}
Expand All @@ -74,7 +76,7 @@ func NewBasecoinApp(logger log.Logger, db dbm.DB, baseAppOptions ...func(*bam.Ba
return &types.AppAccount{}
},
)
app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper)
app.bankKeeper = bank.NewBaseKeeper(app.cdc, app.accountKeeper, app.keyBank)
app.ibcMapper = ibc.NewMapper(app.cdc, app.keyIBC, ibc.DefaultCodespace)

// register message routes
Expand Down
4 changes: 3 additions & 1 deletion docs/examples/democoin/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type DemocoinApp struct {
// keys to access the substores
capKeyMainStore *sdk.KVStoreKey
capKeyAccountStore *sdk.KVStoreKey
capKeyBankStore *sdk.KVStoreKey
capKeyPowStore *sdk.KVStoreKey
capKeyIBCStore *sdk.KVStoreKey
capKeyStakingStore *sdk.KVStoreKey
Expand Down Expand Up @@ -69,6 +70,7 @@ func NewDemocoinApp(logger log.Logger, db dbm.DB) *DemocoinApp {
cdc: cdc,
capKeyMainStore: sdk.NewKVStoreKey("main"),
capKeyAccountStore: sdk.NewKVStoreKey("acc"),
capKeyBankStore: sdk.NewKVStoreKey("bank"),
capKeyPowStore: sdk.NewKVStoreKey("pow"),
capKeyIBCStore: sdk.NewKVStoreKey("ibc"),
capKeyStakingStore: sdk.NewKVStoreKey("stake"),
Expand All @@ -82,7 +84,7 @@ func NewDemocoinApp(logger log.Logger, db dbm.DB) *DemocoinApp {
)

// Add handlers.
app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper)
app.bankKeeper = bank.NewBaseKeeper(app.cdc, app.accountKeeper, app.capKeyBankStore)
app.coolKeeper = cool.NewKeeper(app.capKeyMainStore, app.bankKeeper, cool.DefaultCodespace)
app.powKeeper = pow.NewKeeper(app.capKeyPowStore, pow.NewConfig("pow", int64(1)), app.bankKeeper, pow.DefaultCodespace)
app.ibcMapper = ibc.NewMapper(app.cdc, app.capKeyIBCStore, ibc.DefaultCodespace)
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/democoin/x/cool/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ func getMockApp(t *testing.T) *mock.App {

RegisterCodec(mapp.Cdc)
keyCool := sdk.NewKVStoreKey("cool")
bankKeeper := bank.NewBaseKeeper(mapp.AccountKeeper)
keyBank := sdk.NewKVStoreKey("bank")
bankKeeper := bank.NewBaseKeeper(mapp.Cdc, mapp.AccountKeeper, keyBank)
keeper := NewKeeper(keyCool, bankKeeper, DefaultCodespace)
mapp.Router().AddRoute("cool", NewHandler(keeper))

Expand Down
2 changes: 1 addition & 1 deletion docs/examples/democoin/x/cool/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestCoolKeeper(t *testing.T) {

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

err := InitGenesis(ctx, keeper, Genesis{"icy"})
Expand Down
3 changes: 2 additions & 1 deletion docs/examples/democoin/x/pow/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ func getMockApp(t *testing.T) *mock.App {

RegisterCodec(mapp.Cdc)
keyPOW := sdk.NewKVStoreKey("pow")
bankKeeper := bank.NewBaseKeeper(mapp.AccountKeeper)
keyBank := sdk.NewKVStoreKey("bank")
bankKeeper := bank.NewBaseKeeper(mapp.Cdc, mapp.AccountKeeper, keyBank)
config := Config{"pow", 1}
keeper := NewKeeper(keyPOW, config, bankKeeper, DefaultCodespace)
mapp.Router().AddRoute("pow", keeper.Handler)
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/democoin/x/pow/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestPowHandler(t *testing.T) {
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)
ck := bank.NewBaseKeeper(cdc, am, sdk.NewKVStoreKey("bank"))
keeper := NewKeeper(capKey, config, ck, DefaultCodespace)

handler := keeper.Handler
Expand Down
2 changes: 1 addition & 1 deletion docs/examples/democoin/x/pow/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestPowKeeperGetSet(t *testing.T) {
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)
ck := bank.NewBaseKeeper(cdc, am, sdk.NewKVStoreKey("bank"))
keeper := NewKeeper(capKey, config, ck, DefaultCodespace)

err := InitGenesis(ctx, keeper, Genesis{uint64(1), uint64(0)})
Expand Down
14 changes: 8 additions & 6 deletions docs/examples/democoin/x/simplestake/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,26 @@ import (
"github.com/cosmos/cosmos-sdk/x/bank"
)

func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey, *sdk.KVStoreKey) {
func setupMultiStore() (sdk.MultiStore, *sdk.KVStoreKey, *sdk.KVStoreKey, *sdk.KVStoreKey) {
db := dbm.NewMemDB()
authKey := sdk.NewKVStoreKey("authkey")
bankKey := sdk.NewKVStoreKey("bankkey")
capKey := sdk.NewKVStoreKey("capkey")
ms := store.NewCommitMultiStore(db)
ms.MountStoreWithDB(capKey, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(bankKey, sdk.StoreTypeIAVL, db)
ms.MountStoreWithDB(authKey, sdk.StoreTypeIAVL, db)
ms.LoadLatestVersion()
return ms, authKey, capKey
return ms, authKey, bankKey, capKey
}

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

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

Expand All @@ -59,14 +61,14 @@ func TestKeeperGetSet(t *testing.T) {
}

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

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

accountKeeper := auth.NewAccountKeeper(cdc, authKey, auth.ProtoBaseAccount)
bankKeeper := bank.NewBaseKeeper(accountKeeper)
bankKeeper := bank.NewBaseKeeper(cdc, accountKeeper, bankKey)
stakeKeeper := NewKeeper(capKey, bankKeeper, DefaultCodespace)
addr := sdk.AccAddress([]byte("some-address"))
privKey := ed25519.GenPrivKey()
Expand Down
2 changes: 1 addition & 1 deletion x/bank/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func getBenchmarkMockApp() (*mock.App, error) {
mapp := mock.NewApp()

RegisterCodec(mapp.Cdc)
bankKeeper := NewBaseKeeper(mapp.AccountKeeper)
bankKeeper := NewBaseKeeper(mapp.Cdc, mapp.AccountKeeper, sdk.NewKVStoreKey("bank"))
mapp.Router().AddRoute("bank", NewHandler(bankKeeper))

err := mapp.CompleteSetup()
Expand Down
Loading