Skip to content

Commit 003e5b2

Browse files
authored
Revert "all: remove ethash pow, only retain shims needed for consensus and tests (ethereum#27178)"
This reverts commit 3eb5306.
1 parent 1339804 commit 003e5b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+5484
-210
lines changed

cmd/devp2p/internal/ethtest/testdata/genesis.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"eip155Block": 0,
77
"eip158Block": 0,
88
"byzantiumBlock": 0,
9-
"terminalTotalDifficultyPassed": true,
109
"ethash": {}
1110
},
1211
"nonce": "0xdeadbeefdeadbeef",

cmd/evm/internal/t8ntool/block.go

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/ethereum/go-ethereum/common/hexutil"
2929
"github.com/ethereum/go-ethereum/common/math"
3030
"github.com/ethereum/go-ethereum/consensus/clique"
31+
"github.com/ethereum/go-ethereum/consensus/ethash"
3132
"github.com/ethereum/go-ethereum/core/types"
3233
"github.com/ethereum/go-ethereum/crypto"
3334
"github.com/ethereum/go-ethereum/log"
@@ -73,9 +74,11 @@ type bbInput struct {
7374
Withdrawals []*types.Withdrawal `json:"withdrawals,omitempty"`
7475
Clique *cliqueInput `json:"clique,omitempty"`
7576

76-
Ethash bool `json:"-"`
77-
Txs []*types.Transaction `json:"-"`
78-
Ommers []*types.Header `json:"-"`
77+
Ethash bool `json:"-"`
78+
EthashDir string `json:"-"`
79+
PowMode ethash.Mode `json:"-"`
80+
Txs []*types.Transaction `json:"-"`
81+
Ommers []*types.Header `json:"-"`
7982
}
8083

