gitlab.com/flarenetwork/coreth@v0.1.1/plugin/evm/config.go (about)

     1  // (c) 2019-2020, Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package evm
     5  
     6  import (
     7  	"encoding/json"
     8  	"time"
     9  
    10  	"github.com/spf13/cast"
    11  	"gitlab.com/flarenetwork/coreth/eth"
    12  )
    13  
    14  const (
    15  	defaultEthApiEnabled               = true
    16  	defaultNetApiEnabled               = true
    17  	defaultWeb3ApiEnabled              = true
    18  	defaultPruningEnabled              = true
    19  	defaultSnapshotAsync               = true
    20  	defaultRpcGasCap                   = 2500000000 // 25000000 X 100
    21  	defaultRpcTxFeeCap                 = 100        // 100 AVAX
    22  	defaultApiMaxDuration              = 0          // Default to no maximum API Call duration
    23  	defaultMaxBlocksPerRequest         = 0          // Default to no maximum on the number of blocks per getLogs request
    24  	defaultContinuousProfilerFrequency = 15 * time.Minute
    25  	defaultContinuousProfilerMaxFiles  = 5
    26  )
    27  
    28  type Duration struct {
    29  	time.Duration
    30  }
    31  
    32  // Config ...
    33  type Config struct {
    34  	// Coreth APIs
    35  	SnowmanAPIEnabled     bool `json:"snowman-api-enabled"`
    36  	CorethAdminAPIEnabled bool `json:"coreth-admin-api-enabled"`
    37  	NetAPIEnabled         bool `json:"net-api-enabled"`
    38  
    39  	// Continuous Profiler
    40  	ContinuousProfilerDir       string   `json:"continuous-profiler-dir"`       // If set to non-empty string creates a continuous profiler
    41  	ContinuousProfilerFrequency Duration `json:"continuous-profiler-frequency"` // Frequency to run continuous profiler if enabled
    42  	ContinuousProfilerMaxFiles  int      `json:"continuous-profiler-max-files"` // Maximum number of files to maintain
    43  
    44  	// Coreth API Gas/Price Caps
    45  	RPCGasCap   uint64  `json:"rpc-gas-cap"`
    46  	RPCTxFeeCap float64 `json:"rpc-tx-fee-cap"`
    47  
    48  	// Eth APIs
    49  	EthAPIEnabled      bool `json:"eth-api-enabled"`
    50  	PersonalAPIEnabled bool `json:"personal-api-enabled"`
    51  	TxPoolAPIEnabled   bool `json:"tx-pool-api-enabled"`
    52  	DebugAPIEnabled    bool `json:"debug-api-enabled"`
    53  	Web3APIEnabled     bool `json:"web3-api-enabled"`
    54  
    55  	// Eth Settings
    56  	Pruning        bool `json:"pruning-enabled"`
    57  	SnapshotAsync  bool `json:"snapshot-async"`
    58  	SnapshotVerify bool `json:"snapshot-verification-enabled"`
    59  
    60  	LocalTxsEnabled         bool     `json:"local-txs-enabled"`
    61  	APIMaxDuration          Duration `json:"api-max-duration"`
    62  	MaxBlocksPerRequest     int64    `json:"api-max-blocks-per-request"`
    63  	AllowUnfinalizedQueries bool     `json:"allow-unfinalized-queries"`
    64  
    65  	// Keystore Settings
    66  	KeystoreDirectory             string `json:"keystore-directory"` // both absolute and relative supported
    67  	KeystoreExternalSigner        string `json:"keystore-external-signer"`
    68  	KeystoreInsecureUnlockAllowed bool   `json:"keystore-insecure-unlock-allowed"`
    69  }
    70  
    71  // EthAPIs returns an array of strings representing the Eth APIs that should be enabled
    72  func (c Config) EthAPIs() []string {
    73  	ethAPIs := make([]string, 0)
    74  
    75  	if c.EthAPIEnabled {
    76  		ethAPIs = append(ethAPIs, "eth")
    77  	}
    78  	if c.PersonalAPIEnabled {
    79  		ethAPIs = append(ethAPIs, "personal")
    80  	}
    81  	if c.TxPoolAPIEnabled {
    82  		ethAPIs = append(ethAPIs, "txpool")
    83  	}
    84  	if c.DebugAPIEnabled {
    85  		ethAPIs = append(ethAPIs, "debug")
    86  	}
    87  
    88  	return ethAPIs
    89  }
    90  
    91  func (c Config) EthBackendSettings() eth.Settings {
    92  	return eth.Settings{MaxBlocksPerRequest: c.MaxBlocksPerRequest}
    93  }
    94  
    95  func (c *Config) SetDefaults() {
    96  	c.EthAPIEnabled = defaultEthApiEnabled
    97  	c.NetAPIEnabled = defaultNetApiEnabled
    98  	c.Web3APIEnabled = defaultWeb3ApiEnabled
    99  	c.RPCGasCap = defaultRpcGasCap
   100  	c.RPCTxFeeCap = defaultRpcTxFeeCap
   101  	c.APIMaxDuration.Duration = defaultApiMaxDuration
   102  	c.MaxBlocksPerRequest = defaultMaxBlocksPerRequest
   103  	c.ContinuousProfilerFrequency.Duration = defaultContinuousProfilerFrequency
   104  	c.ContinuousProfilerMaxFiles = defaultContinuousProfilerMaxFiles
   105  	c.Pruning = defaultPruningEnabled
   106  	c.SnapshotAsync = defaultSnapshotAsync
   107  }
   108  
   109  func (d *Duration) UnmarshalJSON(data []byte) (err error) {
   110  	var v interface{}
   111  	if err := json.Unmarshal(data, &v); err != nil {
   112  		return err
   113  	}
   114  	d.Duration, err = cast.ToDurationE(v)
   115  	return err
   116  }