Skip to content

Commit

Permalink
bump submodules
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Jun 7, 2023
1 parent 11bb33d commit 67aaf92
Show file tree
Hide file tree
Showing 38 changed files with 115 additions and 93 deletions.
5 changes: 5 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,8 @@
url = https://github.com/libtom/libtommath
ignore = untracked
branch = develop
[submodule "vendor/nim-kzg4844"]
path = vendor/nim-kzg4844
url = https://github.com/status-im/nim-kzg4844
ignore = untracked
branch = master
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ EXCLUDED_NIM_PACKAGES := \
vendor/nimbus-eth2/vendor/nim-libp2p \
vendor/nimbus-eth2/vendor/nim-presto \
vendor/nimbus-eth2/vendor/nim-zxcvbn \
vendor/nimbus-eth2/vendor/nim-kzg4844 \
vendor/nimbus-eth2/vendor/nimbus-security-resources

# we don't want an error here, so we can handle things later, in the ".DEFAULT" target
Expand Down
4 changes: 4 additions & 0 deletions config.nims
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,7 @@ if defined(windows) and defined(i386):
# avoid undefined reference to 'sqrx_mont_384x' when compiling in 32 bit mode
# without actually using __BLST_PORTABLE__ or __BLST_NO_ASM__
switch("define", "BLS_FORCE_BACKEND:miracl")

# nim-kzg shipping their own blst, nimbus-eth1 too.
# disable nim-kzg's blst
switch("define", "kzgExternalBlst")
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ proc loadNetworkData*(
try:
template genesisData(): auto = metadata.genesisData
newClone(readSszForkedHashedBeaconState(
metadata.cfg, genesisData.toOpenArrayByte(genesisData.low, genesisData.high)))
metadata.cfg, genesisData.toOpenArray(genesisData.low, genesisData.high)))
except CatchableError as err:
raiseAssert "Invalid baked-in state: " & err.msg

Expand Down
2 changes: 1 addition & 1 deletion fluffy/network/history/history_network.nim
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func encode*(receipts: seq[Receipt]): seq[byte] =
# TODO: Failures on validation and perhaps deserialisation should be punished
# for if/when peer scoring/banning is added.

proc calcRootHash(items: Transactions | PortalReceipts| Withdrawals): Hash256 =
proc calcRootHash(items: Transactions | PortalReceipts | Withdrawals): Hash256 =
var tr = initHexaryTrie(newMemoryDB())
for i, item in items:
try:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ procSuite "Portal Beacon Light Client":
try:
template genesisData(): auto = metadata.genesisData
newClone(readSszForkedHashedBeaconState(
metadata.cfg, genesisData.toOpenArrayByte(genesisData.low, genesisData.high)))
metadata.cfg, genesisData.toOpenArray(genesisData.low, genesisData.high)))
except CatchableError as err:
raiseAssert "Invalid baked-in state: " & err.msg

Expand Down
10 changes: 6 additions & 4 deletions fluffy/tools/bridge/beacon_chain_bridge.nim
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import
# for `BlockHeader`.
eth/common/eth_types as etypes,
eth/common/eth_types_rlp,
beacon_chain/eth1/eth1_monitor,
beacon_chain/el/el_manager,
beacon_chain/gossip_processing/optimistic_processor,
beacon_chain/networking/topic_params,
beacon_chain/spec/beaconstate,
Expand Down Expand Up @@ -247,7 +247,8 @@ proc asPortalBlockData*(
nonce: default(BlockNonce),
fee: some(payload.baseFeePerGas),
withdrawalsRoot: withdrawalsRoot,
excessDataGas: options.none(UInt256)
dataGasUsed: options.none(uint64),
excessDataGas: options.none(uint64)
)

