挖矿区块的产生

Create_new_miner_block

自己构建“块”

//NOTE: this function is quite naughty due to chicken and egg problem
// we cannot calculate reward until we known blocksize ( exactly upto byte size )
// also note that we cannot calculate blocksize  until we know reward
// how we do it
// reward field is a varint, ( can be 8 bytes )
// so max deviation can be 8 bytes, due to reward
// so we do a bruterforce till the reward is obtained but lets try to KISS
// the top hash over which to do mining now ( it should already be in the chain)
// this is work in progress
// TODO we need to rework fees algorithm, to improve its quality and lower fees
  • Txs 交易,可以从交易池里面获得(先经过筛选,并且到 Miner Block 后,要从交易池里删除);
  • Tx_hashes 随着 Txs 而来;
  • 元数据,可以自己构建;
  • Coinbase,可以自己创建;
  • Tips 父块数据,可以从数据库里获取当前的值;
  • 其它数据(Proof),由 PoW 产生。

选择 Txs 还有一个策略,一个块里默认 10% 按手续费进行处理,其余 90% 随机处理。

这里主要做的检查工作是“双花检查”,其余它不做,在其它地方做。

除了 Block 对象外,还生成一个完整区块 Complete_Block 对象。

本过滤涉及到的一些特有解决方案、算法:

Mempool_List_TX_SortedInfo
Load_TIPS_ATOMIC
Calculate_Height_At_Tips
BuildReachabilityKeyImages
Mempool_Get_TX
Verify_Transaction_NonCoinbase_DoubleSpend_Check
Mempool_Delete_TX

tx_hash_list_sorted # 备选交易列表,重要临时变量
tx_hash_list_included # 被选中交易列表,重要临时变量
reachable_key_images # 有效密钥镜像,重要临时变量

Verify_Transaction_NonCoinbase_DoubleSpend_Check
Get_Current_Version_at_Height
Get_Ideal_Version_at_Height

Create_Miner_TX2
NewCryptoRandSource # nonce 后续是可以改变的

Create_new_block_template_mining

// returns a new block template ready for mining
// block template has the following format
// miner block header in hex  +
// miner tx in hex +
// 2 bytes ( inhex 4 bytes for number of tx )
// tx hashes that follow

Accept_new_block

接收到“块”

// accept work given by us
// we should verify that the transaction list supplied back by the miner exists in the mempool
// otherwise the miner is trying to attack the network

如何选择交易?

10% 基于手续费(先按顺序选择,填充区块容量大小的十分之一);

90% 基于随机(之后随机选择,填充区块容量剩余部分)。

多少个父块、叔块?

总数是 3 个。

results matching ""

    No results matching ""