Skip to content

Commit 1ecf542

Browse files
committed
#303 Upgrade Cosmos-SDK to v0.47.3
Signed-off-by: Abdulbois <abdulbois.tursunov@dsr-corporation.com> Signed-off-by: Abdulbois <abdulbois123@gmail.com>
1 parent fa1bd32 commit 1ecf542

File tree

247 files changed

+1297
-959
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

247 files changed

+1297
-959
lines changed

README-DEV.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ Re-generate cosmos base openapi (service API from cosmos exposed in DCL) using [
224224
## Update Tendermint Version
225225
226226
Please note, that we depend on the Tendermint fork <https://github.com/zigbee-alliance/tendermint/releases/tag/v0.34.140>
227-
due to hotfixes for <https://github.com/tendermint/tendermint/issues/7640> and <https://github.com/tendermint/tendermint/issues/7641>
227+
due to hotfixes for <https://github.com/cometbft/cometbft/issues/7640> and <https://github.com/cometbft/cometbft/issues/7641>
228228
required for Light Client Proxy.
229229
Now that fixes are merged to Tendermint master, so check if we still need to depend on the fork.
230230

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ See [Run Light Client Proxy](docs/running-light-client-proxy.md) for details how
164164
- There are currently no DC Ledger specific API libraries for various platforms and languages,
165165
but they may be provided in the future.
166166
- The following libraries can be used as light clients:
167-
- [Golang Light Client implementation](https://pkg.go.dev/github.com/tendermint/tendermint/lite2)
167+
- [Golang Light Client implementation](https://pkg.go.dev/github.com/cometbft/cometbft/lite2)
168168
- [Rust Light Client implementation](https://docs.rs/tendermint-light-client/0.23.3/tendermint_light_client/)
169169
- Refer to [this doc](./docs/tendermint-rpc.md) to see how to [subscribe](./docs/tendermint-rpc.md#subscribe) to a Tendermint WebSocket based events and/or [query](./docs/tendermint-rpc.md#querying-application-components) an application components.
170170

app/app.go

+90-48
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,44 @@
11
package app
22

33
import (
4+
"encoding/json"
45
"io"
5-
"net/http"
66
"os"
77
"path/filepath"
88

9+
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
10+
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
11+
dbm "github.com/cometbft/cometbft-db"
12+
abci "github.com/cometbft/cometbft/abci/types"
13+
"github.com/cometbft/cometbft/libs/log"
14+
tmos "github.com/cometbft/cometbft/libs/os"
915
"github.com/cosmos/cosmos-sdk/baseapp"
1016
"github.com/cosmos/cosmos-sdk/client"
17+
nodeservice "github.com/cosmos/cosmos-sdk/client/grpc/node"
1118
"github.com/cosmos/cosmos-sdk/client/grpc/tmservice"
12-
"github.com/cosmos/cosmos-sdk/client/rpc"
1319
"github.com/cosmos/cosmos-sdk/codec"
1420
"github.com/cosmos/cosmos-sdk/codec/types"
21+
"github.com/cosmos/cosmos-sdk/runtime"
22+
runtimeservices "github.com/cosmos/cosmos-sdk/runtime/services"
23+
"github.com/cosmos/cosmos-sdk/server"
1524
"github.com/cosmos/cosmos-sdk/server/api"
1625
"github.com/cosmos/cosmos-sdk/server/config"
1726
servertypes "github.com/cosmos/cosmos-sdk/server/types"
27+
storetypes "github.com/cosmos/cosmos-sdk/store/types"
1828
sdk "github.com/cosmos/cosmos-sdk/types"
1929
"github.com/cosmos/cosmos-sdk/types/module"
2030
"github.com/cosmos/cosmos-sdk/version"
21-
authrest "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
2231
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
32+
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
33+
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
2334
"github.com/cosmos/cosmos-sdk/x/params"
2435
paramskeeper "github.com/cosmos/cosmos-sdk/x/params/keeper"
2536
paramstypes "github.com/cosmos/cosmos-sdk/x/params/types"
2637
"github.com/cosmos/cosmos-sdk/x/upgrade"
2738
upgradekeeper "github.com/cosmos/cosmos-sdk/x/upgrade/keeper"
2839
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
29-
"github.com/tendermint/spm/cosmoscmd"
30-
"github.com/tendermint/spm/openapiconsole"
31-
abci "github.com/tendermint/tendermint/abci/types"
32-
tmjson "github.com/tendermint/tendermint/libs/json"
33-
"github.com/tendermint/tendermint/libs/log"
34-
tmos "github.com/tendermint/tendermint/libs/os"
35-
dbm "github.com/tendermint/tm-db"
36-
"github.com/zigbee-alliance/distributed-compliance-ledger/docs"
40+
41+
appparams "github.com/zigbee-alliance/distributed-compliance-ledger/app/params"
3742
dclpkitypes "github.com/zigbee-alliance/distributed-compliance-ledger/types/pki"
3843
compliancemodule "github.com/zigbee-alliance/distributed-compliance-ledger/x/compliance"
3944
compliancemodulekeeper "github.com/zigbee-alliance/distributed-compliance-ledger/x/compliance/keeper"
@@ -142,7 +147,7 @@ var (
142147
)
143148

144149
var (
145-
_ cosmoscmd.CosmosApp = (*App)(nil)
150+
_ runtime.AppI = (*App)(nil)
146151
_ servertypes.Application = (*App)(nil)
147152
)
148153

@@ -164,13 +169,14 @@ type App struct {
164169
cdc *codec.LegacyAmino
165170
appCodec codec.Codec
166171
interfaceRegistry types.InterfaceRegistry
172+
txConfig client.TxConfig
167173

168174
invCheckPeriod uint
169175

170176
// keys to access the substores
171-
keys map[string]*sdk.KVStoreKey
172-
tkeys map[string]*sdk.TransientStoreKey
173-
memKeys map[string]*sdk.MemoryStoreKey
177+
keys map[string]*storetypes.KVStoreKey
178+
tkeys map[string]*storetypes.TransientStoreKey
179+
memKeys map[string]*storetypes.MemoryStoreKey
174180

175181
// keepers
176182
/*
@@ -184,7 +190,7 @@ type App struct {
184190
GovKeeper govkeeper.Keeper
185191
CrisisKeeper crisiskeeper.Keeper
186192
*/
187-
UpgradeKeeper upgradekeeper.Keeper
193+
UpgradeKeeper *upgradekeeper.Keeper
188194
ParamsKeeper paramskeeper.Keeper
189195
/*
190196
IBCKeeper *ibckeeper.Keeper // IBC Keeper must be a pointer in the app, so we can SetRouter on it correctly
@@ -212,10 +218,24 @@ type App struct {
212218
ModelKeeper modelmodulekeeper.Keeper
213219

214220
ComplianceKeeper compliancemodulekeeper.Keeper
221+
222+
ConsensusParamsKeeper consensusparamkeeper.Keeper
215223
// this line is used by starport scaffolding # stargate/app/keeperDeclaration
216224

217225
// the module manager
218226
mm *module.Manager
227+
228+
// sm is the simulation manager
229+
sm *module.SimulationManager
230+
configurator module.Configurator
231+
}
232+
233+
func (app *App) RegisterNodeService(clientCtx client.Context) {
234+
nodeservice.RegisterNodeService(clientCtx, app.GRPCQueryRouter())
235+
}
236+
237+
func (app *App) SimulationManager() *module.SimulationManager {
238+
return app.sm
219239
}
220240

221241
// New returns a reference to an initialized Gaia.
@@ -227,18 +247,20 @@ func New(
227247
skipUpgradeHeights map[int64]bool,
228248
homePath string,
229249
invCheckPeriod uint,
230-
encodingConfig cosmoscmd.EncodingConfig,
250+
encodingConfig appparams.EncodingConfig,
231251
appOpts servertypes.AppOptions,
232252
baseAppOptions ...func(*baseapp.BaseApp),
233-
) cosmoscmd.App {
234-
appCodec := encodingConfig.Marshaler
253+
) *App {
254+
appCodec := encodingConfig.Codec
235255
cdc := encodingConfig.Amino
236256
interfaceRegistry := encodingConfig.InterfaceRegistry
257+
txConfig := encodingConfig.TxConfig
237258

238259
bApp := baseapp.NewBaseApp(Name, logger, db, encodingConfig.TxConfig.TxDecoder(), baseAppOptions...)
239260
bApp.SetCommitMultiStoreTracer(traceStore)
240261
bApp.SetVersion(version.Version)
241262
bApp.SetInterfaceRegistry(interfaceRegistry)
263+
bApp.SetTxEncoder(txConfig.TxEncoder())
242264

243265
keys := sdk.NewKVStoreKeys(
244266
paramstypes.StoreKey,
@@ -267,6 +289,7 @@ func New(
267289
cdc: cdc,
268290
appCodec: appCodec,
269291
interfaceRegistry: interfaceRegistry,
292+
txConfig: txConfig,
270293
invCheckPeriod: invCheckPeriod,
271294
keys: keys,
272295
tkeys: tkeys,
@@ -276,8 +299,8 @@ func New(
276299
app.ParamsKeeper = initParamsKeeper(appCodec, cdc, keys[paramstypes.StoreKey], tkeys[paramstypes.TStoreKey])
277300

278301
// set the BaseApp's parameter store
279-
bApp.SetParamStore(app.ParamsKeeper.Subspace(baseapp.Paramspace).WithKeyTable(paramskeeper.ConsensusParamsKeyTable()))
280-
// add capability keeper and ScopeToModule for ibc module
302+
app.ConsensusParamsKeeper = consensusparamkeeper.NewKeeper(appCodec, keys[upgradetypes.StoreKey], authtypes.NewModuleAddress(authtypes.ModuleName).String())
303+
bApp.SetParamStore(&app.ConsensusParamsKeeper) // add capability keeper and ScopeToModule for ibc module
281304
// app.CapabilityKeeper = capabilitykeeper.NewKeeper(appCodec, keys[capabilitytypes.StoreKey], memKeys[capabilitytypes.MemStoreKey])
282305

283306
/*
@@ -315,7 +338,7 @@ func New(
315338
316339
app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper)
317340
*/
318-
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp)
341+
app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp, authtypes.NewModuleAddress(upgradetypes.ModuleName).String())
319342
/*
320343
// register the staking hooks
321344
// NOTE: stakingKeeper above is passed by reference, so that it will contain these hooks
@@ -371,7 +394,7 @@ func New(
371394
keys[dclauthmoduletypes.MemStoreKey],
372395
)
373396

374-
dclauthModule := dclauthmodule.NewAppModule(appCodec, app.DclauthKeeper, app.BaseauthKeeper)
397+
dclauthModule := dclauthmodule.NewAppModule(appCodec, app.DclauthKeeper)
375398

376399
app.ValidatorKeeper = *validatormodulekeeper.NewKeeper(
377400
appCodec,
@@ -550,10 +573,23 @@ func New(
550573
)
551574

552575
// app.mm.RegisterInvariants(&app.CrisisKeeper)
553-
app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
576+
//app.mm.RegisterRoutes(app.Router(), app.QueryRouter(), encodingConfig.Amino)
577+
578+
app.configurator = module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
579+
app.mm.RegisterServices(app.configurator)
580+
581+
autocliv1.RegisterQueryServer(app.GRPCQueryRouter(), runtimeservices.NewAutoCLIQueryService(app.mm.Modules))
582+
reflectionSvc, err := runtimeservices.NewReflectionService()
583+
if err != nil {
584+
panic(err)
585+
}
586+
reflectionv1.RegisterReflectionServiceServer(app.GRPCQueryRouter(), reflectionSvc)
554587

555-
cfg := module.NewConfigurator(app.appCodec, app.MsgServiceRouter(), app.GRPCQueryRouter())
556-
app.mm.RegisterServices(cfg)
588+
// create the simulation manager and define the order of the modules for deterministic simulations
589+
overrideModules := map[string]module.AppModuleSimulation{
590+
dclauthmoduletypes.ModuleName: dclauthModule}
591+
app.sm = module.NewSimulationManagerFromAppModules(app.mm.Modules, overrideModules)
592+
app.sm.RegisterStoreDecoders()
557593

558594
// initialize stores
559595
app.MountKVStores(keys)
@@ -627,7 +663,7 @@ func New(
627663
app.UpgradeKeeper.SetUpgradeHandler(
628664
"v1.3",
629665
func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
630-
return app.mm.RunMigrations(ctx, cfg, fromVM)
666+
return app.mm.RunMigrations(ctx, app.configurator, fromVM)
631667
},
632668
)
633669

@@ -650,7 +686,7 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo
650686
// InitChainer application update at chain initialization.
651687
func (app *App) InitChainer(ctx sdk.Context, req abci.RequestInitChain) abci.ResponseInitChain {
652688
var genesisState GenesisState
653-
if err := tmjson.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
689+
if err := json.Unmarshal(req.AppStateBytes, &genesisState); err != nil {
654690
panic(err)
655691
}
656692
app.UpgradeKeeper.SetModuleVersionMap(ctx, app.mm.GetVersionMap())
@@ -699,21 +735,21 @@ func (app *App) InterfaceRegistry() types.InterfaceRegistry {
699735
// GetKey returns the KVStoreKey for the provided store key.
700736
//
701737
// NOTE: This is solely to be used for testing purposes.
702-
func (app *App) GetKey(storeKey string) *sdk.KVStoreKey {
738+
func (app *App) GetKey(storeKey string) *storetypes.KVStoreKey {
703739
return app.keys[storeKey]
704740
}
705741

706742
// GetTKey returns the TransientStoreKey for the provided store key.
707743
//
708744
// NOTE: This is solely to be used for testing purposes.
709-
func (app *App) GetTKey(storeKey string) *sdk.TransientStoreKey {
745+
func (app *App) GetTKey(storeKey string) *storetypes.TransientStoreKey {
710746
return app.tkeys[storeKey]
711747
}
712748

713749
// GetMemKey returns the MemStoreKey for the provided mem key.
714750
//
715751
// NOTE: This is solely used for testing purposes.
716-
func (app *App) GetMemKey(storeKey string) *sdk.MemoryStoreKey {
752+
func (app *App) GetMemKey(storeKey string) *storetypes.MemoryStoreKey {
717753
return app.memKeys[storeKey]
718754
}
719755

@@ -730,23 +766,19 @@ func (app *App) GetSubspace(moduleName string) paramstypes.Subspace {
730766
// API server.
731767
func (app *App) RegisterAPIRoutes(apiSvr *api.Server, apiConfig config.APIConfig) {
732768
clientCtx := apiSvr.ClientCtx
733-
rpc.RegisterRoutes(clientCtx, apiSvr.Router)
734-
735-
// Register legacy tx routes.
736-
authrest.RegisterTxRoutes(clientCtx, apiSvr.Router)
737769
// Register new tx routes from grpc-gateway.
738770
authtx.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
739771

740772
// Register new tendermint queries routes from grpc-gateway.
741773
tmservice.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
742774

743775
// Register legacy and grpc-gateway routes for all modules.
744-
ModuleBasics.RegisterRESTRoutes(clientCtx, apiSvr.Router)
745776
ModuleBasics.RegisterGRPCGatewayRoutes(clientCtx, apiSvr.GRPCGatewayRouter)
746777

747-
// register app's OpenAPI routes.
748-
apiSvr.Router.Handle("/static/openapi.yml", http.FileServer(http.FS(docs.Docs)))
749-
apiSvr.Router.HandleFunc("/", openapiconsole.Handler(Name, "/static/openapi.yml"))
778+
// register swagger API from root so that other applications can override easily
779+
if err := server.RegisterSwaggerAPI(apiSvr.ClientCtx, apiSvr.Router, apiConfig.Swagger); err != nil {
780+
panic(err)
781+
}
750782
}
751783

752784
// RegisterTxService implements the Application.RegisterTxService method.
@@ -756,21 +788,31 @@ func (app *App) RegisterTxService(clientCtx client.Context) {
756788

757789
// RegisterTendermintService implements the Application.RegisterTendermintService method.
758790
func (app *App) RegisterTendermintService(clientCtx client.Context) {
759-
tmservice.RegisterTendermintService(app.BaseApp.GRPCQueryRouter(), clientCtx, app.interfaceRegistry)
791+
tmservice.RegisterTendermintService(
792+
clientCtx,
793+
app.BaseApp.GRPCQueryRouter(),
794+
app.interfaceRegistry,
795+
app.Query,
796+
)
760797
}
761798

762-
// GetMaccPerms returns a copy of the module account permissions.
763-
func GetMaccPerms() map[string][]string {
764-
dupMaccPerms := make(map[string][]string)
765-
for k, v := range maccPerms {
766-
dupMaccPerms[k] = v
767-
}
799+
// TxConfig returns App's TxConfig.
800+
func (app *App) TxConfig() client.TxConfig {
801+
return app.txConfig
802+
}
803+
804+
// Configurator get app configurator
805+
func (app *App) Configurator() module.Configurator {
806+
return app.configurator
807+
}
768808

769-
return dupMaccPerms
809+
// ModuleManager returns the app ModuleManager
810+
func (app *App) ModuleManager() *module.Manager {
811+
return app.mm
770812
}
771813

772814
// initParamsKeeper init params keeper and its subspaces.
773-
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey sdk.StoreKey) paramskeeper.Keeper {
815+
func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino, key, tkey storetypes.StoreKey) paramskeeper.Keeper {
774816
paramsKeeper := paramskeeper.NewKeeper(appCodec, legacyAmino, key, tkey)
775817

776818
paramsKeeper.Subspace(upgradetypes.ModuleName)

app/encoding.go

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package app
2+
3+
import (
4+
"github.com/zigbee-alliance/distributed-compliance-ledger/app/params"
5+
6+
"github.com/cosmos/cosmos-sdk/codec"
7+
"github.com/cosmos/cosmos-sdk/codec/types"
8+
"github.com/cosmos/cosmos-sdk/std"
9+
"github.com/cosmos/cosmos-sdk/x/auth/tx"
10+
)
11+
12+
// makeEncodingConfig creates an EncodingConfig for an amino based test configuration.
13+
func makeEncodingConfig() params.EncodingConfig {
14+
amino := codec.NewLegacyAmino()
15+
interfaceRegistry := types.NewInterfaceRegistry()
16+
marshaler := codec.NewProtoCodec(interfaceRegistry)
17+
txCfg := tx.NewTxConfig(marshaler, tx.DefaultSignModes)
18+
19+
return params.EncodingConfig{
20+
InterfaceRegistry: interfaceRegistry,
21+
Codec: marshaler,
22+
TxConfig: txCfg,
23+
Amino: amino,
24+
}
25+
}
26+
27+
// MakeEncodingConfig creates an EncodingConfig for testing
28+
func MakeEncodingConfig() params.EncodingConfig {
29+
encodingConfig := makeEncodingConfig()
30+
std.RegisterLegacyAminoCodec(encodingConfig.Amino)
31+
std.RegisterInterfaces(encodingConfig.InterfaceRegistry)
32+
ModuleBasics.RegisterLegacyAminoCodec(encodingConfig.Amino)
33+
ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry)
34+
return encodingConfig
35+
}

app/export.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@ package app
33
import (
44
"encoding/json"
55

6+
tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
67
servertypes "github.com/cosmos/cosmos-sdk/server/types"
7-
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
88
"github.com/zigbee-alliance/distributed-compliance-ledger/x/validator"
99
)
1010

1111
// ExportAppStateAndValidators exports the state of the application for a genesis
1212
// file.
13-
func (app *App) ExportAppStateAndValidators(
14-
forZeroHeight bool, jailAllowedAddrs []string,
15-
) (servertypes.ExportedApp, error) {
13+
func (app *App) ExportAppStateAndValidators(forZeroHeight bool, jailAllowedAddrs []string, modulesToExport []string) (servertypes.ExportedApp, error) {
14+
1615
// as if they could withdraw from the start of the next block
1716
ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()})
1817

@@ -27,7 +26,7 @@ func (app *App) ExportAppStateAndValidators(
2726
}
2827
*/
2928

30-
genState := app.mm.ExportGenesis(ctx, app.appCodec)
29+
genState := app.mm.ExportGenesisForModules(ctx, app.appCodec, modulesToExport)
3130
appState, err := json.MarshalIndent(genState, "", " ")
3231
if err != nil {
3332
return servertypes.ExportedApp{}, err

0 commit comments

Comments
 (0)