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* {. serveLightClientData* {.
hidden hidden
desc: "BETA: Serve data for enabling light clients to stay in sync with the network" desc: "BETA: Serve data for enabling light clients to stay in sync with the network"
defaultValue: false name: "serve-light-client-data"}: Option[bool]
name: "serve-light-client-data"}: bool
importLightClientData* {. importLightClientData* {.
hidden hidden
desc: "BETA: Which classes of light client data to import. " & 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)" "Must be one of: none, only-new, full (slow startup), on-demand (may miss validator duties)"
defaultValue: ImportLightClientData.None name: "import-light-client-data"}: Option[ImportLightClientData]
name: "import-light-client-data"}: ImportLightClientData
inProcessValidators* {. 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" 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) node.protocolStates[proto.index] = proto.networkStateInitializer(node)
for msg in proto.messages: for msg in proto.messages:
if msg.isLightClientRequest and not config.serveLightClientData: if msg.isLightClientRequest and not config.serveLightClientData.get:
continue continue
if msg.protocolMounter != nil: if msg.protocolMounter != nil:
msg.protocolMounter node msg.protocolMounter node

View File

@ -9,7 +9,7 @@
import import
std/[sequtils, strutils, os], std/[sequtils, strutils, os],
stew/shims/macros, nimcrypto/hash, stew/byteutils, stew/shims/macros, nimcrypto/hash,
eth/common/eth_types as commonEthTypes, eth/common/eth_types as commonEthTypes,
web3/[ethtypes, conversions], web3/[ethtypes, conversions],
chronicles, chronicles,
@ -18,6 +18,9 @@ import
../spec/eth2_ssz_serialization, ../spec/eth2_ssz_serialization,
../spec/datatypes/phase0 ../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 # 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 # 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 # binary). It makes sense to keep the file small and separated from the rest
@ -37,6 +40,11 @@ type
rinkeby rinkeby
goerli goerli
Eth2NetworkConfigDefaults* = object
## Network specific config defaults
serveLightClientData*: bool
importLightClientData*: ImportLightClientData
Eth2NetworkMetadata* = object Eth2NetworkMetadata* = object
case incompatible*: bool case incompatible*: bool
of false: of false:
@ -71,6 +79,8 @@ type
# unknown genesis state. # unknown genesis state.
genesisData*: string genesisData*: string
genesisDepositsSnapshot*: string genesisDepositsSnapshot*: string
configDefaults*: Eth2NetworkConfigDefaults
else: else:
incompatibilityDesc*: string incompatibilityDesc*: string
@ -143,6 +153,38 @@ proc loadEth2NetworkMetadata*(path: string, eth1Network = none(Eth1Network)): Et
else: 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( Eth2NetworkMetadata(
incompatible: false, incompatible: false,
eth1Network: eth1Network, eth1Network: eth1Network,
@ -150,7 +192,8 @@ proc loadEth2NetworkMetadata*(path: string, eth1Network = none(Eth1Network)): Et
bootstrapNodes: bootstrapNodes, bootstrapNodes: bootstrapNodes,
depositContractDeployedAt: depositContractDeployedAt, depositContractDeployedAt: depositContractDeployedAt,
genesisData: genesisData, genesisData: genesisData,
genesisDepositsSnapshot: genesisDepositsSnapshot) genesisDepositsSnapshot: genesisDepositsSnapshot,
configDefaults: configDefaults)
except PresetIncompatibleError as err: except PresetIncompatibleError as err:
Eth2NetworkMetadata(incompatible: true, Eth2NetworkMetadata(incompatible: true,

View File

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

View File

@ -1155,7 +1155,7 @@ proc handleValidatorDuties*(node: BeaconNode, lastSlot, slot: Slot) {.async.} =
handleAttestations(node, head, slot) handleAttestations(node, head, slot)
handleSyncCommitteeMessages(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( let cutoff = node.beaconClock.fromNow(
slot.optimistic_light_client_update_time()) slot.optimistic_light_client_update_time())
if cutoff.inFuture: if cutoff.inFuture:
@ -1327,7 +1327,7 @@ proc sendBeaconBlock*(node: BeaconNode, forked: ForkedSignedBeaconBlock
blockRoot = shortLog(blck.root), blck = shortLog(blck.message), blockRoot = shortLog(blck.root), blck = shortLog(blck.message),
signature = shortLog(blck.signature) 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 # The optimistic light client update is sent with a delay because it
# only validates once the new block has been processed by the peers. # 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 # 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-address=127.0.0.1",
"--keymanager-port=" & $keymanagerPort, "--keymanager-port=" & $keymanagerPort,
"--keymanager-token-file=" & tokenFilePath, "--keymanager-token-file=" & tokenFilePath,
"--serve-light-client-data=off",
"--import-light-client-data=none",
"--doppelganger-detection=off"], it)) "--doppelganger-detection=off"], it))
let metadata = loadEth2NetworkMetadata(dataDir) let metadata = loadEth2NetworkMetadata(dataDir)