Add loop to history network to log status message on interval (#1526)

This commit is contained in:
Kim De Mey 2023-03-31 18:52:21 +02:00 committed by GitHub
parent 0b960f323c
commit 9453d5bb3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 1 deletions

View File

@ -213,7 +213,7 @@ proc unusedSize(db: ContentDB): int64 =
proc realSize*(db: ContentDB): int64 =
db.size() - db.unusedSize()
proc contentSize(db: ContentDB): int64 =
proc contentSize*(db: ContentDB): int64 =
## Returns total size of content stored in DB
var size: int64 = 0
discard (db.contentSizeStmt.exec do(res: int64):

View File

@ -54,6 +54,7 @@ type
contentQueue*: AsyncQueue[(ContentKeysList, seq[seq[byte]])]
accumulator*: FinishedAccumulator
processContentLoop: Future[void]
statusLogLoop: Future[void]
Block* = (BlockHeader, BlockBody)
@ -651,6 +652,26 @@ proc processContentLoop(n: HistoryNetwork) {.async.} =
except CancelledError:
trace "processContentLoop canceled"
proc statusLogLoop(n: HistoryNetwork) {.async.} =
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",
radius = radiusPercentage.toString(10) & "%",
dbSize = $(n.contentDB.size() div 1000) & "kb",
contentSize = $(n.contentDB.contentSize() div 1000) & "kb",
routingTableNodes = n.portalProtocol.routingTable.len()
await sleepAsync(60.seconds)
except CancelledError:
trace "statusLogLoop canceled"
proc start*(n: HistoryNetwork) =
info "Starting Portal execution history network",
protocolId = n.portalProtocol.protocolId,
@ -658,6 +679,7 @@ proc start*(n: HistoryNetwork) =
n.portalProtocol.start()
n.processContentLoop = processContentLoop(n)
n.statusLogLoop = statusLogLoop(n)
proc stop*(n: HistoryNetwork) =
n.portalProtocol.stop()