github.com/ethereum/go-ethereum@v1.16.1/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 ) 26 27 // Ethash is a consensus engine based on proof-of-work implementing the ethash 28 // algorithm. 29 type Ethash struct { 30 fakeFail *uint64 // Block number which fails PoW check even in fake mode 31 fakeDelay *time.Duration // Time delay to sleep for before returning from verify 32 fakeFull bool // Accepts everything as valid 33 } 34 35 // NewFaker creates an ethash consensus engine with a fake PoW scheme that accepts 36 // all blocks' seal as valid, though they still have to conform to the Ethereum 37 // consensus rules. 38 func NewFaker() *Ethash { 39 return new(Ethash) 40 } 41 42 // NewFakeFailer creates a ethash consensus engine with a fake PoW scheme that 43 // accepts all blocks as valid apart from the single one specified, though they 44 // still have to conform to the Ethereum consensus rules. 45 func NewFakeFailer(fail uint64) *Ethash { 46 return &Ethash{ 47 fakeFail: &fail, 48 } 49 } 50 51 // NewFakeDelayer creates a ethash consensus engine with a fake PoW scheme that 52 // accepts all blocks as valid, but delays verifications by some time, though 53 // they still have to conform to the Ethereum consensus rules. 54 func NewFakeDelayer(delay time.Duration) *Ethash { 55 return &Ethash{ 56 fakeDelay: &delay, 57 } 58 } 59 60 // NewFullFaker creates an ethash consensus engine with a full fake scheme that 61 // accepts all blocks as valid, without checking any consensus rules whatsoever. 62 func NewFullFaker() *Ethash { 63 return &Ethash{ 64 fakeFull: true, 65 } 66 } 67 68 // Close closes the exit channel to notify all backend threads exiting. 69 func (ethash *Ethash) Close() error { 70 return nil 71 } 72 73 // Seal generates a new sealing request for the given input block and pushes 74 // the result into the given channel. For the ethash engine, this method will 75 // just panic as sealing is not supported anymore. 76 func (ethash *Ethash) Seal(chain consensus.ChainHeaderReader, block *types.Block, results chan<- *types.Block, stop <-chan struct{}) error { 77 panic("ethash (pow) sealing not supported any more") 78 }