allow `SyncCommitteePeriod` as libp2p params (#3481)

Adds a converter to allow using `SyncCommitteePeriod` as parameter for
libp2p messages (used in pre-release light client sync protocol).
This commit is contained in:
Etan Kissling 2022-03-11 13:04:08 +01:00 committed by GitHub
parent f589bf2119
commit 438aa17f7b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -1,5 +1,5 @@
# beacon_chain # beacon_chain
# Copyright (c) 2018-2021 Status Research & Development GmbH # Copyright (c) 2018-2022 Status Research & Development GmbH
# Licensed and distributed under either of # Licensed and distributed under either of
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * 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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
@ -17,7 +17,7 @@ export codec, base, typetraits
# Coding and decoding of SSZ to spec-specific types # Coding and decoding of SSZ to spec-specific types
template toSszType*(v: Slot|Epoch): auto = uint64(v) template toSszType*(v: Slot|Epoch|SyncCommitteePeriod): auto = uint64(v)
template toSszType*(v: BlsCurveType): auto = toRaw(v) template toSszType*(v: BlsCurveType): auto = toRaw(v)
template toSszType*(v: ForkDigest|GraffitiBytes): auto = distinctBase(v) template toSszType*(v: ForkDigest|GraffitiBytes): auto = distinctBase(v)
template toSszType*(v: Version): auto = distinctBase(v) template toSszType*(v: Version): auto = distinctBase(v)
@ -34,6 +34,9 @@ template fromSszBytes*(T: type Slot, bytes: openArray[byte]): T =
template fromSszBytes*(T: type Epoch, bytes: openArray[byte]): T = template fromSszBytes*(T: type Epoch, bytes: openArray[byte]): T =
T fromSszBytes(uint64, bytes) T fromSszBytes(uint64, bytes)
template fromSszBytes*(T: type SyncCommitteePeriod, bytes: openArray[byte]): T =
T fromSszBytes(uint64, bytes)
func fromSszBytes*(T: type ForkDigest, bytes: openArray[byte]): T {.raisesssz.} = func fromSszBytes*(T: type ForkDigest, bytes: openArray[byte]): T {.raisesssz.} =
if bytes.len != sizeof(result): if bytes.len != sizeof(result):
raiseIncorrectSize T raiseIncorrectSize T