-
Notifications
You must be signed in to change notification settings - Fork 10
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
Changes from all commits
c21383e
deeafad
ad78f76
8f475fe
b847fe0
6fca45a
4465aa0
1d4024a
bcc22b5
d35a133
2294655
ed883fd
21d9a13
40cb6c9
6071f3d
9a9e8c1
054d6a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Without this edit, the |
||
|
||
// We export at last height + 1, because that's the height at which | ||
// Tendermint will start InitChain. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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 | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See the comment at https://github.com/ExocoreNetwork/exocore/pull/53/files#diff-9bcaf321191d4f6106e27485bdfbbaef716b4e0e4f648d8e5b81a87bc93b6c77R59 for the reason behind this upgrade. |
||
//fix cosmos-sdk error | ||
github.com/cosmos/gogoproto => github.com/cosmos/gogoproto v1.4.10 | ||
// use Evmos geth fork | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
|
@@ -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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since |
||
|
||
validatorC.EXPECT().GetConsensusPower(gomock.Any()).Return(int64(1)) | ||
validatorC.EXPECT().GetConsensusPower(gomock.Any()).Return(int64(1)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See here an example of this call within the SDK. While the SDK technically uses There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
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) | ||
|
There was a problem hiding this comment.
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
.