all: remove ethash pow, only retain shims needed for consensus and tests (#27178)

* all: remove ethash pow, only retain shims needed for consensus and tests

* all: thank you linter

* all: disallow launching Geth in legacy PoW mode

* cmd/env/internal/t8ntool: remove dangling ethash flag
This commit is contained in:
Péter Szilágyi
2023-05-03 12:58:39 +03:00
committed by GitHub
parent ac3418def6
commit dde2da0efb
57 changed files with 210 additions and 5484 deletions
+15 -68
View File
@@ -18,10 +18,7 @@
package ethconfig
import (
"os"
"os/user"
"path/filepath"
"runtime"
"errors"
"time"
"github.com/ethereum/go-ethereum/common"
@@ -34,9 +31,7 @@ import (
"github.com/ethereum/go-ethereum/eth/downloader"
"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/node"
"github.com/ethereum/go-ethereum/params"
)
@@ -62,16 +57,7 @@ var LightClientGPO = gasprice.Config{
// Defaults contains default settings for use on the Ethereum main net.
var Defaults = Config{
SyncMode: downloader.SnapSync,
Ethash: ethash.Config{
CacheDir: "ethash",
CachesInMem: 2,
CachesOnDisk: 3,
CachesLockMmap: false,
DatasetsInMem: 1,
DatasetsOnDisk: 2,
DatasetsLockMmap: false,
},
SyncMode: downloader.SnapSync,
NetworkId: 1,
TxLookupLimit: 2350000,
LightPeers: 100,
@@ -92,27 +78,6 @@ var Defaults = Config{
RPCTxFeeCap: 1, // 1 ether
}
func init() {
home := os.Getenv("HOME")
if home == "" {
if user, err := user.Current(); err == nil {
home = user.HomeDir
}
}
if runtime.GOOS == "darwin" {
Defaults.Ethash.DatasetDir = filepath.Join(home, "Library", "Ethash")
} else if runtime.GOOS == "windows" {
localappdata := os.Getenv("LOCALAPPDATA")
if localappdata != "" {
Defaults.Ethash.DatasetDir = filepath.Join(localappdata, "Ethash")
} else {
Defaults.Ethash.DatasetDir = filepath.Join(home, "AppData", "Local", "Ethash")
}
} else {
Defaults.Ethash.DatasetDir = filepath.Join(home, ".ethash")
}
}
//go:generate go run github.com/fjl/gencodec -type Config -formats toml -out gen_config.go
// Config contains configuration options for of the ETH and LES protocols.
@@ -173,9 +138,6 @@ type Config struct {
// Mining options
Miner miner.Config
// Ethash options
Ethash ethash.Config
// Transaction pool options
TxPool txpool.Config
@@ -202,34 +164,19 @@ type Config struct {
OverrideCancun *uint64 `toml:",omitempty"`
}
// CreateConsensusEngine creates a consensus engine for the given chain configuration.
func CreateConsensusEngine(stack *node.Node, ethashConfig *ethash.Config, cliqueConfig *params.CliqueConfig, notify []string, noverify bool, db ethdb.Database) consensus.Engine {
// CreateConsensusEngine creates a consensus engine for the given chain config.
// Clique is allowed for now to live standalone, but ethash is forbidden and can
// only exist on already merged networks.
func CreateConsensusEngine(config *params.ChainConfig, db ethdb.Database) (consensus.Engine, error) {
// If proof-of-authority is requested, set it up
var engine consensus.Engine
if cliqueConfig != nil {
engine = clique.New(cliqueConfig, db)
} else {
switch ethashConfig.PowMode {
case ethash.ModeFake:
log.Warn("Ethash used in fake mode")
case ethash.ModeTest:
log.Warn("Ethash used in test mode")
case ethash.ModeShared:
log.Warn("Ethash used in shared mode")
}
engine = ethash.New(ethash.Config{
PowMode: ethashConfig.PowMode,
CacheDir: stack.ResolvePath(ethashConfig.CacheDir),
CachesInMem: ethashConfig.CachesInMem,
CachesOnDisk: ethashConfig.CachesOnDisk,
CachesLockMmap: ethashConfig.CachesLockMmap,
DatasetDir: ethashConfig.DatasetDir,
DatasetsInMem: ethashConfig.DatasetsInMem,
DatasetsOnDisk: ethashConfig.DatasetsOnDisk,
DatasetsLockMmap: ethashConfig.DatasetsLockMmap,
NotifyFull: ethashConfig.NotifyFull,
}, notify, noverify)
engine.(*ethash.Ethash).SetThreads(-1) // Disable CPU mining
if config.Clique != nil {
return beacon.New(clique.New(config.Clique, db)), nil
}
return beacon.New(engine)
// If defaulting to proof-of-work, enforce an already merged network since
// we cannot run PoW algorithms and more, so we cannot even follow a chain
// not coordinated by a beacon node.
if !config.TerminalTotalDifficultyPassed {
return nil, errors.New("ethash is only supported as a historical component of already merged networks")
}
return beacon.New(ethash.NewFaker()), nil
}
-7
View File
@@ -6,7 +6,6 @@ import (
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/txpool"
"github.com/ethereum/go-ethereum/eth/downloader"
@@ -48,7 +47,6 @@ func (c Config) MarshalTOML() (interface{}, error) {
Preimages bool
FilterLogCacheSize int
Miner miner.Config
Ethash ethash.Config
TxPool txpool.Config
GPO gasprice.Config
EnablePreimageRecording bool
@@ -90,7 +88,6 @@ func (c Config) MarshalTOML() (interface{}, error) {
enc.Preimages = c.Preimages
enc.FilterLogCacheSize = c.FilterLogCacheSize
enc.Miner = c.Miner
enc.Ethash = c.Ethash
enc.TxPool = c.TxPool
enc.GPO = c.GPO
enc.EnablePreimageRecording = c.EnablePreimageRecording
@@ -136,7 +133,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
Preimages *bool
FilterLogCacheSize *int
Miner *miner.Config
Ethash *ethash.Config
TxPool *txpool.Config
GPO *gasprice.Config
EnablePreimageRecording *bool
@@ -243,9 +239,6 @@ func (c *Config) UnmarshalTOML(unmarshal func(interface{}) error) error {
if dec.Miner != nil {
c.Miner = *dec.Miner
}
if dec.Ethash != nil {
c.Ethash = *dec.Ethash
}
if dec.TxPool != nil {
c.TxPool = *dec.TxPool
}