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:
+2
-6
@@ -24,7 +24,6 @@ import (
|
||||
"io"
|
||||
"math/big"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -86,11 +85,8 @@ func NewMinerAPI(e *Ethereum) *MinerAPI {
|
||||
// usable by this process. If mining is already running, this method adjust the
|
||||
// number of threads allowed to use and updates the minimum price required by the
|
||||
// transaction pool.
|
||||
func (api *MinerAPI) Start(threads *int) error {
|
||||
if threads == nil {
|
||||
return api.e.StartMining(runtime.NumCPU())
|
||||
}
|
||||
return api.e.StartMining(*threads)
|
||||
func (api *MinerAPI) Start() error {
|
||||
return api.e.StartMining()
|
||||
}
|
||||
|
||||
// Stop terminates the miner, both at the consensus engine level as well as at
|
||||
|
||||
+2
-2
@@ -397,8 +397,8 @@ func (b *EthAPIBackend) Miner() *miner.Miner {
|
||||
return b.eth.Miner()
|
||||
}
|
||||
|
||||
func (b *EthAPIBackend) StartMining(threads int) error {
|
||||
return b.eth.StartMining(threads)
|
||||
func (b *EthAPIBackend) StartMining() error {
|
||||
return b.eth.StartMining()
|
||||
}
|
||||
|
||||
func (b *EthAPIBackend) StateAtBlock(ctx context.Context, block *types.Block, reexec uint64, base *state.StateDB, readOnly bool, preferDisk bool) (*state.StateDB, tracers.StateReleaseFunc, error) {
|
||||
|
||||
+6
-17
@@ -134,14 +134,14 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) {
|
||||
log.Error("Failed to recover state", "error", err)
|
||||
}
|
||||
// Transfer mining-related config to the ethash config.
|
||||
ethashConfig := config.Ethash
|
||||
ethashConfig.NotifyFull = config.Miner.NotifyFull
|
||||
cliqueConfig, err := core.LoadCliqueConfig(chainDb, config.Genesis)
|
||||
chainConfig, err := core.LoadChainConfig(chainDb, config.Genesis)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
engine, err := ethconfig.CreateConsensusEngine(chainConfig, chainDb)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
engine := ethconfig.CreateConsensusEngine(stack, ðashConfig, cliqueConfig, config.Miner.Notify, config.Miner.Noverify, chainDb)
|
||||
|
||||
eth := &Ethereum{
|
||||
config: config,
|
||||
merger: consensus.NewMerger(chainDb),
|
||||
@@ -392,18 +392,7 @@ func (s *Ethereum) SetEtherbase(etherbase common.Address) {
|
||||
// StartMining starts the miner with the given number of CPU threads. If mining
|
||||
// is already running, this method adjust the number of threads allowed to use
|
||||
// and updates the minimum price required by the transaction pool.
|
||||
func (s *Ethereum) StartMining(threads int) error {
|
||||
// Update the thread count within the consensus engine
|
||||
type threaded interface {
|
||||
SetThreads(threads int)
|
||||
}
|
||||
if th, ok := s.engine.(threaded); ok {
|
||||
log.Info("Updated mining threads", "threads", threads)
|
||||
if threads == 0 {
|
||||
threads = -1 // Disable the miner from within
|
||||
}
|
||||
th.SetThreads(threads)
|
||||
}
|
||||
func (s *Ethereum) StartMining() error {
|
||||
// If the miner was not running, initialize it
|
||||
if !s.IsMining() {
|
||||
// Propagate the initial price point to the transaction pool
|
||||
|
||||
@@ -440,7 +440,7 @@ func startEthService(t *testing.T, genesis *core.Genesis, blocks []*types.Block)
|
||||
t.Fatal("can't create node:", err)
|
||||
}
|
||||
|
||||
ethcfg := ðconfig.Config{Genesis: genesis, Ethash: ethash.Config{PowMode: ethash.ModeFake}, SyncMode: downloader.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256}
|
||||
ethcfg := ðconfig.Config{Genesis: genesis, SyncMode: downloader.FullSync, TrieTimeout: time.Minute, TrieDirtyCache: 256, TrieCleanCache: 256}
|
||||
ethservice, err := eth.New(n, ethcfg)
|
||||
if err != nil {
|
||||
t.Fatal("can't create eth service:", err)
|
||||
|
||||
@@ -53,11 +53,9 @@ var (
|
||||
reorgProtThreshold = 48 // Threshold number of recent blocks to disable mini reorg protection
|
||||
reorgProtHeaderDelay = 2 // Number of headers to delay delivering to cover mini reorgs
|
||||
|
||||
fsHeaderCheckFrequency = 100 // Verification frequency of the downloaded headers during snap sync
|
||||
fsHeaderSafetyNet = 2048 // Number of headers to discard in case a chain violation is detected
|
||||
fsHeaderForceVerify = 24 // Number of headers to verify before and after the pivot to accept it
|
||||
fsHeaderContCheck = 3 * time.Second // Time interval to check for header continuations during state download
|
||||
fsMinFullBlocks = 64 // Number of blocks to retrieve fully even in snap sync
|
||||
fsHeaderSafetyNet = 2048 // Number of headers to discard in case a chain violation is detected
|
||||
fsHeaderContCheck = 3 * time.Second // Time interval to check for header continuations during state download
|
||||
fsMinFullBlocks = 64 // Number of blocks to retrieve fully even in snap sync
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -175,7 +173,7 @@ type LightChain interface {
|
||||
GetTd(common.Hash, uint64) *big.Int
|
||||
|
||||
// InsertHeaderChain inserts a batch of headers into the local chain.
|
||||
InsertHeaderChain([]*types.Header, int) (int, error)
|
||||
InsertHeaderChain([]*types.Header) (int, error)
|
||||
|
||||
// SetHead rewinds the local chain to a new head.
|
||||
SetHead(uint64) error
|
||||
@@ -1381,19 +1379,6 @@ func (d *Downloader) processHeaders(origin uint64, td, ttd *big.Int, beaconMode
|
||||
|
||||
// In case of header only syncing, validate the chunk immediately
|
||||
if mode == SnapSync || mode == LightSync {
|
||||
// If we're importing pure headers, verify based on their recentness
|
||||
var pivot uint64
|
||||
|
||||
d.pivotLock.RLock()
|
||||
if d.pivotHeader != nil {
|
||||
pivot = d.pivotHeader.Number.Uint64()
|
||||
}
|
||||
d.pivotLock.RUnlock()
|
||||
|
||||
frequency := fsHeaderCheckFrequency
|
||||
if chunkHeaders[len(chunkHeaders)-1].Number.Uint64()+uint64(fsHeaderForceVerify) > pivot {
|
||||
frequency = 1
|
||||
}
|
||||
// Although the received headers might be all valid, a legacy
|
||||
// PoW/PoA sync must not accept post-merge headers. Make sure
|
||||
// that any transition is rejected at this point.
|
||||
@@ -1426,11 +1411,11 @@ func (d *Downloader) processHeaders(origin uint64, td, ttd *big.Int, beaconMode
|
||||
}
|
||||
}
|
||||
if len(chunkHeaders) > 0 {
|
||||
if n, err := d.lightchain.InsertHeaderChain(chunkHeaders, frequency); err != nil {
|
||||
if n, err := d.lightchain.InsertHeaderChain(chunkHeaders); err != nil {
|
||||
rollbackErr = err
|
||||
|
||||
// If some headers were inserted, track them as uncertain
|
||||
if (mode == SnapSync || frequency > 1) && n > 0 && rollback == 0 {
|
||||
if mode == SnapSync && n > 0 && rollback == 0 {
|
||||
rollback = chunkHeaders[0].Number.Uint64()
|
||||
}
|
||||
log.Warn("Invalid header encountered", "number", chunkHeaders[n].Number, "hash", chunkHashes[n], "parent", chunkHeaders[n].ParentHash, "err", err)
|
||||
|
||||
+15
-68
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
+1
-1
@@ -207,7 +207,7 @@ func newHandler(config *handlerConfig) (*handler, error) {
|
||||
return errors.New("unexpected post-merge header")
|
||||
}
|
||||
}
|
||||
return h.chain.Engine().VerifyHeader(h.chain, header, true)
|
||||
return h.chain.Engine().VerifyHeader(h.chain, header)
|
||||
}
|
||||
heighter := func() uint64 {
|
||||
return h.chain.CurrentBlock().Number.Uint64()
|
||||
|
||||
Reference in New Issue
Block a user