From 966adcb1245d814a26fd5f082c4e5ca01bb1fce9 Mon Sep 17 00:00:00 2001 From: andri lim Date: Thu, 15 Feb 2024 09:57:05 +0700 Subject: [PATCH] Prepare source code for nim v2 CI (#2028) * Prepare source code for nim v2 CI * Fix copyright year --- .../nodocker/engine/cancun/blobs.nim | 6 +- .../nodocker/engine/cancun/customizer.nim | 34 +++++----- .../nodocker/engine/cancun_tests.nim | 6 +- .../engine/engine/payload_attributes.nim | 4 +- .../engine/engine/payload_execution.nim | 6 +- .../nodocker/engine/engine/versioning.nim | 4 +- .../nodocker/engine/engine_tests.nim | 4 +- .../nodocker/engine/exchange_cap_tests.nim | 6 +- hive_integration/nodocker/engine/types.nim | 6 -- .../engine/withdrawals/wd_base_spec.nim | 8 +-- .../withdrawals/wd_block_value_spec.nim | 4 +- .../engine/withdrawals/wd_history.nim | 4 +- .../withdrawals/wd_max_init_code_spec.nim | 6 +- .../engine/withdrawals/wd_reorg_spec.nim | 4 +- nimbus/core/clique/clique_snapshot.nim | 35 +++++++---- nimbus/core/clique/clique_verify.nim | 27 ++++---- nimbus/core/tx_pool/tx_item.nim | 12 +++- .../backend/aristo_db/handlers_aristo.nim | 62 ++++++++++--------- nimbus/evm/code_stream.nim | 6 +- nimbus/rpc/p2p.nim | 6 +- nimbus/sync/legacy.nim | 4 +- nimbus/sync/misc/block_queue.nim | 4 +- nimbus/sync/protocol/eth/eth_types.nim | 11 ++-- nimbus/sync/protocol/les_protocol.nim | 6 +- nimbus/sync/protocol/snap/snap_types.nim | 10 +-- nimbus/sync/snap/range_desc.nim | 4 +- .../sync/snap/worker/db/snapdb_accounts.nim | 4 +- nimbus/sync/snap/worker/db/snapdb_desc.nim | 4 ++ nimbus/transaction.nim | 4 +- nimbus/transaction/call_evm.nim | 6 +- stateless/test_witness_json.nim | 2 +- stateless/test_witness_verification.nim | 4 +- tests/test_clique.nim | 10 +-- tests/test_clique/pool.nim | 4 +- tests/test_coredb.nim | 5 +- tests/test_rpc_experimental_json.nim | 2 +- ...test_rpc_getproofs_track_state_changes.nim | 4 +- vendor/ethash | 2 +- vendor/nim-eth | 2 +- vendor/nim-metrics | 2 +- vendor/nim-rocksdb | 2 +- vendor/nim-web3 | 2 +- 42 files changed, 190 insertions(+), 158 deletions(-) diff --git a/hive_integration/nodocker/engine/cancun/blobs.nim b/hive_integration/nodocker/engine/cancun/blobs.nim index a5f472a30..b28dfc000 100644 --- a/hive_integration/nodocker/engine/cancun/blobs.nim +++ b/hive_integration/nodocker/engine/cancun/blobs.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2023-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -15,7 +15,7 @@ import stew/endians2, nimcrypto/sha2, stew/results, - ../../../nimbus/core/eip4844 + ../../../../nimbus/core/eip4844 type BlobID* = uint64 @@ -41,7 +41,7 @@ func getBlobList*(startId: BlobID, count: int, addition: BlobID): BlobIDs = for i in 0.. startIndex: diff --git a/hive_integration/nodocker/engine/cancun/customizer.nim b/hive_integration/nodocker/engine/cancun/customizer.nim index b5e2a3e70..e2c81a89d 100644 --- a/hive_integration/nodocker/engine/cancun/customizer.nim +++ b/hive_integration/nodocker/engine/cancun/customizer.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2023-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -25,11 +25,11 @@ type EngineAPIVersionResolver* = ref object of RootRef com: CommonRef -method setEngineAPIVersionResolver*(cust: EngineAPIVersionResolver, v: CommonRef) {.base.} = +method setEngineAPIVersionResolver*(cust: EngineAPIVersionResolver, v: CommonRef) {.base, gcsafe.} = cust.com = v method forkchoiceUpdatedVersion*(cust: EngineAPIVersionResolver, - headTimestamp: uint64, payloadAttributesTimestamp: Option[uint64] = none(uint64)): Version {.base.} = + headTimestamp: uint64, payloadAttributesTimestamp: Option[uint64] = none(uint64)): Version {.base, gcsafe.} = let ts = if payloadAttributesTimestamp.isNone: headTimestamp.EthTime else: payloadAttributesTimestamp.get().EthTime if cust.com.isCancunOrLater(ts): @@ -39,7 +39,7 @@ method forkchoiceUpdatedVersion*(cust: EngineAPIVersionResolver, else: Version.V1 -method newPayloadVersion*(cust: EngineAPIVersionResolver, timestamp: uint64): Version {.base.} = +method newPayloadVersion*(cust: EngineAPIVersionResolver, timestamp: uint64): Version {.base, gcsafe.} = let ts = timestamp.EthTime if cust.com.isCancunOrLater(ts): Version.V3 @@ -48,7 +48,7 @@ method newPayloadVersion*(cust: EngineAPIVersionResolver, timestamp: uint64): Ve else: Version.V1 -method getPayloadVersion*(cust: EngineAPIVersionResolver, timestamp: uint64): Version {.base.} = +method getPayloadVersion*(cust: EngineAPIVersionResolver, timestamp: uint64): Version {.base, gcsafe.} = let ts = timestamp.EthTime if cust.com.isCancunOrLater(ts): Version.V3 @@ -61,10 +61,10 @@ type GetPayloadCustomizer* = ref object of EngineAPIVersionResolver method getPayloadID*(cust: GetPayloadCustomizer, - basePayloadID: PayloadID): PayloadID {.base.} = + basePayloadID: PayloadID): PayloadID {.base, gcsafe.} = doAssert(false, "getPayloadID unimplemented") -method getExpectedError*(cust: GetPayloadCustomizer): int {.base.} = +method getExpectedError*(cust: GetPayloadCustomizer): int {.base, gcsafe.} = doAssert(false, "getExpectedError unimplemented") type @@ -100,7 +100,7 @@ method getPayloadVersion(cust: DowngradegetPayloadVersion, timestamp: uint64): V type PayloadAttributesCustomizer* = ref object of BaseGetPayloadCustomizer -method getPayloadAttributes*(cust: PayloadAttributesCustomizer, basePayloadAttributes: PayloadAttributes): PayloadAttributes {.base.} = +method getPayloadAttributes*(cust: PayloadAttributesCustomizer, basePayloadAttributes: PayloadAttributes): PayloadAttributes {.base, gcsafe.} = doAssert(false, "getPayloadAttributes unimplemented") type @@ -147,10 +147,10 @@ type ForkchoiceUpdatedCustomizer* = ref object of BasePayloadAttributesCustomizer method getForkchoiceState*(cust: ForkchoiceUpdatedCustomizer, - baseForkchoiceUpdate: ForkchoiceStateV1): ForkchoiceStateV1 {.base.} = + baseForkchoiceUpdate: ForkchoiceStateV1): ForkchoiceStateV1 {.base, gcsafe.} = doAssert(false, "getForkchoiceState unimplemented") -method getExpectInvalidStatus*(cust: ForkchoiceUpdatedCustomizer): bool {.base.} = +method getExpectInvalidStatus*(cust: ForkchoiceUpdatedCustomizer): bool {.base, gcsafe.} = doAssert(false, "getExpectInvalidStatus unimplemented") # Customizer that makes no modifications to the forkchoice directive call. @@ -204,7 +204,7 @@ type hashVersions*: seq[byte] method getVersionedHashes*(cust: VersionedHashesCustomizer, - baseVersionedHashes: openArray[common.Hash256]): Option[seq[common.Hash256]] {.base.} = + baseVersionedHashes: openArray[common.Hash256]): Option[seq[common.Hash256]] {.base, gcsafe.} = if cust.blobs.isNone: return none(seq[common.Hash256]) @@ -218,7 +218,7 @@ method getVersionedHashes*(cust: VersionedHashesCustomizer, v[i] = blobID.getVersionedHash(version) some(v) -method description*(cust: VersionedHashesCustomizer): string {.base.} = +method description*(cust: VersionedHashesCustomizer): string {.base, gcsafe.} = result = "VersionedHashes: " if cust.blobs.isSome: for x in cust.blobs.get: @@ -285,10 +285,10 @@ method getVersionedHashes(cust: ExtraVersionedHash, type PayloadCustomizer* = ref object of EngineAPIVersionResolver -method customizePayload*(cust: PayloadCustomizer, data: ExecutableData): ExecutableData {.base.} = +method customizePayload*(cust: PayloadCustomizer, data: ExecutableData): ExecutableData {.base, gcsafe.} = doAssert(false, "customizePayload unimplemented") -method getTimestamp(cust: PayloadCustomizer, basePayload: ExecutionPayload): uint64 {.base.} = +method getTimestamp(cust: PayloadCustomizer, basePayload: ExecutionPayload): uint64 {.base, gcsafe.} = doAssert(false, "getTimestamp unimplemented") type @@ -296,10 +296,10 @@ type expectedError* : int expectInvalidStatus*: bool -method getExpectedError*(cust: NewPayloadCustomizer): int {.base.} = +method getExpectedError*(cust: NewPayloadCustomizer): int {.base, gcsafe.} = cust.expectedError -method getExpectInvalidStatus*(cust: NewPayloadCustomizer): bool {.base.}= +method getExpectInvalidStatus*(cust: NewPayloadCustomizer): bool {.base, gcsafe.}= cust.expectInvalidStatus type @@ -335,7 +335,7 @@ func getTimestamp*(cust: CustomPayloadData, basePayload: ExecutionPayload): uint # Construct a customized payload by taking an existing payload as base and mixing it CustomPayloadData # blockHash is calculated automatically. -proc customizePayload*(cust: CustomPayloadData, data: ExecutableData): ExecutableData = +proc customizePayload*(cust: CustomPayloadData, data: ExecutableData): ExecutableData {.gcsafe.} = var customHeader = blockHeader(data.basePayload, data.beaconRoot) if cust.transactions.isSome: diff --git a/hive_integration/nodocker/engine/cancun_tests.nim b/hive_integration/nodocker/engine/cancun_tests.nim index a606dad75..87a367f27 100644 --- a/hive_integration/nodocker/engine/cancun_tests.nim +++ b/hive_integration/nodocker/engine/cancun_tests.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2023-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -22,8 +22,8 @@ import ./cancun/helpers, ./cancun/blobs, ./cancun/customizer, - ../../nimbus/constants, - ../../nimbus/common/chain_config + ../../../nimbus/constants, + ../../../nimbus/common/chain_config import ./cancun/step_newpayloads, diff --git a/hive_integration/nodocker/engine/engine/payload_attributes.nim b/hive_integration/nodocker/engine/engine/payload_attributes.nim index 4b7174d3a..b4f6285c2 100644 --- a/hive_integration/nodocker/engine/engine/payload_attributes.nim +++ b/hive_integration/nodocker/engine/engine/payload_attributes.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2023-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -42,7 +42,7 @@ method execute(cs: InvalidPayloadAttributesTest, env: TestEnv): bool = # Send a forkchoiceUpdated with invalid PayloadAttributes let pbRes = env.clMock.produceSingleBlock(BlockProcessCallbacks( - onNewPayloadBroadcast: proc(): bool = + onNewPayloadBroadcast: proc(): bool {.gcsafe.} = # Try to apply the new payload with invalid attributes var fcu = env.clMock.latestForkchoice if cs.syncing: diff --git a/hive_integration/nodocker/engine/engine/payload_execution.nim b/hive_integration/nodocker/engine/engine/payload_execution.nim index 3433d98b7..0f1f08ac2 100644 --- a/hive_integration/nodocker/engine/engine/payload_execution.nim +++ b/hive_integration/nodocker/engine/engine/payload_execution.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2023-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -230,7 +230,7 @@ method execute(cs: MultiplePayloadsExtendingCanonicalChainTest, env: TestEnv): b return true ) - let reExecFunc = proc(): bool = + let reExecFunc = proc(): bool {.gcsafe.} = var payloadCount = 80 if cs.payloadCount > 0: payloadCount = cs.payloadCount @@ -238,7 +238,7 @@ method execute(cs: MultiplePayloadsExtendingCanonicalChainTest, env: TestEnv): b let basePayload = env.clMock.latestExecutableData # Check that the transaction was included - testCond len(basePayload.basePayload.transactions)> 0: + testCond len(basePayload.basePayload.transactions) > 0: fatal "Client failed to include the expected transaction in payload built" # Fabricate and send multiple new payloads by changing the PrevRandao field diff --git a/hive_integration/nodocker/engine/engine/versioning.nim b/hive_integration/nodocker/engine/engine/versioning.nim index 7a1aa5b5e..1147cfdcd 100644 --- a/hive_integration/nodocker/engine/engine/versioning.nim +++ b/hive_integration/nodocker/engine/engine/versioning.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2023-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -46,7 +46,7 @@ method execute(cs: ForkchoiceUpdatedOnPayloadRequestTest, env: TestEnv): bool = testCond ok let pbRes = env.clMock.produceSingleBlock(clmock.BlockProcessCallbacks( - onPayloadAttributesGenerated: proc(): bool = + onPayloadAttributesGenerated: proc(): bool {.gcsafe.} = var attr = env.clMock.latestPayloadAttributes expectedStatus = PayloadExecutionStatus.valid diff --git a/hive_integration/nodocker/engine/engine_tests.nim b/hive_integration/nodocker/engine/engine_tests.nim index b7473f0a7..257f0baec 100644 --- a/hive_integration/nodocker/engine/engine_tests.nim +++ b/hive_integration/nodocker/engine/engine_tests.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2023-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -15,7 +15,7 @@ import ./test_env, ./base_spec, ./cancun/customizer, - ../../nimbus/common/chain_config + ../../../nimbus/common/chain_config import ./engine/suggested_fee_recipient, diff --git a/hive_integration/nodocker/engine/exchange_cap_tests.nim b/hive_integration/nodocker/engine/exchange_cap_tests.nim index 671e89763..1dd4d570e 100644 --- a/hive_integration/nodocker/engine/exchange_cap_tests.nim +++ b/hive_integration/nodocker/engine/exchange_cap_tests.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2023-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -14,9 +14,9 @@ import ./test_env, ./types, chronicles, - ../../nimbus/common/hardforks + ../../../nimbus/common/hardforks -import ../../tools/common/helpers except LogLevel +import ../../../tools/common/helpers except LogLevel type ECSpec* = ref object of BaseSpec diff --git a/hive_integration/nodocker/engine/types.nim b/hive_integration/nodocker/engine/types.nim index 23a810d7c..f26a66ddc 100644 --- a/hive_integration/nodocker/engine/types.nim +++ b/hive_integration/nodocker/engine/types.nim @@ -251,12 +251,6 @@ template expectStorageEqual*(res: untyped, expectedValue: FixedBytes[32]) = testCond res.get == expectedValue: error "invalid storage", get=res.get, expect=expectedValue -template expectBalanceEqual*(res: untyped, expectedBalance: UInt256) = - testCond res.isOk: - error "expectBalanceEqual", msg=res.error - testCond res.get == expectedBalance: - error "invalid balance", expect=expectedBalance, get=res.get - template expectBlobGasUsed*(res: untyped, expected: uint64) = testCond res.isOk: error "expectBlobGasUsed", msg=res.error diff --git a/hive_integration/nodocker/engine/withdrawals/wd_base_spec.nim b/hive_integration/nodocker/engine/withdrawals/wd_base_spec.nim index b9391b733..de6b4d0f5 100644 --- a/hive_integration/nodocker/engine/withdrawals/wd_base_spec.nim +++ b/hive_integration/nodocker/engine/withdrawals/wd_base_spec.nim @@ -21,11 +21,11 @@ import ../types, ../base_spec, ../cancun/customizer, - ../../../nimbus/common/common, - ../../../nimbus/utils/utils, - ../../../nimbus/common/chain_config, + ../../../../nimbus/common/common, + ../../../../nimbus/utils/utils, + ../../../../nimbus/common/chain_config, web3/execution_types, - ../../../nimbus/beacon/web3_eth_conv + ../../../../nimbus/beacon/web3_eth_conv type WDBaseSpec* = ref object of BaseSpec diff --git a/hive_integration/nodocker/engine/withdrawals/wd_block_value_spec.nim b/hive_integration/nodocker/engine/withdrawals/wd_block_value_spec.nim index 71fd865df..54d3bf42d 100644 --- a/hive_integration/nodocker/engine/withdrawals/wd_block_value_spec.nim +++ b/hive_integration/nodocker/engine/withdrawals/wd_block_value_spec.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2023-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -16,7 +16,7 @@ import ../test_env, ../engine_client, ../types, - ../../../nimbus/transaction + ../../../../nimbus/transaction type BlockValueSpec* = ref object of WDBaseSpec diff --git a/hive_integration/nodocker/engine/withdrawals/wd_history.nim b/hive_integration/nodocker/engine/withdrawals/wd_history.nim index 5f639f899..92bbe8d31 100644 --- a/hive_integration/nodocker/engine/withdrawals/wd_history.nim +++ b/hive_integration/nodocker/engine/withdrawals/wd_history.nim @@ -14,8 +14,8 @@ import json_rpc/[rpcclient], stew/[byteutils, results], ../engine_client, - ../../../nimbus/utils/utils, - ../../../nimbus/beacon/web3_eth_conv + ../../../../nimbus/utils/utils, + ../../../../nimbus/beacon/web3_eth_conv type Withdrawals* = ref object diff --git a/hive_integration/nodocker/engine/withdrawals/wd_max_init_code_spec.nim b/hive_integration/nodocker/engine/withdrawals/wd_max_init_code_spec.nim index a19178100..1c99e4810 100644 --- a/hive_integration/nodocker/engine/withdrawals/wd_max_init_code_spec.nim +++ b/hive_integration/nodocker/engine/withdrawals/wd_max_init_code_spec.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2023-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -18,9 +18,9 @@ import ../engine_client, ../types, ../cancun/customizer, - ../../../nimbus/constants, + ../../../../nimbus/constants, web3/execution_types, - ../../../nimbus/beacon/web3_eth_conv + ../../../../nimbus/beacon/web3_eth_conv # EIP-3860 Shanghai Tests: # Send transactions overflowing the MAX_INITCODE_SIZE diff --git a/hive_integration/nodocker/engine/withdrawals/wd_reorg_spec.nim b/hive_integration/nodocker/engine/withdrawals/wd_reorg_spec.nim index 14f4d4381..d2dd3e227 100644 --- a/hive_integration/nodocker/engine/withdrawals/wd_reorg_spec.nim +++ b/hive_integration/nodocker/engine/withdrawals/wd_reorg_spec.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2023-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -20,7 +20,7 @@ import ../engine_client, ../types, ../base_spec, - ../../../nimbus/beacon/web3_eth_conv + ../../../../nimbus/beacon/web3_eth_conv # Withdrawals re-org spec: # Specifies a withdrawals test where the withdrawals re-org can happen diff --git a/nimbus/core/clique/clique_snapshot.nim b/nimbus/core/clique/clique_snapshot.nim index 667ce4dbd..8cec4c7f9 100644 --- a/nimbus/core/clique/clique_snapshot.nim +++ b/nimbus/core/clique/clique_snapshot.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2018 Status Research & Development GmbH +# Copyright (c) 2018-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -49,8 +49,10 @@ type start: LocalPivot ## start here searching for checkpoints trail: LocalPath ## snapshot location subChn: LocalSubChain ## chain[] sub-range - parents: seq[BlockHeader] ## explicit parents + parents: HeadersHolderRef ## explicit parents + HeadersHolderRef* = ref object + headers*: seq[BlockHeader] {.push raises: [].} @@ -150,6 +152,15 @@ proc isSnapshotPosition(d: var LocalSnaps; number: BlockNumber): bool = # Private functions # ------------------------------------------------------------------------------ +func len*(list: HeadersHolderRef): int = + list.headers.len + +func `[]`*(list: HeadersHolderRef, idx: int): BlockHeader = + list.headers[idx] + +func `[]`*(list: HeadersHolderRef, idx: BackwardsIndex): BlockHeader = + list.headers[list.headers.len - int(idx)] + proc findSnapshot(d: var LocalSnaps): bool = ## Search for a snapshot starting at current header starting at the pivot ## value `d.start`. The snapshot returned in `trail` is a clone of the @@ -324,7 +335,7 @@ proc updateSnapshot(d: var LocalSnaps): SnapshotResult # ------------------------------------------------------------------------------ proc cliqueSnapshotSeq*(c: Clique; header: BlockHeader; - parents: var seq[BlockHeader]): SnapshotResult + parents: HeadersHolderRef): SnapshotResult {.gcsafe, raises: [CatchableError].} = ## Create authorisation state snapshot of a given point in the block chain ## and store it in the `Clique` descriptor to be retrievable as `c.snapshot` @@ -343,7 +354,6 @@ proc cliqueSnapshotSeq*(c: Clique; header: BlockHeader; return ok(rc.value) # Avoid deep copy, sequence will not be changed by `updateSnapshot()` - parents.shallow var snaps = LocalSnaps( c: c, @@ -360,7 +370,7 @@ proc cliqueSnapshotSeq*(c: Clique; header: BlockHeader; proc cliqueSnapshotSeq*(c: Clique; hash: Hash256; - parents: var seq[BlockHeader]): SnapshotResult + parents: HeadersHolderRef): SnapshotResult {.gcsafe,raises: [CatchableError].} = ## Create authorisation state snapshot of a given point in the block chain ## and store it in the `Clique` descriptor to be retrievable as `c.snapshot` @@ -383,7 +393,6 @@ proc cliqueSnapshotSeq*(c: Clique; hash: Hash256; return err((errUnknownHash,"")) # Avoid deep copy, sequence will not be changed by `updateSnapshot()` - parents.shallow var snaps = LocalSnaps( c: c, @@ -403,26 +412,30 @@ proc cliqueSnapshotSeq*(c: Clique; hash: Hash256; proc cliqueSnapshot*(c: Clique; header: BlockHeader; parents: var seq[BlockHeader]): SnapshotResult {.gcsafe, raises: [CatchableError].} = - var list = toSeq(parents) + let list = HeadersHolderRef( + headers: toSeq(parents) + ) c.cliqueSnapshotSeq(header,list) proc cliqueSnapshot*(c: Clique;hash: Hash256; parents: openArray[BlockHeader]): SnapshotResult {.gcsafe, raises: [CatchableError].} = - var list = toSeq(parents) + let list = HeadersHolderRef( + headers: toSeq(parents) + ) c.cliqueSnapshotSeq(hash,list) proc cliqueSnapshot*(c: Clique; header: BlockHeader): SnapshotResult {.gcsafe,raises: [CatchableError].} = ## Short for `cliqueSnapshot(c,header,@[])` - var blind: seq[BlockHeader] + let blind = HeadersHolderRef() c.cliqueSnapshotSeq(header, blind) proc cliqueSnapshot*(c: Clique; hash: Hash256): SnapshotResult {.gcsafe,raises: [CatchableError].} = ## Short for `cliqueSnapshot(c,hash,@[])` - var blind: seq[BlockHeader] - c.cliqueSnapshot(hash, blind) + let blind = HeadersHolderRef() + c.cliqueSnapshotSeq(hash, blind) # ------------------------------------------------------------------------------ # End diff --git a/nimbus/core/clique/clique_verify.nim b/nimbus/core/clique/clique_verify.nim index b8e048407..49f5969da 100644 --- a/nimbus/core/clique/clique_verify.nim +++ b/nimbus/core/clique/clique_verify.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2018-2023 Status Research & Development GmbH +# Copyright (c) 2018-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -139,7 +139,7 @@ proc verifySeal(c: Clique; header: BlockHeader): CliqueOkResult = # clique/clique.go(314): func (c *Clique) verifyCascadingFields(chain [..] proc verifyCascadingFields(c: Clique; com: CommonRef; header: BlockHeader; - parents: var seq[BlockHeader]): CliqueOkResult + parents: HeadersHolderRef): CliqueOkResult {.gcsafe, raises: [CatchableError].} = ## Verify all the header fields that are not standalone, rather depend on a ## batch of previous headers. The caller may optionally pass in a batch of @@ -264,7 +264,7 @@ proc verifyHeaderFields(c: Clique; header: BlockHeader): CliqueOkResult = # clique/clique.go(246): func (c *Clique) verifyHeader(chain [..] proc cliqueVerifyImpl(c: Clique; com: CommonRef; header: BlockHeader; - parents: var seq[BlockHeader]): CliqueOkResult + parents: HeadersHolderRef): CliqueOkResult {.gcsafe, raises: [CatchableError].} = ## Check whether a header conforms to the consensus rules. The caller may ## optionally pass in a batch of parents (ascending order) to avoid looking @@ -292,7 +292,7 @@ proc cliqueVerifyImpl(c: Clique; com: CommonRef; header: BlockHeader; c.failed = (header.blockHash, result.error) proc cliqueVerifySeq*(c: Clique; com: CommonRef; header: BlockHeader; - parents: var seq[BlockHeader]): CliqueOkResult + parents: HeadersHolderRef): CliqueOkResult {.gcsafe, raises: [CatchableError].} = ## Check whether a header conforms to the consensus rules. The caller may ## optionally pass in a batch of parents (ascending order) to avoid looking @@ -321,7 +321,7 @@ proc cliqueVerifySeq*(c: Clique; com: CommonRef; header: BlockHeader; ok() proc cliqueVerifySeq(c: Clique; com: CommonRef; - headers: var seq[BlockHeader]): CliqueOkResult + headers: HeadersHolderRef): CliqueOkResult {.gcsafe, raises: [CatchableError].} = ## This function verifies a batch of headers checking each header for ## consensus rules conformance. The `headers` list is supposed to @@ -338,16 +338,17 @@ proc cliqueVerifySeq(c: Clique; com: CommonRef; ## Note that the sequence argument must be write-accessible, even though it ## will be left untouched by this function. if 0 < headers.len: - headers.shallow block: - var blind: seq[BlockHeader] + let blind = HeadersHolderRef() let rc = c.cliqueVerifyImpl(com, headers[0],blind) if rc.isErr: return rc for n in 1 ..< headers.len: - var parent = headers[n-1 .. n-1] # is actually a single item squence + let parent = HeadersHolderRef( + headers: headers.headers[n-1 .. n-1] # is actually a single item squence + ) let rc = c.cliqueVerifyImpl(com, headers[n],parent) if rc.isErr: return rc @@ -384,14 +385,16 @@ proc cliqueVerify*(c: Clique; com: CommonRef; header: BlockHeader; ## ## Use the directives `cliqueSave()`, `cliqueDispose()`, and/or ## `cliqueRestore()` for transaction. - var list = toSeq(parents) + let list = HeadersHolderRef( + headers: toSeq(parents) + ) c.cliqueVerifySeq(com, header, list) # clique/clique.go(217): func (c *Clique) VerifyHeader(chain [..] proc cliqueVerify*(c: Clique; com: CommonRef; header: BlockHeader): CliqueOkResult {.gcsafe, raises: [CatchableError].} = ## Consensus rules verifier without optional parents list. - var blind: seq[BlockHeader] + let blind = HeadersHolderRef() c.cliqueVerifySeq(com, header, blind) proc cliqueVerify*(c: Clique; com: CommonRef; @@ -413,7 +416,9 @@ proc cliqueVerify*(c: Clique; com: CommonRef; ## ## Use the directives `cliqueSave()`, `cliqueDispose()`, and/or ## `cliqueRestore()` for transaction. - var list = toSeq(headers) + let list = HeadersHolderRef( + headers: toSeq(headers) + ) c.cliqueVerifySeq(com, list) # ------------------------------------------------------------------------------ diff --git a/nimbus/core/tx_pool/tx_item.nim b/nimbus/core/tx_pool/tx_item.nim index 28a2a89a2..327858090 100644 --- a/nimbus/core/tx_pool/tx_item.nim +++ b/nimbus/core/tx_pool/tx_item.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2018 Status Research & Development GmbH +# Copyright (c) 2018-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -175,7 +175,15 @@ proc effectiveGasTip*(tx: Transaction; baseFee: UInt256): GasPriceEx = proc dup*(item: TxItemRef): TxItemRef = ## Getter, provide contents copy - item.deepCopy + TxItemRef( + tx: item.tx, + itemID: item.itemID, + timeStamp: item.timeStamp, + sender: item.sender, + info: item.info, + status: item.status, + reject: item.reject + ) proc info*(item: TxItemRef): string = ## Getter diff --git a/nimbus/db/core_db/backend/aristo_db/handlers_aristo.nim b/nimbus/db/core_db/backend/aristo_db/handlers_aristo.nim index 59e89c213..2c1c9a2d5 100644 --- a/nimbus/db/core_db/backend/aristo_db/handlers_aristo.nim +++ b/nimbus/db/core_db/backend/aristo_db/handlers_aristo.nim @@ -110,6 +110,38 @@ func to(vid: CoreDbTrieRef; T: type VertexID): T = func to(address: EthAddress; T: type PathID): T = HashKey.fromBytes(address.keccakHash.data).value.to(T) +# ------------------------------------------------------------------------------ +# Auto destructor should appear before constructor +# to prevent cannot bind another `=destroy` error +# ------------------------------------------------------------------------------ + +proc `=destroy`(cMpt: var AristoChildDbObj) = + ## Auto destructor + let mpt = cMpt.mpt + if not mpt.isNil: + let base = cMpt.base + if mpt != base.adb: # Not the shared descriptor? + # + # The argument `cMpt` will be deleted, so provide another one. The + # `mpt` descriptor must be added to the GC queue which will be + # destructed later on a clean environment. + # + base.gq.add AristoChildDbRef( + base: base, + mpt: mpt, + saveMode: cMpt.saveMode) + elif cMpt.saveMode == AutoSave: # Otherwise there is nothing to do + # + # Prepend cached entry. There is only one needed as it refers to + # the same shared `mpt` descriptor. + # + if base.gq.len == 0 or + base.gq[0].saveMode != AutoSave: + base.gq = AristoChildDbRef( + base: base, + mpt: mpt, + saveMode: cMpt.saveMode) & base.gq + # ------------------------------- func toCoreDbAccount( @@ -202,7 +234,7 @@ func toVoidRc[T]( err rc.error.toError(db, info, error) # ------------------------------------------------------------------------------ -# Private constructor and auto destructor +# Private constructor # ------------------------------------------------------------------------------ proc newTrieCtx( @@ -280,34 +312,6 @@ proc newTrieCtx( ok((db.bless trie).AristoCoreDbTrie) - -proc `=destroy`(cMpt: var AristoChildDbObj) = - ## Auto destructor - let mpt = cMpt.mpt - if not mpt.isNil: - let base = cMpt.base - if mpt != base.adb: # Not the shared descriptor? - # - # The argument `cMpt` will be deleted, so provide another one. The - # `mpt` descriptor must be added to the GC queue which will be - # destructed later on a clean environment. - # - base.gq.add AristoChildDbRef( - base: base, - mpt: mpt, - saveMode: cMpt.saveMode) - elif cMpt.saveMode == AutoSave: # Otherwise there is nothing to do - # - # Prepend cached entry. There is only one needed as it refers to - # the same shared `mpt` descriptor. - # - if base.gq.len == 0 or - base.gq[0].saveMode != AutoSave: - base.gq = AristoChildDbRef( - base: base, - mpt: mpt, - saveMode: cMpt.saveMode) & base.gq - # ------------------------------------------------------------------------------ # Private `MPT` or account call back functions # ------------------------------------------------------------------------------ diff --git a/nimbus/evm/code_stream.nim b/nimbus/evm/code_stream.nim index 7dd66bb8c..dd6a6853f 100644 --- a/nimbus/evm/code_stream.nim +++ b/nimbus/evm/code_stream.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2018 Status Research & Development GmbH +# Copyright (c) 2018-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) # * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) @@ -24,9 +24,9 @@ type proc `$`*(b: byte): string = $(b.int) -proc newCodeStream*(codeBytes: seq[byte]): CodeStream = +proc newCodeStream*(codeBytes: sink seq[byte]): CodeStream = new(result) - shallowCopy(result.bytes, codeBytes) + result.bytes = system.move(codeBytes) result.pc = 0 result.invalidPositions = initHashSet[int]() result.depthProcessed = 0 diff --git a/nimbus/rpc/p2p.nim b/nimbus/rpc/p2p.nim index 7264aa54a..c2fdbaf68 100644 --- a/nimbus/rpc/p2p.nim +++ b/nimbus/rpc/p2p.nim @@ -555,7 +555,7 @@ proc setupEthRpc*( getProof(accDB, address, slots) - server.rpc("eth_getBlockReceipts") do(quantityTag: BlockTag) -> Option[seq[ReceiptObject]]: + server.rpc("eth_getBlockReceipts") do(quantityTag: BlockTag) -> Opt[seq[ReceiptObject]]: try: let header = chainDB.headerFromTag(quantityTag) var @@ -573,9 +573,9 @@ proc setupEthRpc*( recs.add populateReceipt(receipt, gasUsed, txs[index], index, header) inc index - return some(recs) + return Opt.some(recs) except CatchableError: - return none(seq[ReceiptObject]) + return Opt.none(seq[ReceiptObject]) #[ server.rpc("eth_newFilter") do(filterOptions: FilterOptions) -> int: ## Creates a filter object, based on filter options, to notify when the state changes (logs). diff --git a/nimbus/sync/legacy.nim b/nimbus/sync/legacy.nim index 8fa91ff96..7863afa72 100644 --- a/nimbus/sync/legacy.nim +++ b/nimbus/sync/legacy.nim @@ -696,11 +696,11 @@ proc obtainBlocksFromPeer(ctx: LegacySyncRef, peer: Peer) {.async.} = trace trEthSendSendingGetBlockHeaders, peer, startBlock=request.startBlock.number, max=request.maxResults, step=traceStep(request) - let results = await peer.getBlockHeaders(request) + var results = await peer.getBlockHeaders(request) if results.isSome: trace trEthRecvReceivedBlockHeaders, peer, count=results.get.headers.len, requested=request.maxResults - shallowCopy(workItem.headers, results.get.headers) + workItem.headers = system.move(results.get.headers) var reqBodies = newSeqOfCap[bool](workItem.headers.len) diff --git a/nimbus/sync/misc/block_queue.nim b/nimbus/sync/misc/block_queue.nim index b61cd1972..ccdc08476 100644 --- a/nimbus/sync/misc/block_queue.nim +++ b/nimbus/sync/misc/block_queue.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2018-2021 Status Research & Development GmbH +# Copyright (c) 2018-2024 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at # https://opensource.org/licenses/MIT). @@ -370,7 +370,7 @@ proc fetchHeaders( # Import into `wi.headers` else: - wi.headers.shallowCopy(hdrResp.get.headers) + wi.headers = system.move(hdrResp.get.headers) # Calculate block header hashes and verify it against parent links. If # necessary, cut off some offending block headers tail. diff --git a/nimbus/sync/protocol/eth/eth_types.nim b/nimbus/sync/protocol/eth/eth_types.nim index 98e0994cd..8c6c2fe4b 100644 --- a/nimbus/sync/protocol/eth/eth_types.nim +++ b/nimbus/sync/protocol/eth/eth_types.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2018 Status Research & Development GmbH +# Copyright (c) 2018-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -57,7 +57,7 @@ method getReceipts*(ctx: EthWireBase, hashes: openArray[Hash256]): seq[seq[Recei {.base, gcsafe, raises: [CatchableError].} = notImplemented("getReceipts") -method getPooledTxs*(ctx: EthWireBase, hashes: openArray[Hash256]): seq[Transaction] {.base.} = +method getPooledTxs*(ctx: EthWireBase, hashes: openArray[Hash256]): seq[Transaction] {.base, gcsafe.} = notImplemented("getPooledTxs") method getBlockBodies*(ctx: EthWireBase, hashes: openArray[Hash256]): seq[BlockBody] {.base, gcsafe, raises: [CatchableError].} = @@ -75,7 +75,8 @@ method handleAnnouncedTxs*(ctx: EthWireBase, peer: Peer, txs: openArray[Transact {.base, gcsafe, raises: [CatchableError].} = notImplemented("handleAnnouncedTxs") -method handleAnnouncedTxsHashes*(ctx: EthWireBase, peer: Peer, txHashes: openArray[Hash256]) {.base.} = +method handleAnnouncedTxsHashes*(ctx: EthWireBase, peer: Peer, txHashes: openArray[Hash256]) + {.base, gcsafe.} = notImplemented("handleAnnouncedTxsHashes") method handleNewBlockHashes*(ctx: EthWireBase, peer: Peer, hashes: openArray[NewBlockHashesAnnounce]) @@ -83,8 +84,8 @@ method handleNewBlockHashes*(ctx: EthWireBase, peer: Peer, hashes: openArray[New notImplemented("handleNewBlockHashes") when defined(legacy_eth66_enabled): - method getStorageNodes*(ctx: EthWireBase, hashes: openArray[Hash256]): seq[Blob] {.base.} = + method getStorageNodes*(ctx: EthWireBase, hashes: openArray[Hash256]): seq[Blob] {.base, gcsafe.} = notImplemented("getStorageNodes") - method handleNodeData*(ctx: EthWireBase, peer: Peer, data: openArray[Blob]) {.base.} = + method handleNodeData*(ctx: EthWireBase, peer: Peer, data: openArray[Blob]) {.base, gcsafe.} = notImplemented("handleNodeData") diff --git a/nimbus/sync/protocol/les_protocol.nim b/nimbus/sync/protocol/les_protocol.nim index da41a397f..236bc2e39 100644 --- a/nimbus/sync/protocol/les_protocol.nim +++ b/nimbus/sync/protocol/les_protocol.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2018-2023 Status Research & Development GmbH +# Copyright (c) 2018-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -321,13 +321,13 @@ p2pProtocol les(version = lesVersion, if announceType == AnnounceType.Signed: let signature = values.getValue(keyAnnounceSignature, Blob) if signature.isNone: - error "missing announce signature" + chronicles.error "missing announce signature" return let sig = Signature.fromRaw(signature.get).tryGet() let sigMsg = rlp.encodeList(headHash, headNumber, headTotalDifficulty) let signerKey = recover(sig, sigMsg).tryGet() if signerKey.toNodeId != peer.remote.id: - error "invalid announce signature" + chronicles.error "invalid announce signature" # TODO: should we disconnect this peer? return diff --git a/nimbus/sync/protocol/snap/snap_types.nim b/nimbus/sync/protocol/snap/snap_types.nim index d88da7cd9..b3b6d66a8 100644 --- a/nimbus/sync/protocol/snap/snap_types.nim +++ b/nimbus/sync/protocol/snap/snap_types.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2018-2021 Status Research & Development GmbH +# Copyright (c) 2018-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -188,7 +188,7 @@ method getAccountRange*( limit: openArray[byte]; replySizeMax: uint64; ): (seq[SnapAccount], SnapProofNodes) - {.base, raises: [CatchableError].} = + {.base, gcsafe, raises: [CatchableError].} = notImplemented("getAccountRange") method getStorageRanges*( @@ -199,7 +199,7 @@ method getStorageRanges*( limit: openArray[byte]; replySizeMax: uint64; ): (seq[seq[SnapStorage]], SnapProofNodes) - {.base, raises: [CatchableError].} = + {.base, gcsafe, raises: [CatchableError].} = notImplemented("getStorageRanges") method getByteCodes*( @@ -207,7 +207,7 @@ method getByteCodes*( nodes: openArray[Hash256]; replySizeMax: uint64; ): seq[Blob] - {.base, raises: [CatchableError].} = + {.base, gcsafe, raises: [CatchableError].} = notImplemented("getByteCodes") method getTrieNodes*( @@ -216,7 +216,7 @@ method getTrieNodes*( pathGroups: openArray[SnapTriePaths]; replySizeMax: uint64; ): seq[Blob] - {.base, raises: [CatchableError].} = + {.base, gcsafe, raises: [CatchableError].} = notImplemented("getTrieNodes") # ------------------------------------------------------------------------------ diff --git a/nimbus/sync/snap/range_desc.nim b/nimbus/sync/snap/range_desc.nim index 48da8408d..589c26374 100644 --- a/nimbus/sync/snap/range_desc.nim +++ b/nimbus/sync/snap/range_desc.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2018-2021 Status Research & Development GmbH +# Copyright (c) 2018-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -395,7 +395,7 @@ proc fullPC3*(w: openArray[NodeTagRangeSet]): string = proc dump*( ranges: openArray[NodeTagRangeSet]; - moan: proc(overlap: UInt256; iv: NodeTagRange) {.gcsafe.}; + moan: proc(overlap: UInt256; iv: NodeTagRange) {.gcsafe, raises: [].}; printRangesMax = high(int); ): string = ## Dump/anlalyse range sets diff --git a/nimbus/sync/snap/worker/db/snapdb_accounts.nim b/nimbus/sync/snap/worker/db/snapdb_accounts.nim index a1bddb057..209f13b52 100644 --- a/nimbus/sync/snap/worker/db/snapdb_accounts.nim +++ b/nimbus/sync/snap/worker/db/snapdb_accounts.nim @@ -132,7 +132,7 @@ proc dup*( ): SnapDbAccountsRef = ## Resume an accounts session with different `root` key and `peer`. new result - result[].shallowCopy(ps[]) + result.copyWithoutRoot(ps) result.root = root.to(NodeKey) result.peer = peer @@ -142,7 +142,7 @@ proc dup*( ): SnapDbAccountsRef = ## Variant of `dup()` without the `peer` argument. new result - result[].shallowCopy(ps[]) + result.copyWithoutRoot(ps) result.root = root.to(NodeKey) # ------------------------------------------------------------------------------ diff --git a/nimbus/sync/snap/worker/db/snapdb_desc.nim b/nimbus/sync/snap/worker/db/snapdb_desc.nim index 53cd57be9..f4693edba 100644 --- a/nimbus/sync/snap/worker/db/snapdb_desc.nim +++ b/nimbus/sync/snap/worker/db/snapdb_desc.nim @@ -126,6 +126,10 @@ proc init*( new result result.init(ps.base, root) +proc copyWithoutRoot*(a, b: SnapDbBaseRef) = + a.xDb = b.xDb + a.base = b.base + # ------------------------------------------------------------------------------ # Public getters # ------------------------------------------------------------------------------ diff --git a/nimbus/transaction.nim b/nimbus/transaction.nim index dfbc2631d..68c258770 100644 --- a/nimbus/transaction.nim +++ b/nimbus/transaction.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2018 Status Research & Development GmbH +# Copyright (c) 2018-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) # * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) @@ -120,7 +120,7 @@ proc validateTxLegacy(tx: Transaction, fork: EVMFork) = raise newException(ValidationError, "Invalid legacy transaction") proc validateTxEip2930(tx: Transaction) = - var isValid = tx.V in {0'i64, 1'i64} + var isValid = tx.V == 0'i64 or tx.V == 1'i64 isValid = isValid and tx.S >= UInt256.one isValid = isValid and tx.S < SECPK1_N isValid = isValid and tx.R < SECPK1_N diff --git a/nimbus/transaction/call_evm.nim b/nimbus/transaction/call_evm.nim index b08d7bc82..f94a80915 100644 --- a/nimbus/transaction/call_evm.nim +++ b/nimbus/transaction/call_evm.nim @@ -1,6 +1,6 @@ # Nimbus - Various ways of calling the EVM # -# Copyright (c) 2018-2023 Status Research & Development GmbH +# Copyright (c) 2018-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0) # * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT) @@ -204,7 +204,7 @@ proc callParamsForTx(tx: Transaction, sender: EthAddress, vmState: BaseVMState, input: tx.payload ) if tx.txType > TxLegacy: - shallowCopy(result.accessList, tx.accessList) + result.accessList = tx.accessList if tx.txType >= TxEip4844: result.versionedHashes = tx.versionedHashes @@ -225,7 +225,7 @@ proc callParamsForTest(tx: Transaction, sender: EthAddress, vmState: BaseVMState noRefund: true, # Don't apply gas refund/burn rule. ) if tx.txType > TxLegacy: - shallowCopy(result.accessList, tx.accessList) + result.accessList = tx.accessList if tx.txType >= TxEip4844: result.versionedHashes = tx.versionedHashes diff --git a/stateless/test_witness_json.nim b/stateless/test_witness_json.nim index 12b94d27e..b7bff81c6 100644 --- a/stateless/test_witness_json.nim +++ b/stateless/test_witness_json.nim @@ -10,7 +10,7 @@ import eth/common, json, os, unittest2, - ../../nimbus/db/core_db, + ../nimbus/db/core_db, ./tree_from_witness, parseopt, ./witness_types, stew/byteutils diff --git a/stateless/test_witness_verification.nim b/stateless/test_witness_verification.nim index c8656a64a..536e819fe 100644 --- a/stateless/test_witness_verification.nim +++ b/stateless/test_witness_verification.nim @@ -12,8 +12,8 @@ import unittest2, stew/results, eth/[common, trie/trie_defs], - ../../nimbus/db/[ledger, core_db], - ../../nimbus/common/chain_config, + ../nimbus/db/[ledger, core_db], + ../nimbus/common/chain_config, ./[witness_from_tree, multi_keys, witness_types, witness_verification] proc getGenesisAlloc(filePath: string): GenesisAlloc = diff --git a/tests/test_clique.nim b/tests/test_clique.nim index bf26d3a6f..3c50a15c0 100644 --- a/tests/test_clique.nim +++ b/tests/test_clique.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2022-2023 Status Research & Development GmbH +# Copyright (c) 2022-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -78,7 +78,7 @@ proc setErrorLevel = # clique/snapshot_test.go(99): func TestClique(t *testing.T) { proc runCliqueSnapshot(noisy = true; postProcessOk = false; - testIds = {0 .. 999}; skipIds = {0}-{0}) = + testIds = {0'u16 .. 999'u16}; skipIds = {0'u16}-{0'u16}) = ## Clique PoA Snapshot ## :: ## Tests that Clique signer voting is evaluated correctly for various @@ -96,13 +96,13 @@ proc runCliqueSnapshot(noisy = true; postProcessOk = false; setTraceLevel() # clique/snapshot_test.go(379): for i, tt := range tests { - for voterSample in voterSamples.filterIt(it.id in testIds): + for voterSample in voterSamples.filterIt(it.id.uint16 in testIds): let tt = voterSample test &"Snapshots {tt.id:2}: {tt.info.substr(0,50)}...": pool.say "\n" # Noisily skip this test - if tt.id in skipIds: + if tt.id.uint16 in skipIds: skip() else: @@ -133,7 +133,7 @@ proc runCliqueSnapshot(noisy = true; postProcessOk = false; # Verify the final list of signers against the expected ones check snapResult == expected -proc runCliqueSnapshot(noisy = true; postProcessOk = false; testId: int) = +proc runCliqueSnapshot(noisy = true; postProcessOk = false; testId: uint16) = noisy.runCliqueSnapshot(postProcessOk, testIds = {testId}) diff --git a/tests/test_clique/pool.nim b/tests/test_clique/pool.nim index 8e4ca8975..a7bb95cf1 100644 --- a/tests/test_clique/pool.nim +++ b/tests/test_clique/pool.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2021-2023 Status Research & Development GmbH +# Copyright (c) 2021-2024 Status Research & Development GmbH # Licensed under either of # * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or # http://www.apache.org/licenses/LICENSE-2.0) @@ -410,7 +410,7 @@ proc appendVoter*(ap: TesterPool; checkPoint = voter.checkpoint.mapIt(ap.address(it)).sorted(EthAscending)) if 0 < voter.checkpoint.len: - doAssert (header.blockNumber mod ap.clique.cfg.epoch) == 0 + doAssert (header.blockNumber mod ap.clique.cfg.epoch).isZero # Register for debugging let diff --git a/tests/test_coredb.nim b/tests/test_coredb.nim index 0541b992e..40330f372 100644 --- a/tests/test_coredb.nim +++ b/tests/test_coredb.nim @@ -16,8 +16,9 @@ import eth/common, results, unittest2, - ../../nimbus/db/[core_db/persistent, ledger], - ../../nimbus/core/chain, + ../nimbus/db/core_db/persistent, + ../nimbus/db/ledger, + ../nimbus/core/chain, ./replay/pp, ./test_coredb/[coredb_test_xx, test_chainsync, test_helpers] diff --git a/tests/test_rpc_experimental_json.nim b/tests/test_rpc_experimental_json.nim index d183c64e4..da4c8e2d5 100644 --- a/tests/test_rpc_experimental_json.nim +++ b/tests/test_rpc_experimental_json.nim @@ -13,7 +13,7 @@ import ../nimbus/core/chain, ../nimbus/common/common, ../nimbus/rpc, - ../../nimbus/db/[ledger, core_db], + ../nimbus/db/[ledger, core_db], ../stateless/[witness_verification, witness_types], ./rpc/experimental_rpc_client diff --git a/tests/test_rpc_getproofs_track_state_changes.nim b/tests/test_rpc_getproofs_track_state_changes.nim index c3dbd1244..a24b4935d 100644 --- a/tests/test_rpc_getproofs_track_state_changes.nim +++ b/tests/test_rpc_getproofs_track_state_changes.nim @@ -31,7 +31,9 @@ import ../nimbus/core/chain, ../nimbus/common/common, ../nimbus/rpc, - ../../nimbus/db/[core_db, core_db/persistent, state_db/base], + ../nimbus/db/core_db, + ../nimbus/db/core_db/persistent, + ../nimbus/db/state_db/base, ../stateless/[witness_verification, witness_types], ./rpc/experimental_rpc_client diff --git a/vendor/ethash b/vendor/ethash index c1d640184..0306443c5 160000 --- a/vendor/ethash +++ b/vendor/ethash @@ -1 +1 @@ -Subproject commit c1d640184bffa38714974e883f9a9f856779fefa +Subproject commit 0306443c52db0bffb59650ad10bcb119477ce9b1 diff --git a/vendor/nim-eth b/vendor/nim-eth index 2ad07a601..b9c40e138 160000 --- a/vendor/nim-eth +++ b/vendor/nim-eth @@ -1 +1 @@ -Subproject commit 2ad07a60109a4609d672f9f147eeee987e43a15d +Subproject commit b9c40e1380e328d25210bad9bd15da3801df32fe diff --git a/vendor/nim-metrics b/vendor/nim-metrics index a2293e8a3..0e768ca7f 160000 --- a/vendor/nim-metrics +++ b/vendor/nim-metrics @@ -1 +1 @@ -Subproject commit a2293e8a34f2a6cf264aec47e4becf2f53a0e467 +Subproject commit 0e768ca7fb7df4798649145a403e7db65cae1f8b diff --git a/vendor/nim-rocksdb b/vendor/nim-rocksdb index 724b72fe1..5e2b026f8 160000 --- a/vendor/nim-rocksdb +++ b/vendor/nim-rocksdb @@ -1 +1 @@ -Subproject commit 724b72fe104bd0af5e1520326e68e9cee0890ec8 +Subproject commit 5e2b026f841fa57b10e669a2ab1d88a0e40f6bbe diff --git a/vendor/nim-web3 b/vendor/nim-web3 index ce47cde31..10538c667 160000 --- a/vendor/nim-web3 +++ b/vendor/nim-web3 @@ -1 +1 @@ -Subproject commit ce47cde31c9b08e4b702766d4d788cc83fa55cf0 +Subproject commit 10538c667a0a29c7692cce3679ff3bb002624086