Skip to content

refactor: simplify genesis resolution and clean up sidecar task handlers#49

Merged
bdchatham merged 12 commits intomainfrom
refactor/typed-handlers
Mar 31, 2026
Merged

refactor: simplify genesis resolution and clean up sidecar task handlers#49
bdchatham merged 12 commits intomainfrom
refactor/typed-handlers

Conversation

@bdchatham
Copy link
Copy Markdown
Contributor

@bdchatham bdchatham commented Mar 31, 2026

Summary

  • Genesis simplification: All genesis/ceremony task handlers now derive S3 coordinates from environment variables (SEI_GENESIS_BUCKET, SEI_GENESIS_REGION, SEI_CHAIN_ID) instead of receiving them as task params. Genesis resolution: embedded sei-config first, S3 fallback at {bucket}/{chainID}/genesis.json.
  • Bump sei-config to v0.0.9: Corrected embedded genesis files for pacific-1, atlantic-2, arctic-1
  • Remove dead code: CommandRunner type, parseUploadConfig, stale S3 fields from client task types
  • Fix readLocalNodeID: Now derives node ID from Ed25519 key (matching CometBFT's p2p.PubKeyToID), instead of assuming a top-level "id" field in node_key.json
  • Consistency fixes: ConfigPatcher rejects empty files, SEI_SNAPSHOT_UPLOAD_INTERVAL fails fast on invalid value, stale doc comments cleaned up
  • Env var validation: serve.go validates SEI_CHAIN_ID, SEI_GENESIS_BUCKET, SEI_GENESIS_REGION at startup

Deployment notes

  • Requires sei-k8s-controller to inject SEI_GENESIS_BUCKET and SEI_GENESIS_REGION into sidecar pod specs (see sei-protocol/sei-k8s-controller refactor/genesis-env-driven branch)
  • Controller must deploy before this sidecar — new sidecar requires env vars that the new controller injects

Test plan

  • go test ./sidecar/... — all pass (pre-existing TestExportS3UploaderFactoryError unrelated)
  • Genesis embedded path tested (pacific-1, atlantic-2)
  • Genesis S3 fallback tested (unknown chain)
  • Ceremony tasks tested (upload artifacts, assemble genesis, set peers)
  • TypedHandler deserialization integration tests pass for all 17 task types
  • Deploy controller with env var injection, then deploy new sidecar image
  • Verify genesis ceremony end-to-end on dev cluster

🤖 Generated with Claude Code

bdchatham and others added 12 commits March 31, 2026 10:25
Introduce engine.TypedHandler[T] — a generic helper that wraps typed
handler functions into TaskHandler. Each handler now receives its own
typed params struct instead of parsing map[string]any.

The TypedHandler bridges map[string]any → json.Marshal → json.Unmarshal
→ typed struct, giving handlers compile-time type safety without
changing the engine, store, server, or client.

All manual parse functions removed:
  parseSnapshotConfig, parseUploadConfig, parseExportConfig,
  parseAssembleConfig, parseNodeNames, parseArtifactUploadConfig,
  parseGenesisPeersConfig, parseGenesisS3Config, intentFromParams,
  extractStringMap, parseSources, parseEC2TagsSource, parseStaticSource,
  toStringMap, toStringSlice, parseTargetHeight

The float64/int64/json.Number type switches in await_condition and
statesync are eliminated — json.Unmarshal into int64 handles it.

20 files changed, net -241 lines.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… tests

Rename all task param structs from xConfig/xParams to xRequest:
  SnapshotConfig → SnapshotRestoreRequest
  SnapshotUploadConfig → SnapshotUploadRequest
  configPatchParams → ConfigPatchRequest
  ResultExportConfig → ResultExportRequest
  StateSyncParams → StateSyncRequest
  awaitConditionParams → AwaitConditionRequest
  genesisParams → ConfigureGenesisRequest
  genesisPeersConfig → SetGenesisPeersRequest
  identityParams → GenerateIdentityRequest
  gentxParams → GenerateGentxRequest
  assembleConfig → AssembleGenesisRequest
  artifactUploadConfig → UploadArtifactsRequest
  peerDiscoverParams → DiscoverPeersRequest
  configReloadParams → ConfigReloadRequest
  peerSourceConfig → PeerSourceEntry

All structs now exported for external consumers.

Add exhaustive TypedHandler tests:
  - Happy path, malformed JSON, nil params, nested structs, float64→int64
  - Integration tests for all 15 handler deserialization paths

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace explicit URI/region task params with environment-driven
resolution. The fetcher now checks sei-config embedded genesis first,
then falls back to S3 at {bucket}/{chainID}/genesis.json using
SEI_GENESIS_BUCKET and SEI_GENESIS_REGION env vars.

Bump sei-config to v0.0.9 (corrected embedded genesis files).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The sidecar now resolves genesis from chainId alone using sei-config
embedded lookup with S3 fallback. The client no longer needs to send
explicit S3 coordinates.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Remove S3 bucket/prefix/region from ceremony task params
(upload-genesis-artifacts, assemble-and-upload-genesis,
set-genesis-peers). These are now derived from SEI_GENESIS_BUCKET,
SEI_GENESIS_REGION, and SEI_CHAIN_ID env vars at construction time.
The S3 prefix is deterministic: {chainID}/.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…bleAndUploadGenesisTask

Match the simplified handler request types — S3 coordinates are
derived by the sidecar from its environment.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
H1: Remove dead parseUploadConfig and its test (TypedHandler artifact)
H2: (deferred — SubmitSetGenesisPeersTask not needed until controller uses it)
H4: Fix readLocalNodeID to derive node ID from Ed25519 key, matching
    CometBFT's p2p.PubKeyToID derivation (was incorrectly assuming
    top-level "id" field in node_key.json)
M2: ConfigPatcher now rejects empty files (consistent with client validation)
M4: Add AccountBalance and Namespace to client AssembleAndUploadGenesisTask
M7: Remove dead CommandRunner type and DefaultCommandRunner, update all
    constructors (NewIdentityGenerator, NewGentxGenerator, NewGenesisAssembler)
L1: Fix stale ListTasks doc comment
L2: Fail fast on invalid SEI_SNAPSHOT_UPLOAD_INTERVAL instead of silently
    falling back to default

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
# Conflicts:
#	sidecar/tasks/assemble_genesis.go
#	sidecar/tasks/assemble_genesis_test.go
#	sidecar/tasks/config.go
#	sidecar/tasks/genesis.go
#	sidecar/tasks/genesis_peers.go
#	sidecar/tasks/genesis_test.go
#	sidecar/tasks/typed_handler_integration_test.go
#	sidecar/tasks/upload_genesis_artifacts.go
The test expected nil (fail-safe) but Export() correctly propagates
the S3 uploader factory error. The test expectation was wrong.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@bdchatham bdchatham merged commit a9d71d2 into main Mar 31, 2026
2 checks passed
@bdchatham bdchatham deleted the refactor/typed-handlers branch March 31, 2026 22:34
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.

1 participant