diff --git a/.golangci.yml b/.golangci.yml index f82371276..fe4c5c5e3 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -2,6 +2,7 @@ run: tests: false timeout: 5m concurrency: 4 + go: "1.21.9" linters: enable: @@ -49,8 +50,6 @@ linters-settings: allow-leading-space: true require-explanation: false require-specific: false - gofumpt: - lang-version: "1.21.9" gomodguard: blocked: versions: # List of blocked module version constraints diff --git a/app/export.go b/app/export.go index ff680c80b..5e88b207b 100644 --- a/app/export.go +++ b/app/export.go @@ -55,7 +55,8 @@ func (app *ExocoreApp) ExportAppStateAndValidators( ) (servertypes.ExportedApp, error) { // Creates context with current height and checks txs for ctx to be usable by start of next // block - ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}) + ctx := app.NewContext(true, tmproto.Header{Height: app.LastBlockHeight()}). + WithChainID(app.ChainID()) // We export at last height + 1, because that's the height at which // Tendermint will start InitChain. diff --git a/cmd/exocored/root.go b/cmd/exocored/root.go index d821df583..ec45f7600 100644 --- a/cmd/exocored/root.go +++ b/cmd/exocored/root.go @@ -265,22 +265,7 @@ func (a appCreator) newApp(logger log.Logger, db dbm.DB, traceStore io.Writer, a cast.ToUint32(appOpts.Get(sdkserver.FlagStateSyncSnapshotKeepRecent)), ) - // Setup chainId - chainID := cast.ToString(appOpts.Get(flags.FlagChainID)) - if len(chainID) == 0 { - v := viper.New() - v.AddConfigPath(filepath.Join(home, "config")) - v.SetConfigName("client") - v.SetConfigType("toml") - if err := v.ReadInConfig(); err != nil { - panic(err) - } - conf := new(config.ClientConfig) - if err := v.Unmarshal(conf); err != nil { - panic(err) - } - chainID = conf.ChainID - } + chainID := getChainID(appOpts, home) evmosApp := app.NewExocoreApp( logger, db, traceStore, true, skipUpgradeHeights, @@ -323,17 +308,31 @@ func (a appCreator) appExport( return servertypes.ExportedApp{}, errors.New("application home not set") } + chainID := getChainID(appOpts, homePath) + if height != -1 { - evmosApp = app.NewExocoreApp(logger, db, traceStore, false, map[int64]bool{}, "", uint(1), a.encCfg, appOpts) + evmosApp = app.NewExocoreApp( + logger, db, traceStore, false, + map[int64]bool{}, "", uint(1), a.encCfg, appOpts, + baseapp.SetChainID(chainID), + ) if err := evmosApp.LoadHeight(height); err != nil { return servertypes.ExportedApp{}, err } } else { - evmosApp = app.NewExocoreApp(logger, db, traceStore, true, map[int64]bool{}, "", uint(1), a.encCfg, appOpts) + evmosApp = app.NewExocoreApp( + logger, db, traceStore, true, + map[int64]bool{}, "", uint(1), a.encCfg, appOpts, + baseapp.SetChainID(chainID), + ) } - return evmosApp.ExportAppStateAndValidators(forZeroHeight, jailAllowedAddrs, modulesToExport) + return evmosApp.ExportAppStateAndValidators( + forZeroHeight, + jailAllowedAddrs, + modulesToExport, + ) } // initTendermintConfig helps to override default Tendermint Config values. @@ -350,3 +349,24 @@ func initTendermintConfig() *tmcfg.Config { return cfg } + +// getChainID loads the chainID from the flag or the config.toml file, with the +// former taking precedence over the latter. +func getChainID(appOpts servertypes.AppOptions, home string) string { + chainID := cast.ToString(appOpts.Get(flags.FlagChainID)) + if len(chainID) == 0 { + v := viper.New() + v.AddConfigPath(filepath.Join(home, "config")) + v.SetConfigName("client") + v.SetConfigType("toml") + if err := v.ReadInConfig(); err != nil { + panic(err) + } + conf := new(config.ClientConfig) + if err := v.Unmarshal(conf); err != nil { + panic(err) + } + chainID = conf.ChainID + } + return chainID +} diff --git a/go.mod b/go.mod index fa3c6f35a..645310e46 100644 --- a/go.mod +++ b/go.mod @@ -240,7 +240,7 @@ replace ( // use cosmos fork of keyring github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0 // use Cosmos-SDK fork to enable Ledger functionality - github.com/cosmos/cosmos-sdk => github.com/evmos/cosmos-sdk v0.47.5-evmos + github.com/cosmos/cosmos-sdk => github.com/evmos/cosmos-sdk v0.47.5-evmos.2 //fix cosmos-sdk error github.com/cosmos/gogoproto => github.com/cosmos/gogoproto v1.4.10 // use Evmos geth fork diff --git a/go.sum b/go.sum index edd430d16..bc26ea6b1 100644 --- a/go.sum +++ b/go.sum @@ -817,8 +817,8 @@ github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7 github.com/envoyproxy/protoc-gen-validate v0.6.7/go.mod h1:dyJXwwfPK2VSqiB9Klm1J6romD608Ba7Hij42vrOBCo= github.com/envoyproxy/protoc-gen-validate v0.9.1/go.mod h1:OKNgG7TCp5pF4d6XftA0++PMirau2/yoOwVac3AbF2w= github.com/envoyproxy/protoc-gen-validate v0.10.0/go.mod h1:DRjgyB0I43LtJapqN6NiRwroiAU2PaFuvk/vjgh61ss= -github.com/evmos/cosmos-sdk v0.47.5-evmos h1:whqu51IyyDeINswUPNxDrm1WsvD7Bzo8XR71Ttt3DIc= -github.com/evmos/cosmos-sdk v0.47.5-evmos/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c= +github.com/evmos/cosmos-sdk v0.47.5-evmos.2 h1:fyhM0NYw/FnP4ZBXzQ7k+G4fXhfdU07MONoYrGlOCpc= +github.com/evmos/cosmos-sdk v0.47.5-evmos.2/go.mod h1:EHwCeN9IXonsjKcjpS12MqeStdZvIdxt3VYXhus3G3c= github.com/evmos/go-ethereum v1.10.26-evmos-rc2 h1:tYghk1ZZ8X4/OQ4YI9hvtm8aSN8OSqO0g9vo/sCMdBo= github.com/evmos/go-ethereum v1.10.26-evmos-rc2/go.mod h1:/6CsT5Ceen2WPLI/oCA3xMcZ5sWMF/D46SjM/ayY0Oo= github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= diff --git a/x/dogfood/keeper/impl_sdk.go b/x/dogfood/keeper/impl_sdk.go index 0496da2b5..1832fae07 100644 --- a/x/dogfood/keeper/impl_sdk.go +++ b/x/dogfood/keeper/impl_sdk.go @@ -179,11 +179,16 @@ func (k Keeper) IterateBondedValidatorsByPower( // will only happen if there is an error in deserialization. continue } + found, addr := k.operatorKeeper.GetOperatorAddressForChainIDAndConsAddr( + ctx, ctx.ChainID(), sdk.GetConsAddress(pk), + ) + if !found { + // this should never happen. should we panic? + continue + } val, err := stakingtypes.NewValidator( - // TODO: this is not the correct address, which is derived from - // sdk.ValAddress(sdk.AccAddress) - sdk.ValAddress(pk.Address()), - pk, stakingtypes.Description{}, + sdk.ValAddress(addr), + pk, stakingtypes.Description{ /* TODO */ }, ) if err != nil { // will only happen if there is an error in deserialization. @@ -214,7 +219,11 @@ func (k Keeper) IterateDelegations( panic("unimplemented on this keeper") } -func (k Keeper) WriteValidators(ctx sdk.Context) ([]tmtypes.GenesisValidator, error) { +// WriteValidators returns all the currently active validators. This is called by the export +// CLI. which must ensure that `ctx.ChainID()` is set. +func (k Keeper) WriteValidators( + ctx sdk.Context, +) ([]tmtypes.GenesisValidator, error) { validators := k.GetAllExocoreValidators(ctx) sort.SliceStable(validators, func(i, j int) bool { return validators[i].Power > validators[j].Power diff --git a/x/oracle/keeper/msg_server_create_price_test.go b/x/oracle/keeper/msg_server_create_price_test.go index 47e53ffae..b806f8750 100644 --- a/x/oracle/keeper/msg_server_create_price_test.go +++ b/x/oracle/keeper/msg_server_create_price_test.go @@ -31,9 +31,6 @@ var _ = Describe("MsgCreatePrice", func() { Expect(ks.ms).ToNot(BeNil()) validatorC := NewMockValidatorI(ks.ctrl) - validatorC.EXPECT().GetBondedTokens().Return(math.NewInt(1)) - validatorC.EXPECT().GetBondedTokens().Return(math.NewInt(1)) - validatorC.EXPECT().GetBondedTokens().Return(math.NewInt(1)) validatorC.EXPECT().GetConsensusPower(gomock.Any()).Return(int64(1)) validatorC.EXPECT().GetConsensusPower(gomock.Any()).Return(int64(1)) diff --git a/x/oracle/keeper/single.go b/x/oracle/keeper/single.go index 842eb2009..6ea8b3b16 100644 --- a/x/oracle/keeper/single.go +++ b/x/oracle/keeper/single.go @@ -60,7 +60,7 @@ func recacheAggregatorContext(ctx sdk.Context, agc *aggregator.AggregatorContext totalPower := big.NewInt(0) validatorPowers := make(map[string]*big.Int) k.IterateBondedValidatorsByPower(ctx, func(_ int64, validator stakingtypes.ValidatorI) bool { - power := big.NewInt(validator.GetConsensusPower(validator.GetBondedTokens())) + power := big.NewInt(validator.GetConsensusPower(sdk.DefaultPowerReduction)) addr := string(validator.GetOperator()) validatorPowers[addr] = power totalPower = new(big.Int).Add(totalPower, power) @@ -123,7 +123,7 @@ func initAggregatorContext(ctx sdk.Context, agc *aggregator.AggregatorContext, k totalPower := big.NewInt(0) validatorPowers := make(map[string]*big.Int) k.IterateBondedValidatorsByPower(ctx, func(_ int64, validator stakingtypes.ValidatorI) bool { - power := big.NewInt(validator.GetConsensusPower(validator.GetBondedTokens())) + power := big.NewInt(validator.GetConsensusPower(sdk.DefaultPowerReduction)) addr := validator.GetOperator().String() validatorPowers[addr] = power totalPower = new(big.Int).Add(totalPower, power)