Skip to content

core/rawdb/accessors_chain.go

Type MOD
Upstream Lines 943
Changed +10 -1

Append a TD placeholder in WriteAncientBlocks so the ChainFreezerDifficultyTable stays aligned with header/body tables

diff --git a/core/rawdb/accessors_chain.go b/core/rawdb/accessors_chain.go
index d8825b6b8..8bfc0c3a2 100644
--- a/core/rawdb/accessors_chain.go
+++ b/core/rawdb/accessors_chain.go
@@ -775,11 +775,15 @@ func writeAncientBlock(op ethdb.AncientWriteOp, block *types.Block, header *type
    if err := op.AppendRaw(ChainFreezerBALTable, num, nil); err != nil {
        return fmt.Errorf("can't append block %d bals: %v", num, err)
    }
+   // ETC: write nil TD placeholder to keep freezer tables in sync
+   if err := op.AppendRaw(ChainFreezerDifficultyTable, num, nil); err != nil {
+       return fmt.Errorf("can't append block %d td: %v", num, err)
+   }
    return nil
 }

 // WriteAncientHeaderChain writes the supplied headers along with nil block
-// bodies and receipts into the ancient store. It's supposed to be used for
+// bodies, receipts and TD into the ancient store. It's supposed to be used for
 // storing chain segment before the chain cutoff.
 func WriteAncientHeaderChain(db ethdb.AncientWriter, headers []*types.Header) (int64, error) {
    return db.ModifyAncients(func(op ethdb.AncientWriteOp) error {
@@ -804,6 +808,9 @@ func WriteAncientHeaderChain(db ethdb.AncientWriter, headers []*types.Header) (i
            if err := op.AppendRaw(ChainFreezerBALTable, num, nil); err != nil {
                return fmt.Errorf("can't append block %d bals: %v", num, err)
            }
+           if err := op.AppendRaw(ChainFreezerDifficultyTable, num, nil); err != nil {
+               return fmt.Errorf("can't append block %d td: %v", num, err)
+           }
        }
        return nil
    })
@@ -815,6 +822,7 @@ func DeleteBlock(db ethdb.KeyValueWriter, hash common.Hash, number uint64) {
    DeleteHeader(db, hash, number)
    DeleteBody(db, hash, number)
    DeleteAccessList(db, hash, number)
+   DeleteTd(db, hash, number) // ETC: delete total difficulty
 }

 // DeleteBlockWithoutNumber removes all block data associated with a hash, except
@@ -824,6 +832,7 @@ func DeleteBlockWithoutNumber(db ethdb.KeyValueWriter, hash common.Hash, number
    deleteHeaderWithoutNumber(db, hash, number)
    DeleteBody(db, hash, number)
    DeleteAccessList(db, hash, number)
+   DeleteTd(db, hash, number) // ETC: delete total difficulty
 }

 const badBlockToKeep = 10

← Back to Total Difficulty (TD)