move head update to storeBlock
when blocks are supplied via rest, this ensures the newly posted head is chosen
This commit is contained in:
parent
5e9625c1be
commit
065d72fb15
|
@ -151,9 +151,11 @@ proc dumpBlock*[T](
|
||||||
proc storeBlock*(
|
proc storeBlock*(
|
||||||
self: var BlockProcessor,
|
self: var BlockProcessor,
|
||||||
signedBlock: ForkySignedBeaconBlock,
|
signedBlock: ForkySignedBeaconBlock,
|
||||||
wallSlot: Slot): Result[BlockRef, BlockError] =
|
wallSlot: Slot, queueTick: Moment = Moment.now(),
|
||||||
|
validationDur = Duration()): Result[BlockRef, BlockError] =
|
||||||
let
|
let
|
||||||
attestationPool = self.consensusManager.attestationPool
|
attestationPool = self.consensusManager.attestationPool
|
||||||
|
startTick = Moment.now()
|
||||||
|
|
||||||
type Trusted = typeof signedBlock.asTrusted()
|
type Trusted = typeof signedBlock.asTrusted()
|
||||||
let blck = self.consensusManager.dag.addRawBlock(
|
let blck = self.consensusManager.dag.addRawBlock(
|
||||||
|
@ -170,6 +172,25 @@ proc storeBlock*(
|
||||||
# was pruned from the ForkChoice.
|
# was pruned from the ForkChoice.
|
||||||
if blck.isErr:
|
if blck.isErr:
|
||||||
return err(blck.error[1])
|
return err(blck.error[1])
|
||||||
|
|
||||||
|
let storeBlockTick = Moment.now()
|
||||||
|
|
||||||
|
# Eagerly update head: the incoming block "should" get selected
|
||||||
|
self.consensusManager[].updateHead(wallSlot)
|
||||||
|
|
||||||
|
let
|
||||||
|
updateHeadTick = Moment.now()
|
||||||
|
queueDur = startTick - queueTick
|
||||||
|
storeBlockDur = storeBlockTick - startTick
|
||||||
|
updateHeadDur = updateHeadTick - storeBlockTick
|
||||||
|
|
||||||
|
beacon_store_block_duration_seconds.observe(storeBlockDur.toFloatSeconds())
|
||||||
|
|
||||||
|
debug "Block processed",
|
||||||
|
localHeadSlot = self.consensusManager.dag.head.slot,
|
||||||
|
blockSlot = blck.get().slot,
|
||||||
|
validationDur, queueDur, storeBlockDur, updateHeadDur
|
||||||
|
|
||||||
ok(blck.get())
|
ok(blck.get())
|
||||||
|
|
||||||
# Event Loop
|
# Event Loop
|
||||||
|
@ -188,30 +209,10 @@ proc processBlock(self: var BlockProcessor, entry: BlockEntry) =
|
||||||
quit 1
|
quit 1
|
||||||
|
|
||||||
let
|
let
|
||||||
startTick = Moment.now()
|
res = withBlck(entry.blck):
|
||||||
res = withBlck(entry.blck): self.storeBlock(blck, wallSlot)
|
self.storeBlock(blck, wallSlot, entry.queueTick, entry.validationDur)
|
||||||
storeBlockTick = Moment.now()
|
|
||||||
|
|
||||||
if res.isOk():
|
if res.isOk() or (res.error() in {BlockError.Duplicate, BlockError.Old}):
|
||||||
# Eagerly update head in case the new block gets selected
|
|
||||||
self.consensusManager[].updateHead(wallSlot)
|
|
||||||
|
|
||||||
let
|
|
||||||
updateHeadTick = Moment.now()
|
|
||||||
queueDur = startTick - entry.queueTick
|
|
||||||
storeBlockDur = storeBlockTick - startTick
|
|
||||||
updateHeadDur = updateHeadTick - storeBlockTick
|
|
||||||
|
|
||||||
beacon_store_block_duration_seconds.observe(storeBlockDur.toFloatSeconds())
|
|
||||||
|
|
||||||
debug "Block processed",
|
|
||||||
localHeadSlot = self.consensusManager.dag.head.slot,
|
|
||||||
blockSlot = entry.blck.slot,
|
|
||||||
validationDur = entry.validationDur,
|
|
||||||
queueDur, storeBlockDur, updateHeadDur
|
|
||||||
|
|
||||||
entry.done()
|
|
||||||
elif res.error() in {BlockError.Duplicate, BlockError.Old}:
|
|
||||||
# Duplicate and old blocks are ok from a sync point of view, so we mark
|
# Duplicate and old blocks are ok from a sync point of view, so we mark
|
||||||
# them as successful
|
# them as successful
|
||||||
entry.done()
|
entry.done()
|
||||||
|
|
Loading…
Reference in New Issue