Skip to content

Commit 651e8f1

Browse files
mergify[bot]Alex Johnson
andauthored
fix: don't fail post handler on simulate tx with no fee (backport #122) (#123)
* fix: don't fail post handler on simulate tx with no fee (#122) * ok * ok * format * ok * clean readme * retract * mod bump (cherry picked from commit 9a2a3ee) # Conflicts: # go.mod # go.sum # x/feemarket/post/fee.go * fix --------- Co-authored-by: Alex Johnson <alex@skip.money>
1 parent 41098c3 commit 651e8f1

File tree

7 files changed

+146
-20
lines changed

7 files changed

+146
-20
lines changed

README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
# `x/feemarket` Specification
1+
# `x/feemarket` Module
22

33
## Abstract
44

5-
This document specifies the feemarket module.
6-
75
The feemarket module is an implementation of the Additive Increase Multiplicative Decrease (AIMD) EIP-1559
86
feemarket. More information about the implementation can be found [here](./x/feemarket/README.md).
97

10-
## Upgrading to FeeMarket
8+
## Upgrading to Feemarket
119

1210
More information about upgrading your chain to `x/feemarket` can be found in our dedicated [guide](docs/UPGRADING.md).
1311

go.mod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ require (
1919
github.com/golangci/golangci-lint v1.59.1
2020
github.com/grpc-ecosystem/grpc-gateway v1.16.0
2121
github.com/skip-mev/chaintestutil v0.0.0-20231207155412-975710cc9051
22-
github.com/spf13/cobra v1.8.0
22+
github.com/spf13/cobra v1.8.1
2323
github.com/spf13/viper v1.19.0
2424
github.com/stretchr/testify v1.9.0
2525
github.com/vektra/mockery/v2 v2.43.2
2626
golang.org/x/tools v0.22.0
2727
google.golang.org/genproto/googleapis/api v0.0.0-20240610135401-a8a62080eff3
2828
google.golang.org/grpc v1.64.0
29-
google.golang.org/protobuf v1.34.1
29+
google.golang.org/protobuf v1.34.2
3030
mvdan.cc/gofumpt v0.6.0
3131
pgregory.net/rapid v1.1.0
3232
)
@@ -339,3 +339,6 @@ replace (
339339
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
340340
golang.org/x/exp => golang.org/x/exp v0.0.0-20230224173230-c95f2b4c22f2
341341
)
342+
343+
// simulation and fee UX
344+
retract [v1.0.0, v1.0.2]

go.sum

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,7 +632,7 @@ github.com/cosmos/rosetta-sdk-go v0.10.0 h1:E5RhTruuoA7KTIXUcMicL76cffyeoyvNybzU
632632
github.com/cosmos/rosetta-sdk-go v0.10.0/go.mod h1:SImAZkb96YbwvoRkzSMQB6noNJXFgWl/ENIznEoYQI4=
633633
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
634634
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
635-
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
635+
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
636636
github.com/creachadair/taskgroup v0.3.2 h1:zlfutDS+5XG40AOxcHDSThxKzns8Tnr9jnr6VqkYlkM=
637637
github.com/creachadair/taskgroup v0.3.2/go.mod h1:wieWwecHVzsidg2CsUnFinW1faVN4+kq+TDlRJQ0Wbk=
638638
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY=
@@ -1433,8 +1433,8 @@ github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
14331433
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
14341434
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
14351435
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
1436-
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
1437-
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
1436+
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
1437+
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
14381438
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
14391439
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
14401440
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
@@ -2240,8 +2240,8 @@ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
22402240
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
22412241
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
22422242
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
2243-
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
2244-
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
2243+
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
2244+
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
22452245
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
22462246
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
22472247
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

x/feemarket/ante/fee.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (dfd feeMarketCheckDecorator) anteHandle(ctx sdk.Context, tx sdk.Tx, simula
104104

105105
var feeCoin sdk.Coin
106106
if simulate && len(feeCoins) == 0 {
107-
feeCoin = sdk.NewCoin(params.FeeDenom, sdkmath.NewInt(0))
107+
feeCoin = sdk.NewCoin(params.FeeDenom, sdkmath.ZeroInt())
108108
} else {
109109
feeCoin = feeCoins[0]
110110
}

x/feemarket/ante/fee_test.go

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"testing"
66

77
"cosmossdk.io/math"
8-
98
"github.com/cosmos/cosmos-sdk/testutil/testdata"
109
sdk "github.com/cosmos/cosmos-sdk/types"
1110
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
@@ -77,7 +76,7 @@ func TestAnteHandle(t *testing.T) {
7776
ExpErr: sdkerrors.ErrOutOfGas,
7877
},
7978
{
80-
Name: "0 gas given should pass in simulate",
79+
Name: "0 gas given should pass in simulate - no fee",
8180
Malleate: func(suite *antesuite.TestSuite) antesuite.TestCaseArgs {
8281
accs := suite.CreateTestAccounts(1)
8382

@@ -93,6 +92,23 @@ func TestAnteHandle(t *testing.T) {
9392
ExpPass: true,
9493
ExpErr: nil,
9594
},
95+
{
96+
Name: "0 gas given should pass in simulate - fee",
97+
Malleate: func(suite *antesuite.TestSuite) antesuite.TestCaseArgs {
98+
accs := suite.CreateTestAccounts(1)
99+
100+
return antesuite.TestCaseArgs{
101+
Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())},
102+
GasLimit: 0,
103+
FeeAmount: validFee,
104+
}
105+
},
106+
RunAnte: true,
107+
RunPost: false,
108+
Simulate: true,
109+
ExpPass: true,
110+
ExpErr: nil,
111+
},
96112
{
97113
Name: "signer has enough funds, should pass",
98114
Malleate: func(suite *antesuite.TestSuite) antesuite.TestCaseArgs {
@@ -125,6 +141,40 @@ func TestAnteHandle(t *testing.T) {
125141
ExpPass: true,
126142
ExpErr: nil,
127143
},
144+
{
145+
Name: "no fee - fail",
146+
Malleate: func(s *antesuite.TestSuite) antesuite.TestCaseArgs {
147+
accs := s.CreateTestAccounts(1)
148+
149+
return antesuite.TestCaseArgs{
150+
Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())},
151+
GasLimit: 1000000000,
152+
FeeAmount: nil,
153+
}
154+
},
155+
RunAnte: true,
156+
RunPost: true,
157+
Simulate: false,
158+
ExpPass: false,
159+
ExpErr: types.ErrNoFeeCoins,
160+
},
161+
{
162+
Name: "no gas limit - fail",
163+
Malleate: func(s *antesuite.TestSuite) antesuite.TestCaseArgs {
164+
accs := s.CreateTestAccounts(1)
165+
166+
return antesuite.TestCaseArgs{
167+
Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())},
168+
GasLimit: 0,
169+
FeeAmount: nil,
170+
}
171+
},
172+
RunAnte: true,
173+
RunPost: true,
174+
Simulate: false,
175+
ExpPass: false,
176+
ExpErr: sdkerrors.ErrInvalidGasLimit,
177+
},
128178
}
129179

