Skip to content

Commit

Permalink
Merge pull request #310 from terra-money/fix/gas-mismatch
Browse files Browse the repository at this point in the history
Fix/gas mismatch
  • Loading branch information
javiersuweijie authored Jun 13, 2024
2 parents 4258834 + 110d687 commit e1fabaa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
8 changes: 4 additions & 4 deletions x/tokenfactory/keeper/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"

sdk "github.com/cosmos/cosmos-sdk/types"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"

"github.com/stretchr/testify/require"

tmproto "github.com/cometbft/cometbft/proto/tendermint/types"
"github.com/stretchr/testify/suite"

sdk "github.com/cosmos/cosmos-sdk/types"

wasmkeeper "github.com/CosmWasm/wasmd/x/wasm/keeper"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"

Expand Down Expand Up @@ -100,6 +101,5 @@ func (s *KeeperTestSuite) TestBurnFromModuleAccount() {
Amount: sdk.NewCoin(denom, sdk.NewInt(1000)),
BurnFromAddress: govAddr.String(),
})

require.Error(s.T(), err)
}
10 changes: 10 additions & 0 deletions x/tokenfactory/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,21 @@ func (server msgServer) Burn(goCtx context.Context, msg *types.MsgBurn) (*types.
msg.BurnFromAddress = msg.Sender
}

gasBefore1 := ctx.GasMeter().GasConsumed()
acc, err := sdk.AccAddressFromBech32(msg.BurnFromAddress)
if err != nil {
return nil, err
}
accountI := server.Keeper.accountKeeper.GetAccount(ctx, acc)
gasAfter1 := ctx.GasMeter().GasConsumed()
// Note: this is only used in patch v2.11.4. Will be removed from v2.12.0 onwards
// Make this query gas free to prevent app mismatch when burning tf tokens
ctx.GasMeter().RefundGas(gasAfter1-gasBefore1, "refund gas account lookup to prevent app hash")

// Do this so we consume the previous gas too
// TODO: remove
_ = server.Keeper.accountKeeper.GetAccount(ctx, sdk.AccAddress(msg.BurnFromAddress))

_, ok := accountI.(authtypes.ModuleAccountI)
if ok {
return nil, types.ErrBurnFromModuleAccount
Expand Down

0 comments on commit e1fabaa

Please sign in to comment.