Skip to content

Commit

Permalink
Merge pull request #279 from cerc-io/ian_updates
Browse files Browse the repository at this point in the history
rawdb helper functions
  • Loading branch information
i-norden authored Sep 29, 2022
2 parents 7fbb589 + 9f669f8 commit c9beb11
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions core/rawdb/accessors_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,23 @@ func ReadReceipts(db ethdb.Reader, hash common.Hash, number uint64, config *para
return receipts
}

// ReadStorageReceipts is a modification of ReadRawReceipts that skips a conversion to types.Receipt
// and returns the ReceipstForStorage instead
func ReadStorageReceipts(db ethdb.Reader, hash common.Hash, number uint64) []*types.ReceiptForStorage {
// Retrieve the flattened receipt slice
data := ReadReceiptsRLP(db, hash, number)
if len(data) == 0 {
return nil
}
// Convert the receipts from their storage form to their internal representation
var storageReceipts []*types.ReceiptForStorage
if err := rlp.DecodeBytes(data, &storageReceipts); err != nil {
log.Error("Invalid receipt array RLP", "hash", hash, "err", err)
return nil
}
return storageReceipts
}

// WriteReceipts stores all the transaction receipts belonging to a block.
func WriteReceipts(db ethdb.KeyValueWriter, hash common.Hash, number uint64, receipts types.Receipts) {
// Convert the receipts into their storage form and serialize them
Expand Down Expand Up @@ -817,6 +834,17 @@ func WriteAncientBlocks(db ethdb.AncientWriter, blocks []*types.Block, receipts
})
}

// WriteAncientBlock is a public wrapper of writeAncientBlock
func WriteAncientBlock(op ethdb.AncientWriteOp, block *types.Block, receipts types.Receipts, td *big.Int) error {
stReceipts := make([]*types.ReceiptForStorage, len(receipts))
// Convert receipts to storage format and sum up total difficulty.
stReceipts = stReceipts[:0]
for i, receipt := range receipts {
stReceipts[i] = (*types.ReceiptForStorage)(receipt)
}
return writeAncientBlock(op, block, block.Header(), stReceipts, td)
}

func writeAncientBlock(op ethdb.AncientWriteOp, block *types.Block, header *types.Header, receipts []*types.ReceiptForStorage, td *big.Int) error {
num := block.NumberU64()
if err := op.AppendRaw(chainFreezerHashTable, num, block.Hash().Bytes()); err != nil {
Expand Down

0 comments on commit c9beb11

Please sign in to comment.