rm obsolete MergeTracker (#2725)

This commit is contained in:
tersec 2024-10-10 13:25:12 +00:00 committed by GitHub
parent 4ae87e6d19
commit 266b72698d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 14 additions and 151 deletions

View File

@ -104,12 +104,6 @@ proc forkchoiceUpdated*(ben: BeaconEngineRef,
return simpleFCU(PayloadExecutionStatus.syncing) return simpleFCU(PayloadExecutionStatus.syncing)
# Header advertised via a past newPayload request. Start syncing to it. # 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", info "Forkchoice requested sync to new head",
number = header.number, number = header.number,
hash = blockHash.short hash = blockHash.short
@ -167,9 +161,6 @@ proc forkchoiceUpdated*(ben: BeaconEngineRef,
# chain final and completely in PoS mode. # chain final and completely in PoS mode.
let finalizedBlockHash = ethHash update.finalizedBlockHash let finalizedBlockHash = ethHash update.finalizedBlockHash
if finalizedBlockHash != default(common.Hash256): if finalizedBlockHash != default(common.Hash256):
if not ben.posFinalized:
ben.finalizePoS()
if not ben.chain.isCanonical(finalizedBlockHash): if not ben.chain.isCanonical(finalizedBlockHash):
warn "Final block not in canonical chain", warn "Final block not in canonical chain",
hash=finalizedBlockHash.short hash=finalizedBlockHash.short

View File

@ -200,11 +200,4 @@ proc newPayload*(ben: BeaconEngineRef,
let blockHash = latestValidHash(db, parent, ttd) let blockHash = latestValidHash(db, parent, ttd)
return invalidStatus(blockHash, vres.error()) 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) return validStatus(blockHash)

View File

@ -13,7 +13,6 @@ import
./payload_conv, ./payload_conv,
chronicles, chronicles,
web3/execution_types, web3/execution_types,
./merge_tracker,
./payload_queue, ./payload_queue,
./api_handler/api_utils, ./api_handler/api_utils,
../db/core_db, ../db/core_db,
@ -27,7 +26,6 @@ export
type type
BeaconEngineRef* = ref object BeaconEngineRef* = ref object
txPool: TxPoolRef txPool: TxPoolRef
merge : MergeTracker
queue : PayloadQueue queue : PayloadQueue
chain : ForkedChainRef chain : ForkedChainRef
@ -72,7 +70,7 @@ const
# Private helpers # Private helpers
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
proc setWithdrawals(ctx: CasperRef, attrs: PayloadAttributes) = func setWithdrawals(ctx: CasperRef, attrs: PayloadAttributes) =
case attrs.version case attrs.version
of Version.V2, Version.V3: of Version.V2, Version.V3:
ctx.withdrawals = ethWithdrawals attrs.withdrawals.get 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 # setInvalidAncestor is a callback for the downloader to notify us if a bad block
# is encountered during the async sync. # is encountered during the async sync.
proc setInvalidAncestor(ben: BeaconEngineRef, func setInvalidAncestor(ben: BeaconEngineRef,
invalid, origin: common.BlockHeader) = invalid, origin: common.BlockHeader) =
ben.invalidTipsets[origin.blockHash] = invalid ben.invalidTipsets[origin.blockHash] = invalid
inc ben.invalidBlocksHits.mgetOrPut(invalid.blockHash, 0) inc ben.invalidBlocksHits.mgetOrPut(invalid.blockHash, 0)
@ -96,12 +94,11 @@ proc setInvalidAncestor(ben: BeaconEngineRef,
# Constructors # Constructors
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
proc new*(_: type BeaconEngineRef, func new*(_: type BeaconEngineRef,
txPool: TxPoolRef, txPool: TxPoolRef,
chain: ForkedChainRef): BeaconEngineRef = chain: ForkedChainRef): BeaconEngineRef =
let ben = BeaconEngineRef( let ben = BeaconEngineRef(
txPool: txPool, txPool: txPool,
merge : MergeTracker.init(txPool.com.db),
queue : PayloadQueue(), queue : PayloadQueue(),
chain : chain, chain : chain,
) )
@ -116,33 +113,23 @@ proc new*(_: type BeaconEngineRef,
# Public functions, setters # Public functions, setters
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
proc reachTTD*(ben: BeaconEngineRef) = func put*(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,
hash: common.Hash256, header: common.BlockHeader) = hash: common.Hash256, header: common.BlockHeader) =
ben.queue.put(hash, header) ben.queue.put(hash, header)
proc put*(ben: BeaconEngineRef, id: PayloadID, func put*(ben: BeaconEngineRef, id: PayloadID,
blockValue: UInt256, payload: ExecutionPayload, blockValue: UInt256, payload: ExecutionPayload,
blobsBundle: Opt[BlobsBundleV1]) = blobsBundle: Opt[BlobsBundleV1]) =
ben.queue.put(id, blockValue, payload, blobsBundle) ben.queue.put(id, blockValue, payload, blobsBundle)
proc put*(ben: BeaconEngineRef, id: PayloadID, func put*(ben: BeaconEngineRef, id: PayloadID,
blockValue: UInt256, payload: SomeExecutionPayload, blockValue: UInt256, payload: SomeExecutionPayload,
blobsBundle: Opt[BlobsBundleV1]) = blobsBundle: Opt[BlobsBundleV1]) =
doAssert blobsBundle.isNone == (payload is doAssert blobsBundle.isNone == (payload is
ExecutionPayloadV1 | ExecutionPayloadV2) ExecutionPayloadV1 | ExecutionPayloadV2)
ben.queue.put(id, blockValue, payload, blobsBundle) ben.queue.put(id, blockValue, payload, blobsBundle)
proc put*(ben: BeaconEngineRef, id: PayloadID, func put*(ben: BeaconEngineRef, id: PayloadID,
blockValue: UInt256, blockValue: UInt256,
payload: ExecutionPayloadV1 | ExecutionPayloadV2) = payload: ExecutionPayloadV1 | ExecutionPayloadV2) =
ben.queue.put( ben.queue.put(
@ -157,41 +144,33 @@ func com*(ben: BeaconEngineRef): CommonRef =
func chain*(ben: BeaconEngineRef): ForkedChainRef = func chain*(ben: BeaconEngineRef): ForkedChainRef =
ben.chain ben.chain
func ttdReached*(ben: BeaconEngineRef): bool = func get*(ben: BeaconEngineRef, hash: common.Hash256,
## 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,
header: var common.BlockHeader): bool = header: var common.BlockHeader): bool =
ben.queue.get(hash, header) ben.queue.get(hash, header)
proc get*(ben: BeaconEngineRef, id: PayloadID, func get*(ben: BeaconEngineRef, id: PayloadID,
blockValue: var UInt256, blockValue: var UInt256,
payload: var ExecutionPayload, payload: var ExecutionPayload,
blobsBundle: var Opt[BlobsBundleV1]): bool = blobsBundle: var Opt[BlobsBundleV1]): bool =
ben.queue.get(id, blockValue, payload, blobsBundle) ben.queue.get(id, blockValue, payload, blobsBundle)
proc get*(ben: BeaconEngineRef, id: PayloadID, func get*(ben: BeaconEngineRef, id: PayloadID,
blockValue: var UInt256, blockValue: var UInt256,
payload: var ExecutionPayloadV1): bool = payload: var ExecutionPayloadV1): bool =
ben.queue.get(id, blockValue, payload) ben.queue.get(id, blockValue, payload)
proc get*(ben: BeaconEngineRef, id: PayloadID, func get*(ben: BeaconEngineRef, id: PayloadID,
blockValue: var UInt256, blockValue: var UInt256,
payload: var ExecutionPayloadV2): bool = payload: var ExecutionPayloadV2): bool =
ben.queue.get(id, blockValue, payload) ben.queue.get(id, blockValue, payload)
proc get*(ben: BeaconEngineRef, id: PayloadID, func get*(ben: BeaconEngineRef, id: PayloadID,
blockValue: var UInt256, blockValue: var UInt256,
payload: var ExecutionPayloadV3, payload: var ExecutionPayloadV3,
blobsBundle: var BlobsBundleV1): bool = blobsBundle: var BlobsBundleV1): bool =
ben.queue.get(id, blockValue, payload, blobsBundle) ben.queue.get(id, blockValue, payload, blobsBundle)
proc get*(ben: BeaconEngineRef, id: PayloadID, func get*(ben: BeaconEngineRef, id: PayloadID,
blockValue: var UInt256, blockValue: var UInt256,
payload: var ExecutionPayloadV1OrV2): bool = payload: var ExecutionPayloadV1OrV2): bool =
ben.queue.get(id, blockValue, payload) ben.queue.get(id, blockValue, payload)
@ -251,7 +230,7 @@ proc generatePayload*(ben: BeaconEngineRef,
blobsBundle: blobsBundle, blobsBundle: blobsBundle,
blockValue: bundle.blockValue) 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.invalidBlocksHits[blockHash] = 1
ben.invalidTipsets[blockHash] = header ben.invalidTipsets[blockHash] = header

View File

@ -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