Concensus.go Sealer.go Source

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.