mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-28 07:36:44 +00:00
eth: prettify Config again, fix tests
This commit is contained in:
parent
5053cabf3e
commit
f65fa21dc1
5 changed files with 105 additions and 91 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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]),
|
||||
},
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue