Skip to content

WriteAncientBlocksPoW

Source (upstream v1.17.3) Current
File core/rawdb/accessors_chain.go accessors_chain_pow.go
Symbol WriteAncientBlocks WriteAncientBlocksPoW
Ref v1.17.3 etc/v1.17.3-full-node

Based on upstream v1.17.3 WriteAncientBlocks; adds td *big.Int param and TD accumulation per block.

Diff — vs upstream v1.17.3 (modified in-place)

--- a/core/rawdb/accessors_chain.go
+++ b/core/rawdb/accessors_chain_pow.go
@@ -1,9 +1,12 @@
-// WriteAncientBlocks writes entire block data into ancient store and returns the total written size.
-func WriteAncientBlocks(db ethdb.AncientWriter, blocks []*types.Block, receipts []rlp.RawValue) (int64, error) {
+// WriteAncientBlocksPoW writes entire block data into ancient store and returns the total written size.
+// td is the total difficulty of the FIRST block in the slice (including its own difficulty).
+func WriteAncientBlocksPoW(db ethdb.AncientWriter, blocks []*types.Block, receipts []rlp.RawValue, td *big.Int) (int64, error) {
+   tdSum := new(big.Int).Sub(td, blocks[0].Difficulty())
    return db.ModifyAncients(func(op ethdb.AncientWriteOp) error {
        for i, block := range blocks {
            header := block.Header()
-           if err := writeAncientBlock(op, block, header, receipts[i]); err != nil {
+           tdSum.Add(tdSum, header.Difficulty)
+           if err := writeAncientBlockPoW(op, block, header, receipts[i], tdSum); err != nil {
                return err
            }
        }
core-geth validation — +5 -19 | | | |---|---| | File | [`accessors_chain.go`](https://github.com/etclabscore/core-geth/blob/v1.12.20/core/rawdb/accessors_chain.go) | | Symbol | `WriteAncientBlocks` | | Ref | `v1.12.20` |
--- a/core-geth/core/rawdb/accessors_chain.go
+++ b/etc/core/rawdb/accessors_chain_pow.go
@@ -1,26 +1,12 @@
-// WriteAncientBlocks writes entire block data into ancient store and returns the total written size.
-func WriteAncientBlocks(db ethdb.AncientWriter, blocks []*types.Block, receipts []types.Receipts, td *big.Int) (int64, error) {
-   var (
-       tdSum      = new(big.Int).Set(td)
-       stReceipts []*types.ReceiptForStorage
-   )
-   // TODO
-   // --- Maybe:
-   // Check if the 'db' is a remote store, then we can use the original AppendAncients method and return.
-   // Possibly checking for order issues; if out of order, then Truncate and then AppendAncients.
-   // ---
+// WriteAncientBlocksPoW writes entire block data into ancient store and returns the total written size.
+// td is the total difficulty of the FIRST block in the slice (including its own difficulty).
+func WriteAncientBlocksPoW(db ethdb.AncientWriter, blocks []*types.Block, receipts []rlp.RawValue, td *big.Int) (int64, error) {
+   tdSum := new(big.Int).Sub(td, blocks[0].Difficulty())
    return db.ModifyAncients(func(op ethdb.AncientWriteOp) error {
        for i, block := range blocks {
-           // Convert receipts to storage format and sum up total difficulty.
-           stReceipts = stReceipts[:0]
-           for _, receipt := range receipts[i] {
-               stReceipts = append(stReceipts, (*types.ReceiptForStorage)(receipt))
-           }
            header := block.Header()
-           if i > 0 {
                tdSum.Add(tdSum, header.Difficulty)
-           }
-           if err := writeAncientBlock(op, block, header, stReceipts, tdSum); err != nil {
+           if err := writeAncientBlockPoW(op, block, header, receipts[i], tdSum); err != nil {
                return err
            }
        }

← Total Difficulty (TD)