Skip to content

Commit

Permalink
Migrate DeleteHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
JukLee0ira committed Jan 3, 2025
1 parent a8a0fef commit 773f838
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
10 changes: 2 additions & 8 deletions core/database_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,12 +372,6 @@ func WriteBlockReceipts(db ethdb.KeyValueWriter, hash common.Hash, number uint64
return nil
}

// DeleteHeader removes all block header data associated with a hash.
func DeleteHeader(db rawdb.DatabaseDeleter, hash common.Hash, number uint64) {
db.Delete(append(blockHashPrefix, hash.Bytes()...))
db.Delete(append(append(headerPrefix, encodeBlockNumber(number)...), hash.Bytes()...))
}

// DeleteBody removes all block body data associated with a hash.
func DeleteBody(db rawdb.DatabaseDeleter, hash common.Hash, number uint64) {
db.Delete(append(append(bodyPrefix, encodeBlockNumber(number)...), hash.Bytes()...))
Expand All @@ -389,9 +383,9 @@ func DeleteTd(db rawdb.DatabaseDeleter, hash common.Hash, number uint64) {
}

// DeleteBlock removes all block data associated with a hash.
func DeleteBlock(db rawdb.DatabaseDeleter, hash common.Hash, number uint64) {
func DeleteBlock(db ethdb.KeyValueWriter, hash common.Hash, number uint64) {
DeleteBlockReceipts(db, hash, number)
DeleteHeader(db, hash, number)
rawdb.DeleteHeader(db, hash, number)
DeleteBody(db, hash, number)
DeleteTd(db, hash, number)
}
Expand Down
4 changes: 2 additions & 2 deletions core/database_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func TestHeaderStorage(t *testing.T) {
}
}
// Delete the header and verify the execution
DeleteHeader(db, header.Hash(), header.Number.Uint64())
rawdb.DeleteHeader(db, header.Hash(), header.Number.Uint64())
if entry := GetHeader(db, header.Hash(), header.Number.Uint64()); entry != nil {
t.Fatalf("Deleted header returned: %v", entry)
}
Expand Down Expand Up @@ -163,7 +163,7 @@ func TestPartialBlockStorage(t *testing.T) {
if entry := GetBlock(db, block.Hash(), block.NumberU64()); entry != nil {
t.Fatalf("Non existent block returned: %v", entry)
}
DeleteHeader(db, block.Hash(), block.NumberU64())
rawdb.DeleteHeader(db, block.Hash(), block.NumberU64())

// Store a body and check that it's not recognized as a block
rawdb.WriteBody(db, block.Hash(), block.NumberU64(), block.Body())
Expand Down

0 comments on commit 773f838

Please sign in to comment.