mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-02 09:46:26 +00:00
eh fixes (#926)
* work around improbable exceptions in metrics / chronos * fix unnecessary lookup in block pool
This commit is contained in:
parent
7bc18423fa
commit
494ffb63ce
@ -5,6 +5,8 @@
|
|||||||
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
|
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
|
||||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||||
|
|
||||||
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import
|
import
|
||||||
options,
|
options,
|
||||||
./spec/[beaconstate, datatypes, crypto, digest, helpers, validator,
|
./spec/[beaconstate, datatypes, crypto, digest, helpers, validator,
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
# beacon_chain
|
||||||
|
# Copyright (c) 2018-2020 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.
|
||||||
|
|
||||||
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import
|
import
|
||||||
deques, sequtils, tables, options,
|
deques, sequtils, tables, options,
|
||||||
chronicles, stew/[bitseqs, byteutils], json_serialization/std/sets,
|
chronicles, stew/[bitseqs, byteutils], json_serialization/std/sets,
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
|
# beacon_chain
|
||||||
|
# Copyright (c) 2018-2020 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
|
||||||
# Standard library
|
# Standard library
|
||||||
os, tables, random, strutils, times,
|
os, tables, random, strutils, times,
|
||||||
|
@ -1,3 +1,12 @@
|
|||||||
|
# beacon_chain
|
||||||
|
# Copyright (c) 2018-2020 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.
|
||||||
|
|
||||||
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import
|
import
|
||||||
bitops, chronicles, options, tables,
|
bitops, chronicles, options, tables,
|
||||||
ssz, beacon_chain_db, state_transition, extras, kvstore,
|
ssz, beacon_chain_db, state_transition, extras, kvstore,
|
||||||
@ -336,13 +345,13 @@ proc add*(
|
|||||||
logScope: pcs = "block_addition"
|
logScope: pcs = "block_addition"
|
||||||
|
|
||||||
# Already seen this block??
|
# Already seen this block??
|
||||||
if blockRoot in pool.blocks:
|
pool.blocks.withValue(blockRoot, blockRef):
|
||||||
debug "Block already exists",
|
debug "Block already exists",
|
||||||
blck = shortLog(blck),
|
blck = shortLog(blck),
|
||||||
blockRoot = shortLog(blockRoot),
|
blockRoot = shortLog(blockRoot),
|
||||||
cat = "filtering"
|
cat = "filtering"
|
||||||
|
|
||||||
return pool.blocks[blockRoot]
|
return blockRef[]
|
||||||
|
|
||||||
pool.missing.del(blockRoot)
|
pool.missing.del(blockRoot)
|
||||||
|
|
||||||
@ -547,7 +556,7 @@ func checkMissing*(pool: var BlockPool): seq[FetchRecord] =
|
|||||||
|
|
||||||
proc skipAndUpdateState(
|
proc skipAndUpdateState(
|
||||||
state: var HashedBeaconState, slot: Slot,
|
state: var HashedBeaconState, slot: Slot,
|
||||||
afterUpdate: proc (state: HashedBeaconState)) =
|
afterUpdate: proc (state: HashedBeaconState) {.gcsafe.}) =
|
||||||
while state.data.slot < slot:
|
while state.data.slot < slot:
|
||||||
# Process slots one at a time in case afterUpdate needs to see empty states
|
# Process slots one at a time in case afterUpdate needs to see empty states
|
||||||
process_slots(state, state.data.slot + 1)
|
process_slots(state, state.data.slot + 1)
|
||||||
@ -555,7 +564,7 @@ proc skipAndUpdateState(
|
|||||||
|
|
||||||
proc skipAndUpdateState(
|
proc skipAndUpdateState(
|
||||||
state: var HashedBeaconState, signedBlock: SignedBeaconBlock, flags: UpdateFlags,
|
state: var HashedBeaconState, signedBlock: SignedBeaconBlock, flags: UpdateFlags,
|
||||||
afterUpdate: proc (state: HashedBeaconState)): bool =
|
afterUpdate: proc (state: HashedBeaconState) {.gcsafe.}): bool =
|
||||||
|
|
||||||
skipAndUpdateState(state, signedBlock.message.slot - 1, afterUpdate)
|
skipAndUpdateState(state, signedBlock.message.slot - 1, afterUpdate)
|
||||||
|
|
||||||
@ -845,7 +854,10 @@ proc updateHead*(pool: BlockPool, newHead: BlockRef) =
|
|||||||
cat = "fork_choice"
|
cat = "fork_choice"
|
||||||
|
|
||||||
# A reasonable criterion for "reorganizations of the chain"
|
# A reasonable criterion for "reorganizations of the chain"
|
||||||
beacon_reorgs_total.inc()
|
try:
|
||||||
|
beacon_reorgs_total.inc()
|
||||||
|
except Exception as e: # TODO https://github.com/status-im/nim-metrics/pull/22
|
||||||
|
trace "Couldn't update metrics", msg = e.msg
|
||||||
else:
|
else:
|
||||||
info "Updated head block",
|
info "Updated head block",
|
||||||
stateRoot = shortLog(pool.headState.data.root),
|
stateRoot = shortLog(pool.headState.data.root),
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
import
|
import
|
||||||
chronos,
|
chronos,
|
||||||
spec/datatypes
|
spec/datatypes
|
||||||
@ -79,7 +81,13 @@ func saturate*(d: tuple[inFuture: bool, offset: Duration]): Duration =
|
|||||||
if d.inFuture: d.offset else: seconds(0)
|
if d.inFuture: d.offset else: seconds(0)
|
||||||
|
|
||||||
proc addTimer*(fromNow: Duration, cb: CallbackFunc, udata: pointer = nil) =
|
proc addTimer*(fromNow: Duration, cb: CallbackFunc, udata: pointer = nil) =
|
||||||
discard setTimer(Moment.now() + fromNow, cb, udata)
|
try:
|
||||||
|
discard setTimer(Moment.now() + fromNow, cb, udata)
|
||||||
|
except Exception as e:
|
||||||
|
# TODO https://github.com/status-im/nim-chronos/issues/94
|
||||||
|
# shouldn't happen because we should have initialized chronos by now
|
||||||
|
# https://github.com/nim-lang/Nim/issues/10288 - sigh
|
||||||
|
raiseAssert e.msg
|
||||||
|
|
||||||
func shortLog*(d: Duration): string =
|
func shortLog*(d: Duration): string =
|
||||||
let dd = int64(d.milliseconds())
|
let dd = int64(d.milliseconds())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user