Skip to content

Portal Client: Add banOtherClients debug parameter to be used for testing and debugging #3312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion portal/client/nimbus_portal_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ proc run(portalClient: PortalClient, config: PortalConf) {.raises: [CatchableErr
config.radiusConfig, config.disablePoke, config.maxGossipNodes,
config.contentCacheSize, config.disableContentCache, config.offerCacheSize,
config.disableOfferCache, config.maxConcurrentOffers, config.disableBanNodes,
config.radiusCacheSize,
config.banOtherClients, config.radiusCacheSize,
)

portalNodeConfig = PortalNodeConfig(
Expand Down
9 changes: 9 additions & 0 deletions portal/client/nimbus_portal_client_conf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,15 @@ type
name: "debug-disable-ban-nodes"
.}: bool

banOtherClients* {.
hidden,
desc:
"Ban nodes that don't have a ping capabilities payload client info string matching the value used by Nimbus Portal. " &
"This can be useful for testing when we would like to only connect to Nimbus Portal nodes on the network.",
defaultValue: defaultBanOtherClients,
name: "debug-ban-other-clients"
.}: bool

radiusCacheSize* {.
hidden,
desc: "Size of the in memory radius cache.",
Expand Down
2 changes: 2 additions & 0 deletions portal/network/wire/ping_extensions.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ const
MAX_CAPABILITIES_LENGTH* = 400
MAX_ERROR_BYTE_LENGTH* = 300

NIMBUS_PORTAL_CLIENT_INFO* = ByteList[MAX_CLIENT_INFO_BYTE_LENGTH].init(@[])

# Different ping extension payloads, TODO: could be moved to each their own file?
type
CapabilitiesPayload* = object
Expand Down
8 changes: 6 additions & 2 deletions portal/network/wire/portal_protocol.nim
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const
NodeBanDurationInvalidResponse = 30.minutes
NodeBanDurationContentLookupFailedValidation* = 60.minutes
NodeBanDurationOfferFailedValidation* = 60.minutes
NodeBanDurationBanOtherClients* = 24.hours # for testing only

type
ToContentIdHandler* =
Expand Down Expand Up @@ -440,7 +441,7 @@ proc handlePingExtension(
payloadType,
encodePayload(
CapabilitiesPayload(
client_info: ByteList[MAX_CLIENT_INFO_BYTE_LENGTH].init(@[]),
client_info: NIMBUS_PORTAL_CLIENT_INFO,
data_radius: p.dataRadius(),
capabilities: List[uint16, MAX_CAPABILITIES_LENGTH].init(
p.pingExtensionCapabilities.toSeq()
Expand Down Expand Up @@ -849,7 +850,7 @@ proc pingImpl*(
): Future[PortalResult[PongMessage]] {.async: (raises: [CancelledError]).} =
let pingPayload = encodePayload(
CapabilitiesPayload(
client_info: ByteList[MAX_CLIENT_INFO_BYTE_LENGTH].init(@[]),
client_info: NIMBUS_PORTAL_CLIENT_INFO,
data_radius: p.dataRadius(),
capabilities:
List[uint16, MAX_CAPABILITIES_LENGTH].init(p.pingExtensionCapabilities.toSeq()),
Expand Down Expand Up @@ -924,6 +925,9 @@ proc ping*(

p.radiusCache.put(dst.id, payload.data_radius)

if p.config.banOtherClients and payload.client_info != NIMBUS_PORTAL_CLIENT_INFO:
p.banNode(dst.id, NodeBanDurationBanOtherClients)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also look at the 'c' value in the ENR? It might provide a faster way to filter out nodes. I'm not sure which way is better or perhaps using both would be ideal.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The c value is nowhere really specified and I think clients might remove this in the future now that there is the ping extension which provides this information


ok((pong.enrSeq, pong.payload_type, payload))

proc findNodes*(
Expand Down
5 changes: 5 additions & 0 deletions portal/network/wire/portal_protocol_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type
disableOfferCache*: bool
maxConcurrentOffers*: int
disableBanNodes*: bool
banOtherClients*: bool
radiusCacheSize*: int

const
Expand All @@ -63,6 +64,7 @@ const
defaultAlpha* = 3
revalidationTimeout* = chronos.seconds(30)
defaultDisableBanNodes* = true
defaultBanOtherClients* = false
defaultRadiusCacheSize* = 512

defaultPortalProtocolConfig* = PortalProtocolConfig(
Expand All @@ -78,6 +80,7 @@ const
disableOfferCache: defaultDisableOfferCache,
maxConcurrentOffers: defaultMaxConcurrentOffers,
disableBanNodes: defaultDisableBanNodes,
banOtherClients: defaultBanOtherClients,
radiusCacheSize: defaultRadiusCacheSize,
)

Expand All @@ -96,6 +99,7 @@ proc init*(
disableOfferCache: bool,
maxConcurrentOffers: int,
disableBanNodes: bool,
banOtherClients: bool,
radiusCacheSize: int,
): T =
PortalProtocolConfig(
Expand All @@ -112,6 +116,7 @@ proc init*(
disableOfferCache: disableOfferCache,
maxConcurrentOffers: maxConcurrentOffers,
disableBanNodes: disableBanNodes,
banOtherClients: banOtherClients,
radiusCacheSize: radiusCacheSize,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ procSuite "Portal Wire Protocol Tests":
let pong = await proto1.ping(proto2.localNode)

let customPayload = CapabilitiesPayload(
client_info: ByteList[MAX_CLIENT_INFO_BYTE_LENGTH].init(@[]),
client_info: NIMBUS_PORTAL_CLIENT_INFO,
data_radius: UInt256.high(),
capabilities: List[uint16, MAX_CAPABILITIES_LENGTH].init(
proto1.pingExtensionCapabilities.toSeq()
Expand Down
Loading