mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-23 13:00:34 +00:00
clean up sync subcommittee handling
* `SyncCommitteeIndex` -> `SyncSubcommitteeIndex` * `syncCommitteePeriod` -> `sync_committee_period` (spec spelling) * tighten period comparisons * fix assert when validating committee message with non-altair state in REST api
This commit is contained in:
parent
bf6ad41d7d
commit
9cf32c3748
@ -1018,8 +1018,8 @@ proc pruneBlocksDAG(dag: ChainDAGRef) =
|
||||
dagPruneDur = Moment.now() - startTick
|
||||
|
||||
iterator syncSubcommittee*(
|
||||
syncCommittee: openarray[ValidatorPubKey],
|
||||
committeeIdx: SyncCommitteeIndex): ValidatorPubKey =
|
||||
syncCommittee: openArray[ValidatorPubKey],
|
||||
committeeIdx: SyncSubcommitteeIndex): ValidatorPubKey =
|
||||
var
|
||||
i = committeeIdx.asInt * SYNC_SUBCOMMITTEE_SIZE
|
||||
onePastEndIdx = min(syncCommittee.len, i + SYNC_SUBCOMMITTEE_SIZE)
|
||||
@ -1029,8 +1029,8 @@ iterator syncSubcommittee*(
|
||||
inc i
|
||||
|
||||
iterator syncSubcommitteePairs*(
|
||||
syncCommittee: openarray[ValidatorIndex],
|
||||
committeeIdx: SyncCommitteeIndex): tuple[validatorIdx: ValidatorIndex,
|
||||
syncCommittee: openArray[ValidatorIndex],
|
||||
committeeIdx: SyncSubcommitteeIndex): tuple[validatorIdx: ValidatorIndex,
|
||||
committeeIdx: int] =
|
||||
var
|
||||
i = committeeIdx.asInt * SYNC_SUBCOMMITTEE_SIZE
|
||||
@ -1040,37 +1040,26 @@ iterator syncSubcommitteePairs*(
|
||||
yield (syncCommittee[i], i)
|
||||
inc i
|
||||
|
||||
func syncCommitteeParticipants*(dagParam: ChainDAGRef,
|
||||
slotParam: Slot): seq[ValidatorPubKey] =
|
||||
# TODO:
|
||||
# Use view types in Nim 1.6
|
||||
# Right now, the compiler is not able to handle turning this into a
|
||||
# template and returning an openarray
|
||||
let
|
||||
dag = dagParam
|
||||
slot = slotParam
|
||||
|
||||
func syncCommitteeParticipants*(dag: ChainDAGRef,
|
||||
slot: Slot): seq[ValidatorPubKey] =
|
||||
withState(dag.headState.data):
|
||||
when stateFork >= BeaconStateFork.Altair:
|
||||
let
|
||||
headSlot = state.data.slot
|
||||
headCommitteePeriod = syncCommitteePeriod(headSlot)
|
||||
periodStart = syncCommitteePeriodStartSlot(headCommitteePeriod)
|
||||
nextPeriodStart = periodStart + SLOTS_PER_SYNC_COMMITTEE_PERIOD
|
||||
period = sync_committee_period(slot)
|
||||
curPeriod = sync_committee_period(state.data.slot)
|
||||
|
||||
if slot >= nextPeriodStart:
|
||||
@(state.data.next_sync_committee.pubkeys.data)
|
||||
elif slot >= periodStart:
|
||||
if period == curPeriod:
|
||||
@(state.data.current_sync_committee.pubkeys.data)
|
||||
else:
|
||||
@[]
|
||||
elif period == curPeriod + 1:
|
||||
@(state.data.current_sync_committee.pubkeys.data)
|
||||
else: @[]
|
||||
else:
|
||||
@[]
|
||||
|
||||
func getSubcommitteePositionsAux(
|
||||
dag: ChainDAGRef,
|
||||
syncCommittee: openarray[ValidatorPubKey],
|
||||
committeeIdx: SyncCommitteeIndex,
|
||||
committeeIdx: SyncSubcommitteeIndex,
|
||||
validatorIdx: uint64): seq[uint64] =
|
||||
# TODO Can we avoid the key conversions by getting a compressed key
|
||||
# out of ImmutableValidatorData2? If we had this, we can define
|
||||
@ -1086,42 +1075,35 @@ func getSubcommitteePositionsAux(
|
||||
|
||||
func getSubcommitteePositions*(dag: ChainDAGRef,
|
||||
slot: Slot,
|
||||
committeeIdx: SyncCommitteeIndex,
|
||||
committeeIdx: SyncSubcommitteeIndex,
|
||||
validatorIdx: uint64): seq[uint64] =
|
||||
withState(dag.headState.data):
|
||||
when stateFork >= BeaconStateFork.Altair:
|
||||
let
|
||||
headSlot = state.data.slot
|
||||
headCommitteePeriod = syncCommitteePeriod(headSlot)
|
||||
periodStart = syncCommitteePeriodStartSlot(headCommitteePeriod)
|
||||
nextPeriodStart = periodStart + SLOTS_PER_SYNC_COMMITTEE_PERIOD
|
||||
period = sync_committee_period(slot)
|
||||
curPeriod = sync_committee_period(state.data.slot)
|
||||
|
||||
template search(syncCommittee: openarray[ValidatorPubKey]): seq[uint64] =
|
||||
dag.getSubcommitteePositionsAux(syncCommittee, committeeIdx, validatorIdx)
|
||||
|
||||
if slot < periodStart:
|
||||
@[]
|
||||
elif slot >= nextPeriodStart:
|
||||
search(state.data.next_sync_committee.pubkeys.data)
|
||||
else:
|
||||
if period == curPeriod:
|
||||
search(state.data.current_sync_committee.pubkeys.data)
|
||||
elif period == curPeriod + 1:
|
||||
search(state.data.current_sync_committee.pubkeys.data)
|
||||
else: @[]
|
||||
else:
|
||||
@[]
|
||||
|
||||
template syncCommitteeParticipants*(
|
||||
dag: ChainDAGRef,
|
||||
slot: Slot,
|
||||
committeeIdx: SyncCommitteeIndex): seq[ValidatorPubKey] =
|
||||
let
|
||||
startIdx = committeeIdx.asInt * SYNC_SUBCOMMITTEE_SIZE
|
||||
onePastEndIdx = startIdx + SYNC_SUBCOMMITTEE_SIZE
|
||||
# TODO Nim is not happy with returning an openarray here
|
||||
@(toOpenArray(dag.syncCommitteeParticipants(slot), startIdx, onePastEndIdx - 1))
|
||||
committeeIdx: SyncSubcommitteeIndex): seq[ValidatorPubKey] =
|
||||
toSeq(syncSubcommittee(dag.syncCommitteeParticipants(slot), committeeIdx))
|
||||
|
||||
iterator syncCommitteeParticipants*(
|
||||
dag: ChainDAGRef,
|
||||
slot: Slot,
|
||||
committeeIdx: SyncCommitteeIndex,
|
||||
committeeIdx: SyncSubcommitteeIndex,
|
||||
aggregationBits: SyncCommitteeAggregationBits): ValidatorPubKey =
|
||||
for pos, valIdx in pairs(dag.syncCommitteeParticipants(slot, committeeIdx)):
|
||||
if aggregationBits[pos]:
|
||||
|
@ -24,11 +24,11 @@ type
|
||||
SyncCommitteeMsgKey* = object
|
||||
originator*: ValidatorIndex
|
||||
slot*: Slot
|
||||
committeeIdx*: SyncCommitteeIndex
|
||||
committeeIdx*: SyncSubcommitteeIndex
|
||||
|
||||
TrustedSyncCommitteeMsg* = object
|
||||
slot*: Slot
|
||||
committeeIdx*: SyncCommitteeIndex
|
||||
committeeIdx*: SyncSubcommitteeIndex
|
||||
positionInCommittee*: uint64
|
||||
signature*: CookedSig
|
||||
|
||||
@ -91,7 +91,7 @@ func addSyncCommitteeMsg*(
|
||||
slot: Slot,
|
||||
blockRoot: Eth2Digest,
|
||||
signature: CookedSig,
|
||||
committeeIdx: SyncCommitteeIndex,
|
||||
committeeIdx: SyncSubcommitteeIndex,
|
||||
positionInCommittee: uint64) =
|
||||
pool.syncMessages.mgetOrPut(blockRoot, @[]).add TrustedSyncCommitteeMsg(
|
||||
slot: slot,
|
||||
@ -100,7 +100,7 @@ func addSyncCommitteeMsg*(
|
||||
signature: signature)
|
||||
|
||||
func computeAggregateSig(votes: seq[TrustedSyncCommitteeMsg],
|
||||
committeeIdx: SyncCommitteeIndex,
|
||||
committeeIdx: SyncSubcommitteeIndex,
|
||||
contribution: var SyncCommitteeContribution): bool =
|
||||
var
|
||||
aggregateSig {.noInit.}: AggregateSignature
|
||||
@ -127,7 +127,7 @@ func produceContribution*(
|
||||
pool: SyncCommitteeMsgPool,
|
||||
slot: Slot,
|
||||
headRoot: Eth2Digest,
|
||||
committeeIdx: SyncCommitteeIndex,
|
||||
committeeIdx: SyncSubcommitteeIndex,
|
||||
outContribution: var SyncCommitteeContribution): bool =
|
||||
if headRoot in pool.syncMessages:
|
||||
outContribution.slot = slot
|
||||
|
@ -393,7 +393,7 @@ proc voluntaryExitValidator*(
|
||||
proc syncCommitteeMsgValidator*(
|
||||
self: ref Eth2Processor,
|
||||
syncCommitteeMsg: SyncCommitteeMessage,
|
||||
committeeIdx: SyncCommitteeIndex,
|
||||
committeeIdx: SyncSubcommitteeIndex,
|
||||
checkSignature: bool = true): ValidationResult =
|
||||
logScope:
|
||||
syncCommitteeMsg = shortLog(syncCommitteeMsg)
|
||||
|
@ -755,7 +755,7 @@ proc validateSyncCommitteeMessage*(
|
||||
dag: ChainDAGRef,
|
||||
syncCommitteeMsgPool: ref SyncCommitteeMsgPool,
|
||||
msg: SyncCommitteeMessage,
|
||||
syncCommitteeIdx: SyncCommitteeIndex,
|
||||
syncCommitteeIdx: SyncSubcommitteeIndex,
|
||||
wallTime: BeaconTime,
|
||||
checkSignature: bool):
|
||||
Result[void, (ValidationResult, cstring)] =
|
||||
|
@ -1083,7 +1083,7 @@ proc getLowSubnets(node: Eth2Node, epoch: Epoch):
|
||||
# We start looking one epoch before the transition in order to allow
|
||||
# some time for the gossip meshes to get healthy:
|
||||
if epoch + 1 >= node.cfg.ALTAIR_FORK_EPOCH:
|
||||
findLowSubnets(getSyncCommitteeTopic, SyncCommitteeIndex, SYNC_COMMITTEE_SUBNET_COUNT)
|
||||
findLowSubnets(getSyncCommitteeTopic, SyncSubcommitteeIndex, SYNC_COMMITTEE_SUBNET_COUNT)
|
||||
else:
|
||||
default(BitArray[SYNC_COMMITTEE_SUBNET_COUNT])
|
||||
)
|
||||
@ -2186,7 +2186,7 @@ proc broadcastBeaconBlock*(node: Eth2Node, forked: ForkedSignedBeaconBlock) =
|
||||
withBlck(forked): node.broadcastBeaconBlock(blck)
|
||||
|
||||
proc broadcastSyncCommitteeMessage*(
|
||||
node: Eth2Node, msg: SyncCommitteeMessage, committeeIdx: SyncCommitteeIndex) =
|
||||
node: Eth2Node, msg: SyncCommitteeMessage, committeeIdx: SyncSubcommitteeIndex) =
|
||||
let topic = getSyncCommitteeTopic(node.forkDigests.altair, committeeIdx)
|
||||
node.broadcast(topic, msg)
|
||||
|
||||
|
@ -326,13 +326,11 @@ func syncCommitteeParticipants*(forkedState: ForkedHashedBeaconState,
|
||||
withState(forkedState):
|
||||
when stateFork >= BeaconStateFork.Altair:
|
||||
let
|
||||
headSlot = state.data.slot
|
||||
epochPeriod = syncCommitteePeriod(epoch.compute_start_slot_at_epoch())
|
||||
currentPeriod = syncCommitteePeriod(headSlot)
|
||||
nextPeriod = currentPeriod + 1'u64
|
||||
if epochPeriod == currentPeriod:
|
||||
epochPeriod = sync_committee_period(epoch)
|
||||
curPeriod = sync_committee_period(state.data.slot)
|
||||
if epochPeriod == curPeriod:
|
||||
ok(@(state.data.current_sync_committee.pubkeys.data))
|
||||
elif epochPeriod == nextPeriod:
|
||||
elif epochPeriod == curPeriod + 1:
|
||||
ok(@(state.data.next_sync_committee.pubkeys.data))
|
||||
else:
|
||||
err("Epoch is outside the sync committee period of the state")
|
||||
|
@ -426,34 +426,34 @@ type
|
||||
SomeBeaconBlock* = BeaconBlock | SigVerifiedBeaconBlock | TrustedBeaconBlock
|
||||
SomeBeaconBlockBody* = BeaconBlockBody | SigVerifiedBeaconBlockBody | TrustedBeaconBlockBody
|
||||
|
||||
SyncCommitteeIndex* = distinct uint8
|
||||
SyncSubcommitteeIndex* = distinct uint8
|
||||
|
||||
chronicles.formatIt BeaconBlock: it.shortLog
|
||||
chronicles.formatIt SyncCommitteeIndex: uint8(it)
|
||||
chronicles.formatIt SyncSubcommitteeIndex: uint8(it)
|
||||
|
||||
template asInt*(x: SyncCommitteeIndex): int = int(x)
|
||||
template asUInt8*(x: SyncCommitteeIndex): uint8 = uint8(x)
|
||||
template asUInt64*(x: SyncCommitteeIndex): uint64 = uint64(x)
|
||||
template asInt*(x: SyncSubcommitteeIndex): int = int(x)
|
||||
template asUInt8*(x: SyncSubcommitteeIndex): uint8 = uint8(x)
|
||||
template asUInt64*(x: SyncSubcommitteeIndex): uint64 = uint64(x)
|
||||
|
||||
template `[]`*(a: auto; i: SyncCommitteeIndex): auto = a[i.asInt]
|
||||
template `[]`*(a: auto; i: SyncSubcommitteeIndex): auto = a[i.asInt]
|
||||
|
||||
template `==`*(x, y: SyncCommitteeIndex): bool =
|
||||
template `==`*(x, y: SyncSubcommitteeIndex): bool =
|
||||
distinctBase(x) == distinctBase(y)
|
||||
|
||||
iterator allSyncCommittees*: SyncCommitteeIndex =
|
||||
iterator allSyncCommittees*: SyncSubcommitteeIndex =
|
||||
for committeeIdx in 0 ..< SYNC_COMMITTEE_SUBNET_COUNT:
|
||||
yield SyncCommitteeIndex(committeeIdx)
|
||||
yield SyncSubcommitteeIndex(committeeIdx)
|
||||
|
||||
template validateSyncCommitteeIndexOr*(
|
||||
networkValParam: uint64,
|
||||
elseBody: untyped): SyncCommitteeIndex =
|
||||
elseBody: untyped): SyncSubcommitteeIndex =
|
||||
let networkVal = networkValParam
|
||||
if networkVal < SYNC_COMMITTEE_SUBNET_COUNT:
|
||||
SyncCommitteeIndex(networkVal)
|
||||
SyncSubcommitteeIndex(networkVal)
|
||||
else:
|
||||
elseBody
|
||||
|
||||
template asUInt8*(x: SyncCommitteeIndex): uint8 = uint8(x)
|
||||
template asUInt8*(x: SyncSubcommitteeIndex): uint8 = uint8(x)
|
||||
|
||||
Json.useCustomSerialization(BeaconState.justification_bits):
|
||||
read:
|
||||
|
@ -50,7 +50,7 @@ type
|
||||
phase0.SignedBeaconBlock |
|
||||
altair.SignedBeaconBlock |
|
||||
SignedVoluntaryExit |
|
||||
SyncCommitteeIndex
|
||||
SyncSubcommitteeIndex
|
||||
|
||||
EncodeArrays* =
|
||||
seq[ValidatorIndex] |
|
||||
@ -867,19 +867,19 @@ proc writeValue*(writer: var JsonWriter[RestJson], value: ForkedBeaconState) {.
|
||||
writer.writeField("data", value.mergeData)
|
||||
writer.endRecord()
|
||||
|
||||
# SyncCommitteeIndex
|
||||
# SyncSubcommitteeIndex
|
||||
proc writeValue*(writer: var JsonWriter[RestJson],
|
||||
value: SyncCommitteeIndex) {.
|
||||
value: SyncSubcommitteeIndex) {.
|
||||
raises: [IOError, Defect].} =
|
||||
writeValue(writer, Base10.toString(uint8(value)))
|
||||
|
||||
proc readValue*(reader: var JsonReader[RestJson],
|
||||
value: var SyncCommitteeIndex) {.
|
||||
value: var SyncSubcommitteeIndex) {.
|
||||
raises: [IOError, SerializationError, Defect].} =
|
||||
let res = Base10.decode(uint8, reader.readValue(string))
|
||||
if res.isOk():
|
||||
if res.get() < SYNC_COMMITTEE_SUBNET_COUNT:
|
||||
value = SyncCommitteeIndex(res.get())
|
||||
value = SyncSubcommitteeIndex(res.get())
|
||||
else:
|
||||
reader.raiseUnexpectedValue("Sync sub-committee index out of rage")
|
||||
else:
|
||||
@ -982,7 +982,7 @@ proc decodeBytes*[T: SszDecodeTypes](t: typedesc[T], value: openarray[byte],
|
||||
proc encodeString*(value: string): RestResult[string] =
|
||||
ok(value)
|
||||
|
||||
proc encodeString*(value: Epoch|Slot|CommitteeIndex|SyncCommitteeIndex): RestResult[string] =
|
||||
proc encodeString*(value: Epoch|Slot|CommitteeIndex|SyncSubcommitteeIndex): RestResult[string] =
|
||||
ok(Base10.toString(uint64(value)))
|
||||
|
||||
proc encodeString*(value: ValidatorSig): RestResult[string] =
|
||||
@ -1220,8 +1220,8 @@ proc decodeString*(t: typedesc[CommitteeIndex],
|
||||
let res = ? Base10.decode(uint64, value)
|
||||
ok(CommitteeIndex(res))
|
||||
|
||||
proc decodeString*(t: typedesc[SyncCommitteeIndex],
|
||||
value: string): Result[SyncCommitteeIndex, cstring] =
|
||||
proc decodeString*(t: typedesc[SyncSubcommitteeIndex],
|
||||
value: string): Result[SyncSubcommitteeIndex, cstring] =
|
||||
let res = ? Base10.decode(uint8, value)
|
||||
if res.get < SYNC_COMMITTEE_SUBNET_COUNT:
|
||||
ok(CommitteeIndex(res))
|
||||
|
@ -105,7 +105,7 @@ type
|
||||
RestSyncCommitteeDuty* = object
|
||||
pubkey*: ValidatorPubKey
|
||||
validator_index*: ValidatorIndex
|
||||
validator_sync_committee_indices*: seq[SyncCommitteeIndex]
|
||||
validator_sync_committee_indices*: seq[SyncSubcommitteeIndex]
|
||||
|
||||
RestSyncCommitteeMessage* = object
|
||||
slot*: Slot
|
||||
@ -138,7 +138,7 @@ type
|
||||
|
||||
RestSyncCommitteeSubscription* = object
|
||||
validator_index*: ValidatorIndex
|
||||
sync_committee_indices*: seq[SyncCommitteeIndex]
|
||||
sync_committee_indices*: seq[SyncSubcommitteeIndex]
|
||||
until_epoch*: Epoch
|
||||
|
||||
RestBeaconStatesFinalityCheckpoints* = object
|
||||
|
@ -75,7 +75,7 @@ proc prepareSyncCommitteeSubnets*(body: seq[RestSyncCommitteeSubscription]): Res
|
||||
## https://ethereum.github.io/beacon-APIs/#/Validator/prepareSyncCommitteeSubnets
|
||||
|
||||
proc produceSyncCommitteeContribution*(slot: Slot,
|
||||
subcommittee_index: SyncCommitteeIndex,
|
||||
subcommittee_index: SyncSubcommitteeIndex,
|
||||
beacon_block_root: Eth2Digest): RestPlainResponse {.
|
||||
rest, endpoint: "/eth/v1/validator/sync_committee_contribution",
|
||||
meth: MethodGet.}
|
||||
|
@ -352,18 +352,13 @@ func build_proof*(anchor: object, leaf_index: uint64,
|
||||
doAssert proof.len == log2trunc(leaf_index)
|
||||
build_proof_impl(anchor, leaf_index, proof)
|
||||
|
||||
const SLOTS_PER_SYNC_COMMITTEE_PERIOD* =
|
||||
EPOCHS_PER_SYNC_COMMITTEE_PERIOD * SLOTS_PER_EPOCH
|
||||
|
||||
template syncCommitteePeriod*(epoch: Epoch): uint64 =
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.3/specs/altair/validator.md#sync-committee
|
||||
template sync_committee_period*(epoch: Epoch): uint64 =
|
||||
epoch div EPOCHS_PER_SYNC_COMMITTEE_PERIOD
|
||||
|
||||
template syncCommitteePeriod*(slot: Slot): uint64 =
|
||||
template sync_committee_period*(slot: Slot): uint64 =
|
||||
epoch(slot) div EPOCHS_PER_SYNC_COMMITTEE_PERIOD
|
||||
|
||||
func syncCommitteePeriodStartSlot*(period: uint64): Slot =
|
||||
Slot(period * EPOCHS_PER_SYNC_COMMITTEE_PERIOD * SLOTS_PER_EPOCH)
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.0.1/specs/phase0/beacon-chain.md#compute_start_slot_at_epoch
|
||||
func compute_start_slot_at_epoch*(epoch: Epoch): Slot =
|
||||
## Return the start slot of ``epoch``.
|
||||
|
@ -81,7 +81,7 @@ func getAttestationTopic*(forkDigest: ForkDigest,
|
||||
|
||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.0-alpha.8/specs/altair/p2p-interface.md#topics-and-messages
|
||||
func getSyncCommitteeTopic*(forkDigest: ForkDigest,
|
||||
committeeIdx: SyncCommitteeIndex): string =
|
||||
committeeIdx: SyncSubcommitteeIndex): string =
|
||||
## For subscribing and unsubscribing to/from a subnet.
|
||||
eth2Prefix(forkDigest) & "sync_committee_" & $(committeeIdx.asUInt8) & "/ssz"
|
||||
|
||||
|
@ -206,7 +206,7 @@ proc sendAttestation*(
|
||||
|
||||
proc sendSyncCommitteeMessage*(
|
||||
node: BeaconNode, msg: SyncCommitteeMessage,
|
||||
committeeIdx: SyncCommitteeIndex,
|
||||
committeeIdx: SyncSubcommitteeIndex,
|
||||
checkSignature: bool): Future[SendResult] {.async.} =
|
||||
# Validate sync committee message before sending it via gossip
|
||||
# validation will also register the message with the sync committee
|
||||
@ -228,43 +228,36 @@ proc sendSyncCommitteeMessage*(
|
||||
proc sendSyncCommitteeMessages*(node: BeaconNode,
|
||||
msgs: seq[SyncCommitteeMessage]
|
||||
): Future[seq[SendResult]] {.async.} =
|
||||
let validators = getStateField(node.dag.headState.data, validators)
|
||||
var statuses = newSeq[Option[SendResult]](len(msgs))
|
||||
return withState(node.dag.headState.data):
|
||||
when stateFork >= BeaconStateFork.Altair:
|
||||
var statuses = newSeq[Option[SendResult]](len(msgs))
|
||||
|
||||
let ranges =
|
||||
block:
|
||||
let
|
||||
headSlot = getStateField(node.dag.headState.data, slot)
|
||||
headCommitteePeriod = syncCommitteePeriod(headSlot)
|
||||
currentStart = syncCommitteePeriodStartSlot(headCommitteePeriod)
|
||||
currentFinish = currentStart + SLOTS_PER_SYNC_COMMITTEE_PERIOD
|
||||
nextStart = currentFinish
|
||||
nextFinish = nextStart + SLOTS_PER_SYNC_COMMITTEE_PERIOD
|
||||
(curStart: Slot(currentStart), curFinish: Slot(currentFinish),
|
||||
nxtStart: Slot(nextStart), nxtFinish: Slot(nextFinish))
|
||||
curPeriod = sync_committee_period(state.data.slot)
|
||||
nextPeriod = curPeriod + 1
|
||||
|
||||
let (keysCur, keysNxt) =
|
||||
block:
|
||||
var resCur: Table[ValidatorPubKey, int]
|
||||
var resNxt: Table[ValidatorPubKey, int]
|
||||
for index, msg in msgs.pairs():
|
||||
if msg.validator_index < lenu64(validators):
|
||||
if (msg.slot >= ranges.curStart) and (msg.slot < ranges.curFinish):
|
||||
resCur[validators[msg.validator_index].pubkey] = index
|
||||
elif (msg.slot >= ranges.nxtStart) and (msg.slot < ranges.nxtFinish):
|
||||
resNxt[validators[msg.validator_index].pubkey] = index
|
||||
else:
|
||||
statuses[index] =
|
||||
some(SendResult.err("Message's slot out of state's head range"))
|
||||
else:
|
||||
statuses[index] = some(SendResult.err("Incorrect validator's index"))
|
||||
if (len(resCur) == 0) and (len(resNxt) == 0):
|
||||
return statuses.mapIt(it.get())
|
||||
(resCur, resNxt)
|
||||
let (keysCur, keysNxt) =
|
||||
block:
|
||||
var resCur: Table[ValidatorPubKey, int]
|
||||
var resNxt: Table[ValidatorPubKey, int]
|
||||
|
||||
let (pending, indices) =
|
||||
withState(node.dag.headState.data):
|
||||
when stateFork >= BeaconStateFork.Altair:
|
||||
for index, msg in msgs.pairs():
|
||||
if msg.validator_index < lenu64(state.data.validators):
|
||||
let msgPeriod = sync_committee_period(msg.slot)
|
||||
if msgPeriod == curPeriod:
|
||||
resCur[state.data.validators.asSeq[msg.validator_index].pubkey] = index
|
||||
elif msgPeriod == nextPeriod:
|
||||
resNxt[state.data.validators.asSeq[msg.validator_index].pubkey] = index
|
||||
else:
|
||||
statuses[index] =
|
||||
some(SendResult.err("Message's slot out of state's head range"))
|
||||
else:
|
||||
statuses[index] = some(SendResult.err("Incorrect validator's index"))
|
||||
if (len(resCur) == 0) and (len(resNxt) == 0):
|
||||
return statuses.mapIt(it.get())
|
||||
(resCur, resNxt)
|
||||
|
||||
let (pending, indices) = block:
|
||||
var resFutures: seq[Future[SendResult]]
|
||||
var resIndices: seq[int]
|
||||
for committeeIdx in allSyncCommittees():
|
||||
@ -274,7 +267,7 @@ proc sendSyncCommitteeMessages*(node: BeaconNode,
|
||||
if index >= 0:
|
||||
resIndices.add(index)
|
||||
resFutures.add(node.sendSyncCommitteeMessage(msgs[index],
|
||||
committeeIdx, true))
|
||||
committeeIdx, true))
|
||||
for committeeIdx in allSyncCommittees():
|
||||
for valKey in syncSubcommittee(
|
||||
state.data.next_sync_committee.pubkeys.data, committeeIdx):
|
||||
@ -282,29 +275,25 @@ proc sendSyncCommitteeMessages*(node: BeaconNode,
|
||||
if index >= 0:
|
||||
resIndices.add(index)
|
||||
resFutures.add(node.sendSyncCommitteeMessage(msgs[index],
|
||||
committeeIdx, true))
|
||||
committeeIdx, true))
|
||||
(resFutures, resIndices)
|
||||
else:
|
||||
raiseAssert "Sync committee not available in Phase0"
|
||||
|
||||
await allFutures(pending)
|
||||
await allFutures(pending)
|
||||
|
||||
for index, future in pending.pairs():
|
||||
if future.done():
|
||||
let fres = future.read()
|
||||
if fres.isErr():
|
||||
statuses[indices[index]] = some(SendResult.err(fres.error()))
|
||||
else:
|
||||
statuses[indices[index]] = some(SendResult.ok())
|
||||
elif future.failed() or future.cancelled():
|
||||
let exc = future.readError()
|
||||
debug "Unexpected failure while sending committee message",
|
||||
message = msgs[indices[index]], error = $exc.msg
|
||||
statuses[indices[index]] = some(SendResult.err(
|
||||
"Unexpected failure while sending committee message"))
|
||||
for index, future in pending.pairs():
|
||||
if future.done():
|
||||
let fres = future.read()
|
||||
if fres.isErr():
|
||||
statuses[indices[index]] = some(SendResult.err(fres.error()))
|
||||
else:
|
||||
statuses[indices[index]] = some(SendResult.ok())
|
||||
elif future.failed() or future.cancelled():
|
||||
let exc = future.readError()
|
||||
debug "Unexpected failure while sending committee message",
|
||||
message = msgs[indices[index]], error = $exc.msg
|
||||
statuses[indices[index]] = some(SendResult.err(
|
||||
"Unexpected failure while sending committee message"))
|
||||
|
||||
let results =
|
||||
block:
|
||||
var res: seq[SendResult]
|
||||
for item in statuses:
|
||||
if item.isSome():
|
||||
@ -312,7 +301,11 @@ proc sendSyncCommitteeMessages*(node: BeaconNode,
|
||||
else:
|
||||
res.add(SendResult.err("Message validator not in sync committee"))
|
||||
res
|
||||
return results
|
||||
else:
|
||||
var res: seq[SendResult]
|
||||
for _ in msgs:
|
||||
res.add(SendResult.err("Waiting for altair fork"))
|
||||
res
|
||||
|
||||
proc sendSyncCommitteeContribution*(
|
||||
node: BeaconNode,
|
||||
@ -647,7 +640,7 @@ proc handleAttestations(node: BeaconNode, head: BlockRef, slot: Slot) =
|
||||
proc createAndSendSyncCommitteeMessage(node: BeaconNode,
|
||||
slot: Slot,
|
||||
validator: AttachedValidator,
|
||||
committeeIdx: SyncCommitteeIndex,
|
||||
committeeIdx: SyncSubcommitteeIndex,
|
||||
head: BlockRef) {.async.} =
|
||||
try:
|
||||
let
|
||||
@ -732,7 +725,7 @@ proc handleSyncCommitteeContributions(node: BeaconNode,
|
||||
type
|
||||
AggregatorCandidate = object
|
||||
validator: AttachedValidator
|
||||
committeeIdx: SyncCommitteeIndex
|
||||
committeeIdx: SyncSubcommitteeIndex
|
||||
|
||||
var candidateAggregators: seq[AggregatorCandidate]
|
||||
var selectionProofs: seq[Future[ValidatorSig]]
|
||||
|
@ -142,7 +142,7 @@ cli do(slots = SLOTS_PER_EPOCH * 6,
|
||||
proc handleSyncCommitteeActions(slot: Slot) =
|
||||
type
|
||||
Aggregator = object
|
||||
committeeIdx: SyncCommitteeIndex
|
||||
committeeIdx: SyncSubcommitteeIndex
|
||||
validatorIdx: int
|
||||
selectionProof: ValidatorSig
|
||||
|
||||
|
@ -208,7 +208,7 @@ suite "Gossip validation - Extra": # Not based on preset config
|
||||
dag
|
||||
state = newClone(dag.headState.data.altairData)
|
||||
|
||||
syncCommitteeIdx = 0.SyncCommitteeIndex
|
||||
syncCommitteeIdx = 0.SyncSubcommitteeIndex
|
||||
syncCommittee = @(dag.syncCommitteeParticipants(state[].data.slot))
|
||||
subcommittee = toSeq(syncCommittee.syncSubcommittee(syncCommitteeIdx))
|
||||
|
||||
|
@ -60,11 +60,11 @@ suite "Honest validator":
|
||||
"/eth2/00000000/beacon_attestation_62/ssz"
|
||||
getAttestationTopic(forkDigest, SubnetId(63)) ==
|
||||
"/eth2/00000000/beacon_attestation_63/ssz"
|
||||
getSyncCommitteeTopic(forkDigest, SyncCommitteeIndex(0)) ==
|
||||
getSyncCommitteeTopic(forkDigest, SyncSubcommitteeIndex(0)) ==
|
||||
"/eth2/00000000/sync_committee_0/ssz"
|
||||
getSyncCommitteeTopic(forkDigest, SyncCommitteeIndex(1)) ==
|
||||
getSyncCommitteeTopic(forkDigest, SyncSubcommitteeIndex(1)) ==
|
||||
"/eth2/00000000/sync_committee_1/ssz"
|
||||
getSyncCommitteeTopic(forkDigest, SyncCommitteeIndex(3)) ==
|
||||
getSyncCommitteeTopic(forkDigest, SyncSubcommitteeIndex(3)) ==
|
||||
"/eth2/00000000/sync_committee_3/ssz"
|
||||
|
||||
test "is_aggregator":
|
||||
|
@ -24,7 +24,7 @@ suite "Sync committee pool":
|
||||
let success = pool.produceContribution(
|
||||
Slot(1),
|
||||
headRoot,
|
||||
SyncCommitteeIndex(0),
|
||||
SyncSubcommitteeIndex(0),
|
||||
outContribution)
|
||||
|
||||
check(success == false)
|
||||
@ -59,8 +59,8 @@ suite "Sync committee pool":
|
||||
root2Slot = Slot(101)
|
||||
root3Slot = Slot(101)
|
||||
|
||||
subcommittee1 = SyncCommitteeIndex(0)
|
||||
subcommittee2 = SyncCommitteeIndex(1)
|
||||
subcommittee1 = SyncSubcommitteeIndex(0)
|
||||
subcommittee2 = SyncSubcommitteeIndex(1)
|
||||
|
||||
sig1 = blsSign(privkey1, sync_committee_msg_signing_root(
|
||||
fork, root1Slot.epoch, genesisValidatorsRoot, root1).data)
|
||||
|
Loading…
x
Reference in New Issue
Block a user