Few more log improvements for Fluffy (#1060)

This commit is contained in:
Kim De Mey 2022-04-13 11:17:07 +02:00 committed by GitHub
parent d337806301
commit 9626655557
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 11 deletions

View File

@ -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()

View File

@ -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"

View File

@ -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 & ")"

View File

@ -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()

View File

@ -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])