Update ENR record with metadata attnets at each attestation subnet cycle (#2148)

This commit is contained in:
Kim De Mey 2020-12-09 10:13:51 +01:00 committed by GitHub
parent 8b8b25ddac
commit 0ec90b26a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -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] =

View File

@ -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: