Skip to content

Commit

Permalink
Use maxPeersPerPruneMessage instead of maxPrunePeers to limit the amo…
Browse files Browse the repository at this point in the history
…unt of peers processed in PX
  • Loading branch information
diegomrsantos committed Oct 5, 2023
1 parent 9b85d7a commit 6f34311
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ data class GossipParams(
/**
* [maxPeersPerPruneMessage] is the maximum number of peers allowed in an incoming prune message
*/
val maxPeersPerPruneMessage: Int? = null,
val maxPeersPerPruneMessage: Int = 16,

/**
* [pruneBackoff] controls the backoff time for pruned peers. This is how long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ open class GossipRouter(
params.maxIWantMessageIds?.let { iWantMessageIdCount <= it } ?: true &&
params.maxGraftMessages?.let { (msg.control?.graftCount ?: 0) <= it } ?: true &&
params.maxPruneMessages?.let { (msg.control?.pruneCount ?: 0) <= it } ?: true &&
params.maxPeersPerPruneMessage?.let { msg.control?.pruneList?.none { p -> p.peersCount > it } } ?: true
params.maxPeersPerPruneMessage.let { msg.control?.pruneList?.none { p -> p.peersCount > it } } ?: true
}

private fun processControlMessage(controlMsg: Any, receivedFrom: PeerHandler) {
Expand Down Expand Up @@ -349,7 +349,7 @@ open class GossipRouter(
}

private fun processPrunePeers(peersList: List<Rpc.PeerInfo>) {
peersList.shuffled(random).take(params.maxPrunePeers)
peersList.shuffled(random).take(params.maxPeersPerPruneMessage)
.map { PeerId(it.peerID.toByteArray()) to it.signedPeerRecord.toByteArray() }
.filter { (id, _) -> !isConnected(id) }
.forEach { (id, record) -> params.connectCallback(id, record) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ class GossipParamsBuilder {
iWantFollowupTime = iWantFollowupTime!!,
maxGraftMessages = maxGraftMessages,
maxPrunePeers = maxPrunePeers!!,
maxPeersPerPruneMessage = maxPeersPerPruneMessage,
maxPeersPerPruneMessage = maxPeersPerPruneMessage!!,
pruneBackoff = pruneBackoff!!,
maxPruneMessages = maxPruneMessages,
gossipRetransmission = gossipRetransmission!!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class GossipRouterListLimitsTest {

@Test
fun validateProtobufLists_validMessageWithLargeLists_noLimits() {
val msg = fullMsgBuilder(20).build()
val msg = fullMsgBuilder(16).build()

Assertions.assertThat(routerWithNoLimits.validateMessageListLimits(msg)).isTrue()
}
Expand Down

0 comments on commit 6f34311

Please sign in to comment.