github.com/ethereum/go-ethereum@v1.14.3/consensus/ethash/ethash.go (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 // Package ethash implements the ethash proof-of-work consensus engine. 18 package ethash 19 20 import ( 21 "time" 22 23 "github.com/ethereum/go-ethereum/consensus" 24 "github.com/ethereum/go-ethereum/core/types" 25 "github.com/ethereum/go-ethereum/rpc" 26 ) 27 28 // Ethash is a consensus engine based on proof-of-work implementing the ethash 29 // algorithm. 30 type Ethash struct { 31 fakeFail *uint64 // Block number which fails PoW check even in fake mode 32 fakeDelay *time.Duration // Time delay to sleep for before returning from verify 33 fakeFull bool // Accepts everything as valid 34 } 35 36 // NewFaker creates an ethash consensus engine with a fake PoW scheme that accepts 37 // all blocks' seal as valid, though they still have to conform to the Ethereum 38 // consensus rules. 39 func NewFaker() *Ethash { 40 return new(Ethash) 41 } 42 43 // NewFakeFailer creates a ethash consensus engine with a fake PoW scheme that 44 // accepts all blocks as valid apart from the single one specified, though they 45 // still have to conform to the Ethereum consensus rules. 46 func NewFakeFailer(fail uint64) *Ethash { 47 return &Ethash{ 48 fakeFail: &fail, 49 } 50 } 51 52 // NewFakeDelayer creates a ethash consensus engine with a fake PoW scheme that 53 // accepts all blocks as valid, but delays verifications by some time, though 54 // they still have to conform to the Ethereum consensus rules. 55 func NewFakeDelayer(delay time.Duration) *Ethash { 56 return &Ethash{ 57 fakeDelay: &delay, 58 } 59 } 60 61 // NewFullFaker creates an ethash consensus engine with a full fake scheme that 62 // accepts all blocks as valid, without checking any consensus rules whatsoever. 63 func NewFullFaker() *Ethash { 64 return &Ethash{ 65 fakeFull: true, 66 } 67 } 68 69 // Close closes the exit channel to notify all backend threads exiting. 70 func (ethash *Ethash) Close() error { 71 return nil 72 } 73 74 // APIs implements consensus.Engine, returning no APIs as ethash is an empty 75 // shell in the post-merge world. 76 func (ethash *Ethash) APIs(chain consensus.ChainHeaderReader) []rpc.API { 77 return []rpc.API{} 78 } 79 80 // Seal generates a new sealing request for the given input block and pushes 81 // the result into the given channel. For the ethash engine, this method will 82 // just panic as sealing is not supported anymore. 83 func (ethash *Ethash) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error { 84 panic("ethash (pow) sealing not supported any more") 85 }