Merge pull request #420 from status-im/reduce_warnings

reduce compiler warnings
This commit is contained in:
andri lim 2019-11-14 16:34:20 +07:00 committed by GitHub
commit a3efd54d90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
38 changed files with 81 additions and 86 deletions

View File

@ -6,8 +6,7 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
eth/common,
./constants
eth/common
type
Block* = ref object of RootObj

View File

@ -1,5 +1,5 @@
import
math, strutils, eth/common, nimcrypto/hash
eth/common, nimcrypto/hash
proc default(t: typedesc): t = discard

View File

@ -6,7 +6,6 @@ type
PersistDel
DB = TrieDatabaseRef
BytesRange = Range[byte]
CaptureDB* = ref object of RootObj
srcDb: DB

View File

@ -6,8 +6,8 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
tables, sequtils, algorithm,
stew/[byteutils, ranges], state_db, eth/trie/[hexary, db],
sequtils, algorithm,
stew/[byteutils, ranges], eth/trie/[hexary, db],
eth/[common, rlp], chronicles,
../errors, ../constants, ./storage_types,
../utils, ../config

View File

@ -6,10 +6,9 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
sequtils, strformat, tables,
strformat,
chronicles, eth/[common, rlp], eth/trie/[hexary, db],
../constants, ../errors, ../validation, ../utils,
storage_types
../constants, ../utils, storage_types
logScope:
topics = "state_db"

View File

@ -1,6 +1,6 @@
import
times, tables,
eth/[common, rlp, trie], stint, stew/[byteutils, ranges], block_types, nimcrypto,
tables,
eth/[common, rlp, trie], stint, stew/[byteutils, ranges],
chronicles, eth/trie/db,
db/[db_chain, state_db], genesis_alloc, config, constants

View File

@ -1,6 +1,6 @@
import ../db/[db_chain, state_db], eth/common, chronicles, ../vm_state, ../vm_types, ../transaction, stew/ranges,
../vm/[computation, message], ../constants, stint, nimcrypto,
../vm_state_transactions, sugar, ../utils, eth/trie/db, ../tracer, ./executor
import ../db/db_chain, eth/common, chronicles, ../vm_state, ../vm_types, stew/ranges,
../vm/[computation, message], stint, nimcrypto,
../utils, eth/trie/db, ../tracer, ./executor
type
Chain* = ref object of AbstractChainDB

View File

@ -304,11 +304,11 @@ proc fromJson*(n: JsonNode, argName: string, result: var Bytes) =
let hexStr = n.getStr()
if not hexStr.isValidHexData:
raise newException(ValueError, invalidMsg(argName) & " as a hex data \"" & hexStr & "\"")
result = hexToSeqByte(hexStr.string)
result = hexToSeqByte(hexStr)
proc fromJson*(n: JsonNode, argName: string, result: var Hash256) =
n.kind.expect(JString, argName)
let hexStr = n.getStr()
if not hexStr.isValidHash256:
raise newException(ValueError, invalidMsg(argName) & " as a Hash256 \"" & hexStr & "\"")
hexToByteArray(hexStr.string, result.data)
hexToByteArray(hexStr, result.data)

View File

@ -6,7 +6,7 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
constants, errors, eth/[common, rlp, keys], nimcrypto, utils,
constants, errors, eth/[common, rlp, keys], utils,
./vm/interpreter/[vm_forks, gas_costs], constants
import eth/common/transaction as common_transaction

View File

@ -1,6 +1,7 @@
import times
import eth/common, stint
import ../constants, ../vm/interpreter/vm_forks
import
times,
eth/common, stint,
../constants, ../vm/interpreter/vm_forks
const
ExpDiffPeriod = 100000.u256

View File

@ -9,7 +9,7 @@
import
strformat, times, options,
eth/[common, rlp],
../validation, ./difficulty, ../vm/interpreter/vm_forks, ../constants
./difficulty, ../vm/interpreter/vm_forks, ../constants
export BlockHeader

View File

@ -7,7 +7,7 @@
import
strformat,
errors, constants, eth/common
errors, eth/common
proc validateGte*(value: Int256 | int, minimum: int, title: string = "Value") =
if value.i256 < minimum.i256:

View File

