Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
force pushing to fix unstable base
  • Loading branch information
sinkingsugar committed Jan 25, 2021
commit 31cd2720b7b6728d729e573e02b2404e80c6ee76
15 changes: 14 additions & 1 deletion beacon_chain/eth2_network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1561,7 +1561,19 @@ proc createEth2Node*(rng: ref BrHmacDrbgContext,
p.historyLength = 6
p.historyGossip = 3
p.seenTTL = 385.seconds
p.gossipThreshold = -4000
p.publishThreshold = -8000
p.graylistThreshold = -16000
p.decayInterval = 12.seconds
p.decayToZero = 0.01
p.retainScore = 385.seconds
p.ipColocationFactorWeight = -53.75
p.ipColocationFactorThreshold = 3
p.behaviourPenaltyWeight = -15.9
p.behaviourPenaltyDecay = 0.986
p.floodPublish = true
p.gossipFactor = 0.05
p.disconnectBadPeers = true
p.validateParameters().tryGet()
p
pubsub = GossipSub.init(
Expand All @@ -1588,7 +1600,7 @@ proc announcedENR*(node: Eth2Node): enr.Record =
proc shortForm*(id: KeyPair): string =
$PeerID.init(id.pubkey)

proc subscribe*(node: Eth2Node, topic: string, enableTopicMetrics: bool = false) =
proc subscribe*(node: Eth2Node, topic: string, topicParams: TopicParams, enableTopicMetrics: bool = false) =
proc dummyMsgHandler(topic: string, data: seq[byte]) {.async.} =
discard

Expand All @@ -1598,6 +1610,7 @@ proc subscribe*(node: Eth2Node, topic: string, enableTopicMetrics: bool = false)
if enableTopicMetrics:
node.pubsub.knownTopics.incl(topicName)

node.pubsub.topicParams[topicName] = topicParams
node.pubsub.subscribe(topicName, dummyMsgHandler)

proc setValidTopics*(node: Eth2Node, topics: openArray[string]) =
Expand Down
92 changes: 86 additions & 6 deletions beacon_chain/nimbus_beacon_node.nim
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ import

from eth/common/eth_types import BlockHashOrNumber

from
libp2p/protocols/pubsub/gossipsub
import
TopicParams, validateParameters, init

const
hasPrompt = not defined(withoutPrompt)

Expand Down Expand Up @@ -364,10 +369,38 @@ func verifyFinalization(node: BeaconNode, slot: Slot) =
# finalization occurs every slot, to 4 slots vs scheduledSlot.
doAssert finalizedEpoch + 4 >= epoch

proc getTotalValidators(node: BeaconNode): uint64 =
let epochRef = getEpochRef(node.chainDag, node.chainDag.head, node.chainDag.head.slot.epoch)
epochRef.shuffled_active_validator_indices.lenu64()

proc installAttestationSubnetHandlers(node: BeaconNode, subnets: set[uint8]) =
const topicParams = TopicParams(
topicWeight: 0.015625,
timeInMeshWeight: 0.03333333333333333,
timeInMeshQuantum: chronos.seconds(12),
timeInMeshCap: 300,
firstMessageDeliveriesWeight: 0.8611923631641919,
firstMessageDeliveriesDecay: 0.8659643233600653,
firstMessageDeliveriesCap: 46.44723027156447,
meshMessageDeliveriesWeight: -37.221277470375405,
meshMessageDeliveriesDecay: 0.9646616199111993,
meshMessageDeliveriesThreshold: 13.595606364013024,
meshMessageDeliveriesCap: 217.5297018242084,
meshMessageDeliveriesActivation: chronos.seconds(204),
meshMessageDeliveriesWindow: chronos.seconds(2),
meshFailurePenaltyWeight: -37.221277470375405 ,
meshFailurePenaltyDecay: 0.9646616199111993,
invalidMessageDeliveriesWeight: -6879.999999999998,
invalidMessageDeliveriesDecay: 0.9971259067705325
)

static:
# compile time validation
topicParams.validateParameters().tryGet()

# https://github.com/ethereum/eth2.0-specs/blob/v1.0.0/specs/phase0/p2p-interface.md#attestations-and-aggregation
for subnet in subnets:
node.network.subscribe(getAttestationTopic(node.forkDigest, subnet))
node.network.subscribe(getAttestationTopic(node.forkDigest, subnet), topicParams)

proc updateStabilitySubnetMetadata(
node: BeaconNode, stabilitySubnets: set[uint8]) =
Expand Down Expand Up @@ -605,11 +638,58 @@ proc getAttestationSubnetHandlers(node: BeaconNode) =
node.attestationSubnets.subscribedSubnets + initialStabilitySubnets)

proc addMessageHandlers(node: BeaconNode) =
node.network.subscribe(node.topicBeaconBlocks, enableTopicMetrics = true)
node.network.subscribe(getAttesterSlashingsTopic(node.forkDigest))
node.network.subscribe(getProposerSlashingsTopic(node.forkDigest))
node.network.subscribe(getVoluntaryExitsTopic(node.forkDigest))
node.network.subscribe(getAggregateAndProofsTopic(node.forkDigest), enableTopicMetrics = true)
const
blocksTopicParams = TopicParams(
topicWeight: 0.5,
timeInMeshWeight: 0.03333333333333333,
timeInMeshQuantum: chronos.seconds(12),
timeInMeshCap: 300,
firstMessageDeliveriesWeight: 1.1471603557060206,
firstMessageDeliveriesDecay: 0.9928302477768374,
firstMessageDeliveriesCap: 34.86870846001471,
meshMessageDeliveriesWeight: -458.31054878249114,
meshMessageDeliveriesDecay: 0.9716279515771061,
meshMessageDeliveriesThreshold: 0.6849191409056553,
meshMessageDeliveriesCap: 2.054757422716966,
meshMessageDeliveriesActivation: chronos.seconds(384),
meshMessageDeliveriesWindow: chronos.seconds(2),
meshFailurePenaltyWeight: -458.31054878249114 ,
meshFailurePenaltyDecay: 0.9716279515771061,
invalidMessageDeliveriesWeight: -214.99999999999994,
invalidMessageDeliveriesDecay: 0.9971259067705325
)
aggregateTopicParams = TopicParams(
topicWeight: 0.5,
timeInMeshWeight: 0.03333333333333333,
timeInMeshQuantum: chronos.seconds(12),
timeInMeshCap: 300,
firstMessageDeliveriesWeight: 0.10764904539552399,
firstMessageDeliveriesDecay: 0.8659643233600653,
firstMessageDeliveriesCap: 371.5778421725158,
meshMessageDeliveriesWeight: -0.07538533073670682,
meshMessageDeliveriesDecay: 0.930572040929699,
meshMessageDeliveriesThreshold: 53.404248450179836,
meshMessageDeliveriesCap: 213.61699380071934,
meshMessageDeliveriesActivation: chronos.seconds(384),
meshMessageDeliveriesWindow: chronos.seconds(2),
meshFailurePenaltyWeight: -0.07538533073670682 ,
meshFailurePenaltyDecay: 0.930572040929699,
invalidMessageDeliveriesWeight: -214.99999999999994,
invalidMessageDeliveriesDecay: 0.9971259067705325
)
basicParams = TopicParams.init()

static:
# compile time validation
blocksTopicParams.validateParameters().tryGet()
aggregateTopicParams.validateParameters().tryGet()
basicParams.validateParameters.tryGet()

node.network.subscribe(node.topicBeaconBlocks, blocksTopicParams, enableTopicMetrics = true)
node.network.subscribe(getAttesterSlashingsTopic(node.forkDigest), basicParams)
node.network.subscribe(getProposerSlashingsTopic(node.forkDigest), basicParams)
node.network.subscribe(getVoluntaryExitsTopic(node.forkDigest), basicParams)
node.network.subscribe(getAggregateAndProofsTopic(node.forkDigest), aggregateTopicParams, enableTopicMetrics = true)
node.getAttestationSubnetHandlers()

func getTopicSubscriptionEnabled(node: BeaconNode): bool =
Expand Down
2 changes: 1 addition & 1 deletion vendor/nim-libp2p