split subscribe into non-validating subscribe and addValidator (#1485)
* split subscribe into non-validating subscribe and addValidator * stop exporting get_committee_assignments
This commit is contained in:
parent
224ebdfd72
commit
22c1ef5a8d
|
@ -1226,8 +1226,7 @@ func peersCount*(node: Eth2Node): int =
|
|||
|
||||
proc subscribe*[MsgType](node: Eth2Node,
|
||||
topic: string,
|
||||
msgHandler: proc(msg: MsgType) {.gcsafe.},
|
||||
msgValidator: proc(msg: MsgType): bool {.gcsafe.} ) {.async, gcsafe.} =
|
||||
msgHandler: proc(msg: MsgType) {.gcsafe.} ) {.async, gcsafe.} =
|
||||
proc execMsgHandler(topic: string, data: seq[byte]) {.async, gcsafe.} =
|
||||
inc nbc_gossip_messages_received
|
||||
trace "Incoming pubsub message received",
|
||||
|
@ -1238,6 +1237,11 @@ proc subscribe*[MsgType](node: Eth2Node,
|
|||
debug "Gossip msg handler error",
|
||||
msg = err.msg, len = data.len, topic, msgId = gossipId(data)
|
||||
|
||||
await node.switch.subscribe(topic & "_snappy", execMsgHandler)
|
||||
|
||||
proc addValidator*[MsgType](node: Eth2Node,
|
||||
topic: string,
|
||||
msgValidator: proc(msg: MsgType): bool {.gcsafe.} ) =
|
||||
# Validate messages as soon as subscribed
|
||||
proc execValidator(
|
||||
topic: string, message: GossipMsg): Future[bool] {.async, gcsafe.} =
|
||||
|
@ -1252,7 +1256,15 @@ proc subscribe*[MsgType](node: Eth2Node,
|
|||
|
||||
node.switch.addValidator(topic & "_snappy", execValidator)
|
||||
|
||||
await node.switch.subscribe(topic & "_snappy", execMsgHandler)
|
||||
proc subscribe*[MsgType](node: Eth2Node,
|
||||
topic: string,
|
||||
msgHandler: proc(msg: MsgType) {.gcsafe.},
|
||||
msgValidator: proc(msg: MsgType): bool {.gcsafe.} ) {.async, gcsafe.} =
|
||||
node.addValidator(topic, msgValidator)
|
||||
await node.subscribe(topic, msgHandler)
|
||||
|
||||
proc unsubscribe*(node: Eth2Node, topic: string): Future[void] =
|
||||
node.switch.unsubscribeAll(topic)
|
||||
|
||||
proc traceMessage(fut: FutureBase, msgId: string) =
|
||||
fut.addCallback do (arg: pointer):
|
||||
|
|
|
@ -92,7 +92,7 @@ func getAttestationTopic*(forkDigest: ForkDigest,
|
|||
get_committee_count_per_slot(num_active_validators),
|
||||
attestation.data.slot, attestation.data.index.CommitteeIndex))
|
||||
|
||||
func get_committee_assignments*(
|
||||
func get_committee_assignments(
|
||||
state: BeaconState, epoch: Epoch,
|
||||
validator_indices: HashSet[ValidatorIndex]):
|
||||
seq[tuple[subnetIndex: uint64, slot: Slot]] =
|
||||
|
|
Loading…
Reference in New Issue