Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/dynamic fees #91

Merged
merged 15 commits into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ RELAYER_NEUTRON_CHAIN_TIMEOUT=10s
RELAYER_NEUTRON_CHAIN_GAS_PRICES=0.5untrn
RELAYER_NEUTRON_CHAIN_GAS_LIMIT=10000000
RELAYER_NEUTRON_CHAIN_GAS_ADJUSTMENT=2.0
RELAYER_NEUTRON_CHAIN_DENOM=untrn
RELAYER_NEUTRON_CHAIN_MAX_GAS_PRICE=1000
RELAYER_NEUTRON_CHAIN_GAS_PRICE_MULTIPLIER=1.1
RELAYER_NEUTRON_CHAIN_CONNECTION_ID=connection-0
RELAYER_NEUTRON_CHAIN_DEBUG=true
RELAYER_NEUTRON_CHAIN_KEYRING_BACKEND=test
Expand Down
3 changes: 3 additions & 0 deletions .env.example.dev
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ RELAYER_NEUTRON_CHAIN_HOME_DIR=../neutron/data/test-1
RELAYER_NEUTRON_CHAIN_SIGN_KEY_NAME=demowallet3
RELAYER_NEUTRON_CHAIN_TIMEOUT=1000s
RELAYER_NEUTRON_CHAIN_GAS_ADJUSTMENT=2.0
RELAYER_NEUTRON_CHAIN_DENOM=untrn
RELAYER_NEUTRON_CHAIN_MAX_GAS_PRICE=1000
RELAYER_NEUTRON_CHAIN_GAS_PRICE_MULTIPLIER=1.1
RELAYER_NEUTRON_CHAIN_TX_BROADCAST_TYPE=BroadcastTxCommit
RELAYER_NEUTRON_CHAIN_CONNECTION_ID=connection-0
RELAYER_NEUTRON_CHAIN_CLIENT_ID=07-tendermint-0
Expand Down
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.22.3

