mirror of
https://github.com/logos-messaging/logos-messaging-nim.git
synced 2026-01-04 06:53:12 +00:00
chore: Enhance feedback on error cli (#3405)
* better error detail * rm duplicated block
This commit is contained in:
parent
094a68e41d
commit
b435b51c4e
@ -134,13 +134,13 @@ proc updateENRShards(
|
|||||||
): Result[void, string] =
|
): Result[void, string] =
|
||||||
## Add or remove shards from the Discv5 ENR
|
## Add or remove shards from the Discv5 ENR
|
||||||
let newShardOp = topicsToRelayShards(newTopics).valueOr:
|
let newShardOp = topicsToRelayShards(newTopics).valueOr:
|
||||||
return err("ENR update failed: " & error)
|
return err("ENR update failed topicsToRelayShards: " & error)
|
||||||
|
|
||||||
let newShard = newShardOp.valueOr:
|
let newShard = newShardOp.valueOr:
|
||||||
return ok()
|
return ok()
|
||||||
|
|
||||||
let typedRecord = wd.protocol.localNode.record.toTyped().valueOr:
|
let typedRecord = wd.protocol.localNode.record.toTyped().valueOr:
|
||||||
return err("ENR update failed: " & $error)
|
return err("ENR update failed toTyped: " & $error)
|
||||||
|
|
||||||
let currentShardsOp = typedRecord.relaySharding()
|
let currentShardsOp = typedRecord.relaySharding()
|
||||||
|
|
||||||
@ -149,17 +149,17 @@ proc updateENRShards(
|
|||||||
let currentShard = currentShardsOp.get()
|
let currentShard = currentShardsOp.get()
|
||||||
|
|
||||||
if currentShard.clusterId != newShard.clusterId:
|
if currentShard.clusterId != newShard.clusterId:
|
||||||
return err("ENR update failed: clusterId id mismatch")
|
return err("ENR update failed: clusterId id mismatch in add")
|
||||||
|
|
||||||
RelayShards.init(
|
RelayShards.init(
|
||||||
currentShard.clusterId, currentShard.shardIds & newShard.shardIds
|
currentShard.clusterId, currentShard.shardIds & newShard.shardIds
|
||||||
).valueOr:
|
).valueOr:
|
||||||
return err("ENR update failed: " & error)
|
return err("ENR update failed RelayShards.init in add: " & error)
|
||||||
elif not add and currentShardsOp.isSome():
|
elif not add and currentShardsOp.isSome():
|
||||||
let currentShard = currentShardsOp.get()
|
let currentShard = currentShardsOp.get()
|
||||||
|
|
||||||
if currentShard.clusterId != newShard.clusterId:
|
if currentShard.clusterId != newShard.clusterId:
|
||||||
return err("ENR update failed: clusterId id mismatch")
|
return err("ENR update failed: clusterId id mismatch in not add")
|
||||||
|
|
||||||
let currentSet = toHashSet(currentShard.shardIds)
|
let currentSet = toHashSet(currentShard.shardIds)
|
||||||
let newSet = toHashSet(newShard.shardIds)
|
let newSet = toHashSet(newShard.shardIds)
|
||||||
@ -170,7 +170,7 @@ proc updateENRShards(
|
|||||||
return err("ENR update failed: cannot remove all shards")
|
return err("ENR update failed: cannot remove all shards")
|
||||||
|
|
||||||
RelayShards.init(currentShard.clusterId, indices).valueOr:
|
RelayShards.init(currentShard.clusterId, indices).valueOr:
|
||||||
return err("ENR update failed: " & error)
|
return err("ENR update failed RelayShards.init in not add: " & error)
|
||||||
elif add and currentShardsOp.isNone():
|
elif add and currentShardsOp.isNone():
|
||||||
newShard
|
newShard
|
||||||
else:
|
else:
|
||||||
@ -181,12 +181,12 @@ proc updateENRShards(
|
|||||||
(ShardingBitVectorEnrField, resultShard.toBitVector())
|
(ShardingBitVectorEnrField, resultShard.toBitVector())
|
||||||
else:
|
else:
|
||||||
let list = resultShard.toIndicesList().valueOr:
|
let list = resultShard.toIndicesList().valueOr:
|
||||||
return err("ENR update failed: " & $error)
|
return err("ENR update failed toIndicesList: " & $error)
|
||||||
|
|
||||||
(ShardingIndicesListEnrField, list)
|
(ShardingIndicesListEnrField, list)
|
||||||
|
|
||||||
wd.protocol.updateRecord([(field, value)]).isOkOr:
|
wd.protocol.updateRecord([(field, value)]).isOkOr:
|
||||||
return err("ENR update failed: " & $error)
|
return err("ENR update failed updateRecord: " & $error)
|
||||||
|
|
||||||
return ok()
|
return ok()
|
||||||
|
|
||||||
|
|||||||
@ -70,7 +70,7 @@ type WakuNodeConf* = object
|
|||||||
.}: logging.LogFormat
|
.}: logging.LogFormat
|
||||||
|
|
||||||
rlnRelayCredPath* {.
|
rlnRelayCredPath* {.
|
||||||
desc: "The path for peristing rln-relay credential",
|
desc: "The path for persisting rln-relay credential",
|
||||||
defaultValue: "",
|
defaultValue: "",
|
||||||
name: "rln-relay-cred-path"
|
name: "rln-relay-cred-path"
|
||||||
.}: string
|
.}: string
|
||||||
|
|||||||
@ -177,7 +177,7 @@ proc new*(
|
|||||||
var deliveryMonitor: DeliveryMonitor
|
var deliveryMonitor: DeliveryMonitor
|
||||||
if wakuConf.p2pReliability:
|
if wakuConf.p2pReliability:
|
||||||
if wakuConf.remoteStoreNode.isNone():
|
if wakuConf.remoteStoreNode.isNone():
|
||||||
return err("A remoteStoreNode should be set when reliability mode is on")
|
return err("A storenode should be set when reliability mode is on")
|
||||||
|
|
||||||
let deliveryMonitorRes = DeliveryMonitor.new(
|
let deliveryMonitorRes = DeliveryMonitor.new(
|
||||||
node.wakuStoreClient, node.wakuRelay, node.wakuLightpushClient,
|
node.wakuStoreClient, node.wakuRelay, node.wakuLightpushClient,
|
||||||
@ -222,7 +222,7 @@ proc getPorts(
|
|||||||
proc getRunningNetConfig(waku: ptr Waku): Result[NetConfig, string] =
|
proc getRunningNetConfig(waku: ptr Waku): Result[NetConfig, string] =
|
||||||
var conf = waku[].conf
|
var conf = waku[].conf
|
||||||
let (tcpPort, websocketPort) = getPorts(waku[].node.switch.peerInfo.listenAddrs).valueOr:
|
let (tcpPort, websocketPort) = getPorts(waku[].node.switch.peerInfo.listenAddrs).valueOr:
|
||||||
return err("Could not retrieve ports " & error)
|
return err("Could not retrieve ports: " & error)
|
||||||
|
|
||||||
if tcpPort.isSome():
|
if tcpPort.isSome():
|
||||||
conf.networkConf.p2pTcpPort = tcpPort.get()
|
conf.networkConf.p2pTcpPort = tcpPort.get()
|
||||||
@ -246,7 +246,7 @@ proc updateEnr(waku: ptr Waku): Result[void, string] =
|
|||||||
return err("ENR setup failed: " & error)
|
return err("ENR setup failed: " & error)
|
||||||
|
|
||||||
if isClusterMismatched(record, waku[].conf.clusterId):
|
if isClusterMismatched(record, waku[].conf.clusterId):
|
||||||
return err("cluster id mismatch configured shards")
|
return err("cluster-id mismatch configured shards")
|
||||||
|
|
||||||
waku[].node.enr = record
|
waku[].node.enr = record
|
||||||
|
|
||||||
|
|||||||
@ -164,7 +164,7 @@ proc logConf*(conf: WakuConf) =
|
|||||||
|
|
||||||
proc validateNodeKey(wakuConf: WakuConf): Result[void, string] =
|
proc validateNodeKey(wakuConf: WakuConf): Result[void, string] =
|
||||||
wakuConf.nodeKey.getPublicKey().isOkOr:
|
wakuConf.nodeKey.getPublicKey().isOkOr:
|
||||||
return err("Node key is invalid")
|
return err("nodekey param is invalid")
|
||||||
return ok()
|
return ok()
|
||||||
|
|
||||||
proc validateShards(wakuConf: WakuConf): Result[void, string] =
|
proc validateShards(wakuConf: WakuConf): Result[void, string] =
|
||||||
@ -187,58 +187,52 @@ proc validateShards(wakuConf: WakuConf): Result[void, string] =
|
|||||||
proc validateNoEmptyStrings(wakuConf: WakuConf): Result[void, string] =
|
proc validateNoEmptyStrings(wakuConf: WakuConf): Result[void, string] =
|
||||||
if wakuConf.networkConf.dns4DomainName.isSome() and
|
if wakuConf.networkConf.dns4DomainName.isSome() and
|
||||||
isEmptyOrWhiteSpace(wakuConf.networkConf.dns4DomainName.get().string):
|
isEmptyOrWhiteSpace(wakuConf.networkConf.dns4DomainName.get().string):
|
||||||
return err("dns4DomainName is an empty string, set it to none(string) instead")
|
return err("dns4-domain-name is an empty string, set it to none(string) instead")
|
||||||
|
|
||||||
if isEmptyOrWhiteSpace(wakuConf.relayServiceRatio):
|
if isEmptyOrWhiteSpace(wakuConf.relayServiceRatio):
|
||||||
return err("relayServiceRatio is an empty string")
|
return err("relay-service-ratio is an empty string")
|
||||||
|
|
||||||
for sn in wakuConf.staticNodes:
|
for sn in wakuConf.staticNodes:
|
||||||
if isEmptyOrWhiteSpace(sn):
|
if isEmptyOrWhiteSpace(sn):
|
||||||
return err("staticNodes contain an empty string")
|
return err("staticnode contain an empty string")
|
||||||
|
|
||||||
if wakuConf.remoteStoreNode.isSome() and
|
if wakuConf.remoteStoreNode.isSome() and
|
||||||
isEmptyOrWhiteSpace(wakuConf.remoteStoreNode.get()):
|
isEmptyOrWhiteSpace(wakuConf.remoteStoreNode.get()):
|
||||||
return err("remoteStoreNode is an empty string, set it to none(string) instead")
|
return err("storenode is an empty string, set it to none(string) instead")
|
||||||
|
|
||||||
if wakuConf.remoteLightPushNode.isSome() and
|
if wakuConf.remoteLightPushNode.isSome() and
|
||||||
isEmptyOrWhiteSpace(wakuConf.remoteLightPushNode.get()):
|
isEmptyOrWhiteSpace(wakuConf.remoteLightPushNode.get()):
|
||||||
return err("remoteLightPushNode is an empty string, set it to none(string) instead")
|
return err("lightpushnode is an empty string, set it to none(string) instead")
|
||||||
|
|
||||||
if wakuConf.remotePeerExchangeNode.isSome() and
|
if wakuConf.remotePeerExchangeNode.isSome() and
|
||||||
isEmptyOrWhiteSpace(wakuConf.remotePeerExchangeNode.get()):
|
isEmptyOrWhiteSpace(wakuConf.remotePeerExchangeNode.get()):
|
||||||
return
|
return err("peer-exchange-node is an empty string, set it to none(string) instead")
|
||||||
err("remotePeerExchangeNode is an empty string, set it to none(string) instead")
|
|
||||||
|
|
||||||
if wakuConf.remoteFilterNode.isSome() and
|
if wakuConf.remoteFilterNode.isSome() and
|
||||||
isEmptyOrWhiteSpace(wakuConf.remoteFilterNode.get()):
|
isEmptyOrWhiteSpace(wakuConf.remoteFilterNode.get()):
|
||||||
return
|
return err("filternode is an empty string, set it to none(string) instead")
|
||||||
err("remotePeerExchangeNode is an empty string, set it to none(string) instead")
|
|
||||||
|
|
||||||
if wakuConf.dnsDiscoveryConf.isSome() and
|
if wakuConf.dnsDiscoveryConf.isSome() and
|
||||||
isEmptyOrWhiteSpace(wakuConf.dnsDiscoveryConf.get().enrTreeUrl):
|
isEmptyOrWhiteSpace(wakuConf.dnsDiscoveryConf.get().enrTreeUrl):
|
||||||
return err("dnsDiscoveryConf.enrTreeUrl is an empty string")
|
return err("dns-discovery-url is an empty string")
|
||||||
|
|
||||||
# TODO: rln relay config should validate itself
|
# TODO: rln relay config should validate itself
|
||||||
if wakuConf.rlnRelayConf.isSome():
|
if wakuConf.rlnRelayConf.isSome():
|
||||||
let rlnRelayConf = wakuConf.rlnRelayConf.get()
|
let rlnRelayConf = wakuConf.rlnRelayConf.get()
|
||||||
|
|
||||||
if isEmptyOrWhiteSpace(rlnRelayConf.treePath):
|
if isEmptyOrWhiteSpace(rlnRelayConf.treePath):
|
||||||
return err("rlnRelayConf.treepath is an empty string")
|
return err("rln-relay-tree-path is an empty string")
|
||||||
if rlnRelayConf.ethClientUrls.len == 0:
|
if rlnRelayConf.ethClientUrls.len == 0:
|
||||||
return err("rlnRelayConf.ethClientUrls is empty")
|
return err("rln-relay-eth-client-address is empty")
|
||||||
if isEmptyOrWhiteSpace(rlnRelayConf.ethContractAddress):
|
if isEmptyOrWhiteSpace(rlnRelayConf.ethContractAddress):
|
||||||
return err("rlnRelayConf.ethContractAddress is an empty string")
|
return err("rln-relay-eth-contract-address is an empty string")
|
||||||
|
|
||||||
if rlnRelayConf.creds.isSome():
|
if rlnRelayConf.creds.isSome():
|
||||||
let creds = rlnRelayConf.creds.get()
|
let creds = rlnRelayConf.creds.get()
|
||||||
if isEmptyOrWhiteSpace(creds.path):
|
if isEmptyOrWhiteSpace(creds.path):
|
||||||
return err (
|
return err ("rln-relay-cred-path is an empty string")
|
||||||
"rlnRelayConf.creds.path is an empty string, set rlnRelayConf.creds it to none instead"
|
|
||||||
)
|
|
||||||
if isEmptyOrWhiteSpace(creds.password):
|
if isEmptyOrWhiteSpace(creds.password):
|
||||||
return err (
|
return err ("rln-relay-cred-password is an empty string")
|
||||||
"rlnRelayConf.creds.password is an empty string, set rlnRelayConf.creds to none instead"
|
|
||||||
)
|
|
||||||
|
|
||||||
return ok()
|
return ok()
|
||||||
|
|
||||||
|
|||||||
@ -335,9 +335,6 @@ method generateProof*(
|
|||||||
let message_id = uint64ToField(messageId)
|
let message_id = uint64ToField(messageId)
|
||||||
var path_elements = newSeq[byte](0)
|
var path_elements = newSeq[byte](0)
|
||||||
|
|
||||||
if (g.merkleProofCache.len mod 32) != 0:
|
|
||||||
return err("Invalid merkle proof cache length")
|
|
||||||
|
|
||||||
let identity_path_index = uint64ToIndex(g.membershipIndex.get(), 20)
|
let identity_path_index = uint64ToIndex(g.membershipIndex.get(), 20)
|
||||||
for i in 0 ..< g.merkleProofCache.len div 32:
|
for i in 0 ..< g.merkleProofCache.len div 32:
|
||||||
let chunk = g.merkleProofCache[i * 32 .. (i + 1) * 32 - 1]
|
let chunk = g.merkleProofCache[i * 32 .. (i + 1) * 32 - 1]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user