diff --git a/fluffy/fluffy.nim b/fluffy/fluffy.nim index 86b928802..16d6c5b1b 100644 --- a/fluffy/fluffy.nim +++ b/fluffy/fluffy.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). @@ -260,9 +260,10 @@ proc run(config: PortalConf) {.raises: [CatchableError].} = lc.start() proc onSecond(time: Moment) = - let wallSlot = lc.getBeaconTime().slotOrZero() + discard # TODO: # Figure out what to do with this one. + # let wallSlot = lc.getBeaconTime().slotOrZero() # lc.updateGossipStatus(wallSlot + 1) proc runOnSecondLoop() {.async.} = diff --git a/fluffy/network/beacon/beacon_db.nim b/fluffy/network/beacon/beacon_db.nim index 2b84c86fa..c4b75f132 100644 --- a/fluffy/network/beacon/beacon_db.nim +++ b/fluffy/network/beacon/beacon_db.nim @@ -1,5 +1,5 @@ -# Nimbus -# Copyright (c) 2022-2023 Status Research & Development GmbH +# fluffy +# 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). @@ -101,7 +101,7 @@ proc initBestUpdatesStore( delStmt: delStmt ) -func close(store: var BestLightClientUpdateStore) = +func close*(store: var BestLightClientUpdateStore) = store.getStmt.disposeSafe() store.getBulkStmt.disposeSafe() store.putStmt.disposeSafe() diff --git a/fluffy/network/beacon/beacon_init_loader.nim b/fluffy/network/beacon/beacon_init_loader.nim index 6826c2b64..16eb55610 100644 --- a/fluffy/network/beacon/beacon_init_loader.nim +++ b/fluffy/network/beacon/beacon_init_loader.nim @@ -1,4 +1,4 @@ -# Nimbus - Portal Network +# fluffy # 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). @@ -18,25 +18,19 @@ import type NetworkInitData* = object clock*: BeaconClock - metaData*: Eth2NetworkMetadata + metadata*: Eth2NetworkMetadata forks*: ForkDigests genesis_validators_root*: Eth2Digest -proc loadNetworkData*( - networkName: string): NetworkInitData {.raises: [CatchableError].} = +proc loadNetworkData*(networkName: string): NetworkInitData = let - metadata = - try: - loadEth2Network(some("mainnet")) - except CatchableError as exc: - raiseAssert(exc.msg) - + metadata = loadEth2Network(some("mainnet")) genesisState = try: template genesisData(): auto = metadata.genesis.bakedBytes newClone(readSszForkedHashedBeaconState( metadata.cfg, genesisData.toOpenArray(genesisData.low, genesisData.high))) - except CatchableError as err: + except SerializationError as err: raiseAssert "Invalid baked-in state: " & err.msg genesisTime = getStateField(genesisState[], genesis_time) @@ -51,7 +45,7 @@ proc loadNetworkData*( return NetworkInitData( clock: beaconClock, - metaData: metaData, + metadata: metadata, forks: forks[], genesis_validators_root: genesis_validators_root ) diff --git a/fluffy/network/beacon/beacon_light_client_manager.nim b/fluffy/network/beacon/beacon_light_client_manager.nim index 519176f23..5f5babedc 100644 --- a/fluffy/network/beacon/beacon_light_client_manager.nim +++ b/fluffy/network/beacon/beacon_light_client_manager.nim @@ -1,5 +1,5 @@ -# beacon hain light client -# Copyright (c) 2022-2023 Status Research & Development GmbH +# fluffy +# 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). @@ -275,41 +275,6 @@ proc query[E]( # requests however, see: https://github.com/status-im/nimbus-eth1/issues/1769 self.workerTask(e, key) -template query[E]( - self: LightClientManager, - e: typedesc[E] -): Future[bool] = - self.query(e, Nothing()) - -type SchedulingMode = enum - Soon, - CurrentPeriod, - NextPeriod - -func fetchTime( - self: LightClientManager, - wallTime: BeaconTime, - schedulingMode: SchedulingMode -): BeaconTime = - let - remainingTime = - case schedulingMode: - of Soon: - chronos.seconds(0) - of CurrentPeriod: - let - wallPeriod = wallTime.slotOrZero().sync_committee_period - deadlineSlot = (wallPeriod + 1).start_slot - 1 - deadline = deadlineSlot.start_beacon_time() - chronos.nanoseconds((deadline - wallTime).nanoseconds) - of NextPeriod: - chronos.seconds( - (SLOTS_PER_SYNC_COMMITTEE_PERIOD * SECONDS_PER_SLOT).int64) - minDelay = max(remainingTime div 8, chronos.seconds(10)) - jitterSeconds = (minDelay * 2).seconds - jitterDelay = chronos.seconds(self.rng[].rand(jitterSeconds).int64) - return wallTime + minDelay + jitterDelay - # https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.1/specs/altair/light-client/light-client.md#light-client-sync-process proc loop(self: LightClientManager) {.async.} = var nextSyncTaskTime = self.getBeaconTime() diff --git a/fluffy/network/wire/portal_protocol.nim b/fluffy/network/wire/portal_protocol.nim index 303fbd511..a7c873625 100644 --- a/fluffy/network/wire/portal_protocol.nim +++ b/fluffy/network/wire/portal_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). @@ -291,7 +291,9 @@ func truncateEnrs( for n in nodes: let enr = ByteList.init(n.record.raw) if totalSize + enr.len() + enrOverhead <= maxSize: - let res = enrs.add(enr) # 32 limit will not be reached + let res = enrs.add(enr) + # With max payload of discv5 and the sizes of ENRs this should not occur. + doAssert(res, "32 limit will not be reached") totalSize = totalSize + enr.len() else: break @@ -857,6 +859,8 @@ proc offer(p: PortalProtocol, o: OfferRequest): # No point in trying to continue writing data socket.close() return err("Error writing requested data") + + trace "Offered content item send", dataWritten = dataWritten of Database: for i, b in m.contentKeys: if b: @@ -884,6 +888,7 @@ proc offer(p: PortalProtocol, o: OfferRequest): socket.close() return err("Error writing requested data") + trace "Offered content item send", dataWritten = dataWritten await socket.closeWait() debug "Content successfully offered" @@ -1231,8 +1236,6 @@ proc traceContentLookup*(p: PortalProtocol, target: ByteList, targetId: UInt256) let distance = p.distance(content.src.id, targetId) - let address = content.src.address.get() - responses["0x" & $content.src.id] = TraceResponse( durationMs: duration, respondedWith: respondedWith, diff --git a/fluffy/nim.cfg b/fluffy/nim.cfg index 1d6e47d2f..e262b3424 100644 --- a/fluffy/nim.cfg +++ b/fluffy/nim.cfg @@ -16,6 +16,5 @@ --styleCheck:usages --styleCheck:hint ---hint[XDeclaredButNotUsed]:off --hint[ConvFromXtoItselfNotNeeded]:off --hint[Processing]:off diff --git a/fluffy/rpc/rpc_eth_api.nim b/fluffy/rpc/rpc_eth_api.nim index d504a1617..a15d22ae4 100644 --- a/fluffy/rpc/rpc_eth_api.nim +++ b/fluffy/rpc/rpc_eth_api.nim @@ -116,8 +116,7 @@ proc installEthApiHandlers*( # Currently only HistoryNetwork needed, later we might want a master object # holding all the networks. rpcServerWithProxy: var RpcProxy, historyNetwork: HistoryNetwork, - beaconLightClient: Opt[LightClient]) - {.raises: [CatchableError].} = + beaconLightClient: Opt[LightClient]) = # Supported API rpcServerWithProxy.registerProxyMethod("eth_blockNumber") diff --git a/fluffy/rpc/rpc_portal_api.nim b/fluffy/rpc/rpc_portal_api.nim index 7fd2d47d9..64c68dc65 100644 --- a/fluffy/rpc/rpc_portal_api.nim +++ b/fluffy/rpc/rpc_portal_api.nim @@ -1,4 +1,4 @@ -# Nimbus +# fluffy # 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). @@ -40,8 +40,7 @@ TraceResponse.useDefaultSerializationIn JrpcConv # as the proc becomes generic, where the rpc macro from router.nim can no longer # be found, which is why we export rpcserver which should export router. proc installPortalApiHandlers*( - rpcServer: RpcServer|RpcProxy, p: PortalProtocol, network: static string) - {.raises: [CatchableError].} = + rpcServer: RpcServer|RpcProxy, p: PortalProtocol, network: static string) = rpcServer.rpc("portal_" & network & "NodeInfo") do() -> NodeInfo: return p.routingTable.getNodeInfo() diff --git a/fluffy/rpc/rpc_portal_debug_api.nim b/fluffy/rpc/rpc_portal_debug_api.nim index 0b2013a2c..43db716e9 100644 --- a/fluffy/rpc/rpc_portal_debug_api.nim +++ b/fluffy/rpc/rpc_portal_debug_api.nim @@ -1,5 +1,5 @@ # Fluffy -# 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). @@ -18,8 +18,7 @@ export rpcserver # Non-spec-RPCs that are (currently) useful for testing & debugging proc installPortalDebugApiHandlers*( - rpcServer: RpcServer|RpcProxy, p: PortalProtocol, network: static string) - {.raises: [CatchableError].} = + rpcServer: RpcServer|RpcProxy, p: PortalProtocol, network: static string) = rpcServer.rpc("portal_" & network & "_storeContent") do( dataFile: string) -> bool: diff --git a/fluffy/rpc/rpc_web3_api.nim b/fluffy/rpc/rpc_web3_api.nim index 70e9e8061..be941ae7a 100644 --- a/fluffy/rpc/rpc_web3_api.nim +++ b/fluffy/rpc/rpc_web3_api.nim @@ -1,5 +1,5 @@ -# Nimbus fluffy -# Copyright (c) 2023 Status Research & Development GmbH +# fluffy +# 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). @@ -13,8 +13,7 @@ import export rpcserver -proc installWeb3ApiHandlers*(rpcServer: RpcServer|RpcProxy) - {.raises: [CatchableError].} = +proc installWeb3ApiHandlers*(rpcServer: RpcServer|RpcProxy) = rpcServer.rpc("web3_clientVersion") do() -> string: return clientVersion diff --git a/fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim b/fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim index d2783fb5f..05d943c98 100644 --- a/fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim +++ b/fluffy/tools/beacon_lc_bridge/beacon_lc_bridge.nim @@ -106,23 +106,6 @@ template asEthHash(hash: web3types.BlockHash): Hash256 = template unsafeQuantityToInt64(q: Quantity): int64 = int64 q -# TODO: Cannot use the `hexToInt` from rpc_utils as it importing that causes a -# strange "Exception can raise an unlisted exception: Exception` compile error. -func hexToInt( - s: string, T: typedesc[SomeInteger]): T {.raises: [ValueError].} = - var i = 0 - if s[i] == '0' and (s[i+1] in {'x', 'X'}): - inc(i, 2) - if s.len - i > sizeof(T) * 2: - raise newException(ValueError, "Input hex too big for destination int") - - var res: T = 0 - while i < s.len: - res = res shl 4 or readHexChar(s[i]).T - inc(i) - - res - func asTxType(quantity: Option[Quantity]): Result[TxType, string] = let value = quantity.get(0.Quantity).uint8 var txType: TxType @@ -553,7 +536,6 @@ proc run(config: BeaconBridgeConf) {.raises: [CatchableError].} = let root = hash_tree_root(forkyObject.header) contentKey = encode(bootstrapContentKey(root)) - contentId = beacon_content.toContentId(contentKey) forkDigest = forkDigestAtEpoch( forkDigests[], epoch(forkyObject.header.beacon.slot), cfg) content = encodeBootstrapForked( @@ -586,7 +568,6 @@ proc run(config: BeaconBridgeConf) {.raises: [CatchableError].} = let period = forkyObject.attested_header.beacon.slot.sync_committee_period contentKey = encode(updateContentKey(period.uint64, uint64(1))) - contentId = beacon_content.toContentId(contentKey) forkDigest = forkDigestAtEpoch( forkDigests[], epoch(forkyObject.attested_header.beacon.slot), cfg) content = encodeLightClientUpdatesForked( @@ -621,7 +602,6 @@ proc run(config: BeaconBridgeConf) {.raises: [CatchableError].} = let slot = forkyObject.signature_slot contentKey = encode(optimisticUpdateContentKey(slot.uint64)) - contentId = beacon_content.toContentId(contentKey) forkDigest = forkDigestAtEpoch( forkDigests[], epoch(forkyObject.attested_header.beacon.slot), cfg) content = encodeOptimisticUpdateForked( @@ -655,7 +635,6 @@ proc run(config: BeaconBridgeConf) {.raises: [CatchableError].} = let finalizedSlot = forkyObject.finalized_header.beacon.slot contentKey = encode(finalityUpdateContentKey(finalizedSlot.uint64)) - contentId = beacon_content.toContentId(contentKey) forkDigest = forkDigestAtEpoch( forkDigests[], epoch(forkyObject.attested_header.beacon.slot), cfg) content = encodeFinalityUpdateForked( diff --git a/fluffy/tools/eth_data_exporter/cl_data_exporter.nim b/fluffy/tools/eth_data_exporter/cl_data_exporter.nim index e2e5d2017..975b0f24b 100644 --- a/fluffy/tools/eth_data_exporter/cl_data_exporter.nim +++ b/fluffy/tools/eth_data_exporter/cl_data_exporter.nim @@ -23,7 +23,7 @@ const restRequestsTimeout = 30.seconds proc getBeaconData*(): ( - RuntimeConfig, ref ForkDigests, BeaconClock) {.raises: [IOError].} = + RuntimeConfig, ref ForkDigests, BeaconClock) = let metadata = getMetadataForNetwork("mainnet") genesisState = @@ -32,7 +32,7 @@ proc getBeaconData*(): ( newClone(readSszForkedHashedBeaconState( metadata.cfg, genesisData.toOpenArray(genesisData.low, genesisData.high))) - except CatchableError as err: + except SerializationError as err: raiseAssert "Invalid baked-in state: " & err.msg genesis_validators_root = getStateField(genesisState[], genesis_validators_root) @@ -60,14 +60,12 @@ proc exportLCBootstrapUpdate*( fatal "Error occured while closing file", error = e.msg quit 1 - var + let client = RestClientRef.new(restUrl).valueOr: error "Cannot connect to server", error = error quit 1 - var contentTable: JsonPortalContentTable - - var update = + let update = try: notice "Downloading LC bootstrap" awaitWithTimeout( @@ -118,14 +116,12 @@ proc exportLCUpdates*( fatal "Error occured while closing file", error = e.msg quit 1 - var + let client = RestClientRef.new(restUrl).valueOr: error "Cannot connect to server", error = error quit 1 - var contentTable: JsonPortalContentTable - - var updates = + let updates = try: notice "Downloading LC updates" awaitWithTimeout( @@ -181,14 +177,12 @@ proc exportLCFinalityUpdate*( fatal "Error occured while closing file", error = e.msg quit 1 - var + let client = RestClientRef.new(restUrl).valueOr: error "Cannot connect to server", error = error quit 1 - var contentTable: JsonPortalContentTable - - var update = + let update = try: notice "Downloading LC finality update" awaitWithTimeout( @@ -207,7 +201,6 @@ proc exportLCFinalityUpdate*( let finalizedSlot = forkyObject.finalized_header.beacon.slot contentKey = encode(finalityUpdateContentKey(finalizedSlot.uint64)) - contentId = beacon_content.toContentId(contentKey) forkDigest = forkDigestAtEpoch( forkDigests[], epoch(forkyObject.attested_header.beacon.slot), cfg) content = encodeFinalityUpdateForked( @@ -238,14 +231,12 @@ proc exportLCOptimisticUpdate*( fatal "Error occured while closing file", error = e.msg quit 1 - var + let client = RestClientRef.new(restUrl).valueOr: error "Cannot connect to server", error = error quit 1 - var contentTable: JsonPortalContentTable - - var update = + let update = try: notice "Downloading LC optimistic update" awaitWithTimeout( @@ -264,7 +255,6 @@ proc exportLCOptimisticUpdate*( let slot = forkyObject.signature_slot contentKey = encode(optimisticUpdateContentKey(slot.uint64)) - contentId = beacon_content.toContentId(contentKey) forkDigest = forkDigestAtEpoch( forkDigests[], epoch(forkyObject.attested_header.beacon.slot), cfg) content = encodeOptimisticUpdateForked( diff --git a/fluffy/tools/fcli_db.nim b/fluffy/tools/fcli_db.nim index e846f10b0..10d4c0f53 100644 --- a/fluffy/tools/fcli_db.nim +++ b/fluffy/tools/fcli_db.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). @@ -108,7 +108,7 @@ proc cmdBench(conf: DbConf) = for key in keys: withTimer(timers[tDbGet]): - let val = db.get(key) + let _ = db.get(key) for key in keys: withTimer(timers[tDbContains]): @@ -120,17 +120,17 @@ proc cmdBench(conf: DbConf) = for i in 0.. LightClientDataFork.None: let slot = forkyObject.attested_header.beacon.slot - period = forkyObject.attested_header.beacon.slot.sync_committee_period + period = slot.sync_committee_period contentKey = encode(updateContentKey(period.uint64, count)) - forkDigest = forkDigestAtEpoch( - forkDigests[], epoch(forkyObject.attested_header.beacon.slot), cfg) + forkDigest = forkDigestAtEpoch(forkDigests[], epoch(slot), cfg) content = encodeLightClientUpdatesForked( forkDigest, diff --git a/fluffy/tools/portal_bridge/portal_bridge_conf.nim b/fluffy/tools/portal_bridge/portal_bridge_conf.nim index 4a3cf5a04..945d18e19 100644 --- a/fluffy/tools/portal_bridge/portal_bridge_conf.nim +++ b/fluffy/tools/portal_bridge/portal_bridge_conf.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). @@ -60,7 +60,7 @@ type name: "rest-url" .}: string # Backfill options - backFillAmount* {. + backfillAmount* {. desc: "Amount of beacon LC updates to backfill gossip into the network" defaultValue: 64 name: "backfill-amount" .}: uint64 diff --git a/fluffy/tools/portalcli.nim b/fluffy/tools/portalcli.nim index 55d436f9b..a30690607 100644 --- a/fluffy/tools/portalcli.nim +++ b/fluffy/tools/portalcli.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). @@ -261,10 +261,7 @@ proc run(config: PortalCliConf) = else: echo nodes.error of findContent: - proc random(T: type UInt256, rng: var HmacDrbgContext): T = - rng.generate(T) - - # For now just some random bytes + # For now just some bogus bytes let contentKey = ByteList.init(@[1'u8]) let foundContent = waitFor portal.findContent(config.findContentTarget, diff --git a/nimbus_verified_proxy/nim.cfg b/nimbus_verified_proxy/nim.cfg index 46d72112c..cd02861e0 100644 --- a/nimbus_verified_proxy/nim.cfg +++ b/nimbus_verified_proxy/nim.cfg @@ -19,6 +19,5 @@ --styleCheck:usages --styleCheck:hint ---hint[XDeclaredButNotUsed]:off --hint[ConvFromXtoItselfNotNeeded]:off --hint[Processing]:off diff --git a/nimbus_verified_proxy/nimbus_verified_proxy.nim b/nimbus_verified_proxy/nimbus_verified_proxy.nim index c62e51d20..e032932a3 100644 --- a/nimbus_verified_proxy/nimbus_verified_proxy.nim +++ b/nimbus_verified_proxy/nimbus_verified_proxy.nim @@ -66,7 +66,7 @@ proc run(config: VerifiedProxyConf) {.raises: [CatchableError].} = except CatchableError as err: raiseAssert "Invalid baked-in state: " & err.msg - genesistime = getStateField(genesisState[], genesis_time) + genesisTime = getStateField(genesisState[], genesis_time) beaconClock = BeaconClock.init(genesisTime).valueOr: error "Invalid genesis time in state", genesisTime quit QuitFailure