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

正文內(nèi)容

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

2024-08-09 00:43本頁面
  

【正文】 top)// Create a runner and the multiple search threads it directsfound := make(chan *)threads := seed, err := (, ())()}}if threads == 0 {}threads = 0 // Allows disabling local mining without extra logic around local/remotevar pend i threads。(1)defer ()}(i, uint64(()))// Wait until sealing is terminated or a nonce is foundselect {// Outside abort, stop all miner threadscase result = found:close(abort)// Thread count was changed on user request, restart()}()t have to update hash rate on every nonce, so update after after 2^X noncesattempts++if (attempts % (1 15)) == 0 {(attempts)attempts = 0}// Compute the PoW value of this noncedigest, result := hashimotoFull(dataset, hash, nonce)if new().SetBytes(result).Cmp(target) = 0 {// Correct nonce found, create a new header with itheader = (header) = (nonce) = (digest)// Seal and return a block (if still needed)select {case found (header):(Ethash nonce found and reported, attempts, nonceseed, nonce, nonce)case abort:(Ethash nonce found but discarded, attempts, nonceseed, nonce, nonce)}return}nonce++}}}``` `target`是目標(biāo)新塊的難度,`hashimotoFull`方法計算出一個hash值,如果產(chǎn)生的`hash`值小于等于`target`的值,則hash難度符合要求,將符合要求的`header`寫入到`found channel`中,并返回,否則一直循環(huán)```// hashimotoFull aggregates data from the full dataset (using the full inmemory// dataset) in order to produce our final value for a particular header hash and// nonce.func hashimotoFull(dataset []uint32, hash []byte, nonce uint64) ([]byte, []byte) {lookup := func(index uint32) []uint32 {offset := index * hashWordsreturn dataset[offset : offset+hashWords]}return hashimoto(hash, nonce, uint64(len(dataset))*4, lookup)}``````// hashimoto aggregates data from the full dataset in order to produce our final// value for a particular header hash and nonce.func hashimoto(hash []byte, nonce uint64, size uint64, lookup func(index uint32) []uint32) ([]byte, []byte) {// Calculate the number of theoretical rows (we use one buffer nonetheless)rows := uint32(size / mixBytes)// Combine header+nonce into a 64 byte seedseed := make([]byte, 40)copy(seed, hash)(seed[32:], nonce)seed = (seed)seedHead := (seed)// Start the mix with replicated seedmix := make([]uint32, mixBytes/4)for i := 0。 i++ {mix[i] = (seed[i%16*4:])}// Mix in random dataset nodestemp := make([]uint32, len(mix))for i := 0。 i++ {parent := fnv(uint32(i)^seedHead, mix[i%len(mix)]) % rowsfor j := uint32(0)。 j++ {copy(temp[j*hashWords:], lookup(2*parent+j))}fnvHash(mix, temp)}// Compress mixfor i := 0。 i += 4 {mix[i/4] = fnv(fnv(fnv(mix[i], mix[i+1]), mix[i+2]), mix[i+3])}mix = mix[:len(mix)/4]digest := make([]byte, )for i, val := range mix {(digest[i*4:], val)}return digest, (append(seed, digest...))}``` 可以看到,該方法是不斷的進行sha256的hash運算,然后返回進行hash值難度的對比,如果hash的十六進制大小小于等于預(yù)定的難度,那么這個hash就是符合產(chǎn)塊要求的產(chǎn)生一個隨機seed,賦給nonce隨機數(shù),然后進行sha256的hash運算,如果算出的hash難度不符合目標(biāo)難度,則nonce+1,繼續(xù)運算()func (self *worker) wait() {for {mustCommitNewWork := truefor result := range {(amp。 result != nil {(Successfully sealed new block, number, (), hash, ()) amp。Miner{eth: eth,mux: mux,engine: engine,worker: newWorker(config, engine, {}, eth, mux),canStart: 1,}(NewCpuAgent((), engine))go ()return miner}()的邏輯可以看出,對于任何一個Ethereum網(wǎng)絡(luò)中的節(jié)點來說,挖掘一個新區(qū)塊和從其他節(jié)點下載、同步一個新區(qū)塊,根本是相互沖突的。首先是:func (self *Miner) Register(agent Agent) {if () {()}(agent)}func (self *worker) register(agent Agent) {()defer ()[agent] = struct{}{}()}該方法中將self的recv管道綁定在了agent的return管道然后是newWorker方法func newWorker(config *, engine , coinbase , eth Backend, mux *) *worker {worker := amp。re not miningif (amp。re mining, but nothing is being processed, wake on new transactionsif != nil amp。 == 0 {()}}// System stoppedcase ():returncase ():returncase ():return}}},并且是永久循環(huán),如果有錯誤事件發(fā)生,則終止,如果有新的交易事件,則執(zhí)行mitTransactions驗證提交交易到本地的trx判定池中,供下次出塊使用,也就是本地新挖出的塊,如果有挖出,則寫入塊數(shù)據(jù),并廣播一個chainHeadEvent事件,同時將該塊添加到待確認列表中,并且提交一個新的工作量,mitNewWork方法相當(dāng)于共識的第一個階段,它會組裝一個標(biāo)準(zhǔn)的塊,其他包含產(chǎn)出該塊需要的難度,然后將產(chǎn)出該塊的工作以及塊信息廣播給所有代理,開始挖礦,搶該塊的出塊權(quán)func (self *CpuAgent) mine(work *Work, stop chan struct{}) {if result, err := (, , stop)。Result{work, result}} else {if err != nil {(Block sealing failed, err, err)} nil}}該方法中開始進行塊的hash難度計算,如果返回的result結(jié)果不為空,說明挖礦成功,將結(jié)果寫入到returnCh通道中.如果不是組裝好帶有隨機數(shù)hash的,那么存儲塊將會返回錯誤,stat, err := (block, , )if err != nil {(Failed writing block to chain, err, err)continue}remote_agent 提供了一套RPC接口,可以實現(xiàn)遠程礦工進行采礦的功能。 eth共識算法分析,從本地節(jié)點挖到塊開始分析
點擊復(fù)制文檔內(nèi)容
外語相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1