mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-24 19:19:21 +00:00
move fork and gasCosts from Computation to vmState
This commit is contained in:
parent
bab359cabf
commit
c1ef8632b2
@ -283,8 +283,6 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) =
|
||||
kind: if contractCreation: evmcCreate else: evmcCall,
|
||||
depth: 0,
|
||||
gas: gasLimit,
|
||||
gasPrice: gasPrice,
|
||||
origin: sender,
|
||||
sender: sender,
|
||||
contractAddress: destination,
|
||||
codeAddress: CREATE_CONTRACT_ADDRESS,
|
||||
@ -292,6 +290,12 @@ proc setupEthRpc*(node: EthereumNode, chain: BaseChainDB, rpcsrv: RpcServer) =
|
||||
data: data,
|
||||
code: vmState.readOnlyStateDB.getCode(destination).toSeq
|
||||
)
|
||||
|
||||
vmState.txContext(
|
||||
origin = sender,
|
||||
gasPrice = gasPrice
|
||||
)
|
||||
|
||||
result = newComputation(vmState, message)
|
||||
|
||||
rpcsrv.rpc("eth_call") do(call: EthCall, quantityTag: string) -> HexDataStr:
|
||||
|
@ -17,7 +17,7 @@ import
|
||||
logScope:
|
||||
topics = "vm computation"
|
||||
|
||||
proc newComputation*(vmState: BaseVMState, message: Message, forkOverride=none(Fork)): Computation =
|
||||
proc newComputation*(vmState: BaseVMState, message: Message): Computation =
|
||||
new result
|
||||
result.vmState = vmState
|
||||
result.msg = message
|
||||
@ -27,16 +27,16 @@ proc newComputation*(vmState: BaseVMState, message: Message, forkOverride=none(F
|
||||
result.touchedAccounts = initHashSet[EthAddress]()
|
||||
result.suicides = initHashSet[EthAddress]()
|
||||
result.code = newCodeStream(message.code)
|
||||
result.fork =
|
||||
if forkOverride.isSome:
|
||||
forkOverride.get
|
||||
else:
|
||||
vmState.blockNumber.toFork
|
||||
result.gasCosts = result.fork.forkToSchedule
|
||||
# a dummy/terminus continuation proc
|
||||
result.nextProc = proc() =
|
||||
discard
|
||||
|
||||
template gasCosts*(c: Computation): untyped =
|
||||
c.vmState.gasCosts
|
||||
|
||||
template fork*(c: Computation): untyped =
|
||||
c.vmState.fork
|
||||
|
||||
proc isOriginComputation*(c: Computation): bool =
|
||||
# Is this computation the computation initiated by a transaction
|
||||
c.msg.sender == c.vmState.txOrigin
|
||||
|
@ -577,7 +577,7 @@ proc setupCreate(c: Computation, memPos, len: int, value: Uint256, opCode: stati
|
||||
code: callData
|
||||
)
|
||||
|
||||
result = newComputation(c.vmState, childMsg, some(c.fork))
|
||||
result = newComputation(c.vmState, childMsg)
|
||||
|
||||
template genCreate(callName: untyped, opCode: Op): untyped =
|
||||
op callName, inline = false, val, startPosition, size:
|
||||
@ -755,7 +755,7 @@ template genCall(callName: untyped, opCode: Op): untyped =
|
||||
code: code.toSeq,
|
||||
flags: flags)
|
||||
|
||||
var child = newComputation(c.vmState, childMsg, some(c.fork))
|
||||
var child = newComputation(c.vmState, childMsg)
|
||||
|
||||
c.memOutPos = memOutPos
|
||||
c.memOutLen = memOutLen
|
||||
|
@ -6,8 +6,9 @@
|
||||
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
||||
|
||||
import
|
||||
macros, strformat, tables, sets,
|
||||
macros, strformat, tables, sets, options,
|
||||
eth/common,
|
||||
vm/interpreter/[vm_forks, gas_costs],
|
||||
./constants, ./db/[db_chain, state_db],
|
||||
./utils, json, vm_types, vm/transaction_tracer
|
||||
|
||||
@ -42,11 +43,17 @@ proc newBaseVMState*(prevStateRoot: Hash256, header: BlockHeader,
|
||||
new result
|
||||
result.init(prevStateRoot, header, chainDB, tracerFlags)
|
||||
|
||||
proc txContext*(vmState: BaseVMState, origin: EthAddress, gasPrice: GasInt) =
|
||||
proc txContext*(vmState: BaseVMState, origin: EthAddress, gasPrice: GasInt, forkOverride=none(Fork)) =
|
||||
## this proc will be called each time a new transaction
|
||||
## is going to be executed
|
||||
vmState.txOrigin = origin
|
||||
vmState.txGasPrice = gasPrice
|
||||
vmState.fork =
|
||||
if forkOverride.isSome:
|
||||
forkOverride.get
|
||||
else:
|
||||
vmState.blockHeader.blockNumber.toFork
|
||||
vmState.gasCosts = vmState.fork.forkToSchedule
|
||||
|
||||
method blockhash*(vmState: BaseVMState): Hash256 {.base, gcsafe.} =
|
||||
vmState.blockHeader.hash
|
||||
|
@ -46,7 +46,8 @@ proc setupComputation*(vmState: BaseVMState, tx: Transaction, sender, recipient:
|
||||
|
||||
vmState.txContext(
|
||||
origin = sender,
|
||||
gasPrice = tx.gasPrice
|
||||
gasPrice = tx.gasPrice,
|
||||
forkOverride = some(fork)
|
||||
)
|
||||
|
||||
let msg = Message(
|
||||
@ -61,7 +62,7 @@ proc setupComputation*(vmState: BaseVMState, tx: Transaction, sender, recipient:
|
||||
code: code
|
||||
)
|
||||
|
||||
result = newComputation(vmState, msg, some(fork))
|
||||
result = newComputation(vmState, msg)
|
||||
doAssert result.isOriginComputation
|
||||
|
||||
proc execComputation*(c: Computation) =
|
||||
|
@ -30,6 +30,8 @@ type
|
||||
status* : bool
|
||||
txOrigin* : EthAddress
|
||||
txGasPrice* : GasInt
|
||||
gasCosts* : GasCosts
|
||||
fork* : Fork
|
||||
|
||||
AccessLogs* = ref object
|
||||
reads*: Table[string, string]
|
||||
@ -67,8 +69,6 @@ type
|
||||
error*: Error
|
||||
touchedAccounts*: HashSet[EthAddress]
|
||||
suicides*: HashSet[EthAddress]
|
||||
gasCosts*: GasCosts # TODO - will be hidden at a lower layer
|
||||
fork*: Fork
|
||||
logEntries*: seq[Log]
|
||||
dbsnapshot*: Snapshot
|
||||
instr*: Op
|
||||
|
@ -207,7 +207,8 @@ proc initComputation(vmState: BaseVMState, tx: Transaction, sender: EthAddress,
|
||||
|
||||
vmState.txContext(
|
||||
origin = sender,
|
||||
gasPrice = tx.gasPrice
|
||||
gasPrice = tx.gasPrice,
|
||||
forkOverride = some(fork)
|
||||
)
|
||||
|
||||
let contractAddress = generateAddress(sender, tx.accountNonce)
|
||||
@ -223,7 +224,7 @@ proc initComputation(vmState: BaseVMState, tx: Transaction, sender: EthAddress,
|
||||
code: tx.payload
|
||||
)
|
||||
|
||||
newComputation(vmState, msg, some(fork))
|
||||
newComputation(vmState, msg)
|
||||
|
||||
proc initDatabase*(): (Uint256, BaseChainDB) =
|
||||
let
|
||||
|
Loading…
x
Reference in New Issue
Block a user