diff --git a/fluffy/network/header/header_content.nim b/fluffy/network/header/header_content.nim deleted file mode 100644 index 2e41a926f..000000000 --- a/fluffy/network/header/header_content.nim +++ /dev/null @@ -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)) diff --git a/fluffy/tests/portal_spec_tests/mainnet/all_fluffy_portal_spec_tests.nim b/fluffy/tests/portal_spec_tests/mainnet/all_fluffy_portal_spec_tests.nim index 2b86c85bd..a7c31e146 100644 --- a/fluffy/tests/portal_spec_tests/mainnet/all_fluffy_portal_spec_tests.nim +++ b/fluffy/tests/portal_spec_tests/mainnet/all_fluffy_portal_spec_tests.nim @@ -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 diff --git a/fluffy/tests/portal_spec_tests/mainnet/test_header_content.nim b/fluffy/tests/portal_spec_tests/mainnet/test_header_content.nim deleted file mode 100644 index f39d9491d..000000000 --- a/fluffy/tests/portal_spec_tests/mainnet/test_header_content.nim +++ /dev/null @@ -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