eth: prettify Config again, fix tests

This commit is contained in:
Felix Lange 2017-04-06 19:17:33 +02:00
parent 5053cabf3e
commit f65fa21dc1
5 changed files with 105 additions and 91 deletions

View file

@ -61,36 +61,50 @@ func init() {
type Config struct { type Config struct {
// The genesis block, which is inserted if the database is empty. // The genesis block, which is inserted if the database is empty.
// If nil, the Ethereum main net block is used. // If nil, the Ethereum main net block is used.
Genesis *core.Genesis `toml:",omitempty"` 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 // Protocol options
LightMode bool // Running in light client mode NetworkId int // Network ID to use for selecting peers to connect to
LightServ int // Maximum percentage of time allowed for serving LES requests FastSync bool // Enables the state download based fast synchronisation algorithm
LightPeers int // Maximum number of LES client peers LightMode bool // Running in light client mode
MaxPeers int // Maximum number of global peers
SkipBcVersionCheck bool `toml:",omitempty"` // e.g. blockchain export // Light client options
DatabaseCache int LightServ int `toml:",omitempty"` // Maximum percentage of time allowed for serving LES requests
DatabaseHandles int `toml:"-"` LightPeers int `toml:",omitempty"` // Maximum number of LES client peers
DocRoot string `toml:",omitempty"` MaxPeers int `toml:"-"` // Maximum number of global peers
PowFake bool `toml:",omitempty"`
PowTest bool `toml:",omitempty"` // Database options
PowShared bool `toml:",omitempty"` SkipBcVersionCheck bool `toml:"-"`
ExtraData []byte DatabaseHandles int `toml:"-"`
EthashCacheDir string `toml:",omitempty"` 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 EthashCachesInMem int
EthashCachesOnDisk int EthashCachesOnDisk int
EthashDatasetDir string `toml:",omitempty"` EthashDatasetDir string
EthashDatasetsInMem int EthashDatasetsInMem int
EthashDatasetsOnDisk 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 GpoBlocks int
GpoPercentile int GpoPercentile int
// Enables tracking of SHA3 preimages in the VM
EnablePreimageRecording bool EnablePreimageRecording bool
// Miscellaneous options
SolcPath string
DocRoot string `toml:"-"`
PowFake bool `toml:"-"`
PowTest bool `toml:"-"`
PowShared bool `toml:"-"`
} }
type configMarshaling struct { type configMarshaling struct {

View file

@ -16,30 +16,30 @@ func (c Config) MarshalTOML() (interface{}, error) {
NetworkId int NetworkId int
FastSync bool FastSync bool
LightMode bool LightMode bool
LightServ int LightServ int `toml:",omitempty"`
LightPeers int LightPeers int `toml:",omitempty"`
MaxPeers int MaxPeers int `toml:"-"`
SkipBcVersionCheck bool `toml:",omitempty"` SkipBcVersionCheck bool `toml:"-"`
DatabaseHandles int `toml:"-"`
DatabaseCache int DatabaseCache int
DatabaseHandles int `toml:"-"` Etherbase common.Address `toml:",omitempty"`
DocRoot string `toml:",omitempty"` MinerThreads int `toml:",omitempty"`
PowFake bool `toml:",omitempty"` ExtraData hexutil.Bytes `toml:",omitempty"`
PowTest bool `toml:",omitempty"` GasPrice *big.Int
PowShared bool `toml:",omitempty"` EthashCacheDir string
ExtraData hexutil.Bytes
EthashCacheDir string `toml:",omitempty"`
EthashCachesInMem int EthashCachesInMem int
EthashCachesOnDisk int EthashCachesOnDisk int
EthashDatasetDir string `toml:",omitempty"` EthashDatasetDir string
EthashDatasetsInMem int EthashDatasetsInMem int
EthashDatasetsOnDisk int EthashDatasetsOnDisk int
Etherbase common.Address `toml:",omitempty"`
GasPrice *big.Int
MinerThreads int `toml:",omitempty"`
SolcPath string `toml:",omitempty"`
GpoBlocks int GpoBlocks int
GpoPercentile int GpoPercentile int
EnablePreimageRecording bool EnablePreimageRecording bool
SolcPath string
DocRoot string `toml:"-"`
PowFake bool `toml:"-"`
PowTest bool `toml:"-"`
PowShared bool `toml:"-"`
} }
var enc Config var enc Config
enc.Genesis = c.Genesis enc.Genesis = c.Genesis
@ -50,26 +50,26 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.LightPeers = c.LightPeers enc.LightPeers = c.LightPeers
enc.MaxPeers = c.MaxPeers enc.MaxPeers = c.MaxPeers
enc.SkipBcVersionCheck = c.SkipBcVersionCheck enc.SkipBcVersionCheck = c.SkipBcVersionCheck
enc.DatabaseCache = c.DatabaseCache
enc.DatabaseHandles = c.DatabaseHandles enc.DatabaseHandles = c.DatabaseHandles
enc.DocRoot = c.DocRoot enc.DatabaseCache = c.DatabaseCache
enc.PowFake = c.PowFake enc.Etherbase = c.Etherbase
enc.PowTest = c.PowTest enc.MinerThreads = c.MinerThreads
enc.PowShared = c.PowShared
enc.ExtraData = c.ExtraData enc.ExtraData = c.ExtraData
enc.GasPrice = c.GasPrice
enc.EthashCacheDir = c.EthashCacheDir enc.EthashCacheDir = c.EthashCacheDir
enc.EthashCachesInMem = c.EthashCachesInMem enc.EthashCachesInMem = c.EthashCachesInMem
enc.EthashCachesOnDisk = c.EthashCachesOnDisk enc.EthashCachesOnDisk = c.EthashCachesOnDisk
enc.EthashDatasetDir = c.EthashDatasetDir enc.EthashDatasetDir = c.EthashDatasetDir
enc.EthashDatasetsInMem = c.EthashDatasetsInMem enc.EthashDatasetsInMem = c.EthashDatasetsInMem
enc.EthashDatasetsOnDisk = c.EthashDatasetsOnDisk 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.GpoBlocks = c.GpoBlocks
enc.GpoPercentile = c.GpoPercentile enc.GpoPercentile = c.GpoPercentile
enc.EnablePreimageRecording = c.EnablePreimageRecording 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 return &enc, nil
} }
@ -79,30 +79,30 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
NetworkId *int NetworkId *int
FastSync *bool FastSync *bool
LightMode *bool LightMode *bool
LightServ *int LightServ *int `toml:",omitempty"`
LightPeers *int LightPeers *int `toml:",omitempty"`
MaxPeers *int MaxPeers *int `toml:"-"`
SkipBcVersionCheck *bool `toml:",omitempty"` SkipBcVersionCheck *bool `toml:"-"`
DatabaseHandles *int `toml:"-"`
DatabaseCache *int DatabaseCache *int
DatabaseHandles *int `toml:"-"` Etherbase *common.Address `toml:",omitempty"`
DocRoot *string `toml:",omitempty"` MinerThreads *int `toml:",omitempty"`
PowFake *bool `toml:",omitempty"` ExtraData hexutil.Bytes `toml:",omitempty"`
PowTest *bool `toml:",omitempty"` GasPrice *big.Int
PowShared *bool `toml:",omitempty"` EthashCacheDir *string
ExtraData hexutil.Bytes
EthashCacheDir *string `toml:",omitempty"`
EthashCachesInMem *int EthashCachesInMem *int
EthashCachesOnDisk *int EthashCachesOnDisk *int
EthashDatasetDir *string `toml:",omitempty"` EthashDatasetDir *string
EthashDatasetsInMem *int EthashDatasetsInMem *int
EthashDatasetsOnDisk *int EthashDatasetsOnDisk *int
Etherbase *common.Address `toml:",omitempty"`
GasPrice *big.Int
MinerThreads *int `toml:",omitempty"`
SolcPath *string `toml:",omitempty"`
GpoBlocks *int GpoBlocks *int
GpoPercentile *int GpoPercentile *int
EnablePreimageRecording *bool EnablePreimageRecording *bool
SolcPath *string
DocRoot *string `toml:"-"`
PowFake *bool `toml:"-"`
PowTest *bool `toml:"-"`
PowShared *bool `toml:"-"`
} }
var dec Config var dec Config
if err := unmarshal(&dec); err != nil { if err := unmarshal(&dec); err != nil {
@ -132,27 +132,24 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.SkipBcVersionCheck != nil { if dec.SkipBcVersionCheck != nil {
c.SkipBcVersionCheck = *dec.SkipBcVersionCheck c.SkipBcVersionCheck = *dec.SkipBcVersionCheck
} }
if dec.DatabaseCache != nil {
c.DatabaseCache = *dec.DatabaseCache
}
if dec.DatabaseHandles != nil { if dec.DatabaseHandles != nil {
c.DatabaseHandles = *dec.DatabaseHandles c.DatabaseHandles = *dec.DatabaseHandles
} }
if dec.DocRoot != nil { if dec.DatabaseCache != nil {
c.DocRoot = *dec.DocRoot c.DatabaseCache = *dec.DatabaseCache
} }
if dec.PowFake != nil { if dec.Etherbase != nil {
c.PowFake = *dec.PowFake c.Etherbase = *dec.Etherbase
} }
if dec.PowTest != nil { if dec.MinerThreads != nil {
c.PowTest = *dec.PowTest c.MinerThreads = *dec.MinerThreads
}
if dec.PowShared != nil {
c.PowShared = *dec.PowShared
} }
if dec.ExtraData != nil { if dec.ExtraData != nil {
c.ExtraData = dec.ExtraData c.ExtraData = dec.ExtraData
} }
if dec.GasPrice != nil {
c.GasPrice = dec.GasPrice
}
if dec.EthashCacheDir != nil { if dec.EthashCacheDir != nil {
c.EthashCacheDir = *dec.EthashCacheDir c.EthashCacheDir = *dec.EthashCacheDir
} }
@ -171,18 +168,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.EthashDatasetsOnDisk != nil { if dec.EthashDatasetsOnDisk != nil {
c.EthashDatasetsOnDisk = *dec.EthashDatasetsOnDisk 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 { if dec.GpoBlocks != nil {
c.GpoBlocks = *dec.GpoBlocks c.GpoBlocks = *dec.GpoBlocks
} }
@ -192,5 +177,20 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.EnablePreimageRecording != nil { if dec.EnablePreimageRecording != nil {
c.EnablePreimageRecording = *dec.EnablePreimageRecording 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 return nil
} }

View file

@ -476,7 +476,7 @@ func testDAOChallenge(t *testing.T, localForked, remoteForked bool, timeout bool
genesis = gspec.MustCommit(db) genesis = gspec.MustCommit(db)
blockchain, _ = core.NewBlockChain(db, config, pow, evmux, vm.Config{}) 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 { if err != nil {
t.Fatalf("failed to start test protocol manager: %v", err) t.Fatalf("failed to start test protocol manager: %v", err)
} }

View file

@ -65,7 +65,7 @@ func newTestProtocolManager(fastSync bool, blocks int, generator func(int, *core
panic(err) 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 { if err != nil {
return nil, err 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) { func (p *testPeer) handshake(t *testing.T, td *big.Int, head common.Hash, genesis common.Hash) {
msg := &statusData{ msg := &statusData{
ProtocolVersion: uint32(p.version), ProtocolVersion: uint32(p.version),
NetworkId: uint32(NetworkId), NetworkId: uint32(DefaultConfig.NetworkId),
TD: td, TD: td,
CurrentBlock: head, CurrentBlock: head,
GenesisBlock: genesis, GenesisBlock: genesis,

View file

@ -54,7 +54,7 @@ func testStatusMsgErrors(t *testing.T, protocol int) {
wantError: errResp(ErrNoStatusMsg, "first msg has code 2 (!= 0)"), 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), wantError: errResp(ErrProtocolVersionMismatch, "10 (!= %d)", protocol),
}, },
{ {
@ -62,7 +62,7 @@ func testStatusMsgErrors(t *testing.T, protocol int) {
wantError: errResp(ErrNetworkIdMismatch, "999 (!= 1)"), 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]), wantError: errResp(ErrGenesisBlockMismatch, "0300000000000000 (!= %x)", genesis[:8]),
}, },
} }