Skip to content
This repository was archived by the owner on Nov 30, 2021. It is now read-only.

Commit 82d016a

Browse files
authored
Update CosmosSDK version to 0.36.0 (#82)
* Update CosmosSDK version to 0.36 LTR * Added basic EthermintApp run/export test * Go mod tidy from dependency update * Update export comments * Remove confusing comment
1 parent 5777ead commit 82d016a

File tree

9 files changed

+288
-115
lines changed

9 files changed

+288
-115
lines changed

app/ethermint.go

Lines changed: 60 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"github.com/cosmos/cosmos-sdk/x/bank"
1616
"github.com/cosmos/cosmos-sdk/x/crisis"
1717
distr "github.com/cosmos/cosmos-sdk/x/distribution"
18-
distrclient "github.com/cosmos/cosmos-sdk/x/distribution/client"
1918
"github.com/cosmos/cosmos-sdk/x/genaccounts"
2019
"github.com/cosmos/cosmos-sdk/x/genutil"
2120
"github.com/cosmos/cosmos-sdk/x/gov"
@@ -29,9 +28,9 @@ import (
2928
evmtypes "github.com/cosmos/ethermint/x/evm/types"
3029

3130
abci "github.com/tendermint/tendermint/abci/types"
32-
dbm "github.com/tendermint/tendermint/libs/db"
31+
cmn "github.com/tendermint/tendermint/libs/common"
3332
tmlog "github.com/tendermint/tendermint/libs/log"
34-
tmtypes "github.com/tendermint/tendermint/types"
33+
dbm "github.com/tendermint/tm-db"
3534
)
3635

3736
const appName = "Ethermint"
@@ -54,13 +53,23 @@ var (
5453
staking.AppModuleBasic{},
5554
mint.AppModuleBasic{},
5655
distr.AppModuleBasic{},
57-
gov.NewAppModuleBasic(paramsclient.ProposalHandler, distrclient.ProposalHandler),
56+
gov.NewAppModuleBasic(paramsclient.ProposalHandler, distr.ProposalHandler),
5857
params.AppModuleBasic{},
5958
crisis.AppModuleBasic{},
6059
slashing.AppModuleBasic{},
6160
supply.AppModuleBasic{},
6261
evm.AppModuleBasic{},
6362
)
63+
64+
// module account permissions
65+
maccPerms = map[string][]string{
66+
auth.FeeCollectorName: nil,
67+
distr.ModuleName: nil,
68+
mint.ModuleName: {supply.Minter},
69+
staking.BondedPoolName: {supply.Burner, supply.Staking},
70+
staking.NotBondedPoolName: {supply.Burner, supply.Staking},
71+
gov.ModuleName: {supply.Burner},
72+
}
6473
)
6574

6675
// MakeCodec generates the necessary codecs for Amino
@@ -83,20 +92,8 @@ type EthermintApp struct {
8392
invCheckPeriod uint
8493

8594
// keys to access the substores
86-
keyMain *sdk.KVStoreKey
87-
keyAccount *sdk.KVStoreKey
88-
keySupply *sdk.KVStoreKey
89-
keyStaking *sdk.KVStoreKey
90-
tkeyStaking *sdk.TransientStoreKey
91-
keySlashing *sdk.KVStoreKey
92-
keyMint *sdk.KVStoreKey
93-
keyDistr *sdk.KVStoreKey
94-
tkeyDistr *sdk.TransientStoreKey
95-
keyGov *sdk.KVStoreKey
96-
keyParams *sdk.KVStoreKey
97-
tkeyParams *sdk.TransientStoreKey
98-
evmStoreKey *sdk.KVStoreKey
99-
evmCodeKey *sdk.KVStoreKey
95+
keys map[string]*sdk.KVStoreKey
96+
tkeys map[string]*sdk.TransientStoreKey
10097

10198
// keepers
10299
accountKeeper auth.AccountKeeper
@@ -121,35 +118,29 @@ type EthermintApp struct {
121118
// TODO: Ethermint needs to support being bootstrapped as an application running
122119
// in a sovereign zone and as an application running with a shared security model.
123120
// For now, it will support only running as a sovereign application.
124-
func NewEthermintApp(logger tmlog.Logger, db dbm.DB, loadLatest bool,
121+
func NewEthermintApp(
122+
logger tmlog.Logger, db dbm.DB, loadLatest bool,
125123
invCheckPeriod uint, baseAppOptions ...func(*bam.BaseApp)) *EthermintApp {
126124
cdc := MakeCodec()
127125

128-
baseApp := bam.NewBaseApp(appName, logger, db, evmtypes.TxDecoder(cdc), baseAppOptions...)
129-
baseApp.SetAppVersion(version.Version)
126+
bApp := bam.NewBaseApp(appName, logger, db, evmtypes.TxDecoder(cdc), baseAppOptions...)
127+
bApp.SetAppVersion(version.Version)
128+
129+
keys := sdk.NewKVStoreKeys(bam.MainStoreKey, auth.StoreKey, staking.StoreKey,
130+
supply.StoreKey, mint.StoreKey, distr.StoreKey, slashing.StoreKey,
131+
gov.StoreKey, params.StoreKey)
132+
tkeys := sdk.NewTransientStoreKeys(staking.TStoreKey, params.TStoreKey)
130133

131-
var app = &EthermintApp{
132-
BaseApp: baseApp,
134+
app := &EthermintApp{
135+
BaseApp: bApp,
133136
cdc: cdc,
134137
invCheckPeriod: invCheckPeriod,
135-
keyMain: sdk.NewKVStoreKey(bam.MainStoreKey),
136-
keyAccount: sdk.NewKVStoreKey(auth.StoreKey),
137-
keyStaking: sdk.NewKVStoreKey(staking.StoreKey),
138-
keySupply: sdk.NewKVStoreKey(supply.StoreKey),
139-
tkeyStaking: sdk.NewTransientStoreKey(staking.TStoreKey),
140-
keyMint: sdk.NewKVStoreKey(mint.StoreKey),
141-
keyDistr: sdk.NewKVStoreKey(distr.StoreKey),
142-
tkeyDistr: sdk.NewTransientStoreKey(distr.TStoreKey),
143-
keySlashing: sdk.NewKVStoreKey(slashing.StoreKey),
144-
keyGov: sdk.NewKVStoreKey(gov.StoreKey),
145-
keyParams: sdk.NewKVStoreKey(params.StoreKey),
146-
tkeyParams: sdk.NewTransientStoreKey(params.TStoreKey),
147-
evmStoreKey: sdk.NewKVStoreKey(evmtypes.EvmStoreKey),
148-
evmCodeKey: sdk.NewKVStoreKey(evmtypes.EvmCodeKey),
138+
keys: keys,
139+
tkeys: tkeys,
149140
}
150141

151142
// init params keeper and subspaces
152-
app.paramsKeeper = params.NewKeeper(app.cdc, app.keyParams, app.tkeyParams, params.DefaultCodespace)
143+
app.paramsKeeper = params.NewKeeper(app.cdc, keys[params.StoreKey], tkeys[params.TStoreKey], params.DefaultCodespace)
153144
authSubspace := app.paramsKeeper.Subspace(auth.DefaultParamspace)
154145
bankSubspace := app.paramsKeeper.Subspace(bank.DefaultParamspace)
155146
stakingSubspace := app.paramsKeeper.Subspace(staking.DefaultParamspace)
@@ -159,49 +150,39 @@ func NewEthermintApp(logger tmlog.Logger, db dbm.DB, loadLatest bool,
159150
govSubspace := app.paramsKeeper.Subspace(gov.DefaultParamspace)
160151
crisisSubspace := app.paramsKeeper.Subspace(crisis.DefaultParamspace)
161152

162-
// account permissions
163-
maccPerms := map[string][]string{
164-
auth.FeeCollectorName: []string{supply.Basic},
165-
distr.ModuleName: []string{supply.Basic},
166-
mint.ModuleName: []string{supply.Minter},
167-
staking.BondedPoolName: []string{supply.Burner, supply.Staking},
168-
staking.NotBondedPoolName: []string{supply.Burner, supply.Staking},
169-
gov.ModuleName: []string{supply.Burner},
170-
}
171-
172153
// add keepers
173-
app.accountKeeper = auth.NewAccountKeeper(app.cdc, app.keyAccount, authSubspace, auth.ProtoBaseAccount)
174-
app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper, bankSubspace, bank.DefaultCodespace)
175-
app.supplyKeeper = supply.NewKeeper(app.cdc, app.keySupply, app.accountKeeper, app.bankKeeper, supply.DefaultCodespace, maccPerms)
176-
stakingKeeper := staking.NewKeeper(app.cdc, app.keyStaking, app.tkeyStaking,
154+
app.accountKeeper = auth.NewAccountKeeper(app.cdc, keys[auth.StoreKey], authSubspace, auth.ProtoBaseAccount)
155+
app.bankKeeper = bank.NewBaseKeeper(app.accountKeeper, bankSubspace, bank.DefaultCodespace, app.ModuleAccountAddrs())
156+
app.supplyKeeper = supply.NewKeeper(app.cdc, keys[supply.StoreKey], app.accountKeeper, app.bankKeeper, maccPerms)
157+
stakingKeeper := staking.NewKeeper(app.cdc, keys[staking.StoreKey], tkeys[staking.TStoreKey],
177158
app.supplyKeeper, stakingSubspace, staking.DefaultCodespace)
178-
app.mintKeeper = mint.NewKeeper(app.cdc, app.keyMint, mintSubspace, &stakingKeeper, app.supplyKeeper, auth.FeeCollectorName)
179-
app.distrKeeper = distr.NewKeeper(app.cdc, app.keyDistr, distrSubspace, &stakingKeeper,
180-
app.supplyKeeper, distr.DefaultCodespace, auth.FeeCollectorName)
181-
app.slashingKeeper = slashing.NewKeeper(app.cdc, app.keySlashing, &stakingKeeper,
159+
app.mintKeeper = mint.NewKeeper(app.cdc, keys[mint.StoreKey], mintSubspace, &stakingKeeper, app.supplyKeeper, auth.FeeCollectorName)
160+
app.distrKeeper = distr.NewKeeper(app.cdc, keys[distr.StoreKey], distrSubspace, &stakingKeeper,
161+
app.supplyKeeper, distr.DefaultCodespace, auth.FeeCollectorName, app.ModuleAccountAddrs())
162+
app.slashingKeeper = slashing.NewKeeper(app.cdc, keys[slashing.StoreKey], &stakingKeeper,
182163
slashingSubspace, slashing.DefaultCodespace)
183164
app.crisisKeeper = crisis.NewKeeper(crisisSubspace, invCheckPeriod, app.supplyKeeper, auth.FeeCollectorName)
184-
app.evmKeeper = evm.NewKeeper(app.accountKeeper, app.evmStoreKey, app.evmCodeKey, cdc)
185165

186166
// register the proposal types
187167
govRouter := gov.NewRouter()
188168
govRouter.AddRoute(gov.RouterKey, gov.ProposalHandler).
189169
AddRoute(params.RouterKey, params.NewParamChangeProposalHandler(app.paramsKeeper)).
190170
AddRoute(distr.RouterKey, distr.NewCommunityPoolSpendProposalHandler(app.distrKeeper))
191-
app.govKeeper = gov.NewKeeper(app.cdc, app.keyGov, app.paramsKeeper, govSubspace,
171+
app.govKeeper = gov.NewKeeper(app.cdc, keys[gov.StoreKey], app.paramsKeeper, govSubspace,
192172
app.supplyKeeper, &stakingKeeper, gov.DefaultCodespace, govRouter)
193173

194174
// register the staking hooks
195175
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
196176
app.stakingKeeper = *stakingKeeper.SetHooks(
197-
staking.NewMultiStakingHooks(app.distrKeeper.Hooks(), app.slashingKeeper.Hooks()))
177+
staking.NewMultiStakingHooks(app.distrKeeper.Hooks(), app.slashingKeeper.Hooks()),
178+
)
198179

199180
app.mm = module.NewManager(
200181
genaccounts.NewAppModule(app.accountKeeper),
201182
genutil.NewAppModule(app.accountKeeper, app.stakingKeeper, app.BaseApp.DeliverTx),
202183
auth.NewAppModule(app.accountKeeper),
203184
bank.NewAppModule(app.bankKeeper, app.accountKeeper),
204-
crisis.NewAppModule(app.crisisKeeper),
185+
crisis.NewAppModule(&app.crisisKeeper),
205186
supply.NewAppModule(app.supplyKeeper, app.accountKeeper),
206187
distr.NewAppModule(app.distrKeeper, app.supplyKeeper),
207188
gov.NewAppModule(app.govKeeper, app.supplyKeeper),
@@ -216,21 +197,22 @@ func NewEthermintApp(logger tmlog.Logger, db dbm.DB, loadLatest bool,
216197
// CanWithdrawInvariant invariant.
217198
app.mm.SetOrderBeginBlockers(mint.ModuleName, distr.ModuleName, slashing.ModuleName)
218199

219-
app.mm.SetOrderEndBlockers(gov.ModuleName, staking.ModuleName)
200+
app.mm.SetOrderEndBlockers(crisis.ModuleName, gov.ModuleName, staking.ModuleName)
220201

221-
// genutils must occur after staking so that pools are properly
222-
// initialized with tokens from genesis accounts.
223-
app.mm.SetOrderInitGenesis(genaccounts.ModuleName, supply.ModuleName, distr.ModuleName,
224-
staking.ModuleName, auth.ModuleName, bank.ModuleName, slashing.ModuleName,
225-
gov.ModuleName, mint.ModuleName, crisis.ModuleName, genutil.ModuleName, evmtypes.ModuleName)
202+
// NOTE: The genutils module must occur after staking so that pools are
203+
// properly initialized with tokens from genesis accounts.
204+
app.mm.SetOrderInitGenesis(
205+
genaccounts.ModuleName, distr.ModuleName, staking.ModuleName,
206+
auth.ModuleName, bank.ModuleName, slashing.ModuleName, gov.ModuleName,
207+
mint.ModuleName, supply.ModuleName, crisis.ModuleName, genutil.ModuleName,
208+
)
226209

227210
app.mm.RegisterInvariants(&app.crisisKeeper)
228211
app.mm.RegisterRoutes(app.Router(), app.QueryRouter())
229212

230213
// initialize stores
231-
app.MountStores(app.keyMain, app.keyAccount, app.keySupply, app.keyStaking,
232-
app.keyMint, app.keyDistr, app.keySlashing, app.keyGov, app.keyParams,
233-
app.tkeyParams, app.tkeyStaking, app.tkeyDistr, app.evmStoreKey, app.evmCodeKey)
214+
app.MountKVStores(keys)
215+
app.MountTransientStores(tkeys)
234216

235217
// initialize BaseApp
236218
app.SetInitChainer(app.InitChainer)
@@ -239,13 +221,12 @@ func NewEthermintApp(logger tmlog.Logger, db dbm.DB, loadLatest bool,
239221
app.SetEndBlocker(app.EndBlocker)
240222

241223
if loadLatest {
242-
err := app.LoadLatestVersion(app.keyMain)
224+
err := app.LoadLatestVersion(app.keys[bam.MainStoreKey])
243225
if err != nil {
244-
panic(err)
226+
cmn.Exit(err.Error())
245227
}
246228
}
247229
return app
248-
249230
}
250231

251232
// The genesis state of the blockchain is represented here as a map of raw json
@@ -271,26 +252,15 @@ func (app *EthermintApp) InitChainer(ctx sdk.Context, req abci.RequestInitChain)
271252

272253
// load a particular height
273254
func (app *EthermintApp) LoadHeight(height int64) error {
274-
return app.LoadVersion(height, app.keyMain)
255+
return app.LoadVersion(height, app.keys[bam.MainStoreKey])
275256
}
276257

277-
// ExportAppStateAndValidators exports the state of the application for a genesis
278-
// file.
279-
func (app *EthermintApp) ExportAppStateAndValidators(forZeroHeight bool, jailWhiteList []string,
280-
) (appState json.RawMessage, validators []tmtypes.GenesisValidator, err error) {
281-
282-
// Creates context with current height and checks txs for ctx to be usable by start of next block
283-
ctx := app.NewContext(true, abci.Header{Height: app.LastBlockHeight()})
284-
285-
// Export genesis to be used by SDK modules
286-
genState := app.mm.ExportGenesis(ctx)
287-
appState, err = codec.MarshalJSONIndent(app.cdc, genState)
288-
if err != nil {
289-
return nil, nil, err
258+
// ModuleAccountAddrs returns all the app's module account addresses.
259+
func (app *EthermintApp) ModuleAccountAddrs() map[string]bool {
260+
modAccAddrs := make(map[string]bool)
261+
for acc := range maccPerms {
262+
modAccAddrs[app.supplyKeeper.GetModuleAddress(acc).String()] = true
290263
}
291264

292-
// Write validators to staking module to be used by TM node
293-
validators = staking.WriteValidators(ctx, app.stakingKeeper)
294-
295-
return appState, validators, nil
265+
return modAccAddrs
296266
}

app/ethermint_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package app
2+
3+
import (
4+
"os"
5+
"testing"
6+
7+
"github.com/stretchr/testify/require"
8+
"github.com/tendermint/tendermint/libs/log"
9+
dbm "github.com/tendermint/tm-db"
10+
11+
"github.com/cosmos/cosmos-sdk/codec"
12+
13+
abci "github.com/tendermint/tendermint/abci/types"
14+
)
15+
16+
func TestEthermintAppExport(t *testing.T) {
17+
db := dbm.NewMemDB()
18+
app := NewEthermintApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, true, 0)
19+
20+
genesisState := ModuleBasics.DefaultGenesis()
21+
stateBytes, err := codec.MarshalJSONIndent(app.cdc, genesisState)
22+
require.NoError(t, err)
23+
24+
// Initialize the chain
25+
app.InitChain(
26+
abci.RequestInitChain{
27+
Validators: []abci.ValidatorUpdate{},
28+
AppStateBytes: stateBytes,
29+
},
30+
)
31+
app.Commit()
32+
33+
// Making a new app object with the db, so that initchain hasn't been called
34+
app2 := NewEthermintApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, true, 0)
35+
_, _, err = app2.ExportAppStateAndValidators(false, []string{})
36+
require.NoError(t, err, "ExportAppStateAndValidators should not have an error")
37+
}

0 commit comments

Comments
 (0)