From ab7b3ec82f3d9d70e44881ff083615b62d73ebcf Mon Sep 17 00:00:00 2001 From: Ruaridh Date: Thu, 28 Apr 2022 16:01:51 +0100 Subject: [PATCH] ensure akava balances are backed by, not equal to (#1230) module balance --- x/evmutil/keeper/invariants.go | 9 ++++++--- x/evmutil/keeper/invariants_test.go | 6 +++--- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/x/evmutil/keeper/invariants.go b/x/evmutil/keeper/invariants.go index dff75424..a2e5fdb2 100644 --- a/x/evmutil/keeper/invariants.go +++ b/x/evmutil/keeper/invariants.go @@ -24,10 +24,13 @@ func AllInvariants(bankK types.BankKeeper, k Keeper) sdk.Invariant { } } -// FullyBackedInvariant ensures all minor balances are backed exactly by the coins in the module account. +// FullyBackedInvariant ensures all minor balances are backed by the coins in the module account. +// +// The module balance can be greater than the sum of all minor balances. This can happen in rare cases +// where the evm module burns tokens. func FullyBackedInvariant(bankK types.BankKeeper, k Keeper) sdk.Invariant { broken := false - message := sdk.FormatInvariant(types.ModuleName, "fully backed broken", "minor balances do not match module account") + message := sdk.FormatInvariant(types.ModuleName, "fully backed broken", "sum of minor balances greater than module account") return func(ctx sdk.Context) (string, bool) { @@ -40,7 +43,7 @@ func FullyBackedInvariant(bankK types.BankKeeper, k Keeper) sdk.Invariant { bankAddr := authtypes.NewModuleAddress(types.ModuleName) bankBalance := bankK.GetBalance(ctx, bankAddr, CosmosDenom).Amount.Mul(ConversionMultiplier) - broken = !totalMinorBalances.Equal(bankBalance) + broken = totalMinorBalances.GT(bankBalance) return message, broken } diff --git a/x/evmutil/keeper/invariants_test.go b/x/evmutil/keeper/invariants_test.go index df16ccd8..072a065d 100644 --- a/x/evmutil/keeper/invariants_test.go +++ b/x/evmutil/keeper/invariants_test.go @@ -87,11 +87,11 @@ func (suite *invariantTestSuite) TestFullyBackedInvariant() { _, broken = suite.runInvariant("fully-backed", keeper.FullyBackedInvariant) suite.Equal(false, broken) - // break invariant by decreasing minor balances without decreasing module balance - suite.Keeper.RemoveBalance(suite.Ctx, suite.Addrs[0], sdk.OneInt()) + // break invariant by increasing total minor balances above module balance + suite.Keeper.AddBalance(suite.Ctx, suite.Addrs[0], sdk.OneInt()) message, broken := suite.runInvariant("fully-backed", keeper.FullyBackedInvariant) - suite.Equal("evmutil: fully backed broken invariant\nminor balances do not match module account\n", message) + suite.Equal("evmutil: fully backed broken invariant\nsum of minor balances greater than module account\n", message) suite.Equal(true, broken) }