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

extend light client protocol for Electra #6375

Merged
merged 15 commits into from
Jun 26, 2024
Merged

extend light client protocol for Electra #6375

merged 15 commits into from
Jun 26, 2024

Conversation

etan-status
Copy link
Contributor

Add missing Electra support for light client protocol:

Tested against PR consensus-spec-tests, the test runner automatically picks up the new tests once available.

Add missing Electra support for light client protocol:

- ethereum/consensus-specs#3811

Tested against PR consensus-spec-tests, the test runner automatically
picks up the new tests once available.
Copy link

github-actions bot commented Jun 21, 2024

Unit Test Results

         9 files  ±  0    1 334 suites  +6   31m 32s ⏱️ + 5m 3s
  4 998 tests ±  0    4 650 ✔️ ±  0  348 💤 ±0  0 ±0 
20 874 runs  +24  20 470 ✔️ +24  404 💤 ±0  0 ±0 

Results for commit a5c8bae. ± Comparison against base commit 3da85e5.

♻️ This comment has been updated with latest results.

@@ -188,8 +213,71 @@ template kind*(
deneb.LightClientStore]): LightClientDataFork =
LightClientDataFork.Deneb

template kind*(
x: typedesc[ # `SomeLightClientObject` doesn't work here (Nim 1.6)
Copy link
Contributor

Choose a reason for hiding this comment

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

Might link to nim-lang/Nim#18095 here

@@ -951,6 +1135,108 @@ func toDenebLightClientHeader(
execution_branch: blck.message.body.build_proof(
capella.EXECUTION_PAYLOAD_GINDEX).get)

# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.3/specs/electra/light-client/full-node.md#modified-block_to_light_client_header
func toElectraLightClientHeader(
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
Copy link
Contributor

Choose a reason for hiding this comment

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

beacon: blck.message.toBeaconBlockHeader())

func toElectraLightClientHeader(
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
Copy link
Contributor

Choose a reason for hiding this comment

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

nim-lang/Nim#18095

This way it won't be a mystery to check if/when it's eventually fixed

capella.EXECUTION_PAYLOAD_GINDEX).get)

func toElectraLightClientHeader(
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
Copy link
Contributor

Choose a reason for hiding this comment

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

capella.EXECUTION_PAYLOAD_GINDEX).get)

func toElectraLightClientHeader(
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
Copy link
Contributor

Choose a reason for hiding this comment

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

hash_tree_root(payload.consolidation_requests)),
execution_branch: blck.message.body.build_proof(
capella.EXECUTION_PAYLOAD_GINDEX).get)

