sync committee topic names; borrow -> template/distinctbase (#2781)
This commit is contained in:
parent
df48409969
commit
89d9aa9240
|
@ -9,7 +9,7 @@
|
||||||
|
|
||||||
import
|
import
|
||||||
# Std lib
|
# Std lib
|
||||||
std/[typetraits, sequtils, os, algorithm, math, sets, strutils],
|
std/[typetraits, sequtils, os, algorithm, math, sets],
|
||||||
std/options as stdOptions,
|
std/options as stdOptions,
|
||||||
|
|
||||||
# Status libs
|
# Status libs
|
||||||
|
|
|
@ -430,6 +430,8 @@ type
|
||||||
|
|
||||||
SomeSomeSignedBeaconBlock* = SomeSignedBeaconBlock | phase0.SomeSignedBeaconBlock
|
SomeSomeSignedBeaconBlock* = SomeSignedBeaconBlock | phase0.SomeSignedBeaconBlock
|
||||||
|
|
||||||
|
SyncCommitteeIndex* = distinct uint8
|
||||||
|
|
||||||
# TODO when https://github.com/nim-lang/Nim/issues/14440 lands in Status's Nim,
|
# TODO when https://github.com/nim-lang/Nim/issues/14440 lands in Status's Nim,
|
||||||
# switch proc {.noSideEffect.} to func.
|
# switch proc {.noSideEffect.} to func.
|
||||||
when false:
|
when false:
|
||||||
|
@ -440,6 +442,8 @@ when false:
|
||||||
|
|
||||||
chronicles.formatIt BeaconBlock: it.shortLog
|
chronicles.formatIt BeaconBlock: it.shortLog
|
||||||
|
|
||||||
|
template asUInt8*(x: SyncCommitteeIndex): uint8 = uint8(x)
|
||||||
|
|
||||||
Json.useCustomSerialization(BeaconState.justification_bits):
|
Json.useCustomSerialization(BeaconState.justification_bits):
|
||||||
read:
|
read:
|
||||||
let s = reader.readValue(string)
|
let s = reader.readValue(string)
|
||||||
|
|
|
@ -678,10 +678,23 @@ func `[]`*[T](a: seq[T], b: ValidatorIndex): auto =
|
||||||
a[b.int]
|
a[b.int]
|
||||||
|
|
||||||
# `ValidatorIndex` Nim integration
|
# `ValidatorIndex` Nim integration
|
||||||
proc `==`*(x, y: ValidatorIndex) : bool {.borrow, noSideEffect.}
|
template `==`*(x, y: ValidatorIndex) : bool =
|
||||||
proc `<`*(x, y: ValidatorIndex) : bool {.borrow, noSideEffect.}
|
distinctBase(x) == distinctBase(y)
|
||||||
proc hash*(x: ValidatorIndex): Hash {.borrow, noSideEffect.}
|
|
||||||
func `$`*(x: ValidatorIndex): auto = $(distinctBase(x))
|
template `<`*(x, y: ValidatorIndex): bool =
|
||||||
|
distinctBase(x) < distinctBase(y)
|
||||||
|
|
||||||
|
template hash*(x: ValidatorIndex): Hash =
|
||||||
|
hash distinctBase(x)
|
||||||
|
|
||||||
|
template `$`*(x: ValidatorIndex): auto =
|
||||||
|
$ distinctBase(x)
|
||||||
|
|
||||||
|
template `==`*(x: uint64, y: ValidatorIndex): bool =
|
||||||
|
x == uint64(y)
|
||||||
|
|
||||||
|
template `==`*(x: ValidatorIndex, y: uint64): bool =
|
||||||
|
uint64(x) == y
|
||||||
|
|
||||||
# TODO Nim 1.4, but not Nim 1.2, defines a function by this name, which works
|
# TODO Nim 1.4, but not Nim 1.2, defines a function by this name, which works
|
||||||
# only on openArray[int]. They do the same thing, so either's fine, when both
|
# only on openArray[int]. They do the same thing, so either's fine, when both
|
||||||
|
@ -692,13 +705,23 @@ func toIntSet*[T](x: openArray[T]): IntSet =
|
||||||
for item in items(x):
|
for item in items(x):
|
||||||
result.incl(item.int)
|
result.incl(item.int)
|
||||||
|
|
||||||
proc `==`*(x, y: CommitteeIndex) : bool {.borrow, noSideEffect.}
|
template `==`*(x, y: CommitteeIndex): bool =
|
||||||
proc `<`*(x, y: CommitteeIndex) : bool {.borrow, noSideEffect.}
|
distinctBase(x) == distinctBase(y)
|
||||||
proc hash*(x: CommitteeIndex): Hash {.borrow, noSideEffect.}
|
|
||||||
func `$`*(x: CommitteeIndex): auto = $(distinctBase(x))
|
|
||||||
|
|
||||||
proc `==`*(x, y: SubnetId) : bool {.borrow, noSideEffect.}
|
template `<`*(x, y: CommitteeIndex): bool =
|
||||||
proc `$`*(x: SubnetId): string {.borrow, noSideEffect.}
|
distinctBase(x) < distinctBase(y)
|
||||||
|
|
||||||
|
template hash*(x: CommitteeIndex): Hash =
|
||||||
|
hash distinctBase(x)
|
||||||
|
|
||||||
|
template `$`*(x: CommitteeIndex): auto =
|
||||||
|
$ distinctBase(x)
|
||||||
|
|
||||||
|
template `==`*(x, y: SubnetId): bool =
|
||||||
|
distinctBase(x) == distinctBase(y)
|
||||||
|
|
||||||
|
template `$`*(x: SubnetId): string =
|
||||||
|
$ distinctBase(x)
|
||||||
|
|
||||||
func `as`*(d: DepositData, T: type DepositMessage): T =
|
func `as`*(d: DepositData, T: type DepositMessage): T =
|
||||||
T(pubkey: d.pubkey,
|
T(pubkey: d.pubkey,
|
||||||
|
@ -753,7 +776,7 @@ template newClone*[T](x: ref T not nil): ref T =
|
||||||
newClone(x[])
|
newClone(x[])
|
||||||
|
|
||||||
template lenu64*(x: untyped): untyped =
|
template lenu64*(x: untyped): untyped =
|
||||||
x.len.uint64
|
uint64(len(x))
|
||||||
|
|
||||||
func `$`*(v: ForkDigest | Version): string =
|
func `$`*(v: ForkDigest | Version): string =
|
||||||
toHex(array[4, byte](v))
|
toHex(array[4, byte](v))
|
||||||
|
|
|
@ -79,6 +79,17 @@ func getAttestationTopic*(forkDigest: ForkDigest,
|
||||||
## For subscribing and unsubscribing to/from a subnet.
|
## For subscribing and unsubscribing to/from a subnet.
|
||||||
eth2Prefix(forkDigest) & "beacon_attestation_" & $(subnetId) & "/ssz"
|
eth2Prefix(forkDigest) & "beacon_attestation_" & $(subnetId) & "/ssz"
|
||||||
|
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.8/specs/altair/p2p-interface.md#topics-and-messages
|
||||||
|
func getSyncCommitteeTopic*(forkDigest: ForkDigest,
|
||||||
|
committeeIdx: SyncCommitteeIndex): string =
|
||||||
|
## For subscribing and unsubscribing to/from a subnet.
|
||||||
|
eth2Prefix(forkDigest) & "sync_committee_" & $(committeeIdx.asUInt8) & "/ssz"
|
||||||
|
|
||||||
|
# https://github.com/ethereum/eth2.0-specs/blob/v1.1.0-alpha.8/specs/altair/p2p-interface.md#topics-and-messages
|
||||||
|
func getSyncCommitteeContributionAndProofTopic*(forkDigest: ForkDigest): string =
|
||||||
|
## For subscribing and unsubscribing to/from a subnet.
|
||||||
|
eth2Prefix(forkDigest) & "sync_committee_contribution_and_proof" & "/ssz"
|
||||||
|
|
||||||
func getENRForkID*(cfg: RuntimeConfig,
|
func getENRForkID*(cfg: RuntimeConfig,
|
||||||
epoch: Epoch,
|
epoch: Epoch,
|
||||||
genesis_validators_root: Eth2Digest): ENRForkID =
|
genesis_validators_root: Eth2Digest): ENRForkID =
|
||||||
|
|
|
@ -514,7 +514,7 @@ proc cmdValidatorPerf(conf: DbConf, cfg: RuntimeConfig) =
|
||||||
perf.first_slot_head_attester_when_first_slot_not_empty += 1
|
perf.first_slot_head_attester_when_first_slot_not_empty += 1
|
||||||
|
|
||||||
if s.is_previous_epoch_attester.isSome():
|
if s.is_previous_epoch_attester.isSome():
|
||||||
perf.delays.mGetOrPut(
|
perf.delays.mgetOrPut(
|
||||||
s.is_previous_epoch_attester.get().delay, 0'u64) += 1
|
s.is_previous_epoch_attester.get().delay, 0'u64) += 1
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -4,7 +4,7 @@ import
|
||||||
unittest2,
|
unittest2,
|
||||||
./testutil,
|
./testutil,
|
||||||
../beacon_chain/spec/network,
|
../beacon_chain/spec/network,
|
||||||
../beacon_chain/spec/datatypes/base,
|
../beacon_chain/spec/datatypes/[base, altair],
|
||||||
../beacon_chain/validators/attestation_aggregation
|
../beacon_chain/validators/attestation_aggregation
|
||||||
|
|
||||||
suite "Honest validator":
|
suite "Honest validator":
|
||||||
|
@ -17,6 +17,7 @@ suite "Honest validator":
|
||||||
getProposerSlashingsTopic(forkDigest) == "/eth2/00000000/proposer_slashing/ssz"
|
getProposerSlashingsTopic(forkDigest) == "/eth2/00000000/proposer_slashing/ssz"
|
||||||
getAttesterSlashingsTopic(forkDigest) == "/eth2/00000000/attester_slashing/ssz"
|
getAttesterSlashingsTopic(forkDigest) == "/eth2/00000000/attester_slashing/ssz"
|
||||||
getAggregateAndProofsTopic(forkDigest) == "/eth2/00000000/beacon_aggregate_and_proof/ssz"
|
getAggregateAndProofsTopic(forkDigest) == "/eth2/00000000/beacon_aggregate_and_proof/ssz"
|
||||||
|
getSyncCommitteeContributionAndProofTopic(forkDigest) == "/eth2/00000000/sync_committee_contribution_and_proof/ssz"
|
||||||
|
|
||||||
test "Mainnet attestation topics":
|
test "Mainnet attestation topics":
|
||||||
check:
|
check:
|
||||||
|
@ -60,6 +61,12 @@ suite "Honest validator":
|
||||||
"/eth2/00000000/beacon_attestation_62/ssz"
|
"/eth2/00000000/beacon_attestation_62/ssz"
|
||||||
getAttestationTopic(forkDigest, SubnetId(63)) ==
|
getAttestationTopic(forkDigest, SubnetId(63)) ==
|
||||||
"/eth2/00000000/beacon_attestation_63/ssz"
|
"/eth2/00000000/beacon_attestation_63/ssz"
|
||||||
|
getSyncCommitteeTopic(forkDigest, SyncCommitteeIndex(0)) ==
|
||||||
|
"/eth2/00000000/sync_committee_0/ssz"
|
||||||
|
getSyncCommitteeTopic(forkDigest, SyncCommitteeIndex(1)) ==
|
||||||
|
"/eth2/00000000/sync_committee_1/ssz"
|
||||||
|
getSyncCommitteeTopic(forkDigest, SyncCommitteeIndex(3)) ==
|
||||||
|
"/eth2/00000000/sync_committee_3/ssz"
|
||||||
|
|
||||||
test "is_aggregator":
|
test "is_aggregator":
|
||||||
check:
|
check:
|
||||||
|
|
Loading…
Reference in New Issue