Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address #5377 part(1/2) #5418

Merged
merged 1 commit into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions beacon_chain/spec/eth2_apis/eth2_rest_serialization.nim
Original file line number Diff line number Diff line change
Expand Up @@ -940,6 +940,9 @@ template unrecognizedFieldWarning =
trace "JSON field not recognized by the current version of Nimbus. Consider upgrading",
fieldName, typeName = typetraits.name(typeof value)

template unrecognizedFieldIgnore =
discard readValue(reader, JsonString)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a debug log should be added here


## ForkedBeaconBlock
template prepareForkedBlockReading(
reader: var JsonReader[RestJson],
Expand Down Expand Up @@ -2767,7 +2770,7 @@ proc readValue*(reader: var JsonReader[RestJson],
"Multiple `active` fields found", "RestActivityItem")
active = some(reader.readValue(bool))
else:
discard
unrecognizedFieldIgnore()

if index.isNone():
reader.raiseUnexpectedValue("Missing or empty `index` value")
Expand Down Expand Up @@ -2807,7 +2810,7 @@ proc readValue*(reader: var JsonReader[RestJson],
"Multiple `is_live` fields found", "RestLivenessItem")
isLive = some(reader.readValue(bool))
else:
discard
unrecognizedFieldIgnore()

if index.isNone():
reader.raiseUnexpectedValue("Missing or empty `index` value")
Expand Down Expand Up @@ -2935,8 +2938,7 @@ proc readValue*(reader: var JsonReader[RestJson],
"RestErrorMessage")
stacktraces = some(reader.readValue(seq[string]))
else:
# We ignore all additional fields.
discard reader.readValue(JsonString)
unrecognizedFieldIgnore()

if code.isNone():
reader.raiseUnexpectedValue("Missing or invalid `code` value")
Expand Down
12 changes: 12 additions & 0 deletions tests/test_validator_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,15 @@ suite "Validator Client test suite":
check:
res.isOk()
res.get().data == expect

let vector = stringToBytes(
"{\"data\":[{\"index\":\"100000\",\"epoch\":\"202919\",\"is_live\":true}]}")

let contentType = getContentType("application/json").tryGet()
let res = decodeBytes(
GetValidatorsLivenessResponse, vector, Opt.some(contentType))
check:
res.isOk()
len(res.get().data) == 1
res.get().data[0].index == 100000
res.get().data[0].is_live == true