Mining
geth 如何驗證乙太坊礦工的獎勵?
在 ethash 共識的 Finalize() 函式中,礦工和叔叔的獎勵是直接由 state.AddBalance() 給出的。
我可以在哪裡驗證獎勵?估計有兩個地方
1)驗證標頭
2)驗證密封
我不確定獎勵儲存在上述其中之一的位置。
當節點從規範鏈導入一批塊時,它將執行塊驗證,其中一個驗證是驗證狀態根。獎勵/餘額包含在狀態根驗證中。
您可以在以下路徑中找到原始碼
…/go-ethereum/core/block_validator.go
func (v *BlockValidator) ValidateState(block, parent *types.Block, statedb *state.StateDB, receipts types.Receipts, usedGas uint64) error { header := block.Header() if block.GasUsed() != usedGas { return fmt.Errorf("invalid gas used (remote: %d local: %d)", block.GasUsed(), usedGas) } // Validate the received block's bloom with the one derived from the generated receipts. // For valid blocks this should always validate to true. rbloom := types.CreateBloom(receipts) if rbloom != header.Bloom { return fmt.Errorf("invalid bloom (remote: %x local: %x)", header.Bloom, rbloom) } // Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, R1]])) receiptSha := types.DeriveSha(receipts) if receiptSha != header.ReceiptHash { return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash, receiptSha) } // Validate the state root against the received state root and throw // an error if they don't match. if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root { return fmt.Errorf("invalid merkle root (remote: %x local: %x)", header.Root, root) } return nil }