mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-13 05:44:40 +00:00
rm obsolete MergeTracker (#2725)
This commit is contained in:
parent
4ae87e6d19
commit
266b72698d
@ -104,12 +104,6 @@ proc forkchoiceUpdated*(ben: BeaconEngineRef,
|
||||
return simpleFCU(PayloadExecutionStatus.syncing)
|
||||
|
||||
# Header advertised via a past newPayload request. Start syncing to it.
|
||||
# Before we do however, make sure any legacy sync in switched off so we
|
||||
# don't accidentally have 2 cycles running.
|
||||
if not ben.ttdReached():
|
||||
ben.reachTTD()
|
||||
# TODO: cancel downloader
|
||||
|
||||
info "Forkchoice requested sync to new head",
|
||||
number = header.number,
|
||||
hash = blockHash.short
|
||||
@ -167,9 +161,6 @@ proc forkchoiceUpdated*(ben: BeaconEngineRef,
|
||||
# chain final and completely in PoS mode.
|
||||
let finalizedBlockHash = ethHash update.finalizedBlockHash
|
||||
if finalizedBlockHash != default(common.Hash256):
|
||||
if not ben.posFinalized:
|
||||
ben.finalizePoS()
|
||||
|
||||
if not ben.chain.isCanonical(finalizedBlockHash):
|
||||
warn "Final block not in canonical chain",
|
||||
hash=finalizedBlockHash.short
|
||||
|
@ -200,11 +200,4 @@ proc newPayload*(ben: BeaconEngineRef,
|
||||
let blockHash = latestValidHash(db, parent, ttd)
|
||||
return invalidStatus(blockHash, vres.error())
|
||||
|
||||
# We've accepted a valid payload from the beacon client. Mark the local
|
||||
# chain transitions to notify other subsystems (e.g. downloader) of the
|
||||
# behavioral change.
|
||||
if not ben.ttdReached():
|
||||
ben.reachTTD()
|
||||
# TODO: cancel downloader
|
||||
|
||||
return validStatus(blockHash)
|
||||
|
@ -13,7 +13,6 @@ import
|
||||
./payload_conv,
|
||||
chronicles,
|
||||
web3/execution_types,
|
||||
./merge_tracker,
|
||||
./payload_queue,
|
||||
./api_handler/api_utils,
|
||||
../db/core_db,
|
||||
@ -27,7 +26,6 @@ export
|
||||
type
|
||||
BeaconEngineRef* = ref object
|
||||
txPool: TxPoolRef
|
||||
merge : MergeTracker
|
||||
queue : PayloadQueue
|
||||
chain : ForkedChainRef
|
||||
|
||||
@ -72,7 +70,7 @@ const
|
||||
# Private helpers
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
proc setWithdrawals(ctx: CasperRef, attrs: PayloadAttributes) =
|
||||
func setWithdrawals(ctx: CasperRef, attrs: PayloadAttributes) =
|
||||
case attrs.version
|
||||
of Version.V2, Version.V3:
|
||||
ctx.withdrawals = ethWithdrawals attrs.withdrawals.get
|
||||
@ -87,7 +85,7 @@ template wrapException(body: untyped): auto =
|
||||
|
||||
# setInvalidAncestor is a callback for the downloader to notify us if a bad block
|
||||
# is encountered during the async sync.
|
||||
proc setInvalidAncestor(ben: BeaconEngineRef,
|
||||
func setInvalidAncestor(ben: BeaconEngineRef,
|
||||
invalid, origin: common.BlockHeader) =
|
||||
ben.invalidTipsets[origin.blockHash] = invalid
|
||||
inc ben.invalidBlocksHits.mgetOrPut(invalid.blockHash, 0)
|
||||
@ -96,12 +94,11 @@ proc setInvalidAncestor(ben: BeaconEngineRef,
|
||||
# Constructors
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
proc new*(_: type BeaconEngineRef,
|
||||
func new*(_: type BeaconEngineRef,
|
||||
txPool: TxPoolRef,
|
||||
chain: ForkedChainRef): BeaconEngineRef =
|
||||
let ben = BeaconEngineRef(
|
||||
txPool: txPool,
|
||||
merge : MergeTracker.init(txPool.com.db),
|
||||
queue : PayloadQueue(),
|
||||
chain : chain,
|
||||
)
|
||||
@ -116,33 +113,23 @@ proc new*(_: type BeaconEngineRef,
|
||||
# Public functions, setters
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
proc reachTTD*(ben: BeaconEngineRef) =
|
||||
## ReachTTD is called whenever the first NewHead message received
|
||||
## from the consensus-layer.
|
||||
ben.merge.reachTTD()
|
||||
|
||||
proc finalizePoS*(ben: BeaconEngineRef) =
|
||||
## FinalizePoS is called whenever the first FinalisedBlock message received
|
||||
## from the consensus-layer.
|
||||
ben.merge.finalizePoS()
|
||||
|
||||
proc put*(ben: BeaconEngineRef,
|
||||
func put*(ben: BeaconEngineRef,
|
||||
hash: common.Hash256, header: common.BlockHeader) =
|
||||
ben.queue.put(hash, header)
|
||||
|
||||
proc put*(ben: BeaconEngineRef, id: PayloadID,
|
||||
func put*(ben: BeaconEngineRef, id: PayloadID,
|
||||
blockValue: UInt256, payload: ExecutionPayload,
|
||||
blobsBundle: Opt[BlobsBundleV1]) =
|
||||
ben.queue.put(id, blockValue, payload, blobsBundle)
|
||||
|
||||
proc put*(ben: BeaconEngineRef, id: PayloadID,
|
||||
func put*(ben: BeaconEngineRef, id: PayloadID,
|
||||
blockValue: UInt256, payload: SomeExecutionPayload,
|
||||
blobsBundle: Opt[BlobsBundleV1]) =
|
||||
doAssert blobsBundle.isNone == (payload is
|
||||
ExecutionPayloadV1 | ExecutionPayloadV2)
|
||||
ben.queue.put(id, blockValue, payload, blobsBundle)
|
||||
|
||||
proc put*(ben: BeaconEngineRef, id: PayloadID,
|
||||
func put*(ben: BeaconEngineRef, id: PayloadID,
|
||||
blockValue: UInt256,
|
||||
payload: ExecutionPayloadV1 | ExecutionPayloadV2) =
|
||||
ben.queue.put(
|
||||
@ -157,41 +144,33 @@ func com*(ben: BeaconEngineRef): CommonRef =
|
||||
func chain*(ben: BeaconEngineRef): ForkedChainRef =
|
||||
ben.chain
|
||||
|
||||
func ttdReached*(ben: BeaconEngineRef): bool =
|
||||
## TTDReached reports whether the chain has left the PoW stage.
|
||||
ben.merge.ttdReached
|
||||
|
||||
func posFinalized*(ben: BeaconEngineRef): bool =
|
||||
## PoSFinalized reports whether the chain has entered the PoS stage.
|
||||
ben.merge.posFinalized
|
||||
|
||||
proc get*(ben: BeaconEngineRef, hash: common.Hash256,
|
||||
func get*(ben: BeaconEngineRef, hash: common.Hash256,
|
||||
header: var common.BlockHeader): bool =
|
||||
ben.queue.get(hash, header)
|
||||
|
||||
proc get*(ben: BeaconEngineRef, id: PayloadID,
|
||||
func get*(ben: BeaconEngineRef, id: PayloadID,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayload,
|
||||
blobsBundle: var Opt[BlobsBundleV1]): bool =
|
||||
ben.queue.get(id, blockValue, payload, blobsBundle)
|
||||
|
||||
proc get*(ben: BeaconEngineRef, id: PayloadID,
|
||||
func get*(ben: BeaconEngineRef, id: PayloadID,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayloadV1): bool =
|
||||
ben.queue.get(id, blockValue, payload)
|
||||
|
||||
proc get*(ben: BeaconEngineRef, id: PayloadID,
|
||||
func get*(ben: BeaconEngineRef, id: PayloadID,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayloadV2): bool =
|
||||
ben.queue.get(id, blockValue, payload)
|
||||
|
||||
proc get*(ben: BeaconEngineRef, id: PayloadID,
|
||||
func get*(ben: BeaconEngineRef, id: PayloadID,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayloadV3,
|
||||
blobsBundle: var BlobsBundleV1): bool =
|
||||
ben.queue.get(id, blockValue, payload, blobsBundle)
|
||||
|
||||
proc get*(ben: BeaconEngineRef, id: PayloadID,
|
||||
func get*(ben: BeaconEngineRef, id: PayloadID,
|
||||
blockValue: var UInt256,
|
||||
payload: var ExecutionPayloadV1OrV2): bool =
|
||||
ben.queue.get(id, blockValue, payload)
|
||||
@ -251,7 +230,7 @@ proc generatePayload*(ben: BeaconEngineRef,
|
||||
blobsBundle: blobsBundle,
|
||||
blockValue: bundle.blockValue)
|
||||
|
||||
proc setInvalidAncestor*(ben: BeaconEngineRef, header: common.BlockHeader, blockHash: common.Hash256) =
|
||||
func setInvalidAncestor*(ben: BeaconEngineRef, header: common.BlockHeader, blockHash: common.Hash256) =
|
||||
ben.invalidBlocksHits[blockHash] = 1
|
||||
ben.invalidTipsets[blockHash] = header
|
||||
|
||||
|
@ -1,100 +0,0 @@
|
||||
# Nimbus
|
||||
# Copyright (c) 2022-2024 Status Research & Development GmbH
|
||||
# Licensed under either of
|
||||
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
|
||||
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
|
||||
# at your option.
|
||||
# This file may not be copied, modified, or distributed except according to
|
||||
# those terms.
|
||||
|
||||
{.push gcsafe, raises: [].}
|
||||
|
||||
import
|
||||
chronicles,
|
||||
eth/rlp,
|
||||
results,
|
||||
../db/[core_db, storage_types]
|
||||
|
||||
type
|
||||
# transitionStatus describes the status of eth1/2 transition. This switch
|
||||
# between modes is a one-way action which is triggered by corresponding
|
||||
# consensus-layer message.
|
||||
TransitionStatus = object
|
||||
# The flag is set when the first NewHead message received
|
||||
leftPoW : bool
|
||||
|
||||
# The flag is set when the first FinalisedBlock message received
|
||||
enteredPoS: bool
|
||||
|
||||
# Merger is an internal help structure used to track the eth1/2
|
||||
# transition status. It's a common structure can be used in both full node
|
||||
# and light client.
|
||||
MergeTracker* = object
|
||||
db : CoreDbRef
|
||||
status: TransitionStatus
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Private helpers
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
proc writeStatus(db: CoreDbRef, status: TransitionStatus) =
|
||||
db.ctx.getKvt.put(transitionStatusKey().toOpenArray(), rlp.encode(status)).isOkOr:
|
||||
raiseAssert "writeStatus(): put() failed " & $$error
|
||||
|
||||
proc readStatus(db: CoreDbRef): TransitionStatus =
|
||||
var bytes = db.ctx.getKvt.get(transitionStatusKey().toOpenArray()).valueOr:
|
||||
EmptyBlob
|
||||
if bytes.len > 0:
|
||||
try:
|
||||
result = rlp.decode(bytes, typeof result)
|
||||
except CatchableError:
|
||||
error "Failed to decode POS transition status"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Constructors
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
proc init*(_: type MergeTracker, db: CoreDbRef): MergeTracker =
|
||||
MergeTracker(
|
||||
db: db,
|
||||
status: db.readStatus()
|
||||
)
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Public functions, setters
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
proc reachTTD*(m: var MergeTracker) =
|
||||
## ReachTTD is called whenever the first NewHead message received
|
||||
## from the consensus-layer.
|
||||
if m.status.leftPoW:
|
||||
return
|
||||
|
||||
m.status = TransitionStatus(leftPoW: true)
|
||||
m.db.writeStatus(m.status)
|
||||
|
||||
info "Left PoW stage"
|
||||
|
||||
proc finalizePoS*(m: var MergeTracker) =
|
||||
## FinalizePoS is called whenever the first FinalisedBlock message received
|
||||
## from the consensus-layer.
|
||||
|
||||
if m.status.enteredPoS:
|
||||
return
|
||||
|
||||
m.status = TransitionStatus(leftPoW: true, enteredPoS: true)
|
||||
m.db.writeStatus(m.status)
|
||||
|
||||
info "Entered PoS stage"
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Public functions, getters
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
func ttdReached*(m: MergeTracker): bool =
|
||||
## TTDReached reports whether the chain has left the PoW stage.
|
||||
m.status.leftPoW
|
||||
|
||||
func posFinalized*(m: MergeTracker): bool =
|
||||
## PoSFinalized reports whether the chain has entered the PoS stage.
|
||||
m.status.enteredPoS
|
Loading…
x
Reference in New Issue
Block a user