freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

兄弟連區(qū)go語言區(qū)塊鏈技術(shù)培訓(xùn)以太坊源碼分析(11)eth目前的共識算法pow的整理-展示頁

2025-07-08 00:43本頁面
  

【正文】 m. It returns// the difficulty that a new block should have when created at time// given the parent block39。}return err err != nil {if err := ((), header)。// If all checks passed, validate any special fields for hard forks}}return err err != nil {if diff := new().Sub(, )。s +1s timestamp and parent39。// Verify the block39。}return errZeroBlockTimeif () = 0 {}}return if ((().Unix())) 0 {} else {}return errLargeBlockTimeif () 0 {if uncle {s timestamp// Ensure that the header39。return (chain, header, parent, false, seal)}``` 首先看第一個(gè)if,它的邏輯判斷是如果為true,那么就關(guān)閉所有的共識規(guī)則校驗(yàn),緊跟著兩個(gè)if判斷是只要該block的header的hash和number或者上一個(gè)header的hash和number存在鏈上,那么它header的共識規(guī)則校驗(yàn)就通過,如果都不通過,那么就需要做一些其他額外驗(yàn)證```// verifyHeader checks whether a header conforms to the consensus rules of the// stock Ethereum ethash engine.// See YP section . Block Header Validityfunc (ethash *Ethash) verifyHeader(chain , header, parent *, uncle bool, seal bool) error {// Sanity checks passed, do a proper verification}return if parent == nil {parent := (, number1)}return nilif ((), number) != nil {number := ()s parent not// If we39。return manager, nil``` 該方法中生成了一個(gè)校驗(yàn)區(qū)塊頭部的對象`validator` 讓我們繼續(xù)跟進(jìn)`(blockchain, header, true)`方法:```// VerifyHeader checks whether a header conforms to the consensus rules of the// stock Ethereum ethash engine.func (ethash *Ethash) VerifyHeader(chain , header *, seal bool) error { = (, validator, , heighter, inserter, )}return (blocks), 1) // Mark initial sync done on any fetcher importif (amp。// If fast sync is running, deny importing weird blocksinserter := func(blocks ) (int, error) {}return ().NumberU64()heighter := func() uint64 {}return (blockchain, header, true)validator := func(header *) error {makeFullNodeRegisterEthServiceNewProtocolManager verifyHeader VerifySeal``` eth的共識算法pow調(diào)用棧詳解 核心的邏輯需要從/eth/,關(guān)鍵代碼:``` = (mode, chaindb, , blockchain, nil, )NewProtocolManager verifyHeader VerifySeal```__整條鏈的運(yùn)行,打包交易,出塊的流程__```/cmd/geth/(, txs, , )``````eth/txs := (, pending)}return(Failed to fetch pending transactions, err, err)if err != nil {pending, err := ().Pending()}() () == 0 { != nil amp。if amp。work := 兄弟連區(qū)塊鏈技術(shù)培訓(xùn)以太坊源碼分析(11)eth目前的共識算法pow的整理 eth目前的共識算法pow的整理 涉及的代碼子包主要有consensus,miner,core,geth```/consensus 共識算法   1. Prepare方法2. CalcDifficulty方法:計(jì)算工作量3. AccumulateRewards方法:計(jì)算每個(gè)塊的出塊獎勵(lì)4. VerifySeal方法:校驗(yàn)pow的工作量難度是否符合要求,返回nil則通過5. verifyHeader方法:校驗(yàn)區(qū)塊頭是否符合共識規(guī)則```/miner 挖礦mitNewWork():提交新的塊,新的交易,從交易池中獲取未打包的交易,然后提交交易,進(jìn)行打包__核心代碼__:```// Create the current work task and check any fork transitions neededamp。amp。) == 1 {(Discarded bad propagated block, number, blocks[0].Number(), hash, blocks[0].Hash())return 0, nil}(amp。re running a full engine faking, accept any input as validif {return nil}// Short circuit if the header is known, or it39。s extradata section is of a reasonable sizeif uint64(len()) {return (extradata too long: %d %d, len(), )}// Verify the header39。s difficulty based in it39。s difficultyexpected := CalcDifficulty((), (), parent)if () != 0 {return (invalid difficulty: have %v, want %v, , expected)}// Verify that the gas limit is = 2^631if () 0 {return (invalid gasLimit: have %v, max %v, , )}// Verify that the gasUsed is = gasLimitif () 0 {return (invalid gasUsed: have %v, gasLimit %v, , )}// Verify that the gas limit remains within allowed boundsdiff := new().Set()diff = (diff, )(diff)limit := new().Set()limit = (limit, )if (limit) = 0 || () 0 {return (invalid gas limit: have %v, want %v += %v, , , limit)}// Verify that the block number is parent39。 ((1)) != 0 {return }// Verify the engine specific seal securing the blockif seal {if err := (chain, header)。 err != nil {return err}if err := ((), header, uncle)。s time and difficulty.// TODO (karalabe): Move the chain maker into this package and make this private!func CalcDifficulty(config *, time uint64, parent *) * {next := new().Add(, big1)switch {case (next):return calcDifficultyByzantium(time, parent)case (next):return calcDifficultyHomestead(time, parent)default:return calcDifficultyFrontier(time, parent)}}``` 該方法的第一個(gè)`case`是根據(jù)拜占庭規(guī)則去計(jì)算新塊應(yīng)該具有的難度,第二個(gè)`case`是根據(jù)宅基地規(guī)則去計(jì)算新塊應(yīng)該具有的難度,第三個(gè)`case`是根據(jù)邊界規(guī)則去計(jì)算難度 pow計(jì)算生成新塊代碼解析__/consensus/```// Seal implements , attempting to find a nonce that satisfies// the block39。// If we39。if {, = {}, {}}re running a shared PoW, delegate sealing to itreturn (chain, block, s
點(diǎn)擊復(fù)制文檔內(nèi)容
外語相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1