From 9626655557c890577cf959e2ab1dbcd7acb5304c Mon Sep 17 00:00:00 2001 From: Kim De Mey Date: Wed, 13 Apr 2022 11:17:07 +0200 Subject: [PATCH] Few more log improvements for Fluffy (#1060) --- fluffy/common/common_types.nim | 8 ++++++-- fluffy/common/common_utils.nim | 11 ++++++----- fluffy/network/history/history_content.nim | 21 +++++++++++++++++++-- fluffy/network/wire/portal_protocol.nim | 4 ++-- fluffy/populate_db.nim | 2 ++ 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/fluffy/common/common_types.nim b/fluffy/common/common_types.nim index e164df74e..725b85f7a 100644 --- a/fluffy/common/common_types.nim +++ b/fluffy/common/common_types.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2021 Status Research & Development GmbH +# Copyright (c) 2021-2022 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -8,7 +8,8 @@ {.push raises: [Defect].} import - ssz_serialization/types + ssz_serialization/types, + stew/byteutils type ByteList* = List[byte, 2048] @@ -16,3 +17,6 @@ type Bytes32* = array[32, byte] ContentId* = Uint256 + +func `$`*(x: ByteList): string = + x.asSeq.toHex() diff --git a/fluffy/common/common_utils.nim b/fluffy/common/common_utils.nim index 14120d294..2b7edf027 100644 --- a/fluffy/common/common_utils.nim +++ b/fluffy/common/common_utils.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2021 Status Research & Development GmbH +# Copyright (c) 2021-2022 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -60,7 +60,8 @@ proc getPersistentNetKey*( let readResult = readAllChars(keyFilePath) if readResult.isErr(): - fatal "Could not load network key file", error = readResult.error + fatal "Could not load network key file", + error = ioErrorMsg(readResult.error) quit QuitFailure let netKeyInHex = readResult.get() @@ -80,9 +81,9 @@ proc getPersistentNetKey*( info "Network key file is missing, creating a new one" let key = PrivateKey.random(rng) - let writeResult = io2.writeFile(keyFilePath, $key) - if writeResult.isErr: - fatal "Failed to write the network key file", errno = writeResult.error + if (let res = io2.writeFile(keyFilePath, $key); res.isErr): + fatal "Failed to write the network key file", + error = ioErrorMsg(res.error) quit 1 info "New network key file was created" diff --git a/fluffy/network/history/history_content.nim b/fluffy/network/history/history_content.nim index 3a09af7bf..a99e6a14b 100644 --- a/fluffy/network/history/history_content.nim +++ b/fluffy/network/history/history_content.nim @@ -1,5 +1,5 @@ # Nimbus -# Copyright (c) 2021 Status Research & Development GmbH +# Copyright (c) 2021-2022 Status Research & Development GmbH # Licensed and distributed under either of # * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT). # * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0). @@ -11,7 +11,7 @@ import std/options, - nimcrypto/[sha2, hash], stew/objects, stint, + nimcrypto/[sha2, hash], stew/byteutils, stint, ssz_serialization, ../../common/common_types @@ -53,3 +53,20 @@ func toContentId*(contentKey: ByteList): ContentId = func toContentId*(contentKey: ContentKey): ContentId = toContentId(encode(contentKey)) + +func `$`*(x: BlockHash): string = + "0x" & x.data.toHex() + +func `$`*(x: ContentKey): string = + let key = + case x.contentType: + of blockHeader: + x.blockHeaderKey + of blockBody: + x.blockBodyKey + of receipts: + x.receiptsKey + + "(contentType: " & $x.contentType & + ", blockHash: " & $key.blockHash & + ", chainId: " & $key.chainId & ")" diff --git a/fluffy/network/wire/portal_protocol.nim b/fluffy/network/wire/portal_protocol.nim index 5f1092aaa..ed7ef3884 100644 --- a/fluffy/network/wire/portal_protocol.nim +++ b/fluffy/network/wire/portal_protocol.nim @@ -590,7 +590,7 @@ proc findContent*(p: PortalProtocol, dst: Node, contentKey: ByteList): if connectionResult.isErr(): debug "Utp connection error while trying to find content", - msg = connectionResult.error + error = connectionResult.error return err("Error connecting uTP socket") let socket = connectionResult.get() @@ -677,7 +677,7 @@ proc offer(p: PortalProtocol, o: OfferRequest): if connectionResult.isErr(): debug "Utp connection error while trying to offer content", - msg = connectionResult.error + error = connectionResult.error return err("Error connecting uTP socket") let clientSocket = connectionResult.get() diff --git a/fluffy/populate_db.nim b/fluffy/populate_db.nim index 58a0944a0..5b71647e4 100644 --- a/fluffy/populate_db.nim +++ b/fluffy/populate_db.nim @@ -156,6 +156,7 @@ proc propagateHistoryDb*( if blockData.isOk(): for b in blocks(blockData.get(), verify): for value in b: + info "Seeding block content into the network", contentKey = value[0] # Note: This is the slowest part due to the hashing that takes place. let contentId = history_content.toContentId(value[0]) if p.inRange(contentId): @@ -190,6 +191,7 @@ proc propagateBlockHistoryDb*( let blockData = blockDataRes.get() for value in blockData: + info "Seeding block content into the network", contentKey = value[0] let contentId = history_content.toContentId(value[0]) if p.inRange(contentId): p.contentDB.put(contentId, value[1])