Fix proper timing check for bellatrix epoch. (#3807)

This commit is contained in:
Eugene Kabanov 2022-06-28 13:21:16 +03:00 committed by Zahary Karadjov
parent b178999225
commit 725b120bc3
No known key found for this signature in database
GPG Key ID: C8936F8A3073D609
6 changed files with 79 additions and 52 deletions

View File

@ -335,6 +335,15 @@ func shortLog*(v: EpochKey): string =
template setFinalizationCb*(dag: ChainDAGRef, cb: OnFinalizedCallback) =
dag.onFinHappened = cb
template setBlockCb*(dag: ChainDAGRef, cb: OnBlockCallback) =
dag.onBlockAdded = cb
template setHeadCb*(dag: ChainDAGRef, cb: OnHeadCallback) =
dag.onHeadChanged = cb
template setReorgCb*(dag: ChainDAGRef, cb: OnReorgCallback) =
dag.onReorgHappened = cb
func shortLog*(v: EpochRef): string =
# epoch:root when logging epoch, root:slot when logging slot!
if v.isNil():
@ -363,40 +372,36 @@ func blockRef*(key: KeyedBlockRef): BlockRef =
func init*(t: typedesc[HeadChangeInfoObject], slot: Slot, blockRoot: Eth2Digest,
stateRoot: Eth2Digest, epochTransition: bool,
previousDutyDepRoot: Eth2Digest, currentDutyDepRoot: Eth2Digest,
optimistic: Option[bool]): HeadChangeInfoObject =
previousDutyDepRoot: Eth2Digest,
currentDutyDepRoot: Eth2Digest): HeadChangeInfoObject =
HeadChangeInfoObject(
slot: slot,
block_root: blockRoot,
state_root: stateRoot,
epoch_transition: epochTransition,
previous_duty_dependent_root: previousDutyDepRoot,
current_duty_dependent_root: currentDutyDepRoot,
optimistic: optimistic
current_duty_dependent_root: currentDutyDepRoot
)
func init*(t: typedesc[ReorgInfoObject], slot: Slot, depth: uint64,
oldHeadBlockRoot: Eth2Digest, newHeadBlockRoot: Eth2Digest,
oldHeadStateRoot: Eth2Digest, newHeadStateRoot: Eth2Digest,
optimistic: Option[bool]): ReorgInfoObject =
oldHeadStateRoot: Eth2Digest,
newHeadStateRoot: Eth2Digest): ReorgInfoObject =
ReorgInfoObject(
slot: slot,
depth: depth,
old_head_block: oldHeadBlockRoot,
new_head_block: newHeadBlockRoot,
old_head_state: oldHeadStateRoot,
new_head_state: newHeadStateRoot,
optimistic: optimistic
new_head_state: newHeadStateRoot
)
func init*(t: typedesc[FinalizationInfoObject], blockRoot: Eth2Digest,
stateRoot: Eth2Digest, epoch: Epoch,
optimistic: Option[bool]): FinalizationInfoObject =
stateRoot: Eth2Digest, epoch: Epoch): FinalizationInfoObject =
FinalizationInfoObject(
block_root: blockRoot,
state_root: stateRoot,
epoch: epoch,
optimistic: optimistic
epoch: epoch
)
func init*(t: typedesc[EventBeaconBlockObject],

View File

@ -1624,13 +1624,10 @@ proc updateHead*(
if not(isNil(dag.onReorgHappened)):
let
# TODO (cheatfate): Proper implementation required
optimistic =
if dag.getHeadStateMergeComplete(): some(false) else: none[bool]()
data = ReorgInfoObject.init(dag.head.slot, uint64(ancestorDepth),
lastHead.root, newHead.root,
lastHeadStateRoot,
getStateRoot(dag.headState),
optimistic)
getStateRoot(dag.headState))
dag.onReorgHappened(data)
# A reasonable criterion for "reorganizations of the chain"
@ -1652,12 +1649,10 @@ proc updateHead*(
prevDepRoot = withState(dag.headState): state.attester_dependent_root
epochTransition = (finalizedHead != dag.finalizedHead)
# TODO (cheatfate): Proper implementation required
optimistic =
if dag.getHeadStateMergeComplete(): some(false) else: none[bool]()
data = HeadChangeInfoObject.init(dag.head.slot, dag.head.root,
getStateRoot(dag.headState),
epochTransition, depRoot,
prevDepRoot, optimistic)
prevDepRoot)
dag.onHeadChanged(data)
withState(dag.headState):
@ -1717,12 +1712,8 @@ proc updateHead*(
else:
Eth2Digest() # The thing that finalized was >8192 blocks old?
# TODO (cheatfate): Proper implementation required
let optimistic =
if dag.getHeadStateMergeComplete(): some(false) else: none[bool]()
let data = FinalizationInfoObject.init(
dag.finalizedHead.blck.root, stateRoot, dag.finalizedHead.slot.epoch,
optimistic)
dag.finalizedHead.blck.root, stateRoot, dag.finalizedHead.slot.epoch)
dag.onFinHappened(dag, data)
proc isInitialized*(T: type ChainDAGRef, db: BeaconChainDB): Result[void, cstring] =

View File

@ -152,21 +152,8 @@ proc loadChainDag(
eventBus: EventBus,
validatorMonitor: ref ValidatorMonitor,
networkGenesisValidatorsRoot: Option[Eth2Digest]): ChainDAGRef =
var dag: ChainDAGRef
info "Loading block DAG from database", path = config.databaseDir
proc onBlockAdded(data: ForkedTrustedSignedBeaconBlock) =
# TODO (cheatfate): Proper implementation required
let optimistic =
if isNil(dag):
none[bool]()
else:
if dag.getHeadStateMergeComplete(): some(false) else: none[bool]()
eventBus.blocksQueue.emit(EventBeaconBlockObject.init(data, optimistic))
proc onHeadChanged(data: HeadChangeInfoObject) =
eventBus.headQueue.emit(data)
proc onChainReorg(data: ReorgInfoObject) =
eventBus.reorgQueue.emit(data)
proc onLightClientFinalityUpdate(data: altair.LightClientFinalityUpdate) =
eventBus.finUpdateQueue.emit(data)
proc onLightClientOptimisticUpdate(data: altair.LightClientOptimisticUpdate) =
@ -183,16 +170,14 @@ proc loadChainDag(
if config.lightClientDataServe.get: onLightClientOptimisticUpdate
else: nil
dag = ChainDAGRef.init(
cfg, db, validatorMonitor, chainDagFlags, config.eraDir,
onBlockAdded, onHeadChanged, onChainReorg,
onLCFinalityUpdateCb = onLightClientFinalityUpdateCb,
onLCOptimisticUpdateCb = onLightClientOptimisticUpdateCb,
lightClientDataServe = config.lightClientDataServe.get,
lightClientDataImportMode = config.lightClientDataImportMode.get,
vanityLogs = getPandas(detectTTY(config.logStdout)))
dag = ChainDAGRef.init(
cfg, db, validatorMonitor, chainDagFlags, config.eraDir,
onLCFinalityUpdateCb = onLightClientFinalityUpdateCb,
onLCOptimisticUpdateCb = onLightClientOptimisticUpdateCb,
lightClientDataServe = config.lightClientDataServe.get,
lightClientDataImportMode = config.lightClientDataImportMode.get,
vanityLogs = getPandas(detectTTY(config.logStdout)))
let
databaseGenesisValidatorsRoot =
getStateField(dag.headState, genesis_validators_root)
@ -235,6 +220,35 @@ proc initFullNode(
node.eventBus.contribQueue.emit(data)
proc onVoluntaryExitAdded(data: SignedVoluntaryExit) =
node.eventBus.exitQueue.emit(data)
proc onBlockAdded(data: ForkedTrustedSignedBeaconBlock) =
# TODO (cheatfate): Proper implementation required
let optimistic =
if node.currentSlot().epoch() >= dag.cfg.BELLATRIX_FORK_EPOCH:
some(false)
else:
none[bool]()
node.eventBus.blocksQueue.emit(
EventBeaconBlockObject.init(data, optimistic))
proc onHeadChanged(data: HeadChangeInfoObject) =
# TODO (cheatfate): Proper implementation required
let eventData =
if node.currentSlot().epoch() >= dag.cfg.BELLATRIX_FORK_EPOCH:
var res = data
res.optimistic = some(false)
res
else:
data
node.eventBus.headQueue.emit(eventData)
proc onChainReorg(data: ReorgInfoObject) =
# TODO (cheatfate): Proper implementation required
let eventData =
if node.currentSlot().epoch() >= dag.cfg.BELLATRIX_FORK_EPOCH:
var res = data
res.optimistic = some(false)
res
else:
data
node.eventBus.reorgQueue.emit(eventData)
proc makeOnFinalizationCb(
# This `nimcall` functions helps for keeping track of what
# needs to be captured by the onFinalization closure.
@ -248,7 +262,15 @@ proc initFullNode(
finalizedEpochRef.eth1_data,
finalizedEpochRef.eth1_deposit_index)
node.updateLightClientFromDag()
eventBus.finalQueue.emit(data)
# TODO (cheatfate): Proper implementation required
let eventData =
if node.currentSlot().epoch() >= dag.cfg.BELLATRIX_FORK_EPOCH:
var res = data
res.optimistic = some(false)
res
else:
data
eventBus.finalQueue.emit(eventData)
func getLocalHeadSlot(): Slot =
dag.head.slot
@ -305,6 +327,9 @@ proc initFullNode(
getFrontfillSlot, dag.backfill.slot, blockVerifier, maxHeadAge = 0)
dag.setFinalizationCb makeOnFinalizationCb(node.eventBus, node.eth1Monitor)
dag.setBlockCb(onBlockAdded)
dag.setHeadCb(onHeadChanged)
dag.setReorgCb(onChainReorg)
node.dag = dag
node.quarantine = quarantine

View File

@ -263,7 +263,7 @@ proc installNodeApiHandlers*(router: var RestRouter, node: BeaconNode) =
else:
node.syncManager.inProgress
isOptimistic =
if node.dag.getHeadStateMergeComplete():
if node.currentSlot().epoch() >= node.dag.cfg.BELLATRIX_FORK_EPOCH:
# TODO (cheatfate): Proper implementation required
some(false)
else:

View File

@ -274,7 +274,7 @@ proc getRouter*(allowedOrigin: Option[string]): RestRouter =
proc getStateOptimistic*(node: BeaconNode,
state: ForkedHashedBeaconState): Option[bool] =
if node.dag.getHeadStateMergeComplete():
if node.currentSlot().epoch() >= node.dag.cfg.BELLATRIX_FORK_EPOCH:
case state.kind
of BeaconStateFork.Phase0, BeaconStateFork.Altair:
some[bool](false)
@ -287,7 +287,7 @@ proc getStateOptimistic*(node: BeaconNode,
proc getBlockOptimistic*(node: BeaconNode,
blck: ForkedTrustedSignedBeaconBlock |
ForkedSignedBeaconBlock): Option[bool] =
if node.dag.getHeadStateMergeComplete():
if node.currentSlot().epoch() >= node.dag.cfg.BELLATRIX_FORK_EPOCH:
case blck.kind
of BeaconBlockFork.Phase0, BeaconBlockFork.Altair:
some[bool](false)

View File

@ -99,7 +99,10 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
# TODO (cheatfate): Proper implementation required
let optimistic =
if node.dag.getHeadStateMergeComplete(): some(false) else: none[bool]()
if node.currentSlot().epoch() >= node.dag.cfg.BELLATRIX_FORK_EPOCH:
some(false)
else:
none[bool]()
return RestApiResponse.jsonResponseWRoot(
duties, epochRef.attester_dependent_root, optimistic)
@ -150,7 +153,10 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
# TODO (cheatfate): Proper implementation required
let optimistic =
if node.dag.getHeadStateMergeComplete(): some(false) else: none[bool]()
if node.currentSlot().epoch() >= node.dag.cfg.BELLATRIX_FORK_EPOCH:
some(false)
else:
none[bool]()
return RestApiResponse.jsonResponseWRoot(
duties, epochRef.proposer_dependent_root, optimistic)