2023-08-27 01:23:45 +00:00
|
|
|
# Nimbus
|
2024-06-14 07:31:08 +00:00
|
|
|
# Copyright (c) 2023-2024 Status Research & Development GmbH
|
2023-08-27 01:23:45 +00:00
|
|
|
# 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.
|
|
|
|
|
|
|
|
import
|
|
|
|
std/[strutils],
|
2024-10-16 01:34:12 +00:00
|
|
|
eth/common/[base, headers, hashes],
|
2023-08-27 01:23:45 +00:00
|
|
|
../beacon_engine,
|
2023-12-08 09:35:50 +00:00
|
|
|
web3/execution_types,
|
2023-08-27 01:23:45 +00:00
|
|
|
chronicles
|
|
|
|
|
|
|
|
{.push gcsafe, raises:[CatchableError].}
|
|
|
|
|
|
|
|
proc exchangeConf*(ben: BeaconEngineRef,
|
|
|
|
conf: TransitionConfigurationV1):
|
|
|
|
TransitionConfigurationV1 =
|
|
|
|
trace "Engine API request received",
|
|
|
|
meth = "exchangeTransitionConfigurationV1",
|
|
|
|
ttd = conf.terminalTotalDifficulty,
|
|
|
|
number = uint64(conf.terminalBlockNumber),
|
|
|
|
blockHash = conf.terminalBlockHash
|
|
|
|
|
|
|
|
let
|
|
|
|
com = ben.com
|
|
|
|
db = com.db
|
|
|
|
ttd = com.ttd
|
|
|
|
|
|
|
|
if ttd.isNone:
|
|
|
|
raise newException(ValueError, "invalid ttd: EL (none) CL ($1)" % [
|
|
|
|
$conf.terminalTotalDifficulty])
|
|
|
|
|
|
|
|
if conf.terminalTotalDifficulty != ttd.get:
|
|
|
|
raise newException(ValueError, "invalid ttd: EL ($1) CL ($2)" % [
|
|
|
|
$ttd.get, $conf.terminalTotalDifficulty])
|
|
|
|
|
|
|
|
let
|
2024-10-16 01:34:12 +00:00
|
|
|
terminalBlockNumber = base.BlockNumber conf.terminalBlockNumber
|
|
|
|
terminalBlockHash = conf.terminalBlockHash
|
2023-08-27 01:23:45 +00:00
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
if terminalBlockHash != default(Hash32):
|
|
|
|
var headerHash: Hash32
|
2023-08-27 01:23:45 +00:00
|
|
|
|
|
|
|
if not db.getBlockHash(terminalBlockNumber, headerHash):
|
|
|
|
raise newException(ValueError, "cannot get terminal block hash, number $1" %
|
|
|
|
[$terminalBlockNumber])
|
|
|
|
|
|
|
|
if terminalBlockHash != headerHash:
|
|
|
|
raise newException(ValueError, "invalid terminal block hash, got $1 want $2" %
|
|
|
|
[$terminalBlockHash, $headerHash])
|
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
var header: Header
|
2023-08-27 01:23:45 +00:00
|
|
|
if not db.getBlockHeader(headerHash, header):
|
|
|
|
raise newException(ValueError, "cannot get terminal block header, hash $1" %
|
|
|
|
[$terminalBlockHash])
|
|
|
|
|
|
|
|
return TransitionConfigurationV1(
|
|
|
|
terminalTotalDifficulty: ttd.get,
|
2024-10-16 01:34:12 +00:00
|
|
|
terminalBlockHash : headerHash,
|
|
|
|
terminalBlockNumber : Quantity(header.number)
|
2023-08-27 01:23:45 +00:00
|
|
|
)
|
|
|
|
|
2024-06-14 07:31:08 +00:00
|
|
|
if terminalBlockNumber != 0'u64:
|
2023-08-27 01:23:45 +00:00
|
|
|
raise newException(ValueError, "invalid terminal block number: $1" % [
|
|
|
|
$terminalBlockNumber])
|
|
|
|
|
2024-10-16 01:34:12 +00:00
|
|
|
if terminalBlockHash != default(Hash32):
|
2023-08-27 01:23:45 +00:00
|
|
|
raise newException(ValueError, "invalid terminal block hash, no terminal header set")
|
|
|
|
|
|
|
|
TransitionConfigurationV1(terminalTotalDifficulty: ttd.get)
|