130180
for _, tc := range testCases {

x/feemarket/post/fee.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ package post
33
import (
44
"fmt"
55

6-
errorsmod "cosmossdk.io/errors"
76
"cosmossdk.io/math"
7+
8+
errorsmod "cosmossdk.io/errors"
89
sdk "github.com/cosmos/cosmos-sdk/types"
910
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
1011
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
@@ -73,14 +74,20 @@ func (dfd FeeMarketDeductDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simul
7374
feeCoins := feeTx.GetFee()
7475
gas := ctx.GasMeter().GasConsumed() // use context gas consumed
7576

76-
if len(feeCoins) != 1 {
77-
if len(feeCoins) == 0 {
78-
return ctx, errorsmod.Wrapf(feemarkettypes.ErrNoFeeCoins, "got length %d", len(feeCoins))
79-
}
77+
if len(feeCoins) == 0 && !simulate {
78+
return ctx, errorsmod.Wrapf(feemarkettypes.ErrNoFeeCoins, "got length %d", len(feeCoins))
79+
}
80+
if len(feeCoins) > 1 {
8081
return ctx, errorsmod.Wrapf(feemarkettypes.ErrTooManyFeeCoins, "got length %d", len(feeCoins))
8182
}
8283

83-
feeCoin := feeCoins[0]
84+
var feeCoin sdk.Coin
85+
if simulate && len(feeCoins) == 0 {
86+
feeCoin = sdk.NewCoin(params.FeeDenom, math.ZeroInt())
87+
} else {
88+
feeCoin = feeCoins[0]
89+
}
90+
8491
feeGas := int64(feeTx.GetGas())
8592

8693
var (

x/feemarket/post/fee_test.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,74 @@ func TestPostHandle(t *testing.T) {
343343
ExpPass: true,
344344
ExpErr: nil,
345345
},
346+
{
347+
Name: "0 gas given should pass in simulate - no fee",
348+
Malleate: func(suite *antesuite.TestSuite) antesuite.TestCaseArgs {
349+
accs := suite.CreateTestAccounts(1)
350+
351+
return antesuite.TestCaseArgs{
352+
Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())},
353+
GasLimit: 0,
354+
FeeAmount: nil,
355+
}
356+
},
357+
RunAnte: true,
358+
RunPost: false,
359+
Simulate: true,
360+
ExpPass: true,
361+
ExpErr: nil,
362+
},
363+
{
364+
Name: "0 gas given should pass in simulate - fee",
365+
Malleate: func(suite *antesuite.TestSuite) antesuite.TestCaseArgs {
366+
accs := suite.CreateTestAccounts(1)
367+
368+
return antesuite.TestCaseArgs{
369+
Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())},
370+
GasLimit: 0,
371+
FeeAmount: validFee,
372+
}
373+
},
374+
RunAnte: true,
375+
RunPost: false,
376+
Simulate: true,
377+
ExpPass: true,
378+
ExpErr: nil,
379+
},
380+
{
381+
Name: "no fee - fail",
382+
Malleate: func(s *antesuite.TestSuite) antesuite.TestCaseArgs {
383+
accs := s.CreateTestAccounts(1)
384+
385+
return antesuite.TestCaseArgs{
386+
Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())},
387+
GasLimit: 1000000000,
388+
FeeAmount: nil,
389+
}
390+
},
391+
RunAnte: true,
392+
RunPost: true,
393+
Simulate: false,
394+
ExpPass: false,
395+
ExpErr: types.ErrNoFeeCoins,
396+
},
397+
{
398+
Name: "no gas limit - fail",
399+
Malleate: func(s *antesuite.TestSuite) antesuite.TestCaseArgs {
400+
accs := s.CreateTestAccounts(1)
401+
402+
return antesuite.TestCaseArgs{
403+
Msgs: []sdk.Msg{testdata.NewTestMsg(accs[0].Account.GetAddress())},
404+
GasLimit: 0,
405+
FeeAmount: nil,
406+
}
407+
},
408+
RunAnte: true,
409+
RunPost: true,
410+
Simulate: false,
411+
ExpPass: false,
412+
ExpErr: sdkerrors.ErrInvalidGasLimit,
413+
},
346414
}
347415

348416
for _, tc := range testCases {

0 commit comments

Comments
 (0)