fix t8n does not support BLOCKHASH opcode

This commit is contained in:
jangko 2022-12-08 02:09:42 +07:00
parent 05584a21b9
commit ed518c760f
No known key found for this signature in database
GPG Key ID: 31702AE10541E6B9
3 changed files with 18 additions and 17 deletions

View File

@ -9,7 +9,7 @@
# according to those terms.
import
".."/[db/accounts_cache],
".."/[db/accounts_cache, constants],
"."/[code_stream, memory, message, stack, state],
"."/[transaction_tracer, types],
./interpreter/[gas_meter, gas_costs, op_codes],
@ -113,11 +113,25 @@ template getGasPrice*(c: Computation): GasInt =
else:
c.vmState.txGasPrice
template getBlockHash*(c: Computation, blockNumber: UInt256): Hash256 =
proc getBlockHash*(c: Computation, number: UInt256): Hash256 =
when evmc_enabled:
c.host.getBlockHash(blockNumber)
let
blockNumber = c.host.getTxContext().block_number.u256
ancestorDepth = blockNumber - number - 1
if ancestorDepth >= constants.MAX_PREV_HEADER_DEPTH:
return
if number >= blockNumber:
return
c.host.getBlockHash(number)
else:
c.vmState.getAncestorHash(blockNumber.vmWordToBlockNumber)
let
blockNumber = c.vmState.blockNumber
ancestorDepth = blockNumber - number - 1
if ancestorDepth >= constants.MAX_PREV_HEADER_DEPTH:
return
if number >= blockNumber:
return
c.vmState.getAncestorHash(number.vmWordToBlockNumber)
template accountExists*(c: Computation, address: EthAddress): bool =
when evmc_enabled:

View File

@ -94,13 +94,6 @@ proc getTxContext*(ctx: HostContext): nimbus_tx_context {.inline.} =
ctx.host.get_tx_context(ctx.context)
proc getBlockHash*(ctx: HostContext, number: UInt256): Hash256 =
let
blockNumber = ctx.getTxContext().block_number.u256
ancestorDepth = blockNumber - number - 1
if ancestorDepth >= constants.MAX_PREV_HEADER_DEPTH:
return
if number >= blockNumber:
return
ctx.host.get_block_hash(ctx.context, number.truncate(int64))
proc accountExists*(ctx: HostContext, address: EthAddress): bool {.inline.} =

View File

@ -309,12 +309,6 @@ when defined(geth):
import db/geth_db
method getAncestorHash*(vmState: BaseVMState, blockNumber: BlockNumber): Hash256 {.base, gcsafe, raises: [Defect,CatchableError,Exception].} =
var ancestorDepth = vmState.blockNumber - blockNumber - 1
if ancestorDepth >= MAX_PREV_HEADER_DEPTH:
return
if blockNumber >= vmState.blockNumber:
return
let db = vmState.com.db
when defined(geth):
result = db.headerHash(blockNumber.truncate(uint64))