Skip to content

Configurable attestations saving + validator handler reliability/observability#121

Open
kirill-simakov-p2p wants to merge 5 commits into
wealdtech:masterfrom
p2p-org:upstream-pr-attestations-and-handler
Open

Configurable attestations saving + validator handler reliability/observability#121
kirill-simakov-p2p wants to merge 5 commits into
wealdtech:masterfrom
p2p-org:upstream-pr-attestations-and-handler

Conversation

@kirill-simakov-p2p
Copy link
Copy Markdown

Summary

Three independent improvements we have been running on a fork for several weeks against mainnet and Hoodi nodes. Upstreaming now ahead of the in-flight #120 because two of the three touch files that overlap with that branch and we'd rather rebase you than ourselves.

1. blocks.attestations.enable configuration flag (default: true)

Mirrors the existing blocks.blobs.enable pattern added in #119. Lets operators skip writing attestations contained in blocks when they aren't needed downstream (typical case: backfilling old slots where attestations dominate write volume).

  • Configuration: new blocks.attestations.enable key
  • CLI: --blocks.attestations.enable
  • ENV: CHAIND_BLOCKS_ATTESTATIONS_ENABLE
  • Implementation: attestationsSaving parameter on the blocks service; updateAttestationsForBlock and updateElectraAttestationsForBlock return early when disabled

2. Detach validator handler from SSE event-stream context

The validator handler currently inherits the context of the head/finality SSE event that triggered it. When the event stream reconnects, that context is cancelled mid-write and partial writes are rolled back at the database boundary. We saw this manifest as repeated rollbacks under transient beacon-node disconnects.

Fix: derive a fresh context.Background() for the downstream balance write so transactions are not at the mercy of the SSE socket.

3. Fetch/write duration logs in validator balances handler

Adds fetch and write durations to the existing Balance epoch processed info log. We use these to diagnose backpressure between beacon RPC and Postgres, and to attribute slowdowns to the right side.

Tested

  • Local docker-compose build passes
  • Run against Hoodi for ~2 weeks without regression
  • Run against mainnet for ~3 weeks; flag attestations.enable=false cuts insert volume on t_attestations to zero as expected

Files

File Change
CHANGELOG.md dev entry (3 items)
README.md document blocks.attestations.enable
chaind.config.docker-compose.yml example entry
main.go CLI flag wiring
services/blocks/standard/{handler,parameters,service}.go attestations.enable
services/validators/standard/handler.go context detach + duration logs

Notes for review

  • I have not bumped ReleaseVersion; happy to add a commit if you want this on 0.10.3.
  • The three changes are independent. If any one is blocked I can split it into its own PR; otherwise keeping them together saves review overhead.

Same pattern as blocks.blobs.enable (commit fdc70b8). When set to false,
updateAttestationsForBlock and updateElectraAttestationsForBlock return
early without writing to t_attestations. Useful for backfill scenarios
where only deposit_requests and sync_committees are needed - avoids
writing ~144 GB of attestation data.
In go-eth2-client v0.27.1, head event handlers receive the SSE connection
context. When the SSE stream disconnects (Cloudflare timeout, network
issues), the context gets canceled and kills in-flight beacon state
downloads for validator balances (~325 MB, takes 8+ seconds).

This was not an issue with go-eth2-client v0.24.0 where handlers did not
receive the SSE context. The old DWH ChainD (v0.10.1-dbb, go-eth2-client
v0.24.0) works fine with the same beacon nodes for this reason.

Fix: use context.WithoutCancel() to detach from SSE context, restoring
the v0.24.0 behavior.
Log elapsed time for each step of epoch processing:
- validators fetch (state="head" download + DB compare)
- balances fetch + write per epoch
- total handler duration

Needed to diagnose why balance gap grows overnight
despite zero errors from CF/beacon node.
@kirill-simakov-p2p kirill-simakov-p2p marked this pull request as ready for review May 11, 2026 17:12
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