From ee50f06a3e66862a89e546fab01aa579a07877cd Mon Sep 17 00:00:00 2001 From: Adam Spitz Date: Mon, 13 Mar 2023 14:18:30 -0400 Subject: [PATCH] Sketching in "stateless mode". (#1495) (Doesn't do anything yet.) --- nimbus/config.nim | 10 ++++++---- nimbus/nimbus.nim | 12 ++++++++++-- nimbus/sync/stateless.nim | 41 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 6 deletions(-) create mode 100644 nimbus/sync/stateless.nim diff --git a/nimbus/config.nim b/nimbus/config.nim index b0b8325c4..52717e5d4 100644 --- a/nimbus/config.nim +++ b/nimbus/config.nim @@ -140,6 +140,7 @@ type Full ## Beware, experimental Snap ## Beware, experimental SnapCtx ## Beware, experimental + Stateless ## Beware, experimental NimbusConf* = object of RootObj ## Main Nimbus configuration object @@ -169,10 +170,11 @@ type syncMode* {. desc: "Specify particular blockchain sync mode." longDesc: - "- default -- legacy sync mode\n" & - "- full -- full blockchain archive\n" & - "- snap -- experimental snap mode (development only)\n" & - "- snapCtx -- snap considering possible recovery context" + "- default -- legacy sync mode\n" & + "- full -- full blockchain archive\n" & + "- snap -- experimental snap mode (development only)\n" & + "- snapCtx -- snap considering possible recovery context\n" & + "- stateless -- experimental stateless mode (development only)" defaultValue: SyncMode.Default defaultValueDesc: $SyncMode.Default abbr: "y" diff --git a/nimbus/nimbus.nim b/nimbus/nimbus.nim index 1ddab3390..646962999 100644 --- a/nimbus/nimbus.nim +++ b/nimbus/nimbus.nim @@ -27,7 +27,7 @@ import ./core/[chain, sealer, clique/clique_desc, clique/clique_sealer, tx_pool, block_import], ./rpc/merge/merger, - ./sync/[legacy, full, protocol, snap, + ./sync/[legacy, full, protocol, snap, stateless, protocol/les_protocol, handlers, peers] when defined(evmc_enabled): @@ -60,6 +60,7 @@ type legaSyncRef: LegacySyncRef snapSyncRef: SnapSyncRef fullSyncRef: FullSyncRef + statelessSyncRef: StatelessSyncRef merger: MergerRef proc importBlocks(conf: NimbusConf, com: CommonRef) = @@ -186,6 +187,9 @@ proc setupP2P(nimbus: NimbusNode, conf: NimbusConf, nimbus.snapSyncRef = SnapSyncRef.init( nimbus.ethNode, nimbus.chainRef, nimbus.ctx.rng, conf.maxPeers, nimbus.dbBackend, tickerOK, noRecovery=noRecovery, exCtrlFile) + of SyncMode.Stateless: + # FIXME-Adam: what needs to go here? + nimbus.statelessSyncRef = StatelessSyncRef.init() of SyncMode.Default: nimbus.legaSyncRef = LegacySyncRef.new( nimbus.ethNode, nimbus.chainRef) @@ -205,7 +209,7 @@ proc setupP2P(nimbus: NimbusNode, conf: NimbusConf, if conf.maxPeers > 0: var waitForPeers = true case conf.syncMode: - of SyncMode.Snap, SyncMode.SnapCtx: + of SyncMode.Snap, SyncMode.SnapCtx, SyncMode.Stateless: waitForPeers = false of SyncMode.Full, SyncMode.Default: discard @@ -428,6 +432,8 @@ proc start(nimbus: NimbusNode, conf: NimbusConf) = cast[pointer](nimbus.legaSyncRef)) of SyncMode.Full: nimbus.fullSyncRef.start + of SyncMode.Stateless: + nimbus.statelessSyncRef.start of SyncMode.Snap, SyncMode.SnapCtx: nimbus.snapSyncRef.start @@ -455,6 +461,8 @@ proc stop*(nimbus: NimbusNode, conf: NimbusConf) {.async, gcsafe.} = await nimbus.networkLoop.cancelAndWait() if nimbus.peerManager.isNil.not: await nimbus.peerManager.stop() + if nimbus.statelessSyncRef.isNil.not: + nimbus.statelessSyncRef.stop() if nimbus.snapSyncRef.isNil.not: nimbus.snapSyncRef.stop() if nimbus.fullSyncRef.isNil.not: diff --git a/nimbus/sync/stateless.nim b/nimbus/sync/stateless.nim new file mode 100644 index 000000000..7576607e7 --- /dev/null +++ b/nimbus/sync/stateless.nim @@ -0,0 +1,41 @@ +# Nimbus +# Copyright (c) 2023 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) +# at your option. This file may not be copied, modified, or distributed +# except according to those terms. + +{.push raises: [].} + +import + eth/[common, p2p], + chronicles, + chronos, + stew/[interval_set, sorted_set], + "."/[sync_desc, sync_sched, protocol] + +logScope: + topics = "stateless-sync" + +type + StatelessSyncRef* = ref object + # FIXME-Adam: what needs to go in here? + + +# ------------------------------------------------------------------------------ +# Public functions +# ------------------------------------------------------------------------------ + +proc init*(T: type StatelessSyncRef): T = + new result + + +proc start*(ctx: StatelessSyncRef) = + # FIXME-Adam: What do I need here, if anything? + discard + +proc stop*(ctx: StatelessSyncRef) = + discard