From f65fa21dc19d68ef3f82b697b5f2d1c3fa7c1f3a Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Thu, 6 Apr 2017 19:17:33 +0200 Subject: [PATCH] eth: prettify Config again, fix tests --- eth/config.go | 56 ++++++++++++------- eth/gen_config.go | 130 +++++++++++++++++++++---------------------- eth/handler_test.go | 2 +- eth/helper_test.go | 4 +- eth/protocol_test.go | 4 +- 5 files changed, 105 insertions(+), 91 deletions(-) diff --git a/eth/config.go b/eth/config.go index a24216b356..29565fe033 100644 --- a/eth/config.go +++ b/eth/config.go @@ -61,36 +61,50 @@ func init() { type Config struct { // The genesis block, which is inserted if the database is empty. // If nil, the Ethereum main net block is used. - Genesis *core.Genesis `toml:",omitempty"` - NetworkId int // Network ID to use for selecting peers to connect to - FastSync bool // Enables the state download based fast synchronisation algorithm - LightMode bool // Running in light client mode - LightServ int // Maximum percentage of time allowed for serving LES requests - LightPeers int // Maximum number of LES client peers - MaxPeers int // Maximum number of global peers - SkipBcVersionCheck bool `toml:",omitempty"` // e.g. blockchain export - DatabaseCache int - DatabaseHandles int `toml:"-"` - DocRoot string `toml:",omitempty"` - PowFake bool `toml:",omitempty"` - PowTest bool `toml:",omitempty"` - PowShared bool `toml:",omitempty"` - ExtraData []byte - EthashCacheDir string `toml:",omitempty"` + Genesis *core.Genesis `toml:",omitempty"` + + // Protocol options + NetworkId int // Network ID to use for selecting peers to connect to + FastSync bool // Enables the state download based fast synchronisation algorithm + LightMode bool // Running in light client mode + + // Light client options + LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests + LightPeers int `toml:",omitempty"` // Maximum number of LES client peers + MaxPeers int `toml:"-"` // Maximum number of global peers + + // Database options + SkipBcVersionCheck bool `toml:"-"` + DatabaseHandles int `toml:"-"` + DatabaseCache int + + // Mining-related options + Etherbase common.Address `toml:",omitempty"` + MinerThreads int `toml:",omitempty"` + ExtraData []byte `toml:",omitempty"` + GasPrice *big.Int + + // Ethash options + EthashCacheDir string EthashCachesInMem int EthashCachesOnDisk int - EthashDatasetDir string `toml:",omitempty"` + EthashDatasetDir string EthashDatasetsInMem int EthashDatasetsOnDisk int - Etherbase common.Address `toml:",omitempty"` - GasPrice *big.Int - MinerThreads int `toml:",omitempty"` - SolcPath string `toml:",omitempty"` + // Gas Price Oracle options GpoBlocks int GpoPercentile int + // Enables tracking of SHA3 preimages in the VM EnablePreimageRecording bool + + // Miscellaneous options + SolcPath string + DocRoot string `toml:"-"` + PowFake bool `toml:"-"` + PowTest bool `toml:"-"` + PowShared bool `toml:"-"` } type configMarshaling struct { diff --git a/eth/gen_config.go b/eth/gen_config.go index 6323adbb39..6f8bcb9c5b 100644 --- a/eth/gen_config.go +++ b/eth/gen_config.go @@ -16,30 +16,30 @@ func (c Config) MarshalTOML() (interface{}, error) { NetworkId int FastSync bool LightMode bool - LightServ int - LightPeers int - MaxPeers int - SkipBcVersionCheck bool `toml:",omitempty"` + LightServ int `toml:",omitempty"` + LightPeers int `toml:",omitempty"` + MaxPeers int `toml:"-"` + SkipBcVersionCheck bool `toml:"-"` + DatabaseHandles int `toml:"-"` DatabaseCache int - DatabaseHandles int `toml:"-"` - DocRoot string `toml:",omitempty"` - PowFake bool `toml:",omitempty"` - PowTest bool `toml:",omitempty"` - PowShared bool `toml:",omitempty"` - ExtraData hexutil.Bytes - EthashCacheDir string `toml:",omitempty"` + Etherbase common.Address `toml:",omitempty"` + MinerThreads int `toml:",omitempty"` + ExtraData hexutil.Bytes `toml:",omitempty"` + GasPrice *big.Int + EthashCacheDir string EthashCachesInMem int EthashCachesOnDisk int - EthashDatasetDir string `toml:",omitempty"` + EthashDatasetDir string EthashDatasetsInMem int EthashDatasetsOnDisk int - Etherbase common.Address `toml:",omitempty"` - GasPrice *big.Int - MinerThreads int `toml:",omitempty"` - SolcPath string `toml:",omitempty"` GpoBlocks int GpoPercentile int EnablePreimageRecording bool + SolcPath string + DocRoot string `toml:"-"` + PowFake bool `toml:"-"` + PowTest bool `toml:"-"` + PowShared bool `toml:"-"` } var enc Config enc.Genesis = c.Genesis @@ -50,26 +50,26 @@ func (c Config) MarshalTOML() (interface{}, error) { enc.LightPeers = c.LightPeers enc.MaxPeers = c.MaxPeers enc.SkipBcVersionCheck = c.SkipBcVersionCheck - enc.DatabaseCache = c.DatabaseCache enc.DatabaseHandles = c.DatabaseHandles - enc.DocRoot = c.DocRoot - enc.PowFake = c.PowFake - enc.PowTest = c.PowTest - enc.PowShared = c.PowShared + enc.DatabaseCache = c.DatabaseCache + enc.Etherbase = c.Etherbase + enc.MinerThreads = c.MinerThreads enc.ExtraData = c.ExtraData + enc.GasPrice = c.GasPrice enc.EthashCacheDir = c.EthashCacheDir enc.EthashCachesInMem = c.EthashCachesInMem enc.EthashCachesOnDisk = c.EthashCachesOnDisk enc.EthashDatasetDir = c.EthashDatasetDir enc.EthashDatasetsInMem = c.EthashDatasetsInMem enc.EthashDatasetsOnDisk = c.EthashDatasetsOnDisk - enc.Etherbase = c.Etherbase - enc.GasPrice = c.GasPrice - enc.MinerThreads = c.MinerThreads - enc.SolcPath = c.SolcPath enc.GpoBlocks = c.GpoBlocks enc.GpoPercentile = c.GpoPercentile enc.EnablePreimageRecording = c.EnablePreimageRecording + enc.SolcPath = c.SolcPath + enc.DocRoot = c.DocRoot + enc.PowFake = c.PowFake + enc.PowTest = c.PowTest + enc.PowShared = c.PowShared return &enc, nil } @@ -79,30 +79,30 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { NetworkId *int FastSync *bool LightMode *bool - LightServ *int - LightPeers *int - MaxPeers *int - SkipBcVersionCheck *bool `toml:",omitempty"` + LightServ *int `toml:",omitempty"` + LightPeers *int `toml:",omitempty"` + MaxPeers *int `toml:"-"` + SkipBcVersionCheck *bool `toml:"-"` + DatabaseHandles *int `toml:"-"` DatabaseCache *int - DatabaseHandles *int `toml:"-"` - DocRoot *string `toml:",omitempty"` - PowFake *bool `toml:",omitempty"` - PowTest *bool `toml:",omitempty"` - PowShared *bool `toml:",omitempty"` - ExtraData hexutil.Bytes - EthashCacheDir *string `toml:",omitempty"` + Etherbase *common.Address `toml:",omitempty"` + MinerThreads *int `toml:",omitempty"` + ExtraData hexutil.Bytes `toml:",omitempty"` + GasPrice *big.Int + EthashCacheDir *string EthashCachesInMem *int EthashCachesOnDisk *int - EthashDatasetDir *string `toml:",omitempty"` + EthashDatasetDir *string EthashDatasetsInMem *int EthashDatasetsOnDisk *int - Etherbase *common.Address `toml:",omitempty"` - GasPrice *big.Int - MinerThreads *int `toml:",omitempty"` - SolcPath *string `toml:",omitempty"` GpoBlocks *int GpoPercentile *int EnablePreimageRecording *bool + SolcPath *string + DocRoot *string `toml:"-"` + PowFake *bool `toml:"-"` + PowTest *bool `toml:"-"` + PowShared *bool `toml:"-"` } var dec Config if err := unmarshal(&dec); err != nil { @@ -132,27 +132,24 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.SkipBcVersionCheck != nil { c.SkipBcVersionCheck = *dec.SkipBcVersionCheck } - if dec.DatabaseCache != nil { - c.DatabaseCache = *dec.DatabaseCache - } if dec.DatabaseHandles != nil { c.DatabaseHandles = *dec.DatabaseHandles } - if dec.DocRoot != nil { - c.DocRoot = *dec.DocRoot + if dec.DatabaseCache != nil { + c.DatabaseCache = *dec.DatabaseCache } - if dec.PowFake != nil { - c.PowFake = *dec.PowFake + if dec.Etherbase != nil { + c.Etherbase = *dec.Etherbase } - if dec.PowTest != nil { - c.PowTest = *dec.PowTest - } - if dec.PowShared != nil { - c.PowShared = *dec.PowShared + if dec.MinerThreads != nil { + c.MinerThreads = *dec.MinerThreads } if dec.ExtraData != nil { c.ExtraData = dec.ExtraData } + if dec.GasPrice != nil { + c.GasPrice = dec.GasPrice + } if dec.EthashCacheDir != nil { c.EthashCacheDir = *dec.EthashCacheDir } @@ -171,18 +168,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.EthashDatasetsOnDisk != nil { c.EthashDatasetsOnDisk = *dec.EthashDatasetsOnDisk } - if dec.Etherbase != nil { - c.Etherbase = *dec.Etherbase - } - if dec.GasPrice != nil { - c.GasPrice = dec.GasPrice - } - if dec.MinerThreads != nil { - c.MinerThreads = *dec.MinerThreads - } - if dec.SolcPath != nil { - c.SolcPath = *dec.SolcPath - } if dec.GpoBlocks != nil { c.GpoBlocks = *dec.GpoBlocks } @@ -192,5 +177,20 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error { if dec.EnablePreimageRecording != nil { c.EnablePreimageRecording = *dec.EnablePreimageRecording } + if dec.SolcPath != nil { + c.SolcPath = *dec.SolcPath + } + if dec.DocRoot != nil { + c.DocRoot = *dec.DocRoot + } + if dec.PowFake != nil { + c.PowFake = *dec.PowFake + } + if dec.PowTest != nil { + c.PowTest = *dec.PowTest + } + if dec.PowShared != nil { + c.PowShared = *dec.PowShared + } return nil } diff --git a/eth/handler_test.go b/eth/handler_test.go index f85d730b67..19f6ced171 100644 --- a/eth/handler_test.go +++ b/eth/handler_test.go @@ -476,7 +476,7 @@ func testDAOChallenge(t *testing.T, localForked, remoteForked bool, timeout bool genesis = gspec.MustCommit(db) blockchain, _ = core.NewBlockChain(db, config, pow, evmux, vm.Config{}) ) - pm, err := NewProtocolManager(config, false, NetworkId, 1000, evmux, new(testTxPool), pow, blockchain, db) + pm, err := NewProtocolManager(config, false, DefaultConfig.NetworkId, 1000, evmux, new(testTxPool), pow, blockchain, db) if err != nil { t.Fatalf("failed to start test protocol manager: %v", err) } diff --git a/eth/helper_test.go b/eth/helper_test.go index a8c538e6ce..c0daa1b721 100644 --- a/eth/helper_test.go +++ b/eth/helper_test.go @@ -65,7 +65,7 @@ func newTestProtocolManager(fastSync bool, blocks int, generator func(int, *core panic(err) } - pm, err := NewProtocolManager(gspec.Config, fastSync, NetworkId, 1000, evmux, &testTxPool{added: newtx}, engine, blockchain, db) + pm, err := NewProtocolManager(gspec.Config, fastSync, DefaultConfig.NetworkId, 1000, evmux, &testTxPool{added: newtx}, engine, blockchain, db) if err != nil { return nil, err } @@ -172,7 +172,7 @@ func newTestPeer(name string, version int, pm *ProtocolManager, shake bool) (*te func (p *testPeer) handshake(t *testing.T, td *big.Int, head common.Hash, genesis common.Hash) { msg := &statusData{ ProtocolVersion: uint32(p.version), - NetworkId: uint32(NetworkId), + NetworkId: uint32(DefaultConfig.NetworkId), TD: td, CurrentBlock: head, GenesisBlock: genesis, diff --git a/eth/protocol_test.go b/eth/protocol_test.go index 3c9a734dfb..fcc88fb0c6 100644 --- a/eth/protocol_test.go +++ b/eth/protocol_test.go @@ -54,7 +54,7 @@ func testStatusMsgErrors(t *testing.T, protocol int) { wantError: errResp(ErrNoStatusMsg, "first msg has code 2 (!= 0)"), }, { - code: StatusMsg, data: statusData{10, NetworkId, td, currentBlock, genesis}, + code: StatusMsg, data: statusData{10, uint32(DefaultConfig.NetworkId), td, currentBlock, genesis}, wantError: errResp(ErrProtocolVersionMismatch, "10 (!= %d)", protocol), }, { @@ -62,7 +62,7 @@ func testStatusMsgErrors(t *testing.T, protocol int) { wantError: errResp(ErrNetworkIdMismatch, "999 (!= 1)"), }, { - code: StatusMsg, data: statusData{uint32(protocol), NetworkId, td, currentBlock, common.Hash{3}}, + code: StatusMsg, data: statusData{uint32(protocol), uint32(DefaultConfig.NetworkId), td, currentBlock, common.Hash{3}}, wantError: errResp(ErrGenesisBlockMismatch, "0300000000000000 (!= %x)", genesis[:8]), }, }