Skip to content

Commit

Permalink
chore: adding lint job to the CI (#2925)
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielmer authored Jul 23, 2024
1 parent 8d107b0 commit 086cc8e
Show file tree
Hide file tree
Showing 18 changed files with 90 additions and 79 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,25 @@ jobs:
nim_wakunode_image: ${{ needs.build-docker-image.outputs.image }}
test_type: node-optional
debug: waku*

lint:
name: "Lint"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
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}
shopt -s extglob # Enable extended globbing
./nph examples waku tests tools apps *.@(nim|nims|nimble)
git diff --exit-code
29 changes: 19 additions & 10 deletions config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ if defined(windows):
# increase stack size
switch("passL", "-Wl,--stack,8388608")
# https://github.com/nim-lang/Nim/issues/4057
--tlsEmulation:off
--tlsEmulation:
off
if defined(i386):
# set the IMAGE_FILE_LARGE_ADDRESS_AWARE flag so we can use PAE, if enabled, and access more than 2 GiB of RAM
switch("passL", "-Wl,--large-address-aware")
Expand Down Expand Up @@ -60,28 +61,36 @@ else:
switch("passC", "-mno-avx512f")
switch("passL", "-mno-avx512f")


--threads:on
--opt:speed
--excessiveStackTrace:on
--threads:
on
--opt:
speed
--excessiveStackTrace:
on
# enable metric collection
--define:metrics
--define:
metrics
# for heap-usage-by-instance-type metrics and object base-type strings
--define:nimTypeNames
--define:
nimTypeNames

switch("define", "withoutPCRE")

# the default open files limit is too low on macOS (512), breaking the
# "--debugger:native" build. It can be increased with `ulimit -n 1024`.
if not defined(macosx) and not defined(android):
# add debugging symbols and original files and line numbers
--debugger:native
--debugger:
native
if not (defined(windows) and defined(i386)) and not defined(disable_libbacktrace):
# light-weight stack traces using libbacktrace and libunwind
--define:nimStackTraceOverride
--define:
nimStackTraceOverride
switch("import", "libbacktrace")

--define:nimOldCaseObjects # https://github.com/status-im/nim-confutils/issues/9
--define:
nimOldCaseObjects
# https://github.com/status-im/nim-confutils/issues/9

# `switch("warning[CaseTransition]", "off")` fails with "Error: invalid command line option: '--warning[CaseTransition]'"
switch("warning", "CaseTransition:off")
Expand Down
3 changes: 1 addition & 2 deletions examples/wakustealthcommitments/node_spec.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{.push raises: [].}

import
waku/[common/logging, factory/[waku, networks_config, external_config]]
import waku/[common/logging, factory/[waku, networks_config, external_config]]
import
std/[options, strutils, os, sequtils],
stew/shims/net as stewNet,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import
results,
waku/[common/logging,
waku_node,
waku_rln_relay,],
waku/[common/logging, waku_node, waku_rln_relay],
./erc_5564_interface as StealthCommitmentFFI,
./node_spec,
./wire_spec
Expand Down
3 changes: 1 addition & 2 deletions tests/incentivization/test_all.nim
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
import
./test_rpc_codec
import ./test_rpc_codec
12 changes: 7 additions & 5 deletions tests/waku_rln_relay/test_rln_group_manager_onchain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,9 @@ proc setup(): Future[OnchainGroupManager] {.async.} =
chainId: CHAIN_ID,
ethPrivateKey: pk,
rlnInstance: rlnInstance,
onFatalErrorAction: proc (errStr: string) =
onFatalErrorAction: proc(errStr: string) =
raiseAssert errStr
,
)

return manager
Expand Down Expand Up @@ -277,8 +278,9 @@ suite "Onchain group manager":
ethClientUrl: EthClient,
ethContractAddress: $differentContractAddress,
rlnInstance: manager.rlnInstance,
onFatalErrorAction: proc (errStr: string) =
onFatalErrorAction: proc(errStr: string) =
raiseAssert errStr
,
)
(await manager2.init()).isErrOr:
raiseAssert "Expected error when contract address doesn't match"
Expand Down Expand Up @@ -779,7 +781,7 @@ suite "Onchain group manager":
isReady == true

await manager.stop()

asyncTest "rln-relay-max-message-limit testing":
let
nodekey = generateSecp256k1Key()
Expand All @@ -797,9 +799,9 @@ suite "Onchain group manager":
try:
await node.mountRlnRelay(wakuRlnConfig)
except CatchableError as e:
check e.msg == "failed to mount WakuRlnRelay: rln-relay-user-message-limit can't be exceed then MAX_MESSAGE_LIMIT set by rln contract"
check e.msg ==
"failed to mount WakuRlnRelay: rln-relay-user-message-limit can't be exceed then MAX_MESSAGE_LIMIT set by rln contract"


################################
## Terminating/removing Anvil
################################
Expand Down
2 changes: 1 addition & 1 deletion tools/rln_keystore_generator/rln_keystore_generator.nim
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ proc doRlnKeystoreGenerator*(conf: WakuNodeConf) =
keystorePath: none(string),
keystorePassword: none(string),
ethPrivateKey: some(conf.rlnRelayEthPrivateKey),
onFatalErrorAction: onFatalErrorAction
onFatalErrorAction: onFatalErrorAction,
)
try:
(waitFor groupManager.init()).isOkOr:
Expand Down
2 changes: 0 additions & 2 deletions waku/common/rate_limit/per_peer_limiter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
## Rate limit is applied separately by each peer upon first use. Also time period is counted distinct per peer.
## It will use compensating replenish mode for peers to balance the load and allow fair usage of a service.



