Skip to content

Commit

Permalink
Formatting fluffy with nph v0.5.1 + CI check (#2020)
Browse files Browse the repository at this point in the history
* Add nph check to fluffy CI lint

* Add a section on nph usage in the fluffy.guide

* Update copyright years for altered files

* Avoid chained methods formatting style in db code

* Update nph in CI to v0.5

* Remove leftover commented import

* Move comment to avoid nph turning complex list into simple list (nph bug)

* Update nph in CI to v0.5.1

* Formatting fluffy with nph v0.5.1
  • Loading branch information
kdeme authored Feb 28, 2024
1 parent b656875 commit 2d76b8c
Show file tree
Hide file tree
Showing 101 changed files with 4,041 additions and 3,846 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/fluffy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,18 @@ jobs:
with:
fetch-depth: 2 # In PR, has extra merge commit: ^1 = PR, ^2 = base

- name: Check nph formatting
# Pin nph to a specific version to avoid sudden style differences.
# Updating nph version should be accompanied with running the new
# version on the fluffy directory.
run: |
VERSION="v0.5.1"
ARCHIVE="nph-linux_x64.tar.gz"
curl -L "https://github.com/arnetheduck/nph/releases/download/${VERSION}/${ARCHIVE}" -o ${ARCHIVE}
tar -xzf ${ARCHIVE}
./nph fluffy/
git diff --exit-code
- name: Check copyright year
if: ${{ !cancelled() }} && github.event_name == 'pull_request'
run: |
Expand Down
9 changes: 3 additions & 6 deletions fluffy/common/common_types.nim
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# Nimbus
# Copyright (c) 2021-2023 Status Research & Development GmbH
# Copyright (c) 2021-2024 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).
# at your option. This file may not be copied, modified, or distributed except according to those terms.

{.push raises: [].}

import
ssz_serialization,
eth/rlp,
stew/[byteutils, results], nimcrypto/hash
import ssz_serialization, eth/rlp, stew/[byteutils, results], nimcrypto/hash

export hash

Expand Down Expand Up @@ -41,4 +38,4 @@ func decodeSszOrRaise*(input: openArray[byte], T: type): T =
try:
SSZ.decode(input, T)
except SerializationError as e:
raiseAssert(e.msg)
raiseAssert(e.msg)
33 changes: 12 additions & 21 deletions fluffy/common/common_utils.nim
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
# Nimbus
# Copyright (c) 2021-2023 Status Research & Development GmbH
# Copyright (c) 2021-2024 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).
# at your option. This file may not be copied, modified, or distributed except according to those terms.

{.push raises: [].}

import
std/[os, strutils],
chronicles, stew/io2,
eth/p2p/discoveryv5/enr
import std/[os, strutils], chronicles, stew/io2, eth/p2p/discoveryv5/enr

iterator strippedLines(filename: string): string {.raises: [ref IOError].} =
for line in lines(filename):
Expand All @@ -21,19 +18,18 @@ iterator strippedLines(filename: string): string {.raises: [ref IOError].} =
if stripped.len > 0:
yield stripped

proc addBootstrapNode(bootstrapAddr: string,
bootstrapEnrs: var seq[Record]) =
proc addBootstrapNode(bootstrapAddr: string, bootstrapEnrs: var seq[Record]) =
var enrRec: enr.Record
if enrRec.fromURI(bootstrapAddr):
bootstrapEnrs.add enrRec
else:
warn "Ignoring invalid bootstrap ENR", bootstrapAddr

proc loadBootstrapFile*(bootstrapFile: string,
bootstrapEnrs: var seq[Record]) =
if bootstrapFile.len == 0: return
proc loadBootstrapFile*(bootstrapFile: string, bootstrapEnrs: var seq[Record]) =
if bootstrapFile.len == 0:
return
let ext = splitFile(bootstrapFile).ext
if cmpIgnoreCase(ext, ".txt") == 0 or cmpIgnoreCase(ext, ".enr") == 0 :
if cmpIgnoreCase(ext, ".txt") == 0 or cmpIgnoreCase(ext, ".enr") == 0:
try:
for ln in strippedLines(bootstrapFile):
addBootstrapNode(ln, bootstrapEnrs)
Expand All @@ -50,8 +46,8 @@ proc loadBootstrapFile*(bootstrapFile: string,
# However that would require the pull the keystore.nim and parts of
# keystore_management.nim out of nimbus-eth2.
proc getPersistentNetKey*(
rng: var HmacDrbgContext, keyFilePath: string):
tuple[key: PrivateKey, newNetKey: bool] =
rng: var HmacDrbgContext, keyFilePath: string
): tuple[key: PrivateKey, newNetKey: bool] =
logScope:
key_file = keyFilePath

Expand All @@ -60,8 +56,7 @@ proc getPersistentNetKey*(

let readResult = readAllChars(keyFilePath)
if readResult.isErr():
fatal "Could not load network key file",
error = ioErrorMsg(readResult.error)
fatal "Could not load network key file", error = ioErrorMsg(readResult.error)
quit QuitFailure

let netKeyInHex = readResult.get()
Expand All @@ -76,14 +71,12 @@ proc getPersistentNetKey*(
else:
fatal "Invalid length of private in file"
quit QuitFailure

else:
info "Network key file is missing, creating a new one"
let key = PrivateKey.random(rng)

if (let res = io2.writeFile(keyFilePath, $key); res.isErr):
fatal "Failed to write the network key file",
error = ioErrorMsg(res.error)
fatal "Failed to write the network key file", error = ioErrorMsg(res.error)
quit 1

info "New network key file was created"
Expand All @@ -99,8 +92,7 @@ proc getPersistentEnr*(enrFilePath: string): Opt[enr.Record] =

let readResult = readAllChars(enrFilePath)
if readResult.isErr():
warn "Could not load ENR file",
error = ioErrorMsg(readResult.error)
warn "Could not load ENR file", error = ioErrorMsg(readResult.error)
return Opt.none(enr.Record)

let enrUri = readResult.get()
Expand All @@ -113,7 +105,6 @@ proc getPersistentEnr*(enrFilePath: string): Opt[enr.Record] =
return Opt.none(enr.Record)
else:
return Opt.some(record)

else:
warn "Could not find ENR file. Was it manually deleted?"
return Opt.none(enr.Record)
Loading

0 comments on commit 2d76b8c

Please sign in to comment.