Skip to content

Commit 1aac4a6

Browse files
author
Alex Johnson
authored
feat: pre deduct funds (#135)
* escrwo * utd: * bettington * yay * ok * version * ok * fixing * testing working * fix * add comment * alwasy escrow * test * add checks * comment * adding test * format * clean * remove escrow acct * update comment * ok * test * add StateUpdate field * test - disabled -> enabled * ok * use the keeer for enabled height * return -1 when nothing in state
1 parent f2f6773 commit 1aac4a6

29 files changed

+825
-303
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44

55
# Primary repo maintainers
66

7-
* @davidterpay @nivasan1 @aljo242 @Eric-Warehime
7+
* @aljo242 @Eric-Warehime @technicallyty @wesl-ee

go.mod

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
module github.com/skip-mev/feemarket
22

3-
go 1.22.3
3+
go 1.22.6
44

55
require (
66
cosmossdk.io/api v0.7.5
77
cosmossdk.io/client/v2 v2.0.0-00010101000000-000000000000
8-
cosmossdk.io/core v0.11.0
9-
cosmossdk.io/depinject v1.0.0-alpha.4
8+
cosmossdk.io/core v0.11.1
9+
cosmossdk.io/depinject v1.0.0
1010
cosmossdk.io/errors v1.0.1
1111
cosmossdk.io/log v1.3.1
1212
cosmossdk.io/math v1.3.0
@@ -16,14 +16,14 @@ require (
1616
cosmossdk.io/x/evidence v0.1.1
1717
cosmossdk.io/x/feegrant v0.1.1
1818
cosmossdk.io/x/nft v0.1.1
19-
cosmossdk.io/x/tx v0.13.3
20-
cosmossdk.io/x/upgrade v0.1.3
19+
cosmossdk.io/x/tx v0.13.4
20+
cosmossdk.io/x/upgrade v0.1.4
2121
github.com/client9/misspell v0.3.4
22-
github.com/cometbft/cometbft v0.38.8
22+
github.com/cometbft/cometbft v0.38.11
2323
github.com/cosmos/cosmos-db v1.0.2
2424
github.com/cosmos/cosmos-proto v1.0.0-beta.5
25-
github.com/cosmos/cosmos-sdk v0.50.7
26-
github.com/cosmos/gogoproto v1.5.0
25+
github.com/cosmos/cosmos-sdk v0.50.9
26+
github.com/cosmos/gogoproto v1.6.0
2727
github.com/golang/protobuf v1.5.4
2828
github.com/golangci/golangci-lint v1.59.1
2929
github.com/grpc-ecosystem/grpc-gateway v1.16.0
@@ -33,9 +33,9 @@ require (
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
36-
golang.org/x/tools v0.22.0
36+
golang.org/x/tools v0.24.0
3737
google.golang.org/genproto/googleapis/api v0.0.0-20240610135401-a8a62080eff3
38-
google.golang.org/grpc v1.64.1
38+
google.golang.org/grpc v1.65.0
3939
google.golang.org/protobuf v1.34.2
4040
mvdan.cc/gofumpt v0.6.0
4141
pgregory.net/rapid v1.1.0
@@ -222,7 +222,6 @@ require (
222222
github.com/ldez/tagliatelle v0.5.0 // indirect
223223
github.com/leonklingele/grouper v1.1.2 // indirect
224224
github.com/lib/pq v1.10.9 // indirect
225-
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
226225
github.com/linxGnu/grocksdb v1.8.14 // indirect
227226
github.com/lufeee/execinquery v1.2.1 // indirect
228227
github.com/macabu/inamedparam v0.1.3 // indirect
@@ -323,20 +322,20 @@ require (
323322
go.uber.org/automaxprocs v1.5.3 // indirect
324323
go.uber.org/multierr v1.10.0 // indirect
325324
go.uber.org/zap v1.24.0 // indirect
326-
golang.org/x/crypto v0.24.0 // indirect
325+
golang.org/x/crypto v0.26.0 // indirect
327326
golang.org/x/exp v0.0.0-20240404231335-c0f41cb1a7a0 // indirect
328327
golang.org/x/exp/typeparams v0.0.0-20240314144324-c7f7c6466f7f // indirect
329-
golang.org/x/mod v0.18.0 // indirect
330-
golang.org/x/net v0.26.0 // indirect
328+
golang.org/x/mod v0.20.0 // indirect
329+
golang.org/x/net v0.28.0 // indirect
331330
golang.org/x/oauth2 v0.20.0 // indirect
332-
golang.org/x/sync v0.7.0 // indirect
333-
golang.org/x/sys v0.21.0 // indirect
334-
golang.org/x/term v0.21.0 // indirect
335-
golang.org/x/text v0.16.0 // indirect
331+
golang.org/x/sync v0.8.0 // indirect
332+
golang.org/x/sys v0.23.0 // indirect
333+
golang.org/x/term v0.23.0 // indirect
334+
golang.org/x/text v0.17.0 // indirect
336335
golang.org/x/time v0.5.0 // indirect
337336
google.golang.org/api v0.180.0 // indirect
338337
google.golang.org/genproto v0.0.0-20240401170217-c3f982113cda // indirect
339-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240604185151-ef581f913117 // indirect
338+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240709173604-40e1e62336c5 // indirect
340339
gopkg.in/ini.v1 v1.67.0 // indirect
341340
gopkg.in/yaml.v2 v2.4.0 // indirect
342341
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

Lines changed: 34 additions & 36 deletions
Large diffs are not rendered by default.

tests/app/ante.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
// AnteHandlerOptions are the options required for constructing an SDK AnteHandler with the fee market injected.
1414
type AnteHandlerOptions struct {
1515
BaseOptions authante.HandlerOptions
16+
BankKeeper feemarketante.BankKeeper
1617
AccountKeeper feemarketante.AccountKeeper
1718
FeeMarketKeeper feemarketante.FeeMarketKeeper
1819
}
@@ -26,7 +27,7 @@ func NewAnteHandler(options AnteHandlerOptions) (sdk.AnteHandler, error) {
2627
}
2728

2829
if options.BaseOptions.BankKeeper == nil {
29-
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for ante builder")
30+
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "base options bank keeper is required for ante builder")
3031
}
3132

3233
if options.BaseOptions.SignModeHandler == nil {
@@ -37,6 +38,10 @@ func NewAnteHandler(options AnteHandlerOptions) (sdk.AnteHandler, error) {
3738
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "feemarket keeper is required for ante builder")
3839
}
3940

41+
if options.BankKeeper == nil {
42+
return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper keeper is required for ante builder")
43+
}
44+
4045
anteDecorators := []sdk.AnteDecorator{
4146
authante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
4247
authante.NewExtensionOptionsDecorator(options.BaseOptions.ExtensionOptionChecker),
@@ -45,6 +50,9 @@ func NewAnteHandler(options AnteHandlerOptions) (sdk.AnteHandler, error) {
4550
authante.NewValidateMemoDecorator(options.AccountKeeper),
4651
authante.NewConsumeGasForTxSizeDecorator(options.AccountKeeper),
4752
feemarketante.NewFeeMarketCheckDecorator( // fee market check replaces fee deduct decorator
53+
options.AccountKeeper,
54+
options.BankKeeper,
55+
options.BaseOptions.FeegrantKeeper,
4856
options.FeeMarketKeeper,
4957
authante.NewDeductFeeDecorator(
5058
options.AccountKeeper,

tests/app/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ func NewSimApp(
520520
anteOptions := AnteHandlerOptions{
521521
BaseOptions: anteHandlerOptions,
522522
AccountKeeper: app.AccountKeeper,
523+
BankKeeper: app.BankKeeper,
523524
FeeMarketKeeper: app.FeeMarketKeeper,
524525
}
525526
anteHandler, err := NewAnteHandler(anteOptions)
@@ -530,7 +531,6 @@ func NewSimApp(
530531
postHandlerOptions := PostHandlerOptions{
531532
AccountKeeper: app.AccountKeeper,
532533
BankKeeper: app.BankKeeper,
533-
FeeGrantKeeper: app.FeeGrantKeeper,
534534
FeeMarketKeeper: app.FeeMarketKeeper,
535535
}
536536
postHandler, err := NewPostHandler(postHandlerOptions)

tests/app/feemarketd/cmd/commands.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,10 @@ import (
55
"io"
66
"os"
77

8-
"github.com/skip-mev/feemarket/tests/app"
9-
10-
cmtcfg "github.com/cometbft/cometbft/config"
11-
dbm "github.com/cosmos/cosmos-db"
12-
"github.com/spf13/cobra"
13-
"github.com/spf13/viper"
14-
158
"cosmossdk.io/log"
169
confixcmd "cosmossdk.io/tools/confix/cmd"
17-
10+
cmtcfg "github.com/cometbft/cometbft/config"
11+
dbm "github.com/cosmos/cosmos-db"
1812
"github.com/cosmos/cosmos-sdk/client"
1913
"github.com/cosmos/cosmos-sdk/client/debug"
2014
"github.com/cosmos/cosmos-sdk/client/flags"
@@ -30,6 +24,10 @@ import (
3024
authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
3125
"github.com/cosmos/cosmos-sdk/x/crisis"
3226
genutilcli "github.com/cosmos/cosmos-sdk/x/genutil/client/cli"
27+
"github.com/spf13/cobra"
28+
"github.com/spf13/viper"
29+
30+
"github.com/skip-mev/feemarket/tests/app"
3331
)
3432

3533
// initCometBFTConfig helps to override default CometBFT Config values.

tests/app/post.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ type PostHandlerOptions struct {
1313
AccountKeeper feemarketpost.AccountKeeper
1414
BankKeeper feemarketpost.BankKeeper
1515
FeeMarketKeeper feemarketpost.FeeMarketKeeper
16-
FeeGrantKeeper feemarketpost.FeeGrantKeeper
1716
}
1817

1918
// NewPostHandler returns a PostHandler chain with the fee deduct decorator.
@@ -34,7 +33,6 @@ func NewPostHandler(options PostHandlerOptions) (sdk.PostHandler, error) {
3433
feemarketpost.NewFeeMarketDeductDecorator(
3534
options.AccountKeeper,
3635
options.BankKeeper,
37-
options.FeeGrantKeeper,
3836
options.FeeMarketKeeper,
3937
),
4038
}

tests/e2e/setup.go

Lines changed: 60 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func (s *TestSuite) QueryParams() types.Params {
8282
cc, err := grpc.NewClient(grpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
8383
s.Require().NoError(err)
8484

85-
// create the oracle client
85+
// create the feemarket client
8686
c := types.NewQueryClient(cc)
8787

8888
resp, err := c.Params(context.Background(), &types.ParamsRequest{})
@@ -91,6 +91,29 @@ func (s *TestSuite) QueryParams() types.Params {
9191
return resp.Params
9292
}
9393

94+
func (s *TestSuite) QueryBalance(user ibc.Wallet) sdk.Coin {
95+
s.T().Helper()
96+
97+
// get grpc address
98+
grpcAddr := s.chain.GetHostGRPCAddress()
99+
100+
// create the client
101+
cc, err := grpc.NewClient(grpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
102+
s.Require().NoError(err)
103+
104+
// create the bank client
105+
c := banktypes.NewQueryClient(cc)
106+
107+
resp, err := c.Balance(context.Background(), &banktypes.QueryBalanceRequest{
108+
Address: user.FormattedAddress(),
109+
Denom: defaultDenom,
110+
})
111+
s.Require().NoError(err)
112+
s.Require().NotNil(*resp.Balance)
113+
114+
return *resp.Balance
115+
}
116+
94117
func (s *TestSuite) QueryState() types.State {
95118
s.T().Helper()
96119

@@ -100,7 +123,7 @@ func (s *TestSuite) QueryState() types.State {
100123
cc, err := grpc.NewClient(grpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
101124
s.Require().NoError(err)
102125

103-
// create the oracle client
126+
// create the feemarket client
104127
c := types.NewQueryClient(cc)
105128

106129
resp, err := c.State(context.Background(), &types.StateRequest{})
@@ -119,7 +142,7 @@ func (s *TestSuite) QueryDefaultGasPrice() sdk.DecCoin {
119142
cc, err := grpc.NewClient(grpcAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
120143
s.Require().NoError(err)
121144

122-
// create the oracle client
145+
// create the feemarket client
123146
c := types.NewQueryClient(cc)
124147

125148
resp, err := c.GasPrice(context.Background(), &types.GasPriceRequest{
@@ -339,13 +362,32 @@ func (s *TestSuite) SendCoinsMultiBroadcast(ctx context.Context, sender, receive
339362
}
340363
}
341364

342-
tx := s.CreateTx(s.chain, sender, fees.String(), gas, msgs...)
365+
tx := s.CreateTx(s.chain, sender, fees.String(), gas, false, msgs...)
343366

344367
// get an rpc endpoint for the chain
345368
c := s.chain.Nodes()[0].Client
346369
return c.BroadcastTxCommit(ctx, tx)
347370
}
348371

372+
func (s *TestSuite) SendCoinsMultiBroadcastAsync(ctx context.Context, sender, receiver ibc.Wallet, amt, fees sdk.Coins,
373+
gas int64, numMsg int, bumpSequence bool,
374+
) (*coretypes.ResultBroadcastTx, error) {
375+
msgs := make([]sdk.Msg, numMsg)
376+
for i := 0; i < numMsg; i++ {
377+
msgs[i] = &banktypes.MsgSend{
378+
FromAddress: sender.FormattedAddress(),
379+
ToAddress: receiver.FormattedAddress(),
380+
Amount: amt,
381+
}
382+
}
383+
384+
tx := s.CreateTx(s.chain, sender, fees.String(), gas, bumpSequence, msgs...)
385+
386+
// get an rpc endpoint for the chain
387+
c := s.chain.Nodes()[0].Client
388+
return c.BroadcastTxAsync(ctx, tx)
389+
}
390+
349391
// SendCoins creates a executes a SendCoins message and broadcasts the transaction.
350392
func (s *TestSuite) SendCoins(ctx context.Context, keyName, sender, receiver string, amt, fees sdk.Coins, gas int64) (string, error) {
351393
resp, err := s.ExecTx(
@@ -383,7 +425,14 @@ func (s *TestSuite) GetAndFundTestUserWithMnemonic(
383425
return nil, fmt.Errorf("failed to get source user wallet: %w", err)
384426
}
385427

386-
_, err = s.SendCoins(
428+
s.FundUser(ctx, chain, amount, user)
429+
return user, nil
430+
}
431+
432+
func (s *TestSuite) FundUser(ctx context.Context, chain ibc.Chain, amount int64, user ibc.Wallet) {
433+
chainCfg := chain.Config()
434+
435+
_, err := s.SendCoins(
387436
ctx,
388437
interchaintest.FaucetAccountKeyName,
389438
interchaintest.FaucetAccountKeyName,
@@ -393,7 +442,6 @@ func (s *TestSuite) GetAndFundTestUserWithMnemonic(
393442
1000000,
394443
)
395444
s.Require().NoError(err, "failed to get funds from faucet")
396-
return user, nil
397445
}
398446

399447
// GetAndFundTestUsers generates and funds chain users with the native chain denom.
@@ -433,7 +481,9 @@ func (s *TestSuite) ExecTx(ctx context.Context, chain *cosmos.CosmosChain, keyNa
433481
}
434482

435483
// CreateTx creates a new transaction to be signed by the given user, including a provided set of messages
436-
func (s *TestSuite) CreateTx(chain *cosmos.CosmosChain, user cosmos.User, fee string, gas int64, msgs ...sdk.Msg) []byte {
484+
func (s *TestSuite) CreateTx(chain *cosmos.CosmosChain, user cosmos.User, fee string, gas int64,
485+
bumpSequence bool, msgs ...sdk.Msg,
486+
) []byte {
437487
bc := cosmos.NewBroadcaster(s.T(), chain)
438488

439489
ctx := context.Background()
@@ -457,6 +507,9 @@ func (s *TestSuite) CreateTx(chain *cosmos.CosmosChain, user cosmos.User, fee st
457507

458508
// update sequence number
459509
txf = txf.WithSequence(txf.Sequence())
510+
if bumpSequence {
511+
txf = txf.WithSequence(txf.Sequence() + 1)
512+
}
460513

461514
// sign the tx
462515
txBuilder, err := txf.BuildUnsignedTx(msgs...)

0 commit comments

Comments
 (0)