Topics validation and direct peers (#2237)
* pick the right libp2p branch * add topics validation
This commit is contained in:
parent
ce64da1fcd
commit
295e3c9c73
|
@ -1,6 +1,6 @@
|
|||
import
|
||||
# Std lib
|
||||
std/[typetraits, strutils, os, algorithm, math, sets],
|
||||
std/[typetraits, strutils, sequtils, os, algorithm, math, sets],
|
||||
std/options as stdOptions,
|
||||
|
||||
# Status libs
|
||||
|
@ -74,6 +74,7 @@ type
|
|||
forkId: ENRForkID
|
||||
rng*: ref BrHmacDrbgContext
|
||||
peers*: Table[PeerID, Peer]
|
||||
validTopics: HashSet[string]
|
||||
|
||||
EthereumNode = Eth2Node # needed for the definitions in p2p_backends_helpers
|
||||
|
||||
|
@ -1596,6 +1597,14 @@ proc subscribe*(node: Eth2Node, topic: string, enableTopicMetrics: bool = false)
|
|||
|
||||
node.pubsub.subscribe(topicName, dummyMsgHandler)
|
||||
|
||||
proc setValidTopics*(node: Eth2Node, topics: openArray[string]) =
|
||||
let topicsSnappy = topics.mapIt(it & "_snappy")
|
||||
node.validTopics = topicsSnappy.toHashSet()
|
||||
# there is a window of time where we got the switch open, we need this lazy update for now
|
||||
node.pubsub.subscriptionValidator =
|
||||
proc(topic: string): bool {.gcsafe, raises: [Defect].} =
|
||||
topic in node.validTopics
|
||||
|
||||
proc addValidator*[MsgType](node: Eth2Node,
|
||||
topic: string,
|
||||
msgValidator: proc(msg: MsgType):
|
||||
|
|
|
@ -296,6 +296,21 @@ proc init*(T: type BeaconNode,
|
|||
topicAggregateAndProofs: topicAggregateAndProofs,
|
||||
)
|
||||
|
||||
# set topic validation routine
|
||||
network.setValidTopics(
|
||||
block:
|
||||
var
|
||||
topics = @[
|
||||
topicBeaconBlocks,
|
||||
getAttesterSlashingsTopic(enrForkId.forkDigest),
|
||||
getProposerSlashingsTopic(enrForkId.forkDigest),
|
||||
getVoluntaryExitsTopic(enrForkId.forkDigest),
|
||||
getAggregateAndProofsTopic(enrForkId.forkDigest)
|
||||
]
|
||||
for subnet in 0'u64 ..< ATTESTATION_SUBNET_COUNT:
|
||||
topics &= getAttestationTopic(enrForkId.forkDigest, subnet)
|
||||
topics)
|
||||
|
||||
info "Loading slashing protection database", path = conf.validatorsDir()
|
||||
res.attachedValidators = ValidatorPool.init(
|
||||
SlashingProtectionDB.init(
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 3878a95b23306494b5ad1138383b78df7c7e42d0
|
||||
Subproject commit 983003a52b22926603f25bdf54c26e8a23c97254
|
Loading…
Reference in New Issue