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

正文內(nèi)容

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

2025-07-05 00:43本頁(yè)面
  

【正文】 rite transactions}continue(Failed writing block to chain, err, err)if err != nil {stat, err := (block, , )} = ()for _, log := range () {}} = ()for _, l := range {for _, r := range {// receipt/log of individual transactions were created.// Update the block hash in all logs since it is now available and not when thework := block := }continueif result == nil {, 1) amp。// Solutions seems to be valid, return to the miner and notify acceptanceblock := (result)}return false(Invalid proofofwork submitted, hash, hash, err, err) err != nil { 比如我有一個(gè)礦機(jī),礦機(jī)內(nèi)部沒有運(yùn)行以太坊節(jié)點(diǎn),礦機(jī)首先從remote_agent獲取當(dāng)前的任務(wù),然后進(jìn)行挖礦計(jì)算,當(dāng)挖礦完成后,提交計(jì)算結(jié)果,完成挖礦。 amp。(Successfully sealed new block, number, (), hash, ()) result != nil {amp。// If we39。} else {()(, txset, , )txset := (, txs)txs := map[]{acc: {}}acc, _ := (, )()) == 0 {// Apply transaction to the pending state if we39。case ev := :// Handle TxPreEvent()[()] = ()case ev := :// Handle ChainSideEvent()case :// Handle ChainHeadEventselect {// A real event arrived, process interesting contentfor {defer ()defer ()defer ()return worker}該方法中綁定了三個(gè)管道,額外啟動(dòng)了兩個(gè)goroutine執(zhí)行update和wait方法,func (self *worker) update() {()go ()go () = ().SubscribeChainSideEvent() = ().SubscribeChainHeadEvent()// Subscribe events for blockchain = ().SubscribeTxPreEvent()// Subscribe TxPreEvent for tx pool}unconfirmed: newUnconfirmedBlocks((), miningLogAtDepth),agents: make(map[Agent]struct{}),coinbase: coinbase,possibleUncles: make(map[]*),proc: ().Validator(),chain: (),recv: make(chan *Result, resultQueueSize),chainDb: (),chainSideCh: make(chan , chainSideChanSize),chainHeadCh: make(chan , chainHeadChanSize),txCh: make(chan , txChanSize),mux: mux,eth: eth,engine: engine,config: config,worker{這樣的規(guī)定,保證了在某個(gè)節(jié)點(diǎn)上,一個(gè)新區(qū)塊只可能有一種來源,這可以大大降低可能出現(xiàn)的區(qū)塊沖突,并避免全網(wǎng)中計(jì)算資源的浪費(fèi)。miner := amp。}}如果挖到一個(gè)新塊,則將結(jié)果寫到self的return管道中寫塊的方法WriteBlockAndState,如果有結(jié)果,說明本地挖到新塊了,則將新塊進(jìn)行存儲(chǔ),并把該塊放到待確認(rèn)的block判定區(qū),如果有新塊出來,則停止挖礦進(jìn)行下載同步新塊,如果下載完成或失敗的事件,則繼續(xù)開始挖礦./geth/  makeFullNode (ctx, cfg)  (eth, , (), )這個(gè)是啟動(dòng)鏈后到挖礦,共識(shí)代碼的整個(gè)調(diào)用棧,開始分析核心方法func New(eth Backend, config *, mux *, engine ) *Miner { nil}(Block sealing failed, err, err)if err != nil {} else {Result{work, result}if result, err := (, , stop)。}()方法func (self *CpuAgent) mine(work *Work, stop chan struct{}) {continueif result == nil {, 1) i len(mix)。 j mixBytes/hashBytes。 i loopAccesses。 i len(mix)。// We don39。default:return(attempts)(Ethash nonce search aborted, attempts, nonceseed)// Mining terminated, update stats and abortcase abort:select {for {(Started ethash search for new nonces, seed, seed)logger := (miner, id))nonce = seedattempts = int64(0)var (// Start generating random nonces until we abort or find a good one)dataset = (number)number = ()target = new().Div(maxUint256, )hash = ().Bytes()header = ()var (// Extract some data from the headerreturn result, nil}``` 該方法的foreach中并行挖新塊,一旦停止或者找到新快,則廢棄其他所有的,如果協(xié)程計(jì)算有變更,則重新調(diào)用方法 好了pow挖礦的核心方法已經(jīng)出現(xiàn),``,如果挖取到新塊,那么就寫入到`found channel````// mine is the actual proofofwork miner that searches for a nonce starting from// seed that results in correct final block difficulty.func (ethash *Ethash) mine(block *, id int, seed uint64, abort chan struct{}, found chan *) {// Wait for all miners to terminate and return the blockreturn (chain, block, stop)close(abort)case :// One of the threads found a block, abort all othersclose(abort)case stop:var result *}(block, id, nonce, abort, found)go func(id int, nonce uint64) { i++ {for i := 0。}if threads 0 {threads = ()() = ((()))return nil, errif err != nil {if == nil {()abort := make(chan struct{})}if != nil {// If we39。return (header), nilheader := ()re running a fake PoW, simply return a 0 nonce immediatelys difficulty requirements.func (ethash *Ethash) Seal(chain , block *, stop chan struct{}) (*, error) {return nil}``` 該方法會(huì)去校驗(yàn)該區(qū)塊頭中的extra數(shù)據(jù)是不是比約定的參數(shù)最大值還大,如果超過,則返回錯(cuò)誤,其次會(huì)去判斷該區(qū)塊是不是一個(gè)uncle區(qū)塊,如果header的時(shí)間戳不符合規(guī)則則返回錯(cuò)誤,然后根據(jù)鏈的配置,header的時(shí)間戳以及上一個(gè)區(qū)塊計(jì)算中本次區(qū)塊期待的難度,如果header的難度和期待的不一致,或header的gasLimit比最大數(shù)字還大,或已用的gas超過gasLimit,或header的number減去上一個(gè)block的header的number不為1,則返回錯(cuò)誤.`seal`為true,則會(huì)去校驗(yàn)該區(qū)塊是否符合pow的工作量證明的要求(`verifySeal`方法),防止用戶在不同的鏈上,以及校驗(yàn)塊頭的額外數(shù)據(jù)字段是否符合DAO硬叉規(guī)則 uncle block:__eth允許曠工在挖到一個(gè)塊的同時(shí)包含一組uncle block列表,主要有兩個(gè)作用:__1. 由于網(wǎng)絡(luò)傳播的延遲原因,通過獎(jiǎng)勵(lì)那些由于不是鏈組成區(qū)塊部分而產(chǎn)生陳舊或孤立區(qū)塊的曠工,從而減少集權(quán)激勵(lì)2. 通過增加在主鏈上的工作量來增加鏈條的安全性(在工作中,少浪費(fèi)工作在陳舊的塊上)eth的pow核心代碼:```// CalcDifficulty is the difficulty adjustment algorith
點(diǎn)擊復(fù)制文檔內(nèi)容
外語相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1