From 0ec90b26a504074e95b9e704dddfe7cd916b7cf5 Mon Sep 17 00:00:00 2001 From: Kim De Mey Date: Wed, 9 Dec 2020 10:13:51 +0100 Subject: [PATCH] Update ENR record with metadata attnets at each attestation subnet cycle (#2148) --- beacon_chain/eth2_discovery.nim | 3 ++- beacon_chain/nimbus_beacon_node.nim | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/beacon_chain/eth2_discovery.nim b/beacon_chain/eth2_discovery.nim index 1a11b369e..bf6cc406c 100644 --- a/beacon_chain/eth2_discovery.nim +++ b/beacon_chain/eth2_discovery.nim @@ -14,7 +14,8 @@ type PublicKey = keys.PublicKey export - Eth2DiscoveryProtocol, open, start, close, closeWait, randomNodes, results + Eth2DiscoveryProtocol, open, start, close, closeWait, randomNodes, + updateRecord, results proc parseBootstrapAddress*(address: TaintedString): Result[enr.Record, cstring] = diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 0de9b1b7c..964cbdcfb 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -433,6 +433,14 @@ proc cycleAttestationSubnets(node: BeaconNode, slot: Slot) {.async.} = for subnet in 0'u8 ..< ATTESTATION_SUBNET_COUNT: node.network.metadata.attnets[subnet] = subnet in subscribed_subnets + # https://github.com/ethereum/eth2.0-specs/blob/v1.0.0/specs/phase0/p2p-interface.md#attestation-subnet-bitfield + let res = node.network.discovery.updateRecord( + {"attnets": SSZ.encode(node.network.metadata.attnets)}) + if res.isErr(): + # This should not occur in this scenario as the private key would always be + # the correct one and the ENR will not increase in size. + warn "Failed to update record on subnet cycle", error = res.error + proc getAttestationSubnetHandlers(node: BeaconNode): Future[void] = var initialSubnets: set[uint8] for i in 0'u8 ..< ATTESTATION_SUBNET_COUNT: