serve light client data on `prater` by default (#3559)

Applies a `prater` testnet specific config default to serve light client
data on that network.
This commit is contained in:
Etan Kissling 2022-04-01 23:58:06 +02:00 committed by GitHub
parent a18b39c9c1
commit 509aa6c252
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 73 additions and 15 deletions

View File

@ -429,15 +429,13 @@ type
serveLightClientData* {.
hidden
desc: "BETA: Serve data for enabling light clients to stay in sync with the network"
defaultValue: false
name: "serve-light-client-data"}: bool
name: "serve-light-client-data"}: Option[bool]
importLightClientData* {.
hidden
desc: "BETA: Which classes of light client data to import. " &
"Must be one of: none, only-new, full (slow startup), on-demand (may miss validator duties)"
defaultValue: ImportLightClientData.None
name: "import-light-client-data"}: ImportLightClientData
name: "import-light-client-data"}: Option[ImportLightClientData]
inProcessValidators* {.
desc: "Disable the push model (the beacon node tells a signing process with the private keys of the validators what to sign and when) and load the validators in the beacon node itself"

View File

@ -1456,7 +1456,7 @@ proc new*(T: type Eth2Node, config: BeaconNodeConf, runtimeCfg: RuntimeConfig,
node.protocolStates[proto.index] = proto.networkStateInitializer(node)
for msg in proto.messages:
if msg.isLightClientRequest and not config.serveLightClientData:
if msg.isLightClientRequest and not config.serveLightClientData.get:
continue
if msg.protocolMounter != nil:
msg.protocolMounter node

View File

@ -9,7 +9,7 @@
import
std/[sequtils, strutils, os],
stew/shims/macros, nimcrypto/hash,
stew/byteutils, stew/shims/macros, nimcrypto/hash,
eth/common/eth_types as commonEthTypes,
web3/[ethtypes, conversions],
chronicles,
@ -18,6 +18,9 @@ import
../spec/eth2_ssz_serialization,
../spec/datatypes/phase0
from ../consensus_object_pools/block_pools_types_light_client
import ImportLightClientData
# ATTENTION! This file will produce a large C file, because we are inlining
# genesis states as C literals in the generated code (and blobs in the final
# binary). It makes sense to keep the file small and separated from the rest
@ -37,6 +40,11 @@ type
rinkeby
goerli
Eth2NetworkConfigDefaults* = object
## Network specific config defaults
serveLightClientData*: bool
importLightClientData*: ImportLightClientData
Eth2NetworkMetadata* = object
case incompatible*: bool
of false:
@ -71,6 +79,8 @@ type
# unknown genesis state.
genesisData*: string
genesisDepositsSnapshot*: string
configDefaults*: Eth2NetworkConfigDefaults
else:
incompatibilityDesc*: string
@ -143,6 +153,38 @@ proc loadEth2NetworkMetadata*(path: string, eth1Network = none(Eth1Network)): Et
else:
""
enableLightClientData =
if genesisData.len >= 40:
# SSZ processing at compile time does not work well.
#
# `BeaconState` layout:
# ```
# - genesis_time: uint64
# - genesis_validators_root: Eth2Digest
# - ...
# ```
#
# Comparing the first 40 bytes covers those two fields,
# which should identify the network with high likelihood.
let data = (genesisData[0 ..< 40].toHex())
data in [
# Prater
"60F4596000000000043DB0D9A83813551EE2F33450D23797757D430911A9320530AD8A0EABC43EFB"
]
else:
false
configDefaults =
Eth2NetworkConfigDefaults(
serveLightClientData:
enableLightClientData,
importLightClientData:
if enableLightClientData:
ImportLightClientData.OnlyNew
else:
ImportLightClientData.None
)
Eth2NetworkMetadata(
incompatible: false,
eth1Network: eth1Network,
@ -150,7 +192,8 @@ proc loadEth2NetworkMetadata*(path: string, eth1Network = none(Eth1Network)): Et
bootstrapNodes: bootstrapNodes,
depositContractDeployedAt: depositContractDeployedAt,
genesisData: genesisData,
genesisDepositsSnapshot: genesisDepositsSnapshot)
genesisDepositsSnapshot: genesisDepositsSnapshot,
configDefaults: configDefaults)
except PresetIncompatibleError as err:
Eth2NetworkMetadata(incompatible: true,

View File

@ -166,14 +166,14 @@ proc loadChainDag(
if config.verifyFinalization: {verifyFinalization}
else: {}
onOptimisticLightClientUpdateCb =
if config.serveLightClientData: onOptimisticLightClientUpdate
if config.serveLightClientData.get: onOptimisticLightClientUpdate
else: nil
dag = ChainDAGRef.init(
cfg, db, validatorMonitor, chainDagFlags, config.eraDir,
onBlockAdded, onHeadChanged, onChainReorg,
onOptimisticLCUpdateCb = onOptimisticLightClientUpdateCb,
serveLightClientData = config.serveLightClientData,
importLightClientData = config.importLightClientData)
serveLightClientData = config.serveLightClientData.get,
importLightClientData = config.importLightClientData.get)
databaseGenesisValidatorsRoot =
getStateField(dag.headState, genesis_validators_root)
@ -857,7 +857,7 @@ proc addAltairMessageHandlers(node: BeaconNode, forkDigest: ForkDigest, slot: Sl
node.network.updateSyncnetsMetadata(currentSyncCommitteeSubnets)
if node.config.serveLightClientData:
if node.config.serveLightClientData.get:
node.network.subscribe(
getOptimisticLightClientUpdateTopic(forkDigest), basicParams)
@ -872,7 +872,7 @@ proc removeAltairMessageHandlers(node: BeaconNode, forkDigest: ForkDigest) =
node.network.unsubscribe(
getSyncCommitteeContributionAndProofTopic(forkDigest))
if node.config.serveLightClientData:
if node.config.serveLightClientData.get:
node.network.unsubscribe(getOptimisticLightClientUpdateTopic(forkDigest))
proc trackCurrentSyncCommitteeTopics(node: BeaconNode, slot: Slot) =
@ -1392,7 +1392,7 @@ proc installMessageValidators(node: BeaconNode) =
node.network.addValidator(
getOptimisticLightClientUpdateTopic(digest),
proc(msg: OptimisticLightClientUpdate): ValidationResult =
if node.config.serveLightClientData:
if node.config.serveLightClientData.get:
toValidationResult(
node.processor[].optimisticLightClientUpdateValidator(
MsgSource.gossip, msg))
@ -1713,6 +1713,21 @@ proc doRunBeaconNode(config: var BeaconNodeConf, rng: ref BrHmacDrbgContext) {.r
# works
for node in metadata.bootstrapNodes:
config.bootstrapNodes.add node
if config.serveLightClientData.isNone:
if metadata.configDefaults.serveLightClientData:
info "Applying network config default",
serveLightClientData = metadata.configDefaults.serveLightClientData,
eth2Network = config.eth2Network
config.serveLightClientData =
some metadata.configDefaults.serveLightClientData
if config.importLightClientData.isNone:
if metadata.configDefaults.importLightClientData !=
ImportLightClientData.None:
info "Applying network config default",
importLightClientData = metadata.configDefaults.importLightClientData,
eth2Network = config.eth2Network
config.importLightClientData =
some metadata.configDefaults.importLightClientData
let node = BeaconNode.init(
metadata.cfg,

View File

@ -1155,7 +1155,7 @@ proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
handleAttestations(node, head, slot)
handleSyncCommitteeMessages(node, head, slot)
if node.config.serveLightClientData and didSubmitBlock:
if node.config.serveLightClientData.get and didSubmitBlock:
let cutoff = node.beaconClock.fromNow(
slot.optimistic_light_client_update_time())
if cutoff.inFuture:
@ -1327,7 +1327,7 @@ proc sendBeaconBlock*(node: BeaconNode, forked: ForkedSignedBeaconBlock
blockRoot = shortLog(blck.root), blck = shortLog(blck.message),
signature = shortLog(blck.signature)
if node.config.serveLightClientData:
if node.config.serveLightClientData.get:
# The optimistic light client update is sent with a delay because it
# only validates once the new block has been processed by the peers.
# https://github.com/ethereum/consensus-specs/blob/vFuture/specs/altair/sync-protocol.md#block-proposal

View File

@ -154,6 +154,8 @@ proc startSingleNodeNetwork =
"--keymanager-address=127.0.0.1",
"--keymanager-port=" & $keymanagerPort,
"--keymanager-token-file=" & tokenFilePath,
"--serve-light-client-data=off",
"--import-light-client-data=none",
"--doppelganger-detection=off"], it))
let metadata = loadEth2NetworkMetadata(dataDir)