move ttd from vm/state to chain_db
This commit is contained in:
parent
9a1c8fc779
commit
73e28694b5
|
@ -58,6 +58,12 @@ proc newBaseChainDB*(
|
||||||
proc `$`*(db: BaseChainDB): string =
|
proc `$`*(db: BaseChainDB): string =
|
||||||
result = "BaseChainDB"
|
result = "BaseChainDB"
|
||||||
|
|
||||||
|
proc ttd*(db: BaseChainDB): DifficultyInt =
|
||||||
|
if db.config.terminalTotalDifficulty.isSome:
|
||||||
|
db.config.terminalTotalDifficulty.get()
|
||||||
|
else:
|
||||||
|
high(DifficultyInt)
|
||||||
|
|
||||||
proc networkParams*(db: BaseChainDB): NetworkParams =
|
proc networkParams*(db: BaseChainDB): NetworkParams =
|
||||||
NetworkParams(config: db.config, genesis: db.genesis)
|
NetworkParams(config: db.config, genesis: db.genesis)
|
||||||
|
|
||||||
|
|
|
@ -44,9 +44,9 @@ template safeExecutor(info: string; code: untyped) =
|
||||||
let e = getCurrentException()
|
let e = getCurrentException()
|
||||||
raise newException(VmStateError, info & "(): " & $e.name & " -- " & e.msg)
|
raise newException(VmStateError, info & "(): " & $e.name & " -- " & e.msg)
|
||||||
|
|
||||||
proc getMinerAddress(chainDB: BaseChainDB; header: BlockHeader): EthAddress
|
proc getMinerAddress(chainDB: BaseChainDB; header: BlockHeader, ttdReached: bool): EthAddress
|
||||||
{.gcsafe, raises: [Defect,CatchableError].} =
|
{.gcsafe, raises: [Defect,CatchableError].} =
|
||||||
if not chainDB.config.poaEngine:
|
if not chainDB.config.poaEngine or ttdReached:
|
||||||
return header.coinbase
|
return header.coinbase
|
||||||
|
|
||||||
let account = header.ecRecover
|
let account = header.ecRecover
|
||||||
|
@ -195,12 +195,6 @@ proc reinit*(self: BaseVMState; ## Object descriptor
|
||||||
return true
|
return true
|
||||||
# else: false
|
# else: false
|
||||||
|
|
||||||
proc ttd(chainDB: BaseChainDB): DifficultyInt =
|
|
||||||
if chainDB.config.terminalTotalDifficulty.isSome:
|
|
||||||
chainDB.config.terminalTotalDifficulty.get()
|
|
||||||
else:
|
|
||||||
high(DifficultyInt)
|
|
||||||
|
|
||||||
proc reinit*(self: BaseVMState; ## Object descriptor
|
proc reinit*(self: BaseVMState; ## Object descriptor
|
||||||
parent: BlockHeader; ## parent header, account sync pos.
|
parent: BlockHeader; ## parent header, account sync pos.
|
||||||
header: BlockHeader; ## header with tx environment data fields
|
header: BlockHeader; ## header with tx environment data fields
|
||||||
|
@ -213,13 +207,15 @@ proc reinit*(self: BaseVMState; ## Object descriptor
|
||||||
## It requires the `header` argument properly initalised so that for PoA
|
## It requires the `header` argument properly initalised so that for PoA
|
||||||
## networks, the miner address is retrievable via `ecRecover()`.
|
## networks, the miner address is retrievable via `ecRecover()`.
|
||||||
let ttdReached = self.chainDB.totalDifficulty + header.difficulty > self.chainDB.ttd
|
let ttdReached = self.chainDB.totalDifficulty + header.difficulty > self.chainDB.ttd
|
||||||
|
let miner = self.chainDB.getMinerAddress(header, ttdReached)
|
||||||
|
|
||||||
self.reinit(
|
self.reinit(
|
||||||
parent = parent,
|
parent = parent,
|
||||||
timestamp = header.timestamp,
|
timestamp = header.timestamp,
|
||||||
gasLimit = header.gasLimit,
|
gasLimit = header.gasLimit,
|
||||||
fee = header.fee,
|
fee = header.fee,
|
||||||
prevRandao= header.prevRandao,
|
prevRandao= header.prevRandao,
|
||||||
miner = self.chainDB.getMinerAddress(header),
|
miner = miner,
|
||||||
ttdReached= ttdReached,
|
ttdReached= ttdReached,
|
||||||
pruneTrie = pruneTrie)
|
pruneTrie = pruneTrie)
|
||||||
|
|
||||||
|
@ -252,13 +248,14 @@ proc init*(
|
||||||
## It requires the `header` argument properly initalised so that for PoA
|
## It requires the `header` argument properly initalised so that for PoA
|
||||||
## networks, the miner address is retrievable via `ecRecover()`.
|
## networks, the miner address is retrievable via `ecRecover()`.
|
||||||
let ttdReached = chainDB.totalDifficulty + header.difficulty > chainDB.ttd
|
let ttdReached = chainDB.totalDifficulty + header.difficulty > chainDB.ttd
|
||||||
|
let miner = chainDB.getMinerAddress(header, ttdReached)
|
||||||
self.init(AccountsCache.init(chainDB.db, parent.stateRoot, pruneTrie),
|
self.init(AccountsCache.init(chainDB.db, parent.stateRoot, pruneTrie),
|
||||||
parent,
|
parent,
|
||||||
header.timestamp,
|
header.timestamp,
|
||||||
header.gasLimit,
|
header.gasLimit,
|
||||||
header.fee,
|
header.fee,
|
||||||
header.prevRandao,
|
header.prevRandao,
|
||||||
chainDB.getMinerAddress(header),
|
miner,
|
||||||
chainDB,
|
chainDB,
|
||||||
ttdReached,
|
ttdReached,
|
||||||
tracerFlags)
|
tracerFlags)
|
||||||
|
|
|
@ -24,7 +24,7 @@ import
|
||||||
# a temporary solution until nim-eth bumped
|
# a temporary solution until nim-eth bumped
|
||||||
when not compiles(common.prevRandao):
|
when not compiles(common.prevRandao):
|
||||||
import ../merge/eth_common_overload
|
import ../merge/eth_common_overload
|
||||||
|
|
||||||
{.push raises: [Defect].}
|
{.push raises: [Defect].}
|
||||||
|
|
||||||
const
|
const
|
||||||
|
@ -43,9 +43,9 @@ template safeExecutor(info: string; code: untyped) =
|
||||||
let e = getCurrentException()
|
let e = getCurrentException()
|
||||||
raise newException(VmStateError, info & "(): " & $e.name & " -- " & e.msg)
|
raise newException(VmStateError, info & "(): " & $e.name & " -- " & e.msg)
|
||||||
|
|
||||||
proc getMinerAddress(chainDB: BaseChainDB; header: BlockHeader): EthAddress
|
proc getMinerAddress(chainDB: BaseChainDB; header: BlockHeader, ttdReached: bool): EthAddress
|
||||||
{.gcsafe, raises: [Defect,CatchableError].} =
|
{.gcsafe, raises: [Defect,CatchableError].} =
|
||||||
if not chainDB.config.poaEngine:
|
if not chainDB.config.poaEngine or ttdReached:
|
||||||
return header.coinbase
|
return header.coinbase
|
||||||
|
|
||||||
let account = header.ecRecover
|
let account = header.ecRecover
|
||||||
|
@ -194,12 +194,6 @@ proc reinit*(self: BaseVMState; ## Object descriptor
|
||||||
return true
|
return true
|
||||||
# else: false
|
# else: false
|
||||||
|
|
||||||
proc ttd(chainDB: BaseChainDB): DifficultyInt =
|
|
||||||
if chainDB.config.terminalTotalDifficulty.isSome:
|
|
||||||
chainDB.config.terminalTotalDifficulty.get()
|
|
||||||
else:
|
|
||||||
high(DifficultyInt)
|
|
||||||
|
|
||||||
proc reinit*(self: BaseVMState; ## Object descriptor
|
proc reinit*(self: BaseVMState; ## Object descriptor
|
||||||
parent: BlockHeader; ## parent header, account sync pos.
|
parent: BlockHeader; ## parent header, account sync pos.
|
||||||
header: BlockHeader; ## header with tx environment data fields
|
header: BlockHeader; ## header with tx environment data fields
|
||||||
|
@ -212,13 +206,14 @@ proc reinit*(self: BaseVMState; ## Object descriptor
|
||||||
## It requires the `header` argument properly initalised so that for PoA
|
## It requires the `header` argument properly initalised so that for PoA
|
||||||
## networks, the miner address is retrievable via `ecRecover()`.
|
## networks, the miner address is retrievable via `ecRecover()`.
|
||||||
let ttdReached = self.chainDB.totalDifficulty + header.difficulty > self.chainDB.ttd
|
let ttdReached = self.chainDB.totalDifficulty + header.difficulty > self.chainDB.ttd
|
||||||
|
let miner = self.chainDB.getMinerAddress(header, ttdReached)
|
||||||
self.reinit(
|
self.reinit(
|
||||||
parent = parent,
|
parent = parent,
|
||||||
timestamp = header.timestamp,
|
timestamp = header.timestamp,
|
||||||
gasLimit = header.gasLimit,
|
gasLimit = header.gasLimit,
|
||||||
fee = header.fee,
|
fee = header.fee,
|
||||||
prevRandao= header.prevRandao,
|
prevRandao= header.prevRandao,
|
||||||
miner = self.chainDB.getMinerAddress(header),
|
miner = miner,
|
||||||
ttdReached= ttdReached,
|
ttdReached= ttdReached,
|
||||||
pruneTrie = pruneTrie)
|
pruneTrie = pruneTrie)
|
||||||
|
|
||||||
|
@ -251,13 +246,14 @@ proc init*(
|
||||||
## It requires the `header` argument properly initalised so that for PoA
|
## It requires the `header` argument properly initalised so that for PoA
|
||||||
## networks, the miner address is retrievable via `ecRecover()`.
|
## networks, the miner address is retrievable via `ecRecover()`.
|
||||||
let ttdReached = chainDB.totalDifficulty + header.difficulty > chainDB.ttd
|
let ttdReached = chainDB.totalDifficulty + header.difficulty > chainDB.ttd
|
||||||
|
let miner = chainDB.getMinerAddress(header, ttdReached)
|
||||||
self.init(AccountsCache.init(chainDB.db, parent.stateRoot, pruneTrie),
|
self.init(AccountsCache.init(chainDB.db, parent.stateRoot, pruneTrie),
|
||||||
parent,
|
parent,
|
||||||
header.timestamp,
|
header.timestamp,
|
||||||
header.gasLimit,
|
header.gasLimit,
|
||||||
header.fee,
|
header.fee,
|
||||||
header.prevRandao,
|
header.prevRandao,
|
||||||
chainDB.getMinerAddress(header),
|
miner,
|
||||||
chainDB,
|
chainDB,
|
||||||
ttdReached,
|
ttdReached,
|
||||||
tracerFlags)
|
tracerFlags)
|
||||||
|
|
Loading…
Reference in New Issue