Remove old header network code as this no longer exists in specs (#2596)

This commit is contained in:
Kim De Mey 2024-09-06 18:00:58 +02:00 committed by GitHub
parent 8a19118ddf
commit e919f57902
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 0 additions and 112 deletions

View File

@ -1,60 +0,0 @@
# Nimbus
# Copyright (c) 2022-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.
# https://github.com/ethereum/portal-network-specs/blob/master/header-gossip-network.md
{.push raises: [].}
import
std/options,
nimcrypto/[sha2, hash],
stint,
ssz_serialization,
../../common/common_types
export ssz_serialization, common_types, options, hash
type
# Header Gossip Content Keys
# https://github.com/ethereum/portal-network-specs/blob/master/header-gossip-network.md#content-keys
# But with Accumulator removed as per
# https://github.com/ethereum/portal-network-specs/issues/153
ContentType* = enum
newBlockHeader = 0x00
# TODO: remove or fix this temporary
# dummySelector per latest spec.
# This is temporary workaround
# to fool SSZ.isUnion
dummySelector = 0x01
NewBlockHeaderKey* = object
blockHash*: BlockHash
blockNumber*: UInt256
ContentKey* = object
case contentType*: ContentType
of newBlockHeader:
newBlockHeaderKey*: NewBlockHeaderKey
of dummySelector:
dummyField: uint64
func encode*(contentKey: ContentKey): ContentKeyByteList =
ContentKeyByteList.init(SSZ.encode(contentKey))
func decode*(contentKey: ContentKeyByteList): Option[ContentKey] =
try:
some(SSZ.decode(contentKey.asSeq(), ContentKey))
except SerializationError:
return none[ContentKey]()
func toContentId*(contentKey: ContentKeyByteList): ContentId =
# TODO: Should we try to parse the content key here for invalid ones?
let idHash = sha2.sha256.digest(contentKey.asSeq())
readUintBE[256](idHash.data)
func toContentId*(contentKey: ContentKey): ContentId =
toContentId(encode(contentKey))

View File

@ -14,5 +14,4 @@ import
./test_history_content_validation,
./test_history_block_proof_bellatrix,
./test_history_block_proof_capella,
./test_header_content,
./test_accumulator_root

View File

@ -1,51 +0,0 @@
# Nimbus
# Copyright (c) 2022-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.
{.used.}
{.push raises: [].}
import unittest2, stew/byteutils, ../../../network/header/header_content
suite "Header Gossip ContentKey Encodings":
test "BlockHeader":
# Input
const
blockHash = BlockHash.fromHex(
"0xd1c390624d3bd4e409a61a858e5dcc5517729a9170d014a6c96530d64dd8621d"
)
blockNumber = 2.stuint(256)
# Output
const
contentKeyHex =
"00d1c390624d3bd4e409a61a858e5dcc5517729a9170d014a6c96530d64dd8621d0200000000000000000000000000000000000000000000000000000000000000"
contentId =
"93053813395975896824800219097617621670658136800980011170166846009189305194644"
# or
contentIdHexBE =
"cdba9789eec7a1994ec7c033c46c2c94242da2c016051bf09240fd9a81589894"
let contentKey = ContentKey(
contentType: newBlockHeader,
newBlockHeaderKey:
NewBlockHeaderKey(blockHash: blockHash, blockNumber: blockNumber),
)
let encoded = encode(contentKey)
check encoded.asSeq.toHex == contentKeyHex
let decoded = decode(encoded)
check decoded.isSome()
let contentKeyDecoded = decoded.get()
check:
contentKeyDecoded.contentType == contentKey.contentType
contentKeyDecoded.newBlockHeaderKey == contentKey.newBlockHeaderKey
toContentId(contentKey) == parse(contentId, StUint[256], 10)
# In stint this does BE hex string
toContentId(contentKey).toHex() == contentIdHexBE