fix merge issues

This commit is contained in:
Sergei Tikhomirov 2025-07-10 19:42:26 +02:00
parent 921e651ba2
commit e0edb717d0
9 changed files with 11 additions and 176 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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