mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-05-07 07:19:26 +00:00
fix: prefer --num-shards-in-network over preset (#3816)
* fill numShardsInCluster from preset when builder slot is none * add regression tests
This commit is contained in:
parent
9ae108b4a7
commit
9cbb4e7338
@ -213,6 +213,54 @@ suite "Waku Conf - build with cluster conf":
|
||||
check rlnRelayConf.epochSizeSec == networkConf.rlnEpochSizeSec
|
||||
check rlnRelayConf.userMessageLimit == userMessageLimit.uint
|
||||
|
||||
test "num-shards-in-network > 0 overrides preset":
|
||||
## Setup
|
||||
let networkConf = NetworkConf.LogosDevConf()
|
||||
var builder = WakuConfBuilder.init()
|
||||
|
||||
# Sanity check
|
||||
check networkConf.shardingConf.kind == AutoSharding
|
||||
check networkConf.shardingConf.numShardsInCluster > 1
|
||||
|
||||
## Given: preset says >1 shards but user explicitly sets 1
|
||||
builder.withNetworkConf(networkConf)
|
||||
builder.withNumShardsInCluster(1)
|
||||
builder.withShardingConf(AutoSharding)
|
||||
|
||||
## When
|
||||
let conf = builder.build().expect("build should succeed")
|
||||
|
||||
## Then: user value wins, not preset
|
||||
conf.validate().expect("conf should validate")
|
||||
check conf.shardingConf.kind == AutoSharding
|
||||
check conf.shardingConf.numShardsInCluster == 1
|
||||
|
||||
test "num-shards-in-network == 0 does not override preset":
|
||||
## Passing an AutoSharding preset and trying to override with
|
||||
## --num-shards-in-network=0 (which is StaticSharding) doesn't work.
|
||||
## Note that --num-shards-in-network=0 and omitting the switch are
|
||||
## internally the same. Promoting the config to an Option[uint16] is
|
||||
## probably not worth it since overriding an AutoSharding preset with
|
||||
## StaticSharding shouldn't make any sense (that is, no use case).
|
||||
|
||||
## Given: emulate --preset=logos.dev --num-shards-in-network=0
|
||||
let networkConf = NetworkConf.LogosDevConf()
|
||||
var builder = WakuConfBuilder.init()
|
||||
builder.withNetworkConf(networkConf)
|
||||
# Note: builder.withNumShardsInCluster() is not called when the
|
||||
# value that comes from the CLI path is 0 (which means it was
|
||||
# either set to 0 or was left unset).
|
||||
builder.withShardingConf(StaticSharding)
|
||||
|
||||
## When
|
||||
let conf = builder.build().expect("build should succeed")
|
||||
|
||||
## Then: preset wins and StaticSharding user intent is lost
|
||||
conf.validate().expect("conf should validate")
|
||||
check conf.shardingConf.kind == networkConf.shardingConf.kind
|
||||
check conf.shardingConf.numShardsInCluster ==
|
||||
networkConf.shardingConf.numShardsInCluster
|
||||
|
||||
suite "Waku Conf - node key":
|
||||
test "Node key is generated":
|
||||
## Setup
|
||||
|
||||
@ -299,7 +299,6 @@ proc buildShardingConf(
|
||||
bNumShardsInCluster: Option[uint16],
|
||||
bSubscribeShards: Option[seq[uint16]],
|
||||
): (ShardingConf, seq[uint16]) =
|
||||
echo "bSubscribeShards: ", bSubscribeShards
|
||||
case bShardingConfKind.get(AutoSharding)
|
||||
of StaticSharding:
|
||||
(ShardingConf(kind: StaticSharding), bSubscribeShards.get(@[]))
|
||||
@ -374,17 +373,17 @@ proc applyNetworkConf(builder: var WakuConfBuilder) =
|
||||
warn "Sharding Conf was provided alongside a network conf",
|
||||
used = networkConf.shardingConf.kind, discarded = builder.shardingConf
|
||||
|
||||
if builder.numShardsInCluster.isSome():
|
||||
warn "Num Shards In Cluster was provided alongside a network conf",
|
||||
used = networkConf.shardingConf.numShardsInCluster,
|
||||
discarded = builder.numShardsInCluster
|
||||
|
||||
case networkConf.shardingConf.kind
|
||||
of StaticSharding:
|
||||
builder.shardingConf = some(StaticSharding)
|
||||
of AutoSharding:
|
||||
builder.shardingConf = some(AutoSharding)
|
||||
builder.numShardsInCluster = some(networkConf.shardingConf.numShardsInCluster)
|
||||
if builder.numShardsInCluster.isSome():
|
||||
warn "Num Shards In Cluster overrides network conf preset",
|
||||
used = builder.numShardsInCluster.get(),
|
||||
ignored = networkConf.shardingConf.numShardsInCluster
|
||||
else:
|
||||
builder.numShardsInCluster = some(networkConf.shardingConf.numShardsInCluster)
|
||||
|
||||
if networkConf.discv5Discovery:
|
||||
if builder.discv5Conf.enabled.isNone:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user