humaneXNum -> shortLog

This commit is contained in:
Jacek Sieka 2019-08-15 18:01:55 +02:00
parent 6a4d27f4ac
commit e639cd95c7
No known key found for this signature in database
GPG Key ID: A1B09461ABB656B8
8 changed files with 90 additions and 90 deletions

View File

@ -45,10 +45,10 @@ proc validate(
if attestationSlot <
state.finalized_checkpoint.epoch.compute_start_slot_of_epoch():
debug "Old attestation",
attestationSlot = humaneSlotNum(attestationSlot),
attestationEpoch = humaneEpochNum(attestationSlot.compute_epoch_of_slot),
stateSlot = humaneSlotNum(state.slot),
finalizedEpoch = humaneEpochNum(state.finalized_checkpoint.epoch)
attestationSlot = shortLog(attestationSlot),
attestationEpoch = shortLog(attestationSlot.compute_epoch_of_slot),
stateSlot = shortLog(state.slot),
finalizedEpoch = shortLog(state.finalized_checkpoint.epoch)
return
@ -57,10 +57,10 @@ proc validate(
# desperatly behind or someone is sending bogus attestations...
if attestationSlot > state.slot + 64:
debug "Future attestation",
attestationSlot = humaneSlotNum(attestationSlot),
attestationEpoch = humaneEpochNum(attestationSlot.compute_epoch_of_slot),
stateSlot = humaneSlotNum(state.slot),
finalizedEpoch = humaneEpochNum(state.finalized_checkpoint.epoch)
attestationSlot = shortLog(attestationSlot),
attestationEpoch = shortLog(attestationSlot.compute_epoch_of_slot),
stateSlot = shortLog(state.slot),
finalizedEpoch = shortLog(state.finalized_checkpoint.epoch)
return
if not attestation.custody_bits.BitSeq.isZeros:
@ -124,22 +124,22 @@ proc slotIndex(
We should have checked in validate that attestation is newer than
finalized_slot and we never prune things before that, per below condition!
""" &
", attestationSlot: " & $humaneSlotNum(attestationSlot) &
", startingSlot: " & $humaneSlotNum(pool.startingSlot)
", attestationSlot: " & $shortLog(attestationSlot) &
", startingSlot: " & $shortLog(pool.startingSlot)
if pool.slots.len == 0:
# Because the first attestations may arrive in any order, we'll make sure
# to start counting at the last finalized epoch start slot - anything
# earlier than that is thrown out by the above check
info "First attestation!",
attestationSlot = $humaneSlotNum(attestationSlot)
attestationSlot = $shortLog(attestationSlot)
pool.startingSlot =
state.finalized_checkpoint.epoch.compute_start_slot_of_epoch()
if pool.startingSlot + pool.slots.len.uint64 <= attestationSlot:
debug "Growing attestation pool",
attestationSlot = $humaneSlotNum(attestationSlot),
startingSlot = $humaneSlotNum(pool.startingSlot)
attestationSlot = $shortLog(attestationSlot),
startingSlot = $shortLog(pool.startingSlot)
# Make sure there's a pool entry for every slot, even when there's a gap
while pool.startingSlot + pool.slots.len.uint64 <= attestationSlot:
@ -148,9 +148,9 @@ proc slotIndex(
if pool.startingSlot <
state.finalized_checkpoint.epoch.compute_start_slot_of_epoch():
debug "Pruning attestation pool",
startingSlot = $humaneSlotNum(pool.startingSlot),
startingSlot = $shortLog(pool.startingSlot),
finalizedSlot =
$humaneSlotNum(
$shortLog(
state.finalized_checkpoint.epoch.compute_start_slot_of_epoch())
# TODO there should be a better way to remove a whole epoch of stuff..
@ -274,12 +274,12 @@ proc getAttestationsForBlock*(
newBlockSlot: Slot): seq[Attestation] =
if newBlockSlot - GENESIS_SLOT < MIN_ATTESTATION_INCLUSION_DELAY:
debug "Too early for attestations",
newBlockSlot = humaneSlotNum(newBlockSlot)
newBlockSlot = shortLog(newBlockSlot)
return
if pool.slots.len == 0: # startingSlot not set yet!
info "No attestations found (pool empty)",
newBlockSlot = humaneSlotNum(newBlockSlot)
newBlockSlot = shortLog(newBlockSlot)
return
var cache = get_empty_per_epoch_cache()
@ -294,9 +294,9 @@ proc getAttestationsForBlock*(
if attestationSlot < pool.startingSlot or
attestationSlot >= pool.startingSlot + pool.slots.len.uint64:
info "No attestations",
attestationSlot = humaneSlotNum(attestationSlot),
startingSlot = humaneSlotNum(pool.startingSlot),
endingSlot = humaneSlotNum(pool.startingSlot + pool.slots.len.uint64)
attestationSlot = shortLog(attestationSlot),
startingSlot = shortLog(pool.startingSlot),
endingSlot = shortLog(pool.startingSlot + pool.slots.len.uint64)
return

View File

@ -281,8 +281,8 @@ proc updateHead(node: BeaconNode, slot: Slot): BlockRef =
debug "Preparing for fork choice",
stateRoot = shortLog(root),
connectedPeers = node.network.peersCount,
stateSlot = humaneSlotNum(state.slot),
stateEpoch = humaneEpochNum(state.slot.computeEpochOfSlot)
stateSlot = shortLog(state.slot),
stateEpoch = shortLog(state.slot.computeEpochOfSlot)
let
justifiedHead = node.blockPool.latestJustifiedBlock()
@ -296,8 +296,8 @@ proc updateHead(node: BeaconNode, slot: Slot): BlockRef =
lmdGhost(node.attestationPool, state, justifiedHead)
info "Fork chosen",
newHeadSlot = humaneSlotNum(newHead.slot),
newHeadEpoch = humaneEpochNum(newHead.slot.computeEpochOfSlot),
newHeadSlot = shortLog(newHead.slot),
newHeadEpoch = shortLog(newHead.slot.computeEpochOfSlot),
newHeadBlockRoot = shortLog(newHead.root)
node.blockPool.updateHead(node.stateCache, newHead)
@ -336,16 +336,16 @@ proc proposeBlock(node: BeaconNode,
slot: Slot): Future[BlockRef] {.async.} =
if head.slot > slot:
notice "Skipping proposal, we've already selected a newer head",
headSlot = humaneSlotNum(head.slot),
headSlot = shortLog(head.slot),
headBlockRoot = shortLog(head.root),
slot = humaneSlotNum(slot)
slot = shortLog(slot)
return head
if head.slot == slot:
# Weird, we should never see as head the same slot as we're proposing a
# block for - did someone else steal our slot? why didn't we discard it?
warn "Found head at same slot as we're supposed to propose for!",
headSlot = humaneSlotNum(head.slot),
headSlot = shortLog(head.slot),
headBlockRoot = shortLog(head.root)
# TODO investigate how and when this happens.. maybe it shouldn't be an
# assert?
@ -465,8 +465,8 @@ proc handleAttestations(node: BeaconNode, head: BlockRef, slot: Slot) =
# finalized epoch.. also, it seems that posting very old attestations
# is risky from a slashing perspective. More work is needed here.
notice "Skipping attestation, head is too recent",
headSlot = humaneSlotNum(head.slot),
slot = humaneSlotNum(slot)
headSlot = shortLog(head.slot),
slot = shortLog(slot)
return
let attestationHead = head.findAncestorBySlot(slot)
@ -475,13 +475,13 @@ proc handleAttestations(node: BeaconNode, head: BlockRef, slot: Slot) =
# attesting to a past state - we must then recreate the world as it looked
# like back then
notice "Attesting to a state in the past, falling behind?",
headSlot = humaneSlotNum(head.slot),
attestationHeadSlot = humaneSlotNum(attestationHead.slot),
attestationSlot = humaneSlotNum(slot)
headSlot = shortLog(head.slot),
attestationHeadSlot = shortLog(attestationHead.slot),
attestationSlot = shortLog(slot)
debug "Checking attestations",
attestationHeadRoot = shortLog(attestationHead.blck.root),
attestationSlot = humaneSlotNum(slot)
attestationSlot = shortLog(slot)
# Collect data to send before node.stateCache grows stale
@ -566,7 +566,7 @@ proc handleProposal(node: BeaconNode, head: BlockRef, slot: Slot):
debug "Expecting proposal",
headRoot = shortLog(head.root),
slot = humaneSlotNum(slot),
slot = shortLog(slot),
proposer = shortLog(state.validators[proposerIdx].pubKey)
return head
@ -584,17 +584,17 @@ proc onSlotStart(node: BeaconNode, lastSlot, scheduledSlot: Slot) {.gcsafe, asyn
nextSlot = slot + 1
debug "Slot start",
lastSlot = humaneSlotNum(lastSlot),
scheduledSlot = humaneSlotNum(scheduledSlot),
slot = humaneSlotNum(slot)
lastSlot = shortLog(lastSlot),
scheduledSlot = shortLog(scheduledSlot),
slot = shortLog(slot)
if slot < lastSlot:
# This can happen if the system clock changes time for example, and it's
# pretty bad
# TODO shut down? time either was or is bad, and PoS relies on accuracy..
warn "Beacon clock time moved back, rescheduling slot actions",
slot = humaneSlotNum(slot),
scheduledSlot = humaneSlotNum(scheduledSlot)
slot = shortLog(slot),
scheduledSlot = shortLog(scheduledSlot)
addTimer(saturate(node.beaconClock.fromNow(nextSlot))) do (p: pointer):
asyncCheck node.onSlotStart(slot, nextSlot)
@ -608,9 +608,9 @@ proc onSlotStart(node: BeaconNode, lastSlot, scheduledSlot: Slot) {.gcsafe, asyn
# how long attestations remain interesting
# TODO should we shut down instead? clearly we're unable to keep up
warn "Unable to keep up, skipping ahead without doing work",
lastSlot = humaneSlotNum(lastSlot),
slot = humaneSlotNum(slot),
scheduledSlot = humaneSlotNum(scheduledSlot)
lastSlot = shortLog(lastSlot),
slot = shortLog(slot),
scheduledSlot = shortLog(scheduledSlot)
addTimer(saturate(node.beaconClock.fromNow(nextSlot))) do (p: pointer):
# We pass the current slot here to indicate that work should be skipped!
@ -650,9 +650,9 @@ proc onSlotStart(node: BeaconNode, lastSlot, scheduledSlot: Slot) {.gcsafe, asyn
# state rewinds while waiting for async operations like validator
# signature..
notice "Catching up",
curSlot = humaneSlotNum(curSlot),
lastSlot = humaneSlotNum(lastSlot),
slot = humaneSlotNum(slot)
curSlot = shortLog(curSlot),
lastSlot = shortLog(lastSlot),
slot = shortLog(slot)
# For every slot we're catching up, we'll propose then send
# attestations - head should normally be advancing along the same branch
@ -688,7 +688,7 @@ proc onSlotStart(node: BeaconNode, lastSlot, scheduledSlot: Slot) {.gcsafe, asyn
else: halfSlot - attestationStart.offset
debug "Waiting to send attestations",
slot = humaneSlotNum(slot),
slot = shortLog(slot),
fromNow = shortLog(fromNow)
await sleepAsync(fromNow)
@ -703,9 +703,9 @@ proc onSlotStart(node: BeaconNode, lastSlot, scheduledSlot: Slot) {.gcsafe, asyn
nextSlotStart = saturate(node.beaconClock.fromNow(nextSlot))
info "Scheduling slot actions",
lastSlot = humaneSlotNum(slot),
slot = humaneSlotNum(slot),
nextSlot = humaneSlotNum(nextSlot),
lastSlot = shortLog(slot),
slot = shortLog(slot),
nextSlot = shortLog(nextSlot),
fromNow = shortLog(nextSlotStart)
addTimer(nextSlotStart) do (p: pointer):
@ -737,7 +737,7 @@ proc run*(node: BeaconNode) =
fromNow = saturate(node.beaconClock.fromNow(startSlot))
info "Scheduling first slot action",
nextSlot = humaneSlotNum(startSlot),
nextSlot = shortLog(startSlot),
fromNow = shortLog(fromNow)
addTimer(fromNow) do (p: pointer):
@ -767,7 +767,7 @@ proc start(node: BeaconNode, headState: BeaconState) =
slotsSinceFinalization =
int64(node.blockPool.finalizedHead.slot) -
int64(node.beaconClock.now()),
stateSlot = humaneSlotNum(headState.slot),
stateSlot = shortLog(headState.slot),
SHARD_COUNT,
SLOTS_PER_EPOCH,
SECONDS_PER_SLOT,

View File

@ -187,7 +187,7 @@ proc addResolvedBlock(
blck = shortLog(blck),
blockRoot = shortLog(blockRoot),
justifiedRoot = shortLog(foundHead.get().justified.blck.root),
justifiedSlot = humaneSlotNum(foundHead.get().justified.slot)
justifiedSlot = shortLog(foundHead.get().justified.slot)
# Now that we have the new block, we should see if any of the previously
# unresolved blocks magically become resolved
@ -225,7 +225,7 @@ proc add*(
if blck.slot <= pool.finalizedHead.slot:
debug "Old block, dropping",
blck = shortLog(blck),
tailSlot = humaneSlotNum(pool.tail.slot),
tailSlot = shortLog(pool.tail.slot),
blockRoot = shortLog(blockRoot)
return
@ -371,7 +371,7 @@ proc maybePutState(pool: BlockPool, state: HashedBeaconState, blck: BlockRef) =
if state.data.slot mod SLOTS_PER_EPOCH == 0:
if not pool.db.containsState(state.root):
info "Storing state",
stateSlot = humaneSlotNum(state.data.slot),
stateSlot = shortLog(state.data.slot),
stateRoot = shortLog(state.root)
pool.db.putState(state.root, state.data)
# TODO this should be atomic with the above write..
@ -432,10 +432,10 @@ proc rewindState(pool: BlockPool, state: var StateData, bs: BlockSlot):
doAssert false, "Oh noes, we passed big bang!"
debug "Replaying state transitions",
stateSlot = humaneSlotNum(state.data.data.slot),
stateSlot = shortLog(state.data.data.slot),
ancestorStateRoot = shortLog(ancestor.data.state_root),
ancestorStateSlot = humaneSlotNum(ancestorState.get().slot),
slot = humaneSlotNum(bs.slot),
ancestorStateSlot = shortLog(ancestorState.get().slot),
slot = shortLog(bs.slot),
blockRoot = shortLog(bs.blck.root),
ancestors = ancestors.len
@ -513,7 +513,7 @@ proc updateHead*(pool: BlockPool, state: var StateData, blck: BlockRef) =
if pool.head.blck == blck:
debug "No head update this time",
headBlockRoot = shortLog(blck.root),
headBlockSlot = humaneSlotNum(blck.slot)
headBlockSlot = shortLog(blck.slot)
return
@ -533,20 +533,20 @@ proc updateHead*(pool: BlockPool, state: var StateData, blck: BlockRef) =
parentRoot = shortLog(blck.parent.root),
stateRoot = shortLog(state.data.root),
headBlockRoot = shortLog(state.blck.root),
stateSlot = humaneSlotNum(state.data.data.slot),
stateSlot = shortLog(state.data.data.slot),
justifiedEpoch =
humaneEpochNum(state.data.data.current_justified_checkpoint.epoch),
shortLog(state.data.data.current_justified_checkpoint.epoch),
finalizedEpoch =
humaneEpochNum(state.data.data.finalized_checkpoint.epoch)
shortLog(state.data.data.finalized_checkpoint.epoch)
else:
info "Updated head",
stateRoot = shortLog(state.data.root),
headBlockRoot = shortLog(state.blck.root),
stateSlot = humaneSlotNum(state.data.data.slot),
stateSlot = shortLog(state.data.data.slot),
justifiedEpoch =
humaneEpochNum(state.data.data.current_justified_checkpoint.epoch),
shortLog(state.data.data.current_justified_checkpoint.epoch),
finalizedEpoch =
humaneEpochNum(state.data.data.finalized_checkpoint.epoch)
shortLog(state.data.data.finalized_checkpoint.epoch)
let
# TODO there might not be a block at the epoch boundary - what then?
@ -560,9 +560,9 @@ proc updateHead*(pool: BlockPool, state: var StateData, blck: BlockRef) =
if finalizedHead != pool.finalizedHead:
info "Finalized block",
finalizedBlockRoot = shortLog(finalizedHead.blck.root),
finalizedBlockSlot = humaneSlotNum(finalizedHead.slot),
finalizedBlockSlot = shortLog(finalizedHead.slot),
headBlockRoot = shortLog(blck.root),
headBlockSlot = humaneSlotNum(blck.slot)
headBlockSlot = shortLog(blck.slot)
var cur = finalizedHead.blck
while cur != pool.finalizedHead.blck:

View File

@ -497,14 +497,14 @@ proc process_attestation*(
if not (attestation_slot + MIN_ATTESTATION_INCLUSION_DELAY <= stateSlot):
warn("Attestation too new",
attestation_slot = humaneSlotNum(attestation_slot),
state_slot = humaneSlotNum(stateSlot))
attestation_slot = shortLog(attestation_slot),
state_slot = shortLog(stateSlot))
return
if not (stateSlot <= attestation_slot + SLOTS_PER_EPOCH):
warn("Attestation too old",
attestation_slot = humaneSlotNum(attestation_slot),
state_slot = humaneSlotNum(stateSlot))
attestation_slot = shortLog(attestation_slot),
state_slot = shortLog(stateSlot))
return
let pending_attestation = PendingAttestation(

View File

@ -550,10 +550,10 @@ when useListType:
else:
template asSeq*[T; N](x: List[T, N]): auto = x
func humaneSlotNum*(s: Slot): uint64 =
func shortLog*(s: Slot): uint64 =
s - GENESIS_SLOT
func humaneEpochNum*(e: Epoch): uint64 =
func shortLog*(e: Epoch): uint64 =
e - GENESIS_EPOCH
func shortLog*(v: BeaconBlock): tuple[
@ -566,7 +566,7 @@ func shortLog*(v: BeaconBlock): tuple[
transfers_len: int,
signature: string
] = (
humaneSlotNum(v.slot), shortLog(v.parent_root),
shortLog(v.slot), shortLog(v.parent_root),
shortLog(v.state_root), v.body.proposer_slashings.len(),
v.body.attester_slashings.len(), v.body.attestations.len(),
v.body.deposits.len(), v.body.voluntary_exits.len(), v.body.transfers.len(),
@ -576,13 +576,13 @@ func shortLog*(v: BeaconBlock): tuple[
func shortLog*(v: AttestationData): auto =
(
shortLog(v.beacon_block_root),
humaneEpochNum(v.source.epoch), shortLog(v.target.root),
shortLog(v.source.epoch), shortLog(v.target.root),
shortLog(v.source.root),
v.crosslink
)
chronicles.formatIt Slot: it.humaneSlotNum
chronicles.formatIt Epoch: it.humaneEpochNum
chronicles.formatIt Slot: it.shortLog
chronicles.formatIt Epoch: it.shortLog
chronicles.formatIt BeaconBlock: it.shortLog
chronicles.formatIt AttestationData: it.shortLog

View File

@ -44,8 +44,8 @@ proc processBlockHeader(
# Verify that the slots match
if not (blck.slot == state.slot):
notice "Block header: slot mismatch",
block_slot = humaneSlotNum(blck.slot),
state_slot = humaneSlotNum(state.slot)
block_slot = shortLog(blck.slot),
state_slot = shortLog(state.slot)
return false
# Verify that the parent matches
@ -462,37 +462,37 @@ proc processBlock*(
# TODO probably better to do all verification first, then apply state changes
if not processBlockHeader(state, blck, flags, stateCache):
notice "Block header not valid", slot = humaneSlotNum(state.slot)
notice "Block header not valid", slot = shortLog(state.slot)
return false
if not processRandao(state, blck.body, flags, stateCache):
debug "[Block processing] Randao failure", slot = humaneSlotNum(state.slot)
debug "[Block processing] Randao failure", slot = shortLog(state.slot)
return false
processEth1Data(state, blck.body)
if not processProposerSlashings(state, blck, flags, stateCache):
debug "[Block processing] Proposer slashing failure", slot = humaneSlotNum(state.slot)
debug "[Block processing] Proposer slashing failure", slot = shortLog(state.slot)
return false
if not processAttesterSlashings(state, blck, stateCache):
debug "[Block processing] Attester slashing failure", slot = humaneSlotNum(state.slot)
debug "[Block processing] Attester slashing failure", slot = shortLog(state.slot)
return false
if not processAttestations(state, blck, flags, stateCache):
debug "[Block processing] Attestation processing failure", slot = humaneSlotNum(state.slot)
debug "[Block processing] Attestation processing failure", slot = shortLog(state.slot)
return false
if not processDeposits(state, blck):
debug "[Block processing] Deposit processing failure", slot = humaneSlotNum(state.slot)
debug "[Block processing] Deposit processing failure", slot = shortLog(state.slot)
return false
if not processVoluntaryExits(state, blck, flags):
debug "[Block processing] Exit processing failure", slot = humaneSlotNum(state.slot)
debug "[Block processing] Exit processing failure", slot = shortLog(state.slot)
return false
if not processTransfers(state, blck, flags, stateCache):
debug "[Block processing] Transfer processing failure", slot = humaneSlotNum(state.slot)
debug "[Block processing] Transfer processing failure", slot = shortLog(state.slot)
return false
true

View File

@ -58,7 +58,7 @@ func genRandaoReveal*(k: ValidatorPrivKey, state: BeaconState, slot: Slot):
# https://github.com/ethereum/eth2.0-specs/blob/v0.2.0/specs/core/0_beacon-chain.md#randao
# Off-by-one? I often get slot == state.slot but the check was "doAssert slot > state.slot" (Mamy)
doAssert slot >= state.slot, "input slot: " & $humaneSlotNum(slot) & " - beacon state slot: " & $humaneSlotNum(state.slot)
doAssert slot >= state.slot, "input slot: " & $shortLog(slot) & " - beacon state slot: " & $shortLog(state.slot)
bls_sign(k, hash_tree_root(compute_epoch_of_slot(slot).uint64).data,
get_domain(state, DOMAIN_RANDAO, compute_epoch_of_slot(slot)))

View File

@ -34,7 +34,7 @@ template withTimerRet(stats: var RunningStat, body: untyped): untyped =
proc writeJson*(prefix, slot, v: auto) =
var f: File
defer: close(f)
let fileName = fmt"{prefix:04}-{humaneSlotNum(slot):08}.json"
let fileName = fmt"{prefix:04}-{shortLog(slot):08}.json"
Json.saveFile(fileName, v, pretty = true)
cli do(slots = 448,
@ -139,8 +139,8 @@ cli do(slots = 448,
flushFile(stdout)
if (state.slot) mod SLOTS_PER_EPOCH == 0:
echo &" slot: {humaneSlotNum(state.slot)} ",
&"epoch: {humaneEpochNum(state.slot.compute_epoch_of_slot)}"
echo &" slot: {shortLog(state.slot)} ",
&"epoch: {shortLog(state.slot.compute_epoch_of_slot)}"
maybeWrite() # catch that last state as well..