@ -8,7 +8,7 @@
import
chronicles, strformat, strutils, sequtils, parseutils, sets, macros,
eth/common,
../constants, ./interpreter/opcode_values
./interpreter/opcode_values
logScope:
topics = "vm code_stream"
@ -28,7 +28,7 @@ proc newCodeStream*(codeBytes: seq[byte]): CodeStream =
new(result)
result.bytes = codeBytes
result.pc = 0
result.invalidPositions = initSet[int]()
result.invalidPositions = initHashSet[int]()
result.depthProcessed = 0
result.cached = @[]

View File

@ -6,9 +6,9 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
chronicles, strformat, strutils, sequtils, macros, terminal, math, tables, options,
chronicles, strformat, strutils, sequtils, macros, math, tables, options,
sets, eth/[common, keys], eth/trie/db as triedb,
../constants, ../errors, ../validation, ../vm_state, ../vm_types,
../constants, ../errors, ../vm_state, ../vm_types,
./interpreter/[opcode_values, gas_meter, gas_costs, vm_forks],
./code_stream, ./memory, ./message, ./stack, ../db/[state_db, db_chain],
../utils/header, stew/[byteutils, ranges], precompiles,
@ -254,7 +254,7 @@ proc addLogEntry*(c: BaseComputation, log: Log) {.inline.} =
# in order to test some existing code
iterator accountsForDeletion*(c: BaseComputation): EthAddress =
var stack = @[c]
var deletedAccounts = initSet[EthAddress]()
var deletedAccounts = initHashSet[EthAddress]()
while stack.len > 0:
let comp = stack.pop()
if comp.isError: continue

View File

@ -158,15 +158,16 @@ template gasCosts(fork: Fork, prefix, ResultGasCostsName: untyped) =
# TODO: add logging
result = max(newCost - prevCost, 0)
func `prefix all_but_one_64th`(gas: GasInt): GasInt {.inline.} =
## Computes all but 1/64th
## L(n) ≡ n ⌊n/64⌋ - (floored(n/64))
# Introduced in EIP-150 - https://github.com/ethereum/EIPs/blob/master/EIPS/eip-150.md
when fork >= FkTangerine:
func `prefix all_but_one_64th`(gas: GasInt): GasInt {.inline.} =
## Computes all but 1/64th
## L(n) ≡ n ⌊n/64⌋ - (floored(n/64))
# Introduced in EIP-150 - https://github.com/ethereum/EIPs/blob/master/EIPS/eip-150.md
# Note: The all-but-one-64th calculation should occur after the memory expansion fee is taken
# https://github.com/ethereum/yellowpaper/pull/442
# Note: The all-but-one-64th calculation should occur after the memory expansion fee is taken
# https://github.com/ethereum/yellowpaper/pull/442
result = gas - (gas shr 6)
result = gas - (gas shr 6)
# ############### Opcode gas functions ##############################

View File

@ -118,7 +118,7 @@ op signExtend, inline = false, bits, value:
if bits <= 31.u256:
let
one = 1.u256
testBit = bits.toInt * 8 + 7
testBit = bits.truncate(int) * 8 + 7
bitPos = one shl testBit
mask = bitPos - one
if not isZero(value and bitPos):
@ -176,7 +176,7 @@ op notOp, inline = true, value:
op byteOp, inline = true, position, value:
## 0x20, Retrieve single byte from word.
let pos = position.toInt
let pos = position.truncate(int)
push:
if pos >= 32 or pos < 0: zero(Uint256)
@ -453,7 +453,7 @@ proc jumpImpl(computation: BaseComputation, jumpTarget: UInt256) =
if jumpTarget >= computation.code.len.u256:
raise newException(InvalidJumpDestination, "Invalid Jump Destination")
let jt = jumpTarget.toInt
let jt = jumpTarget.truncate(int)
computation.code.pc = jt
let nextOpcode = computation.code.peek

View File

