mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-02-17 08:56:45 +00:00
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
|
import
|
||||||
# Std lib
|
# Std lib
|
||||||
std/[typetraits, strutils, os, algorithm, math, sets],
|
std/[typetraits, strutils, sequtils, os, algorithm, math, sets],
|
||||||
std/options as stdOptions,
|
std/options as stdOptions,
|
||||||
|
|
||||||
# Status libs
|
# Status libs
|
||||||
@ -74,6 +74,7 @@ type
|
|||||||
forkId: ENRForkID
|
forkId: ENRForkID
|
||||||
rng*: ref BrHmacDrbgContext
|
rng*: ref BrHmacDrbgContext
|
||||||
peers*: Table[PeerID, Peer]
|
peers*: Table[PeerID, Peer]
|
||||||
|
validTopics: HashSet[string]
|
||||||
|
|
||||||
EthereumNode = Eth2Node # needed for the definitions in p2p_backends_helpers
|
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)
|
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,
|
proc addValidator*[MsgType](node: Eth2Node,
|
||||||
topic: string,
|
topic: string,
|
||||||
msgValidator: proc(msg: MsgType):
|
msgValidator: proc(msg: MsgType):
|
||||||
|
@ -296,6 +296,21 @@ proc init*(T: type BeaconNode,
|
|||||||
topicAggregateAndProofs: topicAggregateAndProofs,
|
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()
|
info "Loading slashing protection database", path = conf.validatorsDir()
|
||||||
res.attachedValidators = ValidatorPool.init(
|
res.attachedValidators = ValidatorPool.init(
|
||||||
SlashingProtectionDB.init(
|
SlashingProtectionDB.init(
|
||||||
|
2
vendor/nim-libp2p
vendored
2
vendor/nim-libp2p
vendored
@ -1 +1 @@
|
|||||||
Subproject commit 3878a95b23306494b5ad1138383b78df7c7e42d0
|
Subproject commit 983003a52b22926603f25bdf54c26e8a23c97254
|
Loading…
x
Reference in New Issue
Block a user