Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@

- [#7408](https://github.com/ChainSafe/forest/pull/7408): Impl `Forest.IndexBackfill`, `Forest.IndexBackfillStatus` and `Forest.IndexBackfillCancel` RPC methods and the `forest-cli index backfill` command to back-fill the chain index (Ethereum mappings, events, block blooms) through the running daemon, so the node no longer needs to be stopped. An interrupted or cancelled run can be resumed with `--resume`.

- [#7270](https://github.com/ChainSafe/forest/issues/7270): Include `scripts/tests/ribasushi-rpc-checks` that tests Forest against the external Ribasushi dataset

### Changed

### Removed
Expand Down
82 changes: 82 additions & 0 deletions scripts/tests/ribasushi-rpc-checks/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
name: rpc-checks

# docker compose up --build --abort-on-container-exit --exit-code-from rpc-checks

x-env: &env
CHAIN: ${CHAIN:-calibnet}
DAYS_AGO: ${DAYS_AGO:-2}
EPOCHS: ${EPOCHS:-1000}

services:
snapshot:
image: alpine:3.24
environment: *env
volumes:
- ./snapshots:/snapshots
entrypoint: ["/bin/sh", "-euc"]
command:
- |
apk add --no-cache curl jq >/dev/null

# validates DAYS_AGO and EPOCHS

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

pretty complex on its own - best to put it into a dedicated bash script so that shellcheck linter can nicely check it. It's also pretty obscure unreadable bash (not your fault, it's just bash) with regexes, so plenty of comments are needed to assert the logic is sound.

case "$$DAYS_AGO" in ''|*[!0-9]*) echo "DAYS_AGO must be a non-negative integer: '$$DAYS_AGO'"; exit 1;; esac
case "$$EPOCHS" in ''|*[!0-9]*) echo "EPOCHS must be a non-negative integer: '$$EPOCHS'"; exit 1;; esac
[ "$$EPOCHS" -ge 1 ] || { echo "EPOCHS must be at least 1"; exit 1; }

day=$$(date -u -d "@$$(( $$(date -u +%s) - DAYS_AGO * 86400 ))" +%F)
url=$$(curl -sSf --connect-timeout 10 --retry 3 \

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

unless a flag is obvious, e.g., rm -rf, I recommend using full versions of the params, e.g., --silent instead of -s. Then a reader doesn't need a PhD in cURL to parse the file.

"https://forest-archive.chainsafe.dev/list/$$CHAIN/latest-v2?format=json" |
jq -r --arg d "$$day" '[.items[].url | select(contains("_"+$$d+"_"))] | first')
[ "$$url" != null ] || { echo "no $$CHAIN snapshot for $$day"; exit 1; }

file=$$(basename "$$url")
head=$$(echo "$$file" | sed 's/.*_height_\([0-9]*\)\..*/\1/')
Comment thread
EclesioMeloJunior marked this conversation as resolved.
case "$$head" in ''|*[!0-9]*) echo "could not parse a height from '$$file'"; exit 1;; esac
[ "$$EPOCHS" -le "$$head" ] || { echo "EPOCHS ($$EPOCHS) exceeds head ($$head)"; exit 1; }

# only downloads if the snapshot is not present
[ -f "/snapshots/$$file" ] ||
curl -sSfL --connect-timeout 10 --retry 3 -o "/snapshots/$$file" "$$url"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

cURL is pretty bad at downloading large files such as snapshots - a better option would be to use aria2c with, e.g., -x5 set.


# define env vars used later on the next services
printf 'SNAPSHOT=%s\nSTART=%s\nEND=%s\nBACKFILL=%s\n' \
"$$file" "$$((head - EPOCHS))" "$$((head - 1))" "$$((EPOCHS + 1))" > /snapshots/env
cat /snapshots/env

# The RPC port opens only after the backfill finishes, so "healthy" means ready.
forest:
image: ghcr.io/chainsafe/forest:latest

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Re-think your options. Hint: latest is a bad option - why?

https://docs.forest.chainsafe.io/knowledge_base/docker_tips#tags

depends_on:
snapshot:
condition: service_completed_successfully
environment: *env
volumes:
- ./snapshots:/snapshots:ro
ports:
- "2345:2345"
entrypoint: ["/bin/sh", "-euc"]
command:
- |
. /snapshots/env
exec forest-tool api serve "/snapshots/$$SNAPSHOT" --chain "$$CHAIN" \
--port 2345 --height 0 --index-backfill-epochs "$$BACKFILL"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why --height 0?

healthcheck:
test: ["CMD", "forest-cli", "chain", "head"]
interval: 15s
timeout: 10s
retries: 480
Comment on lines +63 to +67

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So... potentially 20h for the probe to fail?


rpc-checks:
image: ghcr.io/chainsafe/forest-rpc-checks:latest
depends_on:
forest:
condition: service_healthy
environment:
FOREST_RPC_URL: forest:2345/rpc/v1
volumes:
- ./snapshots:/snapshots:ro
entrypoint: ["/bin/sh", "-euc"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you just use the image directly?

command:
- |
. /snapshots/env
exec bundle exec ruby check_rpc.rb "$$START" "$$END"
Comment thread
EclesioMeloJunior marked this conversation as resolved.
Loading