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

avoid --gc:arc issue in validator key caching #6203

Merged
merged 2 commits into from
Apr 16, 2024
Merged

Conversation

etan-status
Copy link
Contributor

The current implementation of the validator key cache as introduced in #5883 leads to issues when compiling with --gc:arc. Namely, the assert in injectdestructors.nim > destructiveMoveVar is triggered:

assert n.kind != nkSym or not hasDestructor(c, n.sym.typ)

cached == nkSym, and n.sym.typ == ref HashedValidatorPubKeyItem with hasDestructor(c, n.sym.typ) == true.

Inlining the addr ...[] avoids the problem and allows --gc:arc compilation as part of LC wasm demo project.

Compilation command:

nim c \
    -d:disable_libbacktrace \
    -d:disableMarchNative \
    -d:disableLTO \
    -d:emscripten \
    -d:release \
    -d:useGcAssert \
    -d:useSysAssert \
    --debuginfo:off \
    --nimcache:nimcache \
    --os:linux \
    --cpu:wasm32 \
    --cc:clang \
    --clang.exe:emcc \
    --clang.linkerexe:emcc \
    --gc:arc \
    --exceptions:goto \
    --define:noSignalHandler \
    --define:danger \
    --panics:on \
    --passC:-fpic \
    --passL:-Os \
    --passL:-fpic \
    --passC:'-pthread' \
    --passL:'-pthread' \
    --passC:'-sASSERTIONS' \
    --passL:'-sASSERTIONS' \
    --passC:'-sINITIAL_MEMORY=256MB' \
    --passL:'-sINITIAL_MEMORY=256MB' \
    --passC:'-sSTACK_SIZE=128MB' \
    --passL:'-sSTACK_SIZE=128MB' \
    --passC:'-sUSE_PTHREADS=1' \
    --passL:'-sUSE_PTHREADS=1' \
    --passC:'-sPTHREAD_POOL_SIZE_STRICT=0' \
    --passL:'-sPTHREAD_POOL_SIZE_STRICT=0' \
    --passL:'-sEXPORTED_FUNCTIONS="[_free, _malloc, _NimMain, _ETHRandomNumberCreate, _ETHConsensusConfigCreateFromYaml, _ETHConsensusConfigGetConsensusVersionAtEpoch, _ETHBeaconStateCreateFromSsz, _ETHBeaconStateDestroy, _ETHBeaconStateCopyGenesisValidatorsRoot, _ETHRootDestroy, _ETHForkDigestsCreateFromState, _ETHBeaconClockCreateFromState, _ETHBeaconClockGetSlot, _ETHLightClientStoreCreateFromBootstrap, _ETHLightClientStoreDestroy, _kETHLcSyncKind_UpdatesByRange, _kETHLcSyncKind_FinalityUpdate, _kETHLcSyncKind_OptimisticUpdate, _ETHLightClientStoreGetNextSyncTask, _ETHLightClientStoreGetMillisecondsToNextSyncTask, _ETHLightClientStoreProcessUpdatesByRange, _ETHLightClientStoreProcessFinalityUpdate, _ETHLightClientStoreProcessOptimisticUpdate, _ETHLightClientStoreGetFinalizedHeader, _ETHLightClientStoreIsNextSyncCommitteeKnown, _ETHLightClientStoreGetOptimisticHeader, _ETHLightClientStoreGetSafetyThreshold, _ETHLightClientHeaderCreateCopy, _ETHLightClientHeaderDestroy, _ETHLightClientHeaderCopyBeaconRoot, _ETHLightClientHeaderGetBeacon, _ETHBeaconBlockHeaderGetSlot, _ETHBeaconBlockHeaderGetProposerIndex, _ETHBeaconBlockHeaderGetParentRoot, _ETHBeaconBlockHeaderGetStateRoot, _ETHBeaconBlockHeaderGetBodyRoot, _ETHLightClientHeaderCopyExecutionHash, _ETHLightClientHeaderGetExecution, _ETHExecutionPayloadHeaderGetParentHash, _ETHExecutionPayloadHeaderGetFeeRecipient, _ETHExecutionPayloadHeaderGetStateRoot, _ETHExecutionPayloadHeaderGetReceiptsRoot, _ETHExecutionPayloadHeaderGetLogsBloom, _ETHExecutionPayloadHeaderGetPrevRandao, _ETHExecutionPayloadHeaderGetBlockNumber, _ETHExecutionPayloadHeaderGetGasLimit, _ETHExecutionPayloadHeaderGetGasUsed, _ETHExecutionPayloadHeaderGetTimestamp, _ETHExecutionPayloadHeaderGetExtraDataBytes, _ETHExecutionPayloadHeaderGetBaseFeePerGas, _ETHExecutionPayloadHeaderGetBlobGasUsed, _ETHExecutionPayloadHeaderGetExcessBlobGas, _ETHExecutionBlockHeaderCreateFromJson, _ETHExecutionBlockHeaderDestroy, _ETHExecutionBlockHeaderGetTransactionsRoot, _ETHExecutionBlockHeaderGetWithdrawalsRoot, _ETHTransactionsCreateFromJson, _ETHTransactionsDestroy, _ETHTransactionsGetCount, _ETHTransactionsGet, _ETHTransactionGetHash, _ETHTransactionGetFrom, _ETHTransactionGetNonce, _ETHTransactionGetMaxPriorityFeePerGas, _ETHTransactionGetMaxFeePerGas, _ETHTransactionGetGas, _ETHTransactionIsCreatingContract, _ETHTransactionGetTo, _ETHTransactionGetValue, _ETHTransactionGetInputBytes, _ETHTransactionGetBytes, _ETHTransactionGetEip6493Root, _ETHTransactionGetEip6493Bytes, _ETHTransactionGetNumEip6493SnappyBytes, _ETHReceiptsCreateFromJson, _ETHReceiptsDestroy, _ETHReceiptsGet, _ETHReceiptHasStatus, _ETHReceiptGetBytes, _ETHReceiptGetEip6493Bytes, _ETHReceiptGetNumEip6493SnappyBytes]"' \
    --passL:'-sEXPORTED_RUNTIME_METHODS="[lengthBytesUTF8, stringToNewUTF8]"' \
    --passL:'-Wl,--no-entry' \
    --noMain:on \
    --passL:'-o libnimbus_lc.js' \
    nimbus-eth2/beacon_chain/libnimbus_lc/libnimbus_lc.nim

