Skip to content

Commit 9a2a3ee

Browse files
author
Alex Johnson
authored
fix: don't fail post handler on simulate tx with no fee (#122)
* ok * ok * format * ok * clean readme * retract * mod bump
1 parent d2f4f3b commit 9a2a3ee

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
@@ -29,14 +29,14 @@ require (
2929
github.com/grpc-ecosystem/grpc-gateway v1.16.0
3030
github.com/skip-mev/chaintestutil v0.0.0-20240514161515-056d7ba45610
3131
github.com/spf13/cast v1.6.0
32-
github.com/spf13/cobra v1.8.0
32+
github.com/spf13/cobra v1.8.1
3333
github.com/spf13/viper v1.19.0
3434
github.com/stretchr/testify v1.9.0
3535
github.com/vektra/mockery/v2 v2.43.2
3636
golang.org/x/tools v0.22.0
3737
google.golang.org/genproto/googleapis/api v0.0.0-20240610135401-a8a62080eff3
3838
google.golang.org/grpc v1.64.0
39-
google.golang.org/protobuf v1.34.1
39+
google.golang.org/protobuf v1.34.2
4040
mvdan.cc/gofumpt v0.6.0
4141
pgregory.net/rapid v1.1.0
4242
)
@@ -351,3 +351,6 @@ replace (
351351
github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
352352
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
353353
)
354+
355+
// simulation and fee UX
356+
retract [v1.0.0, v1.0.2]

go.sum

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,7 @@ github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5n
442442
github.com/cosmos/ledger-cosmos-go v0.13.3/go.mod h1:HENcEP+VtahZFw38HZ3+LS3Iv5XV6svsnkk9vdJtLr8=
443443
github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE=
444444
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
445-
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
445+
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
446446
github.com/creachadair/atomicfile v0.3.3 h1:yJlDq8qk9QmD/6ol+jq1X4bcoLNVdYq95+owOnauziE=
447447
github.com/creachadair/atomicfile v0.3.3/go.mod h1:X1r9P4wigJlGkYJO1HXZREdkVn+b1yHrsBBMLSj7tak=
448448
github.com/creachadair/mtest v0.0.0-20231015022703-31f2ea539dce h1:BFjvg2Oq88/2DOcUFu1ScIwKUn7KJYYvLr6AeuCJD54=
@@ -1236,8 +1236,8 @@ github.com/spf13/cast v1.6.0 h1:GEiTHELF+vaR5dhz3VqZfFSzZjYbgeKDpBxQVS4GYJ0=
12361236
github.com/spf13/cast v1.6.0/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
12371237
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
12381238
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
1239-
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
1240-
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
1239+
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
1240+
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
12411241
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
12421242
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
12431243
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
@@ -2026,8 +2026,8 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ
20262026
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
20272027
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
20282028
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
2029-
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
2030-
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
2029+
google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg=
2030+
google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw=
20312031
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
20322032
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
20332033
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
@@ -2,9 +2,10 @@ package post
22

33
import (
44
"bytes"
5-
"cosmossdk.io/math"
65
"fmt"
76

7+
"cosmossdk.io/math"
8+
89
errorsmod "cosmossdk.io/errors"
910

1011
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -75,14 +76,20 @@ func (dfd FeeMarketDeductDecorator) PostHandle(ctx sdk.Context, tx sdk.Tx, simul
7576
feeCoins := feeTx.GetFee()
7677
gas := ctx.GasMeter().GasConsumed() // use context gas consumed
7778

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

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

8895
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)