introduce mix proto config as per new format

This commit is contained in:
Prem Chaitanya Prathi 2025-06-30 20:19:01 +05:30
parent 9a32aedf36
commit 60d881a87b
8 changed files with 81 additions and 33 deletions

View File

@ -8,10 +8,11 @@ import
./discv5_conf_builder,
./web_socket_conf_builder,
./metrics_server_conf_builder,
./rln_relay_conf_builder
./rln_relay_conf_builder,
./mix_conf_builder
export
waku_conf_builder, filter_service_conf_builder, store_sync_conf_builder,
store_service_conf_builder, rest_server_conf_builder, dns_discovery_conf_builder,
discv5_conf_builder, web_socket_conf_builder, metrics_server_conf_builder,
rln_relay_conf_builder
rln_relay_conf_builder, mix_conf_builder

View File

@ -0,0 +1,38 @@
import chronicles, std/options, results
import libp2p/crypto/crypto, libp2p/crypto/curve25519, mix/curve25519
import ../waku_conf
logScope:
topics = "waku conf builder mix"
##################################
## Mix Config Builder ##
##################################
type MixConfBuilder* = object
enabled*: Option[bool]
mixKey*: Option[string]
proc init*(T: type MixConfBuilder): MixConfBuilder =
MixConfBuilder()
proc withEnabled*(b: var MixConfBuilder, enabled: bool) =
b.enabled = some(enabled)
proc withMixKey*(b: var MixConfBuilder, mixKey: string) =
b.mixKey = some(mixKey)
proc build*(b: MixConfBuilder): Result[Option[MixConf], string] =
if not b.enabled.get(false):
return ok(none[MixConf]())
else:
if b.mixKey.isSome():
let mixPrivKey = intoCurve25519Key(ncrutils.fromHex(b.mixKey.get()))
let mixPubKey = public(mixPrivKey)
return ok(some(MixConf(mixKey: mixPrivKey, mixPubKey: mixPubKey)))
else:
# Generate a new key pair if not provided
let keyPairResult = generateKeyPair()
if keyPairResult.isErr:
return err("Generate key pair error: " & $keyPairResult.error)
let (mixPrivKey, mixPubKey) = keyPairResult.get()
return ok(some(MixConf(mixKey: mixPrivKey, mixPubKey: mixPubKey)))

View File

