1.流程圖
存儲(chǔ)Receipt
2.
構(gòu)建key
r + number(區(qū)塊高度) + hash(區(qū)塊hash)
go-ethereum/core/rawdb/schema.go
//key:r + number + hash
// blockReceiptsKey = blockReceiptsPrefix + num (uint64 big endian) + hash
func blockReceiptsKey(number uint64, hash common.Hash) []byte {
return append(append(blockReceiptsPrefix, encodeBlockNumber(number)...), hash.Bytes()...)
}
存入db
-
將Receipt類型轉(zhuǎn)換為ReceiptForStorage
-
將storageReceipts進(jìn)行RLP Encode
-
將RLP Encode后的數(shù)據(jù)存入db
go-ethereum/core/rawdb/accessors_chain.go
// WriteReceipts stores all the transaction receipts belonging to a block.
func WriteReceipts(db DatabaseWriter, hash common.Hash, number uint64, receipts types.Receipts) {
// Convert the receipts into their storage form and serialize them
//Receipt
storageReceipts := make([]*types.ReceiptForStorage, len(receipts))
for i, receipt := range receipts {
storageReceipts[i] = (*types.ReceiptForStorage)(receipt)
}
bytes, err := rlp.EncodeToBytes(storageReceipts)
if err != nil {
log.Crit("Failed to encode block receipts", "err", err)
}
// Store the flattened receipt slice
if err := db.Put(blockReceiptsKey(number, hash), bytes); err != nil {
log.Crit("Failed to store block receipts", "err", err)
}
}