Fluffy: Make number of nodes to gossip content to configurable (#2653)

This commit is contained in:
web3-developer 2024-09-25 15:15:20 +08:00 committed by GitHub
parent b1dc1578f0
commit cb69723ff3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 21 additions and 5 deletions

View File

@ -45,6 +45,7 @@ const
defaultTableIpLimitDesc* = $defaultPortalProtocolConfig.tableIpLimits.tableIpLimit
defaultBucketIpLimitDesc* = $defaultPortalProtocolConfig.tableIpLimits.bucketIpLimit
defaultBitsPerHopDesc* = $defaultPortalProtocolConfig.bitsPerHop
defaultMaxGossipNodesDesc* = $defaultPortalProtocolConfig.maxGossipNodes
type
TrustedDigest* = MDigest[32 * 8]
@ -235,6 +236,14 @@ type
name: "bits-per-hop"
.}: int
maxGossipNodes* {.
hidden,
desc: "The maximum number of nodes to send content to during gossip",
defaultValue: defaultPortalProtocolConfig.maxGossipNodes,
defaultValueDesc: $defaultMaxGossipNodesDesc,
name: "max-gossip-nodes"
.}: int
radiusConfig* {.
desc:
"Radius configuration for a fluffy node. Radius can be either `dynamic` " &

View File

@ -159,7 +159,7 @@ proc run(
let
portalProtocolConfig = PortalProtocolConfig.init(
config.tableIpLimit, config.bucketIpLimit, config.bitsPerHop, config.radiusConfig,
config.disablePoke,
config.disablePoke, config.maxGossipNodes,
)
portalNodeConfig = PortalNodeConfig(

View File

@ -182,6 +182,7 @@ type
offerWorkers: seq[Future[void]]
disablePoke: bool
pingTimings: Table[NodeId, chronos.Moment]
maxGossipNodes: int
PortalResult*[T] = Result[T, string]
@ -573,6 +574,7 @@ proc new*(
offerQueue: newAsyncQueue[OfferRequest](concurrentOffers),
disablePoke: config.disablePoke,
pingTimings: Table[NodeId, chronos.Moment](),
maxGossipNodes: config.maxGossipNodes,
)
proto.baseProtocol.registerTalkProtocol(@(proto.protocolId), proto).expect(
@ -1503,7 +1505,6 @@ proc neighborhoodGossip*(
# in its propagation than when looking only for nodes in the own routing
# table, but at the same time avoid unnecessary node lookups.
# It might still cause issues in data getting propagated in a wider id range.
const maxGossipNodes = 8
let closestLocalNodes =
p.routingTable.neighbours(NodeId(contentId), k = 16, seenOnly = true)
@ -1518,9 +1519,9 @@ proc neighborhoodGossip*(
elif node.id != srcNodeId.get():
gossipNodes.add(node)
if gossipNodes.len >= 8: # use local nodes for gossip
if gossipNodes.len >= p.maxGossipNodes: # use local nodes for gossip
portal_gossip_without_lookup.inc(labelValues = [$p.protocolId])
let numberOfGossipedNodes = min(gossipNodes.len, maxGossipNodes)
let numberOfGossipedNodes = min(gossipNodes.len, p.maxGossipNodes)
for node in gossipNodes[0 ..< numberOfGossipedNodes]:
let req = OfferRequest(dst: node, kind: Direct, contentList: contentList)
await p.offerQueue.addLast(req)
@ -1528,7 +1529,7 @@ proc neighborhoodGossip*(
else: # use looked up nodes for gossip
portal_gossip_with_lookup.inc(labelValues = [$p.protocolId])
let closestNodes = await p.lookup(NodeId(contentId))
let numberOfGossipedNodes = min(closestNodes.len, maxGossipNodes)
let numberOfGossipedNodes = min(closestNodes.len, p.maxGossipNodes)
for node in closestNodes[0 ..< numberOfGossipedNodes]:
# Note: opportunistically not checking if the radius of the node is known
# and thus if the node is in radius with the content. Reason is, these

View File

@ -40,17 +40,21 @@ type
bitsPerHop*: int
radiusConfig*: RadiusConfig
disablePoke*: bool
maxGossipNodes*: int
const
defaultRadiusConfig* = RadiusConfig(kind: Dynamic)
defaultRadiusConfigDesc* = $defaultRadiusConfig.kind
defaultDisablePoke* = false
defaultMaxGossipNodes = 8
revalidationTimeout* = chronos.seconds(30)
defaultPortalProtocolConfig* = PortalProtocolConfig(
tableIpLimits: DefaultTableIpLimits,
bitsPerHop: DefaultBitsPerHop,
radiusConfig: defaultRadiusConfig,
disablePoke: defaultDisablePoke,
maxGossipNodes: defaultMaxGossipNodes,
)
proc init*(
@ -60,6 +64,7 @@ proc init*(
bitsPerHop: int,
radiusConfig: RadiusConfig,
disablePoke: bool,
maxGossipNodes: int,
): T =
PortalProtocolConfig(
tableIpLimits:
@ -67,6 +72,7 @@ proc init*(
bitsPerHop: bitsPerHop,
radiusConfig: radiusConfig,
disablePoke: disablePoke,
maxGossipNodes: maxGossipNodes,
)
func fromLogRadius*(T: type UInt256, logRadius: uint16): T =