headerWithProof = BlockHeaderWithProof(
Expand Down Expand Up @@ -291,7 +292,8 @@ proc asPortalBlockData*(
nonce: default(BlockNonce),
fee: some(payload.baseFeePerGas),
withdrawalsRoot: withdrawalsRoot,
excessDataGas: options.none(UInt256) # TODO: adjust later according to deneb fork
dataGasUsed: options.none(uint64),
excessDataGas: options.none(uint64) # TODO: adjust later according to deneb fork
)

headerWithProof = BlockHeaderWithProof(
Expand Down Expand Up @@ -401,7 +403,7 @@ proc run(config: BeaconBridgeConf) {.raises: [CatchableError].} =
try:
template genesisData(): auto = metadata.genesisData
newClone(readSszForkedHashedBeaconState(
cfg, genesisData.toOpenArrayByte(genesisData.low, genesisData.high)))
cfg, genesisData.toOpenArray(genesisData.low, genesisData.high)))
except CatchableError as err:
raiseAssert "Invalid baked-in state: " & err.msg

Expand Down
3 changes: 1 addition & 2 deletions fluffy/tools/bridge/beacon_chain_bridge_conf.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import
std/os,
json_serialization/std/net,
beacon_chain/light_client,
beacon_chain/conf,
json_rpc/rpcproxy
beacon_chain/conf

export net, conf

Expand Down
48 changes: 33 additions & 15 deletions nimbus/common/chain_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ proc fromHex(c: char): int =
else: -1

proc readValue(reader: var JsonReader, value: var UInt256)
{.gcsafe, raises: [CatchableError].} =
{.gcsafe, raises: [SerializationError, IOError].} =
## Mixin for `Json.loadFile()`. Note that this driver applies the same
## to `BlockNumber` fields as well as generic `UInt265` fields like the
## account `balance`.
Expand Down Expand Up @@ -148,36 +148,54 @@ proc readValue(reader: var JsonReader, value: var UInt256)
reader.lexer.next()

proc readValue(reader: var JsonReader, value: var ChainId)
{.gcsafe, raises: [CatchableError].} =
{.gcsafe, raises: [SerializationError, IOError].} =
value = reader.readValue(int).ChainId

proc readValue(reader: var JsonReader, value: var Hash256)
{.gcsafe, raises: [CatchableError].} =
{.gcsafe, raises: [SerializationError, IOError].} =
value = Hash256.fromHex(reader.readValue(string))

proc readValue(reader: var JsonReader, value: var BlockNonce)
{.gcsafe, raises: [CatchableError].} =
value = fromHex[uint64](reader.readValue(string)).toBlockNonce
{.gcsafe, raises: [SerializationError, IOError].} =
try:
value = fromHex[uint64](reader.readValue(string)).toBlockNonce
except ValueError as ex:
reader.raiseUnexpectedValue(ex.msg)

proc readValue(reader: var JsonReader, value: var EthTime)
{.gcsafe, raises: [CatchableError].} =
value = fromHex[int64](reader.readValue(string)).fromUnix
{.gcsafe, raises: [SerializationError, IOError].} =
try:
value = fromHex[int64](reader.readValue(string)).fromUnix
except ValueError as ex:
reader.raiseUnexpectedValue(ex.msg)

proc readValue(reader: var JsonReader, value: var seq[byte])
{.gcsafe, raises: [CatchableError].} =
value = hexToSeqByte(reader.readValue(string))
{.gcsafe, raises: [SerializationError, IOError].} =
try:
value = hexToSeqByte(reader.readValue(string))
except ValueError as ex:
reader.raiseUnexpectedValue(ex.msg)

proc readValue(reader: var JsonReader, value: var GasInt)
{.gcsafe, raises: [CatchableError].} =
value = fromHex[GasInt](reader.readValue(string))
{.gcsafe, raises: [SerializationError, IOError].} =
try:
value = fromHex[GasInt](reader.readValue(string))
except ValueError as ex:
reader.raiseUnexpectedValue(ex.msg)

