Skip to content

Commit

Permalink
v1.7.1 - Fix vesting ante (#277)
Browse files Browse the repository at this point in the history
* fix: delegate vesting coins
* chore: minor changes
* fix: remove redundant check
* test: add some tests for vesting delegation
* chore: add upgrade handler and bump version
  • Loading branch information
Yurist-85 authored Jan 30, 2024
1 parent 1cdd044 commit a953aa4
Show file tree
Hide file tree
Showing 15 changed files with 106 additions and 44 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ DIFF_TAG=$(shell git rev-list --tags="v*" --max-count=1 --not $(shell git rev-li
DEFAULT_TAG=$(shell git rev-list --tags="v*" --max-count=1)
# VERSION ?= $(shell echo $(shell git describe --tags $(or $(DIFF_TAG), $(DEFAULT_TAG))) | sed 's/^v//')

VERSION := "1.7.0"
VERSION := "1.7.1"
CBFTVERSION := $(shell go list -m github.com/cometbft/cometbft | sed 's:.* ::')
COMMIT := $(shell git log -1 --format='%H')
LEDGER_ENABLED ?= true
Expand Down
6 changes: 3 additions & 3 deletions app/ante/cosmos/eip712.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ import (
evmtypes "github.com/haqq-network/haqq/x/evm/types"
)

var evmosCodec codec.ProtoCodecMarshaler
var protoCodec codec.ProtoCodecMarshaler

func init() {
registry := codectypes.NewInterfaceRegistry()
types.RegisterInterfaces(registry)
evmosCodec = codec.NewProtoCodec(registry)
protoCodec = codec.NewProtoCodec(registry)
}

// Deprecated: LegacyEip712SigVerificationDecorator Verify all signatures for a tx and return an error if any are invalid. Note,
Expand Down Expand Up @@ -223,7 +223,7 @@ func VerifySignature(
FeePayer: feePayer,
}

typedData, err := eip712.LegacyWrapTxToTypedData(evmosCodec, extOpt.TypedDataChainID, msgs[0], txBytes, feeDelegation)
typedData, err := eip712.LegacyWrapTxToTypedData(protoCodec, extOpt.TypedDataChainID, msgs[0], txBytes, feeDelegation)
if err != nil {
return errorsmod.Wrap(err, "failed to create EIP-712 typed data from tx")
}
Expand Down
2 changes: 1 addition & 1 deletion app/ante/cosmos/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func (dfd DeductFeeDecorator) deductFee(ctx sdk.Context, sdkTx sdk.Tx, fees sdk.

// deduct the fees
if err := deductFeesFromBalanceOrUnclaimedStakingRewards(ctx, dfd, deductFeesFromAcc, fees); err != nil {
return fmt.Errorf("insufficient funds and failed to claim sufficient staking rewards to pay for fees: %w", err)
return fmt.Errorf("%q has insufficient funds and failed to claim sufficient staking rewards to pay for fees: %w", deductFeesFrom.String(), err)
}

events := sdk.Events{
Expand Down
4 changes: 2 additions & 2 deletions app/ante/cosmos/min_price_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ var execTypes = []struct {
func (suite *AnteTestSuite) TestMinGasPriceDecorator() {
denom := utils.BaseDenom
testMsg := banktypes.MsgSend{
FromAddress: "evmos1x8fhpj9nmhqk8z9kpgjt95ck2xwyue0ptzkucp",
ToAddress: "evmos1dx67l23hz9l0k9hcher8xz04uj7wf3yu26l2yn",
FromAddress: "haqq1tjdjfavsy956d25hvhs3p0nw9a7pfghqm0up92",
ToAddress: "haqq1hdr0lhv75vesvtndlh78ck4cez6esz8u2lk0hq",
Amount: sdk.Coins{sdk.Coin{Amount: sdkmath.NewInt(10), Denom: denom}},
}

Expand Down
19 changes: 10 additions & 9 deletions app/ante/cosmos/vesting.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ import (
type VestingDelegationDecorator struct {
ak evmtypes.AccountKeeper
sk vestingtypes.StakingKeeper
bk evmtypes.BankKeeper
cdc codec.BinaryCodec
}

// NewVestingDelegationDecorator creates a new VestingDelegationDecorator
func NewVestingDelegationDecorator(ak evmtypes.AccountKeeper, sk vestingtypes.StakingKeeper, cdc codec.BinaryCodec) VestingDelegationDecorator {
func NewVestingDelegationDecorator(ak evmtypes.AccountKeeper, sk vestingtypes.StakingKeeper, bk evmtypes.BankKeeper, cdc codec.BinaryCodec) VestingDelegationDecorator {
return VestingDelegationDecorator{
ak: ak,
sk: sk,
bk: bk,
cdc: cdc,
}
}
Expand Down Expand Up @@ -91,19 +93,18 @@ func (vdd VestingDelegationDecorator) validateMsg(ctx sdk.Context, msg sdk.Msg)

// error if bond amount is > vested coins
bondDenom := vdd.sk.BondDenom(ctx)
coins := clawbackAccount.GetVestedOnly(ctx.BlockTime())
if coins == nil || coins.Empty() {
return errorsmod.Wrap(
vestingtypes.ErrInsufficientVestedCoins,
"account has no vested coins",
)
balance := vdd.bk.GetBalance(ctx, addr, bondDenom)
unvestedOnly := clawbackAccount.GetUnvestedOnly(ctx.BlockTime())
spendable, hasNeg := sdk.Coins{balance}.SafeSub(unvestedOnly...)
if hasNeg {
spendable = sdk.NewCoins()
}

vested := coins.AmountOf(bondDenom)
vested := spendable.AmountOf(bondDenom)
if vested.LT(delegateMsg.Amount.Amount) {
return errorsmod.Wrapf(
vestingtypes.ErrInsufficientVestedCoins,
"cannot delegate unvested coins. coins vested < delegation amount (%s < %s)",
"cannot delegate unvested coins. coins stakable < delegation amount (%s < %s)",
vested, delegateMsg.Amount.Amount,
)
}
Expand Down
24 changes: 12 additions & 12 deletions app/ante/evm/ante_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
from := acc.GetAddress()
gas := uint64(200000)
amount := sdk.NewCoins(sdk.NewCoin(evmtypes.DefaultEVMDenom, sdkmath.NewInt(100*int64(gas))))
txBuilder, err := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, "evmos_9002-1", gas, amount)
txBuilder, err := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, "haqq_121799-1", gas, amount)
suite.Require().NoError(err)
return txBuilder.GetTx()
}, false, false, false,
Expand All @@ -571,7 +571,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
from := acc.GetAddress()
gas := uint64(200000)
amount := sdk.NewCoins(sdk.NewCoin(evmtypes.DefaultEVMDenom, sdkmath.NewInt(100*int64(gas))))
txBuilder, err := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, "evmos_9001-1", gas, amount)
txBuilder, err := suite.CreateTestEIP712TxBuilderMsgSend(from, privKey, "haqq_121799-1", gas, amount)
suite.Require().NoError(err)
return txBuilder.GetTx()
}, false, false, false,
Expand Down Expand Up @@ -640,7 +640,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"evmos",
"ISLM",
sdk.NewInt(1),
),
),
Expand Down Expand Up @@ -670,7 +670,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"evmos",
"ISLM",
sdk.NewInt(1),
),
),
Expand Down Expand Up @@ -700,7 +700,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"evmos",
"ISLM",
sdk.NewInt(1),
),
),
Expand Down Expand Up @@ -755,7 +755,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"evmos",
"ISLM",
sdk.NewInt(1),
),
),
Expand All @@ -765,7 +765,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
privKeys,
signing.SignMode_SIGN_MODE_LEGACY_AMINO_JSON,
msg,
"evmos_9005-1",
"haqq_121799-1",
2000000,
"mixed",
)
Expand All @@ -785,7 +785,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"evmos",
"ISLM",
sdk.NewInt(1),
),
),
Expand Down Expand Up @@ -815,7 +815,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"evmos",
"ISLM",
sdk.NewInt(1),
),
),
Expand Down Expand Up @@ -845,7 +845,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"evmos",
"ISLM",
sdk.NewInt(1),
),
),
Expand Down Expand Up @@ -879,7 +879,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"evmos",
"ISLM",
sdk.NewInt(1),
),
),
Expand Down Expand Up @@ -909,7 +909,7 @@ func (suite *AnteTestSuite) TestAnteHandler() {
addr[:],
sdk.NewCoins(
sdk.NewCoin(
"evmos",
"ISLM",
sdk.NewInt(1),
),
),
Expand Down
8 changes: 4 additions & 4 deletions app/ante/evm/fee_checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

anteutils "github.com/haqq-network/haqq/app/ante/utils"
haqqtypes "github.com/haqq-network/haqq/types"
"github.com/haqq-network/haqq/x/evm/types"
evmtypes "github.com/haqq-network/haqq/x/evm/types"
)