func toLightClientHeader*(
blck: # `SomeSignedBeaconBlock` doesn't work here (Nim 1.6)
Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -990,9 +1275,13 @@ func shortLog*[
capellaData: typeof(x.capellaData.shortLog())
of LightClientDataFork.Deneb:
denebData: typeof(x.denebData.shortLog())
of LightClientDataFork.Electra:
electraData: typeof(x.electraData.shortLog())

let xKind = x.kind # Nim 1.6.12: Using `kind: x.kind` inside case is broken
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this ever isolated/reproduced/fixed/reported/already-reported-upstream or maybe fixed in 2.0.6?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not reported upstream, but this is the error that is produced when trying to inline x.kind:

Error: a case selecting discriminator 'kind' with value 'x.kind' appears in the object construction, but the field(s) 'denebData' are in conflict with this value.

Still applies to 2.0.6, have updated the comment in #6389

Copy link
Contributor

Choose a reason for hiding this comment

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

@tersec
Copy link
Contributor

tersec commented Jun 26, 2024

Also for all the "... works in Nim 1.6 ..." etc comments, as of the last couple days, nimbus-eth2 uses Nim 2.0.6, so that's the relevant version to check. No need to find/update all of them, though, apparently the upstream issue isn't fixed, but at least new comments going in should reference 2.0 or 2.0.6 specifically.


if epoch < cfg.CAPELLA_FORK_EPOCH:
return
header.execution == default(ExecutionPayloadHeader) and
Copy link
Contributor

Choose a reason for hiding this comment

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

In general,

type L = object
  a: string
  b: int
  c: array[32, byte]
  d: array[32, byte]
  e: uint64

func a(x: L): bool =
  x == default(L)

discard a(L())

produces, with Nim 2.0.6 using refc,

struct tyObject_L__0ubpPjj6L2pwUQ1bt60yqg {
  NimStringDesc *a;
  NI b;
  tyArray__vEOa9c5qaE9ajWxR5R4zwfQg c;
  tyArray__vEOa9c5qaE9ajWxR5R4zwfQg d;
  NU64 e;
};

...

N_LIB_PRIVATE N_NIMCALL(NIM_BOOL,
                        a__a_u7)(tyObject_L__0ubpPjj6L2pwUQ1bt60yqg *x_p0) {
  NIM_BOOL result;
  tyObject_L__0ubpPjj6L2pwUQ1bt60yqg T1_;
  result = (NIM_BOOL)0;
  nimZeroMem((void *)(&T1_), sizeof(tyObject_L__0ubpPjj6L2pwUQ1bt60yqg));
  result = eqeq___a_u15(x_p0, (&T1_));
  popFrame();
  return result;
}

whereas

type L = object
  a: string
  b: int
  c: array[32, byte]
  d: array[32, byte]
  e: uint64

func a(x: L): bool =
  x == static(default(L))

discard a(L())

results in

struct tyObject_L__0ubpPjj6L2pwUQ1bt60yqg {
  NimStringDesc *a;
  NI b;
  tyArray__vEOa9c5qaE9ajWxR5R4zwfQg c;
  tyArray__vEOa9c5qaE9ajWxR5R4zwfQg d;
  NU64 e;
};

...

static NIM_CONST tyObject_L__0ubpPjj6L2pwUQ1bt60yqg
    TM__R8RUzYq41iOx0I9bZH5Nyrw_2 = {
        ((NimStringDesc *)NIM_NIL),
        ((NI)0),
        {((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0),
         ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0),
         ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0),
         ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0),
         ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0)},
        {((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0),
         ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0),
         ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0),
         ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0),
         ((NU8)0), ((NU8)0), ((NU8)0), ((NU8)0)},
        0ULL};

...

N_LIB_PRIVATE N_NIMCALL(NIM_BOOL,
                        a__a_u7)(tyObject_L__0ubpPjj6L2pwUQ1bt60yqg *x_p0) {
  NIM_BOOL result;
  result = (NIM_BOOL)0;
  result = eqeq___a_u15(x_p0, (&TM__R8RUzYq41iOx0I9bZH5Nyrw_2));
  popFrame();
  return result;
}

It's possible gcc and clang can both under -O3 -flto deduce that they don't have to consume the stack space, reinitialize/zero every time, et cetera, but that seems fairly excessive when wrapping the default(...) as static(default(...)) or using const foo = default(...); compare_with(foo) avoids the per-call construction/zeroing/stack space altogether of this object.

etan-status added a commit that referenced this pull request Jun 26, 2024
Addresses feedback from #6375 that is applicable to pre-existing code
moreso than to the new PR.
tersec pushed a commit that referenced this pull request Jun 26, 2024
Addresses feedback from #6375 that is applicable to pre-existing code
moreso than to the new PR.
@tersec tersec merged commit 9924aec into unstable Jun 26, 2024
13 checks passed
@tersec tersec deleted the dev/etan/lc-electra branch June 26, 2024 19:02
etan-status added a commit that referenced this pull request Aug 6, 2024
Followup on incorrect upgrade procedure in #6375 where `blob_gas_used`
was accidentally copied into `excess_blob_gas` when running Electra
`LightClientStore` with earlier `LightClient(Bootstrap|Update)`.
tersec pushed a commit that referenced this pull request Aug 6, 2024
Followup on incorrect upgrade procedure in #6375 where `blob_gas_used`
was accidentally copied into `excess_blob_gas` when running Electra
`LightClientStore` with earlier `LightClient(Bootstrap|Update)`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants