Repository navigation
feat(nethermind): report the sync phase through the healthcheck #96
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
Open
3alpha
wants to merge
2
commits into
main
Choose a base branch
from
feat/node-status-report
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| name: Node status test | ||
|
|
||
| on: | ||
| pull_request: | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| repository: dappnode/staker-package-scripts | ||
| path: staker-package-scripts | ||
| - name: Run the node status tests | ||
| run: sh test/node_status_test.sh | ||
| env: | ||
| NODE_STATUS_TOOLS: staker-package-scripts/scripts/node_status_tools.sh | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| #!/bin/sh | ||
|
|
||
| # Node status report of the Nethermind execution client, run as the Docker | ||
| # healthcheck. Prints one JSON line (node status contract, version 1) telling | ||
| # which sync phase Nethermind is in and how far along it is. Whether the node is | ||
| # synced, waiting on the consensus client or stalled is decided by the | ||
| # dappmanager, not here. | ||
| # | ||
| # What it relies on, as of NethermindEth/nethermind 2.2.2: | ||
| # - eth_syncing (src/Nethermind/Nethermind.Facade/Eth/EthSyncingInfo.cs): an | ||
| # object while the head is more than 8 blocks behind the highest known block | ||
| # (the best suggested header or the beacon sync target), or while old bodies | ||
| # and receipts are still downloading. The head (currentBlock) stays at | ||
| # genesis until the snap state sync ends. From 2.3 the object also carries | ||
| # warpChunksProcessed / warpChunksAmount during the state download. | ||
| # - health_nodeStatus (src/Nethermind/Nethermind.HealthChecks/NodeHealthService.cs): | ||
| # "errors" lists ClUnavailable (no forkchoice or payload from the consensus | ||
| # client for 5 minutes) and LowDiskSpace, among others. | ||
| # | ||
| # Environment: | ||
| # NODE_STATUS_TOOLS: Path of the shared helpers (default /etc/profile.d/node_status_tools.sh) | ||
| # NS_RPC_PORT, NS_TIMEOUT: See node_status_tools.sh (NS_TIMEOUT defaults to 2 here) | ||
|
|
||
| # shellcheck source=/dev/null | ||
| . "${NODE_STATUS_TOOLS:-/etc/profile.d/node_status_tools.sh}" | ||
|
|
||
| # At most four sequential calls: keep the worst case well inside the 10 s healthcheck timeout | ||
| NS_TIMEOUT=${NS_TIMEOUT:-2} | ||
|
|
||
| # Nethermind counts the head as synced within this many blocks of the highest known block | ||
| # (EthSyncingInfo.MaxDistanceForSynced) | ||
| MAX_DISTANCE_FOR_SYNCED=8 | ||
|
|
||
| # The JSON-RPC does not answer yet: Nethermind is still opening its database | ||
| if ! syncing=$(ns_rpc eth_syncing); then | ||
| ns_emit starting | ||
| exit $? | ||
| fi | ||
|
|
||
| # Latest block, peers and health issues, in that order; a failed call means the | ||
| # node stopped answering, so the remaining ones are skipped | ||
| set -- | ||
| if head=$(ns_block_head); then | ||
| # shellcheck disable=SC2086 # height=<n> headTime=<n>, two arguments | ||
| set -- $head | ||
| if peers=$(ns_rpc net_peerCount); then | ||
| set -- "$@" peers="$(ns_json_get "$peers")" | ||
| if health=$(ns_rpc health_nodeStatus); then | ||
| # NoPeers is left out: the dappmanager derives it from peers. SyncDegraded is | ||
| # left out too: Nethermind raises it while it only waits for the consensus client | ||
| for error in $(ns_json_get "$health" '(.errors // .Errors // [])[] | strings'); do | ||
| case $error in | ||
| ClUnavailable) set -- "$@" issue="Consensus client not connected" ;; | ||
| LowDiskSpace) set -- "$@" issue="Low disk space" ;; | ||
| esac | ||
| done | ||
| fi | ||
| fi | ||
| fi | ||
|
|
||
| if [ "$syncing" = "false" ]; then | ||
| ns_emit synced "$@" | ||
| exit $? | ||
| fi | ||
|
|
||
| if [ "$(ns_json_get "$syncing" type)" != "object" ]; then | ||
| ns_emit syncing "$@" | ||
| exit $? | ||
| fi | ||
|
|
||
| # Missing or unreadable numbers count as 0, like the dappmanager's old parser | ||
| number() { | ||
| ns_hex_to_dec "$(ns_json_get "$syncing" "$1")" || echo 0 | ||
| } | ||
| current=$(number .currentBlock) | ||
| highest=$(number .highestBlock) | ||
|
|
||
| # The head is past genesis: the state is complete | ||
| if [ "$current" -gt 0 ]; then | ||
| if [ "$highest" -gt $((current + MAX_DISTANCE_FOR_SYNCED)) ]; then | ||
| ns_emit syncing "$@" phase="Catching up" position="$current" target="$highest" | ||
| exit $? | ||
| fi | ||
| # At the head and still reported as syncing: old bodies and receipts are downloading | ||
| ns_emit syncing "$@" background="Downloading old blocks and receipts" | ||
| exit $? | ||
| fi | ||
|
|
||
| # No consensus client has given a target since the start | ||
| if [ "$highest" -eq 0 ]; then | ||
| ns_emit syncing "$@" phase="Downloading block headers" awaitingTarget=true | ||
| exit $? | ||
| fi | ||
|
|
||
| # Snap state download, measured from 2.3 on | ||
| processed=$(number .warpChunksProcessed) | ||
| amount=$(number .warpChunksAmount) | ||
| if [ "$amount" -gt 0 ]; then | ||
| if [ "$processed" -ge "$amount" ]; then | ||
| ns_emit syncing "$@" phase="Healing state" | ||
| exit $? | ||
| fi | ||
| ns_emit syncing "$@" phase="Downloading state" progress="$(jq -n "$processed * 100 / $amount")" | ||
| exit $? | ||
| fi | ||
|
|
||
| # Up to 2.2 nothing tells the header download, the state download and healing apart | ||
| ns_emit syncing "$@" phase="Downloading headers and state" | ||
| exit $? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.