{.push raises: [].}

import std/[options, tables], chronos/timer, libp2p/stream/connection, libp2p/utility
Expand Down
8 changes: 2 additions & 6 deletions waku/incentivization/rpc.nim
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import
json_serialization,
std/options
import
../waku_core
import json_serialization, std/options
import ../waku_core

# Implementing the RFC:
# https://github.com/vacp2p/rfc/tree/master/content/docs/rfcs/73

type

EligibilityProof* = object
proofOfPayment*: Option[seq[byte]]

Expand Down
20 changes: 6 additions & 14 deletions waku/incentivization/rpc_codec.nim
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import
std/options
import
../common/protobuf,
../waku_core,
./rpc

import std/options
import ../common/protobuf, ../waku_core, ./rpc

# Codec for EligibilityProof

proc encode*(epRpc: EligibilityProof): ProtoBuffer =
proc encode*(epRpc: EligibilityProof): ProtoBuffer =
var pb = initProtoBuffer()
if epRpc.proofOfPayment.isSome():
let proofOfPayment = epRpc.proofOfPayment.get()
Expand All @@ -18,7 +13,7 @@ proc encode*(epRpc: EligibilityProof): ProtoBuffer =
discard
pb

proc decode*(T: type EligibilityProof, buffer: seq[byte]): ProtobufResult[T] =
proc decode*(T: type EligibilityProof, buffer: seq[byte]): ProtobufResult[T] =
let pb = initProtoBuffer(buffer)
var epRpc = EligibilityProof()
var proofOfPayment = newSeq[byte]()
Expand All @@ -28,17 +23,16 @@ proc decode*(T: type EligibilityProof, buffer: seq[byte]): ProtobufResult[T] =
epRpc.proofOfPayment = some(proofOfPayment)
ok(epRpc)


# Codec for EligibilityStatus

proc encode*(esRpc: EligibilityStatus): ProtoBuffer =
proc encode*(esRpc: EligibilityStatus): ProtoBuffer =
var pb = initProtoBuffer()
pb.write3(1, esRpc.statusCode)
if esRpc.statusDesc.isSome():
pb.write3(2, esRpc.statusDesc.get())
pb

proc decode*(T: type EligibilityStatus, buffer: seq[byte]): ProtobufResult[T] =
proc decode*(T: type EligibilityStatus, buffer: seq[byte]): ProtobufResult[T] =
let pb = initProtoBuffer(buffer)
var esRpc = EligibilityStatus()
# status code
Expand All @@ -55,5 +49,3 @@ proc decode*(T: type EligibilityStatus, buffer: seq[byte]): ProtobufResult[T] =
else:
esRpc.statusDesc = some(description)
ok(esRpc)


3 changes: 1 addition & 2 deletions waku/waku_api/rest/filter/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,5 @@ proc readValue*(
reader.raiseUnexpectedValue("Field `requestId` is missing")

value = FilterSubscriptionResponse(
requestId: requestId.get(),
statusDesc: statusDesc.get(""),
requestId: requestId.get(), statusDesc: statusDesc.get("")
)
3 changes: 2 additions & 1 deletion waku/waku_api/rest/store/types.nim
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ proc parseHash*(input: Option[string]): Result[Option[WakuMessageHash], string]
return err("waku message hash parsing error: " & error)

if decodedBytes.len != 32:
return err("waku message hash parsing error: invalid hash length: " & $decodedBytes.len)
return
err("waku message hash parsing error: invalid hash length: " & $decodedBytes.len)

let hash: WakuMessageHash = fromBytes(decodedBytes)

Expand Down
5 changes: 2 additions & 3 deletions waku/waku_rln_relay/constants.nim
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const DefaultRlnTreePath* = "rln_tree.db"
const
# pre-processed "rln/waku-rln-relay/v2.0.0" to array[32, byte]
DefaultRlnIdentifier*: RlnIdentifier = [
114, 108, 110, 47, 119, 97, 107, 117, 45, 114, 108, 110, 45, 114, 101, 108, 97,
121, 47, 118, 50, 46, 48, 46, 48, 0, 0, 0, 0, 0, 0, 0,
114, 108, 110, 47, 119, 97, 107, 117, 45, 114, 108, 110, 45, 114, 101, 108, 97, 121,
47, 118, 50, 46, 48, 46, 48, 0, 0, 0, 0, 0, 0, 0,
]
DefaultUserMessageLimit* = UserMessageLimit(20)

Expand Down Expand Up @@ -60052,7 +60052,6 @@ const StaticGroupKeys* =
const StaticGroupMerkleRoot* =
"2c149e48886b5ba3da2edf8db8d7a364ae7a25618489c04cf0c0380f7cdd4d6f"


const MaxClockGapSeconds* = 20.0 # the maximum clock difference between peers in seconds

# RLN Keystore defaults
Expand Down
1 change: 0 additions & 1 deletion waku/waku_rln_relay/contract.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# This contract code is used in deployment, note: this is not the deployedBytecode, it includes constructor args.
# Ref: https://github.com/waku-org/waku-rlnv2-contract
const PoseidonT3* =
Expand Down
1 change: 0 additions & 1 deletion waku/waku_rln_relay/conversion_utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ proc serialize*(
)
return output


proc serialize*(proof: RateLimitProof, data: openArray[byte]): seq[byte] =
## a private proc to convert RateLimitProof and data to a byte seq
## this conversion is used in the proof verification proc
Expand Down
Loading

0 comments on commit 086cc8e

Please sign in to comment.