The current implementation of the validator key cache as introduced in
#5883 leads to issues when compiling with `--gc:arc`. Namely, the assert
in `injectdestructors.nim` > `destructiveMoveVar` is triggered:

```nim
assert n.kind != nkSym or not hasDestructor(c, n.sym.typ)
```

`cached == nkSym`, and `n.sym.typ == ref HashedValidatorPubKeyItem` with
`hasDestructor(c, n.sym.typ) == true`.

Inlining the `addr ...[]` avoids the problem and allows `--gc:arc`
compilation as part of LC wasm demo project.

Compilation command:

```sh
nim c \
    -d:disable_libbacktrace \
    -d:disableMarchNative \
    -d:disableLTO \
    -d:emscripten \
    -d:release \
    -d:useGcAssert \
    -d:useSysAssert \
    --debuginfo:off \
    --nimcache:nimcache \
    --os:linux \
    --cpu:wasm32 \
    --cc:clang \
    --clang.exe:emcc \
    --clang.linkerexe:emcc \
    --gc:arc \
    --exceptions:goto \
    --define:noSignalHandler \
    --define:danger \
    --panics:on \
    --passC:-fpic \
    --passL:-Os \
    --passL:-fpic \
    --passC:'-pthread' \
    --passL:'-pthread' \
    --passC:'-sASSERTIONS' \
    --passL:'-sASSERTIONS' \
    --passC:'-sINITIAL_MEMORY=256MB' \
    --passL:'-sINITIAL_MEMORY=256MB' \
    --passC:'-sSTACK_SIZE=128MB' \
    --passL:'-sSTACK_SIZE=128MB' \
    --passC:'-sUSE_PTHREADS=1' \
    --passL:'-sUSE_PTHREADS=1' \
    --passC:'-sPTHREAD_POOL_SIZE_STRICT=0' \
    --passL:'-sPTHREAD_POOL_SIZE_STRICT=0' \
    --passL:'-sEXPORTED_FUNCTIONS="[_free, _malloc, _NimMain, _ETHRandomNumberCreate, _ETHConsensusConfigCreateFromYaml, _ETHConsensusConfigGetConsensusVersionAtEpoch, _ETHBeaconStateCreateFromSsz, _ETHBeaconStateDestroy, _ETHBeaconStateCopyGenesisValidatorsRoot, _ETHRootDestroy, _ETHForkDigestsCreateFromState, _ETHBeaconClockCreateFromState, _ETHBeaconClockGetSlot, _ETHLightClientStoreCreateFromBootstrap, _ETHLightClientStoreDestroy, _kETHLcSyncKind_UpdatesByRange, _kETHLcSyncKind_FinalityUpdate, _kETHLcSyncKind_OptimisticUpdate, _ETHLightClientStoreGetNextSyncTask, _ETHLightClientStoreGetMillisecondsToNextSyncTask, _ETHLightClientStoreProcessUpdatesByRange, _ETHLightClientStoreProcessFinalityUpdate, _ETHLightClientStoreProcessOptimisticUpdate, _ETHLightClientStoreGetFinalizedHeader, _ETHLightClientStoreIsNextSyncCommitteeKnown, _ETHLightClientStoreGetOptimisticHeader, _ETHLightClientStoreGetSafetyThreshold, _ETHLightClientHeaderCreateCopy, _ETHLightClientHeaderDestroy, _ETHLightClientHeaderCopyBeaconRoot, _ETHLightClientHeaderGetBeacon, _ETHBeaconBlockHeaderGetSlot, _ETHBeaconBlockHeaderGetProposerIndex, _ETHBeaconBlockHeaderGetParentRoot, _ETHBeaconBlockHeaderGetStateRoot, _ETHBeaconBlockHeaderGetBodyRoot, _ETHLightClientHeaderCopyExecutionHash, _ETHLightClientHeaderGetExecution, _ETHExecutionPayloadHeaderGetParentHash, _ETHExecutionPayloadHeaderGetFeeRecipient, _ETHExecutionPayloadHeaderGetStateRoot, _ETHExecutionPayloadHeaderGetReceiptsRoot, _ETHExecutionPayloadHeaderGetLogsBloom, _ETHExecutionPayloadHeaderGetPrevRandao, _ETHExecutionPayloadHeaderGetBlockNumber, _ETHExecutionPayloadHeaderGetGasLimit, _ETHExecutionPayloadHeaderGetGasUsed, _ETHExecutionPayloadHeaderGetTimestamp, _ETHExecutionPayloadHeaderGetExtraDataBytes, _ETHExecutionPayloadHeaderGetBaseFeePerGas, _ETHExecutionPayloadHeaderGetBlobGasUsed, _ETHExecutionPayloadHeaderGetExcessBlobGas, _ETHExecutionBlockHeaderCreateFromJson, _ETHExecutionBlockHeaderDestroy, _ETHExecutionBlockHeaderGetTransactionsRoot, _ETHExecutionBlockHeaderGetWithdrawalsRoot, _ETHTransactionsCreateFromJson, _ETHTransactionsDestroy, _ETHTransactionsGetCount, _ETHTransactionsGet, _ETHTransactionGetHash, _ETHTransactionGetFrom, _ETHTransactionGetNonce, _ETHTransactionGetMaxPriorityFeePerGas, _ETHTransactionGetMaxFeePerGas, _ETHTransactionGetGas, _ETHTransactionIsCreatingContract, _ETHTransactionGetTo, _ETHTransactionGetValue, _ETHTransactionGetInputBytes, _ETHTransactionGetBytes, _ETHTransactionGetEip6493Root, _ETHTransactionGetEip6493Bytes, _ETHTransactionGetNumEip6493SnappyBytes, _ETHReceiptsCreateFromJson, _ETHReceiptsDestroy, _ETHReceiptsGet, _ETHReceiptHasStatus, _ETHReceiptGetBytes, _ETHReceiptGetEip6493Bytes, _ETHReceiptGetNumEip6493SnappyBytes]"' \
    --passL:'-sEXPORTED_RUNTIME_METHODS="[lengthBytesUTF8, stringToNewUTF8]"' \
    --passL:'-Wl,--no-entry' \
    --noMain:on \
    --passL:'-o libnimbus_lc.js' \
    nimbus-eth2/beacon_chain/libnimbus_lc/libnimbus_lc.nim
```
@etan-status
Copy link
Contributor Author

same for --gc:orc

Copy link

github-actions bot commented Apr 15, 2024

Unit Test Results

         9 files  ±0    1 115 suites  ±0   35m 46s ⏱️ + 1m 27s
  4 245 tests ±0    3 898 ✔️ ±0  347 💤 ±0  0 ±0 
16 929 runs  ±0  16 531 ✔️ ±0  398 💤 ±0  0 ±0 

Results for commit fd92101. ± Comparison against base commit c57fcb4.

♻️ This comment has been updated with latest results.

@tersec
Copy link
Contributor

tersec commented Apr 15, 2024

It would be useful to reference upstream issue: nim-lang/Nim#23505

@etan-status etan-status merged commit c7d5ad7 into unstable Apr 16, 2024
13 checks passed
@etan-status etan-status deleted the dev/etan/vk-addr branch April 16, 2024 09:47
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