proc readValue(reader: var JsonReader, value: var EthAddress)
{.gcsafe, raises: [CatchableError].} =
value = parseAddress(reader.readValue(string))
{.gcsafe, raises: [SerializationError, IOError].} =
try:
value = parseAddress(reader.readValue(string))
except ValueError as ex:
reader.raiseUnexpectedValue(ex.msg)

proc readValue(reader: var JsonReader, value: var AccountNonce)
{.gcsafe, raises: [CatchableError].} =
value = fromHex[uint64](reader.readValue(string))
{.gcsafe, raises: [SerializationError, IOError].} =
try:
value = fromHex[uint64](reader.readValue(string))
except ValueError as ex:
reader.raiseUnexpectedValue(ex.msg)

template to(a: string, b: type EthAddress): EthAddress =
# json_serialization decode table stuff
Expand Down
2 changes: 1 addition & 1 deletion nimbus/config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ type
defaultValue: defaultAdminListenAddress
defaultValueDesc: $defaultAdminListenAddressDesc
name: "metrics-address" }: ValidIpAddress

statelessModeDataSourceUrl* {.
desc: "URL of the node to use as a data source for on-demand data fetching via the JSON-RPC API"
defaultValue: ""
Expand Down
2 changes: 1 addition & 1 deletion nimbus/core/casper.nim
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ proc prepare*(ctx: CasperRef, header: var BlockHeader) =
header.prevRandao = ctx.prevRandao
header.difficulty = DifficultyInt.zero

proc prepareForSeal*(ctx: CasperRef, header: var BlockHeader) {.gcsafe, raises:[RlpError].} =
proc prepareForSeal*(ctx: CasperRef, header: var BlockHeader) {.gcsafe, raises:[].} =
header.nonce = default(BlockNonce)
header.extraData = @[] # TODO: probably this should be configurable by user?
# this repetition, assigning prevRandao is because how txpool works
Expand Down
3 changes: 1 addition & 2 deletions nimbus/core/tx_pool.nim
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,7 @@ import
chronicles,
eth/keys,
stew/[keyed_queue, results],
../common/common,
./casper
../common/common

export
TxItemRef,
Expand Down
2 changes: 1 addition & 1 deletion nimbus/core/tx_pool/tx_chain.nim
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ proc prepareHeader(dh: TxChainRef; parent: BlockHeader, timestamp: EthTime)
of ConsensusType.POS:
dh.com.pos.prepare(dh.prepHeader)

proc prepareForSeal(dh: TxChainRef; header: var BlockHeader) {.gcsafe, raises: [RlpError].} =
proc prepareForSeal(dh: TxChainRef; header: var BlockHeader) {.gcsafe, raises: [].} =
case dh.com.consensus
of ConsensusType.POW:
# do nothing, tx pool was designed with POW in mind
Expand Down
4 changes: 2 additions & 2 deletions nimbus/db/incomplete_db.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The points of these two files are:

import
chronicles,
eth/[common, rlp],
eth/[common],
eth/trie/[hexary, db, trie_defs],
storage_types,
./values_from_bytes,
Expand Down Expand Up @@ -41,7 +41,7 @@ proc populateDbWithBranch*(db: TrieDatabaseRef, branch: seq[seq[byte]]) =
for nodeBytes in branch:
let nodeHash = keccakHash(nodeBytes)
db.put(nodeHash.data, nodeBytes)

# Returns a none if there are missing nodes; if the account itself simply
# doesn't exist yet, that's fine and it returns some(newAccount()).
proc ifNodesExistGetAccount*(trie: AccountsTrie, address: EthAddress): Option[Account] =
Expand Down
17 changes: 12 additions & 5 deletions nimbus/evm/async/data_sources/json_rpc_data_source.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ when defined(legacy_eth66_enabled):

from ../../../rpc/rpc_utils import toHash
from web3 import Web3, BlockHash, BlockObject, FixedBytes, Address, ProofResponse, StorageProof, newWeb3, fromJson, fromHex, eth_getBlockByHash, eth_getBlockByNumber, eth_getCode, eth_getProof, blockId, `%`
from web3/ethtypes import Quantity
#from ../../../premix/downloader import request
#from ../../../premix/parser import prefixHex, parseBlockHeader, parseReceipt, parseTransaction

Expand All @@ -32,7 +33,6 @@ from eth/common import BlockHeader
# Trying to do things the new web3 way:
from ../../../nimbus_verified_proxy/validate_proof import getAccountFromProof


export AsyncOperationFactory, AsyncDataSource


Expand Down Expand Up @@ -84,6 +84,12 @@ proc makeAnRpcClient*(web3Url: string): Future[RpcClient] {.async.} =
excessDataGas*: Option[UInt256] # EIP-4844
]#

