-
Notifications
You must be signed in to change notification settings - Fork 251
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
allow trusted node sync based on LC trusted block root #4736
Conversation
Extends `trustedNodeSync` with a new `--trusted-block-root` option that allows initializing a light client. No `--state-id` must be provided. The beacon node will then use this light client to obtain the latest finalized state from the remote server in a trust-minimized fashion. Note that the provided `--trusted-block-root` should be somewhat recent, and that security precautions such as comparing the state root against block explorers is still recommended.
|
o = 0 | ||
while l - o != 0: | ||
# response_chunk_len | ||
if l - o < 8: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth doing something like type foo = uint64; const bar = sizeof(foo)
, not sure.
As it is, there's an implicit relationship here between the two which modifying some, but not all, will cause decoding errors for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, yeah, it's a bit tricky. Two tricky portions further down where reviewing becomes more annoying by reducing magic number:
int.high.foo
only guaranteed to work iffoo.high >= int.high
.- The
ForkDigest
conversion explicitly going from 0 .. 3
Have replaced the magic numbers for now (while keeping them as a comment to be able to reason about it)
raiseRestDecodingBytesError(cstring("Malformed data: " & $exc.msg)) | ||
return res | ||
|
||
if mediaType == ApplicationJsonMediaType: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor, but elif
here would clarify the mutually exclusive nature of these in a way beyond the return res
es at the end of each, and without requiring verifying that there aren't any other early returns within those conditional blocks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved the return to the top to prevent accidents, I think that's what you meant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Partly that, but also, it's structured as
if mutually_exclusive_condition_1:
a couple dozen lines of code with multiple indentation levels and control flow
return
if mutually_exclusive_condition_2:
some more code
return
Both if
blocks can't possibly run, but to infer that needs more than a cursory glance for no particular reason that I can discern. It's a case of is-this-switch-statement-meant-to-fall-through-or-not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean, use elif
for the second condition in these?
downsides are:
- it's not consistently usable, e.g., when there is a
let
in-between the twoif
. - it suggests some sort of relations between the two conditions, or more generally, an exhaustion of multiple options
- if just doing
if
/elif
/elif
..., analyzers like clang-tidy like to point out that anelse
is missing to achieve said exhaustion
ultimately, very minor though.
in the context of this PR, there is only a single return
. are you referring to the raise
?
for example:
if responseChunkLen > int.high.chunkLenType:
raiseRestDecodingBytesError("Malformed data: Unsupported length")
if l - o < responseChunkLen.int:
raiseRestDecodingBytesError("Malformed data: Incomplete chunk")
or, the try
/ except
bloks such as this one:
try:
withLcDataFork(lcDataForkAtConsensusFork(consensusFork)):
when lcDataFork > LightClientDataFork.None:
type T = typeof(res[0])
var obj = T(kind: lcDataFork)
obj.forky(lcDataFork) = SSZ.decode(
data.toOpenArray(begin + contextLen, after - 1),
T.Forky(lcDataFork))
obj.checkForkConsistency(cfg, consensusFork)
res.add obj
else:
raiseRestDecodingBytesError(
cstring("Unsupported fork: " & $consensusFork))
except SszError as exc:
raiseRestDecodingBytesError(cstring("Malformed data: " & $exc.msg))
I can see the "multiple indentation levels and control flow" argument, but nim's try
/ except
kinda pushes that.
Maybe I'm misunderstanding the point.
Extends
trustedNodeSync
with a new--trusted-block-root
option that allows initializing a light client. No--state-id
must be provided. The beacon node will then use this light client to obtain the latest finalized state from the remote server in a trust-minimized fashion. Note that the provided--trusted-block-root
should be somewhat recent, and that security precautions such as comparing the state root against block explorers is still recommended.