Change radius-config option to radius and allow also logRadius (#1100)

This commit is contained in:
Kim De Mey 2022-05-23 23:23:24 +02:00 committed by GitHub
parent ba940a5ce7
commit 553be51217
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 30 deletions

View File

@ -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:<logRadius>` where the node has a hardcoded logarithmic radius value. " &
"Warning: `static:<logRadius>` 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

View File

@ -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 @[]

View File

@ -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)