proc -> func, mainly in spec/state transition and adjecent modules (#3405)
This commit is contained in:
parent
87e98b9e54
commit
79761c78a4
|
@ -894,7 +894,7 @@ func parseCmdArg*(T: type Checkpoint, input: TaintedString): T
|
||||||
func completeCmdArg*(T: type Checkpoint, input: TaintedString): seq[string] =
|
func completeCmdArg*(T: type Checkpoint, input: TaintedString): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
|
|
||||||
proc isPrintable(rune: Rune): bool =
|
func isPrintable(rune: Rune): bool =
|
||||||
# This can be eventually replaced by the `unicodeplus` package, but a single
|
# This can be eventually replaced by the `unicodeplus` package, but a single
|
||||||
# proc does not justify the extra dependencies at the moment:
|
# proc does not justify the extra dependencies at the moment:
|
||||||
# https://github.com/nitely/nim-unicodeplus
|
# https://github.com/nitely/nim-unicodeplus
|
||||||
|
@ -924,7 +924,7 @@ proc parseCmdArg*(T: type enr.Record, p: TaintedString): T
|
||||||
if not fromURI(result, p):
|
if not fromURI(result, p):
|
||||||
raise newException(ConfigurationError, "Invalid ENR")
|
raise newException(ConfigurationError, "Invalid ENR")
|
||||||
|
|
||||||
proc completeCmdArg*(T: type enr.Record, val: TaintedString): seq[string] =
|
func completeCmdArg*(T: type enr.Record, val: TaintedString): seq[string] =
|
||||||
return @[]
|
return @[]
|
||||||
|
|
||||||
func validatorsDir*(config: AnyConf): string =
|
func validatorsDir*(config: AnyConf): string =
|
||||||
|
|
|
@ -205,7 +205,7 @@ proc updateCurrent(pool: var AttestationPool, wallSlot: Slot) =
|
||||||
|
|
||||||
pool.startingSlot = newStartingSlot
|
pool.startingSlot = newStartingSlot
|
||||||
|
|
||||||
proc oneIndex(bits: CommitteeValidatorsBits): Option[int] =
|
func oneIndex(bits: CommitteeValidatorsBits): Option[int] =
|
||||||
# Find the index of the set bit, iff one bit is set
|
# Find the index of the set bit, iff one bit is set
|
||||||
var res = none(int)
|
var res = none(int)
|
||||||
for idx in 0..<bits.len():
|
for idx in 0..<bits.len():
|
||||||
|
@ -482,7 +482,7 @@ func init(
|
||||||
update_attestation_pool_cache(
|
update_attestation_pool_cache(
|
||||||
cur_epoch, state.data.current_epoch_participation)
|
cur_epoch, state.data.current_epoch_participation)
|
||||||
|
|
||||||
proc score(
|
func score(
|
||||||
attCache: var AttestationCache, data: AttestationData,
|
attCache: var AttestationCache, data: AttestationData,
|
||||||
aggregation_bits: CommitteeValidatorsBits): int =
|
aggregation_bits: CommitteeValidatorsBits): int =
|
||||||
# The score of an attestation is loosely based on how many new votes it brings
|
# The score of an attestation is loosely based on how many new votes it brings
|
||||||
|
@ -681,7 +681,7 @@ func getAggregatedAttestation*(pool: var AttestationPool,
|
||||||
|
|
||||||
none(Attestation)
|
none(Attestation)
|
||||||
|
|
||||||
proc getAggregatedAttestation*(pool: var AttestationPool,
|
func getAggregatedAttestation*(pool: var AttestationPool,
|
||||||
slot: Slot,
|
slot: Slot,
|
||||||
index: CommitteeIndex): Option[Attestation] =
|
index: CommitteeIndex): Option[Attestation] =
|
||||||
## Select the attestation that has the most votes going for it in the given
|
## Select the attestation that has the most votes going for it in the given
|
||||||
|
|
|
@ -843,7 +843,7 @@ func stateCheckpoint*(bs: BlockSlot): BlockSlot =
|
||||||
template forkAtEpoch*(dag: ChainDAGRef, epoch: Epoch): Fork =
|
template forkAtEpoch*(dag: ChainDAGRef, epoch: Epoch): Fork =
|
||||||
forkAtEpoch(dag.cfg, epoch)
|
forkAtEpoch(dag.cfg, epoch)
|
||||||
|
|
||||||
proc forkDigestAtEpoch*(dag: ChainDAGRef, epoch: Epoch): ForkDigest =
|
func forkDigestAtEpoch*(dag: ChainDAGRef, epoch: Epoch): ForkDigest =
|
||||||
case dag.cfg.stateForkAtEpoch(epoch)
|
case dag.cfg.stateForkAtEpoch(epoch)
|
||||||
of BeaconStateFork.Bellatrix: dag.forkDigests.bellatrix
|
of BeaconStateFork.Bellatrix: dag.forkDigests.bellatrix
|
||||||
of BeaconStateFork.Altair: dag.forkDigests.altair
|
of BeaconStateFork.Altair: dag.forkDigests.altair
|
||||||
|
|
|
@ -55,7 +55,7 @@ type
|
||||||
dag*: ChainDAGRef
|
dag*: ChainDAGRef
|
||||||
onVoluntaryExitReceived*: OnVoluntaryExitCallback
|
onVoluntaryExitReceived*: OnVoluntaryExitCallback
|
||||||
|
|
||||||
proc init*(T: type ExitPool, dag: ChainDAGRef,
|
func init*(T: type ExitPool, dag: ChainDAGRef,
|
||||||
onVoluntaryExit: OnVoluntaryExitCallback = nil): T =
|
onVoluntaryExit: OnVoluntaryExitCallback = nil): T =
|
||||||
## Initialize an ExitPool from the dag `headState`
|
## Initialize an ExitPool from the dag `headState`
|
||||||
T(
|
T(
|
||||||
|
|
|
@ -47,7 +47,7 @@ func compute_deltas(
|
||||||
logScope:
|
logScope:
|
||||||
topics = "fork_choice"
|
topics = "fork_choice"
|
||||||
|
|
||||||
proc init*(T: type ForkChoiceBackend,
|
func init*(T: type ForkChoiceBackend,
|
||||||
justifiedCheckpoint: Checkpoint,
|
justifiedCheckpoint: Checkpoint,
|
||||||
finalizedCheckpoint: Checkpoint,
|
finalizedCheckpoint: Checkpoint,
|
||||||
useProposerBoosting: bool): T =
|
useProposerBoosting: bool): T =
|
||||||
|
|
|
@ -98,7 +98,7 @@ proc new*(T: type BlockProcessor,
|
||||||
# Sync callbacks
|
# Sync callbacks
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
proc hasBlocks*(self: BlockProcessor): bool =
|
func hasBlocks*(self: BlockProcessor): bool =
|
||||||
self.blockQueue.len() > 0
|
self.blockQueue.len() > 0
|
||||||
|
|
||||||
# Storage
|
# Storage
|
||||||
|
|
|
@ -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).
|
||||||
|
@ -31,7 +31,7 @@ type
|
||||||
# Initialization
|
# Initialization
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
|
|
||||||
proc new*(T: type ConsensusManager,
|
func new*(T: type ConsensusManager,
|
||||||
dag: ChainDAGRef,
|
dag: ChainDAGRef,
|
||||||
attestationPool: ref AttestationPool,
|
attestationPool: ref AttestationPool,
|
||||||
quarantine: ref Quarantine
|
quarantine: ref Quarantine
|
||||||
|
|
|
@ -1053,7 +1053,7 @@ proc onSlotEnd(node: BeaconNode, slot: Slot) {.async.} =
|
||||||
# above, this will be done just before the next slot starts
|
# above, this will be done just before the next slot starts
|
||||||
await node.updateGossipStatus(slot + 1)
|
await node.updateGossipStatus(slot + 1)
|
||||||
|
|
||||||
proc syncStatus(node: BeaconNode): string =
|
func syncStatus(node: BeaconNode): string =
|
||||||
if node.syncManager.inProgress: node.syncManager.syncStatus
|
if node.syncManager.inProgress: node.syncManager.syncStatus
|
||||||
elif node.backfiller.inProgress: "backfill: " & node.backfiller.syncStatus
|
elif node.backfiller.inProgress: "backfill: " & node.backfiller.syncStatus
|
||||||
else: "synced"
|
else: "synced"
|
||||||
|
|
|
@ -122,7 +122,7 @@ func initiate_validator_exit*(cfg: RuntimeConfig, state: var ForkyBeaconState,
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/phase0/beacon-chain.md#slash_validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/phase0/beacon-chain.md#slash_validator
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/altair/beacon-chain.md#modified-slash_validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/altair/beacon-chain.md#modified-slash_validator
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/bellatrix/beacon-chain.md#modified-slash_validator
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/bellatrix/beacon-chain.md#modified-slash_validator
|
||||||
proc get_slashing_penalty*(state: ForkyBeaconState,
|
func get_slashing_penalty*(state: ForkyBeaconState,
|
||||||
validator_effective_balance: Gwei): Gwei =
|
validator_effective_balance: Gwei): Gwei =
|
||||||
# TODO Consider whether this is better than splitting the functions apart; in
|
# TODO Consider whether this is better than splitting the functions apart; in
|
||||||
# each case, tradeoffs. Here, it's just changing a couple of constants.
|
# each case, tradeoffs. Here, it's just changing a couple of constants.
|
||||||
|
@ -641,7 +641,7 @@ proc check_attestation*(
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
proc get_proposer_reward*(state: ForkyBeaconState,
|
func get_proposer_reward*(state: ForkyBeaconState,
|
||||||
attestation: SomeAttestation,
|
attestation: SomeAttestation,
|
||||||
base_reward_per_increment: Gwei,
|
base_reward_per_increment: Gwei,
|
||||||
cache: var StateCache,
|
cache: var StateCache,
|
||||||
|
@ -757,7 +757,7 @@ func get_next_sync_committee_keys(state: altair.BeaconState | bellatrix.BeaconSt
|
||||||
res
|
res
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/altair/beacon-chain.md#get_next_sync_committee
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/altair/beacon-chain.md#get_next_sync_committee
|
||||||
proc get_next_sync_committee*(state: altair.BeaconState | bellatrix.BeaconState):
|
func get_next_sync_committee*(state: altair.BeaconState | bellatrix.BeaconState):
|
||||||
SyncCommittee =
|
SyncCommittee =
|
||||||
## Return the *next* sync committee for a given ``state``.
|
## Return the *next* sync committee for a given ``state``.
|
||||||
var res: SyncCommittee
|
var res: SyncCommittee
|
||||||
|
@ -795,7 +795,8 @@ func translate_participation(
|
||||||
state.previous_epoch_participation[index] =
|
state.previous_epoch_participation[index] =
|
||||||
add_flag(state.previous_epoch_participation[index], flag_index)
|
add_flag(state.previous_epoch_participation[index], flag_index)
|
||||||
|
|
||||||
proc upgrade_to_altair*(cfg: RuntimeConfig, pre: phase0.BeaconState): ref altair.BeaconState =
|
func upgrade_to_altair*(cfg: RuntimeConfig, pre: phase0.BeaconState):
|
||||||
|
ref altair.BeaconState =
|
||||||
var
|
var
|
||||||
empty_participation = EpochParticipationFlags()
|
empty_participation = EpochParticipationFlags()
|
||||||
inactivity_scores = HashList[uint64, Limit VALIDATOR_REGISTRY_LIMIT]()
|
inactivity_scores = HashList[uint64, Limit VALIDATOR_REGISTRY_LIMIT]()
|
||||||
|
|
|
@ -106,7 +106,7 @@ func toPubKey*(pubKey: CookedPubKey): ValidatorPubKey =
|
||||||
# Un-specced in either hash-to-curve or Eth2
|
# Un-specced in either hash-to-curve or Eth2
|
||||||
ValidatorPubKey(blob: pubKey.toRaw())
|
ValidatorPubKey(blob: pubKey.toRaw())
|
||||||
|
|
||||||
proc load*(v: ValidatorPubKey): Option[CookedPubKey] =
|
func load*(v: ValidatorPubKey): Option[CookedPubKey] =
|
||||||
## Parse signature blob - this may fail
|
## Parse signature blob - this may fail
|
||||||
var val: blscurve.PublicKey
|
var val: blscurve.PublicKey
|
||||||
if fromBytes(val, v.blob):
|
if fromBytes(val, v.blob):
|
||||||
|
@ -114,7 +114,7 @@ proc load*(v: ValidatorPubKey): Option[CookedPubKey] =
|
||||||
else:
|
else:
|
||||||
none CookedPubKey
|
none CookedPubKey
|
||||||
|
|
||||||
proc load*(v: UncompressedPubKey): Option[CookedPubKey] =
|
func load*(v: UncompressedPubKey): Option[CookedPubKey] =
|
||||||
## Parse signature blob - this may fail
|
## Parse signature blob - this may fail
|
||||||
var val: blscurve.PublicKey
|
var val: blscurve.PublicKey
|
||||||
if fromBytes(val, v.blob):
|
if fromBytes(val, v.blob):
|
||||||
|
@ -150,7 +150,7 @@ proc loadWithCache*(v: ValidatorPubKey): Option[CookedPubKey] =
|
||||||
cache[v.blob] = cooked.get()
|
cache[v.blob] = cooked.get()
|
||||||
return cooked
|
return cooked
|
||||||
|
|
||||||
proc load*(v: ValidatorSig): Option[CookedSig] =
|
func load*(v: ValidatorSig): Option[CookedSig] =
|
||||||
## Parse signature blob - this may fail
|
## Parse signature blob - this may fail
|
||||||
var parsed: blscurve.Signature
|
var parsed: blscurve.Signature
|
||||||
if fromBytes(parsed, v.blob):
|
if fromBytes(parsed, v.blob):
|
||||||
|
@ -165,7 +165,7 @@ func init*(agg: var AggregatePublicKey, pubkey: CookedPubKey) {.inline.}=
|
||||||
func init*(T: type AggregatePublicKey, pubkey: CookedPubKey): T =
|
func init*(T: type AggregatePublicKey, pubkey: CookedPubKey): T =
|
||||||
result.init(pubkey)
|
result.init(pubkey)
|
||||||
|
|
||||||
proc aggregate*(agg: var AggregatePublicKey, pubkey: CookedPubKey) {.inline.}=
|
func aggregate*(agg: var AggregatePublicKey, pubkey: CookedPubKey) {.inline.}=
|
||||||
## Aggregate two valid Validator Public Keys
|
## Aggregate two valid Validator Public Keys
|
||||||
agg.aggregate(blscurve.PublicKey(pubkey))
|
agg.aggregate(blscurve.PublicKey(pubkey))
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ func init*(agg: var AggregateSignature, sig: CookedSig) {.inline.}=
|
||||||
func init*(T: type AggregateSignature, sig: CookedSig): T =
|
func init*(T: type AggregateSignature, sig: CookedSig): T =
|
||||||
result.init(sig)
|
result.init(sig)
|
||||||
|
|
||||||
proc aggregate*(agg: var AggregateSignature, sig: CookedSig) {.inline.}=
|
func aggregate*(agg: var AggregateSignature, sig: CookedSig) {.inline.}=
|
||||||
## Aggregate two valid Validator Signatures
|
## Aggregate two valid Validator Signatures
|
||||||
agg.aggregate(blscurve.Signature(sig))
|
agg.aggregate(blscurve.Signature(sig))
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ func finish*(agg: AggregateSignature): CookedSig {.inline.} =
|
||||||
CookedSig(sig)
|
CookedSig(sig)
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/phase0/beacon-chain.md#bls-signatures
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/phase0/beacon-chain.md#bls-signatures
|
||||||
proc blsVerify*(
|
func blsVerify*(
|
||||||
pubkey: CookedPubKey, message: openArray[byte],
|
pubkey: CookedPubKey, message: openArray[byte],
|
||||||
signature: CookedSig): bool =
|
signature: CookedSig): bool =
|
||||||
## Check that a signature is valid for a message
|
## Check that a signature is valid for a message
|
||||||
|
@ -230,7 +230,7 @@ proc blsVerify*(
|
||||||
# Guard against invalid signature blobs that fail to parse
|
# Guard against invalid signature blobs that fail to parse
|
||||||
parsedSig.isSome() and blsVerify(pubkey, message, parsedSig.get())
|
parsedSig.isSome() and blsVerify(pubkey, message, parsedSig.get())
|
||||||
|
|
||||||
proc blsVerify*(sigSet: SignatureSet): bool =
|
func blsVerify*(sigSet: SignatureSet): bool =
|
||||||
## Unbatched verification
|
## Unbatched verification
|
||||||
## of 1 SignatureSet
|
## of 1 SignatureSet
|
||||||
## tuple[pubkey: blscurve.PublicKey, message: array[32, byte], blscurve.signature: Signature]
|
## tuple[pubkey: blscurve.PublicKey, message: array[32, byte], blscurve.signature: Signature]
|
||||||
|
@ -244,7 +244,7 @@ func blsSign*(privkey: ValidatorPrivKey, message: openArray[byte]): CookedSig =
|
||||||
## Computes a signature from a secret key and a message
|
## Computes a signature from a secret key and a message
|
||||||
CookedSig(SecretKey(privkey).sign(message))
|
CookedSig(SecretKey(privkey).sign(message))
|
||||||
|
|
||||||
proc blsFastAggregateVerify*(
|
func blsFastAggregateVerify*(
|
||||||
publicKeys: openArray[CookedPubKey],
|
publicKeys: openArray[CookedPubKey],
|
||||||
message: openArray[byte],
|
message: openArray[byte],
|
||||||
signature: CookedSig
|
signature: CookedSig
|
||||||
|
@ -284,7 +284,7 @@ proc blsFastAggregateVerify*(
|
||||||
|
|
||||||
fastAggregateVerify(unwrapped, message, blscurve.Signature(signature))
|
fastAggregateVerify(unwrapped, message, blscurve.Signature(signature))
|
||||||
|
|
||||||
proc blsFastAggregateVerify*(
|
func blsFastAggregateVerify*(
|
||||||
publicKeys: openArray[CookedPubKey],
|
publicKeys: openArray[CookedPubKey],
|
||||||
message: openArray[byte],
|
message: openArray[byte],
|
||||||
signature: ValidatorSig
|
signature: ValidatorSig
|
||||||
|
@ -474,5 +474,5 @@ func init*(T: typedesc[ValidatorSig], data: array[RawSigSize, byte]): T {.noinit
|
||||||
func infinity*(T: type ValidatorSig): T =
|
func infinity*(T: type ValidatorSig): T =
|
||||||
result.blob[0] = byte 0xC0
|
result.blob[0] = byte 0xC0
|
||||||
|
|
||||||
proc burnMem*(key: var ValidatorPrivKey) =
|
func burnMem*(key: var ValidatorPrivKey) =
|
||||||
burnMem(addr key, sizeof(ValidatorPrivKey))
|
burnMem(addr key, sizeof(ValidatorPrivKey))
|
||||||
|
|
|
@ -613,7 +613,7 @@ proc readValue*(
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raiseUnexpectedValue(reader, "Hex string of 4 bytes expected")
|
raiseUnexpectedValue(reader, "Hex string of 4 bytes expected")
|
||||||
|
|
||||||
proc `$`*(x: JustificationBits): string =
|
func `$`*(x: JustificationBits): string =
|
||||||
"0x" & toHex(uint8(x))
|
"0x" & toHex(uint8(x))
|
||||||
|
|
||||||
proc readValue*(reader: var JsonReader, value: var JustificationBits)
|
proc readValue*(reader: var JsonReader, value: var JustificationBits)
|
||||||
|
@ -856,7 +856,7 @@ proc readValue*(r: var JsonReader, T: type GraffitiBytes): T
|
||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
r.raiseUnexpectedValue err.msg
|
r.raiseUnexpectedValue err.msg
|
||||||
|
|
||||||
proc load*(
|
func load*(
|
||||||
validators: openArray[ImmutableValidatorData2],
|
validators: openArray[ImmutableValidatorData2],
|
||||||
index: ValidatorIndex | uint64): Option[CookedPubKey] =
|
index: ValidatorIndex | uint64): Option[CookedPubKey] =
|
||||||
if validators.lenu64() <= index.uint64:
|
if validators.lenu64() <= index.uint64:
|
||||||
|
@ -896,7 +896,7 @@ template isomorphicCast*[T, U](x: U): T =
|
||||||
doAssert getSizeofSig(T()) == getSizeofSig(U())
|
doAssert getSizeofSig(T()) == getSizeofSig(U())
|
||||||
cast[ptr T](unsafeAddr x)[]
|
cast[ptr T](unsafeAddr x)[]
|
||||||
|
|
||||||
proc clear*(cache: var StateCache) =
|
func clear*(cache: var StateCache) =
|
||||||
cache.shuffled_active_validator_indices.clear
|
cache.shuffled_active_validator_indices.clear
|
||||||
cache.beacon_proposer_indices.clear
|
cache.beacon_proposer_indices.clear
|
||||||
cache.sync_committees.clear
|
cache.sync_committees.clear
|
||||||
|
|
|
@ -327,11 +327,11 @@ type
|
||||||
func encodeQuantityHex*(x: auto): string =
|
func encodeQuantityHex*(x: auto): string =
|
||||||
"0x" & x.toHex
|
"0x" & x.toHex
|
||||||
|
|
||||||
proc fromHex*(T: typedesc[BloomLogs], s: string): T {.
|
func fromHex*(T: typedesc[BloomLogs], s: string): T {.
|
||||||
raises: [Defect, ValueError].} =
|
raises: [Defect, ValueError].} =
|
||||||
hexToByteArray(s, result.data)
|
hexToByteArray(s, result.data)
|
||||||
|
|
||||||
proc fromHex*(T: typedesc[ExecutionAddress], s: string): T {.
|
func fromHex*(T: typedesc[ExecutionAddress], s: string): T {.
|
||||||
raises: [Defect, ValueError].} =
|
raises: [Defect, ValueError].} =
|
||||||
hexToByteArray(s, result.data)
|
hexToByteArray(s, result.data)
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ proc readValue*(r: var JsonReader, a: var Eth2Digest) {.raises: [Defect, IOError
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raiseUnexpectedValue(r, "Hex string expected")
|
raiseUnexpectedValue(r, "Hex string expected")
|
||||||
|
|
||||||
proc toGaugeValue*(hash: Eth2Digest): int64 =
|
func toGaugeValue*(hash: Eth2Digest): int64 =
|
||||||
# Only the last 8 bytes are taken into consideration in accordance
|
# Only the last 8 bytes are taken into consideration in accordance
|
||||||
# to the ETH2 metrics spec:
|
# to the ETH2 metrics spec:
|
||||||
# https://github.com/ethereum/eth2.0-metrics/blob/6a79914cb31f7d54858c7dd57eee75b6162ec737/metrics.md#interop-metrics
|
# https://github.com/ethereum/eth2.0-metrics/blob/6a79914cb31f7d54858c7dd57eee75b6162ec737/metrics.md#interop-metrics
|
||||||
|
|
|
@ -429,19 +429,19 @@ func bellatrixFork*(cfg: RuntimeConfig): Fork =
|
||||||
current_version: cfg.BELLATRIX_FORK_VERSION,
|
current_version: cfg.BELLATRIX_FORK_VERSION,
|
||||||
epoch: cfg.BELLATRIX_FORK_EPOCH)
|
epoch: cfg.BELLATRIX_FORK_EPOCH)
|
||||||
|
|
||||||
proc forkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Fork =
|
func forkAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Fork =
|
||||||
case cfg.stateForkAtEpoch(epoch)
|
case cfg.stateForkAtEpoch(epoch)
|
||||||
of BeaconStateFork.Bellatrix: cfg.bellatrixFork
|
of BeaconStateFork.Bellatrix: cfg.bellatrixFork
|
||||||
of BeaconStateFork.Altair: cfg.altairFork
|
of BeaconStateFork.Altair: cfg.altairFork
|
||||||
of BeaconStateFork.Phase0: cfg.genesisFork
|
of BeaconStateFork.Phase0: cfg.genesisFork
|
||||||
|
|
||||||
proc forkVersionAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Version =
|
func forkVersionAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Version =
|
||||||
case cfg.stateForkAtEpoch(epoch)
|
case cfg.stateForkAtEpoch(epoch)
|
||||||
of BeaconStateFork.Bellatrix: cfg.BELLATRIX_FORK_VERSION
|
of BeaconStateFork.Bellatrix: cfg.BELLATRIX_FORK_VERSION
|
||||||
of BeaconStateFork.Altair: cfg.ALTAIR_FORK_VERSION
|
of BeaconStateFork.Altair: cfg.ALTAIR_FORK_VERSION
|
||||||
of BeaconStateFork.Phase0: cfg.GENESIS_FORK_VERSION
|
of BeaconStateFork.Phase0: cfg.GENESIS_FORK_VERSION
|
||||||
|
|
||||||
proc nextForkEpochAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Epoch =
|
func nextForkEpochAtEpoch*(cfg: RuntimeConfig, epoch: Epoch): Epoch =
|
||||||
case cfg.stateForkAtEpoch(epoch)
|
case cfg.stateForkAtEpoch(epoch)
|
||||||
of BeaconStateFork.Bellatrix: FAR_FUTURE_EPOCH
|
of BeaconStateFork.Bellatrix: FAR_FUTURE_EPOCH
|
||||||
of BeaconStateFork.Altair: cfg.BELLATRIX_FORK_EPOCH
|
of BeaconStateFork.Altair: cfg.BELLATRIX_FORK_EPOCH
|
||||||
|
|
|
@ -69,7 +69,7 @@ proc verify_block_signature(
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/phase0/beacon-chain.md#beacon-chain-state-transition-function
|
||||||
proc verifyStateRoot(
|
func verifyStateRoot(
|
||||||
state: ForkyBeaconState, blck: ForkyBeaconBlock | ForkySigVerifiedBeaconBlock):
|
state: ForkyBeaconState, blck: ForkyBeaconBlock | ForkySigVerifiedBeaconBlock):
|
||||||
Result[void, cstring] =
|
Result[void, cstring] =
|
||||||
# This is inlined in state_transition(...) in spec.
|
# This is inlined in state_transition(...) in spec.
|
||||||
|
@ -151,7 +151,7 @@ func noRollback*(state: var altair.HashedBeaconState) =
|
||||||
func noRollback*(state: var bellatrix.HashedBeaconState) =
|
func noRollback*(state: var bellatrix.HashedBeaconState) =
|
||||||
trace "Skipping rollback of broken Bellatrix state"
|
trace "Skipping rollback of broken Bellatrix state"
|
||||||
|
|
||||||
proc maybeUpgradeStateToAltair(
|
func maybeUpgradeStateToAltair(
|
||||||
cfg: RuntimeConfig, state: var ForkedHashedBeaconState) =
|
cfg: RuntimeConfig, state: var ForkedHashedBeaconState) =
|
||||||
# Both process_slots() and state_transition_block() call this, so only run it
|
# Both process_slots() and state_transition_block() call this, so only run it
|
||||||
# once by checking for existing fork.
|
# once by checking for existing fork.
|
||||||
|
@ -175,7 +175,7 @@ func maybeUpgradeStateToBellatrix(
|
||||||
bellatrixData: bellatrix.HashedBeaconState(
|
bellatrixData: bellatrix.HashedBeaconState(
|
||||||
root: hash_tree_root(newState[]), data: newState[]))[]
|
root: hash_tree_root(newState[]), data: newState[]))[]
|
||||||
|
|
||||||
proc maybeUpgradeState*(
|
func maybeUpgradeState*(
|
||||||
cfg: RuntimeConfig, state: var ForkedHashedBeaconState) =
|
cfg: RuntimeConfig, state: var ForkedHashedBeaconState) =
|
||||||
cfg.maybeUpgradeStateToAltair(state)
|
cfg.maybeUpgradeStateToAltair(state)
|
||||||
cfg.maybeUpgradeStateToBellatrix(state)
|
cfg.maybeUpgradeStateToBellatrix(state)
|
||||||
|
|
|
@ -255,7 +255,7 @@ proc process_attester_slashing*(
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
proc findValidatorIndex*(state: ForkyBeaconState, pubkey: ValidatorPubKey): int =
|
func findValidatorIndex*(state: ForkyBeaconState, pubkey: ValidatorPubKey): int =
|
||||||
# This linear scan is unfortunate, but should be fairly fast as we do a simple
|
# This linear scan is unfortunate, but should be fairly fast as we do a simple
|
||||||
# byte comparison of the key. The alternative would be to build a Table, but
|
# byte comparison of the key. The alternative would be to build a Table, but
|
||||||
# given that each block can hold no more than 16 deposits, it's slower to
|
# given that each block can hold no more than 16 deposits, it's slower to
|
||||||
|
@ -558,13 +558,13 @@ proc process_block*(
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
proc process_block*(
|
func process_block*(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: var altair.BeaconState, blck: SomePhase0Block, flags: UpdateFlags,
|
state: var altair.BeaconState, blck: SomePhase0Block, flags: UpdateFlags,
|
||||||
cache: var StateCache): Result[void, cstring] =
|
cache: var StateCache): Result[void, cstring] =
|
||||||
err("process_block: Altair state with Phase 0 block")
|
err("process_block: Altair state with Phase 0 block")
|
||||||
|
|
||||||
proc process_block*(
|
func process_block*(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: var bellatrix.BeaconState, blck: SomePhase0Block, flags: UpdateFlags,
|
state: var bellatrix.BeaconState, blck: SomePhase0Block, flags: UpdateFlags,
|
||||||
cache: var StateCache): Result[void, cstring] =
|
cache: var StateCache): Result[void, cstring] =
|
||||||
|
@ -630,25 +630,25 @@ proc process_block*(
|
||||||
|
|
||||||
ok()
|
ok()
|
||||||
|
|
||||||
proc process_block*(
|
func process_block*(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: var phase0.BeaconState, blck: SomeAltairBlock, flags: UpdateFlags,
|
state: var phase0.BeaconState, blck: SomeAltairBlock, flags: UpdateFlags,
|
||||||
cache: var StateCache): Result[void, cstring]=
|
cache: var StateCache): Result[void, cstring]=
|
||||||
err("process_block: Phase 0 state with Altair block")
|
err("process_block: Phase 0 state with Altair block")
|
||||||
|
|
||||||
proc process_block*(
|
func process_block*(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: var phase0.BeaconState, blck: SomeMergeBlock, flags: UpdateFlags,
|
state: var phase0.BeaconState, blck: SomeMergeBlock, flags: UpdateFlags,
|
||||||
cache: var StateCache): Result[void, cstring]=
|
cache: var StateCache): Result[void, cstring]=
|
||||||
err("process_block: Phase 0 state with Merge block")
|
err("process_block: Phase 0 state with Merge block")
|
||||||
|
|
||||||
proc process_block*(
|
func process_block*(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: var altair.BeaconState, blck: SomeMergeBlock, flags: UpdateFlags,
|
state: var altair.BeaconState, blck: SomeMergeBlock, flags: UpdateFlags,
|
||||||
cache: var StateCache): Result[void, cstring]=
|
cache: var StateCache): Result[void, cstring]=
|
||||||
err("process_block: Altair state with Merge block")
|
err("process_block: Altair state with Merge block")
|
||||||
|
|
||||||
proc process_block*(
|
func process_block*(
|
||||||
cfg: RuntimeConfig,
|
cfg: RuntimeConfig,
|
||||||
state: var bellatrix.BeaconState, blck: SomeAltairBlock, flags: UpdateFlags,
|
state: var bellatrix.BeaconState, blck: SomeAltairBlock, flags: UpdateFlags,
|
||||||
cache: var StateCache): Result[void, cstring]=
|
cache: var StateCache): Result[void, cstring]=
|
||||||
|
|
|
@ -985,7 +985,8 @@ func process_participation_flag_updates*(state: var (altair.BeaconState | bellat
|
||||||
state.current_epoch_participation.resetCache()
|
state.current_epoch_participation.resetCache()
|
||||||
|
|
||||||
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/altair/beacon-chain.md#sync-committee-updates
|
# https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/altair/beacon-chain.md#sync-committee-updates
|
||||||
proc process_sync_committee_updates*(state: var (altair.BeaconState | bellatrix.BeaconState)) =
|
func process_sync_committee_updates*(
|
||||||
|
state: var (altair.BeaconState | bellatrix.BeaconState)) =
|
||||||
let next_epoch = get_current_epoch(state) + 1
|
let next_epoch = get_current_epoch(state) + 1
|
||||||
if next_epoch.is_sync_committee_period():
|
if next_epoch.is_sync_committee_period():
|
||||||
state.current_sync_committee = state.next_sync_committee
|
state.current_sync_committee = state.next_sync_committee
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
# beacon_chain
|
||||||
|
# Copyright (c) 2021-2022 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.
|
||||||
|
|
||||||
import
|
import
|
||||||
std/[tables, sequtils],
|
std/[tables, sequtils],
|
||||||
bearssl,
|
bearssl,
|
||||||
|
@ -199,10 +206,10 @@ func getNextProposalSlot*(tracker: ActionTracker, slot: Slot): Slot =
|
||||||
tracker.proposingSlots,
|
tracker.proposingSlots,
|
||||||
tracker.lastCalculatedEpoch, slot)
|
tracker.lastCalculatedEpoch, slot)
|
||||||
|
|
||||||
proc dependentRoot(epoch: Epoch, head, tail: BlockRef): Eth2Digest =
|
func dependentRoot(epoch: Epoch, head, tail: BlockRef): Eth2Digest =
|
||||||
head.prevDependentBlock(tail, epoch).root
|
head.prevDependentBlock(tail, epoch).root
|
||||||
|
|
||||||
proc needsUpdate*(
|
func needsUpdate*(
|
||||||
tracker: ActionTracker, epoch: Epoch, head, tail: BlockRef): bool =
|
tracker: ActionTracker, epoch: Epoch, head, tail: BlockRef): bool =
|
||||||
# Using prevDependentBlock here means we lock the action tracking to
|
# Using prevDependentBlock here means we lock the action tracking to
|
||||||
# the dependent root for attestation duties and not block proposal -
|
# the dependent root for attestation duties and not block proposal -
|
||||||
|
@ -210,7 +217,7 @@ proc needsUpdate*(
|
||||||
# and the action tracker is speculative in nature.
|
# and the action tracker is speculative in nature.
|
||||||
tracker.dependentRoot != dependentRoot(epoch, head, tail)
|
tracker.dependentRoot != dependentRoot(epoch, head, tail)
|
||||||
|
|
||||||
proc updateActions*(
|
func updateActions*(
|
||||||
tracker: var ActionTracker, epochRef: EpochRef, head, tail: BlockRef) =
|
tracker: var ActionTracker, epochRef: EpochRef, head, tail: BlockRef) =
|
||||||
# Updates the schedule for upcoming attestation and proposal work
|
# Updates the schedule for upcoming attestation and proposal work
|
||||||
let
|
let
|
||||||
|
@ -258,7 +265,7 @@ proc updateActions*(
|
||||||
tracker.attestingSlots[epoch mod 2] or
|
tracker.attestingSlots[epoch mod 2] or
|
||||||
(1'u32 shl (slot mod SLOTS_PER_EPOCH))
|
(1'u32 shl (slot mod SLOTS_PER_EPOCH))
|
||||||
|
|
||||||
proc init*(
|
func init*(
|
||||||
T: type ActionTracker, rng: ref BrHmacDrbgContext,
|
T: type ActionTracker, rng: ref BrHmacDrbgContext,
|
||||||
subscribeAllAttnets: bool): T =
|
subscribeAllAttnets: bool): T =
|
||||||
T(
|
T(
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
# beacon_chain
|
||||||
|
# Copyright (c) 2022 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.
|
||||||
|
|
||||||
import
|
import
|
||||||
re, strutils, os, math,
|
re, strutils, os, math,
|
||||||
stew/bitops2,
|
stew/bitops2,
|
||||||
|
@ -45,7 +52,7 @@ const
|
||||||
epochFileNameExtension* = ".epoch"
|
epochFileNameExtension* = ".epoch"
|
||||||
epochNumberRegexStr = r"\d{" & $epochInfoFileNameDigitsCount & r"}\"
|
epochNumberRegexStr = r"\d{" & $epochInfoFileNameDigitsCount & r"}\"
|
||||||
|
|
||||||
proc copyParticipationFlags*(auxiliaryState: var AuxiliaryState,
|
func copyParticipationFlags*(auxiliaryState: var AuxiliaryState,
|
||||||
forkedState: ForkedHashedBeaconState) =
|
forkedState: ForkedHashedBeaconState) =
|
||||||
withState(forkedState):
|
withState(forkedState):
|
||||||
when stateFork > BeaconStateFork.Phase0:
|
when stateFork > BeaconStateFork.Phase0:
|
||||||
|
@ -91,14 +98,14 @@ proc getAggregatedFilesLastEpoch*(dir: string): Epoch =
|
||||||
largestEpochInFileName = fileLastEpoch
|
largestEpochInFileName = fileLastEpoch
|
||||||
return largestEpochInFileName.Epoch
|
return largestEpochInFileName.Epoch
|
||||||
|
|
||||||
proc epochAsString*(epoch: Epoch): string =
|
func epochAsString*(epoch: Epoch): string =
|
||||||
let strEpoch = $epoch
|
let strEpoch = $epoch
|
||||||
'0'.repeat(epochInfoFileNameDigitsCount - strEpoch.len) & strEpoch
|
'0'.repeat(epochInfoFileNameDigitsCount - strEpoch.len) & strEpoch
|
||||||
|
|
||||||
proc getFilePathForEpoch*(epoch: Epoch, dir: string): string =
|
func getFilePathForEpoch*(epoch: Epoch, dir: string): string =
|
||||||
dir / epochAsString(epoch) & epochFileNameExtension
|
dir / epochAsString(epoch) & epochFileNameExtension
|
||||||
|
|
||||||
proc getFilePathForEpochs*(startEpoch, endEpoch: Epoch, dir: string): string =
|
func getFilePathForEpochs*(startEpoch, endEpoch: Epoch, dir: string): string =
|
||||||
let fileName = epochAsString(startEpoch) & "_" &
|
let fileName = epochAsString(startEpoch) & "_" &
|
||||||
epochAsString(endEpoch) & epochFileNameExtension
|
epochAsString(endEpoch) & epochFileNameExtension
|
||||||
dir / fileName
|
dir / fileName
|
||||||
|
@ -119,7 +126,7 @@ func getBlockRange*(dag: ChainDAGRef, start, ends: Slot): seq[BlockRef] =
|
||||||
func getOutcome(delta: RewardDelta): int64 =
|
func getOutcome(delta: RewardDelta): int64 =
|
||||||
delta.rewards.int64 - delta.penalties.int64
|
delta.rewards.int64 - delta.penalties.int64
|
||||||
|
|
||||||
proc collectSlashings(
|
func collectSlashings(
|
||||||
rewardsAndPenalties: var seq[RewardsAndPenalties],
|
rewardsAndPenalties: var seq[RewardsAndPenalties],
|
||||||
state: ForkyBeaconState, total_balance: Gwei) =
|
state: ForkyBeaconState, total_balance: Gwei) =
|
||||||
let
|
let
|
||||||
|
@ -134,7 +141,7 @@ proc collectSlashings(
|
||||||
validator[].get_slashing_penalty(
|
validator[].get_slashing_penalty(
|
||||||
adjusted_total_slashing_balance, total_balance).int64
|
adjusted_total_slashing_balance, total_balance).int64
|
||||||
|
|
||||||
proc getFinalizedCheckpoint(state: ForkyBeaconState,
|
func getFinalizedCheckpoint(state: ForkyBeaconState,
|
||||||
total_active_balance,
|
total_active_balance,
|
||||||
previous_epoch_target_balance,
|
previous_epoch_target_balance,
|
||||||
current_epoch_target_balance: Gwei):
|
current_epoch_target_balance: Gwei):
|
||||||
|
@ -189,13 +196,13 @@ proc getFinalizedCheckpoint(state: ForkyBeaconState,
|
||||||
|
|
||||||
return state.finalized_checkpoint
|
return state.finalized_checkpoint
|
||||||
|
|
||||||
proc getFinalizedCheckpoint(state: phase0.BeaconState, balances: TotalBalances):
|
func getFinalizedCheckpoint(state: phase0.BeaconState, balances: TotalBalances):
|
||||||
Checkpoint =
|
Checkpoint =
|
||||||
getFinalizedCheckpoint(state, balances.current_epoch,
|
getFinalizedCheckpoint(state, balances.current_epoch,
|
||||||
balances.previous_epoch_target_attesters,
|
balances.previous_epoch_target_attesters,
|
||||||
balances.current_epoch_target_attesters)
|
balances.current_epoch_target_attesters)
|
||||||
|
|
||||||
proc getFinalizedCheckpoint(
|
func getFinalizedCheckpoint(
|
||||||
state: altair.BeaconState | bellatrix.BeaconState,
|
state: altair.BeaconState | bellatrix.BeaconState,
|
||||||
balances: UnslashedParticipatingBalances): Checkpoint =
|
balances: UnslashedParticipatingBalances): Checkpoint =
|
||||||
getFinalizedCheckpoint(state, balances.current_epoch,
|
getFinalizedCheckpoint(state, balances.current_epoch,
|
||||||
|
@ -206,7 +213,7 @@ func getFinalityDelay*(state: ForkyBeaconState,
|
||||||
finalizedCheckpoint: Checkpoint): uint64 =
|
finalizedCheckpoint: Checkpoint): uint64 =
|
||||||
state.get_previous_epoch - finalizedCheckpoint.epoch
|
state.get_previous_epoch - finalizedCheckpoint.epoch
|
||||||
|
|
||||||
proc collectEpochRewardsAndPenalties*(
|
func collectEpochRewardsAndPenalties*(
|
||||||
rewardsAndPenalties: var seq[RewardsAndPenalties],
|
rewardsAndPenalties: var seq[RewardsAndPenalties],
|
||||||
state: phase0.BeaconState, cache: var StateCache, cfg: RuntimeConfig,
|
state: phase0.BeaconState, cache: var StateCache, cfg: RuntimeConfig,
|
||||||
flags: UpdateFlags) =
|
flags: UpdateFlags) =
|
||||||
|
@ -271,7 +278,7 @@ proc collectEpochRewardsAndPenalties*(
|
||||||
|
|
||||||
rewardsAndPenalties.collectSlashings(state, info.balances.current_epoch)
|
rewardsAndPenalties.collectSlashings(state, info.balances.current_epoch)
|
||||||
|
|
||||||
proc collectEpochRewardsAndPenalties*(
|
func collectEpochRewardsAndPenalties*(
|
||||||
rewardsAndPenalties: var seq[RewardsAndPenalties],
|
rewardsAndPenalties: var seq[RewardsAndPenalties],
|
||||||
state: altair.BeaconState | bellatrix.BeaconState,
|
state: altair.BeaconState | bellatrix.BeaconState,
|
||||||
cache: var StateCache, cfg: RuntimeConfig, flags: UpdateFlags) =
|
cache: var StateCache, cfg: RuntimeConfig, flags: UpdateFlags) =
|
||||||
|
@ -326,7 +333,7 @@ proc collectEpochRewardsAndPenalties*(
|
||||||
|
|
||||||
rewardsAndPenalties.collectSlashings(state, info.balances.current_epoch)
|
rewardsAndPenalties.collectSlashings(state, info.balances.current_epoch)
|
||||||
|
|
||||||
proc collectFromSlashedValidator(
|
func collectFromSlashedValidator(
|
||||||
rewardsAndPenalties: var seq[RewardsAndPenalties],
|
rewardsAndPenalties: var seq[RewardsAndPenalties],
|
||||||
state: ForkyBeaconState, slashedIndex, proposerIndex: ValidatorIndex) =
|
state: ForkyBeaconState, slashedIndex, proposerIndex: ValidatorIndex) =
|
||||||
template slashed_validator: untyped = state.validators[slashedIndex]
|
template slashed_validator: untyped = state.validators[slashedIndex]
|
||||||
|
@ -335,7 +342,7 @@ proc collectFromSlashedValidator(
|
||||||
rewardsAndPenalties[slashedIndex].slashing_outcome -= slashingPenalty.int64
|
rewardsAndPenalties[slashedIndex].slashing_outcome -= slashingPenalty.int64
|
||||||
rewardsAndPenalties[proposerIndex].slashing_outcome += whistleblowerReward.int64
|
rewardsAndPenalties[proposerIndex].slashing_outcome += whistleblowerReward.int64
|
||||||
|
|
||||||
proc collectFromProposerSlashings(
|
func collectFromProposerSlashings(
|
||||||
rewardsAndPenalties: var seq[RewardsAndPenalties],
|
rewardsAndPenalties: var seq[RewardsAndPenalties],
|
||||||
forkedState: ForkedHashedBeaconState,
|
forkedState: ForkedHashedBeaconState,
|
||||||
forkedBlock: ForkedTrustedSignedBeaconBlock) =
|
forkedBlock: ForkedTrustedSignedBeaconBlock) =
|
||||||
|
@ -346,7 +353,7 @@ proc collectFromProposerSlashings(
|
||||||
rewardsAndPenalties.collectFromSlashedValidator(state.data,
|
rewardsAndPenalties.collectFromSlashedValidator(state.data,
|
||||||
slashedIndex.ValidatorIndex, blck.message.proposer_index.ValidatorIndex)
|
slashedIndex.ValidatorIndex, blck.message.proposer_index.ValidatorIndex)
|
||||||
|
|
||||||
proc collectFromAttesterSlashings(
|
func collectFromAttesterSlashings(
|
||||||
rewardsAndPenalties: var seq[RewardsAndPenalties],
|
rewardsAndPenalties: var seq[RewardsAndPenalties],
|
||||||
forkedState: ForkedHashedBeaconState,
|
forkedState: ForkedHashedBeaconState,
|
||||||
forkedBlock: ForkedTrustedSignedBeaconBlock) =
|
forkedBlock: ForkedTrustedSignedBeaconBlock) =
|
||||||
|
@ -359,7 +366,7 @@ proc collectFromAttesterSlashings(
|
||||||
rewardsAndPenalties.collectFromSlashedValidator(
|
rewardsAndPenalties.collectFromSlashedValidator(
|
||||||
state.data, slashedIndex, blck.message.proposer_index.ValidatorIndex)
|
state.data, slashedIndex, blck.message.proposer_index.ValidatorIndex)
|
||||||
|
|
||||||
proc collectFromAttestations(
|
func collectFromAttestations(
|
||||||
rewardsAndPenalties: var seq[RewardsAndPenalties],
|
rewardsAndPenalties: var seq[RewardsAndPenalties],
|
||||||
forkedState: ForkedHashedBeaconState,
|
forkedState: ForkedHashedBeaconState,
|
||||||
forkedBlock: ForkedTrustedSignedBeaconBlock,
|
forkedBlock: ForkedTrustedSignedBeaconBlock,
|
||||||
|
@ -408,7 +415,7 @@ proc collectFromDeposits(
|
||||||
rewardsAndPenalties.add(
|
rewardsAndPenalties.add(
|
||||||
RewardsAndPenalties(deposits: amount))
|
RewardsAndPenalties(deposits: amount))
|
||||||
|
|
||||||
proc collectFromSyncAggregate(
|
func collectFromSyncAggregate(
|
||||||
rewardsAndPenalties: var seq[RewardsAndPenalties],
|
rewardsAndPenalties: var seq[RewardsAndPenalties],
|
||||||
forkedState: ForkedHashedBeaconState,
|
forkedState: ForkedHashedBeaconState,
|
||||||
forkedBlock: ForkedTrustedSignedBeaconBlock,
|
forkedBlock: ForkedTrustedSignedBeaconBlock,
|
||||||
|
|
|
@ -92,7 +92,7 @@ cli do(slots = SLOTS_PER_EPOCH * 6,
|
||||||
quarantine = newClone(Quarantine.init())
|
quarantine = newClone(Quarantine.init())
|
||||||
attPool = AttestationPool.init(dag, quarantine)
|
attPool = AttestationPool.init(dag, quarantine)
|
||||||
batchCrypto = BatchCrypto.new(
|
batchCrypto = BatchCrypto.new(
|
||||||
keys.newRng(), eager = proc(): bool = true, taskpool)
|
keys.newRng(), eager = func(): bool = true, taskpool)
|
||||||
syncCommitteePool = newClone SyncCommitteeMsgPool.init(keys.newRng())
|
syncCommitteePool = newClone SyncCommitteeMsgPool.init(keys.newRng())
|
||||||
timers: array[Timers, RunningStat]
|
timers: array[Timers, RunningStat]
|
||||||
attesters: RunningStat
|
attesters: RunningStat
|
||||||
|
|
|
@ -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).
|
||||||
|
@ -89,7 +89,7 @@ template mockGenesisDepositsImpl(
|
||||||
depositsData.add result[valIdx]
|
depositsData.add result[valIdx]
|
||||||
depositsDataHash.add hash_tree_root(result[valIdx])
|
depositsDataHash.add hash_tree_root(result[valIdx])
|
||||||
|
|
||||||
proc mockGenesisBalancedDeposits*(
|
func mockGenesisBalancedDeposits*(
|
||||||
validatorCount: uint64,
|
validatorCount: uint64,
|
||||||
amountInEth: Positive,
|
amountInEth: Positive,
|
||||||
flags: UpdateFlags = {}
|
flags: UpdateFlags = {}
|
||||||
|
@ -106,7 +106,7 @@ proc mockGenesisBalancedDeposits*(
|
||||||
mockGenesisDepositsImpl(result, validatorCount,amount,flags):
|
mockGenesisDepositsImpl(result, validatorCount,amount,flags):
|
||||||
discard
|
discard
|
||||||
|
|
||||||
proc mockUpdateStateForNewDeposit*(
|
func mockUpdateStateForNewDeposit*(
|
||||||
state: var ForkyBeaconState,
|
state: var ForkyBeaconState,
|
||||||
validator_index: uint64,
|
validator_index: uint64,
|
||||||
amount: uint64,
|
amount: uint64,
|
||||||
|
|
|
@ -14,7 +14,7 @@ import
|
||||||
../beacon_chain/spec/datatypes/phase0,
|
../beacon_chain/spec/datatypes/phase0,
|
||||||
../beacon_chain/consensus_object_pools/block_quarantine
|
../beacon_chain/consensus_object_pools/block_quarantine
|
||||||
|
|
||||||
proc makeBlock(slot: Slot, parent: Eth2Digest): ForkedSignedBeaconBlock =
|
func makeBlock(slot: Slot, parent: Eth2Digest): ForkedSignedBeaconBlock =
|
||||||
var
|
var
|
||||||
b = phase0.SignedBeaconBlock(
|
b = phase0.SignedBeaconBlock(
|
||||||
message: phase0.BeaconBlock(slot: slot, parent_root: parent))
|
message: phase0.BeaconBlock(slot: slot, parent_root: parent))
|
||||||
|
|
Loading…
Reference in New Issue