Skip to content

Commit

Permalink
Bump json-serialization to v0.2.0: Improve lexer flexibility
Browse files Browse the repository at this point in the history
  • Loading branch information
jangko committed Dec 26, 2023
1 parent 540db59 commit 5e95df6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
25 changes: 9 additions & 16 deletions nimbus/common/chain_config.nim
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ export

type
Genesis* = ref object
# for geth compatibility
config* : ChainConfig

nonce* : BlockNonce
timestamp* : EthTime
extraData* : seq[byte]
Expand Down Expand Up @@ -148,17 +145,17 @@ proc readValue(reader: var JsonReader, value: var UInt256)
## to `BlockNumber` fields as well as generic `UInt265` fields like the
## account `balance`.
var (accu, ok) = (0.u256, true)
if reader.lexer.lazyTok == tkNumeric:
let tokKind = reader.tokKind
if tokKind == JsonValueKind.Number:
try:
reader.lexer.customIntValueIt:
reader.customIntValueIt:
accu = accu * 10 + it.u256
ok = reader.lexer.lazyTok == tkExInt # non-negative wanted
except CatchableError:
ok = false
elif reader.lexer.lazyTok == tkQuoted:
elif tokKind == JsonValueKind.String:
try:
var (sLen, base) = (0, 10)
reader.lexer.customTextValueIt:
reader.customStringValueIt:
if ok:
var num = it.fromHex
if base <= num:
Expand All @@ -184,7 +181,6 @@ proc readValue(reader: var JsonReader, value: var UInt256)
if not ok:
reader.raiseUnexpectedValue("Uint256 parse error")
value = accu
reader.lexer.next()

proc readValue(reader: var JsonReader, value: var ChainId)
{.gcsafe, raises: [SerializationError, IOError].} =
Expand Down Expand Up @@ -215,18 +211,15 @@ proc readValue(reader: var JsonReader, value: var EthTime)

# but shanghaiTime and cancunTime in config is in int literal
proc readValue(reader: var JsonReader, value: var Option[EthTime])
{.gcsafe, raises: [IOError].} =
let tok = reader.lexer.lazyTok
if tok == tkNull:
{.gcsafe, raises: [IOError, JsonReaderError].} =
if reader.tokKind == JsonValueKind.Null:
reset value
reader.lexer.next()
reader.parseNull()
else:
# both readValue(GasInt/AccountNonce) will be called if
# we use readValue(int64/uint64)
let tok {.used.} = reader.lexer.tok # resove lazy token
let val = EthTime reader.lexer.absIntVal
let val = EthTime reader.parseInt(uint64)
value = some val
reader.lexer.next()

proc readValue(reader: var JsonReader, value: var seq[byte])
{.gcsafe, raises: [SerializationError, IOError].} =
Expand Down
2 changes: 1 addition & 1 deletion vendor/nim-json-serialization
2 changes: 1 addition & 1 deletion vendor/nimbus-eth2
Submodule nimbus-eth2 updated 50 files
+11 −8 beacon_chain/beacon_node.nim
+6 −4 beacon_chain/conf.nim
+1 −1 beacon_chain/conf_light_client.nim
+3 −3 beacon_chain/consensus_object_pools/README.md
+1 −1 beacon_chain/consensus_object_pools/sync_committee_msg_pool.nim
+17 −3 beacon_chain/consensus_object_pools/validator_change_pool.nim
+0 −2 beacon_chain/deposits.nim
+17 −6 beacon_chain/el/el_conf.nim
+3 −1 beacon_chain/el/el_manager.nim
+1 −1 beacon_chain/gossip_processing/README.md
+6 −4 beacon_chain/gossip_processing/eth2_processor.nim
+14 −1 beacon_chain/gossip_processing/gossip_validation.nim
+1 −1 beacon_chain/libnimbus_lc/libnimbus_lc.h
+1 −1 beacon_chain/libnimbus_lc/libnimbus_lc.nim
+2 −2 beacon_chain/networking/eth2_network.nim
+23 −14 beacon_chain/nimbus_beacon_node.nim
+4 −5 beacon_chain/rpc/rest_beacon_api.nim
+12 −0 beacon_chain/rpc/rest_event_api.nim
+14 −0 beacon_chain/rpc/rest_nimbus_api.nim
+4 −0 beacon_chain/rpc/rest_node_api.nim
+3 −3 beacon_chain/spec/beacon_time.nim
+1 −1 beacon_chain/spec/beaconstate.nim
+1 −1 beacon_chain/spec/datatypes/capella.nim
+2 −2 beacon_chain/spec/datatypes/constants.nim
+7 −9 beacon_chain/spec/datatypes/deneb.nim
+229 −31 beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim
+3 −1 beacon_chain/spec/eth2_apis/rest_types.nim
+1 −1 beacon_chain/spec/forks_light_client.nim
+2 −2 beacon_chain/spec/network.nim
+2 −2 beacon_chain/spec/signatures.nim
+2 −2 beacon_chain/spec/state_transition_block.nim
+1 −1 beacon_chain/spec/state_transition_epoch.nim
+0 −1 beacon_chain/trusted_node_sync.nim
+6 −6 beacon_chain/validator_client/duties_service.nim
+1 −7 beacon_chain/validator_client/selection_proofs.nim
+1 −4 beacon_chain/validator_client/sync_committee_service.nim
+35 −3 beacon_chain/validators/beacon_validators.nim
+2 −2 beacon_chain/validators/validator_pool.nim
+1 −1 docs/block_flow.md
+43 −5 docs/the_nimbus_book/src/eth1.md
+1 −1 docs/the_nimbus_book/src/keep-updated.md
+128 −121 ncli/ncli_testnet.nim
+1 −1 ncli/nimquery.nim
+1 −1 tests/all_tests.nim
+1 −1 tests/test_validator_change_pool.nim
+5 −0 tests/test_validator_client.nim
+1 −1 tests/testblockutil.nim
+1 −1 vendor/nim-json-serialization
+1 −1 vendor/nim-libp2p
+1 −1 vendor/nim-serialization

0 comments on commit 5e95df6

Please sign in to comment.