@ -11,7 +11,7 @@
import
macros, strformat, stint, eth/common,
../../computation, ../../stack, ../../code_stream,
../../../constants, ../../../vm_types, ../../memory,
../../../vm_types, ../../memory,
../../../errors, ../../message, ../../interpreter/[gas_meter, opcode_values],
../../interpreter/utils/utils_numeric
@ -43,7 +43,7 @@ macro op*(procname: untyped, inline: static[bool], stackParams_body: varargs[unt
if len != 0:
for params in stackParams:
popStackStmt.add newIdentNode(params.ident)
popStackStmt.add newIdentNode(params.strVal)
popStackStmt.add newEmptyNode()
popStackStmt.add quote do:

View File

@ -6,7 +6,7 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
strformat, strutils, sequtils, endians, macros,
macros,
eth/common/eth_types, eth/rlp,
../../../constants
@ -57,7 +57,7 @@ func cleanMemRef*(x: UInt256): int {.inline.} =
const upperBound = (high(int32) shr 2).u256
if x > upperBound:
return high(int32) shr 2
return x.toInt
return x.truncate(int)
proc rangeToPadded*[T: StUint](x: openarray[byte], first, last: int, toLen = 0): T =
## Convert take a slice of a sequence of bytes interpret it as the big endian

View File

@ -8,7 +8,7 @@
import
sequtils,
chronicles, eth/common/eth_types,
../constants, ../errors, ../validation,
../errors, ../validation,
./interpreter/utils/utils_numeric
logScope:
@ -25,7 +25,6 @@ proc newMemory*: Memory =
proc len*(memory: Memory): int =
result = memory.bytes.len
proc extend*(memory: var Memory; startPos: Natural; size: Natural) =
if size == 0:
return
@ -50,7 +49,6 @@ proc write*(memory: var Memory, startPos: Natural, value: openarray[byte]) =
#echo size
#echo startPos
validateLte(startPos + size, memory.len)
let index = memory.len
if memory.len < startPos + size:
memory.bytes = memory.bytes.concat(repeat(0.byte, memory.len - (startPos + size))) # TODO: better logarithmic scaling?

View File

@ -7,7 +7,7 @@
import
chronicles, strformat, strutils, sequtils, macros, eth/[rlp, common], nimcrypto,
../errors, ../validation, ./interpreter/utils/utils_numeric, ../constants
../errors, ../validation
logScope:
topics = "vm stack"

View File

@ -1,7 +1,7 @@
import
json, strutils, sets, hashes,
chronicles, nimcrypto, eth/common, stint,
../vm_types, memory, stack, ../db/[db_chain, state_db],
../vm_types, memory, stack, ../db/state_db,
eth/trie/hexary, ./message, stew/ranges/typedranges,
./interpreter/opcode_values
@ -21,7 +21,7 @@ proc initTracer*(tracer: var TransactionTracer, flags: set[TracerFlags] = {}) =
tracer.trace["structLogs"] = newJArray()
tracer.flags = flags
tracer.accounts = initSet[EthAddress]()
tracer.accounts = initHashSet[EthAddress]()
tracer.storageKeys = @[]
proc prepare*(tracer: var TransactionTracer, compDepth: int) =
@ -32,9 +32,9 @@ proc prepare*(tracer: var TransactionTracer, compDepth: int) =
let prevLen = tracer.storageKeys.len
tracer.storageKeys.setLen(compDepth + 1)
for i in prevLen ..< tracer.storageKeys.len - 1:
tracer.storageKeys[i] = initSet[Uint256]()
tracer.storageKeys[i] = initHashSet[Uint256]()
tracer.storageKeys[compDepth] = initSet[Uint256]()
tracer.storageKeys[compDepth] = initHashSet[Uint256]()
proc rememberStorageKey(tracer: var TransactionTracer, compDepth: int, key: Uint256) =
tracer.storageKeys[compDepth].incl key

View File

@ -7,8 +7,8 @@
import
macros, strformat, tables, sets,
eth/common, eth/trie/db,
./constants, ./errors, ./transaction, ./db/[db_chain, state_db],
eth/common,
./constants, ./db/[db_chain, state_db],
./utils, json, vm_types, vm/transaction_tracer
proc newAccessLogs*: AccessLogs =
@ -36,7 +36,7 @@ proc init*(self: BaseVMState, prevStateRoot: Hash256, header: BlockHeader,
self.logEntries = @[]
self.blockHeader.stateRoot = prevStateRoot
self.accountDb = newAccountStateDB(chainDB.db, prevStateRoot, chainDB.pruneTrie)
self.touchedAccounts = initSet[EthAddress]()
self.touchedAccounts = initHashSet[EthAddress]()
proc newBaseVMState*(prevStateRoot: Hash256, header: BlockHeader,
chainDB: BaseChainDB, tracerFlags: set[TracerFlags] = {}): BaseVMState =

View File

@ -6,10 +6,10 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
stew/ranges/typedranges, sequtils, strformat, tables, options, sets,
eth/common, chronicles, ./db/[db_chain, state_db],
constants, errors, transaction, vm_types, vm_state, utils,
./vm/[computation, interpreter], ./vm/interpreter/gas_costs
stew/ranges/typedranges, options, sets,
eth/common, chronicles, ./db/state_db,
transaction, vm_types, vm_state,
./vm/[computation, interpreter]
proc validateTransaction*(vmState: BaseVMState, tx: Transaction, sender: EthAddress, fork: Fork): bool =
# XXX: https://github.com/status-im/nimbus/issues/35#issuecomment-391726518

View File

@ -7,7 +7,7 @@
import
tables, eth/common, eth/trie/db,
options, ./constants, json, sets,
options, json, sets,
./vm/[memory, stack, code_stream],
./vm/interpreter/[gas_costs, opcode_values, vm_forks], # TODO - will be hidden at a lower layer
./db/[db_chain, state_db]
@ -73,7 +73,7 @@ type
# continuation helpers
nextProc*: proc() {.gcsafe.}
memOutLen*: int
memOutPos*: int
memOutPos*: int
Error* = ref object
info*: string

View File

@ -6,10 +6,10 @@ import
import
options, json, os, eth/trie/[db, hexary],
../nimbus/[vm_state, tracer, vm_types, transaction, utils],
../nimbus/[vm_state, vm_types, transaction, utils],
../nimbus/db/[db_chain, state_db],
../nimbus/vm_state_transactions,
../nimbus/vm/interpreter/[vm_forks, gas_costs],
../nimbus/vm/interpreter/vm_forks,
../nimbus/vm/[message, computation, memory]
export opcode_values, byteutils
@ -246,6 +246,7 @@ proc initComputation(blockNumber: Uint256, chainDB: BaseChainDB, payload, data:
proc runVM*(blockNumber: Uint256, chainDB: BaseChainDB, boa: Assembler): bool =
var computation = initComputation(blockNumber, chainDB, boa.code, boa.data, boa.fork)
# TODO: support gas comsumption validation
let gas = computation.gasMeter.gasRemaining
execComputation(computation)
let gasUsed = gas - computation.gasMeter.gasRemaining

View File

@ -5,7 +5,7 @@
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import unittest2, strutils, sequtils,
import unittest2, sequtils,
../nimbus/vm/interpreter
proc codeStreamMain*() =

View File

@ -1,4 +1,4 @@
import unittest2, strutils, tables, ospaths, json,
import unittest2, strutils, tables, os, json,
../nimbus/utils/difficulty, stint, times,
eth/common, test_helpers, stew/byteutils

View File

@ -6,11 +6,11 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
unittest2, strformat, strutils, tables, json, ospaths, times, os,
stew/byteutils, stew/ranges/typedranges, nimcrypto, options,
unittest2, strformat, strutils, tables, json, times, os,
stew/ranges/typedranges, nimcrypto, options,
eth/[rlp, common], eth/trie/[db, trie_defs], chronicles,
./test_helpers, ../nimbus/p2p/executor, test_config,
../nimbus/[constants, errors, transaction],
../nimbus/transaction,
../nimbus/[vm_state, vm_types, vm_state_transactions, utils],
../nimbus/vm/interpreter,
../nimbus/db/[db_chain, state_db]
@ -114,9 +114,8 @@ proc testFixtureIndexes(tester: Tester, testStatusIMPL: var TestStatus) =
# perhaps the entire validateTransaction block
# should be moved into processTransaction
if tester.fork >= FkSpurious:
let recipient = tester.tx.getRecipient()
let miner = tester.header.coinbase
let touchedAccounts = [miner] # [sender, miner, recipient]
let touchedAccounts = [miner]
for account in touchedAccounts:
debug "state clearing", account
if db.accountExists(account) and db.isEmptyAccount(account):

View File

@ -6,11 +6,11 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
os, macros, json, strformat, strutils, parseutils, ospaths, tables,
os, macros, json, strformat, strutils, parseutils, os, tables,
stew/byteutils, stew/ranges/typedranges, net, eth/[common, keys, rlp, p2p], unittest2,
../nimbus/[vm_state, constants, config, transaction, utils, errors],
../nimbus/[vm_state, config, transaction, utils, errors],
../nimbus/db/[db_chain, state_db],
../nimbus/vm/interpreter/[gas_costs, vm_forks],
../nimbus/vm/interpreter/vm_forks,
../tests/test_generalstate_failing
func revmap(x: Table[Fork, string]): Table[string, Fork] =

View File

@ -8,7 +8,7 @@
import
unittest2, sequtils,
eth/common/eth_types,
../nimbus/[constants, errors, vm/memory]
../nimbus/[errors, vm/memory]
proc memory32: Memory =
result = newMemory()

View File

@ -1,7 +1,6 @@
import
macro_assembler, unittest2, macros, strutils,
stew/byteutils, eth/common, ../nimbus/db/state_db,
../nimbus/db/db_chain, stew/ranges
macro_assembler, unittest2, macros,
stew/byteutils, eth/common, stew/ranges
proc opCustomMain*() =
suite "Custom Opcodes Test":

View File

@ -1,5 +1,5 @@
import
macro_assembler, unittest2, macros, strutils,
macro_assembler, unittest2, macros,
stew/byteutils, eth/common, ../nimbus/db/state_db,
../nimbus/db/db_chain, stew/ranges

View File

@ -1,7 +1,6 @@
import
macro_assembler, unittest2, macros, strutils,
stew/byteutils, eth/common, ../nimbus/db/state_db,
../nimbus/db/db_chain, stew/ranges
macro_assembler, unittest2, macros,
stew/byteutils, eth/common, stew/ranges
proc opMiscMain*() =
suite "Misc Opcodes":

View File

@ -8,7 +8,7 @@
import
unittest2, json, os, tables, strformat, strutils,
eth/[common, rlp], stew/byteutils, eth/trie/db,
./test_helpers, ../nimbus/db/[db_chain, storage_types], ../nimbus/[tracer, vm_types],
./test_helpers, ../nimbus/db/db_chain,
../nimbus/p2p/chain
# use tracerTestGen.nim to generate additional test data

View File

@ -6,9 +6,9 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
unittest2, ../nimbus/vm/precompiles, json, stew/byteutils, test_helpers, ospaths, tables,
strformat, strutils, eth/trie/db, eth/common, ../nimbus/db/[db_chain, state_db],
../nimbus/[constants, vm_types, vm_state], ../nimbus/vm/[computation, message], macros,
unittest2, ../nimbus/vm/precompiles, json, stew/byteutils, test_helpers, os, tables,
strformat, strutils, eth/trie/db, eth/common, ../nimbus/db/db_chain,
../nimbus/[vm_types, vm_state], ../nimbus/vm/[computation, message], macros,
../nimbus/vm/blake2b_f
proc initAddress(i: byte): EthAddress = result[19] = i

View File

@ -38,7 +38,7 @@ proc stackMain*() =
test "push does not allow stack to exceed 1024":
var stack = newStack()
for z in 0 .. < 1024:
for z in 0 ..< 1024:
stack.push(z.uint)
check(stack.len == 1024)
expect(FullStack):

View File

@ -5,7 +5,7 @@
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import unittest2, strutils, eth/trie/[hexary, db],
import unittest2, eth/trie/[hexary, db],
../nimbus/db/state_db, stew/byteutils, eth/common,
stew/ranges

View File

@ -6,10 +6,10 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
unittest2, strformat, strutils, sequtils, tables, json, ospaths, times,
unittest2, strformat, strutils, tables, json, os, times,
stew/byteutils, stew/ranges/typedranges, eth/[rlp, common], eth/trie/db,
./test_helpers, ../nimbus/vm/interpreter,
../nimbus/[constants, errors, vm_state, vm_types, utils],
../nimbus/[constants, vm_state, vm_types, utils],
../nimbus/db/[db_chain, state_db]
proc testFixture(fixtures: JsonNode, testStatusIMPL: var TestStatus)