Unverified Commit 098a2b6e authored by gary rong's avatar gary rong Committed by GitHub

eth: move eth.Config to a common package (#22205)

This moves the eth config definition into a separate package, eth/ethconfig. 
Packages eth and les can now import this common package instead of
importing eth from les, reducing dependencies.
Co-authored-by: 's avatarFelix Lange <fjl@twurst.com>
parent 28121324
...@@ -47,8 +47,8 @@ import ( ...@@ -47,8 +47,8 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/ethstats" "github.com/ethereum/go-ethereum/ethstats"
"github.com/ethereum/go-ethereum/les" "github.com/ethereum/go-ethereum/les"
...@@ -247,7 +247,7 @@ func newFaucet(genesis *core.Genesis, port int, enodes []*enode.Node, network ui ...@@ -247,7 +247,7 @@ func newFaucet(genesis *core.Genesis, port int, enodes []*enode.Node, network ui
} }
// Assemble the Ethereum light client protocol // Assemble the Ethereum light client protocol
cfg := eth.DefaultConfig cfg := ethconfig.Defaults
cfg.SyncMode = downloader.LightSync cfg.SyncMode = downloader.LightSync
cfg.NetworkId = network cfg.NetworkId = network
cfg.Genesis = genesis cfg.Genesis = genesis
......
...@@ -27,7 +27,7 @@ import ( ...@@ -27,7 +27,7 @@ import (
"gopkg.in/urfave/cli.v1" "gopkg.in/urfave/cli.v1"
"github.com/ethereum/go-ethereum/cmd/utils" "github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/internal/ethapi" "github.com/ethereum/go-ethereum/internal/ethapi"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/metrics"
...@@ -85,7 +85,7 @@ type whisperDeprecatedConfig struct { ...@@ -85,7 +85,7 @@ type whisperDeprecatedConfig struct {
} }
type gethConfig struct { type gethConfig struct {
Eth eth.Config Eth ethconfig.Config
Shh whisperDeprecatedConfig Shh whisperDeprecatedConfig
Node node.Config Node node.Config
Ethstats ethstatsConfig Ethstats ethstatsConfig
...@@ -121,7 +121,7 @@ func defaultNodeConfig() node.Config { ...@@ -121,7 +121,7 @@ func defaultNodeConfig() node.Config {
func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) { func makeConfigNode(ctx *cli.Context) (*node.Node, gethConfig) {
// Load defaults. // Load defaults.
cfg := gethConfig{ cfg := gethConfig{
Eth: eth.DefaultConfig, Eth: ethconfig.Defaults,
Node: defaultNodeConfig(), Node: defaultNodeConfig(),
Metrics: metrics.DefaultConfig, Metrics: metrics.DefaultConfig,
} }
......
...@@ -33,7 +33,7 @@ import ( ...@@ -33,7 +33,7 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/internal/debug" "github.com/ethereum/go-ethereum/internal/debug"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
...@@ -75,7 +75,7 @@ func StartNode(ctx *cli.Context, stack *node.Node) { ...@@ -75,7 +75,7 @@ func StartNode(ctx *cli.Context, stack *node.Node) {
signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM) signal.Notify(sigc, syscall.SIGINT, syscall.SIGTERM)
defer signal.Stop(sigc) defer signal.Stop(sigc)
minFreeDiskSpace := eth.DefaultConfig.TrieDirtyCache minFreeDiskSpace := ethconfig.Defaults.TrieDirtyCache
if ctx.GlobalIsSet(MinFreeDiskSpaceFlag.Name) { if ctx.GlobalIsSet(MinFreeDiskSpaceFlag.Name) {
minFreeDiskSpace = ctx.GlobalInt(MinFreeDiskSpaceFlag.Name) minFreeDiskSpace = ctx.GlobalInt(MinFreeDiskSpaceFlag.Name)
} else if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheGCFlag.Name) { } else if ctx.GlobalIsSet(CacheFlag.Name) || ctx.GlobalIsSet(CacheGCFlag.Name) {
......
This diff is collapsed.
...@@ -20,7 +20,7 @@ import ( ...@@ -20,7 +20,7 @@ import (
"fmt" "fmt"
"strings" "strings"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
"gopkg.in/urfave/cli.v1" "gopkg.in/urfave/cli.v1"
) )
...@@ -55,12 +55,12 @@ var ( ...@@ -55,12 +55,12 @@ var (
LegacyMinerGasTargetFlag = cli.Uint64Flag{ LegacyMinerGasTargetFlag = cli.Uint64Flag{
Name: "targetgaslimit", Name: "targetgaslimit",
Usage: "Target gas floor for mined blocks (deprecated, use --miner.gastarget)", Usage: "Target gas floor for mined blocks (deprecated, use --miner.gastarget)",
Value: eth.DefaultConfig.Miner.GasFloor, Value: ethconfig.Defaults.Miner.GasFloor,
} }
LegacyMinerGasPriceFlag = BigFlag{ LegacyMinerGasPriceFlag = BigFlag{
Name: "gasprice", Name: "gasprice",
Usage: "Minimum gas price for mining a transaction (deprecated, use --miner.gasprice)", Usage: "Minimum gas price for mining a transaction (deprecated, use --miner.gasprice)",
Value: eth.DefaultConfig.Miner.GasPrice, Value: ethconfig.Defaults.Miner.GasPrice,
} }
LegacyMinerEtherbaseFlag = cli.StringFlag{ LegacyMinerEtherbaseFlag = cli.StringFlag{
Name: "etherbase", Name: "etherbase",
...@@ -76,12 +76,12 @@ var ( ...@@ -76,12 +76,12 @@ var (
LegacyLightServFlag = cli.IntFlag{ LegacyLightServFlag = cli.IntFlag{
Name: "lightserv", Name: "lightserv",
Usage: "Maximum percentage of time allowed for serving LES requests (deprecated, use --light.serve)", Usage: "Maximum percentage of time allowed for serving LES requests (deprecated, use --light.serve)",
Value: eth.DefaultConfig.LightServ, Value: ethconfig.Defaults.LightServ,
} }
LegacyLightPeersFlag = cli.IntFlag{ LegacyLightPeersFlag = cli.IntFlag{
Name: "lightpeers", Name: "lightpeers",
Usage: "Maximum number of light clients to serve, or light servers to attach to (deprecated, use --light.maxpeers)", Usage: "Maximum number of light clients to serve, or light servers to attach to (deprecated, use --light.maxpeers)",
Value: eth.DefaultConfig.LightPeers, Value: ethconfig.Defaults.LightPeers,
} }
// (Deprecated April 2020) // (Deprecated April 2020)
...@@ -143,12 +143,12 @@ var ( ...@@ -143,12 +143,12 @@ var (
LegacyGpoBlocksFlag = cli.IntFlag{ LegacyGpoBlocksFlag = cli.IntFlag{
Name: "gpoblocks", Name: "gpoblocks",
Usage: "Number of recent blocks to check for gas prices (deprecated, use --gpo.blocks)", Usage: "Number of recent blocks to check for gas prices (deprecated, use --gpo.blocks)",
Value: eth.DefaultConfig.GPO.Blocks, Value: ethconfig.Defaults.GPO.Blocks,
} }
LegacyGpoPercentileFlag = cli.IntFlag{ LegacyGpoPercentileFlag = cli.IntFlag{
Name: "gpopercentile", Name: "gpopercentile",
Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices (deprecated, use --gpo.percentile)", Usage: "Suggested gas price is the given percentile of a set of recent transaction gas prices (deprecated, use --gpo.percentile)",
Value: eth.DefaultConfig.GPO.Percentile, Value: ethconfig.Defaults.GPO.Percentile,
} }
LegacyBootnodesV4Flag = cli.StringFlag{ LegacyBootnodesV4Flag = cli.StringFlag{
Name: "bootnodesv4", Name: "bootnodesv4",
......
...@@ -31,6 +31,7 @@ import ( ...@@ -31,6 +31,7 @@ import (
"github.com/ethereum/go-ethereum/console/prompt" "github.com/ethereum/go-ethereum/console/prompt"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/internal/jsre" "github.com/ethereum/go-ethereum/internal/jsre"
"github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
...@@ -85,7 +86,7 @@ type tester struct { ...@@ -85,7 +86,7 @@ type tester struct {
// newTester creates a test environment based on which the console can operate. // newTester creates a test environment based on which the console can operate.
// Please ensure you call Close() on the returned tester to avoid leaks. // Please ensure you call Close() on the returned tester to avoid leaks.
func newTester(t *testing.T, confOverride func(*eth.Config)) *tester { func newTester(t *testing.T, confOverride func(*ethconfig.Config)) *tester {
// Create a temporary storage for the node keys and initialize it // Create a temporary storage for the node keys and initialize it
workspace, err := ioutil.TempDir("", "console-tester-") workspace, err := ioutil.TempDir("", "console-tester-")
if err != nil { if err != nil {
...@@ -97,7 +98,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester { ...@@ -97,7 +98,7 @@ func newTester(t *testing.T, confOverride func(*eth.Config)) *tester {
if err != nil { if err != nil {
t.Fatalf("failed to create node: %v", err) t.Fatalf("failed to create node: %v", err)
} }
ethConf := &eth.Config{ ethConf := &ethconfig.Config{
Genesis: core.DeveloperGenesisBlock(15, common.Address{}), Genesis: core.DeveloperGenesisBlock(15, common.Address{}),
Miner: miner.Config{ Miner: miner.Config{
Etherbase: common.HexToAddress(testAddress), Etherbase: common.HexToAddress(testAddress),
......
// Copyright 2021 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package core
import (
"context"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/bitutil"
"github.com/ethereum/go-ethereum/core/bloombits"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
)
const (
// bloomThrottling is the time to wait between processing two consecutive index
// sections. It's useful during chain upgrades to prevent disk overload.
bloomThrottling = 100 * time.Millisecond
)
// BloomIndexer implements a core.ChainIndexer, building up a rotated bloom bits index
// for the Ethereum header bloom filters, permitting blazing fast filtering.
type BloomIndexer struct {
size uint64 // section size to generate bloombits for
db ethdb.Database // database instance to write index data and metadata into
gen *bloombits.Generator // generator to rotate the bloom bits crating the bloom index
section uint64 // Section is the section number being processed currently
head common.Hash // Head is the hash of the last header processed
}
// NewBloomIndexer returns a chain indexer that generates bloom bits data for the
// canonical chain for fast logs filtering.
func NewBloomIndexer(db ethdb.Database, size, confirms uint64) *ChainIndexer {
backend := &BloomIndexer{
db: db,
size: size,
}
table := rawdb.NewTable(db, string(rawdb.BloomBitsIndexPrefix))
return NewChainIndexer(db, table, backend, size, confirms, bloomThrottling, "bloombits")
}
// Reset implements core.ChainIndexerBackend, starting a new bloombits index
// section.
func (b *BloomIndexer) Reset(ctx context.Context, section uint64, lastSectionHead common.Hash) error {
gen, err := bloombits.NewGenerator(uint(b.size))
b.gen, b.section, b.head = gen, section, common.Hash{}
return err
}
// Process implements core.ChainIndexerBackend, adding a new header's bloom into
// the index.
func (b *BloomIndexer) Process(ctx context.Context, header *types.Header) error {
b.gen.AddBloom(uint(header.Number.Uint64()-b.section*b.size), header.Bloom)
b.head = header.Hash()
return nil
}
// Commit implements core.ChainIndexerBackend, finalizing the bloom section and
// writing it out into the database.
func (b *BloomIndexer) Commit() error {
batch := b.db.NewBatch()
for i := 0; i < types.BloomBitLength; i++ {
bits, err := b.gen.Bitset(uint(i))
if err != nil {
return err
}
rawdb.WriteBloomBits(batch, uint(i), b.section, b.head, bitutil.CompressBytes(bits))
}
return batch.Write()
}
// Prune returns an empty error since we don't support pruning here.
func (b *BloomIndexer) Prune(threshold uint64) error {
return nil
}
...@@ -31,13 +31,13 @@ import ( ...@@ -31,13 +31,13 @@ import (
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/clique" "github.com/ethereum/go-ethereum/consensus/clique"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/bloombits" "github.com/ethereum/go-ethereum/core/bloombits"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/filters" "github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/eth/gasprice" "github.com/ethereum/go-ethereum/eth/gasprice"
"github.com/ethereum/go-ethereum/eth/protocols/eth" "github.com/ethereum/go-ethereum/eth/protocols/eth"
...@@ -55,9 +55,13 @@ import ( ...@@ -55,9 +55,13 @@ import (
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
) )
// Config contains the configuration options of the ETH protocol.
// Deprecated: use ethconfig.Config instead.
type Config = ethconfig.Config
// Ethereum implements the Ethereum full node service. // Ethereum implements the Ethereum full node service.
type Ethereum struct { type Ethereum struct {
config *Config config *ethconfig.Config
// Handlers // Handlers
txPool *core.TxPool txPool *core.TxPool
...@@ -93,7 +97,7 @@ type Ethereum struct { ...@@ -93,7 +97,7 @@ type Ethereum struct {
// New creates a new Ethereum object (including the // New creates a new Ethereum object (including the
// initialisation of the common Ethereum object) // initialisation of the common Ethereum object)
func New(stack *node.Node, config *Config) (*Ethereum, error) { func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
// Ensure configuration values are compatible and sane // Ensure configuration values are compatible and sane
if config.SyncMode == downloader.LightSync { if config.SyncMode == downloader.LightSync {
return nil, errors.New("can't run eth.Ethereum in light sync mode, use les.LightEthereum") return nil, errors.New("can't run eth.Ethereum in light sync mode, use les.LightEthereum")
...@@ -102,8 +106,8 @@ func New(stack *node.Node, config *Config) (*Ethereum, error) { ...@@ -102,8 +106,8 @@ func New(stack *node.Node, config *Config) (*Ethereum, error) {
return nil, fmt.Errorf("invalid sync mode %d", config.SyncMode) return nil, fmt.Errorf("invalid sync mode %d", config.SyncMode)
} }
if config.Miner.GasPrice == nil || config.Miner.GasPrice.Cmp(common.Big0) <= 0 { if config.Miner.GasPrice == nil || config.Miner.GasPrice.Cmp(common.Big0) <= 0 {
log.Warn("Sanitizing invalid miner gas price", "provided", config.Miner.GasPrice, "updated", DefaultConfig.Miner.GasPrice) log.Warn("Sanitizing invalid miner gas price", "provided", config.Miner.GasPrice, "updated", ethconfig.Defaults.Miner.GasPrice)
config.Miner.GasPrice = new(big.Int).Set(DefaultConfig.Miner.GasPrice) config.Miner.GasPrice = new(big.Int).Set(ethconfig.Defaults.Miner.GasPrice)
} }
if config.NoPruning && config.TrieDirtyCache > 0 { if config.NoPruning && config.TrieDirtyCache > 0 {
if config.SnapshotCache > 0 { if config.SnapshotCache > 0 {
...@@ -132,13 +136,13 @@ func New(stack *node.Node, config *Config) (*Ethereum, error) { ...@@ -132,13 +136,13 @@ func New(stack *node.Node, config *Config) (*Ethereum, error) {
chainDb: chainDb, chainDb: chainDb,
eventMux: stack.EventMux(), eventMux: stack.EventMux(),
accountManager: stack.AccountManager(), accountManager: stack.AccountManager(),
engine: CreateConsensusEngine(stack, chainConfig, &config.Ethash, config.Miner.Notify, config.Miner.Noverify, chainDb), engine: ethconfig.CreateConsensusEngine(stack, chainConfig, &config.Ethash, config.Miner.Notify, config.Miner.Noverify, chainDb),
closeBloomHandler: make(chan struct{}), closeBloomHandler: make(chan struct{}),
networkID: config.NetworkId, networkID: config.NetworkId,
gasPrice: config.Miner.GasPrice, gasPrice: config.Miner.GasPrice,
etherbase: config.Miner.Etherbase, etherbase: config.Miner.Etherbase,
bloomRequests: make(chan chan *bloombits.Retrieval), bloomRequests: make(chan chan *bloombits.Retrieval),
bloomIndexer: NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms), bloomIndexer: core.NewBloomIndexer(chainDb, params.BloomBitsBlocks, params.BloomConfirms),
p2pServer: stack.Server(), p2pServer: stack.Server(),
} }
...@@ -269,39 +273,6 @@ func makeExtraData(extra []byte) []byte { ...@@ -269,39 +273,6 @@ func makeExtraData(extra []byte) []byte {
return extra return extra
} }
// CreateConsensusEngine creates the required type of consensus engine instance for an Ethereum service
func CreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
// If proof-of-authority is requested, set it up
if chainConfig.Clique != nil {
return clique.New(chainConfig.Clique, db)
}
// Otherwise assume proof-of-work
switch config.PowMode {
case ethash.ModeFake:
log.Warn("Ethash used in fake mode")
return ethash.NewFaker()
case ethash.ModeTest:
log.Warn("Ethash used in test mode")
return ethash.NewTester(nil, noverify)
case ethash.ModeShared:
log.Warn("Ethash used in shared mode")
return ethash.NewShared()
default:
engine := ethash.New(ethash.Config{
CacheDir: stack.ResolvePath(config.CacheDir),
CachesInMem: config.CachesInMem,
CachesOnDisk: config.CachesOnDisk,
CachesLockMmap: config.CachesLockMmap,
DatasetDir: config.DatasetDir,
DatasetsInMem: config.DatasetsInMem,
DatasetsOnDisk: config.DatasetsOnDisk,
DatasetsLockMmap: config.DatasetsLockMmap,
}, notify, noverify)
engine.SetThreads(-1) // Disable CPU mining
return engine
}
}
// APIs return the collection of RPC services the ethereum package offers. // APIs return the collection of RPC services the ethereum package offers.
// NOTE, some of these services probably need to be moved to somewhere else. // NOTE, some of these services probably need to be moved to somewhere else.
func (s *Ethereum) APIs() []rpc.API { func (s *Ethereum) APIs() []rpc.API {
......
...@@ -17,16 +17,10 @@ ...@@ -17,16 +17,10 @@
package eth package eth
import ( import (
"context"
"time" "time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/bitutil" "github.com/ethereum/go-ethereum/common/bitutil"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/bloombits"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb"
) )
const ( const (
...@@ -78,66 +72,3 @@ func (eth *Ethereum) startBloomHandlers(sectionSize uint64) { ...@@ -78,66 +72,3 @@ func (eth *Ethereum) startBloomHandlers(sectionSize uint64) {
}() }()
} }
} }
const (
// bloomThrottling is the time to wait between processing two consecutive index
// sections. It's useful during chain upgrades to prevent disk overload.
bloomThrottling = 100 * time.Millisecond
)
// BloomIndexer implements a core.ChainIndexer, building up a rotated bloom bits index
// for the Ethereum header bloom filters, permitting blazing fast filtering.
type BloomIndexer struct {
size uint64 // section size to generate bloombits for
db ethdb.Database // database instance to write index data and metadata into
gen *bloombits.Generator // generator to rotate the bloom bits crating the bloom index
section uint64 // Section is the section number being processed currently
head common.Hash // Head is the hash of the last header processed
}
// NewBloomIndexer returns a chain indexer that generates bloom bits data for the
// canonical chain for fast logs filtering.
func NewBloomIndexer(db ethdb.Database, size, confirms uint64) *core.ChainIndexer {
backend := &BloomIndexer{
db: db,
size: size,
}
table := rawdb.NewTable(db, string(rawdb.BloomBitsIndexPrefix))
return core.NewChainIndexer(db, table, backend, size, confirms, bloomThrottling, "bloombits")
}
// Reset implements core.ChainIndexerBackend, starting a new bloombits index
// section.
func (b *BloomIndexer) Reset(ctx context.Context, section uint64, lastSectionHead common.Hash) error {
gen, err := bloombits.NewGenerator(uint(b.size))
b.gen, b.section, b.head = gen, section, common.Hash{}
return err
}
// Process implements core.ChainIndexerBackend, adding a new header's bloom into
// the index.
func (b *BloomIndexer) Process(ctx context.Context, header *types.Header) error {
b.gen.AddBloom(uint(header.Number.Uint64()-b.section*b.size), header.Bloom)
b.head = header.Hash()
return nil
}
// Commit implements core.ChainIndexerBackend, finalizing the bloom section and
// writing it out into the database.
func (b *BloomIndexer) Commit() error {
batch := b.db.NewBatch()
for i := 0; i < types.BloomBitLength; i++ {
bits, err := b.gen.Bitset(uint(i))
if err != nil {
return err
}
rawdb.WriteBloomBits(batch, uint(i), b.section, b.head, bitutil.CompressBytes(bits))
}
return batch.Write()
}
// Prune returns an empty error since we don't support pruning here.
func (b *BloomIndexer) Prune(threshold uint64) error {
return nil
}
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
// You should have received a copy of the GNU Lesser General Public License // You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package eth // Package ethconfig contains the configuration of the ETH and LES protocols.
package ethconfig
import ( import (
"math/big" "math/big"
...@@ -25,30 +26,35 @@ import ( ...@@ -25,30 +26,35 @@ import (
"time" "time"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/clique"
"github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/gasprice" "github.com/ethereum/go-ethereum/eth/gasprice"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/miner" "github.com/ethereum/go-ethereum/miner"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
// DefaultFullGPOConfig contains default gasprice oracle settings for full node. // FullNodeGPO contains default gasprice oracle settings for full node.
var DefaultFullGPOConfig = gasprice.Config{ var FullNodeGPO = gasprice.Config{
Blocks: 20, Blocks: 20,
Percentile: 60, Percentile: 60,
MaxPrice: gasprice.DefaultMaxPrice, MaxPrice: gasprice.DefaultMaxPrice,
} }
// DefaultLightGPOConfig contains default gasprice oracle settings for light client. // LightClientGPO contains default gasprice oracle settings for light client.
var DefaultLightGPOConfig = gasprice.Config{ var LightClientGPO = gasprice.Config{
Blocks: 2, Blocks: 2,
Percentile: 60, Percentile: 60,
MaxPrice: gasprice.DefaultMaxPrice, MaxPrice: gasprice.DefaultMaxPrice,
} }
// DefaultConfig contains default settings for use on the Ethereum main net. // Defaults contains default settings for use on the Ethereum main net.
var DefaultConfig = Config{ var Defaults = Config{
SyncMode: downloader.FastSync, SyncMode: downloader.FastSync,
Ethash: ethash.Config{ Ethash: ethash.Config{
CacheDir: "ethash", CacheDir: "ethash",
...@@ -77,7 +83,7 @@ var DefaultConfig = Config{ ...@@ -77,7 +83,7 @@ var DefaultConfig = Config{
}, },
TxPool: core.DefaultTxPoolConfig, TxPool: core.DefaultTxPoolConfig,
RPCGasCap: 25000000, RPCGasCap: 25000000,
GPO: DefaultFullGPOConfig, GPO: FullNodeGPO,
RPCTxFeeCap: 1, // 1 ether RPCTxFeeCap: 1, // 1 ether
} }
...@@ -89,21 +95,22 @@ func init() { ...@@ -89,21 +95,22 @@ func init() {
} }
} }
if runtime.GOOS == "darwin" { if runtime.GOOS == "darwin" {
DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "Library", "Ethash") Defaults.Ethash.DatasetDir = filepath.Join(home, "Library", "Ethash")
} else if runtime.GOOS == "windows" { } else if runtime.GOOS == "windows" {
localappdata := os.Getenv("LOCALAPPDATA") localappdata := os.Getenv("LOCALAPPDATA")
if localappdata != "" { if localappdata != "" {
DefaultConfig.Ethash.DatasetDir = filepath.Join(localappdata, "Ethash") Defaults.Ethash.DatasetDir = filepath.Join(localappdata, "Ethash")
} else { } else {
DefaultConfig.Ethash.DatasetDir = filepath.Join(home, "AppData", "Local", "Ethash") Defaults.Ethash.DatasetDir = filepath.Join(home, "AppData", "Local", "Ethash")
} }
} else { } else {
DefaultConfig.Ethash.DatasetDir = filepath.Join(home, ".ethash") Defaults.Ethash.DatasetDir = filepath.Join(home, ".ethash")
} }
} }
//go:generate gencodec -type Config -formats toml -out gen_config.go //go:generate gencodec -type Config -formats toml -out gen_config.go
// Config contains configuration options for of the ETH and LES protocols.
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.
...@@ -190,3 +197,36 @@ type Config struct { ...@@ -190,3 +197,36 @@ type Config struct {
// CheckpointOracle is the configuration for checkpoint oracle. // CheckpointOracle is the configuration for checkpoint oracle.
CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"` CheckpointOracle *params.CheckpointOracleConfig `toml:",omitempty"`
} }
// CreateConsensusEngine creates a consensus engine for the given chain configuration.
func CreateConsensusEngine(stack *node.Node, chainConfig *params.ChainConfig, config *ethash.Config, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
// If proof-of-authority is requested, set it up
if chainConfig.Clique != nil {
return clique.New(chainConfig.Clique, db)
}
// Otherwise assume proof-of-work
switch config.PowMode {
case ethash.ModeFake:
log.Warn("Ethash used in fake mode")
return ethash.NewFaker()
case ethash.ModeTest:
log.Warn("Ethash used in test mode")
return ethash.NewTester(nil, noverify)
case ethash.ModeShared:
log.Warn("Ethash used in shared mode")
return ethash.NewShared()
default:
engine := ethash.New(ethash.Config{
CacheDir: stack.ResolvePath(config.CacheDir),
CachesInMem: config.CachesInMem,
CachesOnDisk: config.CachesOnDisk,
CachesLockMmap: config.CachesLockMmap,
DatasetDir: config.DatasetDir,
DatasetsInMem: config.DatasetsInMem,
DatasetsOnDisk: config.DatasetsOnDisk,
DatasetsLockMmap: config.DatasetsLockMmap,
}, notify, noverify)
engine.SetThreads(-1) // Disable CPU mining
return engine
}
}
// Code generated by github.com/fjl/gencodec. DO NOT EDIT. // Code generated by github.com/fjl/gencodec. DO NOT EDIT.
package eth package ethconfig
import ( import (
"time" "time"
......
...@@ -34,6 +34,7 @@ import ( ...@@ -34,6 +34,7 @@ import (
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/rpc"
...@@ -195,7 +196,7 @@ func newTestBackend(t *testing.T) (*node.Node, []*types.Block) { ...@@ -195,7 +196,7 @@ func newTestBackend(t *testing.T) (*node.Node, []*types.Block) {
t.Fatalf("can't create new node: %v", err) t.Fatalf("can't create new node: %v", err)
} }
// Create Ethereum Service // Create Ethereum Service
config := &eth.Config{Genesis: genesis} config := &ethconfig.Config{Genesis: genesis}
config.Ethash.PowMode = ethash.ModeFake config.Ethash.PowMode = ethash.ModeFake
ethservice, err := eth.New(n, config) ethservice, err := eth.New(n, config)
if err != nil { if err != nil {
......
...@@ -28,6 +28,7 @@ import ( ...@@ -28,6 +28,7 @@ import (
"github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
...@@ -191,7 +192,7 @@ func createNode(t *testing.T, gqlEnabled bool) *node.Node { ...@@ -191,7 +192,7 @@ func createNode(t *testing.T, gqlEnabled bool) *node.Node {
func createGQLService(t *testing.T, stack *node.Node) { func createGQLService(t *testing.T, stack *node.Node) {
// create backend // create backend
ethConf := &eth.Config{ ethConf := &ethconfig.Config{
Genesis: &core.Genesis{ Genesis: &core.Genesis{
Config: params.AllEthashProtocolChanges, Config: params.AllEthashProtocolChanges,
GasLimit: 11500000, GasLimit: 11500000,
......
...@@ -33,6 +33,7 @@ import ( ...@@ -33,6 +33,7 @@ import (
"github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/les/flowcontrol" "github.com/ethereum/go-ethereum/les/flowcontrol"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/node" "github.com/ethereum/go-ethereum/node"
...@@ -492,14 +493,14 @@ func testSim(t *testing.T, serverCount, clientCount int, serverDir, clientDir [] ...@@ -492,14 +493,14 @@ func testSim(t *testing.T, serverCount, clientCount int, serverDir, clientDir []
} }
func newLesClientService(ctx *adapters.ServiceContext, stack *node.Node) (node.Lifecycle, error) { func newLesClientService(ctx *adapters.ServiceContext, stack *node.Node) (node.Lifecycle, error) {
config := eth.DefaultConfig config := ethconfig.Defaults
config.SyncMode = downloader.LightSync config.SyncMode = downloader.LightSync
config.Ethash.PowMode = ethash.ModeFake config.Ethash.PowMode = ethash.ModeFake
return New(stack, &config) return New(stack, &config)
} }
func newLesServerService(ctx *adapters.ServiceContext, stack *node.Node) (node.Lifecycle, error) { func newLesServerService(ctx *adapters.ServiceContext, stack *node.Node) (node.Lifecycle, error) {
config := eth.DefaultConfig config := ethconfig.Defaults
config.SyncMode = downloader.FullSync config.SyncMode = downloader.FullSync
config.LightServ = testServerCapacity config.LightServ = testServerCapacity
config.LightPeers = testMaxClients config.LightPeers = testMaxClients
......
...@@ -30,8 +30,8 @@ import ( ...@@ -30,8 +30,8 @@ import (
"github.com/ethereum/go-ethereum/core/bloombits" "github.com/ethereum/go-ethereum/core/bloombits"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/eth/filters" "github.com/ethereum/go-ethereum/eth/filters"
"github.com/ethereum/go-ethereum/eth/gasprice" "github.com/ethereum/go-ethereum/eth/gasprice"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
...@@ -76,7 +76,7 @@ type LightEthereum struct { ...@@ -76,7 +76,7 @@ type LightEthereum struct {
} }
// New creates an instance of the light client. // New creates an instance of the light client.
func New(stack *node.Node, config *eth.Config) (*LightEthereum, error) { func New(stack *node.Node, config *ethconfig.Config) (*LightEthereum, error) {
chainDb, err := stack.OpenDatabase("lightchaindata", config.DatabaseCache, config.DatabaseHandles, "eth/db/chaindata/") chainDb, err := stack.OpenDatabase("lightchaindata", config.DatabaseCache, config.DatabaseHandles, "eth/db/chaindata/")
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -105,9 +105,9 @@ func New(stack *node.Node, config *eth.Config) (*LightEthereum, error) { ...@@ -105,9 +105,9 @@ func New(stack *node.Node, config *eth.Config) (*LightEthereum, error) {
eventMux: stack.EventMux(), eventMux: stack.EventMux(),
reqDist: newRequestDistributor(peers, &mclock.System{}), reqDist: newRequestDistributor(peers, &mclock.System{}),
accountManager: stack.AccountManager(), accountManager: stack.AccountManager(),
engine: eth.CreateConsensusEngine(stack, chainConfig, &config.Ethash, nil, false, chainDb), engine: ethconfig.CreateConsensusEngine(stack, chainConfig, &config.Ethash, nil, false, chainDb),
bloomRequests: make(chan chan *bloombits.Retrieval), bloomRequests: make(chan chan *bloombits.Retrieval),
bloomIndexer: eth.NewBloomIndexer(chainDb, params.BloomBitsBlocksClient, params.HelperTrieConfirmations), bloomIndexer: core.NewBloomIndexer(chainDb, params.BloomBitsBlocksClient, params.HelperTrieConfirmations),
valueTracker: lpc.NewValueTracker(lespayDb, &mclock.System{}, requestList, time.Minute, 1/float64(time.Hour), 1/float64(time.Hour*100), 1/float64(time.Hour*1000)), valueTracker: lpc.NewValueTracker(lespayDb, &mclock.System{}, requestList, time.Minute, 1/float64(time.Hour), 1/float64(time.Hour*100), 1/float64(time.Hour*1000)),
p2pServer: stack.Server(), p2pServer: stack.Server(),
p2pConfig: &stack.Config().P2P, p2pConfig: &stack.Config().P2P,
......
...@@ -25,7 +25,7 @@ import ( ...@@ -25,7 +25,7 @@ import (
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/les/checkpointoracle" "github.com/ethereum/go-ethereum/les/checkpointoracle"
...@@ -48,7 +48,7 @@ type chainReader interface { ...@@ -48,7 +48,7 @@ type chainReader interface {
// lesCommons contains fields needed by both server and client. // lesCommons contains fields needed by both server and client.
type lesCommons struct { type lesCommons struct {
genesis common.Hash genesis common.Hash
config *eth.Config config *ethconfig.Config
chainConfig *params.ChainConfig chainConfig *params.ChainConfig
iConfig *light.IndexerConfig iConfig *light.IndexerConfig
chainDb ethdb.Database chainDb ethdb.Database
...@@ -138,7 +138,7 @@ func (c *lesCommons) localCheckpoint(index uint64) params.TrustedCheckpoint { ...@@ -138,7 +138,7 @@ func (c *lesCommons) localCheckpoint(index uint64) params.TrustedCheckpoint {
} }
// setupOracle sets up the checkpoint oracle contract client. // setupOracle sets up the checkpoint oracle contract client.
func (c *lesCommons) setupOracle(node *node.Node, genesis common.Hash, ethconfig *eth.Config) *checkpointoracle.CheckpointOracle { func (c *lesCommons) setupOracle(node *node.Node, genesis common.Hash, ethconfig *ethconfig.Config) *checkpointoracle.CheckpointOracle {
config := ethconfig.CheckpointOracle config := ethconfig.CheckpointOracle
if config == nil { if config == nil {
// Try loading default config. // Try loading default config.
......
...@@ -24,7 +24,7 @@ import ( ...@@ -24,7 +24,7 @@ import (
"time" "time"
"github.com/ethereum/go-ethereum/common/mclock" "github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/les/flowcontrol" "github.com/ethereum/go-ethereum/les/flowcontrol"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
...@@ -137,7 +137,7 @@ type costTracker struct { ...@@ -137,7 +137,7 @@ type costTracker struct {
// newCostTracker creates a cost tracker and loads the cost factor statistics from the database. // newCostTracker creates a cost tracker and loads the cost factor statistics from the database.
// It also returns the minimum capacity that can be assigned to any peer. // It also returns the minimum capacity that can be assigned to any peer.
func newCostTracker(db ethdb.Database, config *eth.Config) (*costTracker, uint64) { func newCostTracker(db ethdb.Database, config *ethconfig.Config) (*costTracker, uint64) {
utilTarget := float64(config.LightServ) * flowcontrol.FixedPointMultiplier / 100 utilTarget := float64(config.LightServ) * flowcontrol.FixedPointMultiplier / 100
ct := &costTracker{ ct := &costTracker{
db: db, db: db,
......
...@@ -22,7 +22,9 @@ import ( ...@@ -22,7 +22,9 @@ import (
"time" "time"
"github.com/ethereum/go-ethereum/common/mclock" "github.com/ethereum/go-ethereum/common/mclock"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/les/flowcontrol" "github.com/ethereum/go-ethereum/les/flowcontrol"
lps "github.com/ethereum/go-ethereum/les/lespay/server" lps "github.com/ethereum/go-ethereum/les/lespay/server"
"github.com/ethereum/go-ethereum/light" "github.com/ethereum/go-ethereum/light"
...@@ -50,6 +52,15 @@ func init() { ...@@ -50,6 +52,15 @@ func init() {
priorityPoolSetup.Connect(balanceTrackerSetup.BalanceField, balanceTrackerSetup.UpdateFlag) // NodeBalance implements nodePriority priorityPoolSetup.Connect(balanceTrackerSetup.BalanceField, balanceTrackerSetup.UpdateFlag) // NodeBalance implements nodePriority
} }
type ethBackend interface {
ArchiveMode() bool
BlockChain() *core.BlockChain
BloomIndexer() *core.ChainIndexer
ChainDb() ethdb.Database
Synced() bool
TxPool() *core.TxPool
}
type LesServer struct { type LesServer struct {
lesCommons lesCommons
...@@ -73,7 +84,7 @@ type LesServer struct { ...@@ -73,7 +84,7 @@ type LesServer struct {
p2pSrv *p2p.Server p2pSrv *p2p.Server
} }
func NewLesServer(node *node.Node, e *eth.Ethereum, config *eth.Config) (*LesServer, error) { func NewLesServer(node *node.Node, e ethBackend, config *ethconfig.Config) (*LesServer, error) {
ns := nodestate.NewNodeStateMachine(nil, nil, mclock.System{}, serverSetup) ns := nodestate.NewNodeStateMachine(nil, nil, mclock.System{}, serverSetup)
// Calculate the number of threads used to service the light client // Calculate the number of threads used to service the light client
// requests based on the user-specified value. // requests based on the user-specified value.
......
...@@ -38,7 +38,7 @@ import ( ...@@ -38,7 +38,7 @@ import (
"github.com/ethereum/go-ethereum/core/rawdb" "github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/les/checkpointoracle" "github.com/ethereum/go-ethereum/les/checkpointoracle"
...@@ -163,7 +163,7 @@ func prepare(n int, backend *backends.SimulatedBackend) { ...@@ -163,7 +163,7 @@ func prepare(n int, backend *backends.SimulatedBackend) {
func testIndexers(db ethdb.Database, odr light.OdrBackend, config *light.IndexerConfig, disablePruning bool) []*core.ChainIndexer { func testIndexers(db ethdb.Database, odr light.OdrBackend, config *light.IndexerConfig, disablePruning bool) []*core.ChainIndexer {
var indexers [3]*core.ChainIndexer var indexers [3]*core.ChainIndexer
indexers[0] = light.NewChtIndexer(db, odr, config.ChtSize, config.ChtConfirms, disablePruning) indexers[0] = light.NewChtIndexer(db, odr, config.ChtSize, config.ChtConfirms, disablePruning)
indexers[1] = eth.NewBloomIndexer(db, config.BloomSize, config.BloomConfirms) indexers[1] = core.NewBloomIndexer(db, config.BloomSize, config.BloomConfirms)
indexers[2] = light.NewBloomTrieIndexer(db, odr, config.BloomSize, config.BloomTrieSize, disablePruning) indexers[2] = light.NewBloomTrieIndexer(db, odr, config.BloomSize, config.BloomTrieSize, disablePruning)
// make bloomTrieIndexer as a child indexer of bloom indexer. // make bloomTrieIndexer as a child indexer of bloom indexer.
indexers[1].AddChildIndexer(indexers[2]) indexers[1].AddChildIndexer(indexers[2])
...@@ -204,7 +204,7 @@ func newTestClientHandler(backend *backends.SimulatedBackend, odr *LesOdr, index ...@@ -204,7 +204,7 @@ func newTestClientHandler(backend *backends.SimulatedBackend, odr *LesOdr, index
client := &LightEthereum{ client := &LightEthereum{
lesCommons: lesCommons{ lesCommons: lesCommons{
genesis: genesis.Hash(), genesis: genesis.Hash(),
config: &eth.Config{LightPeers: 100, NetworkId: NetworkId}, config: &ethconfig.Config{LightPeers: 100, NetworkId: NetworkId},
chainConfig: params.AllEthashProtocolChanges, chainConfig: params.AllEthashProtocolChanges,
iConfig: light.TestClientIndexerConfig, iConfig: light.TestClientIndexerConfig,
chainDb: db, chainDb: db,
...@@ -269,7 +269,7 @@ func newTestServerHandler(blocks int, indexers []*core.ChainIndexer, db ethdb.Da ...@@ -269,7 +269,7 @@ func newTestServerHandler(blocks int, indexers []*core.ChainIndexer, db ethdb.Da
server := &LesServer{ server := &LesServer{
lesCommons: lesCommons{ lesCommons: lesCommons{
genesis: genesis.Hash(), genesis: genesis.Hash(),
config: &eth.Config{LightPeers: 100, NetworkId: NetworkId}, config: &ethconfig.Config{LightPeers: 100, NetworkId: NetworkId},
chainConfig: params.AllEthashProtocolChanges, chainConfig: params.AllEthashProtocolChanges,
iConfig: light.TestServerIndexerConfig, iConfig: light.TestServerIndexerConfig,
chainDb: db, chainDb: db,
......
...@@ -185,7 +185,7 @@ func makeSealer(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) { ...@@ -185,7 +185,7 @@ func makeSealer(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) {
return nil, nil, err return nil, nil, err
} }
// Create and register the backend // Create and register the backend
ethBackend, err := eth.New(stack, &eth.Config{ ethBackend, err := eth.New(stack, &ethconfig.Config{
Genesis: genesis, Genesis: genesis,
NetworkId: genesis.Config.ChainID.Uint64(), NetworkId: genesis.Config.ChainID.Uint64(),
SyncMode: downloader.FullSync, SyncMode: downloader.FullSync,
......
...@@ -162,7 +162,7 @@ func makeMiner(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) { ...@@ -162,7 +162,7 @@ func makeMiner(genesis *core.Genesis) (*node.Node, *eth.Ethereum, error) {
if err != nil { if err != nil {
return nil, nil, err return nil, nil, err
} }
ethBackend, err := eth.New(stack, &eth.Config{ ethBackend, err := eth.New(stack, &ethconfig.Config{
Genesis: genesis, Genesis: genesis,
NetworkId: genesis.Config.ChainID.Uint64(), NetworkId: genesis.Config.ChainID.Uint64(),
SyncMode: downloader.FullSync, SyncMode: downloader.FullSync,
......
...@@ -25,8 +25,8 @@ import ( ...@@ -25,8 +25,8 @@ import (
"path/filepath" "path/filepath"
"github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/eth/downloader" "github.com/ethereum/go-ethereum/eth/downloader"
"github.com/ethereum/go-ethereum/eth/ethconfig"
"github.com/ethereum/go-ethereum/ethclient" "github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/ethstats" "github.com/ethereum/go-ethereum/ethstats"
"github.com/ethereum/go-ethereum/internal/debug" "github.com/ethereum/go-ethereum/internal/debug"
...@@ -182,7 +182,7 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) { ...@@ -182,7 +182,7 @@ func NewNode(datadir string, config *NodeConfig) (stack *Node, _ error) {
} }
// Register the Ethereum protocol if requested // Register the Ethereum protocol if requested
if config.EthereumEnabled { if config.EthereumEnabled {
ethConf := eth.DefaultConfig ethConf := ethconfig.Defaults
ethConf.Genesis = genesis ethConf.Genesis = genesis
ethConf.SyncMode = downloader.LightSync ethConf.SyncMode = downloader.LightSync
ethConf.NetworkId = uint64(config.EthereumNetworkID) ethConf.NetworkId = uint64(config.EthereumNetworkID)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment