Skip to content
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

Add GossipParam tests and fix a few small issues #232

Merged
merged 7 commits into from
Mar 7, 2022
Merged
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
37 changes: 22 additions & 15 deletions src/main/kotlin/io/libp2p/pubsub/gossip/GossipParams.kt
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,15 @@ data class GossipParams(
val connectCallback: (PeerId, ByteArray) -> Unit = { _: PeerId, _: ByteArray -> }
) {
init {
check(D >= 0, "D should be >= 0")
check(DOut >= 0, "DOut should be >= 0")
check(DLow >= 0, "DLow should be >= 0")
check(DHigh >= 0, "DHigh should be >= 0")
check(DOut < DLow || (DOut == 0 && DLow == 0), "DOut should be < DLow or both 0")
check(DOut <= D / 2, "DOut should be <= D/2")
check(DLow <= D, "DLow should be <= D")
check(DHigh >= D, "DHigh should be >= D")
check(gossipFactor in 0.0..1.0, "gossipFactor should be in range [0.0, 1.1]")
check(gossipFactor in 0.0..1.0, "gossipFactor should be in range [0.0, 1.0]")
}

companion object {
Expand Down Expand Up @@ -276,7 +280,7 @@ data class GossipScoreParams(

/**
* [graylistThreshold] is the score threshold below which message processing is supressed altogether,
* implementing an effective graylist according to peer score; should be negative and <= [publishThreshold].
* implementing an effective graylist according to peer score; should be negative and < [publishThreshold].
*/
val graylistThreshold: Double = 0.0,

Expand All @@ -293,11 +297,14 @@ data class GossipScoreParams(
val opportunisticGraftThreshold: Double = 0.0
) {
init {
check(gossipThreshold <= 0, "gossipThreshold should be < 0")
check(gossipThreshold <= 0, "gossipThreshold should be <= 0")
check(publishThreshold <= gossipThreshold, "publishThreshold should be <= than gossipThreshold")
check(graylistThreshold <= publishThreshold, "gossipThreshold should be < publishThreshold")
check(acceptPXThreshold >= 0, "acceptPXThreshold should be > 0")
check(opportunisticGraftThreshold >= 0, "opportunisticGraftThreshold should be > 0")
check(
graylistThreshold < publishThreshold || (publishThreshold == 0.0 && graylistThreshold == 0.0),
"graylistThreshold should be < publishThreshold or both 0"
)
check(acceptPXThreshold >= 0, "acceptPXThreshold should be >= 0")
check(opportunisticGraftThreshold >= 0, "opportunisticGraftThreshold should be >= 0")
}

companion object {
Expand Down Expand Up @@ -396,7 +403,7 @@ data class GossipPeerScoreParams(
)
check(behaviourPenaltyWeight <= 0.0, "behaviourPenaltyWeight should be <= 0")
check(
behaviourPenaltyWeight == 0.0 || (behaviourPenaltyDecay > 0.0 && behaviourPenaltyDecay <= 1.0),
behaviourPenaltyDecay > 0.0 && behaviourPenaltyDecay <= 1.0,
"behaviourPenaltyDecay should be in range (0.0, 1.0]"
)
check(behaviourPenaltyThreshold >= 0.0, "behaviourPenaltyThreshold should be >= 0")
Expand Down Expand Up @@ -512,17 +519,17 @@ data class GossipTopicScoreParams(
val invalidMessageDeliveriesDecay: Double = 0.0
) {
init {
check(timeInMeshWeight >= 0, "timeInMeshWeight >= 0")
check(timeInMeshCap >= 0, "timeInMeshCap >= 0")
check(firstMessageDeliveriesWeight >= 0, "firstMessageDeliveriesWeight >= 0")
check(meshMessageDeliveriesWeight <= 0, "meshMessageDeliveriesWeight <= 0")
check(meshMessageDeliveriesThreshold >= 0, "meshMessageDeliveriesThreshold >= 0")
check(timeInMeshWeight >= 0, "timeInMeshWeight should be >= 0")
check(timeInMeshCap >= 0, "timeInMeshCap should be >= 0")
check(firstMessageDeliveriesWeight >= 0, "firstMessageDeliveriesWeight should be >= 0")
check(meshMessageDeliveriesWeight <= 0, "meshMessageDeliveriesWeight should be <= 0")
check(meshMessageDeliveriesThreshold >= 0, "meshMessageDeliveriesThreshold should be >= 0")
check(
meshMessageDeliveriesCap >= meshMessageDeliveriesThreshold,
"meshMessageDeliveriesCap >= meshMessageDeliveriesThreshold"
"meshMessageDeliveriesCap should be >= meshMessageDeliveriesThreshold"
)
check(meshFailurePenaltyWeight <= 0, "meshFailurePenaltyWeight <= 0")
check(invalidMessageDeliveriesWeight <= 0, "invalidMessageDeliveriesWeight <= 0")
check(meshFailurePenaltyWeight <= 0, "meshFailurePenaltyWeight should be <= 0")
check(invalidMessageDeliveriesWeight <= 0, "invalidMessageDeliveriesWeight should be <= 0")
}
companion object {
@JvmStatic
Expand Down
Loading