move `EpochParticipationFlags, SyncCommittee` to `base`

Preparation for EIP-7495 SSZ `StableContainer` which can only contain
immutable types in their fields.
This commit is contained in:
Etan Kissling 2024-05-27 13:56:38 +02:00
parent ea58e9353f
commit 8910de65a4
No known key found for this signature in database
GPG Key ID: B21DA824C5A3D03D
2 changed files with 53 additions and 53 deletions

View File

@ -75,20 +75,6 @@ static: doAssert TIMELY_SOURCE_WEIGHT + TIMELY_TARGET_WEIGHT +
type
### New types
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/altair/beacon-chain.md#custom-types
ParticipationFlags* = uint8
EpochParticipationFlags* =
distinct List[ParticipationFlags, Limit VALIDATOR_REGISTRY_LIMIT]
## Not a HashList because the list sees significant updates every block
## effectively making the cost of clearing the cache higher than the typical
## gains
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/altair/beacon-chain.md#synccommittee
SyncCommittee* = object
pubkeys*: HashArray[Limit SYNC_COMMITTEE_SIZE, ValidatorPubKey]
aggregate_pubkey*: ValidatorPubKey
# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.2/specs/altair/validator.md#synccommitteemessage
SyncCommitteeMessage* = object
slot*: Slot
@ -536,45 +522,6 @@ template `[]`*(arr: array[SYNC_COMMITTEE_SIZE, auto] | seq;
makeLimitedU8(SyncSubcommitteeIndex, SYNC_COMMITTEE_SUBNET_COUNT)
makeLimitedU16(IndexInSyncCommittee, SYNC_COMMITTEE_SIZE)
template asList*(epochFlags: EpochParticipationFlags): untyped =
List[ParticipationFlags, Limit VALIDATOR_REGISTRY_LIMIT] epochFlags
template asList*(epochFlags: var EpochParticipationFlags): untyped =
let tmp = cast[ptr List[ParticipationFlags, Limit VALIDATOR_REGISTRY_LIMIT]](addr epochFlags)
tmp[]
template asSeq*(epochFlags: EpochParticipationFlags): untyped =
seq[ParticipationFlags] asList(epochFlags)
template asSeq*(epochFlags: var EpochParticipationFlags): untyped =
let tmp = cast[ptr seq[ParticipationFlags]](addr epochFlags)
tmp[]
template item*(epochFlags: EpochParticipationFlags, idx: ValidatorIndex): ParticipationFlags =
asList(epochFlags)[idx]
template `[]`*(epochFlags: EpochParticipationFlags, idx: ValidatorIndex|uint64|int): ParticipationFlags =
asList(epochFlags)[idx]
template `[]=`*(epochFlags: EpochParticipationFlags, idx: ValidatorIndex, flags: ParticipationFlags) =
asList(epochFlags)[idx] = flags
template add*(epochFlags: var EpochParticipationFlags, flags: ParticipationFlags): bool =
asList(epochFlags).add flags
template len*(epochFlags: EpochParticipationFlags): int =
asList(epochFlags).len
template low*(epochFlags: EpochParticipationFlags): int =
asSeq(epochFlags).low
template high*(epochFlags: EpochParticipationFlags): int =
asSeq(epochFlags).high
template assign*(v: var EpochParticipationFlags, src: EpochParticipationFlags) =
# TODO https://github.com/nim-lang/Nim/issues/21123
mixin assign
var tmp = cast[ptr seq[ParticipationFlags]](addr v)
assign(tmp[], distinctBase src)
func shortLog*(v: SomeBeaconBlock): auto =
(
slot: shortLog(v.slot),

View File

@ -465,6 +465,20 @@ type
source_index*: uint64
target_index*: uint64
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/altair/beacon-chain.md#custom-types
ParticipationFlags* = uint8
EpochParticipationFlags* =
distinct List[ParticipationFlags, Limit VALIDATOR_REGISTRY_LIMIT]
## Not a HashList because the list sees significant updates every block
## effectively making the cost of clearing the cache higher than the typical
## gains
# https://github.com/ethereum/consensus-specs/blob/v1.4.0/specs/altair/beacon-chain.md#synccommittee
SyncCommittee* = object
pubkeys*: HashArray[Limit SYNC_COMMITTEE_SIZE, ValidatorPubKey]
aggregate_pubkey*: ValidatorPubKey
# https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.6/specs/phase0/beacon-chain.md#beaconblockheader
BeaconBlockHeader* = object
slot*: Slot
@ -969,6 +983,45 @@ func shortLog*(v: SignedBLSToExecutionChange): auto =
chronicles.formatIt AttestationData: it.shortLog
chronicles.formatIt Checkpoint: it.shortLog
template asList*(epochFlags: EpochParticipationFlags): untyped =
List[ParticipationFlags, Limit VALIDATOR_REGISTRY_LIMIT] epochFlags
template asList*(epochFlags: var EpochParticipationFlags): untyped =
let tmp = cast[ptr List[ParticipationFlags, Limit VALIDATOR_REGISTRY_LIMIT]](addr epochFlags)
tmp[]
template asSeq*(epochFlags: EpochParticipationFlags): untyped =
seq[ParticipationFlags] asList(epochFlags)
template asSeq*(epochFlags: var EpochParticipationFlags): untyped =
let tmp = cast[ptr seq[ParticipationFlags]](addr epochFlags)
tmp[]
template item*(epochFlags: EpochParticipationFlags, idx: ValidatorIndex): ParticipationFlags =
asList(epochFlags)[idx]
template `[]`*(epochFlags: EpochParticipationFlags, idx: ValidatorIndex|uint64|int): ParticipationFlags =
asList(epochFlags)[idx]
template `[]=`*(epochFlags: EpochParticipationFlags, idx: ValidatorIndex, flags: ParticipationFlags) =
asList(epochFlags)[idx] = flags
template add*(epochFlags: var EpochParticipationFlags, flags: ParticipationFlags): bool =
asList(epochFlags).add flags
template len*(epochFlags: EpochParticipationFlags): int =
asList(epochFlags).len
template low*(epochFlags: EpochParticipationFlags): int =
asSeq(epochFlags).low
template high*(epochFlags: EpochParticipationFlags): int =
asSeq(epochFlags).high
template assign*(v: var EpochParticipationFlags, src: EpochParticipationFlags) =
# TODO https://github.com/nim-lang/Nim/issues/21123
mixin assign
var tmp = cast[ptr seq[ParticipationFlags]](addr v)
assign(tmp[], distinctBase src)
const
# http://facweb.cs.depaul.edu/sjost/it212/documents/ascii-pr.htm
PrintableAsciiChars = {' '..'~'}