func fromQty(x: Option[Quantity]): Option[uint64] =
if x.isSome:
some(x.get().uint64)
else:
none(uint64)

func blockHeaderFromBlockObject(o: BlockObject): BlockHeader =
let nonce: BlockNonce = if o.nonce.isSome: distinctBase(o.nonce.get) else: default(BlockNonce)
BlockHeader(
Expand All @@ -104,7 +110,8 @@ func blockHeaderFromBlockObject(o: BlockObject): BlockHeader =
nonce: nonce,
fee: o.baseFeePerGas,
withdrawalsRoot: o.withdrawalsRoot.map(toHash),
excessDataGas: o.excessDataGas
dataGasUsed: fromQty(o.dataGasUsed),
excessDataGas: fromQty(o.excessDataGas)
)

proc fetchBlockHeaderWithHash*(rpcClient: RpcClient, h: Hash256): Future[BlockHeader] {.async.} =
Expand Down Expand Up @@ -287,8 +294,8 @@ proc fetchCode(client: RpcClient, p: CodeFetchingInfo): Future[seq[byte]] {.asyn

proc verifyFetchedCode(fetchedCode: seq[byte], desiredCodeHash: Hash256): Result[void, Hash256] =
let fetchedCodeHash = keccakHash(fetchedCode)
if (desiredCodeHash == fetchedCodeHash):
ok[void]()
if desiredCodeHash == fetchedCodeHash:
ok()
else:
err(fetchedCodeHash)

Expand Down Expand Up @@ -371,7 +378,7 @@ proc verifyFetchedBlockHeader(fetchedHeader: BlockHeader, desiredBlockNumber: Bl
# *Can* we do anything to verify this header, given that all we know
# is the desiredBlockNumber and we want to run statelessly so we don't
# know what block hash we want?
ok[void]()
ok()

proc storeBlockHeader(chainDB: ChainDBRef, header: BlockHeader) =
chainDB.persistHeaderToDbWithoutSetHeadOrScore(header)
Expand Down
5 changes: 2 additions & 3 deletions nimbus/evm/memory.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
# at your option. This file may not be copied, modified, or distributed except according to those terms.

import
sequtils,
chronicles, eth/common/eth_types,
../errors, ./validation,
./validation,
./interpreter/utils/utils_numeric

type
Expand Down Expand Up @@ -50,6 +49,6 @@ proc write*(memory: var Memory, startPos: Natural, value: openArray[byte]) =
let size = value.len
if size == 0:
return
validateLte(startPos + size, memory.len)
validateLte(startPos + size, memory.len)
for z, b in value:
memory.bytes[z + startPos] = b
18 changes: 5 additions & 13 deletions nimbus/graphql/ethapi.nim
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,6 @@ proc getTxCount(ctx: GraphqlContextRef, txRoot: Hash256): RespResult =
ok(resp(getTransactionCount(ctx.chainDB, txRoot)))
except CatchableError as e:
err("can't get txcount: " & e.msg)
except Exception as em:
err("can't get txcount: " & em.msg)

proc longNode(val: uint64 | int64): RespResult =
ok(Node(kind: nkInt, intVal: $val, pos: Pos()))
Expand Down Expand Up @@ -228,8 +226,6 @@ proc getOmmerCount(ctx: GraphqlContextRef, ommersHash: Hash256): RespResult =
ok(resp(getUnclesCount(ctx.chainDB, ommersHash)))
except CatchableError as e:
err("can't get ommers count: " & e.msg)
except Exception as em:
err("can't get ommers count: " & em.msg)

proc getOmmers(ctx: GraphqlContextRef, ommersHash: Hash256): RespResult =
try:
Expand Down Expand Up @@ -281,8 +277,6 @@ proc getTxs(ctx: GraphqlContextRef, header: BlockHeader): RespResult =
ok(list)
except CatchableError as e:
err("can't get transactions: " & e.msg)
except Exception as em:
err("can't get transactions: " & em.msg)

proc getTxAt(ctx: GraphqlContextRef, header: BlockHeader, index: int): RespResult =
try:
Expand Down Expand Up @@ -315,8 +309,6 @@ proc getTxByHash(ctx: GraphqlContextRef, hash: Hash256): RespResult =
getTxAt(ctx, header, index)
except CatchableError as e:
err("can't get transaction by hash '$1': $2" % [hash.data.toHex, e.msg])
except Exception as em:
err("can't get transaction by hash '$1': $2" % [hash.data.toHex, em.msg])

proc accountNode(ctx: GraphqlContextRef, header: BlockHeader, address: EthAddress): RespResult =
try:
Expand Down Expand Up @@ -999,7 +991,7 @@ proc blockCall(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.
try:
let callData = toCallData(param)
ctx.makeCall(callData, h.header)
except Exception as em:
except CatchableError as em:
err("call error: " & em.msg)

proc blockEstimateGas(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
Expand All @@ -1011,7 +1003,7 @@ proc blockEstimateGas(ud: RootRef, params: Args, parent: Node): RespResult {.api
# TODO: DEFAULT_RPC_GAS_CAP should configurable
let gasUsed = rpcEstimateGas(callData, h.header, ctx.com, DEFAULT_RPC_GAS_CAP)
longNode(gasUsed)
except Exception as em:
except CatchableError as em:
err("estimateGas error: " & em.msg)

proc blockBaseFeePerGas(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
Expand Down Expand Up @@ -1214,7 +1206,7 @@ proc queryGasPrice(ud: RootRef, params: Args, parent: Node): RespResult {.apiPra
let ctx = GraphqlContextRef(ud)
try:
bigIntNode(calculateMedianGasPrice(ctx.chainDB))
except Exception as em:
except CatchableError as em:
err("can't get gasPrice: " & em.msg)

proc queryProtocolVersion(ud: RootRef, params: Args, parent: Node): RespResult {.apiPragma.} =
Expand Down Expand Up @@ -1260,8 +1252,8 @@ proc sendRawTransaction(ud: RootRef, params: Args, parent: Node): RespResult {.a
let _ = decodeTx(data) # we want to know if it is a valid tx blob
let txHash = keccakHash(data)
resp(txHash)
except Exception as em:
return err("failed to process raw transaction")
except CatchableError as em:
return err("failed to process raw transaction: " & em.msg)

const mutationProcs = {
"sendRawTransaction": sendRawTransaction
Expand Down
2 changes: 1 addition & 1 deletion nimbus/nimbus.nim
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ proc setupP2P(nimbus: NimbusNode, conf: NimbusConf,
block:
let
exCtrlFile = if conf.syncCtrlFile.isNone: none(string)
else: some(conf.syncCtrlFile.get.string)
else: some(conf.syncCtrlFile.get)
tickerOK = conf.logLevel in {
LogLevel.INFO, LogLevel.DEBUG, LogLevel.TRACE}
case conf.syncMode:
Expand Down
Loading

0 comments on commit 67aaf92

Please sign in to comment.