require (
cosmossdk.io/api v0.7.5
cosmossdk.io/math v1.3.0
github.com/avast/retry-go/v4 v4.5.1
github.com/cometbft/cometbft v0.38.7
github.com/cosmos/cosmos-sdk v0.50.7
Expand All @@ -14,16 +15,19 @@ require (
github.com/go-openapi/strfmt v0.21.3
github.com/go-openapi/swag v0.22.3
github.com/go-openapi/validate v0.21.0
github.com/golang/mock v1.6.0
github.com/gorilla/mux v1.8.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/neutron-org/neutron-logger v0.0.0-20221027125151-535167f2dd73
github.com/neutron-org/neutron/v4 v4.0.1
github.com/prometheus/client_golang v1.19.1
github.com/skip-mev/feemarket v1.0.3
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d
go.uber.org/mock v0.4.0
go.uber.org/zap v1.27.0

)

require (
Expand All @@ -38,7 +42,6 @@ require (
cosmossdk.io/depinject v1.0.0-alpha.4 // indirect
cosmossdk.io/errors v1.0.1 // indirect
cosmossdk.io/log v1.3.1 // indirect
cosmossdk.io/math v1.3.0 // indirect
cosmossdk.io/store v1.1.0 // indirect
cosmossdk.io/x/feegrant v0.1.1 // indirect
cosmossdk.io/x/tx v0.13.3 // indirect
Expand Down Expand Up @@ -121,7 +124,6 @@ require (
github.com/gogo/protobuf v1.3.3 // indirect
github.com/golang/glog v1.2.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/golang/snappy v0.0.5-0.20220116011046-fa5810519dcb // indirect
github.com/google/btree v1.1.2 // indirect
Expand Down Expand Up @@ -197,7 +199,6 @@ require (
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1480,6 +1480,8 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/skip-mev/feemarket v1.0.3 h1:DpB1tj51MlFN5iOg1lN+fwWqSF62xdND46BqgTko0C4=
github.com/skip-mev/feemarket v1.0.3/go.mod h1:lszt7zGEEActbDYq1hOKogQvfCsnLEHH5113LwgmYcE=
github.com/sourcegraph/conc v0.3.0 h1:OQTbbt6P72L20UqAkXXuLOj79LfEanQ+YQFNpLA9ySo=
github.com/sourcegraph/conc v0.3.0/go.mod h1:Sdozi7LEKbFPqYX2/J+iBAM6HpqSLTASQIKqDmF7Mt0=
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
Expand Down Expand Up @@ -1930,7 +1932,6 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220624220833-87e55d714810/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
29 changes: 16 additions & 13 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,22 @@ type NeutronQueryRelayerConfig struct {
const EnvPrefix string = "RELAYER"

type NeutronChainConfig struct {
RPCAddr string `required:"true" split_words:"true"`
RESTAddr string `required:"true" split_words:"true"`
HomeDir string `required:"true" split_words:"true"`
SignKeyName string `required:"true" split_words:"true"`
Timeout time.Duration `split_words:"true" default:"10s"`
GasPrices string `required:"true" split_words:"true"`
GasLimit uint64 `split_words:"true" default:"0"`
GasAdjustment float64 `required:"true" split_words:"true"`
ConnectionID string `required:"true" split_words:"true"`
Debug bool `split_words:"true" default:"false"`
KeyringBackend string `required:"true" split_words:"true"`
OutputFormat string `split_words:"true" default:"json"`
SignModeStr string `split_words:"true" default:"direct"`
RPCAddr string `required:"true" split_words:"true"`
RESTAddr string `required:"true" split_words:"true"`
HomeDir string `required:"true" split_words:"true"`
SignKeyName string `required:"true" split_words:"true"`
Timeout time.Duration `split_words:"true" default:"10s"`
GasPrices string `required:"true" split_words:"true"`
GasLimit uint64 `split_words:"true" default:"0"`
GasAdjustment float64 `required:"true" split_words:"true"`
ConnectionID string `required:"true" split_words:"true"`
Debug bool `split_words:"true" default:"false"`
KeyringBackend string `required:"true" split_words:"true"`
OutputFormat string `split_words:"true" default:"json"`
SignModeStr string `split_words:"true" default:"direct"`
Denom string `required:"true" split_words:"true"`
MaxGasPrice float64 `required:"true" split_words:"true"`
GasPriceMultiplier float64 `required:"true" split_words:"true"`
}

type TargetChainConfig struct {
Expand Down
153 changes: 153 additions & 0 deletions internal/submit/submit_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package submit

import (
"context"
"testing"

cosmossdk_io_math "cosmossdk.io/math"
abci "github.com/cometbft/cometbft/abci/types"
coretypes "github.com/cometbft/cometbft/rpc/core/types"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types"
authtxtypes "github.com/cosmos/cosmos-sdk/x/auth/tx"
"github.com/golang/mock/gomock"
submit_mock "github.com/neutron-org/neutron-query-relayer/testutil/mocks/submit"
feemarkettypes "github.com/skip-mev/feemarket/x/feemarket/types"
"github.com/stretchr/testify/require"
"go.uber.org/zap"
)

func setupTest(t *testing.T, gasMultiplier float64, maxGas float64, gasPrices string, mockClient *submit_mock.MockClient) *TxSender {
logger, _ := zap.NewDevelopment()
txConfig := authtxtypes.NewTxConfig(codec.NewProtoCodec(nil), authtxtypes.DefaultSignModes)
return &TxSender{
rpcClient: mockClient,
txConfig: txConfig,
logger: logger,
denom: "testdenom",
gasPriceMultiplier: gasMultiplier,
maxGasPrice: maxGas,
gasPrices: gasPrices,
}
}

func TestQueryDynamicPrice(t *testing.T) {
tests := []struct {
name string
gasMultiplier float64
maxGas float64
gasPrices string
mockResponse *coretypes.ResultABCIQuery
expectedPrice string
expectError bool
}{
{
name: "Basic",
gasMultiplier: 1.0,
maxGas: 100000000,
mockResponse: &coretypes.ResultABCIQuery{
Response: abci.ResponseQuery{
Code: 0,
Value: func() []byte {
gasPrice := feemarkettypes.GasPriceResponse{
Price: types.DecCoin{
Denom: "testdenom",
Amount: cosmossdk_io_math.LegacyNewDec(123),
},
}
rawGasPrice, _ := gasPrice.Marshal()
return rawGasPrice
}(),
},
},
expectedPrice: "123testdenom",
expectError: false,
},
{
name: "Multiply",
gasMultiplier: 1.1,
maxGas: 100000000,
mockResponse: &coretypes.ResultABCIQuery{
Response: abci.ResponseQuery{
Code: 0,
Value: func() []byte {
gasPrice := feemarkettypes.GasPriceResponse{
Price: types.DecCoin{
Denom: "testdenom",
Amount: cosmossdk_io_math.LegacyNewDec(123),
},
}
rawGasPrice, _ := gasPrice.Marshal()
return rawGasPrice
}(),
},
},
expectedPrice: "135.3testdenom",
expectError: false,
},
{
name: "DefaultGasPrice",
gasMultiplier: 1.0,
maxGas: 100.0,
gasPrices: "99.0testdenom",
mockResponse: &coretypes.ResultABCIQuery{
Response: abci.ResponseQuery{
Code: 1,
},
},
expectedPrice: "99.0testdenom",
expectError: false,
},
{
name: "MaxGasPrice",
gasMultiplier: 1.5,
maxGas: 111.1,
gasPrices: "99.0testdenom",
mockResponse: &coretypes.ResultABCIQuery{
Response: abci.ResponseQuery{
Code: 0,
Value: func() []byte {
gasPrice := feemarkettypes.GasPriceResponse{
Price: types.DecCoin{
Denom: "testdenom",
Amount: cosmossdk_io_math.LegacyNewDec(123),
},
}
rawGasPrice, _ := gasPrice.Marshal()
return rawGasPrice
}(),
},
},
expectedPrice: "111.1testdenom",
expectError: false,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()

mockClient := submit_mock.NewMockClient(ctrl)
txs := setupTest(t, tt.gasMultiplier, tt.maxGas, tt.gasPrices, mockClient)

if tt.mockResponse != nil {
mockClient.EXPECT().
ABCIQueryWithOptions(gomock.Any(), getPricesQueryPath, gomock.Any(), gomock.Any()).
Return(tt.mockResponse, nil)
} else {
mockClient.EXPECT().
ABCIQueryWithOptions(gomock.Any(), getPricesQueryPath, gomock.Any(), gomock.Any()).
Return(nil, nil)
}

price, err := txs.getGasPrice(context.Background())
if tt.expectError {
require.Error(t, err)
} else {
require.NoError(t, err)
require.Equal(t, tt.expectedPrice, price)
}
})
}
}
Loading
Loading