Fluffy state network now enabled by default and improve status logs (#2640)

* Enable state network by default. Create status log loop for state and beacon networks. Create status log loop for portal node. Implement stop functions.
This commit is contained in:
web3-developer 2024-09-19 21:38:49 +08:00 committed by GitHub
parent 2fe8cc4551
commit a9ad10cadc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 89 additions and 17 deletions

View File

@ -89,7 +89,7 @@ type
portalSubnetworks* {.
desc: "Select which networks (Portal sub-protocols) to enable",
defaultValue: {PortalSubnetwork.history},
defaultValue: {PortalSubnetwork.history, PortalSubnetwork.state},
name: "portal-subnetworks"
.}: set[PortalSubnetwork]

View File

@ -178,10 +178,13 @@ proc new*(
)
proc start*(lightClient: LightClient) =
notice "Starting beacon light client",
trusted_block_root = lightClient.trustedBlockRoot
info "Starting beacon light client", trusted_block_root = lightClient.trustedBlockRoot
lightClient.manager.start()
proc stop*(lightClient: LightClient) =
info "Stopping beacon light client"
discard lightClient.manager.stop()
proc resetToFinalizedHeader*(
lightClient: LightClient,
header: ForkedLightClientHeader,

View File

@ -31,6 +31,7 @@ type BeaconNetwork* = ref object
forkDigests*: ForkDigests
trustedBlockRoot: Opt[Eth2Digest]
processContentLoop: Future[void]
statusLogLoop: Future[void]
func toContentIdHandler(contentKey: ContentKeyByteList): results.Opt[ContentId] =
ok(toContentId(contentKey))
@ -364,13 +365,29 @@ proc processContentLoop(n: BeaconNetwork) {.async: (raises: []).} =
except CancelledError:
trace "processContentLoop canceled"
proc statusLogLoop(n: BeaconNetwork) {.async: (raises: []).} =
try:
while true:
info "Beacon network status",
routingTableNodes = n.portalProtocol.routingTable.len()
await sleepAsync(60.seconds)
except CancelledError:
trace "statusLogLoop canceled"
proc start*(n: BeaconNetwork) =
info "Starting Portal beacon chain network"
n.portalProtocol.start()
n.processContentLoop = processContentLoop(n)
proc stop*(n: BeaconNetwork) =
info "Stopping Portal beacon chain network"
n.portalProtocol.stop()
if not n.processContentLoop.isNil:
n.processContentLoop.cancelSoon()
if not n.statusLogLoop.isNil():
n.statusLogLoop.cancelSoon()

View File

@ -704,17 +704,7 @@ proc processContentLoop(n: HistoryNetwork) {.async: (raises: []).} =
proc statusLogLoop(n: HistoryNetwork) {.async: (raises: []).} =
try:
while true:
# This is the data radius percentage compared to full storage. This will
# drop a lot when using the logbase2 scale, namely `/ 2` per 1 logaritmic
# radius drop.
# TODO: Get some float precision calculus?
let radiusPercentage =
n.portalProtocol.dataRadius() div (UInt256.high() div u256(100))
info "History network status",
radiusPercentage = radiusPercentage.toString(10) & "%",
radius = n.portalProtocol.dataRadius().toHex(),
dbSize = $(n.contentDB.size() div 1000) & "kb",
routingTableNodes = n.portalProtocol.routingTable.len()
await sleepAsync(60.seconds)
@ -725,6 +715,7 @@ proc start*(n: HistoryNetwork) =
info "Starting Portal execution history network",
protocolId = n.portalProtocol.protocolId,
accumulatorRoot = hash_tree_root(n.accumulator)
n.portalProtocol.start()
n.processContentLoop = processContentLoop(n)
@ -732,10 +723,12 @@ proc start*(n: HistoryNetwork) =
pruneDeprecatedAccumulatorRecords(n.accumulator, n.contentDB)
proc stop*(n: HistoryNetwork) =
info "Stopping Portal execution history network"
n.portalProtocol.stop()
if not n.processContentLoop.isNil:
n.processContentLoop.cancelSoon()
if not n.processContentLoop.isNil:
if not n.statusLogLoop.isNil:
n.statusLogLoop.cancelSoon()

View File

@ -128,7 +128,6 @@ proc gossipOffer*(
debug "Offered content gossipped successfully with peers", keyBytes, peers
# Currently only used for testing to gossip an entire account trie proof
# This may also be useful for the state network bridge
proc recursiveGossipOffer*(
p: PortalProtocol,
srcNodeId: Opt[NodeId],

View File

@ -31,6 +31,7 @@ type StateNetwork* = ref object
contentDB*: ContentDB
contentQueue*: AsyncQueue[(Opt[NodeId], ContentKeysList, seq[seq[byte]])]
processContentLoop: Future[void]
statusLogLoop: Future[void]
historyNetwork: Opt[HistoryNetwork]
validateStateIsCanonical: bool
@ -221,15 +222,32 @@ proc processContentLoop(n: StateNetwork) {.async: (raises: []).} =
except CancelledError:
trace "processContentLoop canceled"
proc statusLogLoop(n: StateNetwork) {.async: (raises: []).} =
try:
while true:
info "State network status",
routingTableNodes = n.portalProtocol.routingTable.len()
await sleepAsync(60.seconds)
except CancelledError:
trace "statusLogLoop canceled"
proc start*(n: StateNetwork) =
info "Starting Portal execution state network",
protocolId = n.portalProtocol.protocolId
n.portalProtocol.start()
n.processContentLoop = processContentLoop(n)
n.statusLogLoop = statusLogLoop(n)
proc stop*(n: StateNetwork) =
info "Stopping Portal execution state network"
n.portalProtocol.stop()
if not n.processContentLoop.isNil:
if not n.processContentLoop.isNil():
n.processContentLoop.cancelSoon()
if not n.statusLogLoop.isNil():
n.statusLogLoop.cancelSoon()

View File

@ -9,6 +9,7 @@
import
results,
chronos,
eth/p2p/discoveryv5/protocol,
beacon_chain/spec/forks,
./network_metadata,
@ -39,6 +40,7 @@ type
historyNetwork*: Opt[HistoryNetwork]
stateNetwork*: Opt[StateNetwork]
beaconLightClient*: Opt[LightClient]
statusLogLoop: Future[void]
# Beacon light client application callbacks triggered when new finalized header
# or optimistic header is available.
@ -179,7 +181,27 @@ proc new*(
beaconLightClient: beaconLightClient,
)
proc statusLogLoop(n: PortalNode) {.async: (raises: []).} =
try:
while true:
# This is the data radius percentage compared to full storage. This will
# drop a lot when using the logbase2 scale, namely `/ 2` per 1 logaritmic
# radius drop.
# TODO: Get some float precision calculus?
let radiusPercentage = n.contentDB.dataRadius div (UInt256.high() div u256(100))
info "Portal node status",
radiusPercentage = radiusPercentage.toString(10) & "%",
radius = n.contentDB.dataRadius.toHex(),
dbSize = $(n.contentDB.size() div 1000) & "kb"
await sleepAsync(60.seconds)
except CancelledError:
trace "statusLogLoop canceled"
proc start*(n: PortalNode) =
debug "Starting Portal node"
if n.beaconNetwork.isSome():
n.beaconNetwork.value.start()
if n.historyNetwork.isSome():
@ -189,3 +211,21 @@ proc start*(n: PortalNode) =
if n.beaconLightClient.isSome():
n.beaconLightClient.value.start()
n.statusLogLoop = statusLogLoop(n)
proc stop*(n: PortalNode) =
debug "Stopping Portal node"
if n.beaconNetwork.isSome():
n.beaconNetwork.value.stop()
if n.historyNetwork.isSome():
n.historyNetwork.value.stop()
if n.stateNetwork.isSome():
n.stateNetwork.value.stop()
if n.beaconLightClient.isSome():
n.beaconLightClient.value.stop()
if not n.statusLogLoop.isNil:
n.statusLogLoop.cancelSoon()

View File

@ -298,7 +298,9 @@ proc runBackfillGossipBlockOffersLoop(
for k, v in offersMap:
try:
let numPeers = await portalClient.portal_stateGossip(k.to0xHex(), v.to0xHex())
if numPeers == 0:
if numPeers > 0:
debug "Offer successfully gossipped to peers: ", numPeers, workerId
elif numPeers == 0:
warn "Offer gossipped to no peers", workerId
retryGossip = true
break