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

add libnimbus_lc.a C library #5122

Merged
merged 28 commits into from
Jul 19, 2023
Merged

add libnimbus_lc.a C library #5122

merged 28 commits into from
Jul 19, 2023

Conversation

etan-status
Copy link
Contributor

Add a new C library for processing light client data based on the Nimbus implementation. This can be used from other, non-Nimbus components.

Add a new C library for processing light client data based on the Nimbus
implementation. This can be used from other, non-Nimbus components.
@github-actions
Copy link

github-actions bot commented Jun 24, 2023

Unit Test Results

         9 files  ±0    1 077 suites  ±0   43m 3s ⏱️ + 2m 47s
  3 712 tests ±0    3 433 ✔️ ±0  279 💤 ±0  0 ±0 
15 832 runs  ±0  15 527 ✔️ ±0  305 💤 ±0  0 ±0 

Results for commit f60fdbf. ± Comparison against base commit 346d05a.

♻️ This comment has been updated with latest results.

@etan-status etan-status marked this pull request as draft June 26, 2023 12:49
@etan-status
Copy link
Contributor Author

macOS requires #5132

@etan-status etan-status marked this pull request as ready for review July 11, 2023 10:11
@tersec
Copy link
Contributor

tersec commented Jul 11, 2023

Whatever nitpicks one might have about the C implementation, this PR is almost pure addition rather than modification of existing functionality, and presents no new default-running attack surface, so worth merging and adjusting from there.

@arnetheduck
Copy link
Member

I might have a few but I'll need a few days to review - no opinion on merge order

@etan-status etan-status merged commit 971b448 into unstable Jul 19, 2023
@etan-status etan-status deleted the dev/etan/lc-wasm branch July 19, 2023 07:48
* of the API. Also, all following calls must come from the same thread as from
* which this call was done.
*/
void NimMain(void);
Copy link
Member

Choose a reason for hiding this comment

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

See https://github.com/status-im/nim-style-guide/blob/main/interop/async/asynclib.nim#L16 - NimMain should not be exposed to users of the library

* @return `NULL` - If an error occurred.
*/
ETH_RESULT_USE_CHECK
ETHRandomNumber *ETHRandomNumberCreate(void);
Copy link
Member

Choose a reason for hiding this comment

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

RNG feels like something we should hide behind a generic light client context - ie no need for library consumer to know / care

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What if someone wants to run multiple light client engines in the same thread? e.g., for a dashboard that tracks both Goerli and Mainnet? Sharing the RNG would be great in that case. Or should it simply be set up as part of a library wide ETHContextCreate?

ETH_RESULT_USE_CHECK
ETHBeaconState *ETHBeaconStateCreateFromSsz(
const ETHConsensusConfig *cfg,
const char *consensusVersion,
Copy link
Member

Choose a reason for hiding this comment

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

we don't need the version (we can deduce it from the header)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's only possible due to a coincidence and not generally applicable. The header is not necessarily at the same location forever.

*
* @see https://github.com/ethereum/consensus-specs/blob/v1.4.0-beta.0/specs/phase0/beacon-chain.md#custom-types
*/
void ETHRootDestroy(ETHRoot *root);
Copy link
Member

Choose a reason for hiding this comment

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

it might be easier to pass these around by value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe. In the WASM case, can only pass cint/pointer, so there would still be the need for memory management in the client.

## * Data gas used.
execution[].data_gas_used.cint

func ETHExecutionPayloadHeaderGetExcessDataGas(
Copy link
Member

Choose a reason for hiding this comment

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

isn't cint too small for this? ie max 2**31?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, same for Slot, in theory would have to return it as a pair of high/low cint, or 4x / 8x (or allocate + matching Destroy).
But for practical ranges, cint is good enough. If higher values are possible in practice, needs to be extended.

@arnetheduck
Copy link
Member

In terms of C API, I'm not necessarily convinced that we need this great level of detail to access the internal details of the Nimbus implementation (the stores, the RNG, etc etc) - ie the REST API has a an appropriate abstraction level in that it represents the data and the events necessary to build a consumer of the light client API, and it has the benefit of being familiar to the ecosystem and well documented.

As such, when thinking about a light client data consumer, I envision they launch the light client via some startLightClient(LCContext* context) function and receive events when things happen (ie onLightClientHeader or whatever the events are called.

One can also plausibly think that someone might not want the entire async stack but rather drive the application using well-known data: in this case, one would feed it the messages as they come off the libp2p stack instead but again forego the internal implementation details and rather focus on a high-level context that collects everything needed under an opaque type.

Re tests, why the genesis.ssz and other binary files? these can trivially be generated and thus not bloat the git history (which unfortunately will have to stay due to this being merged already)...

@arnetheduck
Copy link
Member

+ rm -f build/libnimbus_lc.a
+ /home/arnetheduck/status/nimbus-eth2/vendor/nimbus-build-system/scripts/env.sh nim c -d:disable_libbacktrace -d:release --app:staticlib --noMain --nimcache:nimcache/libnimbus_lc_static -o:build/libnimbus_lc.a -d:release --parallelBuild:1 -d:libp2p_agents_metrics -d:KnownLibP2PAgents=nimbus,lighthouse,lodestar,prysm,teku --verbosity:0 --hints:off -d:chronicles_log_level=DEBUG beacon_chain/libnimbus_lc/libnimbus_lc.nim

debugging leftovers in make test

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.

3 participants