Core data structure analysis
1 | struct { |
The timestamp in the structure is the timestamp of the block packed, and the previous is the previous The id of a block, transaction_mroot represents the merkle root of all transactions, and action_root represents The merkle root of the action.
num_from_id find blocknum through blockid.
1 span>
|
struct signed_block_header : block_header { |
struct signed_block_header :
This structure inherits block_header, contains producer_signature inside, and provides the signature of the producer
struct block_header_state:
Includes basic block information, blockid, blocknum, and signed_block_header signature header information.
struct block_header_with_merkle_path:
Include block_header of type block_header_state and merkle_path composed of id sequence. The blockid in this merkle_path needs to be linked one by one without interruption. In addition, the last blockid needs to point to the previous one of block_header id.
struct action_receipt :
Receipts for an action, including recipients, summary information, authorization order, acceptance order, encoding order, etc.
Using UML diagrams to indicate the relationship between the above categories:
Core api analysis
1 |
uint32_t block_header::num_from_id(const block_id_type& id) |
Take out the hash value of id, and then invert the upper 32 bits to obtain blocknum
1 |
checksum256 block_header::id() const { |
When calculating the id, set itself The 256hash value goes to the high 32 bits, inverted with the high 32 bits of blocknum() obtained before, and added to obtain the id number.
1< br>2 |
digest_type block_header::digest() const { |
To get the summary, it means to perform 256hash to get the summary.
1< br>2 | template <typename span> T>
|
Sha256 is a hash function based on a universal type template encapsulated by our eocs team. First, package the value, and then The hash result is stored in the variable hash, and this result is returned as the digest.
1< br>2 |
void block_header_state::validate() const { |
This function first calculates the digest, and then removes the producer signature information and block signature of the header according to the digest key value.
Next, determine whether the id of the header matches your id.
1< br>2 |
producer_key block_header_state::get_scheduled_producer(block_timestamp_type t)const { |
This function gets polled producers, producer_repetitions is the number of repeated producers, index is divided by this number to get the number of polls, and then the corresponding producer is taken out according to the index in the polling table.
1 |
uint32_t block_header_state ::calc_dpos_last_irreversible()const { |
This function calculates the last irreversible block num, first defines the sequence of blocknums, and then according to producer_to_last_implied_irb (containing irreversible blocks Producer map), put the corresponding block nums into the blocknums sequence, and then divide by three according to the sequence size -1 to get the block index, which is the final irreversible block number.
End here
Original text: Big column Design and implementation of eocs cross-chain contract block data structure