diff --git a/Makefile b/Makefile index 8a3624013..98fa648c3 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -# Copyright (c) 2018-2023 Status Research & Development GmbH. Licensed under +# Copyright (c) 2018-2024 Status Research & Development GmbH. Licensed under # either of: # - Apache License, version 2.0 # - MIT license @@ -115,6 +115,7 @@ GIT_SUBMODULE_UPDATE := git -c submodule."vendor/nimbus-eth2".update=none submod git submodule update --init vendor/eth2-networks; \ git submodule update --init vendor/holesky; \ git submodule update --init vendor/sepolia; \ + git submodule update --init vendor/goerli; \ git submodule update --init vendor/gnosis-chain-configs; \ git submodule update --init --recursive vendor/nim-kzg4844; \ cd ../.. diff --git a/fluffy/network/beacon/beacon_init_loader.nim b/fluffy/network/beacon/beacon_init_loader.nim index e532aa510..6826c2b64 100644 --- a/fluffy/network/beacon/beacon_init_loader.nim +++ b/fluffy/network/beacon/beacon_init_loader.nim @@ -1,5 +1,5 @@ # Nimbus - Portal Network -# Copyright (c) 2022-2023 Status Research & Development GmbH +# Copyright (c) 2022-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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -8,6 +8,7 @@ {.push raises: [].} import + chronicles, beacon_chain/networking/network_metadata, beacon_chain/spec/forks, beacon_chain/spec/datatypes/altair, @@ -38,7 +39,10 @@ proc loadNetworkData*( except CatchableError as err: raiseAssert "Invalid baked-in state: " & err.msg - beaconClock = BeaconClock.init(getStateField(genesisState[], genesis_time)) + genesisTime = getStateField(genesisState[], genesis_time) + beaconClock = BeaconClock.init(genesisTime).valueOr: + error "Invalid genesis time in state", genesisTime + quit QuitFailure genesis_validators_root = getStateField(genesisState[], genesis_validators_root) diff --git a/fluffy/tests/test_portal_wire_protocol.nim b/fluffy/tests/test_portal_wire_protocol.nim index 3179143f1..222bc9e31 100644 --- a/fluffy/tests/test_portal_wire_protocol.nim +++ b/fluffy/tests/test_portal_wire_protocol.nim @@ -1,5 +1,5 @@ # Fluffy -# Copyright (c) 2021-2023 Status Research & Development GmbH +# Copyright (c) 2021-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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). diff --git a/fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim b/fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim index cdf9b5e12..a4e87c69f 100644 --- a/fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim +++ b/fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2023-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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -389,7 +389,10 @@ proc run(config: BeaconBridgeConf) {.raises: [CatchableError].} = except CatchableError as err: raiseAssert "Invalid baked-in state: " & err.msg - beaconClock = BeaconClock.init(getStateField(genesisState[], genesis_time)) + genesisTime = getStateField(genesisState[], genesis_time) + beaconClock = BeaconClock.init(genesisTime).valueOr: + error "Invalid genesis time in state", genesisTime + quit QuitFailure getBeaconTime = beaconClock.getBeaconTimeFn() diff --git a/fluffy/tools/eth_data_exporter/cl_data_exporter.nim b/fluffy/tools/eth_data_exporter/cl_data_exporter.nim index bfdd71070..e2e5d2017 100644 --- a/fluffy/tools/eth_data_exporter/cl_data_exporter.nim +++ b/fluffy/tools/eth_data_exporter/cl_data_exporter.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2023-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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -39,8 +39,10 @@ proc getBeaconData*(): ( forkDigests = newClone ForkDigests.init( metadata.cfg, genesis_validators_root) - beaconClock = BeaconClock.init(getStateField(genesisState[], genesis_time)) - + genesisTime = getStateField(genesisState[], genesis_time) + beaconClock = BeaconClock.init(genesisTime).valueOr: + error "Invalid genesis time in state", genesisTime + quit QuitFailure return (metadata.cfg, forkDigests, beaconClock) diff --git a/fluffy/tools/portal_bridge/portal_bridge.nim b/fluffy/tools/portal_bridge/portal_bridge.nim index f3c84bbd2..38554b354 100644 --- a/fluffy/tools/portal_bridge/portal_bridge.nim +++ b/fluffy/tools/portal_bridge/portal_bridge.nim @@ -1,5 +1,5 @@ # Fluffy -# Copyright (c) 2023 Status Research & Development GmbH +# Copyright (c) 2023-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). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -62,7 +62,7 @@ proc runBeacon(config: PortalBridgeConf) {.raises: [CatchableError].} = portalRpcClient = newRpcHttpClient() restClient = RestClientRef.new(config.restUrl).valueOr: fatal "Cannot connect to server", error = $error - quit 1 + quit QuitFailure proc backfill( beaconRestClient: RestClientRef, rpcAddress: string, rpcPort: Port, diff --git a/nimbus/common/hardforks.nim b/nimbus/common/hardforks.nim index 04b01748f..b33bb7b66 100644 --- a/nimbus/common/hardforks.nim +++ b/nimbus/common/hardforks.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)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) @@ -199,13 +199,13 @@ type time*: Option[EthTime] func countTimeFields(): int {.compileTime.} = - var z = Chainconfig() + var z = ChainConfig() for name, _ in fieldPairs(z[]): if name.endsWith("Time"): inc result func countBlockFields(): int {.compileTime.} = - var z = Chainconfig() + var z = ChainConfig() for name, _ in fieldPairs(z[]): if name == "mergeNetsplitBlock": # skip mergeForkBlock alias @@ -219,7 +219,7 @@ const blockFieldsCount = countBlockFields() func collectTimeFields(): array[timeFieldsCount, string] = - var z = Chainconfig() + var z = ChainConfig() var i = 0 for name, _ in fieldPairs(z[]): if name.endsWith("Time"): @@ -227,7 +227,7 @@ func collectTimeFields(): array[timeFieldsCount, string] = inc i func collectBlockFields(): array[blockFieldsCount, string] = - var z = Chainconfig() + var z = ChainConfig() var i = 0 for name, _ in fieldPairs(z[]): if name == "mergeNetsplitBlock": diff --git a/nimbus/evm/async/data_sources.nim b/nimbus/evm/async/data_sources.nim index adc7d0399..c981c8b81 100644 --- a/nimbus/evm/async/data_sources.nim +++ b/nimbus/evm/async/data_sources.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) @@ -17,10 +17,10 @@ import type AsyncDataSource* = ref object of RootObj - ifNecessaryGetSlots*: proc(db: CoreDbRef, blockNumber: BlockNumber, stateRoot: Hash256, address: EthAddress, slots: seq[UInt256], newStateRootForSanityChecking: Hash256): Future[void] {.gcsafe.} - ifNecessaryGetCode*: proc(db: CoreDbRef, blockNumber: BlockNumber, stateRoot: Hash256, address: EthAddress, newStateRootForSanityChecking: Hash256): Future[void] {.gcsafe.} - ifNecessaryGetAccount*: proc(db: CoreDbRef, blockNumber: BlockNumber, stateRoot: Hash256, address: EthAddress, newStateRootForSanityChecking: Hash256): Future[void] {.gcsafe.} - ifNecessaryGetBlockHeaderByNumber*: proc(coreDb: CoreDbRef, blockNumber: BlockNumber): Future[void] {.gcsafe.} + ifNecessaryGetSlots*: proc(db: CoreDbRef, blockNumber: BlockNumber, stateRoot: Hash256, address: EthAddress, slots: seq[UInt256], newStateRootForSanityChecking: Hash256): Future[void] {.gcsafe, raises: [].} + ifNecessaryGetCode*: proc(db: CoreDbRef, blockNumber: BlockNumber, stateRoot: Hash256, address: EthAddress, newStateRootForSanityChecking: Hash256): Future[void] {.gcsafe, raises: [].} + ifNecessaryGetAccount*: proc(db: CoreDbRef, blockNumber: BlockNumber, stateRoot: Hash256, address: EthAddress, newStateRootForSanityChecking: Hash256): Future[void] {.gcsafe, raises: [].} + ifNecessaryGetBlockHeaderByNumber*: proc(coreDb: CoreDbRef, blockNumber: BlockNumber): Future[void] {.gcsafe, raises: [].} # FIXME-Adam: Later. #fetchNodes*: proc(stateRoot: Hash256, paths: seq[seq[seq[byte]]], nodeHashes: seq[Hash256]): Future[seq[seq[byte]]] {.gcsafe.} fetchBlockHeaderWithHash*: proc(h: Hash256): Future[BlockHeader] {.gcsafe.} @@ -50,6 +50,7 @@ proc ifNecessaryGetCode*(asyncFactory: AsyncOperationFactory, db: CoreDbRef, blo if asyncFactory.maybeDataSource.isSome: await asyncFactory.maybeDataSource.get.ifNecessaryGetCode(db, blockNumber, stateRoot, address, newStateRootForSanityChecking) + proc ifNecessaryGetAccount*(asyncFactory: AsyncOperationFactory, db: CoreDbRef, blockNumber: BlockNumber, stateRoot: Hash256, address: EthAddress, newStateRootForSanityChecking: Hash256): Future[void] {.async.} = if asyncFactory.maybeDataSource.isSome: await asyncFactory.maybeDataSource.get.ifNecessaryGetAccount(db, blockNumber, stateRoot, address, newStateRootForSanityChecking) diff --git a/nimbus/evm/async/data_sources/json_rpc_data_source.nim b/nimbus/evm/async/data_sources/json_rpc_data_source.nim index 50888739e..c3cdda914 100644 --- a/nimbus/evm/async/data_sources/json_rpc_data_source.nim +++ b/nimbus/evm/async/data_sources/json_rpc_data_source.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) @@ -186,7 +186,7 @@ proc fetchUsingGetNodeData(peer: Peer, nodeHashes: seq[common.Hash256]): Future[ # AARDVARK whatever return @[] -proc findPeersAndMakeSomeCalls[R](peerPool: PeerPool, protocolName: string, protocolType: typedesc, initiateAttempt: (proc(p: Peer): Future[R] {.gcsafe.})): Future[seq[Future[R]]] {.async.} = +proc findPeersAndMakeSomeCalls[R](peerPool: PeerPool, protocolName: string, protocolType: typedesc, initiateAttempt: (proc(p: Peer): Future[R] {.gcsafe, raises: [].})): Future[seq[Future[R]]] {.async.} = var attempts: seq[Future[R]] while true: #info("AARDVARK: findPeersAndMakeSomeCalls about to loop through the peer pool", count=peerPool.connectedNodes.len) diff --git a/nimbus/graphql/ethapi.nim b/nimbus/graphql/ethapi.nim index 8f622ced9..7aa4bbd86 100644 --- a/nimbus/graphql/ethapi.nim +++ b/nimbus/graphql/ethapi.nim @@ -1,5 +1,5 @@ # nim-graphql -# Copyright (c) 2021 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)) # * MIT license ([LICENSE-MIT](LICENSE-MIT)) @@ -74,15 +74,14 @@ type ethNode: EthereumNode txPool: TxPoolRef -when (NimMajor, NimMinor, NimPatch) >= (1, 6, 0): - {.push hint[XCannotRaiseY]: off.} -else: - {.push hint[XDeclaredButNotUsed]: off.} +{.push gcsafe, raises: [].} +{.pragma: apiRaises, raises: [].} +{.pragma: apiPragma, cdecl, gcsafe, apiRaises, locks:0.} -proc toHash(n: Node): Hash256 = +proc toHash(n: Node): Hash256 {.gcsafe, raises: [ValueError].} = result.data = hexToByteArray[32](n.stringVal) -proc toBlockNumber(n: Node): BlockNumber = +proc toBlockNumber(n: Node): BlockNumber {.gcsafe, raises: [ValueError].} = if n.kind == nkInt: result = parse(n.intVal, UInt256, radix = 10) elif n.kind == nkString: @@ -331,10 +330,10 @@ proc getTxAt(ctx: GraphqlContextRef, header: BlockHeader, index: int): RespResul ok(txn) else: ok(respNull()) - except CatchableError as e: - err("can't get transaction by index '$1': $2" % [$index, e.msg]) - except RlpError as em: - err("can't get transaction by index '$1': $2" % [$index, em.msg]) + except CatchableError as exc: + err("can't get transaction by index '" & $index & "': " & exc.msg) + except RlpError as exc: + err("can't get transaction by index '" & $index & "': " & exc.msg) proc getTxByHash(ctx: GraphqlContextRef, hash: Hash256): RespResult = try: @@ -342,7 +341,7 @@ proc getTxByHash(ctx: GraphqlContextRef, hash: Hash256): RespResult = let header = getBlockHeader(ctx.chainDB, blockNumber) getTxAt(ctx, header, index) except CatchableError as e: - err("can't get transaction by hash '$1': $2" % [hash.data.toHex, e.msg]) + err("can't get transaction by hash '" & hash.data.toHex & "': $2" & e.msg) proc accountNode(ctx: GraphqlContextRef, header: BlockHeader, address: EthAddress): RespResult = try: @@ -377,16 +376,12 @@ proc parseU64(node: Node): uint64 = for c in node.intVal: result = result * 10 + (c.uint64 - '0'.uint64) -{.pragma: apiRaises, raises: [].} - -{.pragma: apiPragma, cdecl, gcsafe, apiRaises, locks:0.} -{.push hint[XDeclaredButNotUsed]: off.} - proc validateHex(x: Node, minLen = 0): NodeResult = if x.stringVal.len < 2: return err("hex is too short") if x.stringVal.len != 2 + minLen * 2 and minLen != 0: - return err("expect hex with len '$1', got '$2'" % [$(2 * minLen + 2), $x.stringVal.len]) + return err("expect hex with len '" & + $(2 * minLen + 2) & "', got '" & $x.stringVal.len & "'") if x.stringVal.len mod 2 != 0: return err("hex must have even number of nibbles") if x.stringVal[0] != '0' or x.stringVal[1] != 'x': @@ -419,51 +414,54 @@ proc validateFixedLenHex(x: Node, minLen: int, kind: string, padding = false): N if x.stringVal.len < 2: return err(kind & " hex is too short") - var prefixLen = 0 - if x.stringVal[0] == '0' and x.stringVal[1] == 'x': - prefixLen = 2 + try: + var prefixLen = 0 + if x.stringVal[0] == '0' and x.stringVal[1] == 'x': + prefixLen = 2 - let expectedLen = minLen * 2 + prefixLen - if x.stringVal.len < expectedLen: - if not padding: - return err("$1 len is too short: expect $2 got $3" % + let expectedLen = minLen * 2 + prefixLen + if x.stringVal.len < expectedLen: + if not padding: + return err("$1 len is too short: expect $2 got $3" % + [kind, $expectedLen, $x.stringVal.len]) + else: + padBytes(x, prefixLen, minLen * 2) + elif x.stringVal.len > expectedLen: + return err("$1 len is too long: expect $2 got $3" % [kind, $expectedLen, $x.stringVal.len]) - else: - padBytes(x, prefixLen, minLen * 2) - elif x.stringVal.len > expectedLen: - return err("$1 len is too long: expect $2 got $3" % - [kind, $expectedLen, $x.stringVal.len]) - for i in prefixLen..