Skip to content

bootstrap enabled token verifier#904

Merged
winder merged 14 commits intomainfrom
will/bootstrap-token-verifier
Mar 16, 2026
Merged

bootstrap enabled token verifier#904
winder merged 14 commits intomainfrom
will/bootstrap-token-verifier

Conversation

@winder
Copy link
Copy Markdown
Collaborator

@winder winder commented Mar 12, 2026

  • Adopt the bootstrap interface for TokenVerifier by splitting the existing token verifier main.go entrypoint into separate Start and Stop functions.
  • Add new options to bootstrap to support running with direct configurations as an alternative to JD.

Comment on lines 190 to -208
}
go func() {
lggr.Infow("🌐 HTTP API server starting", "port", "8100")
if err := httpServer.ListenAndServe(); err != nil && err != http.ErrServerClosed {
lggr.Errorw("HTTP server error", "error", err)
tvf.lggr.Infow("🌐 HTTP API server starting", "port", "8100")
if err := tvf.httpServer.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
// TODO: how to register an error with the bootstrapper?
tvf.lggr.Errorw("HTTP server error", "error", err)
}
}()

lggr.Infow("🎯 Verifier service fully started and ready!")

// Wait for shutdown signal
<-sigCh
lggr.Infow("🛑 Shutdown signal received, stopping verifier...")

// Graceful shutdown
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 30*time.Second)
defer shutdownCancel()

if err := httpServer.Shutdown(shutdownCtx); err != nil {
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This part moved to the Stop function.

@winder winder force-pushed the will/bootstrap-token-verifier branch from f6667ad to c20db88 Compare March 13, 2026 12:52
Comment thread bootstrap/bootstrap.go Outdated
Comment on lines +195 to +200
if b.jdConfig != nil {
return b.startWithJDLifecycle(ctx)
}
if b.appCfg != nil {
return b.startWithAppConfig(ctx)
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The new With options essentially toggle whether the JD lifecycle object is used or if the start/stop functions are called directly.

Comment thread bootstrap/bootstrap.go
Comment on lines -169 to +217
func (b *Bootstrapper[AppConfig]) connectToDB(ctx context.Context) (*sqlx.DB, error) {
db, err := sqlx.ConnectContext(ctx, "postgres", b.cfg.DB.URL)
func connectToDB(ctx context.Context, connStr string) (*sqlx.DB, error) {
db, err := sqlx.ConnectContext(ctx, "postgres", connStr)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Pure functions simplify testing.

Comment thread bootstrap/bootstrap.go
Comment on lines -244 to -252
configPath := os.Getenv(ConfigPathEnv)
if configPath == "" {
configPath = DefaultConfigPath
}

cfg, err := LoadConfig(configPath)
if err != nil {
return fmt.Errorf("failed to load config: %w", err)
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Moved into the constructor so that the config path can be controlled via Options.

Comment on lines +12 to +16
err := bootstrap.Run(
"TokenVerifier",
&tokenVerifierFactory{},
// TODO: remove the AppConfig generic type to streamline this API, update factory to accept config as a string.
bootstrap.WithTOMLAppConfig[token.ConfigWithBlockchainInfos]("/etc/config.toml"),
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

New bootstrap function configured to use the config as AppConfig rather than JD Lifecycle Config.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Copy/pasted from the original main() function and split into Start/Stop functions.

Comment thread verifier/token/job.go Outdated
Comment thread verifier/token/load.go Outdated
Comment thread bootstrap/bootstrap.go Outdated
Comment thread bootstrap/bootstrap.go
db, err := b.connectToDB(ctx)
// startWithAppConfig is a passthrough to the application's Start function.
func (b *Bootstrapper[AppConfig]) startWithAppConfig(ctx context.Context) error {
return b.fac.Start(ctx, *b.appCfg, ServiceDeps{})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I wonder if we'd still wanna pass in the keystore in this app config passthru mode... I guess I'm a fan of being consistent where possible

The token verifier doesn't need it right now but future apps might

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Maybe its as simple as calling connectToDB and initializeKeystore above

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agree. In my first attempt I had several options like WithJD(), WithDB(), WithKeystore(), etc. I think it makes a lot of sense to treat these as different components the app can request from the bootstrap layer.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We need to have a discussion about what interface we want to expose from the bootstrapper.

I'm starting to think it should launch the app being bootstrapped in a separate process rather than being compiled in.

Comment thread bootstrap/bootstrap.go Outdated
Comment thread bootstrap/config.go Outdated
Comment thread cmd/verifier/committee/servicefactory.go Outdated
Comment on lines +114 to +115
registry := accessors.NewRegistry(blockchainHelper)
cmd.RegisterEVM(ctx, registry, tvf.lggr, blockchainHelper, config.OnRampAddresses, config.RMNRemoteAddresses)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

To make this chain-agnostic I think we need something similar to what we have for commit, where the accessor factory is created and returns the chain-specific impls of the source readers

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can do in a follow up though

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Makes sense, this PR was focusing on installing the bootstrap layer. Extracting the factory registration makes sense as a followup.

Comment thread verifier/token/job.go Outdated
Comment thread verifier/token/load.go Outdated
@winder winder force-pushed the will/bootstrap-token-verifier branch from 818496f to 6200bec Compare March 13, 2026 15:37
@github-actions
Copy link
Copy Markdown

Code coverage report:

Package main will/bootstrap-token-verifier diff
github.com/smartcontractkit/chainlink-ccv/aggregator 48.04% 48.04% +0.00%
github.com/smartcontractkit/chainlink-ccv/bootstrap 39.78% 42.35% +2.57%
github.com/smartcontractkit/chainlink-ccv/cmd 0.00% 0.00% +0.00%
github.com/smartcontractkit/chainlink-ccv/committee 100.00% 100.00% +0.00%
github.com/smartcontractkit/chainlink-ccv/common 52.89% 52.89% +0.00%
github.com/smartcontractkit/chainlink-ccv/executor 48.05% 48.05% +0.00%
github.com/smartcontractkit/chainlink-ccv/indexer 36.67% 36.68% +0.01%
github.com/smartcontractkit/chainlink-ccv/integration 45.57% 45.68% +0.11%
github.com/smartcontractkit/chainlink-ccv/pkg 100.00% 100.00% +0.00%
github.com/smartcontractkit/chainlink-ccv/pricer 0.00% 0.00% +0.00%
github.com/smartcontractkit/chainlink-ccv/protocol 64.82% 64.82% +0.00%
github.com/smartcontractkit/chainlink-ccv/verifier 41.83% 41.83% +0.00%

@winder winder marked this pull request as ready for review March 13, 2026 18:19
@winder winder requested review from a team and skudasov as code owners March 13, 2026 18:20
@winder winder requested a review from mateusz-sekara March 13, 2026 18:20
@winder winder requested a review from makramkd March 13, 2026 18:20
@winder winder added this pull request to the merge queue Mar 16, 2026
Merged via the queue into main with commit cc903fd Mar 16, 2026
23 checks passed
@winder winder deleted the will/bootstrap-token-verifier branch March 16, 2026 15:26
@winder winder changed the title WIP: bootstrap enabled token verifier bootstrap enabled token verifier Mar 19, 2026
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