From 9453d5bb3c04b1cf3ba2f8cffbe089faaf6ffec3 Mon Sep 17 00:00:00 2001 From: Kim De Mey Date: Fri, 31 Mar 2023 18:52:21 +0200 Subject: [PATCH] Add loop to history network to log status message on interval (#1526) --- fluffy/content_db.nim | 2 +- fluffy/network/history/history_network.nim | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/fluffy/content_db.nim b/fluffy/content_db.nim index e6e4e576e..fa8cc2f46 100644 --- a/fluffy/content_db.nim +++ b/fluffy/content_db.nim @@ -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): diff --git a/fluffy/network/history/history_network.nim b/fluffy/network/history/history_network.nim index ef420af7a..b17c62242 100644 --- a/fluffy/network/history/history_network.nim +++ b/fluffy/network/history/history_network.nim @@ -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()