Use of BlockNumber to be able to switch between UInt256 and int64

This commit is contained in:
kdeme 2019-07-10 09:40:46 +02:00
parent b2680fbee7
commit f62816c4f3
7 changed files with 28 additions and 28 deletions

View File

@ -206,24 +206,24 @@ proc publicChainConfig*(id: PublicNetwork): ChainConfig =
of RopstenNet:
ChainConfig(
chainId: RopstenNet.uint,
homesteadBlock: 0.u256,
homesteadBlock: 0.toBlockNumber,
daoForkSupport: true,
eip150Block: 0.u256,
eip150Block: 0.toBlockNumber,
eip150Hash: toDigest("41941023680923e0fe4d74a34bdac8141f2540e3ae90623718e47d66d1ca4a2d"),
eip155Block: 10.u256,
eip158Block: 10.u256,
byzantiumBlock: 1700000.u256
eip155Block: 10.toBlockNumber,
eip158Block: 10.toBlockNumber,
byzantiumBlock: 1700000.toBlockNumber
)
of RinkebyNet:
ChainConfig(
chainId: RinkebyNet.uint,
homesteadBlock: 1.u256,
homesteadBlock: 1.toBlockNumber,
daoForkSupport: true,
eip150Block: 2.u256,
eip150Block: 2.toBlockNumber,
eip150Hash: toDigest("9b095b36c15eaf13044373aef8ee0bd3a382a5abb92e402afa44b8249c3a90e9"),
eip155Block: 3.u256,
eip158Block: 3.u256,
byzantiumBlock: 1035301.u256
eip155Block: 3.toBlockNumber,
eip158Block: 3.toBlockNumber,
byzantiumBlock: 1035301.toBlockNumber
)
else:
error "No chain config for public network", networkId = id

View File

@ -36,7 +36,7 @@ const
EMPTY_UNCLE_HASH* = "1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347".toDigest
GENESIS_BLOCK_NUMBER* = 0.u256
GENESIS_BLOCK_NUMBER* = 0.toBlockNumber
GENESIS_DIFFICULTY* = 131_072.u256
GENESIS_GAS_LIMIT* = 3_141_592
GENESIS_PARENT_HASH* = ZERO_HASH32

View File

@ -150,8 +150,8 @@ proc processBlock*(chainDB: BaseChainDB, header: BlockHeader, body: BlockBody, v
debug "Uncle hash mismatch"
return ValidationResult.Error
for uncle in body.uncles:
var uncleReward = uncle.blockNumber + 8.u256
uncleReward -= header.blockNumber
var uncleReward = uncle.blockNumber.u256 + 8.u256
uncleReward -= header.blockNumber.u256
uncleReward = uncleReward * blockReward
uncleReward = uncleReward div 8.u256
vmState.mutateStateDB:

View File

@ -31,4 +31,4 @@ proc headerFromTag*(chain: BaseChainDB, blockTag: string): BlockHeader =
# Raises are trapped and wrapped in JSON when returned to the user.
tag.validateHexQuantity
let blockNum = stint.fromHex(UInt256, tag)
result = chain.getBlockHeader(blockNum)
result = chain.getBlockHeader(blockNum.toBlockNumber)

View File

@ -17,7 +17,7 @@ import
logScope:
topics = "vm computation"
proc newBaseComputation*(vmState: BaseVMState, blockNumber: UInt256, message: Message, forkOverride=none(Fork)): BaseComputation =
proc newBaseComputation*(vmState: BaseVMState, blockNumber: BlockNumber, message: Message, forkOverride=none(Fork)): BaseComputation =
new result
result.vmState = vmState
result.msg = message

View File

@ -361,7 +361,7 @@ op returnDataCopy, inline = false, memStartPos, copyStartPos, size:
op blockhash, inline = true, blockNumber:
## 0x40, Get the hash of one of the 256 most recent complete blocks.
push: computation.vmState.getAncestorHash(blockNumber)
push: computation.vmState.getAncestorHash(blockNumber.vmWordToBlockNumber)
op coinbase, inline = true:
## 0x41, Get the block's beneficiary address.
@ -373,7 +373,7 @@ op timestamp, inline = true:
op blocknumber, inline = true:
## 0x43, Get the block's number.
push: computation.vmState.blockNumber
push: computation.vmState.blockNumber.blockNumberToVmWord
op difficulty, inline = true:
## 0x44, Get the block's difficulty

View File

@ -5,7 +5,7 @@
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import stint
import stint, eth/common/eth_types
type
Fork* = enum
@ -19,18 +19,18 @@ type
FkConstantinople
const
forkBlocks*: array[Fork, Uint256] = [
FkFrontier: 1.u256, # 30/07/2015 19:26:28
FkThawing: 200_000.u256, # 08/09/2015 01:33:09
FkHomestead: 1_150_000.u256, # 14/03/2016 20:49:53
FkDao: 1_920_000.u256, # 20/07/2016 17:20:40
FkTangerine: 2_463_000.u256, # 18/10/2016 17:19:31
FkSpurious: 2_675_000.u256, # 22/11/2016 18:15:44
FkByzantium: 4_370_000.u256, # 16/10/2017 09:22:11
FkConstantinople: 7_280_000.u256 # 28/02/2019 07:52:04
forkBlocks*: array[Fork, BlockNumber] = [
FkFrontier: 1.toBlockNumber, # 30/07/2015 19:26:28
FkThawing: 200_000.toBlockNumber, # 08/09/2015 01:33:09
FkHomestead: 1_150_000.toBlockNumber, # 14/03/2016 20:49:53
FkDao: 1_920_000.toBlockNumber, # 20/07/2016 17:20:40
FkTangerine: 2_463_000.toBlockNumber, # 18/10/2016 17:19:31
FkSpurious: 2_675_000.toBlockNumber, # 22/11/2016 18:15:44
FkByzantium: 4_370_000.toBlockNumber, # 16/10/2017 09:22:11
FkConstantinople: 7_280_000.toBlockNumber # 28/02/2019 07:52:04
]
proc toFork*(blockNumber: UInt256): Fork =
proc toFork*(blockNumber: BlockNumber): Fork =
# TODO: uint256 comparison is probably quite expensive
# hence binary search is probably worth it earlier than