mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-01-11 14:54:12 +00:00
broaden SszError
catches to SerializationError
(#5081)
`nim-serialization` is tagged with `{.raises:[SerializationError].}` so it is no longer sufficient to catch `SszError` in some situations. `SszError` inherits from `SerializationError`, so broadening the caught exception types can be done now, to enable bumping `nim-serialization`. https://github.com/status-im/nimbus-eth2/pull/5043#issuecomment-1584227993 #5061 is also needed to bump `nim-serialization`.
This commit is contained in:
parent
98ab0afcc3
commit
a6f0a7a55d
@ -194,7 +194,7 @@ proc getHeader*[T: ForkyLightClientHeader](
|
|||||||
res.expect("SQL query OK")
|
res.expect("SQL query OK")
|
||||||
try:
|
try:
|
||||||
return ok SSZ.decode(header, T)
|
return ok SSZ.decode(header, T)
|
||||||
except SszError as exc:
|
except SerializationError as exc:
|
||||||
error "LC data store corrupted", store = "headers", kind = T.kind,
|
error "LC data store corrupted", store = "headers", kind = T.kind,
|
||||||
blockRoot, exc = exc.msg
|
blockRoot, exc = exc.msg
|
||||||
return Opt.none(T)
|
return Opt.none(T)
|
||||||
@ -278,7 +278,7 @@ proc getCurrentSyncCommitteeBranch*(
|
|||||||
res.expect("SQL query OK")
|
res.expect("SQL query OK")
|
||||||
try:
|
try:
|
||||||
return ok SSZ.decode(branch, altair.CurrentSyncCommitteeBranch)
|
return ok SSZ.decode(branch, altair.CurrentSyncCommitteeBranch)
|
||||||
except SszError as exc:
|
except SerializationError as exc:
|
||||||
error "LC data store corrupted", store = "currentBranches",
|
error "LC data store corrupted", store = "currentBranches",
|
||||||
slot, exc = exc.msg
|
slot, exc = exc.msg
|
||||||
return Opt.none(altair.CurrentSyncCommitteeBranch)
|
return Opt.none(altair.CurrentSyncCommitteeBranch)
|
||||||
@ -361,7 +361,7 @@ proc getSyncCommittee*(
|
|||||||
res.expect("SQL query OK")
|
res.expect("SQL query OK")
|
||||||
try:
|
try:
|
||||||
return ok SSZ.decode(branch, altair.SyncCommittee)
|
return ok SSZ.decode(branch, altair.SyncCommittee)
|
||||||
except SszError as exc:
|
except SerializationError as exc:
|
||||||
error "LC data store corrupted", store = "syncCommittees",
|
error "LC data store corrupted", store = "syncCommittees",
|
||||||
period, exc = exc.msg
|
period, exc = exc.msg
|
||||||
return Opt.none(altair.SyncCommittee)
|
return Opt.none(altair.SyncCommittee)
|
||||||
@ -511,7 +511,7 @@ proc getBestUpdate*(
|
|||||||
warn "Unsupported LC data store kind", store = "bestUpdates",
|
warn "Unsupported LC data store kind", store = "bestUpdates",
|
||||||
period, kind = update[0]
|
period, kind = update[0]
|
||||||
return default(ForkedLightClientUpdate)
|
return default(ForkedLightClientUpdate)
|
||||||
except SszError as exc:
|
except SerializationError as exc:
|
||||||
error "LC data store corrupted", store = "bestUpdates",
|
error "LC data store corrupted", store = "bestUpdates",
|
||||||
period, kind = update[0], exc = exc.msg
|
period, kind = update[0], exc = exc.msg
|
||||||
return default(ForkedLightClientUpdate)
|
return default(ForkedLightClientUpdate)
|
||||||
|
@ -159,7 +159,7 @@ proc getLatestFinalizedHeader*(
|
|||||||
warn "Unsupported LC store kind", store = "headers",
|
warn "Unsupported LC store kind", store = "headers",
|
||||||
key, kind = header[0]
|
key, kind = header[0]
|
||||||
return default(ForkedLightClientHeader)
|
return default(ForkedLightClientHeader)
|
||||||
except SszError as exc:
|
except SerializationError as exc:
|
||||||
error "LC store corrupted", store = "headers",
|
error "LC store corrupted", store = "headers",
|
||||||
key, kind = header[0], exc = exc.msg
|
key, kind = header[0], exc = exc.msg
|
||||||
return default(ForkedLightClientHeader)
|
return default(ForkedLightClientHeader)
|
||||||
@ -248,7 +248,7 @@ proc getSyncCommittee*(
|
|||||||
res.expect("SQL query OK")
|
res.expect("SQL query OK")
|
||||||
try:
|
try:
|
||||||
return ok SSZ.decode(syncCommittee, altair.SyncCommittee)
|
return ok SSZ.decode(syncCommittee, altair.SyncCommittee)
|
||||||
except SszError as exc:
|
except SerializationError as exc:
|
||||||
error "LC store corrupted", store = "syncCommittees",
|
error "LC store corrupted", store = "syncCommittees",
|
||||||
period, exc = exc.msg
|
period, exc = exc.msg
|
||||||
return Opt.none(altair.SyncCommittee)
|
return Opt.none(altair.SyncCommittee)
|
||||||
|
@ -2441,7 +2441,7 @@ proc addValidator*[MsgType](node: Eth2Node,
|
|||||||
let decoded = SSZ.decode(decompressed, MsgType)
|
let decoded = SSZ.decode(decompressed, MsgType)
|
||||||
decompressed = newSeq[byte](0) # release memory before validating
|
decompressed = newSeq[byte](0) # release memory before validating
|
||||||
msgValidator(decoded) # doesn't raise!
|
msgValidator(decoded) # doesn't raise!
|
||||||
except SszError as e:
|
except SerializationError as e:
|
||||||
inc nbc_gossip_failed_ssz
|
inc nbc_gossip_failed_ssz
|
||||||
debug "Error decoding gossip",
|
debug "Error decoding gossip",
|
||||||
topic, len = message.data.len, decompressed = decompressed.len,
|
topic, len = message.data.len, decompressed = decompressed.len,
|
||||||
@ -2472,7 +2472,7 @@ proc addAsyncValidator*[MsgType](node: Eth2Node,
|
|||||||
let decoded = SSZ.decode(decompressed, MsgType)
|
let decoded = SSZ.decode(decompressed, MsgType)
|
||||||
decompressed = newSeq[byte](0) # release memory before validating
|
decompressed = newSeq[byte](0) # release memory before validating
|
||||||
msgValidator(decoded) # doesn't raise!
|
msgValidator(decoded) # doesn't raise!
|
||||||
except SszError as e:
|
except SerializationError as e:
|
||||||
inc nbc_gossip_failed_ssz
|
inc nbc_gossip_failed_ssz
|
||||||
debug "Error decoding gossip",
|
debug "Error decoding gossip",
|
||||||
topic, len = message.data.len, decompressed = decompressed.len,
|
topic, len = message.data.len, decompressed = decompressed.len,
|
||||||
|
@ -53,7 +53,7 @@ func decodeSszLightClientObject[T: SomeForkedLightClientObject](
|
|||||||
else:
|
else:
|
||||||
raiseRestDecodingBytesError(
|
raiseRestDecodingBytesError(
|
||||||
cstring("Unsupported fork: " & $consensusFork))
|
cstring("Unsupported fork: " & $consensusFork))
|
||||||
except SszError as exc:
|
except SerializationError as exc:
|
||||||
raiseRestDecodingBytesError(cstring("Malformed data: " & $exc.msg))
|
raiseRestDecodingBytesError(cstring("Malformed data: " & $exc.msg))
|
||||||
|
|
||||||
proc decodeJsonLightClientObject[T: SomeForkedLightClientObject](
|
proc decodeJsonLightClientObject[T: SomeForkedLightClientObject](
|
||||||
@ -145,7 +145,7 @@ proc decodeSszLightClientObjects[S: seq[SomeForkedLightClientObject]](
|
|||||||
else:
|
else:
|
||||||
raiseRestDecodingBytesError(
|
raiseRestDecodingBytesError(
|
||||||
cstring("Unsupported fork: " & $consensusFork))
|
cstring("Unsupported fork: " & $consensusFork))
|
||||||
except SszError as exc:
|
except SerializationError as exc:
|
||||||
raiseRestDecodingBytesError(cstring("Malformed data: " & $exc.msg))
|
raiseRestDecodingBytesError(cstring("Malformed data: " & $exc.msg))
|
||||||
res
|
res
|
||||||
|
|
||||||
|
@ -980,7 +980,7 @@ template readSszForkedHashedBeaconState*(
|
|||||||
cfg.consensusForkAtEpoch(slot.epoch()).readSszForkedHashedBeaconState(data)
|
cfg.consensusForkAtEpoch(slot.epoch()).readSszForkedHashedBeaconState(data)
|
||||||
|
|
||||||
func readSszForkedHashedBeaconState*(cfg: RuntimeConfig, data: openArray[byte]):
|
func readSszForkedHashedBeaconState*(cfg: RuntimeConfig, data: openArray[byte]):
|
||||||
ForkedHashedBeaconState {.raises: [Defect, SszError].} =
|
ForkedHashedBeaconState {.raises: [SerializationError].} =
|
||||||
## Read a state picking the right fork by first reading the slot from the byte
|
## Read a state picking the right fork by first reading the slot from the byte
|
||||||
## source
|
## source
|
||||||
if data.len() < sizeof(BeaconStateHeader):
|
if data.len() < sizeof(BeaconStateHeader):
|
||||||
@ -1000,7 +1000,7 @@ type
|
|||||||
|
|
||||||
func readSszForkedSignedBeaconBlock*(
|
func readSszForkedSignedBeaconBlock*(
|
||||||
cfg: RuntimeConfig, data: openArray[byte]):
|
cfg: RuntimeConfig, data: openArray[byte]):
|
||||||
ForkedSignedBeaconBlock {.raises: [Defect, SszError].} =
|
ForkedSignedBeaconBlock {.raises: [SerializationError].} =
|
||||||
## Helper to read a header from bytes when it's not certain what kind of block
|
## Helper to read a header from bytes when it's not certain what kind of block
|
||||||
## it is
|
## it is
|
||||||
if data.len() < sizeof(ForkedBeaconBlockHeader):
|
if data.len() < sizeof(ForkedBeaconBlockHeader):
|
||||||
|
@ -72,14 +72,10 @@ template decodeAndProcess(typ, process: untyped): bool =
|
|||||||
data {.inject.} = newClone(
|
data {.inject.} = newClone(
|
||||||
try:
|
try:
|
||||||
SSZ.decode(input, typ)
|
SSZ.decode(input, typ)
|
||||||
except MalformedSszError as e:
|
except SerializationError as e:
|
||||||
raise newException(
|
raise newException(
|
||||||
FuzzCrashError,
|
FuzzCrashError,
|
||||||
"Malformed SSZ, likely bug in preprocessing.", e)
|
"Malformed SSZ, likely bug in preprocessing.", e)
|
||||||
except SszSizeMismatchError as e:
|
|
||||||
raise newException(
|
|
||||||
FuzzCrashError,
|
|
||||||
"SSZ size mismatch, likely bug in preprocessing.", e)
|
|
||||||
)
|
)
|
||||||
let processOk =
|
let processOk =
|
||||||
try:
|
try:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user