Ether Square Source code (): POA block generation mechanism

Source: Internet
Author: User
Tags prepare

Directory

1 noun Introduction

2 POA block data structure

3 new zone block generation cycle

4 new zone block generation priority


1 noun Introduction


Node: Ordinary etheric square node, no block generation rights.

Miner: The etheric square node with the right of block generation

Committee: The collection of all miners


2 POA block data structure

PoA consensus, the block data and pow some differences, mainly reflected in the header structure:



3 new zone block generation cycle


Miners start building blocks in three cases:


When the program starts, executes the Newworker method to initialize the worker object, calls the Commitnewwork method, and begins to generate the new chunk. (Miner/worker.go)

The network receives a new block broadcast by other miners, the block validation is effectively inserted into the block chain, generates a chainheadevent log, the Worker object's update process detects the log, calls the Commitnewwork method, and begins to generate a new chunk. (Miner/worker.go)

The miners themselves build new chunks into the chain, call the Commitnewwork method, and start generating new chunks.

(Wait coprocessor, Miner/worker.go)

When the new block is generated, the miner will carry out a certain delay and delay algorithm:


High-priority miners:

Header. Time = new (big. INT). ADD (parent. Time, new (big. INT). SetUint64 (C.config.period))

Delay: = time. Unix (header. Time.int64 (), 0). Sub (time. Now ())

(Prepare and seal two method definitions in consensus/clique/clique.go)


Other miners:

Header. Time = new (big. INT). ADD (parent. Time, new (big. INT). SetUint64 (C.config.period))

Delay: = time. Unix (header. Time.int64 (), 0). Sub (time. Now ())

Wiggle: = time. Duration (Len (SNAP). Signers)/2+1) * Wiggletime

Delay = time. Duration (Rand. Int63n (Int64 (Wiggle))

(Prepare and seal two method definitions in consensus/clique/clique.go)



4 new zone block generation priority


In the POA consensus algorithm, each miner in the Committee would continue to generate new blocks, and for the same number of blocks, the miners would have different priority when they generated the block.


Priority calculation Method:

Number: block numbers for the blocks to be generated

A collection of committees recorded in the Signers:snapshot and arranged in ascending order according to the miners ' addresses.

Offset: The position of the miner in the signers collection

If: (number% UInt64 (signers)) = = UInt64 (offset), then the highest priority, header. difficulty = 2; otherwise, header. Difficulty = 1


This article is organized by the core chain team.

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.