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

fix(cli,oracle): export + vote power #53

Merged
merged 17 commits into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ run:
tests: false
timeout: 5m
concurrency: 4
go: "1.21.9"

linters:
enable:
Expand Down Expand Up @@ -49,8 +50,6 @@ linters-settings:
allow-leading-space: true
require-explanation: false
require-specific: false
gofumpt:
lang-version: "1.21.9"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was deprecated and has been moved to run.go.

gomodguard:
blocked:
versions: # List of blocked module version constraints
Expand Down
3 changes: 2 additions & 1 deletion app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this edit, the export command complains of no such key in the store. The function app.ChainID() is available in cosmos-sdk v0.47.5-evmos.2, which has been added to go.mod. The only change over the previous version is the addition of this method.


// We export at last height + 1, because that's the height at which
// Tendermint will start InitChain.
Expand Down
58 changes: 39 additions & 19 deletions cmd/exocored/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this function since to avoid repeated code. It is called during exocored start as well as exocored export.

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
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//fix cosmos-sdk error
github.com/cosmos/gogoproto => github.com/cosmos/gogoproto v1.4.10
// use Evmos geth fork
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
19 changes: 14 additions & 5 deletions x/dogfood/keeper/impl_sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger or 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),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this edit, the prior TODO is resolved.

pk, stakingtypes.Description{ /* TODO */ },
)
if err != nil {
// will only happen if there is an error in deserialization.
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions x/oracle/keeper/msg_server_create_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since GetBondedTokens() is not being called, this can be removed.


validatorC.EXPECT().GetConsensusPower(gomock.Any()).Return(int64(1))
validatorC.EXPECT().GetConsensusPower(gomock.Any()).Return(int64(1))
Expand Down
4 changes: 2 additions & 2 deletions x/oracle/keeper/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Copy link
Contributor Author

@MaxMustermann2 MaxMustermann2 May 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See here an example of this call within the SDK.
https://github.com/evmos/cosmos-sdk/blob/v0.47.5-evmos.2/x/staking/keeper/invariants.go#L115

While the SDK technically uses stakingKeeper.PowerReduction(), it is not a parameter but hardcoded to sdk.DefaultPowerReduction.
https://github.com/evmos/cosmos-sdk/blob/v0.47.5-evmos.2/x/staking/keeper/params.go#L44

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to rename DefaultPowerReduction to VirtualUSDDecimal? This way, the token converted from power could be considered as a virtual USD token. I didn't find the meaning of DefaultPowerReduction in the system.

addr := string(validator.GetOperator())
validatorPowers[addr] = power
totalPower = new(big.Int).Add(totalPower, power)
Expand Down Expand Up @@ -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)
Expand Down
Loading