Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to obtain the Bytom Genesis Block

2025-04-10 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to obtain the Bytom creation block". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to get the Bytom creation block".

Introduction of Genesis Block

The first block in the block chain is called the Genesis Block. It is the common ancestor of all blocks in the blockchain.

In the original chain, the creation block is hard-coded into the bytomd, and each original node starts from the same creation block, which ensures that the creation block will not be changed. Each node takes the Genesis block as the first block of the block chain, thus building a secure and credible block chain.

Get Genesis Block. / bytomcli get-block 0 {"bits": 2161727821137910500, "difficulty": "15154807", "hash": "a75483474799ea1aa6bb910a1a5025b4372bf20bef20f246a2c2dc5e12e8a053", "height": 0, "nonce": 9253507043297, "previous_block_hash": "000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 "transactions": [{"id": "158d7d7c6a8d2464725d508fafca76f0838d998eacaacb42ccc58cfb0c155352", "inputs": [{"amount": 0, "arbitrary": "496e666f726d6174696f6e20697320706f7765722e202d2d204a616e2f31312f323031332e20436f6d707574696e6720697320706f7765722e202d2d204170722f32342f323031382e", "asset_definition": {}, "asset_id": "0000000000000000000000000000000000000000000000000000000000000000", "type": "coinbase"}] "outputs": [{"address": "bm1q3jwsv0lhfmndnlag3kp6avpcq6pkd3xy8e5r88", "amount": 140700041250000000, "asset_definition": {}, "asset_id": "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", "control_program": "00148c9d063ff74ee6d9ffa88d83aeb038068366c4c4", "id": "e3325bf07c4385af4b60ad6ecc682ee0773f9b96e1cfbbae9f0f12b86b5f1093", "position": 0 "type": "control"}], "size": 151, "status_fail": false, "time_range": 0, "version": 1}], "version": 1}

Use the bytomcli client to query block information with a height of 0. We can see the above output.

Bits: target value. If the hash calculated during mining is less than or equal to the target value, the new block will be built successfully.

Difficulty: the difficulty value, the difficulty for the miner to find the next valid block. This parameter is not stored on the block chain, but is calculated by bits

Hash: current block hash

Height: current block height

Nonce: random number. Different nonce is used repeatedly to generate different hash values when mining.

Previous_block_hash: the parent block hash value of the current block

Size: the number of bytes in the current block

Timestamp: out of block time

Transaction_merkle_root: the root node of merkle tree in Genesis Block

Transactions: utxo transactions in the current block

Because the Genesis Block is the first block, the parent block of the Genesis Block, the previous_block_hash parameter, defaults to 000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

The timestamp timestamp is 1524549600, and the time is 2018-04-24 14:00:00, which is the time compared to the main network on the original chain.

Obtaining the status of block chain by source code analysis

* * protocol/protocol.go * *

Func NewChain (store Store, txPool * TxPool) (* Chain, error) {/ /. StoreStatus: = store.GetStoreStatus () if storeStatus = = nil {if err: = c.initChainStatus (); err! = nil {return nil, err} storeStatus = store.GetStoreStatus ()} / /.}

When we start the original chain node for the first time, store.GetStoreStatus will obtain the storage status from db. The process of obtaining the storage status is to query the data whose key is blockStore from LevelDB. If the query goes wrong, it is considered to be the first run of the original chain node, so you need to initialize the original main chain.

Initialize the main chain

* * protocol/protocol.go * *

Func (c * Chain) initChainStatus () error {genesisBlock: = config.GenesisBlock () txStatus: = bc.NewTransactionStatus () for I: = range genesisBlock.Transactions {txStatus.SetStatus (I, false)} if err: = c.store.SaveBlock (genesisBlock, txStatus) Err! = nil {return err} utxoView: = state.NewUtxoViewpoint () bcBlock: = types.MapBlock (genesisBlock) if err: = utxoView.ApplyBlock (bcBlock, txStatus) Err! = nil {return err} node, err: = state.NewBlockNode (& genesisBlock.BlockHeader, nil) if err! = nil {return err} return c.store.SaveChainStatus (node, utxoView)}

There are several steps to initialize the main chain:

Config.GenesisBlock () acquires the Genesis Block

Set the status of all transactions in the Genesis Block

Store Genesis blocks to LevelDB

State.NewUtxoViewpoint () is used for temporary small utxo state storage collections

Instantiate BlockNode,BlockNode to select the optimal chain as the main chain

Save the latest state of the main chain

Hard-coded Genesis Block

* * config/genesis.go * *

Func genesisTx () * types.Tx {contract, err: = hex.DecodeString ("00148c9d063ff74ee6d9ffa88d83aeb038068366c4c4") if err! = nil {log.Panicf ("fail on decode genesis tx output control program")} txData: = types.TxData {Version: 1, Inputs: [] * types.TxInput {types.NewCoinbaseInput ([] byte ("Information is power. -- Jan/11/2013. Computing is power. -- Apr/24/2018. "),}, Outputs: [] * types.TxOutput {types.NewTxOutput (* consensus.BTMAssetID, consensus.InitialBlockSubsidy, contract),} } return types.NewTx (txData)} func mainNetGenesisBlock () * types.Block {tx: = genesisTx () txStatus: = bc.NewTransactionStatus () txStatus.SetStatus (0, false) txStatusHash, err: = bc.TxStatusMerkleRoot (txStatus.VerifyStatus) if err! = nil {log.Panicf ("fail on calc genesis tx status merkle root")} merkleRoot Err: = bc.TxMerkleRoot ([] * bc.Tx {tx.Tx}) if err! = nil {log.Panicf ("fail on calc genesis tx merkel root")} block: = & types.Block {BlockHeader: types.BlockHeader {Version: 1, Height: 0 Nonce: 9253507043297, Timestamp: 1524549600, Bits: 2161727821137910632, BlockCommitment: types.BlockCommitment {TransactionsMerkleRoot: merkleRoot, TransactionStatusHash: txStatusHash,} }, Transactions: [] * types.Tx {tx},} return block}

MainNetGenesisBlock mainly operates as follows:

Generate a transaction in the Genesis block, which defaults to one transaction.

Set the transaction status in the block to false

Set the Genesis block as the root node of the merkle tree

Instantiate the Block block and return

The genesisTx function generates transactions in the creation block, which defaults to one transaction, which contains input input and output output.

Input input: there is a sentence in the input: "Information is power.-- Jan/11/2013. Computing is power.-- Apr/24/2018." This is to commemorate the spirit of Aaron Swartz.

Output output: we see the reward for the consensus.InitialBlockSubsidy creation block in the output. Total 140700041250000000/1e8 = 1407000412. That's 1.4 billion BTM coins.

Calculation is power

To quote something that is longer than the founder of the original chain:

April 24, our main online, information is power, 2013 Jaruary11; computing is power, 2018 April24. This sentence commemorates the spirit of Aaron Swartz that information is power can be regarded as an Internet manifesto dedicated to the free dissemination of information and the protection of citizens' privacy. Calculation is power, committed to the free trading of assets, the free flow of assets, so that the wealth of citizens can be protected, I think this is a very good memorial.

Thank you for your reading, the above is the content of "how to obtain the Bytom creation Block". After the study of this article, I believe you have a deeper understanding of how to obtain the Bytom creation Block, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report