add eligibilityEnabled config flag

This commit is contained in:
Sergei Tikhomirov 2025-04-03 15:29:05 +02:00
parent 49b918b852
commit c4cb4121ed
3 changed files with 22 additions and 3 deletions

View File

@ -16,6 +16,7 @@ proc newTestWakuLightpushNode*(
switch: Switch,
handler: PushMessageHandler,
rateLimitSetting: Option[RateLimitSetting] = none[RateLimitSetting](),
eligibilityEnabled: bool = false,
): Future[WakuLightPush] {.async.} =
let
peerManager = PeerManager.new(switch)
@ -28,7 +29,7 @@ proc newTestWakuLightpushNode*(
return proto
proc newTestWakuLightpushClient*(
switch: Switch, reputationEnabled: bool = false
): WakuLightPushClient =
switch: Switch, reputationEnabled: bool = false
): WakuLightPushClient =
let peerManager = PeerManager.new(switch, reputationEnabled = reputationEnabled)
WakuLightPushClient.new(peerManager, rng)

View File

@ -513,6 +513,14 @@ hence would have reachability issues.""",
name: "reputation"
.}: bool
## Eligibility config
eligibilityEnabled* {.
desc:
"Enable server-side eligibility (proof-of-payment) check for light protocols: true|false",
defaultValue: false,
name: "eligibility"
.}: bool
## Reliability config
reliabilityEnabled* {.
desc:

View File

@ -22,7 +22,7 @@ import
../../waku_metadata,
./peer_store/peer_storage,
./waku_peer_store,
../../incentivization/reputation_manager
../../incentivization/[reputation_manager, eligibility_manager]
export waku_peer_store, peer_storage, peers
@ -97,7 +97,10 @@ type PeerManager* = ref object of RootObj
started: bool
shardedPeerManagement: bool # temp feature flag
onConnectionChange*: ConnectionChangeHandler
# 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]
#~~~~~~~~~~~~~~~~~~~#
# Helper Functions #
@ -1037,6 +1040,7 @@ proc new*(
colocationLimit = DefaultColocationLimit,
shardedPeerManagement = false,
reputationEnabled = false,
eligibilityEnabled = false,
): PeerManager {.gcsafe.} =
let capacity = switch.peerStore.capacity
let maxConnections = switch.connManager.inSema.size
@ -1117,4 +1121,10 @@ proc new*(
else:
none(ReputationManager)
pm.eligibilityManager =
if eligibilityEnabled:
some(EligibilityManager.new())
else:
none(EligibilityManager)
return pm