In Eth/concensus.go, it is mainly to verify the block head, adjust the mining difficulty of the algorithm, as well as verify that the dug block is correct and so on. There are pre-preparation, calculation of rewards, etc.
Verifyseal implements consensus.
Engine, checking whether the given block satisfies//the PoW difficulty requirements. Func (Ethash *ethash) verifyseal (chain consensus. Chainreader, Header *types. Header) Error {//If we ' re running a fake PoW, accept any seal as valid If Ethash.config.PowMode = = Modefake | | ethash. Config. Powmode = = Modefullfake {time. Sleep (ethash.fakedelay) If Ethash.fakefail = = header. Number.uint64 () {return errinvalidpow} return nil}//If we ' re running a shared PoW, delegate verification to it if ethash.shared! = Nil {return ethash.shared.VerifySeal (chain, header)}//sanity check that the block number I s below the lookup table size (60M blocks) Number: = header. Number.uint64 () If Number/epochlength >= UInt64 (len (cachesizes)) {//Go < 1.7 cannot calculate new Cache/dataset Sizes (no fast prime check) return Errnonceoutofrange}//Ensure that we had a valid difficulty for the block if H Eader.
Difficulty.sign () <= 0 {Return errinvaliddifficulty}//Recompute the digest and PoW value and verify against the header cache: = Ethash.cache Size: = datasetsize (number) if Ethash.config.PowMode = = modetest {size = + * 1024x768} digest, Result: = Ha Shimotolight (size, cache, header.) Hashnononce (). Bytes (), header. Nonce.uint64 ()) if!bytes. Equal (header. mixdigest[:], Digest) {return errinvalidmixdigest} target: = new (big. INT). Div (maxUint256, header. Difficulty) if new (big. INT). SetBytes (Result). CMP (target) > 0 {return Errinvalidpow} return nil}In Sealer.go, there are mainly two functions of mine and seal. Seal implements consensus. Engine, attempting to find a nonce that satisfies//The block ' s difficulty requirements.
Mine is the actual proof-of-work miner, searches for a nonce starting from//seed, results in correct final block Difficulty.