From 553be51217cff46032a008d9e499dee0ddc2526a Mon Sep 17 00:00:00 2001 From: Kim De Mey Date: Mon, 23 May 2022 23:23:24 +0200 Subject: [PATCH] Change radius-config option to radius and allow also logRadius (#1100) --- fluffy/conf.nim | 16 +++---- .../network/wire/portal_protocol_config.nim | 48 +++++++++++-------- fluffy/scripts/launch_local_testnet.sh | 2 +- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/fluffy/conf.nim b/fluffy/conf.nim index b5688d810..ca7ad83a0 100644 --- a/fluffy/conf.nim +++ b/fluffy/conf.nim @@ -183,20 +183,20 @@ type name: "bits-per-hop" .}: int radiusConfig* {. - hidden - desc: "Radius configuration for a fluffy node. Radius can be either `dynamic`" & - "where node adjust radius based on storage size limit," & - "or `static:logRadius` where node have hardcoded logRadius value. " & - "Warning: Setting it `static:logRadius` disable storage size limits and" & - "makes fluffy node to store fraction of the network." + desc: "Radius configuration for a fluffy node. Radius can be either `dynamic` " & + "where the node adjusts the radius based on `storage-size` option, " & + "or `static:` where the node has a hardcoded logarithmic radius value. " & + "Warning: `static:` disables `storage-size` limits and " & + "makes the node store a fraction of the network based on set radius." defaultValue: defaultRadiusConfig - name: "radius-config" .}: RadiusConfig + defaultValueDesc: $defaultRadiusConfigDesc + name: "radius" .}: RadiusConfig # TODO maybe it is worth defining minimal storage size and throw error if # value provided is smaller than minimum storageSize* {. desc: "Maximum amount (in bytes) of content which will be stored " & - "in local database." + "in the local database." defaultValue: defaultStorageSize defaultValueDesc: $defaultStorageSizeDesc name: "storage-size" .}: uint32 diff --git a/fluffy/network/wire/portal_protocol_config.nim b/fluffy/network/wire/portal_protocol_config.nim index a1653a26d..20b26c9d3 100644 --- a/fluffy/network/wire/portal_protocol_config.nim +++ b/fluffy/network/wire/portal_protocol_config.nim @@ -21,6 +21,7 @@ type const defaultRadiusConfig* = RadiusConfig(kind: Dynamic) + defaultRadiusConfigDesc* = $defaultRadiusConfig.kind defaultPortalProtocolConfig* = PortalProtocolConfig( tableIpLimits: DefaultTableIpLimits, @@ -44,34 +45,39 @@ proc init*( ) proc parseCmdArg*(T: type RadiusConfig, p: TaintedString): T - {.raises: [Defect, ConfigurationError].} = - + {.raises: [Defect, ConfigurationError].} = if p.startsWith("dynamic") and len(p) == 7: - return RadiusConfig(kind: Dynamic) + RadiusConfig(kind: Dynamic) elif p.startsWith("static:"): let num = p[7..^1] - try: - let parsed = uint16.parseCmdArg(num) + let parsed = + try: + uint16.parseCmdArg(num) + except ValueError: + let msg = "Provided logRadius: " & num & " is not a valid number" + raise newException(ConfigurationError, msg) - if parsed > 256: - raise newException( - ConfigurationError, "Provided logRadius should be <= 256" - ) - - return RadiusConfig(kind: Static, logRadius: parsed) - except ValueError: - let msg = "Provided logRadius: " & num & " is not a valid number" + if parsed > 256: raise newException( - ConfigurationError, msg + ConfigurationError, "Provided logRadius should be <= 256" ) + + RadiusConfig(kind: Static, logRadius: parsed) else: - let msg = - "Not supported radius config option: " & p & " . " & - "Supported options: dynamic, static:logRadius" - raise newException( - ConfigurationError, - msg - ) + let parsed = + try: + uint16.parseCmdArg(p) + except ValueError: + let msg = + "Not supported radius config option: " & p & " . " & + "Supported options: dynamic and static:logRadius" + raise newException(ConfigurationError, msg) + + if parsed > 256: + raise newException( + ConfigurationError, "Provided logRadius should be <= 256") + + RadiusConfig(kind: Static, logRadius: parsed) proc completeCmdArg*(T: type RadiusConfig, val: TaintedString): seq[string] = return @[] diff --git a/fluffy/scripts/launch_local_testnet.sh b/fluffy/scripts/launch_local_testnet.sh index 4a877c13b..5406230f0 100755 --- a/fluffy/scripts/launch_local_testnet.sh +++ b/fluffy/scripts/launch_local_testnet.sh @@ -248,7 +248,7 @@ for NUM_NODE in $(seq 0 $(( NUM_NODES - 1 ))); do BOOTSTRAP_ARG="--bootstrap-file=${BOOTSTRAP_ENR_FILE}" # All nodes but bootstrap node run with log. radius of 254 which should # result in ~1/4th of the data set stored. - RADIUS_ARG="--radius-config=static:254" + RADIUS_ARG="--radius=static:254" # Wait for the bootstrap node to write out its enr file START_TIMESTAMP=$(date +%s)