Add style check to config.nims and fix styles in source code (#2038)

* Add style check to config.nims and fix styles in source code

* Fix copyright year
This commit is contained in:
andri lim 2024-02-20 10:07:38 +07:00 committed by GitHub
parent 47b254d8b5
commit 7c1af9a78f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 77 additions and 74 deletions

View File

@ -105,6 +105,8 @@ if not defined(windows):
--define:metrics
# for heap-usage-by-instance-type metrics and object base-type strings
--define:nimTypeNames
--styleCheck:usages
--styleCheck:hint
switch("define", "withoutPCRE")

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2023 Status Research & Development GmbH
# Copyright (c) 2023-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
@ -73,7 +73,7 @@ proc reachTTD*(ben: BeaconEngineRef) =
proc finalizePoS*(ben: BeaconEngineRef) =
## FinalizePoS is called whenever the first FinalisedBlock message received
## from the consensus-layer.
ben.merge.finalizePos()
ben.merge.finalizePoS()
proc put*(ben: BeaconEngineRef,
hash: common.Hash256, header: common.BlockHeader) =

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2023 Status Research & Development GmbH
# Copyright (c) 2023-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
@ -19,18 +19,18 @@ import
func wdRoot(list: openArray[WithdrawalV1]): common.Hash256
{.gcsafe, raises:[].} =
{.nosideEffect.}:
{.noSideEffect.}:
calcWithdrawalsRoot(ethWithdrawals list)
func wdRoot(x: Option[seq[WithdrawalV1]]): Option[common.Hash256]
{.gcsafe, raises:[].} =
{.nosideEffect.}:
{.noSideEffect.}:
if x.isNone: none(common.Hash256)
else: some(wdRoot x.get)
func txRoot(list: openArray[Web3Tx]): common.Hash256
{.gcsafe, raises:[RlpError].} =
{.nosideEffect.}:
{.noSideEffect.}:
calcTxRoot(ethTxs(list, removeBlobs = true))
# ------------------------------------------------------------------------------

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2022-2023 Status Research & Development GmbH
# Copyright (c) 2022-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
@ -533,7 +533,7 @@ proc setTTD*(com: CommonRef, ttd: Option[DifficultyInt]) =
# rebuild the MergeFork piece of the forkTransitionTable
com.forkTransitionTable.mergeForkTransitionThreshold = com.config.mergeForkTransitionThreshold
proc setFork*(com: CommonRef, fork: HardFork): Hardfork =
proc setFork*(com: CommonRef, fork: HardFork): HardFork =
## useful for testing
result = com.currentFork
com.currentFork = fork

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2023 Status Research & Development GmbH
# Copyright (c) 2023-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -111,10 +111,10 @@ proc getTotalBlobGas*(tx: Transaction): uint64 =
GAS_PER_BLOB * tx.versionedHashes.len.uint64
proc getTotalBlobGas*(versionedHashesLen: int): uint64 =
GAS_PER_BLOB * versionedHasheslen.uint64
GAS_PER_BLOB * versionedHashesLen.uint64
# getBlobGasPrice implements get_data_gas_price from EIP-4844
func getBlobGasprice*(excessBlobGas: uint64): UInt256 =
func getBlobGasPrice*(excessBlobGas: uint64): UInt256 =
fakeExponential(
MIN_BLOB_GASPRICE.u256,
excessBlobGas.u256,
@ -124,7 +124,7 @@ func getBlobGasprice*(excessBlobGas: uint64): UInt256 =
proc calcDataFee*(versionedHashesLen: int,
excessBlobGas: uint64): UInt256 =
getTotalBlobGas(versionedHashesLen).u256 *
getBlobGasprice(excessBlobGas)
getBlobGasPrice(excessBlobGas)
func blobGasUsed(txs: openArray[Transaction]): uint64 =
for tx in txs:

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2018-2023 Status Research & Development GmbH
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -554,7 +554,7 @@ proc smartHead*(xp: TxPoolRef; pos: BlockHeader; blindMode = false): bool
## simply set ignoring all changes. This mode makes sense only in very
## particular circumstances.
if blindMode:
xp.sethead(pos)
xp.setHead(pos)
return true
let rcDiff = xp.headDiff(pos)
@ -563,7 +563,7 @@ proc smartHead*(xp: TxPoolRef; pos: BlockHeader; blindMode = false): bool
# Need to move head before adding txs which may rightly be rejected in
# `addTxs()` otherwise.
xp.sethead(pos)
xp.setHead(pos)
# Re-inject transactions, do that via job queue
if 0 < changes.addTxs.len:
@ -817,7 +817,7 @@ iterator okPairs*(xp: TxPoolRef): (Hash256, TxItemRef) =
proc numTxs*(xp: TxPoolRef): int =
xp.txDB.byItemID.len
proc disposeAll*(xp: TxpoolRef) {.gcsafe,raises: [CatchableError].} =
proc disposeAll*(xp: TxPoolRef) {.gcsafe,raises: [CatchableError].} =
let numTx = xp.numTxs
var list = newSeqOfCap[TxItemRef](numTx)
for x in nextPairs(xp.txDB.byItemID):

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2018 Status Research & Development GmbH
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2018-2023 Status Research & Development GmbH
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -232,10 +232,10 @@ proc validateTxBasic*(
if validateFork:
if tx.txType == TxEip2930 and fork < FkBerlin:
return err("invalid tx: Eip2930 Tx type detected before Berlin")
if tx.txType == TxEip1559 and fork < FkLondon:
return err("invalid tx: Eip1559 Tx type detected before London")
if tx.txType == TxEip4844 and fork < FkCancun:
return err("invalid tx: Eip4844 Tx type detected before Cancun")

View File

@ -1,5 +1,5 @@
# nimbus-eth1
# Copyright (c) 2023 Status Research & Development GmbH
# Copyright (c) 2023-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -114,7 +114,7 @@ proc blobify*(vtx: VertexRef; data: var Blob): Result[void,AristoError] =
let
pSegm = vtx.ePfx.hexPrefixEncode(isleaf = false)
psLen = pSegm.len.byte
if psLen == 0 or 33 < pslen:
if psLen == 0 or 33 < psLen:
return err(BlobifyExtPathOverflow)
if not vtx.eVid.isValid:
return err(BlobifyExtMissingRefs)
@ -325,7 +325,7 @@ proc deblobify(data: Blob; pyl: var PayloadRef): Result[void,AristoError] =
else:
return err(DeblobCodeLenUnsupported)
pyl = pacc
pyl = pAcc
ok()
proc deblobify*(record: Blob; vtx: var VertexRef): Result[void,AristoError] =
@ -365,10 +365,10 @@ proc deblobify*(record: Blob; vtx: var VertexRef): Result[void,AristoError] =
of 2: # `Extension` vertex
let
sLen = record[^1].int and 0x3f # length of path segment
rlen = record.len - 1 # `vertexID` + path segm
rLen = record.len - 1 # `vertexID` + path segm
if record.len < 10:
return err(DeblobExtTooShort)
if 8 + sLen != rlen: # => slen is at least 1
if 8 + sLen != rLen: # => slen is at least 1
return err(DeblobExtSizeGarbled)
let (isLeaf, pathSegment) = hexPrefixDecode record[8 ..< rLen]
if isLeaf:
@ -381,15 +381,15 @@ proc deblobify*(record: Blob; vtx: var VertexRef): Result[void,AristoError] =
of 3: # `Leaf` vertex
let
sLen = record[^1].int and 0x3f # length of path segment
rlen = record.len - 1 # payload + path segment
rLen = record.len - 1 # payload + path segment
pLen = rLen - sLen # payload length
if rlen < sLen:
if rLen < sLen:
return err(DeblobLeafSizeGarbled)
let (isLeaf, pathSegment) = hexPrefixDecode record[pLen ..< rLen]
if not isLeaf:
return err(DeblobLeafGotExtPrefix)
var pyl: PayloadRef
? record[0 ..< plen].deblobify(pyl)
? record[0 ..< pLen].deblobify(pyl)
vtx = VertexRef(
vType: Leaf,
lPfx: pathSegment,

View File

@ -266,7 +266,7 @@ func dup*(vtx: VertexRef): VertexRef =
VertexRef(
vType: Leaf,
lPfx: vtx.lPfx,
lData: vtx.ldata.dup)
lData: vtx.lData.dup)
of Extension:
VertexRef(
vType: Extension,
@ -288,7 +288,7 @@ func dup*(node: NodeRef): NodeRef =
NodeRef(
vType: Leaf,
lPfx: node.lPfx,
lData: node.ldata.dup,
lData: node.lData.dup,
key: node.key)
of Extension:
NodeRef(

View File

@ -95,7 +95,7 @@ func pathPfxPad*(pfx: NibblesSeq; dblNibble: static[byte]): NibblesSeq =
let padLen = 64 - pfx.len
if 0 <= padLen:
result = pfx & dblNibble.repeat(padlen div 2).mapIt(it.byte).initNibbleRange
result = pfx & dblNibble.repeat(padLen div 2).mapIt(it.byte).initNibbleRange
if (padLen and 1) == 1:
result = result & @[dblNibble.byte].initNibbleRange.slice(1)
else:

View File

@ -40,7 +40,7 @@ proc toAccount*(
var acc = Account(
nonce: payload.account.nonce,
balance: payload.account.balance,
codeHash: payload.account.codehash,
codeHash: payload.account.codeHash,
storageRoot: EMPTY_ROOT_HASH)
if payload.account.storageID.isValid:
acc.storageRoot = (? db.getKeyRc payload.account.storageID).to(Hash256)
@ -75,7 +75,7 @@ proc toAccount*(
var acc = Account(
nonce: node.lData.account.nonce,
balance: node.lData.account.balance,
codeHash: node.lData.account.codehash,
codeHash: node.lData.account.codeHash,
storageRoot: EMPTY_ROOT_HASH)
if node.lData.account.storageID.isValid:
if not node.key[0].isValid:

View File

@ -514,7 +514,7 @@ proc baseMethods(
ok(db.bless db.top),
captureFn: proc(flgs: set[CoreDbCaptFlags]): CoreDbRc[CoreDxCaptRef] =
let fns = newRecorderRef(tdb, dbtype, flgs).cptMethods
let fns = newRecorderRef(tdb, dbType, flgs).cptMethods
ok(db.bless CoreDxCaptRef(methods: fns)))
# ------------------------------------------------------------------------------

View File

@ -67,18 +67,18 @@ proc toStr*(w: seq[(UInt256,UInt256)]): string =
# Public helpers
# ------------------------------------------------------------------------------
proc db*(t: SomeLedger): CoreDbRef =
t.distinctBase.parent
proc db*(led: SomeLedger): CoreDbRef =
led.distinctBase.parent
proc rootHash*(t: SomeLedger): Hash256 =
proc rootHash*(led: SomeLedger): Hash256 =
const info = "SomeLedger/rootHash(): "
let rc = t.distinctBase.getTrie().rootHash()
let rc = led.distinctBase.getTrie().rootHash()
if rc.isErr:
raiseAssert info & $$rc.error
rc.value
proc getTrie*(t: SomeLedger): CoreDbTrieRef =
t.distinctBase.getTrie()
proc getTrie*(led: SomeLedger): CoreDbTrieRef =
led.distinctBase.getTrie()
# ------------------------------------------------------------------------------
# Public functions: accounts ledger

View File

@ -73,7 +73,7 @@ template getTimestamp*(c: Computation): uint64 =
template getBlockNumber*(c: Computation): UInt256 =
when evmc_enabled:
c.host.getTxContext().block_number.u256
c.host.getTxContext().blockNumber.u256
else:
c.vmState.blockNumber.blockNumberToVmWord
@ -97,7 +97,7 @@ template getBaseFee*(c: Computation): UInt256 =
template getChainId*(c: Computation): uint =
when evmc_enabled:
UInt256.fromEvmc(c.host.getTxContext().chain_id).truncate(uint)
UInt256.fromEvmc(c.host.getTxContext().chainId).truncate(uint)
else:
c.vmState.com.chainId.uint

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2018-2023 Status Research & Development GmbH
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -182,16 +182,16 @@ proc afterExecCreate(c: Computation)
const
MsgKindToOp: array[CallKind, Op] = [
CALL,
DELEGATECALL,
CALLCODE,
CREATE,
CREATE2
Call,
DelegateCall,
CallCode,
Create,
Create2
]
func msgToOp(msg: Message): Op =
if EVMC_STATIC in msg.flags:
return STATICCALL
return StaticCall
MsgKindToOp[msg.kind]
proc beforeExec(c: Computation): bool

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2023 Status Research & Development GmbH
# Copyright (c) 2023-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -152,7 +152,8 @@ template getPtr(z: untyped): untyped =
proc mp_init_multi(mp: mp_int): mp_err {.mp_abi, varargs.}
# free a bignum
proc mp_clear(a: mp_int) {.mp_abi.}
when false:
proc mp_clear(a: mp_int) {.mp_abi.}
# clear multiple mp_ints, terminated with nil
proc mp_clear_multi(mp: mp_int) {.mp_abi, varargs.}

View File

@ -832,7 +832,7 @@ const txProcs = {
"maxPriorityFeePerGas": txMaxPriorityFeePerGas,
"effectiveGasPrice": txEffectiveGasPrice,
"chainID": txChainId,
"maxFeePerBlobGas": txmaxFeePerBlobGas,
"maxFeePerBlobGas": txMaxFeePerBlobGas,
"versionedHashes": txVersionedHashes,
"raw": txRaw,
"rawReceipt": txRawReceipt
@ -1113,7 +1113,7 @@ proc blockBlobGasUsed(ud: RootRef, params: Args, parent: Node): RespResult {.api
else:
ok(respNull())
proc blockexcessBlobGas(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
proc blockExcessBlobGas(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
let h = HeaderNode(parent)
if h.header.excessBlobGas.isSome:
longNode(h.header.excessBlobGas.get)

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2018-2023 Status Research & Development GmbH
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE))
# * MIT license ([LICENSE-MIT](LICENSE-MIT))
@ -300,4 +300,4 @@ proc populateReceipt*(receipt: Receipt, gasUsed: GasInt, tx: Transaction,
if tx.txType == TxEip4844:
result.blobGasUsed = some(w3Qty(tx.versionedHashes.len.uint64 * GAS_PER_BLOB.uint64))
result.blobGasPrice = some(getBlobGasprice(header.excessBlobGas.get(0'u64)))
result.blobGasPrice = some(getBlobGasPrice(header.excessBlobGas.get(0'u64)))

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2023 Status Research & Development GmbH
# Copyright (c) 2023-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).
@ -425,11 +425,11 @@ proc processNewHead*(sk: SkeletonRef, head: BlockHeader,
elif last.head >= number:
# Check if its duplicate announcement, if not trim the head and
# let the match run after this if block
let mayBeDupBlock = sk.getHeader(number).valueOr:
let maybeDupBlock = sk.getHeader(number).valueOr:
return err(error)
let maybeDupHash = mayBeDupBlock.blockHash
if mayBeDupBlock.isSome and mayBeDupHash == headHash:
let maybeDupHash = maybeDupBlock.blockHash
if maybeDupBlock.isSome and maybeDupHash == headHash:
debug "Skeleton duplicate announcement",
tail=last.tail, head=last.head, number, hash=headHash.short
return ok(false)
@ -441,7 +441,7 @@ proc processNewHead*(sk: SkeletonRef, head: BlockHeader,
tail=last.tail,
head=last.head,
number=number,
expected=mayBeDupHash.short,
expected=maybeDupHash.short,
actual=headHash.short
else:
debug "Skeleton stale announcement",

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2023 Status Research & Development GmbH
# Copyright (c) 2023-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).
@ -61,7 +61,7 @@ type
filling* : bool # Whether we are actively filling the canonical chain
started* : Time # Timestamp when the skeleton syncer was created
logged* : Time # Timestamp when progress was last logged to user
db* : CoreDBRef
db* : CoreDbRef
chain* : ChainRef
conf* : SkeletonConfig
fillLogIndex*: uint64

View File

@ -1,5 +1,5 @@
# nimbus-eth1
# Copyright (c) 2021 Status Research & Development GmbH
# Copyright (c) 2021-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -71,7 +71,7 @@ proc complete(
of Extension:
let newKey = node.eLink
if not newkey.isZeroLink:
if not newKey.isZeroLink:
let newNode = newKey.getNode(db)
if newNode.isOK:
uPath.path.add typeof(path.path[0])(key: key, node: node, nibble: -1)

View File

@ -1,5 +1,5 @@
# nimbus-eth1
# Copyright (c) 2021 Status Research & Development GmbH
# Copyright (c) 2021-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -90,7 +90,7 @@ proc getNode*(
return ok(nodeRlp.toBranchNode)
of 2:
let (isLeaf,pfx) = hexPrefixDecode nodeRlp.listElem(0).toBytes
if isleaf:
if isLeaf:
return ok(nodeRlp.toLeafNode pfx)
else:
return ok(nodeRlp.toExtensionNode pfx)
@ -138,7 +138,7 @@ proc padPartialPath*(pfx: NibblesSeq; dblNibble: byte): NodeKey =
let padLen = 64 - pfx.len
if 0 <= padLen:
padded = pfx & dblNibble.repeat(padlen div 2).initNibbleRange
padded = pfx & dblNibble.repeat(padLen div 2).initNibbleRange
if (padLen and 1) == 1:
padded = padded & @[dblNibble].initNibbleRange.slice(1)
else:

View File

@ -86,7 +86,7 @@ proc toAccountsKey(a: RepairKey): auto =
proc toStorageSlotsKey(a: RepairKey): auto =
a.convertTo(NodeKey).toStorageSlotsKey
proc stateRootGet*(db: CoreDbRef; nodeKey: Nodekey): Blob =
proc stateRootGet*(db: CoreDbRef; nodeKey: NodeKey): Blob =
if db.isLegacy:
return db.kvt.backend.toLegacy.get(nodeKey.toStateRootKey.toOpenArray)
@ -196,7 +196,7 @@ proc persistentContractPut*(
defer: dbTx.commit
for (key,val) in data:
base.kvt.put(key.toContracthashKey.toOpenArray,val)
base.kvt.put(key.toContractHashKey.toOpenArray,val)
ok()
@ -378,7 +378,7 @@ proc persistentContractPut*(
let
nodeKey = nodeTag.to(NodeKey)
data = lookup[nodeKey]
if not bulker.add(nodeKey.toContracthashKey.toOpenArray, data):
if not bulker.add(nodeKey.toContractHashKey.toOpenArray, data):
let error = AddBulkItemFailed
when extraTraceMessages:
trace logTxt "rocksdb bulk load failure",

View File

@ -1,5 +1,5 @@
# Nimbus
# Copyright (c) 2018-2021 Status Research & Development GmbH
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Licensed and distributed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
# http://www.apache.org/licenses/LICENSE-2.0)
@ -83,7 +83,7 @@ proc processReplyStep(
maxLen = min(nSlotPaths, nodeBlobs.len - startInx)
# Fill up nodes
for n in 0 ..< maxlen:
for n in 0 ..< maxLen:
let nodeBlob = nodeBlobs[startInx + n]
if 0 < nodeBlob.len:
result.nodes.add NodeSpecs(

View File

@ -1,6 +1,6 @@
# Nimbus - Common entry point to the EVM from all different callers
#
# Copyright (c) 2018-2023 Status Research & Development GmbH
# Copyright (c) 2018-2024 Status Research & Development GmbH
# Licensed under either of
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
@ -134,7 +134,7 @@ proc setupHost(call: CallParams): TransactionHost =
origin : call.origin.get(call.sender),
gasPrice : call.gasPrice,
versionedHashes: call.versionedHashes,
blobBaseFee : getBlobGasprice(vmState.blockCtx.excessBlobGas),
blobBaseFee : getBlobGasPrice(vmState.blockCtx.excessBlobGas),
),
forkOverride = call.forkOverride
)