Search in sources :

Example 1 with GossipPeerScoringConfig

use of tech.pegasys.teku.networking.p2p.gossip.config.GossipPeerScoringConfig in project teku by ConsenSys.

the class GossipScoringConfiguratorTest method configure_preGenesis.

@Test
public void configure_preGenesis() {
    final GossipConfig.Builder builder = GossipConfig.builder();
    configurator.configure(builder, preGenesisEth2Context());
    final GossipConfig config = builder.build();
    final GossipScoringConfig scoringConfig = config.getScoringConfig();
    assertThat(scoringConfig.getGossipThreshold()).isEqualTo(-4000);
    assertThat(scoringConfig.getPublishThreshold()).isEqualTo(-8000);
    assertThat(scoringConfig.getGraylistThreshold()).isEqualTo(-16000);
    assertThat(scoringConfig.getAcceptPXThreshold()).isEqualTo(100);
    assertThat(scoringConfig.getOpportunisticGraftThreshold()).isEqualTo(5);
    final GossipPeerScoringConfig peerScoring = scoringConfig.getPeerScoringConfig();
    assertThat(peerScoring.getTopicScoreCap()).isCloseTo(53.75, within(TOLERANCE));
    assertThat(peerScoring.getIpColocationFactorWeight()).isCloseTo(-53.75, within(TOLERANCE));
    assertThat(peerScoring.getIpColocationFactorThreshold()).isEqualTo(3);
    assertThat(peerScoring.getBehaviourPenaltyDecay()).isCloseTo(0.9857, within(TOLERANCE));
    assertThat(peerScoring.getBehaviourPenaltyWeight()).isCloseTo(-15.8793, within(TOLERANCE));
    assertThat(peerScoring.getBehaviourPenaltyThreshold()).isEqualTo(6.0);
    assertThat(peerScoring.getDecayToZero()).isEqualTo(0.01);
    assertThat(peerScoring.getDecayInterval().toSeconds()).isEqualTo(12);
    assertThat(peerScoring.getRetainScore().toSeconds()).isEqualTo(38400);
    // Check topics
    final Map<String, GossipTopicScoringConfig> topicsConfig = scoringConfig.getTopicScoringConfig();
    assertThat(topicsConfig).isEmpty();
}
Also used : GossipScoringConfig(tech.pegasys.teku.networking.p2p.gossip.config.GossipScoringConfig) GossipConfig(tech.pegasys.teku.networking.p2p.gossip.config.GossipConfig) GossipTopicScoringConfig(tech.pegasys.teku.networking.p2p.gossip.config.GossipTopicScoringConfig) GossipPeerScoringConfig(tech.pegasys.teku.networking.p2p.gossip.config.GossipPeerScoringConfig) Test(org.junit.jupiter.api.Test)

Example 2 with GossipPeerScoringConfig

use of tech.pegasys.teku.networking.p2p.gossip.config.GossipPeerScoringConfig in project teku by ConsenSys.

the class LibP2PParamsFactory method createPeerScoreParams.

public static GossipPeerScoreParams createPeerScoreParams(final GossipPeerScoringConfig config) {
    final GossipPeerScoreParamsBuilder builder = GossipPeerScoreParams.builder().topicScoreCap(config.getTopicScoreCap()).appSpecificWeight(config.getAppSpecificWeight()).ipColocationFactorWeight(config.getIpColocationFactorWeight()).ipColocationFactorThreshold(config.getIpColocationFactorThreshold()).behaviourPenaltyWeight(config.getBehaviourPenaltyWeight()).behaviourPenaltyDecay(config.getBehaviourPenaltyDecay()).behaviourPenaltyThreshold(config.getBehaviourPenaltyThreshold()).decayInterval(config.getDecayInterval()).decayToZero(config.getDecayToZero()).retainScore(config.getRetainScore());
    // Configure optional params
    config.getAppSpecificScorer().ifPresent(scorer -> {
        final Function1<? super PeerId, Double> appSpecificScore = peerId -> scorer.scorePeer(new LibP2PNodeId(peerId));
        builder.appSpecificScore(appSpecificScore);
    });
    config.getDirectPeerManager().ifPresent(mgr -> {
        final Function1<? super PeerId, Boolean> isDirectPeer = peerId -> mgr.isDirectPeer(new LibP2PNodeId(peerId));
        builder.isDirect(isDirectPeer);
    });
    config.getWhitelistManager().ifPresent(mgr -> {
        // Ip whitelisting
        final Function1<? super String, Boolean> isIpWhitelisted = mgr::isWhitelisted;
        builder.ipWhitelisted(isIpWhitelisted);
    });
    return builder.build();
}
Also used : GossipPeerScoreParams(io.libp2p.pubsub.gossip.GossipPeerScoreParams) GossipScoringConfig(tech.pegasys.teku.networking.p2p.gossip.config.GossipScoringConfig) GossipPeerScoreParamsBuilder(io.libp2p.pubsub.gossip.builders.GossipPeerScoreParamsBuilder) GossipConfig(tech.pegasys.teku.networking.p2p.gossip.config.GossipConfig) GossipParams(io.libp2p.pubsub.gossip.GossipParams) GossipScoreParams(io.libp2p.pubsub.gossip.GossipScoreParams) Function1(kotlin.jvm.functions.Function1) Collectors(java.util.stream.Collectors) GossipPeerScoringConfig(tech.pegasys.teku.networking.p2p.gossip.config.GossipPeerScoringConfig) PeerId(io.libp2p.core.PeerId) GossipTopicScoreParams(io.libp2p.pubsub.gossip.GossipTopicScoreParams) LibP2PNodeId(tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId) Map(java.util.Map) GossipTopicsScoreParams(io.libp2p.pubsub.gossip.GossipTopicsScoreParams) GossipTopicScoringConfig(tech.pegasys.teku.networking.p2p.gossip.config.GossipTopicScoringConfig) LibP2PNodeId(tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId) GossipPeerScoreParamsBuilder(io.libp2p.pubsub.gossip.builders.GossipPeerScoreParamsBuilder)

Aggregations

GossipConfig (tech.pegasys.teku.networking.p2p.gossip.config.GossipConfig)2 GossipPeerScoringConfig (tech.pegasys.teku.networking.p2p.gossip.config.GossipPeerScoringConfig)2 GossipScoringConfig (tech.pegasys.teku.networking.p2p.gossip.config.GossipScoringConfig)2 GossipTopicScoringConfig (tech.pegasys.teku.networking.p2p.gossip.config.GossipTopicScoringConfig)2 PeerId (io.libp2p.core.PeerId)1 GossipParams (io.libp2p.pubsub.gossip.GossipParams)1 GossipPeerScoreParams (io.libp2p.pubsub.gossip.GossipPeerScoreParams)1 GossipScoreParams (io.libp2p.pubsub.gossip.GossipScoreParams)1 GossipTopicScoreParams (io.libp2p.pubsub.gossip.GossipTopicScoreParams)1 GossipTopicsScoreParams (io.libp2p.pubsub.gossip.GossipTopicsScoreParams)1 GossipPeerScoreParamsBuilder (io.libp2p.pubsub.gossip.builders.GossipPeerScoreParamsBuilder)1 Map (java.util.Map)1 Collectors (java.util.stream.Collectors)1 Function1 (kotlin.jvm.functions.Function1)1 Test (org.junit.jupiter.api.Test)1 LibP2PNodeId (tech.pegasys.teku.networking.p2p.libp2p.LibP2PNodeId)1