8184
type cliqueInput struct {
@@ -159,13 +162,42 @@ func (i *bbInput) ToBlock() *types.Block {
159162
// SealBlock seals the given block using the configured engine.
160163
func (i *bbInput) SealBlock(block *types.Block) (*types.Block, error) {
161164
switch {
165+
case i.Ethash:
166+
return i.sealEthash(block)
162167
case i.Clique != nil:
163168
return i.sealClique(block)
164169
default:
165170
return block, nil
166171
}
167172
}
168173

174+
// sealEthash seals the given block using ethash.
175+
func (i *bbInput) sealEthash(block *types.Block) (*types.Block, error) {
176+
if i.Header.Nonce != nil {
177+
return nil, NewError(ErrorConfig, fmt.Errorf("sealing with ethash will overwrite provided nonce"))
178+
}
179+
ethashConfig := ethash.Config{
180+
PowMode: i.PowMode,
181+
DatasetDir: i.EthashDir,
182+
CacheDir: i.EthashDir,
183+
DatasetsInMem: 1,
184+
DatasetsOnDisk: 2,
185+
CachesInMem: 2,
186+
CachesOnDisk: 3,
187+
}
188+
engine := ethash.New(ethashConfig, nil, true)
189+
defer engine.Close()
190+
// Use a buffered chan for results.
191+
// If the testmode is used, the sealer will return quickly, and complain
192+
// "Sealing result is not read by miner" if it cannot write the result.
193+
results := make(chan *types.Block, 1)
194+
if err := engine.Seal(nil, block, results, nil); err != nil {
195+
panic(fmt.Sprintf("failed to seal block: %v", err))
196+
}
197+
found := <-results
198+
return block.WithSeal(found.Header()), nil
199+
}
200+
169201
// sealClique seals the given block using clique.
170202
func (i *bbInput) sealClique(block *types.Block) (*types.Block, error) {
171203
// If any clique value overwrites an explicit header value, fail
@@ -235,8 +267,28 @@ func readInput(ctx *cli.Context) (*bbInput, error) {
235267
withdrawalsStr = ctx.String(InputWithdrawalsFlag.Name)
236268
txsStr = ctx.String(InputTxsRlpFlag.Name)
237269
cliqueStr = ctx.String(SealCliqueFlag.Name)
270+
ethashOn = ctx.Bool(SealEthashFlag.Name)
271+
ethashDir = ctx.String(SealEthashDirFlag.Name)
272+
ethashMode = ctx.String(SealEthashModeFlag.Name)
238273
inputData = &bbInput{}
239274
)
275+
if ethashOn && cliqueStr != "" {
276+
return nil, NewError(ErrorConfig, fmt.Errorf("both ethash and clique sealing specified, only one may be chosen"))
277+
}
278+
if ethashOn {
279+
inputData.Ethash = ethashOn
280+
inputData.EthashDir = ethashDir
281+
switch ethashMode {
282+
case "normal":
283+
inputData.PowMode = ethash.ModeNormal
284+
case "test":
285+
inputData.PowMode = ethash.ModeTest
286+
case "fake":
287+
inputData.PowMode = ethash.ModeFake
288+
default:
289+
return nil, NewError(ErrorConfig, fmt.Errorf("unknown pow mode: %s, supported modes: test, fake, normal", ethashMode))
290+
}
291+
}
240292
if headerStr == stdinSelector || ommersStr == stdinSelector || txsStr == stdinSelector || cliqueStr == stdinSelector {
241293
decoder := json.NewDecoder(os.Stdin)
242294
if err := decoder.Decode(inputData); err != nil {

cmd/evm/internal/t8ntool/flags.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,19 @@ var (
125125
Name: "seal.clique",
126126
Usage: "Seal block with Clique. `stdin` or file name of where to find the Clique sealing data.",
127127
}
128+
SealEthashFlag = &cli.BoolFlag{
129+
Name: "seal.ethash",
130+
Usage: "Seal block with ethash.",
131+
}
132+
SealEthashDirFlag = &cli.StringFlag{
133+
Name: "seal.ethash.dir",
134+
Usage: "Path to ethash DAG. If none exists, a new DAG will be generated.",
135+
}
136+
SealEthashModeFlag = &cli.StringFlag{
137+
Name: "seal.ethash.mode",
138+
Usage: "Defines the type and amount of PoW verification an ethash engine makes.",
139+
Value: "normal",
140+
}
128141
RewardFlag = &cli.Int64Flag{
129142
Name: "state.reward",
130143
Usage: "Mining reward. Set to -1 to disable",

cmd/evm/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ var blockBuilderCommand = &cli.Command{
179179
t8ntool.InputWithdrawalsFlag,
180180
t8ntool.InputTxsRlpFlag,
181181
t8ntool.SealCliqueFlag,
182+
t8ntool.SealEthashFlag,
183+
t8ntool.SealEthashDirFlag,
184+
t8ntool.SealEthashModeFlag,
182185
t8ntool.VerbosityFlag,
183186
},
184187
}

cmd/geth/genesis_test.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,7 @@ var customGenesisTests = []struct {
4141
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
4242
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
4343
"timestamp" : "0x00",
44-
"config" : {
45-
"terminalTotalDifficultyPassed": true
46-
}
44+
"config" : {}
4745
}`,
4846
query: "eth.getBlock(0).nonce",
4947
result: "0x0000000000001338",
@@ -61,10 +59,9 @@ var customGenesisTests = []struct {
6159
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
6260
"timestamp" : "0x00",
6361
"config" : {
64-
"homesteadBlock" : 42,
65-
"daoForkBlock" : 141,
66-
"daoForkSupport" : true,
67-
"terminalTotalDifficultyPassed" : true
62+
"homesteadBlock" : 42,
63+
"daoForkBlock" : 141,
64+
"daoForkSupport" : true
6865
}
6966
}`,
7067
query: "eth.getBlock(0).nonce",
@@ -114,10 +111,8 @@ func TestCustomBackend(t *testing.T) {
114111
"mixhash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
115112
"parentHash" : "0x0000000000000000000000000000000000000000000000000000000000000000",
116113
"timestamp" : "0x00",
117-
"config" : {
118-
"terminalTotalDifficultyPassed": true
119-
}
120-
}`
114+
"config" : {}
115+
}`
121116
type backendTest struct {
122117
initArgs []string
123118
initExpect string

cmd/geth/main.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ var (
6666
utils.SmartCardDaemonPathFlag,
6767
utils.OverrideCancun,
6868
utils.EnablePersonal,
69+
utils.EthashCacheDirFlag,
70+
utils.EthashCachesInMemoryFlag,
71+
utils.EthashCachesOnDiskFlag,
72+
utils.EthashCachesLockMmapFlag,
73+
utils.EthashDatasetDirFlag,
74+
utils.EthashDatasetsInMemoryFlag,
75+
utils.EthashDatasetsOnDiskFlag,
76+
utils.EthashDatasetsLockMmapFlag,
6977
utils.TxPoolLocalsFlag,
7078
utils.TxPoolNoLocalsFlag,
7179
utils.TxPoolJournalFlag,
@@ -112,11 +120,14 @@ var (
112120
utils.MaxPeersFlag,
113121
utils.MaxPendingPeersFlag,
114122
utils.MiningEnabledFlag,
123+
utils.MinerThreadsFlag,
124+
utils.MinerNotifyFlag,
115125
utils.MinerGasLimitFlag,
116126
utils.MinerGasPriceFlag,
117127
utils.MinerEtherbaseFlag,
118128
utils.MinerExtraDataFlag,
119129
utils.MinerRecommitIntervalFlag,
130+
utils.MinerNoVerifyFlag,
120131
utils.MinerNewPayloadTimeout,
121132
utils.NATFlag,
122133
utils.NoDiscoverFlag,
@@ -131,11 +142,13 @@ var (
131142
utils.VMEnableDebugFlag,
132143
utils.NetworkIdFlag,
133144
utils.EthStatsURLFlag,
145+
utils.FakePoWFlag,
134146
utils.NoCompactionFlag,
135147
utils.GpoBlocksFlag,
136148
utils.GpoPercentileFlag,
137149
utils.GpoMaxGasPriceFlag,
138150
utils.GpoIgnoreGasPriceFlag,
151+
utils.MinerNotifyFullFlag,
139152
configFileFlag,
140153
}, utils.NetworkFlags, utils.DatabasePathFlags)
141154

@@ -211,6 +224,8 @@ func init() {
211224
attachCommand,
212225
javascriptCommand,
213226
// See misccmd.go:
227+
makecacheCommand,
228+
makedagCommand,
214229
versionCommand,
215230
versionCheckCommand,
216231
licenseCommand,
@@ -423,7 +438,9 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, isCon
423438
// Set the gas price to the limits from the CLI and start mining
424439
gasprice := flags.GlobalBig(ctx, utils.MinerGasPriceFlag.Name)
425440
ethBackend.TxPool().SetGasPrice(gasprice)
426-
if err := ethBackend.StartMining(); err != nil {
441+
// start mining
442+
threads := ctx.Int(utils.MinerThreadsFlag.Name)
443+
if err := ethBackend.StartMining(threads); err != nil {
427444
utils.Fatalf("Failed to start mining: %v", err)
428445
}
429446
}

cmd/geth/misccmd.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ import (
2020
"fmt"
2121
"os"
2222
"runtime"
23+
"strconv"
2324
"strings"
2425

26+
"github.com/ethereum/go-ethereum/cmd/utils"
27+
"github.com/ethereum/go-ethereum/consensus/ethash"
2528
"github.com/ethereum/go-ethereum/internal/version"
2629
"github.com/ethereum/go-ethereum/params"
2730
"github.com/urfave/cli/v2"
@@ -38,6 +41,30 @@ var (
3841
Usage: "Version to check",
3942
Value: version.ClientName(clientIdentifier),
4043
}
44+
makecacheCommand = &cli.Command{
45+
Action: makecache,
46+
Name: "makecache",
47+
Usage: "Generate ethash verification cache (for testing)",
48+
ArgsUsage: "<blockNum> <outputDir>",
49+
Description: `
50+
The makecache command generates an ethash cache in <outputDir>.
51+
52+
This command exists to support the system testing project.
53+
Regular users do not need to execute it.
54+
`,
55+
}
56+
makedagCommand = &cli.Command{
57+
Action: makedag,
58+
Name: "makedag",
59+
Usage: "Generate ethash mining DAG (for testing)",
60+
ArgsUsage: "<blockNum> <outputDir>",
61+
Description: `
62+
The makedag command generates an ethash DAG in <outputDir>.
63+
64+
This command exists to support the system testing project.
65+
Regular users do not need to execute it.
66+
`,
67+
}
4168
versionCommand = &cli.Command{
4269
Action: printVersion,
4370
Name: "version",
@@ -69,6 +96,36 @@ and displays information about any security vulnerabilities that affect the curr
6996
}
7097
)
7198

99+
// makecache generates an ethash verification cache into the provided folder.
100+
func makecache(ctx *cli.Context) error {
101+
args := ctx.Args().Slice()
102+
if len(args) != 2 {
103+
utils.Fatalf(`Usage: geth makecache <block number> <outputdir>`)
104+
}
105+
block, err := strconv.ParseUint(args[0], 0, 64)
106+
if err != nil {
107+
utils.Fatalf("Invalid block number: %v", err)
108+
}
109+
ethash.MakeCache(block, args[1])
110+
111+
return nil
112+
}
113+
114+
// makedag generates an ethash mining DAG into the provided folder.
115+
func makedag(ctx *cli.Context) error {
116+
args := ctx.Args().Slice()
117+
if len(args) != 2 {
118+
utils.Fatalf(`Usage: geth makedag <block number> <outputdir>`)
119+
}
120+
block, err := strconv.ParseUint(args[0], 0, 64)
121+
if err != nil {
122+
utils.Fatalf("Invalid block number: %v", err)
123+
}
124+
ethash.MakeDataset(block, args[1])
125+
126+
return nil
127+
}
128+
72129
func printVersion(ctx *cli.Context) error {
73130
git, _ := version.VCS()
74131

0 commit comments

Comments
 (0)