Skip to content

Commit

Permalink
Merge pull request #39 from m-Peter/configurable-gas-price
Browse files Browse the repository at this point in the history
Make value returned by `eth_gasPrice` configurable
  • Loading branch information
m-Peter authored Feb 6, 2024
2 parents 4d4d3d3 + 7a979d0 commit c8c43be
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
3 changes: 1 addition & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
)

const EthNamespace = "eth"
const defaultGasPrice = 8049999872

// TODO: Fetch these from flow-go/fvm/evm/emulator/config.go
var (
Expand Down Expand Up @@ -211,7 +210,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
3 changes: 3 additions & 0 deletions api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/ethereum/go-ethereum/common"
)

var DefaultGasPrice = big.NewInt(8049999872)

// TODO(m-Peter) Add more config options, such as:
// - host
// - port
Expand All @@ -15,4 +17,5 @@ import (
type Config struct {
ChainID *big.Int
Coinbase common.Address
GasPrice *big.Int
}
2 changes: 2 additions & 0 deletions api/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestServerJSONRPCOveHTTPHandler(t *testing.T) {
config := &api.Config{
ChainID: api.FlowEVMTestnetChainID,
Coinbase: common.HexToAddress("0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb"),
GasPrice: api.DefaultGasPrice,
}
blockchainAPI := api.NewBlockChainAPI(config, store, mockFlowClient)
supportedAPIs := api.SupportedAPIs(blockchainAPI)
Expand Down Expand Up @@ -230,6 +231,7 @@ func TestServerJSONRPCOveWebSocketHandler(t *testing.T) {
config := &api.Config{
ChainID: api.FlowEVMTestnetChainID,
Coinbase: common.HexToAddress("0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb"),
GasPrice: 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.Int64(), "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

0 comments on commit c8c43be

Please sign in to comment.