aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--eth/api.go46
-rw-r--r--eth/api_backend.go37
-rw-r--r--eth/api_tracer.go32
-rw-r--r--eth/filters/api.go5
-rw-r--r--eth/filters/filter.go2
-rw-r--r--internal/ethapi/api.go65
-rw-r--r--plugin/evm/config.go39
-rw-r--r--plugin/evm/service.go67
-rw-r--r--plugin/evm/vm.go23
-rw-r--r--plugin/main.go7
-rw-r--r--plugin/params.go41
-rw-r--r--rpc/types.go9
12 files changed, 185 insertions, 188 deletions
diff --git a/eth/api.go b/eth/api.go
index ada2a97..bad357d 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -278,21 +278,13 @@ func NewPublicDebugAPI(eth *Ethereum) *PublicDebugAPI {
// DumpBlock retrieves the entire state of the database at a given block.
func (api *PublicDebugAPI) DumpBlock(blockNr rpc.BlockNumber) (state.Dump, error) {
- if blockNr == rpc.PendingBlockNumber {
- // If we're dumping the pending state, we need to request
- // both the pending block as well as the pending state from
- // the miner and operate on those
- _, stateDb := api.eth.miner.Pending()
- return stateDb.RawDump(false, false, true), nil
- }
var block *types.Block
- if blockNr == rpc.LatestBlockNumber {
- block = api.eth.blockchain.CurrentBlock()
- } else if blockNr == rpc.AcceptedBlockNumber {
+ if blockNr.IsAccepted() {
block = api.eth.AcceptedBlock()
} else {
block = api.eth.blockchain.GetBlockByNumber(uint64(blockNr))
}
+
if block == nil {
return state.Dump{}, fmt.Errorf("block #%d not found", blockNr)
}
@@ -362,27 +354,19 @@ func (api *PublicDebugAPI) AccountRange(blockNrOrHash rpc.BlockNumberOrHash, sta
var err error
if number, ok := blockNrOrHash.Number(); ok {
- if number == rpc.PendingBlockNumber {
- // If we're dumping the pending state, we need to request
- // both the pending block as well as the pending state from
- // the miner and operate on those
- _, stateDb = api.eth.miner.Pending()
+ var block *types.Block
+ if number.IsAccepted() {
+ block = api.eth.AcceptedBlock()
} else {
- var block *types.Block
- if number == rpc.LatestBlockNumber {
- block = api.eth.blockchain.CurrentBlock()
- } else if number == rpc.AcceptedBlockNumber {
- block = api.eth.AcceptedBlock()
- } else {
- block = api.eth.blockchain.GetBlockByNumber(uint64(number))
- }
- if block == nil {
- return state.IteratorDump{}, fmt.Errorf("block #%d not found", number)
- }
- stateDb, err = api.eth.BlockChain().StateAt(block.Root())
- if err != nil {
- return state.IteratorDump{}, err
- }
+ block = api.eth.blockchain.GetBlockByNumber(uint64(number))
+ }
+
+ if block == nil {
+ return state.IteratorDump{}, fmt.Errorf("block #%d not found", number)
+ }
+ stateDb, err = api.eth.BlockChain().StateAt(block.Root())
+ if err != nil {
+ return state.IteratorDump{}, err
}
} else if hash, ok := blockNrOrHash.Hash(); ok {
block := api.eth.blockchain.GetBlockByHash(hash)
@@ -393,6 +377,8 @@ func (api *PublicDebugAPI) AccountRange(blockNrOrHash rpc.BlockNumberOrHash, sta
if err != nil {
return state.IteratorDump{}, err
}
+ } else {
+ return state.IteratorDump{}, errors.New("either block number or block hash must be specified")
}
if maxResults > AccountRangeMaxResults || maxResults <= 0 {
diff --git a/eth/api_backend.go b/eth/api_backend.go
index 6c5ebd8..f1b5f74 100644
--- a/eth/api_backend.go
+++ b/eth/api_backend.go
@@ -65,20 +65,12 @@ func (b *EthAPIBackend) SetHead(number uint64) {
}
func (b *EthAPIBackend) HeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Header, error) {
- // Pending block is only known by the miner in
- // Ethereum, but Coreth does not have the same notion.
- // So we treat requests for the pending block identically
- // to the latest accepted block instead
- if number == rpc.PendingBlockNumber {
- return b.eth.AcceptedBlock().Header(), nil
- }
- // Otherwise resolve and return the block
- if number == rpc.LatestBlockNumber {
- return b.eth.blockchain.CurrentBlock().Header(), nil
- }
- if number == rpc.AcceptedBlockNumber {
+ // Treat requests for the pending, latest, or accepted block
+ // identically.
+ if number.IsAccepted() {
return b.eth.AcceptedBlock().Header(), nil
}
+
return b.eth.blockchain.GetHeaderByNumber(uint64(number)), nil
}
@@ -104,20 +96,12 @@ func (b *EthAPIBackend) HeaderByHash(ctx context.Context, hash common.Hash) (*ty
}
func (b *EthAPIBackend) BlockByNumber(ctx context.Context, number rpc.BlockNumber) (*types.Block, error) {
- // Pending block is only known by the miner in
- // Ethereum, but Coreth does not have the same notion.
- // So we treat requests for the pending block identically
- // to the latest accepted block instead
- if number == rpc.PendingBlockNumber {
- return b.eth.AcceptedBlock(), nil
- }
- // Otherwise resolve and return the block
- if number == rpc.LatestBlockNumber {
- return b.eth.blockchain.CurrentBlock(), nil
- }
- if number == rpc.AcceptedBlockNumber {
+ // Treat requests for the pending, latest, or accepted block
+ // identically.
+ if number.IsAccepted() {
return b.eth.AcceptedBlock(), nil
}
+
return b.eth.blockchain.GetBlockByNumber(uint64(number)), nil
}
@@ -147,11 +131,6 @@ func (b *EthAPIBackend) BlockByNumberOrHash(ctx context.Context, blockNrOrHash r
}
func (b *EthAPIBackend) StateAndHeaderByNumber(ctx context.Context, number rpc.BlockNumber) (*state.StateDB, *types.Header, error) {
- // Note: Ethereum typically first checks if the request is for
- // the pending block (by rpc.PendingBlockNumber), but Coreth
- // does not have the same notion of the miner having a pending
- // block, so this is skipped here
-
// Request the block by its number and retrieve its state
header, err := b.HeaderByNumber(ctx, number)
if err != nil {
diff --git a/eth/api_tracer.go b/eth/api_tracer.go
index c044dcc..23209de 100644
--- a/eth/api_tracer.go
+++ b/eth/api_tracer.go
@@ -105,26 +105,18 @@ func (api *PrivateDebugAPI) TraceChain(ctx context.Context, start, end rpc.Block
// Fetch the block interval that we want to trace
var from, to *types.Block
- switch start {
- case rpc.PendingBlockNumber:
- from = api.eth.miner.PendingBlock()
- case rpc.LatestBlockNumber:
- from = api.eth.blockchain.CurrentBlock()
- case rpc.AcceptedBlockNumber:
+ if start.IsAccepted() {
from = api.eth.AcceptedBlock()
- default:
+ } else {
from = api.eth.blockchain.GetBlockByNumber(uint64(start))
}
- switch end {
- case rpc.PendingBlockNumber:
- to = api.eth.miner.PendingBlock()
- case rpc.LatestBlockNumber:
- to = api.eth.blockchain.CurrentBlock()
- case rpc.AcceptedBlockNumber:
- from = api.eth.AcceptedBlock()
- default:
+
+ if end.IsAccepted() {
+ to = api.eth.AcceptedBlock()
+ } else {
to = api.eth.blockchain.GetBlockByNumber(uint64(end))
}
+
// Trace the chain if we've found all our blocks
if from == nil {
return nil, fmt.Errorf("starting block #%d not found", start)
@@ -360,16 +352,12 @@ func (api *PrivateDebugAPI) TraceBlockByNumber(ctx context.Context, number rpc.B
// Fetch the block that we want to trace
var block *types.Block
- switch number {
- case rpc.PendingBlockNumber:
- block = api.eth.miner.PendingBlock()
- case rpc.LatestBlockNumber:
- block = api.eth.blockchain.CurrentBlock()
- case rpc.AcceptedBlockNumber:
+ if number.IsAccepted() {
block = api.eth.AcceptedBlock()
- default:
+ } else {
block = api.eth.blockchain.GetBlockByNumber(uint64(number))
}
+
// Trace the block if it was found
if block == nil {
return nil, fmt.Errorf("block #%d not found", number)
diff --git a/eth/filters/api.go b/eth/filters/api.go
index 71e6454..9ee96af 100644
--- a/eth/filters/api.go
+++ b/eth/filters/api.go
@@ -330,6 +330,8 @@ func (api *PublicFilterAPI) GetLogs(ctx context.Context, crit FilterCriteria) ([
filter = NewBlockFilter(api.backend, *crit.BlockHash, crit.Addresses, crit.Topics)
} else {
// Convert the RPC block numbers into internal representations
+ // LatestBlockNumber is left in place here to be handled
+ // correctly within NewRangeFilter
begin := rpc.LatestBlockNumber.Int64()
if crit.FromBlock != nil {
begin = crit.FromBlock.Int64()
@@ -385,6 +387,9 @@ func (api *PublicFilterAPI) GetFilterLogs(ctx context.Context, id rpc.ID) ([]*ty
filter = NewBlockFilter(api.backend, *f.crit.BlockHash, f.crit.Addresses, f.crit.Topics)
} else {
// Convert the RPC block numbers into internal representations
+ // Leave LatestBlockNumber in place here as the defaults
+ // Should be handled correctly as request for the last
+ // accepted block instead throughout all APIs.
begin := rpc.LatestBlockNumber.Int64()
if f.crit.FromBlock != nil {
begin = f.crit.FromBlock.Int64()
diff --git a/eth/filters/filter.go b/eth/filters/filter.go
index 48a76c7..3c18e6e 100644
--- a/eth/filters/filter.go
+++ b/eth/filters/filter.go
@@ -129,6 +129,8 @@ func (f *Filter) Logs(ctx context.Context) ([]*types.Log, error) {
return f.blockLogs(ctx, header)
}
// Figure out the limits of the filter range
+ // LatestBlockNumber is handled appropriately in HeaderByNumber
+ // so it is left in place here.
header, _ := f.backend.HeaderByNumber(ctx, rpc.LatestBlockNumber)
if header == nil {
return nil, nil
diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go
index 825f8fc..728fb07 100644
--- a/internal/ethapi/api.go
+++ b/internal/ethapi/api.go
@@ -77,20 +77,21 @@ func (s *PublicEthereumAPI) ProtocolVersion() hexutil.Uint {
// - pulledStates: number of state entries processed until now
// - knownStates: number of known state entries that still need to be pulled
func (s *PublicEthereumAPI) Syncing() (interface{}, error) {
- progress := s.b.Downloader().Progress()
-
- // Return not syncing if the synchronisation already completed
- if progress.CurrentBlock >= progress.HighestBlock {
- return false, nil
- }
- // Otherwise gather the block sync stats
- return map[string]interface{}{
- "startingBlock": hexutil.Uint64(progress.StartingBlock),
- "currentBlock": hexutil.Uint64(progress.CurrentBlock),
- "highestBlock": hexutil.Uint64(progress.HighestBlock),
- "pulledStates": hexutil.Uint64(progress.PulledStates),
- "knownStates": hexutil.Uint64(progress.KnownStates),
- }, nil
+ return nil, errors.New("not implemented in coreth") // Info or Health API should be used instead
+ // progress := s.b.Downloader().Progress()
+
+ // // Return not syncing if the synchronisation already completed
+ // if progress.CurrentBlock >= progress.HighestBlock {
+ // return false, nil
+ // }
+ // // Otherwise gather the block sync stats
+ // return map[string]interface{}{
+ // "startingBlock": hexutil.Uint64(progress.StartingBlock),
+ // "currentBlock": hexutil.Uint64(progress.CurrentBlock),
+ // "highestBlock": hexutil.Uint64(progress.HighestBlock),
+ // "pulledStates": hexutil.Uint64(progress.PulledStates),
+ // "knownStates": hexutil.Uint64(progress.KnownStates),
+ // }, nil
}
// PublicTxPoolAPI offers and API for the transaction pool. It only operates on data that is non confidential.
@@ -546,8 +547,8 @@ func (s *PublicBlockChainAPI) BlockNumber() hexutil.Uint64 {
}
// GetBalance returns the amount of wei for the given address in the state of the
-// given block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta
-// block numbers are also allowed.
+// given block number. The rpc.LatestBlockNumber, rpc.PendingBlockNumber, and
+// rpc.AcceptedBlockNumber meta block numbers are also allowed.
func (s *PublicBlockChainAPI) GetBalance(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash) (*hexutil.Big, error) {
state, _, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
if state == nil || err != nil {
@@ -556,9 +557,9 @@ func (s *PublicBlockChainAPI) GetBalance(ctx context.Context, address common.Add
return (*hexutil.Big)(state.GetBalance(address)), state.Error()
}
-// GetBalanceMultiCoin returns the amount of wei for the given address in the state of the
-// given block number. The rpc.LatestBlockNumber and rpc.PendingBlockNumber meta
-// block numbers are also allowed.
+// GetAssetBalance returns the amount of wei for the given address in the state of the
+// given block number. The rpc.LatestBlockNumber, rpc.PendingBlockNumber, and
+// rpc.AcceptedBlockNumber meta block numbers are also allowed.
func (s *PublicBlockChainAPI) GetAssetBalance(ctx context.Context, address common.Address, blockNrOrHash rpc.BlockNumberOrHash, assetID ids.ID) (*hexutil.Big, error) {
state, _, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash)
if state == nil || err != nil {
@@ -640,12 +641,13 @@ func (s *PublicBlockChainAPI) GetHeaderByNumber(ctx context.Context, number rpc.
header, err := s.b.HeaderByNumber(ctx, number)
if header != nil && err == nil {
response := s.rpcMarshalHeader(ctx, header)
- if number == rpc.PendingBlockNumber {
- // Pending header need to nil out a few fields
- for _, field := range []string{"hash", "nonce", "miner"} {
- response[field] = nil
- }
- }
+ // coreth has no notion of a pending block
+ // if number == rpc.PendingBlockNumber {
+ // // Pending header need to nil out a few fields
+ // for _, field := range []string{"hash", "nonce", "miner"} {
+ // response[field] = nil
+ // }
+ // }
return response, err
}
return nil, err
@@ -669,12 +671,13 @@ func (s *PublicBlockChainAPI) GetBlockByNumber(ctx context.Context, number rpc.B
block, err := s.b.BlockByNumber(ctx, number)
if block != nil && err == nil {
response, err := s.rpcMarshalBlock(ctx, block, true, fullTx)
- if err == nil && number == rpc.PendingBlockNumber {
- // Pending blocks need to nil out a few fields
- for _, field := range []string{"hash", "nonce", "miner"} {
- response[field] = nil
- }
- }
+ // coreth has no notion of a pending block
+ // if err == nil && number == rpc.PendingBlockNumber {
+ // // Pending blocks need to nil out a few fields
+ // for _, field := range []string{"hash", "nonce", "miner"} {
+ // response[field] = nil
+ // }
+ // }
return response, err
}
return nil, err
diff --git a/plugin/evm/config.go b/plugin/evm/config.go
new file mode 100644
index 0000000..4669807
--- /dev/null
+++ b/plugin/evm/config.go
@@ -0,0 +1,39 @@
+package evm
+
+// CommandLineConfig ...
+type CommandLineConfig struct {
+ // Coreth APIs
+ SnowmanAPIEnabled bool `json:"snowmanAPIEnabled"`
+ Web3APIEnabled bool `json:"web3APIEnabled"`
+ CorethAdminAPIEnabled bool `json:"corethAdminAPIEnabled"`
+
+ // Coreth API Gas/Price Caps
+ RPCGasCap uint64 `json:"rpcGasCap"`
+ RPCTxFeeCap float64 `json:"rpcTxFeeCap"`
+
+ // Eth APIs
+ EthAPIEnabled bool `json:"ethAPIEnabled"`
+ PersonalAPIEnabled bool `json:"personalAPIEnabled"`
+ TxPoolAPIEnabled bool `json:"txPoolAPIEnabled"`
+ DebugAPIEnabled bool `json:"debugAPIEnabled"`
+}
+
+// EthAPIs returns an array of strings representing the Eth APIs that should be enabled
+func (c CommandLineConfig) EthAPIs() []string {
+ ethAPIs := make([]string, 0)
+
+ if c.EthAPIEnabled {
+ ethAPIs = append(ethAPIs, "eth")
+ }
+ if c.PersonalAPIEnabled {
+ ethAPIs = append(ethAPIs, "personal")
+ }
+ if c.TxPoolAPIEnabled {
+ ethAPIs = append(ethAPIs, "txpool")
+ }
+ if c.DebugAPIEnabled {
+ ethAPIs = append(ethAPIs, "debug")
+ }
+
+ return ethAPIs
+}
diff --git a/plugin/evm/service.go b/plugin/evm/service.go
index a844f10..128b98e 100644
--- a/plugin/evm/service.go
+++ b/plugin/evm/service.go
@@ -5,22 +5,18 @@ package evm
import (
"context"
- "crypto/rand"
"errors"
"fmt"
"math/big"
"net/http"
"strings"
- "github.com/ava-labs/coreth"
-
"github.com/ava-labs/avalanchego/api"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/constants"
"github.com/ava-labs/avalanchego/utils/crypto"
"github.com/ava-labs/avalanchego/utils/formatting"
"github.com/ava-labs/avalanchego/utils/json"
- "github.com/ava-labs/coreth/core/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
@@ -28,7 +24,7 @@ import (
)
const (
- version = "Athereum 1.0"
+ version = "coreth-v0.3.7"
)
// test constants
@@ -37,30 +33,12 @@ const (
GenesisTestKey = "0xabd71b35d559563fea757f0f5edbde286fb8c043105b15abb7cd57189306d7d1"
)
-// DebugAPI introduces helper functions for debuging
-type DebugAPI struct{ vm *VM }
-
// SnowmanAPI introduces snowman specific functionality to the evm
type SnowmanAPI struct{ vm *VM }
-// NetAPI offers network related API methods
-type NetAPI struct{ vm *VM }
-
// AvaxAPI offers Avalanche network related API methods
type AvaxAPI struct{ vm *VM }
-// NewNetAPI creates a new net API instance.
-func NewNetAPI(vm *VM) *NetAPI { return &NetAPI{vm} }
-
-// Listening returns an indication if the node is listening for network connections.
-func (s *NetAPI) Listening() bool { return true } // always listening
-
-// PeerCount returns the number of connected peers
-func (s *NetAPI) PeerCount() hexutil.Uint { return hexutil.Uint(0) } // TODO: report number of connected peers
-
-// Version returns the current ethereum protocol version.
-func (s *NetAPI) Version() string { return fmt.Sprintf("%d", s.vm.networkID) }
-
// Web3API offers helper API methods
type Web3API struct{}
@@ -86,49 +64,8 @@ func (api *SnowmanAPI) GetAcceptedFront(ctx context.Context) (*GetAcceptedFrontR
}, nil
}
-// GetGenesisBalance returns the current funds in the genesis
-func (api *DebugAPI) GetGenesisBalance(ctx context.Context) (*hexutil.Big, error) {
- lastAccepted := api.vm.getLastAccepted()
- log.Trace(fmt.Sprintf("Currently accepted block front: %s", lastAccepted.ethBlock.Hash().Hex()))
- state, err := api.vm.chain.BlockState(lastAccepted.ethBlock)
- if err != nil {
- return nil, err
- }
- return (*hexutil.Big)(state.GetBalance(common.HexToAddress(GenesisTestAddr))), nil
-}
-
-// SpendGenesis funds
-func (api *DebugAPI) SpendGenesis(ctx context.Context, nonce uint64) error {
- log.Info("Spending the genesis")
-
- value := big.NewInt(1000000000000)
- gasLimit := 21000
- gasPrice := big.NewInt(1000000000)
-
- genPrivateKey, err := ethcrypto.HexToECDSA(GenesisTestKey[2:])
- if err != nil {
- return err
- }
- bob, err := coreth.NewKey(rand.Reader)
- if err != nil {
- return err
- }
-
- tx := types.NewTransaction(nonce, bob.Address, value, uint64(gasLimit), gasPrice, nil)
- signedTx, err := types.SignTx(tx, types.NewEIP155Signer(api.vm.chainID), genPrivateKey)
- if err != nil {
- return err
- }
-
- if err := api.vm.issueRemoteTxs([]*types.Transaction{signedTx}); err != nil {
- return err
- }
-
- return nil
-}
-
// IssueBlock to the chain
-func (api *DebugAPI) IssueBlock(ctx context.Context) error {
+func (api *SnowmanAPI) IssueBlock(ctx context.Context) error {
log.Info("Issuing a new block")
return api.vm.tryBlockGen()
diff --git a/plugin/evm/vm.go b/plugin/evm/vm.go
index f19c105..c429bca 100644
--- a/plugin/evm/vm.go
+++ b/plugin/evm/vm.go
@@ -154,6 +154,8 @@ func init() {
type VM struct {
ctx *snow.Context
+ CLIConfig CommandLineConfig
+
chainID *big.Int
networkID uint64
genesisHash common.Hash
@@ -259,8 +261,8 @@ func (vm *VM) Initialize(
// Set minimum price for mining and default gas price oracle value to the min
// gas price to prevent so transactions and blocks all use the correct fees
config.Miner.GasPrice = params.MinGasPrice
- config.RPCGasCap = 2500000000 // 25000000 x 100
- config.RPCTxFeeCap = 100 // 100 AVAX
+ config.RPCGasCap = vm.CLIConfig.RPCGasCap
+ config.RPCTxFeeCap = vm.CLIConfig.RPCTxFeeCap
config.GPO.Default = params.MinGasPrice
config.TxPool.PriceLimit = params.MinGasPrice.Uint64()
config.TxPool.NoLocals = true
@@ -512,12 +514,17 @@ func newHandler(name string, service interface{}, lockOption ...commonEng.LockOp
// CreateHandlers makes new http handlers that can handle API calls
func (vm *VM) CreateHandlers() map[string]*commonEng.HTTPHandler {
handler := vm.chain.NewRPCHandler()
- vm.chain.AttachEthService(handler, []string{"eth", "personal", "txpool"})
- handler.RegisterName("net", &NetAPI{vm})
- handler.RegisterName("snowman", &SnowmanAPI{vm})
- handler.RegisterName("web3", &Web3API{})
- handler.RegisterName("debug", &DebugAPI{vm})
- handler.RegisterName("admin", &admin.Performance{})
+ vm.chain.AttachEthService(handler, vm.CLIConfig.EthAPIs())
+
+ if vm.CLIConfig.SnowmanAPIEnabled {
+ handler.RegisterName("snowman", &SnowmanAPI{vm})
+ }
+ if vm.CLIConfig.Web3APIEnabled {
+ handler.RegisterName("web3", &Web3API{})
+ }
+ if vm.CLIConfig.CorethAdminAPIEnabled {
+ handler.RegisterName("admin", &admin.Performance{})
+ }
return map[string]*commonEng.HTTPHandler{
"/rpc": {LockOptions: commonEng.NoLock, Handler: handler},
diff --git a/plugin/main.go b/plugin/main.go
index c79a305..b42ba14 100644
--- a/plugin/main.go
+++ b/plugin/main.go
@@ -1,6 +1,8 @@
package main
import (
+ "fmt"
+
"github.com/hashicorp/go-plugin"
"github.com/ava-labs/avalanchego/vms/rpcchainvm"
@@ -9,10 +11,13 @@ import (
)
func main() {
+ if errs.Errored() {
+ panic(fmt.Sprintf("Errored while parsing Coreth CLI Config: %w", errs.Err))
+ }
plugin.Serve(&plugin.ServeConfig{
HandshakeConfig: rpcchainvm.Handshake,
Plugins: map[string]plugin.Plugin{
- "vm": rpcchainvm.New(&evm.VM{}),
+ "vm": rpcchainvm.New(&evm.VM{CLIConfig: cliConfig}),
},
// A non-nil value here enables gRPC serving for this plugin...
diff --git a/plugin/params.go b/plugin/params.go
new file mode 100644
index 0000000..1810295
--- /dev/null
+++ b/plugin/params.go
@@ -0,0 +1,41 @@
+package main
+
+import (
+ "encoding/json"
+ "flag"
+ "os"
+
+ "github.com/ava-labs/avalanchego/utils/wrappers"
+ "github.com/ava-labs/coreth/plugin/evm"
+)
+
+const (
+ name = "coreth"
+)
+
+var (
+ cliConfig evm.CommandLineConfig
+ errs wrappers.Errs
+)
+
+func init() {
+ errs := wrappers.Errs{}
+ fs := flag.NewFlagSet(name, flag.ContinueOnError)
+
+ config := fs.String("coreth-config", "default", "Pass in CLI Config to set runtime attributes for Coreth")
+
+ if err := fs.Parse(os.Args[1:]); err != nil {
+ errs.Add(err)
+ return
+ }
+
+ if *config == "default" {
+ cliConfig.EthAPIEnabled = true
+ cliConfig.TxPoolAPIEnabled = true
+ cliConfig.RPCGasCap = 2500000000 // 25000000 x 100
+ cliConfig.RPCTxFeeCap = 100 // 100 AVAX
+ } else {
+ // TODO only overwrite values that were explicitly set
+ errs.Add(json.Unmarshal([]byte(*config), &cliConfig))
+ }
+}
diff --git a/rpc/types.go b/rpc/types.go
index 99e29fc..4e62a53 100644
--- a/rpc/types.go
+++ b/rpc/types.go
@@ -92,7 +92,7 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
*bn = EarliestBlockNumber
return nil
case "latest":
- *bn = AcceptedBlockNumber
+ *bn = LatestBlockNumber
return nil
case "pending":
*bn = PendingBlockNumber
@@ -117,6 +117,11 @@ func (bn BlockNumber) Int64() int64 {
return (int64)(bn)
}
+// IsAccepted returns true if this blockNumber should be treated as a request for the last accepted block
+func (bn BlockNumber) IsAccepted() bool {
+ return bn < EarliestBlockNumber && bn >= AcceptedBlockNumber
+}
+
type BlockNumberOrHash struct {
BlockNumber *BlockNumber `json:"blockNumber,omitempty"`
BlockHash *common.Hash `json:"blockHash,omitempty"`
@@ -147,7 +152,7 @@ func (bnh *BlockNumberOrHash) UnmarshalJSON(data []byte) error {
bnh.BlockNumber = &bn
return nil
case "latest":
- bn := AcceptedBlockNumber
+ bn := LatestBlockNumber
bnh.BlockNumber = &bn
return nil
case "pending":
'n1351' href='#n1351'>1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504