// NewDynamicFeeChecker returns a `TxFeeChecker` that applies a dynamic fee to
Expand Down Expand Up @@ -69,7 +69,7 @@ func NewDynamicFeeChecker(k DynamicFeeEVMKeeper) anteutils.TxFeeChecker {
}

// calculate the effective gas price using the EIP-1559 logic.
effectivePrice := sdkmath.NewIntFromBigInt(types.EffectiveGasPrice(baseFeeInt.BigInt(), feeCap.BigInt(), maxPriorityPrice.BigInt()))
effectivePrice := sdkmath.NewIntFromBigInt(evmtypes.EffectiveGasPrice(baseFeeInt.BigInt(), feeCap.BigInt(), maxPriorityPrice.BigInt()))

// NOTE: create a new coins slice without having to validate the denom
effectiveFee := sdk.Coins{
Expand All @@ -79,7 +79,7 @@ func NewDynamicFeeChecker(k DynamicFeeEVMKeeper) anteutils.TxFeeChecker {
},
}

bigPriority := effectivePrice.Sub(baseFeeInt).Quo(types.DefaultPriorityReduction)
bigPriority := effectivePrice.Sub(baseFeeInt).Quo(evmtypes.DefaultPriorityReduction)
priority := int64(math.MaxInt64)

if bigPriority.IsInt64() {
Expand Down Expand Up @@ -127,7 +127,7 @@ func getTxPriority(fees sdk.Coins, gas int64) int64 {

for _, fee := range fees {
gasPrice := fee.Amount.QuoRaw(gas)
amt := gasPrice.Quo(types.DefaultPriorityReduction)
amt := gasPrice.Quo(evmtypes.DefaultPriorityReduction)
p := int64(math.MaxInt64)

if amt.IsInt64() {
Expand Down
4 changes: 2 additions & 2 deletions app/ante/evm/fees.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func (empd EthMinGasPriceDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simul
if fee.LT(requiredFee) {
return ctx, errorsmod.Wrapf(
errortypes.ErrInsufficientFee,
"provided fee < minimum global fee (%d < %d). Please increase the priority tip (for EIP-1559 txs) or the gas prices (for access list or legacy txs)", //nolint:lll
fee.TruncateInt().Int64(), requiredFee.TruncateInt().Int64(),
"provided fee < minimum global fee (%s < %s). Please increase the priority tip (for EIP-1559 txs) or the gas prices (for access list or legacy txs)", //nolint:lll
fee.TruncateInt().String(), requiredFee.TruncateInt().String(),
)
}
}
Expand Down
7 changes: 3 additions & 4 deletions app/ante/handler_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import (
vestingtypes "github.com/haqq-network/haqq/x/vesting/types"
)

// HandlerOptions defines the list of module keepers required to run the Evmos
// AnteHandler decorators.
// HandlerOptions defines the list of module keepers required to run the Haqq AnteHandler decorators.
type HandlerOptions struct {
Cdc codec.BinaryCodec
AccountKeeper evmtypes.AccountKeeper
Expand Down Expand Up @@ -115,7 +114,7 @@ func newCosmosAnteHandler(options HandlerOptions) sdk.AnteHandler {
cosmosante.NewMinGasPriceDecorator(options.FeeMarketKeeper, options.EvmKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
cosmosante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.DistributionKeeper, options.FeegrantKeeper, options.StakingKeeper, options.TxFeeChecker),
cosmosante.NewVestingDelegationDecorator(options.AccountKeeper, options.StakingKeeper, options.Cdc),
cosmosante.NewVestingDelegationDecorator(options.AccountKeeper, options.StakingKeeper, options.BankKeeper, options.Cdc),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
Expand All @@ -142,7 +141,7 @@ func newLegacyCosmosAnteHandlerEip712(options HandlerOptions) sdk.AnteHandler {
ante.NewValidateMemoDecorator(options.AccountKeeper),
ante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
cosmosante.NewDeductFeeDecorator(options.AccountKeeper, options.BankKeeper, options.DistributionKeeper, options.FeegrantKeeper, options.StakingKeeper, options.TxFeeChecker),
cosmosante.NewVestingDelegationDecorator(options.AccountKeeper, options.StakingKeeper, options.Cdc),
cosmosante.NewVestingDelegationDecorator(options.AccountKeeper, options.StakingKeeper, options.BankKeeper, options.Cdc),
// SetPubKeyDecorator must be called before all signature verification decorators
ante.NewSetPubKeyDecorator(options.AccountKeeper),
ante.NewValidateSigCountDecorator(options.AccountKeeper),
Expand Down
2 changes: 1 addition & 1 deletion app/ante/sigverify.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
Secp256k1VerifyCost uint64 = 21000
)

// SigVerificationGasConsumer is the Evmos implementation of SignatureVerificationGasConsumer. It consumes gas
// SigVerificationGasConsumer is the Haqq implementation of SignatureVerificationGasConsumer. It consumes gas
// for signature verification based upon the public key type. The cost is fetched from the given params and is matched
// by the concrete type.
// The types of keys supported are:
Expand Down
7 changes: 7 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ import (
v163 "github.com/haqq-network/haqq/app/upgrades/v1.6.3"
v164 "github.com/haqq-network/haqq/app/upgrades/v1.6.4"
v170 "github.com/haqq-network/haqq/app/upgrades/v1.7.0"
v171 "github.com/haqq-network/haqq/app/upgrades/v1.7.1"

// NOTE: override ICS20 keeper to support IBC transfers of ERC20 tokens
"github.com/haqq-network/haqq/x/ibc/transfer"
Expand Down Expand Up @@ -1189,6 +1190,12 @@ func (app *Haqq) setupUpgradeHandlers() {
),
)

// v1.7.1 Fix Vesting AnteHandler
app.UpgradeKeeper.SetUpgradeHandler(
v171.UpgradeName,
v171.CreateUpgradeHandler(app.mm, app.configurator),
)

// When a planned update height is reached, the old binary will panic
// writing on disk the height and name of the update that triggered it
// This will read that value, and execute the preparations for the upgrade.
Expand Down
6 changes: 6 additions & 0 deletions app/upgrades/v1.7.1/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package v171

const (
// UpgradeName is the shared upgrade plan name for mainnet and testnet
UpgradeName = "v1.7.1"
)
20 changes: 20 additions & 0 deletions app/upgrades/v1.7.1/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package v171

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

// CreateUpgradeHandler creates an SDK upgrade handler for v1.7.1
func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
logger := ctx.Logger()
logger.Info("run migration v1.7.1")

return mm.RunMigrations(ctx, configurator, vm)
}
}
Loading

0 comments on commit a953aa4

Please sign in to comment.