From e0edb717d069a33ae210b166bbe6ad92b17f9e08 Mon Sep 17 00:00:00 2001 From: Sergei Tikhomirov Date: Thu, 10 Jul 2025 19:42:26 +0200 Subject: [PATCH] fix merge issues --- .../conf_builder/waku_conf_builder.nim | 4 +- waku/factory/node_factory.nim | 16 --- waku/factory/waku_conf.nim | 7 +- waku/incentivization/reputation_manager.nim | 14 +-- waku/node/peer_manager/peer_manager.nim | 7 -- waku/node/waku_node.nim | 5 - waku/waku_lightpush/client.nim | 4 - waku/waku_lightpush/common.nim | 15 --- waku/waku_lightpush/protocol.nim | 115 +----------------- 9 files changed, 11 insertions(+), 176 deletions(-) diff --git a/waku/factory/conf_builder/waku_conf_builder.nim b/waku/factory/conf_builder/waku_conf_builder.nim index a26e80329..619ba1441 100644 --- a/waku/factory/conf_builder/waku_conf_builder.nim +++ b/waku/factory/conf_builder/waku_conf_builder.nim @@ -500,7 +500,7 @@ proc build*( let reputationConf = builder.reputationConf.build().valueOr: return err("Reputation Conf building failed: " & $error) - let rateLimitConf = builder.rateLimitConf.build().valueOr: + let rateLimit = builder.rateLimitConf.build().valueOr: return err("Rate limits Conf building failed: " & $error) # End - Build sub-configs @@ -620,7 +620,7 @@ proc build*( dnsDiscoveryConf: dnsDiscoveryConf, eligibilityConf: eligibilityConf, reputationConf: reputationConf, - rateLimitConf: rateLimitConf, + rateLimit: rateLimit, # end confs nodeKey: nodeKey, clusterId: clusterId, diff --git a/waku/factory/node_factory.nim b/waku/factory/node_factory.nim index e1f5fbf0a..063ffc22f 100644 --- a/waku/factory/node_factory.nim +++ b/waku/factory/node_factory.nim @@ -109,7 +109,6 @@ proc initNode( else: false -<<<<<<< HEAD let reputationEnabled = if conf.reputationConf.isSome(): conf.reputationConf.get().enabled @@ -137,22 +136,7 @@ proc initNode( eligibilityEnabled = eligibilityEnabled, reputationEnabled = reputationEnabled, ) - builder.withRateLimit(conf.rateLimits) -======= - builder.withPeerManagerConfig( - maxConnections = conf.maxConnections, - relayServiceRatio = $relayRatio & ":" & $serviceRatio, - shardAware = conf.relayShardedPeerManagement, - ) - error "maxRelayPeers is deprecated. It is recommended to use relayServiceRatio instead. If relayServiceRatio is not set, it will be automatically calculated based on maxConnections and maxRelayPeers." - else: - builder.withPeerManagerConfig( - maxConnections = conf.maxConnections, - relayServiceRatio = conf.relayServiceRatio, - shardAware = conf.relayShardedPeerManagement, - ) builder.withRateLimit(conf.rateLimit) ->>>>>>> master builder.withCircuitRelay(relay) let node = diff --git a/waku/factory/waku_conf.nim b/waku/factory/waku_conf.nim index eec712a51..c56e3184c 100644 --- a/waku/factory/waku_conf.nim +++ b/waku/factory/waku_conf.nim @@ -160,13 +160,8 @@ proc logConf*(wakuConf: WakuConf) = info "Configuration. Network", cluster = wakuConf.clusterId -<<<<<<< HEAD - for shard in wakuConf.shards: - info "Configuration. Shards", shard = shard -======= - for shard in conf.subscribeShards: + for shard in wakuConf.subscribeShards: info "Configuration. Active Relay Shards", shard = shard ->>>>>>> master if wakuConf.discv5Conf.isSome(): for i in wakuConf.discv5Conf.get().bootstrapNodes: diff --git a/waku/incentivization/reputation_manager.nim b/waku/incentivization/reputation_manager.nim index 582aa29bf..3ef01aa9a 100644 --- a/waku/incentivization/reputation_manager.nim +++ b/waku/incentivization/reputation_manager.nim @@ -2,11 +2,11 @@ import tables, std/options, chronicles import ../waku_lightpush/[rpc, common] import libp2p/peerid -const BadResponseStatusCodes* = [ - LightpushStatusCode.INTERNAL_SERVER_ERROR, - LightpushStatusCode.SERVICE_NOT_AVAILABLE, - LightpushStatusCode.OUT_OF_RLN_PROOF, - LightpushStatusCode.NO_PEERS_TO_RELAY +const BadLightPushErrorCodes* = [ + LightPushErrorCode.INTERNAL_SERVER_ERROR, + LightPushErrorCode.SERVICE_NOT_AVAILABLE, + LightPushErrorCode.OUT_OF_RLN_PROOF, + LightPushErrorCode.NO_PEERS_TO_RELAY ] type @@ -40,9 +40,9 @@ proc getReputation*(manager: ReputationManager, peer: PeerId): Option[bool] = # Evaluate the quality of a LightPushResponse by checking its status code proc evaluateResponse*(response: LightPushResponse): ResponseQuality = - if response.statusCode == LightpushStatusCode.SUCCESS.uint32: + if response.isSuccess(): return GoodResponse - elif LightpushStatusCode(response.statusCode) in BadResponseStatusCodes: + elif response.statusCode in BadLightPushErrorCodes: return BadResponse else: return NeutralResponse diff --git a/waku/node/peer_manager/peer_manager.nim b/waku/node/peer_manager/peer_manager.nim index dba823a45..7a32a191c 100644 --- a/waku/node/peer_manager/peer_manager.nim +++ b/waku/node/peer_manager/peer_manager.nim @@ -97,16 +97,12 @@ type PeerManager* = ref object of RootObj started: bool shardedPeerManagement: bool # temp feature flag onConnectionChange*: ConnectionChangeHandler -<<<<<<< HEAD # clients of light protocols (like Lightpush) may track servers' reputation reputationManager*: Option[ReputationManager] # servers of light protocols (like Lightpush) may track client requests' eligibility eligibilityManager*: Option[EligibilityManager] dnsNameServers*: seq[IpAddress] - online: bool -======= online: bool ## state managed by online_monitor module ->>>>>>> master #~~~~~~~~~~~~~~~~~~~# # Helper Functions # @@ -1071,12 +1067,9 @@ proc new*( maxFailedAttempts = MaxFailedAttempts, colocationLimit = DefaultColocationLimit, shardedPeerManagement = false, -<<<<<<< HEAD reputationEnabled = false, eligibilityEnabled = false, dnsNameServers = newSeq[IpAddress](), -======= ->>>>>>> master ): PeerManager {.gcsafe.} = let capacity = switch.peerStore.capacity let maxConnections = switch.connManager.inSema.size diff --git a/waku/node/waku_node.nim b/waku/node/waku_node.nim index d2dd3acb2..59d128171 100644 --- a/waku/node/waku_node.nim +++ b/waku/node/waku_node.nim @@ -1206,13 +1206,8 @@ proc lightpushPublish*( elif not node.wakuLightpushClient.isNil(): node.peerManager.selectPeer(WakuLightPushCodec).valueOr: let msg = "no suitable remote peers" -<<<<<<< HEAD - error "failed to publish message", err = msg - return lighpushErrorResult(NO_PEERS_TO_RELAY, msg) -======= error "failed to publish message", msg = msg return lighpushErrorResult(LightPushErrorCode.NO_PEERS_TO_RELAY, msg) ->>>>>>> master else: return lighpushErrorResult( LightPushErrorCode.NO_PEERS_TO_RELAY, "no suitable remote peers" diff --git a/waku/waku_lightpush/client.nim b/waku/waku_lightpush/client.nim index e193627ac..ed7aea1a3 100644 --- a/waku/waku_lightpush/client.nim +++ b/waku/waku_lightpush/client.nim @@ -46,13 +46,9 @@ proc sendPushRequest( try: buffer = await connection.readLp(DefaultMaxRpcSize.int) except LPStreamRemoteClosedError: -<<<<<<< HEAD error "Failed to read responose from peer", error = getCurrentExceptionMsg() if wl.peerManager.reputationManager.isSome: wl.peerManager.reputationManager.get().setReputation(peer.peerId, some(false)) -======= - error "Failed to read response from peer", error = getCurrentExceptionMsg() ->>>>>>> master return lightpushResultInternalError( "Failed to read response from peer: " & getCurrentExceptionMsg() ) diff --git a/waku/waku_lightpush/common.nim b/waku/waku_lightpush/common.nim index ecda5c365..f2687834e 100644 --- a/waku/waku_lightpush/common.nim +++ b/waku/waku_lightpush/common.nim @@ -7,20 +7,6 @@ from ../waku_core/codecs import WakuLightPushCodec export WakuLightPushCodec export LightPushStatusCode -<<<<<<< HEAD -type LightpushStatusCode* = enum - SUCCESS = uint32(200) - BAD_REQUEST = uint32(400) - PAYMENT_REQUIRED = uint32(402) - PAYLOAD_TOO_LARGE = uint32(413) - INVALID_MESSAGE_ERROR = uint32(420) - UNSUPPORTED_PUBSUB_TOPIC = uint32(421) - TOO_MANY_REQUESTS = uint32(429) - INTERNAL_SERVER_ERROR = uint32(500) - SERVICE_NOT_AVAILABLE = uint32(503) - OUT_OF_RLN_PROOF = uint32(504) - NO_PEERS_TO_RELAY = uint32(505) -======= const LightPushSuccessCode* = (SUCCESS: LightPushStatusCode(200)) const LightPushErrorCode* = ( @@ -34,7 +20,6 @@ const LightPushErrorCode* = ( OUT_OF_RLN_PROOF: LightPushStatusCode(504), NO_PEERS_TO_RELAY: LightPushStatusCode(505), ) ->>>>>>> master type ErrorStatus* = tuple[code: LightpushStatusCode, desc: Option[string]] type WakuLightPushResult* = Result[uint32, ErrorStatus] diff --git a/waku/waku_lightpush/protocol.nim b/waku/waku_lightpush/protocol.nim index 912d208b3..955b1ade5 100644 --- a/waku/waku_lightpush/protocol.nim +++ b/waku/waku_lightpush/protocol.nim @@ -16,8 +16,7 @@ import ./rpc, ./rpc_codec, ./protocol_metrics, - ../common/rate_limit/request_limiter, - ../incentivization/[eligibility_manager, rpc] + ../common/rate_limit/request_limiter logScope: topics = "waku lightpush" @@ -86,120 +85,8 @@ proc handleRequest*( waku_lightpush_v3_errors.inc(labelValues = [$errorCode]) return LightPushResponse( requestId: "N/A", # due to decode failure we don't know requestId -<<<<<<< HEAD - statusCode: LightpushStatusCode.BAD_REQUEST.uint32, - statusDesc: some(decodeRpcFailure & ": " & $reqDecodeRes.error), - ) - else: - let pushRequest = reqDecodeRes.get() - - let pubsubTopic = pushRequest.pubSubTopic.valueOr: - let parsedTopic = NsContentTopic.parse(pushRequest.message.contentTopic).valueOr: - let msg = "Invalid content-topic:" & $error - error "lightpush request handling error", error = msg - return LightpushResponse( - requestId: pushRequest.requestId, - statusCode: LightpushStatusCode.INVALID_MESSAGE_ERROR.uint32, - statusDesc: some(msg), - ) - - wl.sharding.getShard(parsedTopic).valueOr: - let msg = "Autosharding error: " & error - error "lightpush request handling error", error = msg - return LightpushResponse( - requestId: pushRequest.requestId, - statusCode: LightpushStatusCode.INTERNAL_SERVER_ERROR.uint32, - statusDesc: some(msg), - ) - - # ensure checking topic will not cause error at gossipsub level - if pubsubTopic.isEmptyOrWhitespace(): - let msg = "topic must not be empty" - error "lightpush request handling error", error = msg - return LightPushResponse( - requestId: pushRequest.requestId, - statusCode: LightpushStatusCode.BAD_REQUEST.uint32, - statusDesc: some(msg), - ) - - waku_lightpush_v3_messages.inc(labelValues = ["PushRequest"]) - - let msg_hash = pubsubTopic.computeMessageHash(pushRequest.message).to0xHex() - notice "handling lightpush request", - my_peer_id = wl.peerManager.switch.peerInfo.peerId, - peer_id = peerId, - requestId = pushRequest.requestId, - pubsubTopic = pushRequest.pubsubTopic, - eligibilityProof = pushRequest.eligibilityProof, - msg_hash = msg_hash, - receivedTime = getNowInNanosecondTime() - - # Check eligibility if manager is available - if wl.peerManager.eligibilityManager.isSome(): - debug "eligibilityManager is enabled" - let em = wl.peerManager.eligibilityManager.get() - - try: - debug "checking eligibilityProof..." - - # Check if eligibility proof is provided - if pushRequest.eligibilityProof.isNone(): - let msg = "Eligibility proof is required" - error "lightpush request handling error", error = msg - return LightpushResponse( - requestId: pushRequest.requestId, - statusCode: LightpushStatusCode.PAYMENT_REQUIRED.uint32, - statusDesc: some(msg), - ) - - let isEligible = await em.isEligibleTxId(pushRequest.eligibilityProof.get()) - if isEligible.isErr(): - let msg = "Eligibility check failed: " & isEligible.error - error "lightpush request handling error", error = msg - return LightpushResponse( - requestId: pushRequest.requestId, - statusCode: LightpushStatusCode.PAYMENT_REQUIRED.uint32, - statusDesc: some(msg), - ) - - debug "Eligibility check passed!" - - except CatchableError: - let msg = "Eligibility check threw exception: " & getCurrentExceptionMsg() - error "lightpush request handling error", error = msg - return LightpushResponse( - requestId: pushRequest.requestId, - statusCode: LightpushStatusCode.PAYMENT_REQUIRED.uint32, - statusDesc: some(msg), - ) - else: - # the service node doesn't want to check eligibility - debug "eligibilityManager is disabled - skipping eligibility check" - - let handleRes = await wl.pushHandler(peerId, pubsubTopic, pushRequest.message) - - isSuccess = handleRes.isOk() - pushResponse = LightpushResponse( - requestId: pushRequest.requestId, - statusCode: - if isSuccess: - LightpushStatusCode.SUCCESS.uint32 - else: - handleRes.error.code.uint32, - statusDesc: - if isSuccess: - none[string]() - else: - handleRes.error.desc, - relayPeerCount: - if isSuccess: - some(handleRes.get()) - else: - none[uint32](), -======= statusCode: errorCode, statusDesc: some(desc), ->>>>>>> master ) let relayPeerCount = (await handleRequest(wl, peerId, pushRequest)).valueOr: