Skip to content
Open
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
63 changes: 63 additions & 0 deletions changelog/2026-11-23_indexer_unavailable_verifier_retry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Indexer retries a message when a configured verifier did not start

## Executive Summary

- When the reader of a configured verifier does not start, the indexer now counts that verifier as unavailable. The message retries until its deadline.
- Before this change, the task treated the address as unknown and ignored it. The message could become `SUCCESS` without the verifications of that verifier.
- Config validation now rejects an invalid or repeated issuer address in a verifier, so a config error stops the indexer at boot. Only a reader that does not start makes a verifier unavailable.
- Two new metrics show unavailable verifiers and the message attempts that they block.
- This change affects `indexer/pkg/registry`, `indexer/pkg/worker`, `indexer/pkg/config`, `indexer/pkg/monitoring`, `indexer/pkg/common` and `indexer/cmd`.
- It adds two registry methods, two labeler methods and one pool method. It has no schema changes.

## AI Adapter Index

| Symbol | Kind | Search | Location | Section |
|---|---|---|---|---|
| `worker.TaskResult.UnavailableCCVs` | behavior-changed | `UnavailableCCVs` | `indexer/pkg/worker/worker.go` | [#unavailable-ccvs-include-unstarted-verifiers](#unavailable-ccvs-include-unstarted-verifiers) |
| `registry.VerifierRegistry.MarkUnavailable`, `IsUnavailable` | added | `MarkUnavailable\(\|IsUnavailable\(` | `indexer/pkg/registry/verifier_registry.go` | [#registry-records-unstarted-verifiers](#registry-records-unstarted-verifiers) |
| `common.IndexerMetricLabeler.RecordVerifierUnavailableGauge`, `IncrementUnavailableVerifierRetries` | signature-changed | `IndexerMetricLabeler\b` | `indexer/pkg/common/metrics.go` | [#metrics](#metrics) |
| `worker.Pool.SetMetrics` | added | `SetMetrics\(` | `indexer/pkg/worker/worker_pool.go` | [#metrics](#metrics) |
| `config.Config.Validate` issuer addresses | behavior-changed | `IssuerAddresses` | `indexer/pkg/config/config.go` | [#config-validation-rejects-bad-issuer-addresses](#config-validation-rejects-bad-issuer-addresses) |

## Breaking Changes

### Config validation rejects bad issuer addresses

- **What changed:** `Config.Validate` rejects a `[[Verifiers]]` entry with an issuer address that is not valid hex, or with the same address two times. Before, startup skipped that verifier.
- The same address in two verifiers is still valid. HA setups use it.
- **Who is affected:** deploy configs with a bad issuer address. The indexer does not start until you correct the config.

### IndexerMetricLabeler has two new methods

- **Who is affected:** custom `IndexerMetricLabeler` implementations. Add the two methods in [Metrics](#metrics). Regenerate mocks with `just mock`.

## Migration Guide

1. Validate each deploy config before the rollout. Correct all invalid or repeated issuer addresses.
2. Add `RecordVerifierUnavailableGauge` and `IncrementUnavailableVerifierRetries` to custom `IndexerMetricLabeler` implementations.
3. Regenerate mocks: `just mock`.

## New Features / Additions

### Registry records unstarted verifiers

- `VerifierRegistry.MarkUnavailable(address, name)` records a configured address whose reader did not start, and its verifier name.
- `VerifierRegistry.IsUnavailable(address)` returns true when the address is marked and has no registered reader.
- `cmd/main.go` calls `MarkUnavailable` for each issuer address of a verifier that `createReadersForVerifier` skips.
- After the config validation, a skip occurs only when the reader cannot be created or started.

### Unavailable CCVs include unstarted verifiers

- `Task.loadVerifierReaders` returns a fourth list: the addresses that are configured but have no started reader.
- `Execute` adds these addresses to `TaskResult.UnavailableCCVs`. The worker retries a message while `UnavailableCCVs > 0`.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In what situation would we have a case of unavailable CCVs in practice? Seems like it would be very rare? Looking at the bootup toml code unknown Type is already rejected. deduplication is also done so there won't be duplicates. so most likely the error will be due to invalid Issuer address if they are hand-typed in the config. But even that comes from datastore

I generally agree that marking UNAVAILABLE is better than not even registering. But doesn't this open a silent delay in messages if there is a misconfigured verifier config. Because all messages will continue to retry until timeout because the verifier is unavailable. Would be nicer if this is caught before boot (like reject the toml invalid error)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes that's a good callout, we should catch as much as we can early in the config validation and only have unavailable in exceptional case. We should be loud about it if it ever happen so will add the metric there as well

- An address that is in no `[[Verifiers]]` entry stays unknown. The task logs it and does not count it, as before.
- **Why:** With more than one replica, each replica builds its own registry. A replica with a failed reader could set `SUCCESS` before the other replicas collect the missing verification.

## Metrics

- **Added:** `indexer_verifier_unavailable` (gauge, label `verifier`). It is 1 when a configured verifier has no started reader on this replica, else 0. Startup records it for each verifier. Alert when it is above 0.
- **Added:** `indexer_unavailable_verifier_retries_total` (counter, label `verifier`). It counts the message attempts that retry because the verifier has no started reader. `Pool.SetMetrics` gives the labeler to the tasks.

## Compatibility & Requirements

- **Rollout:** no special steps. The change applies per replica at startup.
9 changes: 9 additions & 0 deletions indexer/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ func main() {
if err != nil {
lggr.Fatalf("Failed to initalize worker pool: %v", err)
}
pool.SetMetrics(indexerMonitoring.Metrics())
pool.Start(ctx)
if leaderElector != nil {
leaderElector.Start(ctx)
Expand Down Expand Up @@ -230,8 +231,16 @@ func createAllVerifierReaders(ctx context.Context, lggr logger.Logger, verifierR
if err != nil {
lggr.Errorw("Skipping verifier, failed to create readers", "verifier", verifierConfig.Name, "error", err)
startupSkips.Skip(fmt.Sprintf("VerifierReader[%s]", verifierConfig.Name), err)
// Mark the addresses so tasks retry them; else this replica can set SUCCESS without this verifier.
for _, address := range verifierConfig.IssuerAddresses {
if a, parseErr := protocol.NewUnknownAddressFromHex(address); parseErr == nil {
verifierRegistry.MarkUnavailable(a, verifierConfig.Name)
}
}
indexerMonitoring.Metrics().RecordVerifierUnavailableGauge(ctx, verifierConfig.Name, true)
continue
}
indexerMonitoring.Metrics().RecordVerifierUnavailableGauge(ctx, verifierConfig.Name, false)
created++
}
if len(config.Verifiers) > 0 && created == 0 {
Expand Down
4 changes: 4 additions & 0 deletions indexer/pkg/common/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ type IndexerMetricLabeler interface {
RecordIndexerMessageDiscoveryLatency(ctx context.Context, latency time.Duration)
// RecordTimeToIndex records the total time between aggregation and indexing.
RecordTimeToIndex(ctx context.Context, latency time.Duration, discoveryType string)
// RecordVerifierUnavailableGauge records 1 when a configured verifier has no started reader, else 0.
RecordVerifierUnavailableGauge(ctx context.Context, verifier string, unavailable bool)
// IncrementUnavailableVerifierRetries counts a message attempt that retries because the verifier has no started reader.
IncrementUnavailableVerifierRetries(ctx context.Context, verifier string)
// RecordCircuitBreakerStatus records the status of the circuit breaker.
RecordCircuitBreakerStatus(ctx context.Context, status bool)
// RecordGRPCPayloadSize records the gRPC wire-level payload size in bytes.
Expand Down
20 changes: 20 additions & 0 deletions indexer/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/BurntSushi/toml"

"github.com/smartcontractkit/chainlink-ccv/common"
"github.com/smartcontractkit/chainlink-ccv/protocol"
hmacutil "github.com/smartcontractkit/chainlink-ccv/protocol/common/hmac"
)

Expand Down Expand Up @@ -437,6 +438,9 @@ func (c *Config) validate(withoutSecrets bool) error {
if err := v.Validate(i); err != nil {
return fmt.Errorf("verifier[%d] validation failed: %w", i, err)
}
if err := validateIssuerAddresses(v.IssuerAddresses); err != nil {
return fmt.Errorf("verifier[%d] validation failed: %w", i, err)
}
}

// Validate storage config
Expand Down Expand Up @@ -574,6 +578,22 @@ func (v *VerifierConfig) Validate(index int) error {
return validateMaxResponseBytes(v.MaxResponseBytes, fmt.Sprintf("verifier %d", index))
}

// validateIssuerAddresses rejects an invalid or repeated address; HA may repeat it across verifiers.
func validateIssuerAddresses(addresses []string) error {
seen := make(map[string]struct{}, len(addresses))
for _, address := range addresses {
a, err := protocol.NewUnknownAddressFromHex(address)
if err != nil {
return fmt.Errorf("invalid issuer address %q: %w", address, err)
}
if _, dup := seen[a.String()]; dup {
return fmt.Errorf("duplicate issuer address %q", address)
}
seen[a.String()] = struct{}{}
}
return nil
}

// Validate performs validation on the aggregator reader configuration.
func (a *AggregatorReaderConfig) Validate(index int) error {
if a.Address == "" {
Expand Down
26 changes: 26 additions & 0 deletions indexer/pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,3 +498,29 @@ func TestConfig_Validate_LeaderElectionNeedsTwoConnections(t *testing.T) {
require.NoError(t, newCfg(true, 2).Validate())
require.NoError(t, newCfg(false, 1).Validate())
}

func TestValidateIssuerAddresses(t *testing.T) {
const a = "0x1234567890abcdef1234567890abcdef12345678"
tests := []struct {
name string
addresses []string
errSub string
}{
{"accepts empty", nil, ""},
{"accepts valid addresses", []string{a, "0xabcdef1234567890abcdef1234567890abcdef12"}, ""},
{"rejects invalid hex", []string{"0xzz"}, "invalid issuer address"},
{"rejects duplicate", []string{a, a}, "duplicate issuer address"},
{"rejects duplicate with other casing", []string{a, "0x1234567890ABCDEF1234567890ABCDEF12345678"}, "duplicate issuer address"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err := validateIssuerAddresses(tt.addresses)
if tt.errSub == "" {
require.NoError(t, err)
return
}
require.Error(t, err)
assert.Contains(t, err.Error(), tt.errSub)
})
}
}
32 changes: 32 additions & 0 deletions indexer/pkg/monitoring/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ type IndexerMetrics struct {
discoveryLatencySeconds metric.Float64Histogram
timeToIndexSeconds metric.Float64Histogram
circuitBreakerStatus metric.Int64Gauge
verifierUnavailableGauge metric.Int64Gauge
unavailableVerifierRetries metric.Int64Counter

// gRPC client transport metrics
grpcPayloadSizeBytes metric.Int64Histogram
Expand Down Expand Up @@ -152,6 +154,20 @@ func InitMetrics() (im *IndexerMetrics, err error) {
return nil, fmt.Errorf("failed to register circuit breaker status gauge: %w", err)
}

im.verifierUnavailableGauge, err = beholder.GetMeter().Int64Gauge("indexer_verifier_unavailable",
metric.WithDescription("1 when a configured verifier has no started reader on this replica, else 0"),
)
if err != nil {
return nil, fmt.Errorf("failed to register verifier unavailable gauge: %w", err)
}

im.unavailableVerifierRetries, err = beholder.GetMeter().Int64Counter("indexer_unavailable_verifier_retries_total",
metric.WithDescription("Total number of message attempts that retry because a configured verifier has no started reader"),
)
if err != nil {
return nil, fmt.Errorf("failed to register unavailable verifier retries counter: %w", err)
}

im.grpcPayloadSizeBytes, err = beholder.GetMeter().Int64Histogram(
"indexer_grpc_payload_size_bytes",
metric.WithDescription("Wire-level gRPC payload size in bytes for aggregator client calls"),
Expand Down Expand Up @@ -336,6 +352,22 @@ func (c *IndexerMetricLabeler) RecordTimeToIndex(ctx context.Context, latency ti
}...), metric.WithAttributes(otelLabels...))
}

func (c *IndexerMetricLabeler) RecordVerifierUnavailableGauge(ctx context.Context, verifier string, unavailable bool) {
otelLabels := beholder.OtelAttributes(c.Labels).AsStringAttributes()
otelLabels = append(otelLabels, attribute.String("verifier", verifier))
var gaugeValue int64
if unavailable {
gaugeValue = 1
}
c.im.verifierUnavailableGauge.Record(ctx, gaugeValue, metric.WithAttributes(otelLabels...))
}

func (c *IndexerMetricLabeler) IncrementUnavailableVerifierRetries(ctx context.Context, verifier string) {
otelLabels := beholder.OtelAttributes(c.Labels).AsStringAttributes()
otelLabels = append(otelLabels, attribute.String("verifier", verifier))
c.im.unavailableVerifierRetries.Add(ctx, 1, metric.WithAttributes(otelLabels...))
}

func (c *IndexerMetricLabeler) RecordCircuitBreakerStatus(ctx context.Context, status bool) {
otelLabels := beholder.OtelAttributes(c.Labels).AsStringAttributes()
var gaugeValue int64
Expand Down
2 changes: 2 additions & 0 deletions indexer/pkg/monitoring/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ func (n *NoopIndexerMetricLabeler) RecordScannerPollingErrorsCounter(ctx context
func (n *NoopIndexerMetricLabeler) RecordVerificationRecordChannelSizeGauge(ctx context.Context, size int64) {
}
func (n *NoopIndexerMetricLabeler) RecordActiveReadersGauge(ctx context.Context, count int64) {}
func (n *NoopIndexerMetricLabeler) RecordVerifierUnavailableGauge(context.Context, string, bool) {}
func (n *NoopIndexerMetricLabeler) IncrementUnavailableVerifierRetries(context.Context, string) {}
func (n *NoopIndexerMetricLabeler) RecordDiscoveryLeaderGauge(ctx context.Context, isLeader bool) {}
func (n *NoopIndexerMetricLabeler) IncrementDiscoveryLeaderChanges(ctx context.Context) {}
func (n *NoopIndexerMetricLabeler) IncrementDiscoveryLeaderErrors(ctx context.Context, op string) {}
Expand Down
27 changes: 24 additions & 3 deletions indexer/pkg/registry/verifier_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ import (
type VerifierRegistry struct {
verifiers map[string][]*readers.VerifierReader
addrToName map[string]string
mu sync.RWMutex
// unavailable holds configured addresses whose reader did not start.
unavailable map[string]struct{}
mu sync.RWMutex
}

// NewVerifierRegistry creates and returns a new VerifierRegistry instance.
func NewVerifierRegistry() *VerifierRegistry {
return &VerifierRegistry{
verifiers: make(map[string][]*readers.VerifierReader),
addrToName: make(map[string]string),
verifiers: make(map[string][]*readers.VerifierReader),
addrToName: make(map[string]string),
unavailable: make(map[string]struct{}),
}
}

Expand Down Expand Up @@ -126,3 +129,21 @@ func (v *VerifierRegistry) GetVerifierNameFromAddress(address protocol.UnknownAd

return v.addrToName[address.String()]
}

// MarkUnavailable records a configured address whose reader did not start, so tasks retry it.
func (v *VerifierRegistry) MarkUnavailable(address protocol.UnknownAddress, name string) {
v.mu.Lock()
defer v.mu.Unlock()
v.unavailable[address.String()] = struct{}{}
if _, ok := v.addrToName[address.String()]; !ok {
v.addrToName[address.String()] = name
}
}

// IsUnavailable reports if address is configured but has no started reader.
func (v *VerifierRegistry) IsUnavailable(address protocol.UnknownAddress) bool {
v.mu.RLock()
defer v.mu.RUnlock()
_, ok := v.unavailable[address.String()]
return ok && len(v.verifiers[address.String()]) == 0
}
37 changes: 32 additions & 5 deletions indexer/pkg/worker/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ type Task struct {
registry *registry.VerifierRegistry
storage common.IndexerStorage
tracing commontracing.Tracing
traceParent string // discovery w3c traceparent
attempt int // 1-indexed
metrics common.IndexerMetricLabeler // optional
traceParent string // discovery w3c traceparent
attempt int // 1-indexed
runAt time.Time
index int // heap index
lastErr error
Expand Down Expand Up @@ -151,7 +152,7 @@ func (t *Task) collectVerifierResults(ctx context.Context, targets []verifierTar
return results
}

func (t *Task) loadVerifierReaders(verifierAddresses []string) (readerList []verifierTarget, loadedReaders, missingReaders []string) {
func (t *Task) loadVerifierReaders(verifierAddresses []string) (readerList []verifierTarget, loadedReaders, missingReaders, unavailable []string) {
for _, v := range verifierAddresses {
unknownAddress, err := protocol.NewUnknownAddressFromHex(v)
if err != nil {
Expand All @@ -163,7 +164,11 @@ func (t *Task) loadVerifierReaders(verifierAddresses []string) (readerList []ver
// multiple readers backed by different aggregators).
addrReaders := t.registry.GetVerifiers(unknownAddress)
if len(addrReaders) == 0 {
missingReaders = append(missingReaders, v)
if t.registry.IsUnavailable(unknownAddress) {
unavailable = append(unavailable, v)
} else {
missingReaders = append(missingReaders, v)
}
continue
}

Expand All @@ -173,7 +178,29 @@ func (t *Task) loadVerifierReaders(verifierAddresses []string) (readerList []ver
// normalize casing to lower-case hex strings to match getExistingVerifiers/getVerifiers
loadedReaders = append(loadedReaders, strings.ToLower(unknownAddress.String()))
}
return readerList, loadedReaders, missingReaders
return readerList, loadedReaders, missingReaders, unavailable
}

// recordUnavailableRetries counts one retry for each verifier in unavailable.
func (t *Task) recordUnavailableRetries(ctx context.Context, unavailable []string) {
if t.metrics == nil {
return
}
for _, address := range unavailable {
t.metrics.IncrementUnavailableVerifierRetries(ctx, t.verifierLabel(address))
}
}

// verifierLabel returns the configured name of address, or address when it has no name.
func (t *Task) verifierLabel(address string) string {
a, err := protocol.NewUnknownAddressFromHex(address)
if err != nil {
return address
}
if name := t.registry.GetVerifierNameFromAddress(a); name != "" {
return name
}
return address
}

func (t *Task) getMissingVerifiers(ctx context.Context) (missing []string, err error) {
Expand Down
33 changes: 31 additions & 2 deletions indexer/pkg/worker/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestTask_LoadVerifierReaders(t *testing.T) {
tsk := &Task{registry: reg, logger: lggr}

addrs := []string{addr1.String(), addr2.String()}
readersList, loaded, missing := tsk.loadVerifierReaders(addrs)
readersList, loaded, missing, _ := tsk.loadVerifierReaders(addrs)

require.Len(t, readersList, 1)
require.Len(t, loaded, 1)
Expand Down Expand Up @@ -170,7 +170,7 @@ func TestLoadVerifierReaders_InvalidAndLoaded(t *testing.T) {
tsk := &Task{registry: reg, logger: lggr}

addrs := []string{"not-a-hex", addr.String()}
readersList, loaded, missing := tsk.loadVerifierReaders(addrs)
readersList, loaded, missing, _ := tsk.loadVerifierReaders(addrs)

require.Len(t, readersList, 1)
require.Len(t, loaded, 1)
Expand Down Expand Up @@ -294,3 +294,32 @@ func TestCollectVerifierResults(t *testing.T) {
require.Equal(t, "verifier-2", res[0].Metadata.VerifierName)
})
}

// A configured verifier whose reader did not start is unstarted, not unknown, so the job retries.
func TestLoadVerifierReaders_UnstartedReader(t *testing.T) {
reg := registry.NewVerifierRegistry()
addr := mustAddr(t, "0x5555555555555555555555555555555555555555")
reg.MarkUnavailable(addr, "down-verifier")
tsk := &Task{registry: reg, logger: logger.Test(t)}

readersList, loaded, missing, unstarted := tsk.loadVerifierReaders([]string{addr.String()})

require.Empty(t, readersList)
require.Empty(t, loaded)
require.Empty(t, missing)
require.Equal(t, []string{addr.String()}, unstarted)
}

// Each unstarted verifier counts one retry under its configured name.
func TestRecordUnavailableRetries(t *testing.T) {
reg := registry.NewVerifierRegistry()
addr := mustAddr(t, "0x5555555555555555555555555555555555555555")
reg.MarkUnavailable(addr, "down-verifier")
m := mocks.NewMockIndexerMetricLabeler(t)
m.EXPECT().IncrementUnavailableVerifierRetries(mock.Anything, "down-verifier").Once()
tsk := &Task{registry: reg, logger: logger.Test(t), metrics: m}

tsk.recordUnavailableRetries(context.Background(), []string{addr.String()})

(&Task{registry: reg, logger: logger.Test(t)}).recordUnavailableRetries(context.Background(), []string{addr.String()})
}
Loading
Loading