feat(p2p/sensor): add ClickHouse database backend#961
Open
minhd-vu wants to merge 2 commits into
Open
Conversation
Add a ClickHouse backend for the p2p sensor as an alternative to GCP Datastore, selectable with --database=clickhouse --clickhouse-dsn. - Implements the Database interface with client-side batched, append-only writes (no read-before-write) via a generic drop-on-full rowBatcher, so the sensor hot path never blocks on the database. - Recovers and stores the block signer at ingest (util.Ecrecover), matching the sensor's block-signer validation and the data-analysis tools. - Adds an integration test (skipped unless POLYCLI_TEST_CLICKHOUSE_DSN is set) verifying writes and signer round-trip against a real server. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Persist the remaining header fields (uncle hash, roots, logs bloom, extra data, mix digest, nonce) so downstream consumers (panoptichain, data-analysis) can reconstruct the header and re-run bor/clique ecrecover. Cheap on ClickHouse: the Datastore cost was index bloat, not these values. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



Summary
Adds a ClickHouse backend for the
polycli p2p sensor, as a cheaper alternative to GCP Datastore. Selectable via--database=clickhouse --clickhouse-dsn=clickhouse://user:pass@host:9000/sensor.Part of the sensor Datastore→ClickHouse migration (Datastore currently ~$14–15k/mo, dominated by read-before-write dedup ops; ClickHouse's append-only model + columnar storage removes that).
What's included
p2p/database/clickhouse.go— implements theDatabaseinterface:rowBatcher(buffered channel + background flusher). TheWrite*calls only enqueue, so the sensor hot path never blocks; a slow/down DB drops rows rather than exhausting memory. No read-before-write.ReplacingMergeTreesemantics on the target schema for dedup/merge.util.Ecrecover), consistent with--validate-block-signerand the data-analysis tools, so signer-based analytics don't re-ecrecoverper query.HasBlockis a cheap indexed point lookup;NodeListis the recent-distinct-peers query.cmd/p2p/sensor/sensor.go—--database=clickhousecase,--clickhouse-dsnflag, params field, help text.p2p/database/clickhouse_test.go— integration test, skipped unlessPOLYCLI_TEST_CLICKHOUSE_DSNis set; verifies write batching, field round-trip, and signer recovery against a real ClickHouse.github.com/ClickHouse/clickhouse-go/v2.Testing
make build,go vet,gofmt, andgo test ./p2p/database/all pass. Integration test verified against a dockerized ClickHouse:Notes
none.🤖 Generated with Claude Code