eth/backend.go — Version Comparison¶
| v1.16.8 | v1.17.3 | |
|---|---|---|
| Branch | etc/v1.16.8-full-node |
etc/v1.17.3-full-node |
| Delta | +38 -12 | +50 -11 |
ETC delta on v1.16.8 (+38 -12)
diff --git a/eth/backend.go b/eth/backend.go
index 850956182..d1446edb7 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -179,7 +179,10 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
if err != nil {
return nil, err
}
- engine, err := ethconfig.CreateConsensusEngine(chainConfig, chainDb)
+ // Resolve ethash cache directory relative to datadir (pre-purge3: stack.ResolvePath).
+ // Without this, the relative "etchash" path is created in CWD (e.g. / under systemd).
+ config.Ethash.CacheDir = stack.ResolvePath(config.Ethash.CacheDir)
+ engine, err := ethconfig.CreateConsensusEngineWithConfig(chainConfig, chainDb, config.Ethash)
if err != nil {
return nil, err
}
@@ -327,22 +330,30 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
// Permit the downloader to use the trie cache allowance during fast sync
cacheLimit := options.TrieCleanLimit + options.TrieDirtyLimit + options.SnapshotLimit
if eth.handler, err = newHandler(&handlerConfig{
- NodeID: eth.p2pServer.Self().ID(),
- Database: chainDb,
- Chain: eth.blockchain,
- TxPool: eth.txPool,
- Network: networkID,
- Sync: config.SyncMode,
- BloomCache: uint64(cacheLimit),
- EventMux: eth.eventMux,
- RequiredBlocks: config.RequiredBlocks,
+ NodeID: eth.p2pServer.Self().ID(),
+ Database: chainDb,
+ Chain: eth.blockchain,
+ TxPool: eth.txPool,
+ Network: networkID,
+ Sync: config.SyncMode,
+ BloomCache: uint64(cacheLimit),
+ EventMux: eth.eventMux,
+ RequiredBlocks: config.RequiredBlocks,
+ IsPow: eth.blockchain.Config().IsPow(),
+ MESSForceEnable: config.MESSForceEnable,
+ MESSForceDisable: config.MESSForceDisable,
}); err != nil {
return nil, err
}
eth.dropper = newDropper(eth.p2pServer.MaxDialedConns(), eth.p2pServer.MaxInboundConns())
- eth.miner = miner.New(eth, config.Miner, eth.engine)
+ if chainConfig.IsPow() {
+ eth.miner = miner.NewPoW(eth, config.Miner, eth.engine, eth.eventMux)
+ go eth.minerUpdate()
+ } else {
+ eth.miner = miner.New(eth, config.Miner, eth.engine)
+ }
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
eth.miner.SetPrioAddresses(config.TxPool.Locals)
@@ -388,9 +399,21 @@ func makeExtraData(extra []byte) []byte {
func (s *Ethereum) APIs() []rpc.API {
apis := ethapi.GetAPIs(s.APIBackend)
+ // Register ethash engine APIs (eth_getWork, eth_submitWork, etc.) if available.
+ // Removed from consensus.Engine interface in upstream; restored for PoW chains.
+ type engineAPIs interface {
+ APIs(consensus.ChainHeaderReader) []rpc.API
+ }
+ if ea, ok := s.engine.(engineAPIs); ok {
+ apis = append(apis, ea.APIs(s.blockchain)...)
+ }
+
// Append all the local APIs and return
return append(apis, []rpc.API{
{
+ Namespace: "eth",
+ Service: NewEthereumAPI(s),
+ }, {
Namespace: "miner",
Service: NewMinerAPI(s),
}, {
@@ -430,7 +453,7 @@ func (s *Ethereum) ArchiveMode() bool { return s.config.NoPruni
// Protocols returns all the currently configured
// network protocols to start.
func (s *Ethereum) Protocols() []p2p.Protocol {
- protos := eth.MakeProtocols((*ethHandler)(s.handler), s.networkID, s.discmix)
+ protos := eth.MakeProtocols((*ethHandler)(s.handler), s.networkID, s.discmix, eth.GetProtocolVersions(s.blockchain.Config().IsPow()))
if s.config.SnapshotCache > 0 {
protos = append(protos, snap.MakeProtocols((*snapHandler)(s.handler))...)
}
@@ -569,6 +592,9 @@ func (s *Ethereum) setupDiscovery() error {
// Stop implements node.Lifecycle, terminating all internal goroutines used by the
// Ethereum protocol.
func (s *Ethereum) Stop() error {
+ // Stop PoW miner if running.
+ s.miner.CloseMining()
+
// Stop all the peer-related stuff first.
s.discmix.Close()
s.dropper.Stop()
ETC delta on v1.17.3 (+50 -11)
diff --git a/eth/backend.go b/eth/backend.go
index af8b04bda..e1149fb6d 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -172,13 +172,29 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
}
}
+ // One-shot migration of a datadir created by core-geth: it stores the chain
+ // config under the same key but in a different JSON schema, which would otherwise
+ // trip CheckCompatible and rewind the chain. This rewrites it in place on the
+ // first start; afterwards it is a no-op. Safe to remove together with
+ // core/coregeth_migration.go once core-geth is deprecated.
+ if err := core.MigrateCoreGethChainConfig(chainDb); err != nil {
+ return nil, err
+ }
+
// Here we determine genesis hash and active ChainConfig.
// We need these to figure out the consensus parameters and to set up history pruning.
chainConfig, genesisHash, err := core.LoadChainConfig(chainDb, config.Genesis)
if err != nil {
return nil, err
}
- engine, err := ethconfig.CreateConsensusEngine(chainConfig, chainDb)
+ // Resolve ethash cache directory relative to datadir (pre-purge3: stack.ResolvePath).
+ // Without this, the relative "etchash" path is created in CWD (e.g. / under systemd).
+ config.Ethash.CacheDir = stack.ResolvePath(config.Ethash.CacheDir)
+ // Transfer the miner-side notify settings into the ethash config so
+ // --miner.notify / --miner.notify.full / --miner.noverify actually reach
+ // the underlying engine (mirrors the pre-purge plumbing).
+ config.Ethash.NotifyFull = config.Miner.NotifyFull
+ engine, err := ethconfig.CreateConsensusEngineWithConfig(chainConfig, chainDb, config.Ethash, config.Miner.Notify, config.Miner.Noverify)
if err != nil {
return nil, err
}
@@ -334,21 +350,29 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
// Permit the downloader to use the trie cache allowance during fast sync
cacheLimit := options.TrieCleanLimit + options.TrieDirtyLimit + options.SnapshotLimit
if eth.handler, err = newHandler(&handlerConfig{
- NodeID: eth.p2pServer.Self().ID(),
- Database: chainDb,
- Chain: eth.blockchain,
- TxPool: eth.txPool,
- Network: networkID,
- Sync: config.SyncMode,
- BloomCache: uint64(cacheLimit),
- RequiredBlocks: config.RequiredBlocks,
+ NodeID: eth.p2pServer.Self().ID(),
+ Database: chainDb,
+ Chain: eth.blockchain,
+ TxPool: eth.txPool,
+ Network: networkID,
+ Sync: config.SyncMode,
+ BloomCache: uint64(cacheLimit),
+ RequiredBlocks: config.RequiredBlocks,
+ IsPow: eth.blockchain.Config().IsPow(),
+ MESSForceEnable: config.MESSForceEnable,
+ MESSForceDisable: config.MESSForceDisable,
}); err != nil {
return nil, err
}
eth.dropper = newDropper(eth.p2pServer.MaxDialedConns(), eth.p2pServer.MaxInboundConns())
- eth.miner = miner.New(eth, config.Miner, eth.engine)
+ if chainConfig.IsPow() {
+ eth.miner = miner.NewPoW(eth, config.Miner, eth.engine, eth.handler.EventMux())
+ go eth.minerUpdate()
+ } else {
+ eth.miner = miner.New(eth, config.Miner, eth.engine)
+ }
eth.miner.SetExtra(makeExtraData(config.Miner.ExtraData))
eth.miner.SetPrioAddresses(config.TxPool.Locals)
@@ -394,9 +418,21 @@ func makeExtraData(extra []byte) []byte {
func (s *Ethereum) APIs() []rpc.API {
apis := ethapi.GetAPIs(s.APIBackend)
+ // Register ethash engine APIs (eth_getWork, eth_submitWork, etc.) if available.
+ // Removed from consensus.Engine interface in upstream; restored for PoW chains.
+ type engineAPIs interface {
+ APIs(consensus.ChainHeaderReader) []rpc.API
+ }
+ if ea, ok := s.engine.(engineAPIs); ok {
+ apis = append(apis, ea.APIs(s.blockchain)...)
+ }
+
// Append all the local APIs and return
return append(apis, []rpc.API{
{
+ Namespace: "eth",
+ Service: NewEthereumAPI(s),
+ }, {
Namespace: "miner",
Service: NewMinerAPI(s),
}, {
@@ -436,7 +472,7 @@ func (s *Ethereum) ArchiveMode() bool { return s.config.NoPruni
// Protocols returns all the currently configured
// network protocols to start.
func (s *Ethereum) Protocols() []p2p.Protocol {
- protos := eth.MakeProtocols((*ethHandler)(s.handler), s.networkID, s.discmix)
+ protos := eth.MakeProtocols((*ethHandler)(s.handler), s.networkID, s.discmix, eth.GetProtocolVersions(s.blockchain.Config().IsPow()))
if s.config.SnapshotCache > 0 {
protos = append(protos, snap.MakeProtocols((*snapHandler)(s.handler))...)
}
@@ -578,6 +614,9 @@ func (s *Ethereum) setupDiscovery() error {
// Stop implements node.Lifecycle, terminating all internal goroutines used by the
// Ethereum protocol.
func (s *Ethereum) Stop() error {
+ // Stop PoW miner if running.
+ s.miner.CloseMining()
+
// Stop all the peer-related stuff first.
s.discmix.Close()
s.dropper.Stop()