nimbus-eth1/fluffy/network/history/content/content_deprecated.nim
Kim De Mey 833719a866
Remove usage of aliases for Hash32 such as BlockHash (#2707)
These create only confusion as if they are actual different types
and it is within their usage already clear what they are about
because of the name of the variable or the function.

They are also nowhere aliased like this in any of the Portal
specification.
2024-10-07 22:39:07 +02:00

72 lines
2.1 KiB
Nim

# fluffy
# Copyright (c) 2024 Status Research & Development GmbH
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
## File do be deleted when pruneDeprecatedAccumulatorRecords has been active
## for long enough that most users have upgraded and as a result cleaned up
## their database.
{.push raises: [].}
import
nimcrypto/[sha2, hash],
stint,
chronicles,
ssz_serialization,
../../../common/common_types,
../../../database/content_db,
../validation/historical_hashes_accumulator
type
ContentType = enum
blockHeader = 0x00
blockBody = 0x01
receipts = 0x02
epochRecordDeprecated = 0x03
BlockKey = object
blockHash: Hash32
EpochRecordKeyDeprecated = object
epochHash: Digest
ContentKey = object
case contentType: ContentType
of blockHeader:
blockHeaderKey: BlockKey
of blockBody:
blockBodyKey: BlockKey
of receipts:
receiptsKey: BlockKey
of epochRecordDeprecated:
epochRecordKeyDeprecated: EpochRecordKeyDeprecated
func encode(contentKey: ContentKey): ContentKeyByteList =
ContentKeyByteList.init(SSZ.encode(contentKey))
func toContentId(contentKey: ContentKeyByteList): ContentId =
let idHash = sha2.sha256.digest(contentKey.asSeq())
readUintBE[256](idHash.data)
proc pruneDeprecatedAccumulatorRecords*(
accumulator: FinishedHistoricalHashesAccumulator, contentDB: ContentDB
) =
info "Pruning deprecated accumulator records"
for i, hash in accumulator.historicalEpochs:
let
root = Digest(data: hash)
epochRecordKey = ContentKey(
contentType: epochRecordDeprecated,
epochRecordKeyDeprecated: EpochRecordKeyDeprecated(epochHash: root),
)
encodedKey = encode(epochRecordKey)
contentId = toContentId(encodedKey)
contentDB.del(contentId)
info "Pruning deprecated accumulator records finished"