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

Make value returned by eth_gasPrice configurable #39

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

const EthNamespace = "eth"
const defaultGasPrice = 8049999872
const DefaultGasPrice = 8049999872
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

probably better to have these default config variables in the config.go

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also to make it big.int type since that is needed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea 👍 Updated in 7a979d0


// TODO: Fetch these from flow-go/fvm/evm/emulator/config.go
var (
Expand Down Expand Up @@ -211,7 +211,7 @@ func (s *BlockChainAPI) FeeHistory(
// eth_gasPrice (returns the gas price)
// GasPrice returns a suggestion for a gas price for legacy transactions.
func (s *BlockChainAPI) GasPrice(ctx context.Context) (*hexutil.Big, error) {
return (*hexutil.Big)(big.NewInt(defaultGasPrice)), nil
return (*hexutil.Big)(s.config.GasPrice), nil
}

// eth_maxPriorityFeePerGas
Expand Down
9 changes: 8 additions & 1 deletion api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,17 @@ func TestBlockChainAPI(t *testing.T) {
})

t.Run("GasPrice", func(t *testing.T) {
config := &api.Config{
ChainID: api.FlowEVMTestnetChainID,
Coinbase: common.HexToAddress("0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb"),
GasPrice: big.NewInt(5049999872),
}
blockchainAPI := api.NewBlockChainAPI(config, store, flowClient)

gasPrice, err := blockchainAPI.GasPrice(context.Background())
require.NoError(t, err)

assert.Equal(t, gasPrice, (*hexutil.Big)(big.NewInt(8049999872)))
assert.Equal(t, gasPrice, (*hexutil.Big)(big.NewInt(5049999872)))
})

t.Run("MaxPriorityFeePerGas", func(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ import (
type Config struct {
ChainID *big.Int
Coinbase common.Address
GasPrice *big.Int
}
3 changes: 3 additions & 0 deletions api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
_ "embed"
"encoding/hex"
"io"
"math/big"
"net/http"
"strings"
"testing"
Expand Down Expand Up @@ -40,6 +41,7 @@ func TestServerJSONRPCOveHTTPHandler(t *testing.T) {
config := &api.Config{
ChainID: api.FlowEVMTestnetChainID,
Coinbase: common.HexToAddress("0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb"),
GasPrice: big.NewInt(api.DefaultGasPrice),
}
blockchainAPI := api.NewBlockChainAPI(config, store, mockFlowClient)
supportedAPIs := api.SupportedAPIs(blockchainAPI)
Expand Down Expand Up @@ -230,6 +232,7 @@ func TestServerJSONRPCOveWebSocketHandler(t *testing.T) {
config := &api.Config{
ChainID: api.FlowEVMTestnetChainID,
Coinbase: common.HexToAddress("0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb"),
GasPrice: big.NewInt(api.DefaultGasPrice),
}
flowClient, err := api.NewFlowClient(grpc.EmulatorHost)
require.NoError(t, err)
Expand Down
9 changes: 7 additions & 2 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"flag"
"fmt"
"math/big"
"runtime"
"time"

Expand Down Expand Up @@ -33,13 +34,17 @@ var evmEventTypes = []string{

func main() {
var network, coinbase string
var gasPrice int64

flag.StringVar(&network, "network", "testnet", "network to connect the gateway to")
flag.StringVar(&coinbase, "coinbase", coinbaseAddr, "coinbase address to use for fee collection")
flag.Int64Var(&gasPrice, "gasPrice", api.DefaultGasPrice, "gas price for transactions")
flag.Parse()

config := &api.Config{}
config.Coinbase = common.HexToAddress(coinbase)
config := &api.Config{
Coinbase: common.HexToAddress(coinbase),
GasPrice: big.NewInt(gasPrice),
}
if network == "testnet" {
config.ChainID = api.FlowEVMTestnetChainID
} else if network == "mainnet" {
Expand Down
Loading