github.com/klaytn/klaytn@v1.12.1/node/cn/config.go (about)

     1  // Modifications Copyright 2018 The klaytn Authors
     2  // Copyright 2017 The go-ethereum Authors
     3  // This file is part of go-ethereum.
     4  //
     5  // The go-ethereum library is free software: you can redistribute it and/or modify
     6  // it under the terms of the GNU Lesser General Public License as published by
     7  // the Free Software Foundation, either version 3 of the License, or
     8  // (at your option) any later version.
     9  //
    10  // The go-ethereum library is distributed in the hope that it will be useful,
    11  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    13  // GNU Lesser General Public License for more details.
    14  //
    15  // You should have received a copy of the GNU Lesser General Public License
    16  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    17  //
    18  // This file is derived from eth/config.go (2018/06/04).
    19  // Modified and improved for the klaytn development.
    20  
    21  package cn
    22  
    23  import (
    24  	"math/big"
    25  	"os"
    26  	"os/user"
    27  	"time"
    28  
    29  	"github.com/klaytn/klaytn/storage/statedb"
    30  
    31  	"github.com/klaytn/klaytn/blockchain"
    32  	"github.com/klaytn/klaytn/blockchain/vm"
    33  	"github.com/klaytn/klaytn/common"
    34  	"github.com/klaytn/klaytn/common/hexutil"
    35  	"github.com/klaytn/klaytn/consensus/istanbul"
    36  	"github.com/klaytn/klaytn/datasync/downloader"
    37  	"github.com/klaytn/klaytn/log"
    38  	"github.com/klaytn/klaytn/node/cn/gasprice"
    39  	"github.com/klaytn/klaytn/params"
    40  	"github.com/klaytn/klaytn/storage/database"
    41  )
    42  
    43  var logger = log.NewModuleLogger(log.NodeCN)
    44  
    45  // GetDefaultConfig returns default settings for use on the Klaytn main net.
    46  func GetDefaultConfig() *Config {
    47  	return &Config{
    48  		SyncMode:             downloader.FullSync,
    49  		NetworkId:            params.CypressNetworkId,
    50  		LevelDBCacheSize:     768,
    51  		TrieCacheSize:        512,
    52  		TrieTimeout:          5 * time.Minute,
    53  		TrieBlockInterval:    blockchain.DefaultBlockInterval,
    54  		TrieNodeCacheConfig:  *statedb.GetEmptyTrieNodeCacheConfig(),
    55  		TriesInMemory:        blockchain.DefaultTriesInMemory,
    56  		LivePruningRetention: blockchain.DefaultLivePruningRetention,
    57  		GasPrice:             big.NewInt(18 * params.Ston),
    58  
    59  		TxPool: blockchain.DefaultTxPoolConfig,
    60  		GPO: gasprice.Config{
    61  			Blocks:           20,
    62  			Percentile:       60,
    63  			MaxHeaderHistory: 1024,
    64  			MaxBlockHistory:  1024,
    65  		},
    66  		WsEndpoint: "localhost:8546",
    67  
    68  		Istanbul:      *istanbul.DefaultConfig,
    69  		RPCEVMTimeout: 5 * time.Second,
    70  	}
    71  }
    72  
    73  func init() {
    74  	home := os.Getenv("HOME")
    75  	if home == "" {
    76  		if user, err := user.Current(); err == nil {
    77  			home = user.HomeDir
    78  		}
    79  	}
    80  }
    81  
    82  //go:generate gencodec -type Config -field-override configMarshaling -formats toml -out gen_config.go
    83  
    84  type Config struct {
    85  	// The genesis block, which is inserted if the database is empty.
    86  	// If nil, the Klaytn main net block is used.
    87  	Genesis *blockchain.Genesis `toml:",omitempty"`
    88  
    89  	// Protocol options
    90  	NetworkId     uint64 // Network ID to use for selecting peers to connect to
    91  	SyncMode      downloader.SyncMode
    92  	NoPruning     bool
    93  	WorkerDisable bool // disables worker and does not start istanbul
    94  
    95  	// KES options
    96  	DownloaderDisable bool
    97  	FetcherDisable    bool
    98  
    99  	// Service chain options
   100  	ParentOperatorAddr *common.Address `toml:",omitempty"` // A hex account address in the parent chain used to sign a child chain transaction.
   101  	AnchoringPeriod    uint64          // Period when child chain sends an anchoring transaction to the parent chain. Default value is 1.
   102  	SentChainTxsLimit  uint64          // Number of chain transactions stored for resending. Default value is 1000.
   103  
   104  	// Light client options
   105  	// LightServ  int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
   106  	// LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
   107  
   108  	OverwriteGenesis bool
   109  	StartBlockNumber uint64
   110  
   111  	// Database options
   112  	DBType               database.DBType
   113  	SkipBcVersionCheck   bool `toml:"-"`
   114  	SingleDB             bool
   115  	NumStateTrieShards   uint
   116  	EnableDBPerfMetrics  bool
   117  	LevelDBCompression   database.LevelDBCompressionType
   118  	LevelDBBufferPool    bool
   119  	LevelDBCacheSize     int
   120  	DynamoDBConfig       database.DynamoDBConfig
   121  	RocksDBConfig        database.RocksDBConfig
   122  	TrieCacheSize        int
   123  	TrieTimeout          time.Duration
   124  	TrieBlockInterval    uint
   125  	TriesInMemory        uint64
   126  	LivePruning          bool
   127  	LivePruningRetention uint64
   128  	SenderTxHashIndexing bool
   129  	ParallelDBWrite      bool
   130  	TrieNodeCacheConfig  statedb.TrieNodeCacheConfig
   131  	SnapshotCacheSize    int
   132  	SnapshotAsyncGen     bool
   133  
   134  	// Mining-related options
   135  	ServiceChainSigner common.Address `toml:",omitempty"`
   136  	ExtraData          []byte         `toml:",omitempty"`
   137  	GasPrice           *big.Int
   138  
   139  	// Reward
   140  	Rewardbase common.Address `toml:",omitempty"`
   141  
   142  	// Transaction pool options
   143  	TxPool blockchain.TxPoolConfig
   144  
   145  	// Gas Price Oracle options
   146  	GPO gasprice.Config
   147  
   148  	// Enables tracking of SHA3 preimages in the VM
   149  	EnablePreimageRecording bool
   150  	// Enables collecting internal transaction data during processing a block
   151  	EnableInternalTxTracing bool
   152  	// Enables collecting and printing opcode execution time when node stops
   153  	EnableOpDebug bool
   154  
   155  	// Istanbul options
   156  	Istanbul istanbul.Config
   157  
   158  	// Miscellaneous options
   159  	DocRoot string `toml:"-"`
   160  
   161  	WsEndpoint string `toml:",omitempty"`
   162  
   163  	// Tx Resending options
   164  	TxResendInterval  uint64
   165  	TxResendCount     int
   166  	TxResendUseLegacy bool
   167  
   168  	// Service Chain
   169  	NoAccountCreation bool
   170  
   171  	// use separate network different from baobab or cypress
   172  	IsPrivate bool
   173  
   174  	// Restart
   175  	AutoRestartFlag    bool
   176  	RestartTimeOutFlag time.Duration
   177  	DaemonPathFlag     string
   178  
   179  	// RPCGasCap is the global gas cap for eth-call variants.
   180  	RPCGasCap *big.Int `toml:",omitempty"`
   181  
   182  	// RPCEVMTimeout is the global timeout for klay/eth-call.
   183  	RPCEVMTimeout time.Duration
   184  
   185  	// RPCTxFeeCap is the global transaction fee(price * gaslimit) cap for
   186  	// send-transction variants. The unit is klay.
   187  	// This is used by eth namespace RPC APIs
   188  	RPCTxFeeCap float64
   189  
   190  	// Disable option for unsafe debug APIs
   191  	DisableUnsafeDebug         bool          `toml:",omitempty"`
   192  	StateRegenerationTimeLimit time.Duration `toml:",omitempty"`
   193  }
   194  
   195  type configMarshaling struct {
   196  	ExtraData hexutil.Bytes
   197  }
   198  
   199  func (c *Config) getVMConfig() vm.Config {
   200  	return vm.Config{
   201  		EnablePreimageRecording: c.EnablePreimageRecording,
   202  		EnableInternalTxTracing: c.EnableInternalTxTracing,
   203  		EnableOpDebug:           c.EnableOpDebug,
   204  	}
   205  }