mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-11 21:04:11 +00:00
Change EthTime from std.Time to distinct uint64 (#1820)
* Change EthTime from std.Time to distinct uint64 * Bump nimbus-eth2
This commit is contained in:
parent
ca61a7009d
commit
04c7ed8ec9
@ -18,8 +18,6 @@ import
|
||||
../wire/[portal_protocol, portal_stream, portal_protocol_config],
|
||||
"."/[history_content, accumulator]
|
||||
|
||||
from std/times import toUnix
|
||||
|
||||
logScope:
|
||||
topics = "portal_hist"
|
||||
|
||||
@ -278,7 +276,7 @@ proc validateBlockBodyBytes*(
|
||||
## header.
|
||||
## TODO: improve this decoding in combination with the block body validation
|
||||
## calls.
|
||||
let timestamp = Moment.init(header.timestamp.toUnix(), Second)
|
||||
let timestamp = Moment.init(header.timestamp.int64, Second)
|
||||
# TODO: The additional header checks are not needed as header is implicitly
|
||||
# verified by means of the accumulator? Except that we don't use this yet
|
||||
# post merge, so the checks are still useful, for now.
|
||||
@ -352,7 +350,7 @@ proc get(db: ContentDB, T: type BlockBody, contentId: ContentId,
|
||||
return Opt.none(T)
|
||||
|
||||
let
|
||||
timestamp = Moment.init(header.timestamp.toUnix(), Second)
|
||||
timestamp = Moment.init(header.timestamp.int64, Second)
|
||||
body =
|
||||
if isShanghai(chainConfig, timestamp):
|
||||
BlockBody.fromPortalBlockBodyOrRaise(
|
||||
|
@ -93,7 +93,7 @@ func init*(
|
||||
totalDifficulty: encodeQuantity(UInt256.low()),
|
||||
gasLimit: encodeQuantity(header.gasLimit.uint64),
|
||||
gasUsed: encodeQuantity(header.gasUsed.uint64),
|
||||
timestamp: encodeQuantity(header.timestamp.toUnix.uint64)
|
||||
timestamp: encodeQuantity(header.timestamp.uint64)
|
||||
)
|
||||
|
||||
let size = sizeof(BlockHeader) - sizeof(Blob) + header.extraData.len
|
||||
|
@ -241,7 +241,7 @@ proc asPortalBlockData*(
|
||||
blockNumber: payload.blockNumber.distinctBase.u256,
|
||||
gasLimit: payload.gasLimit.unsafeQuantityToInt64,
|
||||
gasUsed: payload.gasUsed.unsafeQuantityToInt64,
|
||||
timestamp: fromUnix payload.timestamp.unsafeQuantityToInt64,
|
||||
timestamp: payload.timestamp.EthTime,
|
||||
extraData: bytes payload.extraData,
|
||||
mixDigest: payload.prevRandao.asEthHash,
|
||||
nonce: default(BlockNonce),
|
||||
@ -286,7 +286,7 @@ proc asPortalBlockData*(
|
||||
blockNumber: payload.blockNumber.distinctBase.u256,
|
||||
gasLimit: payload.gasLimit.unsafeQuantityToInt64,
|
||||
gasUsed: payload.gasUsed.unsafeQuantityToInt64,
|
||||
timestamp: fromUnix payload.timestamp.unsafeQuantityToInt64,
|
||||
timestamp: payload.timestamp.EthTime,
|
||||
extraData: bytes payload.extraData,
|
||||
mixDigest: payload.prevRandao.asEthHash,
|
||||
nonce: default(BlockNonce),
|
||||
|
@ -1,5 +1,5 @@
|
||||
import
|
||||
std/[times, tables],
|
||||
std/[tables],
|
||||
chronicles,
|
||||
nimcrypto/sysrand,
|
||||
stew/[byteutils, endians2],
|
||||
@ -165,16 +165,16 @@ proc isBlockPoS*(cl: CLMocker, bn: common.BlockNumber): bool =
|
||||
return true
|
||||
|
||||
# Return the per-block timestamp value increment
|
||||
func getTimestampIncrement(cl: CLMocker): int =
|
||||
cl.blockTimestampIncrement.get(1)
|
||||
func getTimestampIncrement(cl: CLMocker): EthTime =
|
||||
EthTime cl.blockTimestampIncrement.get(1)
|
||||
|
||||
# Returns the timestamp value to be included in the next payload attributes
|
||||
func getNextBlockTimestamp(cl: CLMocker): int64 =
|
||||
func getNextBlockTimestamp(cl: CLMocker): EthTime =
|
||||
if cl.firstPoSBlockNumber.isNone and cl.transitionPayloadTimestamp.isSome:
|
||||
# We are producing the transition payload and there's a value specified
|
||||
# for this specific payload
|
||||
return cl.transitionPayloadTimestamp.get
|
||||
return cl.latestHeader.timestamp.toUnix + cl.getTimestampIncrement().int64
|
||||
return EthTime cl.transitionPayloadTimestamp.get
|
||||
return cl.latestHeader.timestamp + cl.getTimestampIncrement()
|
||||
|
||||
func setNextWithdrawals(cl: CLMocker, nextWithdrawals: Option[seq[WithdrawalV1]]) =
|
||||
cl.nextWithdrawals = nextWithdrawals
|
||||
@ -185,11 +185,11 @@ func timestampToBeaconRoot(timestamp: Quantity): FixedBytes[32] =
|
||||
FixedBytes[32](h.data)
|
||||
|
||||
func isShanghai(cl: CLMocker, timestamp: Quantity): bool =
|
||||
let ts = fromUnix(timestamp.int64)
|
||||
let ts = EthTime(timestamp.uint64)
|
||||
cl.com.isShanghaiOrLater(ts)
|
||||
|
||||
func isCancun(cl: CLMocker, timestamp: Quantity): bool =
|
||||
let ts = fromUnix(timestamp.int64)
|
||||
let ts = EthTime(timestamp.uint64)
|
||||
cl.com.isCancunOrLater(ts)
|
||||
|
||||
# Picks the next payload producer from the set of clients registered
|
||||
|
@ -226,7 +226,7 @@ proc toBlockHeader(bc: eth_api.BlockObject): common.BlockHeader =
|
||||
mixDigest : bc.mixHash,
|
||||
gasLimit : hexToInt(string bc.gasLimit, GasInt),
|
||||
gasUsed : hexToInt(string bc.gasUsed, GasInt),
|
||||
timestamp : initTime(hexToInt(string bc.timestamp, int64), 0),
|
||||
timestamp : EthTime hexToInt(string bc.timestamp, uint64),
|
||||
fee : maybeU256(bc.baseFeePerGas),
|
||||
withdrawalsRoot: bc.withdrawalsRoot,
|
||||
blobGasUsed : maybeU64(bc.blobGasUsed),
|
||||
|
@ -1,11 +1,13 @@
|
||||
import
|
||||
std/[options, times],
|
||||
std/[options],
|
||||
eth/common/eth_types,
|
||||
./test_env,
|
||||
./types,
|
||||
chronicles,
|
||||
../../tools/common/helpers,
|
||||
../../nimbus/common/hardforks
|
||||
|
||||
import ../../tools/common/helpers except LogLevel
|
||||
|
||||
type
|
||||
ECSpec* = ref object of BaseSpec
|
||||
exec*: proc(env: TestEnv): bool
|
||||
@ -50,11 +52,11 @@ proc ecCancun(env: TestEnv): bool =
|
||||
|
||||
proc getCCShanghai(timestamp: int): ChainConfig =
|
||||
result = getChainConfig("Shanghai")
|
||||
result.shanghaiTime = some(fromUnix(timestamp))
|
||||
result.shanghaiTime = some(EthTime(timestamp))
|
||||
|
||||
proc getCCCancun(timestamp: int): ChainConfig =
|
||||
result = getChainConfig("Cancun")
|
||||
result.cancunTime = some(fromUnix(timestamp))
|
||||
result.cancunTime = some(EthTime(timestamp))
|
||||
|
||||
proc specExecute(ws: BaseSpec): bool =
|
||||
let ws = ECSpec(ws)
|
||||
|
@ -1,5 +1,5 @@
|
||||
import
|
||||
std/[typetraits, times],
|
||||
std/[typetraits],
|
||||
nimcrypto/sysrand,
|
||||
eth/[common, rlp, keys],
|
||||
json_rpc/[rpcclient],
|
||||
@ -283,7 +283,7 @@ proc generateInvalidPayload*(basePayload: ExecutableData,
|
||||
of InvalidGasUsed:
|
||||
customPayload.gasUsed = some(basePayload.gasUsed - 1)
|
||||
of InvalidTimestamp:
|
||||
customPayload.timestamp = some(basePayload.timestamp - 1.seconds)
|
||||
customPayload.timestamp = some(basePayload.timestamp - 1)
|
||||
of InvalidPrevRandao:
|
||||
# This option potentially requires a transaction that uses the PREVRANDAO opcode.
|
||||
# Otherwise the payload will still be valid.
|
||||
|
@ -1,5 +1,5 @@
|
||||
import
|
||||
std/[times, options],
|
||||
std/[options],
|
||||
stint,
|
||||
chronicles,
|
||||
chronos,
|
||||
@ -11,13 +11,14 @@ import
|
||||
../test_env,
|
||||
../engine_client,
|
||||
../types,
|
||||
../../../tools/common/helpers,
|
||||
../../../nimbus/common/common,
|
||||
../../../nimbus/utils/utils,
|
||||
../../../nimbus/common/chain_config,
|
||||
../../../nimbus/beacon/execution_types,
|
||||
../../../nimbus/beacon/web3_eth_conv
|
||||
|
||||
import ../../../tools/common/helpers except LogLevel
|
||||
|
||||
type
|
||||
WDBaseSpec* = ref object of BaseSpec
|
||||
timeIncrements*: int # Timestamp increments per block throughout the test
|
||||
@ -63,7 +64,7 @@ func getWithdrawalsForkTime(ws: WDBaseSpec): int =
|
||||
# Generates the fork config, including withdrawals fork timestamp.
|
||||
func getForkConfig*(ws: WDBaseSpec): ChainConfig =
|
||||
result = getChainConfig("Shanghai")
|
||||
result.shanghaiTime = some(ws.getWithdrawalsForkTime().fromUnix)
|
||||
result.shanghaiTime = some(ws.getWithdrawalsForkTime().EthTime)
|
||||
|
||||
# Get the start account for all withdrawals.
|
||||
func getWithdrawalsStartAccount*(ws: WDBaseSpec): UInt256 =
|
||||
|
@ -183,8 +183,7 @@ proc runTest(node: JsonNode, network: string): TestStatus =
|
||||
|
||||
const
|
||||
skipName = [
|
||||
"beacon_root_contract_timestamps.json",
|
||||
"beacon_root_equal_to_timestamp.json",
|
||||
"nothing skipped",
|
||||
]
|
||||
|
||||
caseFolderCancun = "tests/fixtures/eth_tests/EIPTests/Pyspecs/cancun"
|
||||
|
@ -8,7 +8,6 @@
|
||||
# those terms.
|
||||
|
||||
import
|
||||
std/[times],
|
||||
eth/common,
|
||||
stew/results,
|
||||
../web3_eth_conv,
|
||||
|
@ -8,7 +8,7 @@
|
||||
# those terms.
|
||||
|
||||
import
|
||||
std/[options, times, typetraits],
|
||||
std/[options, typetraits],
|
||||
web3/ethtypes,
|
||||
web3/engine_api_types,
|
||||
eth/common/eth_types_rlp,
|
||||
@ -86,7 +86,7 @@ func u256*(x: Web3Quantity): UInt256 =
|
||||
u256(x.uint64)
|
||||
|
||||
func ethTime*(x: Web3Quantity): common.EthTime =
|
||||
fromUnix(x.unsafeQuantityToInt64)
|
||||
common.EthTime(x.unsafeQuantityToInt64)
|
||||
|
||||
func ethHash*(x: Web3PrevRandao): common.Hash256 =
|
||||
common.Hash256(data: distinctBase x)
|
||||
@ -163,10 +163,10 @@ func w3Qty*(x: common.GasInt): Web3Quantity =
|
||||
Web3Quantity x.uint64
|
||||
|
||||
func w3Qty*(x: common.EthTime): Web3Quantity =
|
||||
Web3Quantity x.toUnix
|
||||
Web3Quantity x.uint64
|
||||
|
||||
func w3Qty*(x: common.EthTime, y: int): Web3Quantity =
|
||||
Web3Quantity(x.toUnix + y.int64)
|
||||
Web3Quantity(x + y.EthTime)
|
||||
|
||||
func w3Qty*(x: Web3Quantity, y: int): Web3Quantity =
|
||||
Web3Quantity(x.uint64 + y.uint64)
|
||||
|
@ -86,6 +86,14 @@ const
|
||||
# ------------------------------------------------------------------------------
|
||||
# Private helper functions
|
||||
# ------------------------------------------------------------------------------
|
||||
proc writeValue(writer: var JsonWriter, value: Option[EthTime])
|
||||
{.gcsafe, raises: [IOError].} =
|
||||
mixin writeValue
|
||||
|
||||
if value.isSome:
|
||||
writer.writeValue value.get.uint64
|
||||
else:
|
||||
writer.writeValue JsonString("null")
|
||||
|
||||
proc read(rlp: var Rlp, x: var AddressBalance, _: type EthAddress): EthAddress
|
||||
{.gcsafe, raises: [RlpError].} =
|
||||
@ -172,13 +180,13 @@ proc readValue(reader: var JsonReader, value: var BlockNonce)
|
||||
proc readValue(reader: var JsonReader, value: var EthTime)
|
||||
{.gcsafe, raises: [SerializationError, IOError].} =
|
||||
try:
|
||||
value = fromHex[int64](reader.readValue(string)).fromUnix
|
||||
value = fromHex[int64](reader.readValue(string)).EthTime
|
||||
except ValueError as ex:
|
||||
reader.raiseUnexpectedValue(ex.msg)
|
||||
|
||||
# but shanghaiTime and cancunTime in config is in int literal
|
||||
proc readValue(reader: var JsonReader, value: var Option[EthTime])
|
||||
{.gcsafe, raises: [SerializationError, IOError].} =
|
||||
{.gcsafe, raises: [IOError].} =
|
||||
let tok = reader.lexer.lazyTok
|
||||
if tok == tkNull:
|
||||
reset value
|
||||
@ -187,8 +195,8 @@ proc readValue(reader: var JsonReader, value: var Option[EthTime])
|
||||
# both readValue(GasInt/AccountNonce) will be called if
|
||||
# we use readValue(int64/uint64)
|
||||
let tok {.used.} = reader.lexer.tok # resove lazy token
|
||||
let val = reader.lexer.absIntVal.int64
|
||||
value = some val.fromUnix
|
||||
let val = EthTime reader.lexer.absIntVal
|
||||
value = some val
|
||||
reader.lexer.next()
|
||||
|
||||
proc readValue(reader: var JsonReader, value: var seq[byte])
|
||||
@ -401,7 +409,7 @@ proc chainConfigForNetwork*(id: NetworkId): ChainConfig =
|
||||
arrowGlacierBlock: some(13_773_000.toBlockNumber), # 2021-12-09 19:55:23 UTC
|
||||
grayGlacierBlock: some(15_050_000.toBlockNumber), # 2022-06-30 10:54:04 UTC
|
||||
terminalTotalDifficulty: some(mainNetTTD),
|
||||
shanghaiTime: some(1_681_338_455.fromUnix)
|
||||
shanghaiTime: some(1_681_338_455.EthTime)
|
||||
)
|
||||
of RopstenNet:
|
||||
ChainConfig(
|
||||
@ -462,7 +470,7 @@ proc chainConfigForNetwork*(id: NetworkId): ChainConfig =
|
||||
berlinBlock: some(4_460_644.toBlockNumber), # 2021-03-18 05:29:51 UTC
|
||||
londonBlock: some(5_062_605.toBlockNumber), # 2021-07-01 03:19:39 UTC
|
||||
terminalTotalDifficulty: some(10790000.u256),
|
||||
shanghaiTime: some(1_678_832_736.fromUnix)
|
||||
shanghaiTime: some(1_678_832_736.EthTime)
|
||||
)
|
||||
of SepoliaNet:
|
||||
const sepoliaTTD = parse("17000000000000000",UInt256)
|
||||
@ -483,7 +491,7 @@ proc chainConfigForNetwork*(id: NetworkId): ChainConfig =
|
||||
berlinBlock: some(0.toBlockNumber),
|
||||
londonBlock: some(0.toBlockNumber),
|
||||
terminalTotalDifficulty: some(sepoliaTTD),
|
||||
shanghaiTime: some(1_677_557_088.fromUnix)
|
||||
shanghaiTime: some(1_677_557_088.EthTime)
|
||||
)
|
||||
else:
|
||||
ChainConfig()
|
||||
@ -510,7 +518,7 @@ proc genesisBlockForNetwork*(id: NetworkId): Genesis
|
||||
of RinkebyNet:
|
||||
Genesis(
|
||||
nonce: 0.toBlockNonce,
|
||||
timestamp: initTime(0x58ee40ba, 0),
|
||||
timestamp: EthTime(0x58ee40ba),
|
||||
extraData: hexToSeqByte("0x52657370656374206d7920617574686f7269746168207e452e436172746d616e42eb768f2244c8811c63729a21a3569731535f067ffc57839b00206d1ad20c69a1981b489f772031b279182d99e65703f0076e4812653aab85fca0f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
|
||||
gasLimit: 4700000,
|
||||
difficulty: 1.u256,
|
||||
@ -519,7 +527,7 @@ proc genesisBlockForNetwork*(id: NetworkId): Genesis
|
||||
of GoerliNet:
|
||||
Genesis(
|
||||
nonce: 0.toBlockNonce,
|
||||
timestamp: initTime(0x5c51a607, 0),
|
||||
timestamp: EthTime(0x5c51a607),
|
||||
extraData: hexToSeqByte("0x22466c6578692069732061207468696e6722202d204166726900000000000000e0a2bd4258d2768837baa26a28fe71dc079f84c70000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"),
|
||||
gasLimit: 0xa00000,
|
||||
difficulty: 1.u256,
|
||||
@ -528,7 +536,7 @@ proc genesisBlockForNetwork*(id: NetworkId): Genesis
|
||||
of SepoliaNet:
|
||||
Genesis(
|
||||
nonce: 0.toBlockNonce,
|
||||
timestamp: initTime(0x6159af19, 0),
|
||||
timestamp: EthTime(0x6159af19),
|
||||
extraData: hexToSeqByte("0x5365706f6c69612c20417468656e732c204174746963612c2047726565636521"),
|
||||
gasLimit: 0x1c9c380,
|
||||
difficulty: 0x20000.u256,
|
||||
|
@ -10,7 +10,7 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
std/[options, times],
|
||||
std/[options],
|
||||
chronicles,
|
||||
eth/trie/trie_defs,
|
||||
../core/[pow, clique, casper],
|
||||
@ -101,7 +101,7 @@ proc hardForkTransition*(
|
||||
com: CommonRef, forkDeterminer: ForkDeterminationInfo)
|
||||
{.gcsafe, raises: [].}
|
||||
|
||||
func cliquePeriod*(com: CommonRef): int
|
||||
func cliquePeriod*(com: CommonRef): EthTime
|
||||
|
||||
func cliqueEpoch*(com: CommonRef): int
|
||||
|
||||
@ -158,7 +158,7 @@ proc init(com : CommonRef,
|
||||
# set it before creating genesis block
|
||||
# TD need to be some(0.u256) because it can be the genesis
|
||||
# already at the MergeFork
|
||||
const TimeZero = fromUnix(0)
|
||||
const TimeZero = EthTime(0)
|
||||
|
||||
# com.forkIds and com.blockZeroHash is set
|
||||
# by setForkId
|
||||
@ -432,9 +432,9 @@ func ttd*(com: CommonRef): Option[DifficultyInt] =
|
||||
# if you messing with clique period and
|
||||
# and epoch, it likely will fail clique verification
|
||||
# at epoch * blocknumber
|
||||
func cliquePeriod*(com: CommonRef): int =
|
||||
func cliquePeriod*(com: CommonRef): EthTime =
|
||||
if com.config.clique.period.isSome:
|
||||
return com.config.clique.period.get()
|
||||
return EthTime com.config.clique.period.get()
|
||||
|
||||
func cliqueEpoch*(com: CommonRef): int =
|
||||
if com.config.clique.epoch.isSome:
|
||||
|
@ -8,7 +8,7 @@
|
||||
# those terms.
|
||||
|
||||
import
|
||||
std/[options, times],
|
||||
std/[options],
|
||||
eth/common,
|
||||
stew/endians2,
|
||||
json_serialization,
|
||||
@ -114,7 +114,7 @@ func adjustForNextBlock*(t: EthTime): EthTime =
|
||||
#
|
||||
# If this makes no sense, what should the callers
|
||||
# do instead?
|
||||
fromUnix(t.toUnix + 12)
|
||||
t + 12
|
||||
|
||||
func adjustForNextBlock*(f: ForkDeterminationInfo): ForkDeterminationInfo =
|
||||
ForkDeterminationInfo(
|
||||
@ -343,7 +343,7 @@ func toNextFork(n: Option[BlockNumber]): uint64 =
|
||||
# EIP-6122: ForkID now works with timestamps too.
|
||||
func toNextFork(t: Option[EthTime]): uint64 =
|
||||
if t.isSome:
|
||||
t.get.toUnix.uint64
|
||||
t.get.uint64
|
||||
else:
|
||||
0'u64
|
||||
|
||||
|
@ -19,7 +19,6 @@
|
||||
##
|
||||
|
||||
import
|
||||
std/[times],
|
||||
./clique/[clique_cfg, clique_defs, clique_desc],
|
||||
./clique/snapshot/[ballot, snapshot_desc],
|
||||
stew/results
|
||||
@ -44,7 +43,7 @@ type
|
||||
# Public
|
||||
# ------------------------------------------------------------------------------
|
||||
|
||||
proc newClique*(db: CoreDbRef, cliquePeriod, cliqueEpoch: int): Clique =
|
||||
proc newClique*(db: CoreDbRef, cliquePeriod: EthTime, cliqueEpoch: int): Clique =
|
||||
## Constructor for a new Clique proof-of-authority consensus engine. The
|
||||
## initial state of the engine is `empty`, there are no authorised signers.
|
||||
##
|
||||
@ -54,7 +53,7 @@ proc newClique*(db: CoreDbRef, cliquePeriod, cliqueEpoch: int): Clique =
|
||||
|
||||
let cfg = db.newCliqueCfg
|
||||
if cliquePeriod > 0:
|
||||
cfg.period = initDuration(seconds = cliquePeriod)
|
||||
cfg.period = cliquePeriod
|
||||
if cliqueEpoch > 0:
|
||||
cfg.epoch = cliqueEpoch
|
||||
cfg.newClique
|
||||
|
@ -43,7 +43,7 @@ type
|
||||
snapsData*: uint64
|
||||
## Raw payload stored on disk (for logging troublesshoting)
|
||||
|
||||
period: Duration
|
||||
period: EthTime
|
||||
## Time between blocks to enforce.
|
||||
|
||||
ckpInterval: int
|
||||
@ -108,9 +108,9 @@ proc `epoch=`*(cfg: CliqueCfg; epoch: SomeInteger) =
|
||||
cfg.epoch = if 0 < epoch: epoch
|
||||
else: EPOCH_LENGTH
|
||||
|
||||
proc `period=`*(cfg: CliqueCfg; period: Duration) =
|
||||
proc `period=`*(cfg: CliqueCfg; period: EthTime) =
|
||||
## Setter
|
||||
cfg.period = if period != Duration(): period
|
||||
cfg.period = if period != EthTime(0): period
|
||||
else: BLOCK_PERIOD
|
||||
|
||||
proc `ckpInterval=`*(cfg: CliqueCfg; numBlocks: SomeInteger) =
|
||||
@ -147,7 +147,7 @@ proc epoch*(cfg: CliqueCfg): BlockNumber =
|
||||
## Getter
|
||||
cfg.epoch.u256
|
||||
|
||||
proc period*(cfg: CliqueCfg): Duration =
|
||||
proc period*(cfg: CliqueCfg): EthTime =
|
||||
## Getter
|
||||
cfg.period
|
||||
|
||||
|
@ -51,7 +51,7 @@ const
|
||||
## Minimum difference in seconds between two consecutive block timestamps.
|
||||
## Suggested time is 15s for the `testnet` to remain analogous to the
|
||||
## `mainnet` ethash target.
|
||||
initDuration(seconds = 15)
|
||||
EthTime 15
|
||||
|
||||
EXTRA_VANITY* = ##\
|
||||
## Fixed number of extra-data prefix bytes reserved for signer vanity.
|
||||
|
@ -19,7 +19,7 @@
|
||||
##
|
||||
|
||||
import
|
||||
std/[sequtils, times],
|
||||
std/[sequtils],
|
||||
eth/[common, keys],
|
||||
../../constants,
|
||||
./clique_cfg,
|
||||
@ -64,7 +64,7 @@ proc cliqueGenvote*(
|
||||
voter: EthAddress; # new voter account/identity
|
||||
seal: PrivateKey; # signature key
|
||||
parent: BlockHeader;
|
||||
elapsed = initDuration();
|
||||
elapsed = EthTime(0);
|
||||
voteInOk = false; # vote in the new voter if `true`
|
||||
outOfTurn = false;
|
||||
checkPoint: seq[EthAddress] = @[]): BlockHeader =
|
||||
@ -124,7 +124,7 @@ proc cliqueGenvote*(
|
||||
## block is a block where the block number is a multiple of `c.cfg.epoch`.
|
||||
## Typically, `c.cfg.epoch` is initialised as `30'000`.
|
||||
##
|
||||
let timeElapsed = if elapsed == initDuration(): c.cfg.period else: elapsed
|
||||
let timeElapsed = if elapsed == EthTime(0): c.cfg.period else: elapsed
|
||||
|
||||
result = BlockHeader(
|
||||
parentHash: parent.blockHash,
|
||||
@ -157,7 +157,7 @@ proc cliqueGenvote*(
|
||||
|
||||
proc cliqueGenvote*(
|
||||
c: Clique; voter: EthAddress; seal: PrivateKey;
|
||||
elapsed = initDuration();
|
||||
elapsed = EthTime(0);
|
||||
voteInOk = false;
|
||||
outOfTurn = false;
|
||||
checkPoint: seq[EthAddress] = @[]): BlockHeader
|
||||
|
@ -129,8 +129,8 @@ proc prepare*(c: Clique; parent: BlockHeader, header: var BlockHeader): CliqueOk
|
||||
|
||||
# Ensure the timestamp has the correct delay
|
||||
header.timestamp = parent.timestamp + c.cfg.period
|
||||
if header.timestamp < getTime():
|
||||
header.timestamp = getTime()
|
||||
if header.timestamp < EthTime.now():
|
||||
header.timestamp = EthTime.now()
|
||||
|
||||
ok()
|
||||
|
||||
@ -182,7 +182,7 @@ proc seal*(c: Clique; ethBlock: var EthBlock):
|
||||
|
||||
# For 0-period chains, refuse to seal empty blocks (no reward but would spin
|
||||
# sealing)
|
||||
if c.cfg.period.isZero and ethBlock.txs.len == 0:
|
||||
if c.cfg.period == 0 and ethBlock.txs.len == 0:
|
||||
info $nilCliqueSealNoBlockYet
|
||||
return err((nilCliqueSealNoBlockYet, ""))
|
||||
|
||||
@ -207,21 +207,22 @@ proc seal*(c: Clique; ethBlock: var EthBlock):
|
||||
info $nilCliqueSealSignedRecently
|
||||
return err((nilCliqueSealSignedRecently, ""))
|
||||
|
||||
# Sweet, the protocol permits us to sign the block, wait for our time
|
||||
var delay = header.timestamp - getTime()
|
||||
if header.difficulty == DIFF_NOTURN:
|
||||
# It's not our turn explicitly to sign, delay it a bit
|
||||
let wiggle = c.snapshot.signersThreshold.int64 * WIGGLE_TIME
|
||||
# Kludge for limited rand() argument range
|
||||
if wiggle.inSeconds < (int.high div 1000).int64:
|
||||
let rndWiggleMs = c.cfg.rand(wiggle.inMilliseconds.int)
|
||||
delay += initDuration(milliseconds = rndWiggleMs)
|
||||
else:
|
||||
let rndWiggleSec = c.cfg.rand((wiggle.inSeconds and int.high).int)
|
||||
delay += initDuration(seconds = rndWiggleSec)
|
||||
when false:
|
||||
# Sweet, the protocol permits us to sign the block, wait for our time
|
||||
var delay = header.timestamp - EthTime.now()
|
||||
if header.difficulty == DIFF_NOTURN:
|
||||
# It's not our turn explicitly to sign, delay it a bit
|
||||
let wiggle = c.snapshot.signersThreshold.int64 * WIGGLE_TIME
|
||||
# Kludge for limited rand() argument range
|
||||
if wiggle.inSeconds < (int.high div 1000).int64:
|
||||
let rndWiggleMs = c.cfg.rand(wiggle.inMilliseconds.int)
|
||||
delay += initDuration(milliseconds = rndWiggleMs)
|
||||
else:
|
||||
let rndWiggleSec = c.cfg.rand((wiggle.inSeconds and int.high).int)
|
||||
delay += initDuration(seconds = rndWiggleSec)
|
||||
|
||||
trace "Out-of-turn signing requested",
|
||||
wiggle = $wiggle
|
||||
trace "Out-of-turn signing requested",
|
||||
wiggle = $wiggle
|
||||
|
||||
# Sign all the things!
|
||||
try:
|
||||
|
@ -205,7 +205,7 @@ proc verifyHeaderFields(c: Clique; header: BlockHeader): CliqueOkResult =
|
||||
# clique/clique.go(250): number := header.Number.Uint64()
|
||||
|
||||
# Don't waste time checking blocks from the future
|
||||
if getTime() < header.timestamp:
|
||||
if EthTime.now() < header.timestamp:
|
||||
return err((errFutureBlock,""))
|
||||
|
||||
# Checkpoint blocks need to enforce zero beneficiary
|
||||
|
@ -1,5 +1,4 @@
|
||||
import
|
||||
times,
|
||||
../../common/common
|
||||
|
||||
export
|
||||
@ -37,8 +36,8 @@ template difficultyBomb(periodCount: UInt256) =
|
||||
func calcDifficultyFrontier*(timeStamp: EthTime, parent: BlockHeader): DifficultyInt =
|
||||
var diff: DifficultyInt
|
||||
let adjust = parent.difficulty div DifficultyBoundDivisorU
|
||||
let time = timeStamp.toUnix()
|
||||
let parentTime = parent.timestamp.toUnix()
|
||||
let time = timeStamp
|
||||
let parentTime = parent.timestamp
|
||||
|
||||
if time - parentTime < DurationLimit:
|
||||
diff = parent.difficulty + adjust
|
||||
@ -61,12 +60,12 @@ func calcDifficultyHomestead*(timeStamp: EthTime, parent: BlockHeader): Difficul
|
||||
# (parent_diff / 2048 * max(1 - (block_timestamp - parent_timestamp) # 10, -99))
|
||||
# ) + 2^(periodCount - 2)
|
||||
|
||||
let time = timeStamp.toUnix()
|
||||
let parentTime = parent.timestamp.toUnix()
|
||||
let time = timeStamp
|
||||
let parentTime = parent.timestamp
|
||||
let parentDifficulty = cast[Int256](parent.difficulty)
|
||||
|
||||
# 1 - (block_timestamp - parent_timestamp) # 10
|
||||
var x = (time - parentTime).i256
|
||||
var x = (time - parentTime).uint64.i256
|
||||
x = x div bigTenI
|
||||
x = bigOneI - x
|
||||
|
||||
@ -102,12 +101,12 @@ func makeDifficultyCalculator(bombDelay: static[int], timeStamp: EthTime, parent
|
||||
# (parent_diff / 2048 * max((2 if len(parent.uncles) else 1) - ((timestamp - parent.timestamp) # 9), -99))
|
||||
# ) + 2^(periodCount - 2)
|
||||
|
||||
let time = timeStamp.toUnix()
|
||||
let parentTime = parent.timestamp.toUnix()
|
||||
let time = timeStamp
|
||||
let parentTime = parent.timestamp
|
||||
let parentDifficulty = cast[Int256](parent.difficulty)
|
||||
|
||||
# (2 if len(parent_uncles) else 1) - (block_timestamp - parent_timestamp) # 9
|
||||
var x = (time - parentTime).i256
|
||||
var x = (time - parentTime).uint64.i256
|
||||
x = x div bigNine
|
||||
|
||||
if parent.ommersHash == EMPTY_UNCLE_HASH:
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
import
|
||||
std/[strformat, times],
|
||||
std/[strformat],
|
||||
./difficulty
|
||||
|
||||
export BlockHeader
|
||||
|
@ -8,7 +8,6 @@
|
||||
# those terms.
|
||||
|
||||
import
|
||||
std/[times],
|
||||
pkg/[chronos,
|
||||
stew/results,
|
||||
chronicles,
|
||||
@ -95,7 +94,7 @@ proc sealingLoop(engine: SealingEngineRef): Future[void] {.async.} =
|
||||
clique.authorize(engine.signer, signerFunc)
|
||||
|
||||
# convert times.Duration to chronos.Duration
|
||||
let period = chronos.seconds(clique.cfg.period.inSeconds)
|
||||
let period = chronos.seconds(clique.cfg.period.int64)
|
||||
|
||||
while engine.state == EngineRunning:
|
||||
# the sealing engine will tick every `cliquePeriod` seconds
|
||||
|
@ -107,11 +107,11 @@ proc prepareForSeal(dh: TxChainRef; header: var BlockHeader) {.gcsafe, raises: [
|
||||
proc getTimestamp(dh: TxChainRef, parent: BlockHeader): EthTime =
|
||||
case dh.com.consensus
|
||||
of ConsensusType.POW:
|
||||
getTime().utc.toTime
|
||||
EthTime.now()
|
||||
of ConsensusType.POA:
|
||||
let timestamp = parent.timestamp + dh.com.poa.cfg.period
|
||||
if timestamp < getTime():
|
||||
getTime()
|
||||
if timestamp < EthTime.now():
|
||||
EthTime.now()
|
||||
else:
|
||||
timestamp
|
||||
of ConsensusType.POS:
|
||||
|
@ -9,7 +9,7 @@
|
||||
# according to those terms.
|
||||
|
||||
import
|
||||
std/[sequtils, sets, times, strutils],
|
||||
std/[sequtils, sets, strutils],
|
||||
../db/accounts_cache,
|
||||
".."/[transaction, common/common],
|
||||
".."/[errors],
|
||||
@ -92,7 +92,7 @@ proc validateHeader(
|
||||
if header.blockNumber != parentHeader.blockNumber + 1:
|
||||
return err("Blocks must be numbered consecutively")
|
||||
|
||||
if header.timestamp.toUnix <= parentHeader.timestamp.toUnix:
|
||||
if header.timestamp <= parentHeader.timestamp:
|
||||
return err("timestamp must be strictly later than parent")
|
||||
|
||||
if com.daoForkSupport and inDAOExtraRange(header.blockNumber):
|
||||
|
@ -101,7 +101,7 @@ func blockHeaderFromBlockObject(o: BlockObject): BlockHeader =
|
||||
blockNumber: distinctBase(o.number).u256,
|
||||
gasLimit: int64(distinctBase(o.gasLimit)),
|
||||
gasUsed: int64(distinctBase(o.gasUsed)),
|
||||
timestamp: initTime(int64(distinctBase(o.timestamp)), 0),
|
||||
timestamp: EthTime(distinctBase(o.timestamp)),
|
||||
extraData: distinctBase(o.extraData),
|
||||
#mixDigest: o.mixHash.toHash, # AARDVARK what's this?
|
||||
nonce: nonce,
|
||||
|
@ -67,11 +67,11 @@ template getCoinbase*(c: Computation): EthAddress =
|
||||
else:
|
||||
c.vmState.coinbase
|
||||
|
||||
template getTimestamp*(c: Computation): int64 =
|
||||
template getTimestamp*(c: Computation): uint64 =
|
||||
when evmc_enabled:
|
||||
c.host.getTxContext().block_timestamp
|
||||
cast[uint64](c.host.getTxContext().block_timestamp)
|
||||
else:
|
||||
c.vmState.blockCtx.timestamp.toUnix
|
||||
c.vmState.blockCtx.timestamp.uint64
|
||||
|
||||
template getBlockNumber*(c: Computation): UInt256 =
|
||||
when evmc_enabled:
|
||||
|
@ -27,7 +27,7 @@ proc len*(stack: Stack): int {.inline.} =
|
||||
len(stack.values)
|
||||
|
||||
proc toStackElement(v: UInt256, elem: var StackElement) {.inline.} = elem = v
|
||||
proc toStackElement(v: uint | int | GasInt, elem: var StackElement) {.inline.} = elem = v.u256
|
||||
proc toStackElement(v: uint64 | uint | int | GasInt, elem: var StackElement) {.inline.} = elem = v.u256
|
||||
proc toStackElement(v: EthAddress, elem: var StackElement) {.inline.} = elem.initFromBytesBE(v)
|
||||
proc toStackElement(v: MDigest, elem: var StackElement) {.inline.} = elem.initFromBytesBE(v.data)
|
||||
|
||||
@ -46,7 +46,7 @@ proc pushAux[T](stack: var Stack, value: T) =
|
||||
stack.values.setLen(stack.values.len + 1)
|
||||
toStackElement(value, stack.values[^1])
|
||||
|
||||
proc push*(stack: var Stack, value: uint | int | GasInt | UInt256 | EthAddress | Hash256) {.inline.} =
|
||||
proc push*(stack: var Stack, value: uint64 | uint | int | GasInt | UInt256 | EthAddress | Hash256) {.inline.} =
|
||||
pushAux(stack, value)
|
||||
|
||||
proc push*(stack: var Stack, value: openArray[byte]) {.inline.} =
|
||||
|
@ -8,7 +8,7 @@
|
||||
# those terms.
|
||||
|
||||
import
|
||||
std/[strutils, times],
|
||||
std/[strutils],
|
||||
stew/[results, byteutils], stint,
|
||||
eth/common/eth_types_rlp, chronos,
|
||||
stew/shims/net,
|
||||
@ -967,7 +967,7 @@ proc blockGasUsed(ud: RootRef, params: Args, parent: Node): RespResult {.apiPrag
|
||||
proc blockTimestamp(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
|
||||
let ctx = GraphqlContextRef(ud)
|
||||
let h = HeaderNode(parent)
|
||||
bigIntNode(h.header.timestamp.toUnix.uint64)
|
||||
bigIntNode(h.header.timestamp.uint64)
|
||||
|
||||
proc blockLogsBloom(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
|
||||
let ctx = GraphqlContextRef(ud)
|
||||
|
@ -10,7 +10,7 @@
|
||||
{.push raises: [].}
|
||||
|
||||
import hexstrings, eth/[common, keys], stew/byteutils,
|
||||
../db/core_db, strutils, algorithm, options, times, json,
|
||||
../db/core_db, strutils, algorithm, options, json,
|
||||
../constants, stint, rpc_types,
|
||||
../utils/utils, ../transaction,
|
||||
../transaction/call_evm
|
||||
@ -216,7 +216,7 @@ proc populateBlockObject*(header: BlockHeader, chain: CoreDbRef, fullTx: bool, i
|
||||
|
||||
result.gasLimit = encodeQuantity(header.gasLimit.uint64)
|
||||
result.gasUsed = encodeQuantity(header.gasUsed.uint64)
|
||||
result.timestamp = encodeQuantity(header.timestamp.toUnix.uint64)
|
||||
result.timestamp = encodeQuantity(header.timestamp.uint64)
|
||||
result.baseFeePerGas = if header.fee.isSome:
|
||||
some(encodeQuantity(header.baseFee))
|
||||
else:
|
||||
|
@ -213,7 +213,7 @@ proc validateHeader(ctx: LegacySyncRef, header: BlockHeader,
|
||||
return false
|
||||
|
||||
if consensusType == ConsensusType.POA:
|
||||
let period = initDuration(seconds = com.cliquePeriod)
|
||||
let period = com.cliquePeriod
|
||||
# Timestamp diff between blocks is lower than PERIOD (clique)
|
||||
if parentHeader.timestamp + period > header.timestamp:
|
||||
trace "invalid timestamp diff (lower than period)",
|
||||
|
@ -83,7 +83,7 @@ proc rpcCallEvm*(call: RpcCallData, header: BlockHeader, com: CommonRef): CallRe
|
||||
const globalGasCap = 0 # TODO: globalGasCap should configurable by user
|
||||
let topHeader = BlockHeader(
|
||||
parentHash: header.blockHash,
|
||||
timestamp: getTime().utc.toTime,
|
||||
timestamp: EthTime.now(),
|
||||
gasLimit: 0.GasInt, ## ???
|
||||
fee: UInt256.none()) ## ???
|
||||
let vmState = BaseVMState.new(topHeader, com)
|
||||
@ -99,7 +99,7 @@ proc rpcEstimateGas*(cd: RpcCallData, header: BlockHeader, com: CommonRef, gasCa
|
||||
# Binary search the gas requirement, as it may be higher than the amount used
|
||||
let topHeader = BlockHeader(
|
||||
parentHash: header.blockHash,
|
||||
timestamp: getTime().utc.toTime,
|
||||
timestamp: EthTime.now(),
|
||||
gasLimit: 0.GasInt, ## ???
|
||||
fee: UInt256.none()) ## ???
|
||||
let vmState = BaseVMState.new(topHeader, com)
|
||||
|
@ -58,7 +58,7 @@ proc setupTxContext(host: TransactionHost) =
|
||||
host.txContext.block_number = (vmState.blockNumber
|
||||
.truncate(typeof(host.txContext.block_number)))
|
||||
# vmState.timestamp now unused
|
||||
host.txContext.block_timestamp = vmState.blockCtx.timestamp.toUnix
|
||||
host.txContext.block_timestamp = cast[int64](vmState.blockCtx.timestamp)
|
||||
# vmState.gasLimit now unused
|
||||
host.txContext.block_gas_limit = vmState.blockCtx.gasLimit
|
||||
# vmState.difficulty now unused
|
||||
|
@ -9,7 +9,7 @@
|
||||
# according to those terms.
|
||||
|
||||
import
|
||||
std/[options, times, json, strutils],
|
||||
std/[options, json, strutils],
|
||||
../common/common,
|
||||
stew/byteutils,
|
||||
../vm_state,
|
||||
@ -43,7 +43,7 @@ proc debug*(h: BlockHeader): string =
|
||||
result.add "blockNumber : " & $h.blockNumber & "\n"
|
||||
result.add "gasLimit : " & $h.gasLimit & "\n"
|
||||
result.add "gasUsed : " & $h.gasUsed & "\n"
|
||||
result.add "timestamp : " & $h.timestamp.toUnix & "\n"
|
||||
result.add "timestamp : " & $h.timestamp & "\n"
|
||||
result.add "extraData : " & $h.extraData & "\n"
|
||||
result.add "mixDigest : " & $h.mixDigest & "\n"
|
||||
result.add "nonce : " & $h.nonce & "\n"
|
||||
@ -97,7 +97,7 @@ proc debugAccounts*(vmState: BaseVMState): string =
|
||||
proc debug*(vms: BaseVMState): string =
|
||||
result.add "com.consensus : " & $vms.com.consensus & "\n"
|
||||
result.add "parent : " & $vms.parent.blockHash & "\n"
|
||||
result.add "timestamp : " & $vms.blockCtx.timestamp.toUnix & "\n"
|
||||
result.add "timestamp : " & $vms.blockCtx.timestamp & "\n"
|
||||
result.add "gasLimit : " & $vms.blockCtx.gasLimit & "\n"
|
||||
result.add "fee : " & $vms.blockCtx.fee & "\n"
|
||||
result.add "prevRandao : " & $vms.blockCtx.prevRandao & "\n"
|
||||
|
@ -113,7 +113,7 @@ func blockHeaderSize(
|
||||
blockNumber : payload.blockNumber.distinctBase.u256,
|
||||
gasLimit : payload.gasLimit.unsafeQuantityToInt64,
|
||||
gasUsed : payload.gasUsed.unsafeQuantityToInt64,
|
||||
timestamp : fromUnix payload.timestamp.unsafeQuantityToInt64,
|
||||
timestamp : payload.timestamp.EthTime,
|
||||
extraData : bytes payload.extraData,
|
||||
mixDigest : payload.prevRandao.asEthHash,
|
||||
nonce : default(etypes.BlockNonce),
|
||||
|
@ -1,5 +1,5 @@
|
||||
import
|
||||
json, strutils, times, options, os,
|
||||
json, strutils, options, os,
|
||||
eth/common, httputils, nimcrypto/utils,
|
||||
stint, stew/byteutils
|
||||
|
||||
@ -75,8 +75,8 @@ proc fromJson*(n: JsonNode, name: string, x: var SomeInteger) =
|
||||
doAssert($x == $node.getInt, name)
|
||||
|
||||
proc fromJson*(n: JsonNode, name: string, x: var EthTime) =
|
||||
x = initTime(hexToInt(n[name].getStr(), int64), 0)
|
||||
doAssert(x.toUnix.prefixHex == toLowerAscii(n[name].getStr()), name)
|
||||
x = EthTime(hexToInt(n[name].getStr(), uint64))
|
||||
doAssert(x.uint64.prefixHex == toLowerAscii(n[name].getStr()), name)
|
||||
|
||||
proc fromJson*[T](n: JsonNode, name: string, x: var Option[T]) =
|
||||
if name in n:
|
||||
|
@ -1,5 +1,5 @@
|
||||
import
|
||||
std/[macrocache, strutils, times],
|
||||
std/[macrocache, strutils],
|
||||
eth/keys,
|
||||
unittest2,
|
||||
chronicles,
|
||||
@ -12,22 +12,22 @@ import
|
||||
../nimbus/vm_internals,
|
||||
../nimbus/transaction/[call_common, call_evm],
|
||||
../nimbus/[vm_types, vm_state],
|
||||
../nimbus/core/pow/difficulty,
|
||||
../tools/common/helpers
|
||||
../nimbus/core/pow/difficulty
|
||||
|
||||
# Ditto, for GasPrice.
|
||||
import ../nimbus/transaction except GasPrice
|
||||
import ../tools/common/helpers except LogLevel
|
||||
|
||||
export byteutils
|
||||
{.experimental: "dynamicBindSym".}
|
||||
|
||||
# backported from Nim 0.19.9
|
||||
# remove this when we use newer Nim
|
||||
proc newLitFixed*(arg: enum): NimNode {.compileTime.} =
|
||||
result = newCall(
|
||||
arg.type.getTypeInst[1],
|
||||
newLit(int(arg))
|
||||
)
|
||||
#proc newLitFixed*(arg: enum): NimNode {.compileTime.} =
|
||||
# result = newCall(
|
||||
# arg.type.getTypeInst[1],
|
||||
# newLit(int(arg))
|
||||
# )
|
||||
|
||||
type
|
||||
VMWord* = array[32, byte]
|
||||
@ -271,7 +271,7 @@ proc initVMEnv*(network: string): BaseVMState =
|
||||
stateRoot: EMPTY_ROOT_HASH,
|
||||
parentHash: parentHash,
|
||||
coinbase: coinbase,
|
||||
timestamp: fromUnix(0x1234),
|
||||
timestamp: EthTime(0x1234),
|
||||
difficulty: 1003.u256,
|
||||
gasLimit: 100_000
|
||||
)
|
||||
|
@ -13,7 +13,7 @@
|
||||
## ----------------------------------------------------
|
||||
|
||||
import
|
||||
std/[tables, times],
|
||||
std/[tables],
|
||||
./pp_light,
|
||||
../../nimbus/common/chain_config,
|
||||
eth/common
|
||||
@ -45,7 +45,7 @@ proc pp*(h: BlockHeader; sep = " "): string =
|
||||
&"coinbase={h.coinbase.pp}{sep}" &
|
||||
&"gasLimit={h.gasLimit}{sep}" &
|
||||
&"gasUsed={h.gasUsed}{sep}" &
|
||||
&"timestamp={h.timestamp.toUnix}{sep}" &
|
||||
&"timestamp={h.timestamp}{sep}" &
|
||||
&"extraData={h.extraData.pp}{sep}" &
|
||||
&"difficulty={h.difficulty}{sep}" &
|
||||
&"mixDigest={h.mixDigest.pp}{sep}" &
|
||||
@ -62,7 +62,7 @@ proc pp*(h: BlockHeader; sep = " "): string =
|
||||
proc pp*(g: Genesis; sep = " "): string =
|
||||
"" &
|
||||
&"nonce={g.nonce.pp}{sep}" &
|
||||
&"timestamp={g.timestamp.toUnix}{sep}" &
|
||||
&"timestamp={g.timestamp}{sep}" &
|
||||
&"extraData={g.extraData.pp}{sep}" &
|
||||
&"gasLimit={g.gasLimit}{sep}" &
|
||||
&"difficulty={g.difficulty}{sep}" &
|
||||
|
@ -84,7 +84,7 @@ func header*(bn: uint64, temp, parent: BlockHeader, diff: uint64): BlockHeader =
|
||||
blockNumber: bn.toBlockNumber,
|
||||
parentHash : parent.blockHash,
|
||||
difficulty : diff.u256,
|
||||
timestamp : fromUnix(parent.timestamp.toUnix + 1),
|
||||
timestamp : parent.timestamp + 1,
|
||||
gasLimit : temp.gasLimit,
|
||||
stateRoot : temp.stateRoot,
|
||||
txRoot : temp.txRoot,
|
||||
|
@ -387,9 +387,9 @@ proc testFixture(node: JsonNode, testStatusIMPL: var TestStatus, debugMode = fal
|
||||
proc blockchainJsonMain*(debugMode = false) =
|
||||
const
|
||||
legacyFolder = "eth_tests/LegacyTests/Constantinople/BlockchainTests"
|
||||
newFolder = "eth_tests/BlockchainTests"
|
||||
#newFolder = "eth_tests/BlockchainTests"
|
||||
#newFolder = "eth_tests/EIPTests/BlockchainTests"
|
||||
#newFolder = "eth_tests/EIPTests/Pyspecs/cancun"
|
||||
newFolder = "eth_tests/EIPTests/Pyspecs/cancun"
|
||||
|
||||
let res = loadKzgTrustedSetup()
|
||||
if res.isErr:
|
||||
|
@ -9,7 +9,7 @@
|
||||
# according to those terms.
|
||||
|
||||
import
|
||||
std/[algorithm, sequtils, strformat, strutils, tables, times],
|
||||
std/[algorithm, sequtils, strformat, strutils, tables],
|
||||
eth/keys,
|
||||
ethash,
|
||||
secp256k1/abi,
|
||||
@ -404,7 +404,7 @@ proc appendVoter*(ap: TesterPool;
|
||||
voter = ap.address(voter.voted),
|
||||
seal = ap.privateKey(voter.signer),
|
||||
parent = parent,
|
||||
elapsed = initDuration(seconds = 100),
|
||||
elapsed = EthTime(100),
|
||||
voteInOk = voter.auth,
|
||||
outOfTurn = voter.noTurn,
|
||||
checkPoint = voter.checkpoint.mapIt(ap.address(it)).sorted(EthAscending))
|
||||
|
@ -1,5 +1,5 @@
|
||||
import
|
||||
std/[strutils, tables, os, json, times],
|
||||
std/[strutils, tables, os, json],
|
||||
unittest2,
|
||||
stew/byteutils,
|
||||
../nimbus/core/pow/difficulty,
|
||||
@ -84,12 +84,12 @@ proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus) =
|
||||
for title, t in tests:
|
||||
let p = BlockHeader(
|
||||
difficulty : t.parentDifficulty,
|
||||
timestamp : times.fromUnix(t.parentTimestamp),
|
||||
timestamp : EthTime(t.parentTimestamp),
|
||||
blockNumber: t.currentBlockNumber - 1,
|
||||
ommersHash : t.parentUncles
|
||||
)
|
||||
|
||||
let timestamp = times.fromUnix(t.currentTimeStamp)
|
||||
let timestamp = EthTime(t.currentTimeStamp)
|
||||
|
||||
let diff = calculator(revision, timestamp, p)
|
||||
check diff == t.currentDifficulty
|
||||
|
@ -98,7 +98,7 @@ proc setupEnv(com: CommonRef, signer, ks2: EthAddress, ctx: EthContext): TestEnv
|
||||
let
|
||||
receiptRoot = com.db.persistReceipts(vmState.receipts)
|
||||
date = dateTime(2017, mMar, 30)
|
||||
timeStamp = date.toTime
|
||||
timeStamp = date.toTime.toUnix.EthTime
|
||||
difficulty = com.calcDifficulty(timeStamp, parent)
|
||||
|
||||
# call persist() before we get the rootHash
|
||||
|
@ -638,7 +638,7 @@ proc runTxPackerTests(noisy = true) =
|
||||
|
||||
test &"Clear and re-pack bucket":
|
||||
# prepare for POS transition in txpool
|
||||
xq.chain.com.pos.timestamp = getTime()
|
||||
xq.chain.com.pos.timestamp = EthTime.now()
|
||||
|
||||
let
|
||||
items0 = xq.toItems(txItemPacked)
|
||||
|
@ -1,5 +1,5 @@
|
||||
import
|
||||
std/[tables, times, os],
|
||||
std/[tables, os],
|
||||
eth/[keys],
|
||||
stew/[byteutils, results], unittest2,
|
||||
../nimbus/db/state_db,
|
||||
@ -89,10 +89,10 @@ proc initEnv(envFork: HardFork): TestEnv =
|
||||
conf.networkParams.config.terminalTotalDifficulty = some(100.u256)
|
||||
|
||||
if envFork >= Shanghai:
|
||||
conf.networkParams.config.shanghaiTime = some(0.fromUnix)
|
||||
conf.networkParams.config.shanghaiTime = some(0.EthTime)
|
||||
|
||||
if envFork >= Cancun:
|
||||
conf.networkParams.config.cancunTime = some(0.fromUnix)
|
||||
conf.networkParams.config.cancunTime = some(0.EthTime)
|
||||
|
||||
let
|
||||
com = CommonRef.new(
|
||||
@ -207,7 +207,7 @@ proc runTxPoolCliqueTest*() =
|
||||
return
|
||||
|
||||
# prevent block from future detected in persistBlocks
|
||||
os.sleep(com.cliquePeriod * 1000)
|
||||
os.sleep(com.cliquePeriod.int * 1000)
|
||||
|
||||
xp.chain.clearAccounts
|
||||
check xp.chain.vmState.processBlock(blk.header, body).isOK
|
||||
@ -240,7 +240,7 @@ proc runTxPoolPosTest*() =
|
||||
test "TxPool ethBlock":
|
||||
com.pos.prevRandao = prevRandao
|
||||
com.pos.feeRecipient = feeRecipient
|
||||
com.pos.timestamp = getTime()
|
||||
com.pos.timestamp = EthTime.now()
|
||||
|
||||
blk = xp.ethBlock()
|
||||
|
||||
@ -303,7 +303,7 @@ proc runTxPoolBlobhashTest*() =
|
||||
test "TxPool ethBlock":
|
||||
com.pos.prevRandao = prevRandao
|
||||
com.pos.feeRecipient = feeRecipient
|
||||
com.pos.timestamp = getTime()
|
||||
com.pos.timestamp = EthTime.now()
|
||||
|
||||
blk = xp.ethBlock()
|
||||
|
||||
@ -381,7 +381,7 @@ proc runTxHeadDelta*(noisy = true) =
|
||||
# pending/staged/packed : total/disposed
|
||||
&" stats={xp.nItems.pp}"
|
||||
|
||||
timestamp = timestamp + 1.seconds
|
||||
timestamp = timestamp + 1
|
||||
com.pos.prevRandao = prevRandao
|
||||
com.pos.timestamp = timestamp
|
||||
com.pos.feeRecipient = feeRecipient
|
||||
|
@ -9,7 +9,6 @@
|
||||
# according to those terms.
|
||||
|
||||
import
|
||||
std/times,
|
||||
../../nimbus/common/common,
|
||||
./types
|
||||
|
||||
@ -19,7 +18,7 @@ export
|
||||
const
|
||||
BlockNumberZero: BlockNumber = 0.toBlockNumber
|
||||
BlockNumberFive: BlockNumber = 5.toBlockNumber
|
||||
TimeZero: EthTime = fromUnix(0)
|
||||
TimeZero = EthTime(0)
|
||||
|
||||
proc createForkTransitionTable(transitionFork: HardFork, b: Option[BlockNumber], t: Option[EthTime], ttd: Option[DifficultyInt]): ForkTransitionTable =
|
||||
|
||||
@ -112,11 +111,11 @@ func getChainConfig*(network: string, c: ChainConfig) =
|
||||
of $TestFork.Shanghai:
|
||||
c.assignTime(HardFork.Shanghai, TimeZero)
|
||||
of $TestFork.MergeToShanghaiAtTime15k:
|
||||
c.assignTime(HardFork.Shanghai, fromUnix(15000))
|
||||
c.assignTime(HardFork.Shanghai, EthTime(15000))
|
||||
of $TestFork.Cancun:
|
||||
c.assignTime(HardFork.Cancun, TimeZero)
|
||||
of $TestFork.ShanghaiToCancunAtTime15k:
|
||||
c.assignTime(HardFork.Cancun, fromUnix(15000))
|
||||
c.assignTime(HardFork.Cancun, EthTime(15000))
|
||||
else:
|
||||
raise newException(ValueError, "unsupported network " & network)
|
||||
|
||||
|
@ -47,7 +47,7 @@ template fromJson(T: type AccountNonce, n: JsonNode): AccountNonce =
|
||||
fromHex[AccountNonce](n.getStr)
|
||||
|
||||
template fromJson(T: type EthTime, n: JsonNode): EthTime =
|
||||
fromUnix(fromHex[int64](n.getStr))
|
||||
EthTime(fromHex[uint64](n.getStr))
|
||||
|
||||
proc fromJson(T: type PrivateKey, n: JsonNode): PrivateKey =
|
||||
var secretKey = n.getStr
|
||||
|
@ -72,7 +72,7 @@ proc fromJson(T: type Hash256, n: JsonNode, field: string): Hash256 =
|
||||
fromJson(T, n[field])
|
||||
|
||||
template fromJson(T: type EthTime, n: JsonNode, field: string): EthTime =
|
||||
fromUnix(parseHexOrInt[int64](n[field].getStr()))
|
||||
EthTime(parseHexOrInt[uint64](n[field].getStr()))
|
||||
|
||||
proc fromJson(T: type AccessList, n: JsonNode, field: string): AccessList =
|
||||
let z = n[field]
|
||||
|
@ -9,7 +9,7 @@
|
||||
# according to those terms.
|
||||
|
||||
import
|
||||
std/[json, strutils, times, tables, os, streams],
|
||||
std/[json, strutils, tables, os, streams],
|
||||
eth/[rlp, trie, eip1559],
|
||||
stint, stew/results,
|
||||
"."/[config, types, helpers],
|
||||
|
2
vendor/nim-bearssl
vendored
2
vendor/nim-bearssl
vendored
@ -1 +1 @@
|
||||
Subproject commit acf9645e328bdcab481cfda1c158e07ecd46bd7b
|
||||
Subproject commit d55d3a86d7ec3ad11b244e17b3bad490bfbd076d
|
2
vendor/nim-chronicles
vendored
2
vendor/nim-chronicles
vendored
@ -1 +1 @@
|
||||
Subproject commit af31ca2157ed5c65ed339a0bbe5bed6faa033502
|
||||
Subproject commit d1d34b9490f99fa2052ffcff2bcf0edaf42d1bdd
|
2
vendor/nim-eth
vendored
2
vendor/nim-eth
vendored
@ -1 +1 @@
|
||||
Subproject commit fe88d9e6b73f97d92cefa861add6f069ef70abf2
|
||||
Subproject commit e34a9c4e5daee654d6ea16f6c4595253548ffb17
|
2
vendor/nim-http-utils
vendored
2
vendor/nim-http-utils
vendored
@ -1 +1 @@
|
||||
Subproject commit aad684d3758a74c1b327df93da2e956458410b48
|
||||
Subproject commit 87b7cbf032c90b9e6b446081f4a647e950362cec
|
2
vendor/nim-kzg4844
vendored
2
vendor/nim-kzg4844
vendored
@ -1 +1 @@
|
||||
Subproject commit f8b78edcc8296f412c2593e6d60f47c77aa421c5
|
||||
Subproject commit 6c406c70ad8cde6ab56320158dd969beb45322ef
|
2
vendor/nim-libp2p
vendored
2
vendor/nim-libp2p
vendored
@ -1 +1 @@
|
||||
Subproject commit 20b0e40f7d89da3f9f1a0a7e823112e938365337
|
||||
Subproject commit 60f953629d725c061f4c0c7ffe79f506efaad7be
|
2
vendor/nim-presto
vendored
2
vendor/nim-presto
vendored
@ -1 +1 @@
|
||||
Subproject commit 35652ed19ccbbf042e95941bc2f8bab39e3f6030
|
||||
Subproject commit 2ae448ff5b0808c8f562c6f0a70bbd7a05407a37
|
2
vendor/nim-stint
vendored
2
vendor/nim-stint
vendored
@ -1 +1 @@
|
||||
Subproject commit 54e24cae415b1bed39a987ecd08c19a34f740972
|
||||
Subproject commit 711cda4456c32d3ba3c6c4524135b3453dffeb9c
|
2
vendor/nim-toml-serialization
vendored
2
vendor/nim-toml-serialization
vendored
@ -1 +1 @@
|
||||
Subproject commit bad61aa6db4fd7aa0007c99b07276da55cc097da
|
||||
Subproject commit 43c546c365af4d291c33b7d94b5b730300165aaf
|
2
vendor/nim-web3
vendored
2
vendor/nim-web3
vendored
@ -1 +1 @@
|
||||
Subproject commit b52a53e7a544850569002224f7bada07fb757ded
|
||||
Subproject commit ebf4a12cbaf8d07c2a6c315adf6278a67c1fdc54
|
2
vendor/nimbus-eth2
vendored
2
vendor/nimbus-eth2
vendored
@ -1 +1 @@
|
||||
Subproject commit 35bf03a3fbb6a55c52911479760c9bbb69e7c2cc
|
||||
Subproject commit 0f9b52933eed5035e497ca3dd7d580536ad98e9a
|
Loading…
x
Reference in New Issue
Block a user