@ -23,7 +23,8 @@ import
./discv5_conf_builder,
./web_socket_conf_builder,
./metrics_server_conf_builder,
./rln_relay_conf_builder
./rln_relay_conf_builder,
./mix_conf_builder
logScope:
topics = "waku conf builder"
@ -72,6 +73,7 @@ type WakuConfBuilder* = object
restServerConf*: RestServerConfBuilder
rlnRelayConf*: RlnRelayConfBuilder
storeServiceConf*: StoreServiceConfBuilder
mixConf*: MixConfBuilder
webSocketConf*: WebSocketConfBuilder
# End conf builders
relay: Option[bool]
@ -79,6 +81,7 @@ type WakuConfBuilder* = object
peerExchange: Option[bool]
storeSync: Option[bool]
relayPeerExchange: Option[bool]
mix: Option[bool]
# TODO: move within a relayConf
rendezvous: Option[bool]
@ -273,6 +276,9 @@ proc withMaxMessageSize*(builder: var WakuConfBuilder, maxMessageSize: string) =
proc withStaticNodes*(builder: var WakuConfBuilder, staticNodes: seq[string]) =
builder.staticNodes = concat(builder.staticNodes, staticNodes)
proc withMix*(builder: var WakuConfBuilder, mix: bool) =
builder.mix = some(mix)
proc nodeKey(
builder: WakuConfBuilder, rng: ref HmacDrbgContext
): Result[crypto.PrivateKey, string] =
@ -402,6 +408,13 @@ proc build*(
warn "whether to mount rendezvous is not specified, defaulting to not mounting"
false
let mix =
if builder.mix.isSome():
builder.mix.get()
else:
warn "whether to mount mix is not specified, defaulting to not mounting"
false
let relayPeerExchange = builder.relayPeerExchange.get(false)
let nodeKey = ?nodeKey(builder, rng)
@ -467,6 +480,9 @@ proc build*(
let storeServiceConf = builder.storeServiceConf.build().valueOr:
return err("Store Conf building failed: " & $error)
let mixConf = builder.mixConf.build().valueOr:
return err("Mix Conf building failed: " & $error)
let webSocketConf = builder.webSocketConf.build().valueOr:
return err("WebSocket Conf building failed: " & $error)
# End - Build sub-configs
@ -574,6 +590,7 @@ proc build*(
store = storeServiceConf.isSome,
relay = relay,
sync = storeServiceConf.isSome() and storeServiceConf.get().storeSyncConf.isSome,
mix = mix,
)
let wakuConf = WakuConf(
@ -585,6 +602,7 @@ proc build*(
metricsServerConf: metricsServerConf,
restServerConf: restServerConf,
dnsDiscoveryConf: dnsDiscoveryConf,
mixConf: mixConf,
# end confs
nodeKey: nodeKey,
clusterId: clusterId,

View File

@ -638,13 +638,6 @@ with the drawback of consuming some more bandwidth.""",
mixkey* {.desc: "ED25519 private key as 64 char hex string.", name: "mixkey".}:
Option[string]
#TODO: Temp config for simulations.Ideally need to get this info from bootstrap ENRs
#[ mixBootstrapNodes* {.
desc:
"Text-encoded data for mix bootstrap node. Encoded in the format Multiaddress:libp2pPubKey:MixPubKey. Argument may be repeated.",
name: "mix-bootstrap-node"
.}: seq[string] ]#
## websocket config
websocketSupport* {.
desc: "Enable websocket: true|false",
@ -997,6 +990,10 @@ proc toWakuConf*(n: WakuNodeConf): ConfResult[WakuConf] =
b.storeServiceConf.storeSyncConf.withRangeSec(n.storeSyncRange)
b.storeServiceConf.storeSyncConf.withRelayJitterSec(n.storeSyncRelayJitter)
b.mixConf.withEnabled(n.mix)
if n.mixkey.isSome():
b.mixConf.withMixKey(n.mixkey.get())
b.filterServiceConf.withEnabled(n.filter)
b.filterServiceConf.withSubscriptionTimeout(n.filterSubscriptionTimeout)
b.filterServiceConf.withMaxPeersToServe(n.filterMaxPeersToServe)

View File

@ -11,12 +11,13 @@ import
../common/utils/nat,
../node/net_config,
../waku_enr,
../waku_enr/mix,
../waku_core,
./waku_conf,
./networks_config
proc enrConfiguration*(
conf: WakuConf, netConfig: NetConfig, mixPubKey: Option[Curve25519Key]
conf: WakuConf, netConfig: NetConfig
): Result[enr.Record, string] =
var enrBuilder = EnrBuilder.init(conf.nodeKey)
@ -34,8 +35,8 @@ proc enrConfiguration*(
).isOkOr:
return err("could not initialize ENR with shards")
if conf.mix and mixPubKey.isSome():
enrBuilder.withMixKey(mixPubKey.get())
if conf.mixConf.isSome():
enrBuilder.withMixKey(conf.mixConf.get().mixPubKey)
let recordRes = enrBuilder.build()
let record =

View File

@ -37,8 +37,7 @@ import
../node/peer_manager/peer_store/migrations as peer_store_sqlite_migrations,
../waku_lightpush_legacy/common,
../common/rate_limit/setting,
../common/databases/dburl,
mix/curve25519
../common/databases/dburl
## Peer persistence
@ -147,7 +146,7 @@ proc getAutoshards*(
return ok(autoshards)
proc setupProtocols(
node: WakuNode, conf: WakuConf, mixPrivKey: Curve25519Key
node: WakuNode, conf: WakuConf
): Future[Result[void, string]] {.async.} =
## Setup configured protocols on an existing Waku v2 node.
## Optionally include persistent message storage.
@ -418,8 +417,8 @@ proc setupProtocols(
err("failed to set node waku peer-exchange peer: " & peerExchangeNode.error)
#mount mix
if conf.mix:
(await node.mountMix(conf.clusterId, mixPrivKey)).isOkOr:
if conf.mixConf.isSome():
(await node.mountMix(conf.clusterId, conf.mixConf.get().mixKey)).isOkOr:
return err("failed to mount waku mix protocol: " & $error)
return ok()
@ -481,18 +480,6 @@ proc startNode*(
proc setupNode*(
wakuConf: WakuConf, rng: ref HmacDrbgContext = crypto.newRng(), relay: Relay
): Result[WakuNode, string] =
var mixPubKey, mixPrivKey: Curve25519Key
if conf.mix:
if conf.mixKey.isSome():
mixPrivKey = intoCurve25519Key(ncrutils.fromHex(conf.mixKey.get()))
mixPubKey = public(mixPrivKey)
else:
warn "missing mix key, generating new"
let keyPairResult = generateKeyPair()
if keyPairResult.isErr:
return err("Generate key pair error: " & $keyPairResult.error)
(mixPrivKey, mixPubKey) = keyPairResult.get()
let netConfig = networkConfiguration(
wakuConf.clusterId, wakuConf.networkConf, wakuConf.discv5Conf,
wakuConf.webSocketConf, wakuConf.wakuFlags, wakuConf.dnsAddrsNameServers,
@ -501,7 +488,7 @@ proc setupNode*(
error "failed to create internal config", error = error
return err("failed to create internal config: " & error)
let record = enrConfiguration(wakuConf, netConfig, some(mixPubKey)).valueOr:
let record = enrConfiguration(wakuConf, netConfig).valueOr:
error "failed to create record", error = error
return err("failed to create record: " & error)
@ -527,7 +514,7 @@ proc setupNode*(
debug "Mounting protocols"
try:
(waitFor node.setupProtocols(wakuConf, mixPrivKey)).isOkOr:
(waitFor node.setupProtocols(wakuConf)).isOkOr:
error "Mounting protocols failed", error = error
return err("Mounting protocols failed: " & error)
except CatchableError:

View File

@ -267,7 +267,7 @@ proc getRunningNetConfig(waku: ptr Waku): Result[NetConfig, string] =
proc updateEnr(waku: ptr Waku): Result[void, string] =
let netConf: NetConfig = getRunningNetConfig(waku).valueOr:
return err("error calling updateNetConfig: " & $error)
let record = enrConfiguration(waku[].conf, netConf, none(Curve25519Key)).valueOr:
let record = enrConfiguration(waku[].conf, netConf).valueOr:
return err("ENR setup failed: " & error)
if isClusterMismatched(record, waku[].conf.clusterId):

View File

@ -3,6 +3,7 @@ import
chronicles,
libp2p/crypto/crypto,
libp2p/multiaddress,
libp2p/crypto/curve25519,
secp256k1,
results
@ -35,6 +36,10 @@ type StoreSyncConf* {.requiresInit.} = object
intervalSec*: uint32
relayJitterSec*: uint32
type MixConf* = ref object
mixKey*: Curve25519Key
mixPubKey*: Curve25519Key
type StoreServiceConf* {.requiresInit.} = object
dbMigration*: bool
dbURl*: string
@ -93,6 +98,7 @@ type WakuConf* {.requiresInit.} = ref object
restServerConf*: Option[RestServerConf]
metricsServerConf*: Option[MetricsServerConf]
webSocketConf*: Option[WebSocketConf]
mixConf*: Option[MixConf]
portsShift*: uint16
dnsAddrsNameServers*: seq[IpAddress]