diff --git a/app/upgrades/v21/upgrades.go b/app/upgrades/v21/upgrades.go index 92b51c4c62b..6d8d79dd172 100644 --- a/app/upgrades/v21/upgrades.go +++ b/app/upgrades/v21/upgrades.go @@ -3,6 +3,7 @@ package v21 import ( "context" "fmt" + providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types" errorsmod "cosmossdk.io/errors" "cosmossdk.io/math" @@ -13,7 +14,6 @@ import ( bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" "github.com/cosmos/gaia/v21/app/keepers" providerkeeper "github.com/cosmos/interchain-security/v6/x/ccv/provider/keeper" - providertypes "github.com/cosmos/interchain-security/v6/x/ccv/provider/types" ) // Neutron and Stride denoms that were not whitelisted but the consumer rewards pool contains amounts of those denoms. @@ -32,8 +32,6 @@ const ( ) // CreateUpgradeHandler returns an upgrade handler for Gaia v21. -// It performs module migrations, as well as the following tasks: -// - Initializes the MaxProviderConsensusValidators parameter in the provider module to 180. func CreateUpgradeHandler( mm *module.Manager, configurator module.Configurator, @@ -48,10 +46,10 @@ func CreateUpgradeHandler( return vm, errorsmod.Wrapf(err, "running module migrations") } - ctx.Logger().Info("distributing rewards of Neutron and Stride unaccounted denoms") - err = DistributeNeutronAndStrideUnaccountedDenoms(ctx, keepers.ProviderKeeper, keepers.BankKeeper, keepers.AccountKeeper) + ctx.Logger().Info("allocating rewards of Neutron and Stride unaccounted denoms") + err = AllocateNeutronAndStrideUnaccountedDenoms(ctx, keepers.ProviderKeeper, keepers.BankKeeper, keepers.AccountKeeper) if err != nil { - return vm, errorsmod.Wrapf(err, "could not distribute rewards of Neutron and Stride unaccounted denoms") + return vm, errorsmod.Wrapf(err, "could not allocate rewards of Neutron and Stride unaccounted denoms") } ctx.Logger().Info("Upgrade v21 complete") @@ -59,35 +57,22 @@ func CreateUpgradeHandler( } } -// DistributeDenoms distributes all the `denoms` that reside in the `address` and are meant for the chain with `consumerId` -func DistributeDenoms(ctx sdk.Context, providerKeeper providerkeeper.Keeper, bankKeeper bankkeeper.Keeper, address sdk.AccAddress, consumerId string, denoms []string) error { +// AllocateRewards allocates all the `denoms` that reside in the `address` and are meant for the chain with `consumerId` +func AllocateRewards(ctx sdk.Context, providerKeeper providerkeeper.Keeper, bankKeeper bankkeeper.Keeper, address sdk.AccAddress, consumerId string, denoms []string) error { for _, denom := range denoms { coinRewards := bankKeeper.GetBalance(ctx, address, denom) decCoinRewards := sdk.DecCoins{sdk.DecCoin{Denom: coinRewards.Denom, Amount: math.LegacyNewDecFromInt(coinRewards.Amount)}} - consumerRewardsAllocation := types2.ConsumerRewardsAllocation{Rewards: decCoinRewards} - - isDenomAllowlisted := providerKeeper.ConsumerRewardDenomExists(ctx, denom) - - // allowlist the denom that distribution can take place - providerKeeper.SetConsumerRewardDenom(ctx, denom) + consumerRewardsAllocation := providertypes.ConsumerRewardsAllocation{Rewards: decCoinRewards} err := providerKeeper.SetConsumerRewardsAllocationByDenom(ctx, consumerId, denom, consumerRewardsAllocation) if err != nil { return err } - - // call `BeginBlockRD` to actually perform the distribution - providerKeeper.BeginBlockRD(ctx) - - // if you were not allowlisted before, revert to initial state - if !isDenomAllowlisted { - providerKeeper.DeleteConsumerRewardDenom(ctx, denom) - } } return nil } -// HasExpectedChainIdSanityCheck return true if the chain with the provided `consumerId` is of a chain with the `expectedChainId` +// HasExpectedChainIdSanityCheck returns true if the chain with the provided `consumerId` is of a chain with the `expectedChainId` func HasExpectedChainIdSanityCheck(ctx sdk.Context, providerKeeper providerkeeper.Keeper, consumerId string, expectedChainId string) bool { actualChainId, err := providerKeeper.GetConsumerChainId(ctx, consumerId) if err != nil { @@ -99,9 +84,9 @@ func HasExpectedChainIdSanityCheck(ctx sdk.Context, providerKeeper providerkeepe return true } -// DistributeNeutronAndStrideUnaccountedDenoms distributed previously unaccounted denoms to the Stride and Neutron consumer chains -func DistributeNeutronAndStrideUnaccountedDenoms(ctx sdk.Context, providerKeeper providerkeeper.Keeper, bankKeeper bankkeeper.Keeper, accountKeeper authkeeper.AccountKeeper) error { - consumerRewardsPoolAddress := accountKeeper.GetModuleAccount(ctx, types2.ConsumerRewardsPool).GetAddress() +// AllocateNeutronAndStrideUnaccountedDenoms allocates previously unaccounted denoms to the Stride and Neutron consumer chains +func AllocateNeutronAndStrideUnaccountedDenoms(ctx sdk.Context, providerKeeper providerkeeper.Keeper, bankKeeper bankkeeper.Keeper, accountKeeper authkeeper.AccountKeeper) error { + consumerRewardsPoolAddress := accountKeeper.GetModuleAccount(ctx, providertypes.ConsumerRewardsPool).GetAddress() const NeutronConsumerId = "0" const NeutronChainId = "neutron-1" @@ -111,9 +96,9 @@ func DistributeNeutronAndStrideUnaccountedDenoms(ctx sdk.Context, providerKeeper } neutronUnaccountedDenoms := []string{NeutronUusdc, NeutronUtia} - err := DistributeDenoms(ctx, providerKeeper, bankKeeper, consumerRewardsPoolAddress, NeutronConsumerId, neutronUnaccountedDenoms) + err := AllocateRewards(ctx, providerKeeper, bankKeeper, consumerRewardsPoolAddress, NeutronConsumerId, neutronUnaccountedDenoms) if err != nil { - return fmt.Errorf("cannot distribute rewards for consumer id (%s): %w", NeutronConsumerId, err) + return fmt.Errorf("cannot allocate rewards for consumer id (%s): %w", NeutronConsumerId, err) } const StrideConsumerId = "1" @@ -124,9 +109,9 @@ func DistributeNeutronAndStrideUnaccountedDenoms(ctx sdk.Context, providerKeeper } strideUnaccountedDenoms := []string{StrideStutia, StrideStadym, StrideStaISLM, StrideStuband, StrideStadydx, StrideStusaga} - err = DistributeDenoms(ctx, providerKeeper, bankKeeper, consumerRewardsPoolAddress, StrideConsumerId, strideUnaccountedDenoms) + err = AllocateRewards(ctx, providerKeeper, bankKeeper, consumerRewardsPoolAddress, StrideConsumerId, strideUnaccountedDenoms) if err != nil { - return fmt.Errorf("cannot distribute rewards for consumer id (%s): %w", StrideConsumerId, err) + return fmt.Errorf("cannot allocate rewards for consumer id (%s): %w", StrideConsumerId, err) } return nil diff --git a/app/upgrades/v21/upgrades_test.go b/app/upgrades/v21/upgrades_test.go new file mode 100644 index 00000000000..4de485ff31e --- /dev/null +++ b/app/upgrades/v21/upgrades_test.go @@ -0,0 +1,26 @@ +package v21 + +import ( + tmproto "github.com/cometbft/cometbft/proto/tendermint/types" + "github.com/cosmos/gaia/v21/app/helpers" + "github.com/stretchr/testify/require" + "testing" +) + +func TestHasExpectedChainIdSanityCheck(t *testing.T) { + gaiaApp := helpers.Setup(t) + ctx := gaiaApp.NewUncachedContext(true, tmproto.Header{}) + + pk := gaiaApp.ProviderKeeper + + // no such consumer chain + consumerId := "0" + require.False(t, HasExpectedChainIdSanityCheck(ctx, pk, consumerId, "chain-1")) + + // consumer chain does not have `chain-1` id + pk.SetConsumerChainId(ctx, consumerId, "chain-2") + require.False(t, HasExpectedChainIdSanityCheck(ctx, pk, consumerId, "chain-1")) + + pk.SetConsumerChainId(ctx, consumerId, "chain-1") + require.True(t, HasExpectedChainIdSanityCheck(ctx, pk, consumerId, "chain-1")) +} diff --git a/go.mod b/go.mod index b3c34fd48ab..897fd23cf20 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( cosmossdk.io/tools/rosetta v0.2.1-0.20230613133644-0a778132a60f cosmossdk.io/x/evidence v0.1.1 cosmossdk.io/x/feegrant v0.1.1 - cosmossdk.io/x/tx v0.13.4 + cosmossdk.io/x/tx v0.13.5 cosmossdk.io/x/upgrade v0.1.4 github.com/CosmWasm/wasmd v0.53.0 github.com/cometbft/cometbft v0.38.11 @@ -32,7 +32,7 @@ require ( github.com/google/gofuzz v1.2.0 github.com/gorilla/mux v1.8.1 github.com/ory/dockertest/v3 v3.11.0 - github.com/prometheus/client_golang v1.20.2 + github.com/prometheus/client_golang v1.20.4 github.com/rakyll/statik v0.1.7 github.com/skip-mev/feemarket v1.1.1 github.com/spf13/cast v1.7.0 @@ -250,7 +250,6 @@ replace ( // Use special SDK v0.50.x release with support for both ICS and LSM github.com/cosmos/cosmos-sdk => github.com/cosmos/cosmos-sdk v0.50.9-lsm - github.com/cosmos/interchain-security/v6 => /Users/karolos/interchain-security // TODO: remove it: https://github.com/cosmos/cosmos-sdk/issues/13134 github.com/dgrijalva/jwt-go => github.com/golang-jwt/jwt/v4 v4.4.2 diff --git a/go.sum b/go.sum index f9c11417d68..92fff64ada3 100644 --- a/go.sum +++ b/go.sum @@ -220,8 +220,8 @@ cosmossdk.io/x/feegrant v0.1.1 h1:EKFWOeo/pup0yF0svDisWWKAA9Zags6Zd0P3nRvVvw8= cosmossdk.io/x/feegrant v0.1.1/go.mod h1:2GjVVxX6G2fta8LWj7pC/ytHjryA6MHAJroBWHFNiEQ= cosmossdk.io/x/nft v0.1.1 h1:pslAVS8P5NkW080+LWOamInjDcq+v2GSCo+BjN9sxZ8= cosmossdk.io/x/nft v0.1.1/go.mod h1:Kac6F6y2gsKvoxU+fy8uvxRTi4BIhLOor2zgCNQwVgY= -cosmossdk.io/x/tx v0.13.4 h1:Eg0PbJgeO0gM8p5wx6xa0fKR7hIV6+8lC56UrsvSo0Y= -cosmossdk.io/x/tx v0.13.4/go.mod h1:BkFqrnGGgW50Y6cwTy+JvgAhiffbGEKW6KF9ufcDpvk= +cosmossdk.io/x/tx v0.13.5 h1:FdnU+MdmFWn1pTsbfU0OCf2u6mJ8cqc1H4OMG418MLw= +cosmossdk.io/x/tx v0.13.5/go.mod h1:V6DImnwJMTq5qFjeGWpXNiT/fjgE4HtmclRmTqRVM3w= cosmossdk.io/x/upgrade v0.1.4 h1:/BWJim24QHoXde8Bc64/2BSEB6W4eTydq0X/2f8+g38= cosmossdk.io/x/upgrade v0.1.4/go.mod h1:9v0Aj+fs97O+Ztw+tG3/tp5JSlrmT7IcFhAebQHmOPo= dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= @@ -443,6 +443,8 @@ github.com/cosmos/ibc-go/v8 v8.5.1 h1:3JleEMKBjRKa3FeTKt4fjg22za/qygLBo7mDkoYTNB github.com/cosmos/ibc-go/v8 v8.5.1/go.mod h1:P5hkAvq0Qbg0h18uLxDVA9q1kOJ0l36htMsskiNwXbo= github.com/cosmos/ics23/go v0.11.0 h1:jk5skjT0TqX5e5QJbEnwXIS2yI2vnmLOgpQPeM5RtnU= github.com/cosmos/ics23/go v0.11.0/go.mod h1:A8OjxPE67hHST4Icw94hOxxFEJMBG031xIGF/JHNIY0= +github.com/cosmos/interchain-security/v6 v6.1.0 h1:ycTpT+If90nSEvRVu86ThPJxNtcmnOMjJmFC9ptd/yo= +github.com/cosmos/interchain-security/v6 v6.1.0/go.mod h1:+5zIZEzkL4yNHB/UWXCu75t6GeEgEmWHbz5OnBWiL0o= github.com/cosmos/keyring v1.2.0 h1:8C1lBP9xhImmIabyXW4c3vFjjLiBdGCmfLUfeZlV1Yo= github.com/cosmos/keyring v1.2.0/go.mod h1:fc+wB5KTk9wQ9sDx0kFXB3A0MaeGHM9AwRStKOQ5vOA= github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM= @@ -1120,8 +1122,8 @@ github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5Fsn github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og= github.com/prometheus/client_golang v1.4.0/go.mod h1:e9GMxYsXl05ICDXkRhurwBS4Q3OK1iX/F2sw+iXX5zU= github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M= -github.com/prometheus/client_golang v1.20.2 h1:5ctymQzZlyOON1666svgwn3s6IKWgfbjsejTMiXIyjg= -github.com/prometheus/client_golang v1.20.2/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= +github.com/prometheus/client_golang v1.20.4 h1:Tgh3Yr67PaOv/uTqloMsCEdeuFTatm5zIq5+qNN23vI= +github.com/prometheus/client_golang v1.20.4/go.mod h1:PIEt8X02hGcP8JWbeHyeZ53Y/jReSnHgO035n//V5WE= github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo= github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=