From 3c5e8d6028f2555fd53d4b057c468a6ef37650ad Mon Sep 17 00:00:00 2001 From: violet Date: Wed, 11 Dec 2024 10:29:28 -0500 Subject: [PATCH] fix: export only active consensus validators Otherwise the genesis import will fail because the provider module will tell it to expect only those validators --- .../bug-fixes/3445-export-consensus-validators.md | 2 ++ app/export.go | 13 +++++++++++++ 2 files changed, 15 insertions(+) create mode 100644 .changelog/unreleased/bug-fixes/3445-export-consensus-validators.md diff --git a/.changelog/unreleased/bug-fixes/3445-export-consensus-validators.md b/.changelog/unreleased/bug-fixes/3445-export-consensus-validators.md new file mode 100644 index 00000000000..daf910e3473 --- /dev/null +++ b/.changelog/unreleased/bug-fixes/3445-export-consensus-validators.md @@ -0,0 +1,2 @@ +- Export only validators that are participating in consensus + ([\#3445](https://github.com/cosmos/gaia/pull/3445)) diff --git a/app/export.go b/app/export.go index b82996ea886..f9d9236f1c6 100644 --- a/app/export.go +++ b/app/export.go @@ -2,6 +2,7 @@ package gaia import ( "encoding/json" + "sort" tmproto "github.com/cometbft/cometbft/proto/tendermint/types" @@ -43,6 +44,18 @@ func (app *GaiaApp) ExportAppStateAndValidators( } validators, err := staking.WriteValidators(ctx, app.StakingKeeper) + if err != nil { + return servertypes.ExportedApp{}, err + } + sort.SliceStable(validators, func(i, j int) bool { + return validators[i].Power > validators[j].Power + }) + // we have to trim this to only active consensus validators + maxVals := app.ProviderKeeper.GetMaxProviderConsensusValidators(ctx) + if len(validators) > int(maxVals) { + validators = validators[:maxVals] + } + return servertypes.ExportedApp{ AppState: appState, Validators: validators,