From 8f1afd84a8b9cd06625f382fcadd457e5949ceac Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Thu, 29 Oct 2026 07:16:59 -0500 Subject: [PATCH 01/13] ConsensusQueue: wire no-op ReportingPlugin --- .../workflow-gateway-capabilities-don.toml | 2 +- core/services/internal/internal.go | 9 ++ core/services/ocr2/delegate.go | 39 +++-- core/services/ocr2/validate/validate.go | 11 ++ core/services/ocr3_1/plugins/queue/config.go | 14 ++ core/services/ocr3_1/plugins/queue/queue.go | 89 ++++++----- .../ocr3_1/plugins/queue/transmitter.go | 33 ++++ .../workflows/v2/capability_executor.go | 12 +- .../workflows/v2/capability_executor_test.go | 8 +- .../workflows/v2/triggers/triggers.go | 25 +++ .../jobs/pkg/templates/consensus-queue.tmpl | 14 ++ deployment/cre/jobs/propose_job_spec_test.go | 2 + system-tests/lib/cre/don.go | 2 +- .../lib/cre/environment/environment.go | 43 ++++++ system-tests/lib/cre/features/queue/queue.go | 146 ++++++++++++++++++ system-tests/lib/cre/features/sets/sets.go | 2 + system-tests/lib/cre/flags/provider.go | 2 + system-tests/lib/cre/types.go | 3 +- 18 files changed, 384 insertions(+), 72 deletions(-) create mode 100644 core/services/internal/internal.go create mode 100644 core/services/ocr3_1/plugins/queue/config.go create mode 100644 core/services/ocr3_1/plugins/queue/transmitter.go create mode 100644 deployment/cre/jobs/pkg/templates/consensus-queue.tmpl create mode 100644 system-tests/lib/cre/features/queue/queue.go diff --git a/core/scripts/cre/environment/configs/workflow-gateway-capabilities-don.toml b/core/scripts/cre/environment/configs/workflow-gateway-capabilities-don.toml index e9cf7c74544..a885c6e09ab 100644 --- a/core/scripts/cre/environment/configs/workflow-gateway-capabilities-don.toml +++ b/core/scripts/cre/environment/configs/workflow-gateway-capabilities-don.toml @@ -49,7 +49,7 @@ supported_evm_chains = [1337, 2337] env_vars = { CL_EVM_CMD = "", OTEL_SERVICE_NAME = "chainlink-node", CL_CRE_SETTINGS = '{"global":{"PerOrg":{"BaseTriggerRetransmitEnabled":"true"}}}' } - capabilities = ["cron", "http-action", "http-trigger", "consensus", "don-time", "evm-1337"] + capabilities = ["cron", "http-action", "http-trigger", "consensus", "don-time", "evm-1337", "consensus-queue"] registry_based_launch_allowlist = ["cron-trigger@1.0.0", "dontime@1.0.0"] # See ./examples/workflow-don-overrides.toml to learn how to override capability configs diff --git a/core/services/internal/internal.go b/core/services/internal/internal.go new file mode 100644 index 00000000000..7da30869133 --- /dev/null +++ b/core/services/internal/internal.go @@ -0,0 +1,9 @@ +package internal + +import "github.com/smartcontractkit/chainlink-common/pkg/capabilities/actions/vault" + +const ( + ConsensusQueueCapabilityID = "consensus-queue@1.0.0" + DontimeCapabilityID = "dontime@1.0.0" + VaultCapabilityID = vault.CapabilityID +) diff --git a/core/services/ocr2/delegate.go b/core/services/ocr2/delegate.go index 0f3c7cdf358..faa8c5befc5 100644 --- a/core/services/ocr2/delegate.go +++ b/core/services/ocr2/delegate.go @@ -60,6 +60,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/config/env" "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/v2/core/services/arbiter" + "github.com/smartcontractkit/chainlink/v2/core/services/internal" "github.com/smartcontractkit/chainlink/v2/core/services/job" "github.com/smartcontractkit/chainlink/v2/core/services/keystore" "github.com/smartcontractkit/chainlink/v2/core/services/llo" @@ -86,17 +87,17 @@ import ( ) const ( - vaultCapabilityID = "vault@1.0.0" + vaultCapabilityID = internal.VaultCapabilityID vaultOCRConfigKey = "vault" dkgOCRConfigKey = "dkg" - dontimeCapabilityID = "dontime@1.0.0" + dontimeCapabilityID = internal.DontimeCapabilityID // dontimeCapabilityPrefix matches any dontime version (e.g. "dontime@2.0.0"), // so the registry-driven launch guard keeps working if the version changes. dontimeCapabilityPrefix = "dontime" gaugeVaultDiskUsageBytes = "platform_vault_disk_usage_bytes" vaultDiskMonitorTickInterval = time.Minute - consensusQueueCapabilityID = "consensus-queue@1.0.0" + consensusQueueCapabilityID = internal.ConsensusQueueCapabilityID consensusQueueOCRConfigKey = "consensus-queue" gaugeConsensusQueueBytes = "platform_consensus_queue_usage_bytes" consensusQueueDiskMonitorTickInterval = time.Minute @@ -798,7 +799,11 @@ func (d *Delegate) newServicesConsensusQueue( ) (srvs []job.ServiceCtx, err error) { spec := jb.OCR2OracleSpec - // TODO ticket validate job spec + cfg := &queue.PluginConfig{} + err = json.Unmarshal(spec.PluginConfig.Bytes(), cfg) + if err != nil { + return nil, fmt.Errorf("failed to unmarshal plugin config: %w", err) + } rid, relayer, err := d.getRelayer(spec) if err != nil { @@ -826,7 +831,7 @@ func (d *Delegate) newServicesConsensusQueue( rid.Network, rid.ChainID, spec.ContractID, - synchronization.TelemetryType(types.VaultPlugin), + synchronization.TelemetryType(types.ConsensusQueue), ) ocrLogger := ocrcommon.NewOCRWrapper(lggr, d.cfg.OCR2().TraceLogging(), func(ctx context.Context, msg string) { @@ -859,7 +864,6 @@ func (d *Delegate) newServicesConsensusQueue( return nil, err } - // Get DKG config tracker and digester, optionally wrapping with OCRConfigService configTracker, configDigester, lc, err := d.maybeWrapConfigService(consensusQueueCapabilityID, consensusQueueOCRConfigKey, lggr, provider.ContractConfigTracker(), provider.OffchainConfigDigester(), lc) if err != nil { return nil, err @@ -869,19 +873,20 @@ func (d *Delegate) newServicesConsensusQueue( BinaryNetworkEndpointFactory: d.peerWrapper.Peer3_1, V2Bootstrappers: bootstrapPeers, ContractConfigTracker: configTracker, - ContractTransmitter: nil, // TODO ticket transmitter - Database: ocrDB, - KeyValueDatabaseFactory: kvFactory, - LocalConfig: lc, - Logger: ocrLogger, - MonitoringEndpoint: oracleEndpoint, - OffchainConfigDigester: configDigester, - OffchainKeyring: kb, - OnchainKeyring: ocr3shims.OnchainKeyringAsOnchainKeyring2(onchainKeyringAdapter), - MetricsRegisterer: prometheus.WrapRegistererWith(map[string]string{"job_name": jb.Name.ValueOrZero()}, prometheus.DefaultRegisterer), + //TODO pass engine as EventSink + ContractTransmitter: queue.NewTransmitter(lggr, ocrtypes.Account(spec.TransmitterID.String), nil), + Database: ocrDB, + KeyValueDatabaseFactory: kvFactory, + LocalConfig: lc, + Logger: ocrLogger, + MonitoringEndpoint: oracleEndpoint, + OffchainConfigDigester: configDigester, + OffchainKeyring: kb, + OnchainKeyring: ocr3shims.OnchainKeyringAsOnchainKeyring2(onchainKeyringAdapter), + MetricsRegisterer: prometheus.WrapRegistererWith(map[string]string{"job_name": jb.Name.ValueOrZero()}, prometheus.DefaultRegisterer), } - rpf, err := queue.NewConsensusQueuePluginFactory(lggr, d.limitsFactory) + rpf, err := queue.NewConsensusQueuePluginFactory(lggr, cfg, d.limitsFactory) if err != nil { return nil, err } diff --git a/core/services/ocr2/validate/validate.go b/core/services/ocr2/validate/validate.go index 5e2b8668e1a..687e3eb2a11 100644 --- a/core/services/ocr2/validate/validate.go +++ b/core/services/ocr2/validate/validate.go @@ -23,6 +23,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/job" ringconfig "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/ring/config" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/vault" + "github.com/smartcontractkit/chainlink/v2/core/services/ocr3_1/plugins/queue" "github.com/smartcontractkit/chainlink/v2/core/services/ocrcommon" "github.com/smartcontractkit/chainlink/v2/core/services/relay" "github.com/smartcontractkit/chainlink/v2/plugins" @@ -122,6 +123,8 @@ func validateSpec(ctx context.Context, tree *toml.Tree, spec job.Job, rc plugins return validateDonTimePluginSpec(spec.OCR2OracleSpec.PluginConfig) case types.RingPlugin: return validateRingPluginSpec(spec.OCR2OracleSpec.PluginConfig) + case types.ConsensusQueue: + return validateConsensusQueuePluginSpec(spec.OCR2OracleSpec.PluginConfig) case "": return errors.New("no plugin specified") default: @@ -323,3 +326,11 @@ func validateOCR2LLOSpec(jsonConfig job.JSONConfig) error { } return pkgerrors.Wrap(pluginConfig.Validate(), "LLO PluginConfig is invalid") } + +func validateConsensusQueuePluginSpec(jsonConfig job.JSONConfig) error { + cfg := &queue.PluginConfig{} + if err := json.Unmarshal(jsonConfig.Bytes(), &cfg); err != nil { + return fmt.Errorf("failed to unmarshal consensus queue plugin config: %w", err) + } + return cfg.Validate() +} diff --git a/core/services/ocr3_1/plugins/queue/config.go b/core/services/ocr3_1/plugins/queue/config.go new file mode 100644 index 00000000000..b63436ca646 --- /dev/null +++ b/core/services/ocr3_1/plugins/queue/config.go @@ -0,0 +1,14 @@ +package queue + +import ( + "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3_1types" +) + +type PluginConfig struct { + Limits ocr3_1types.ReportingPluginLimits `json:"limits,omitzero"` +} + +func (c *PluginConfig) Validate() error { + //TODO validate? + return nil +} diff --git a/core/services/ocr3_1/plugins/queue/queue.go b/core/services/ocr3_1/plugins/queue/queue.go index 27f76a0a775..73a3b43bf9c 100644 --- a/core/services/ocr3_1/plugins/queue/queue.go +++ b/core/services/ocr3_1/plugins/queue/queue.go @@ -2,13 +2,14 @@ package queue import ( "context" - "errors" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3_1types" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + "github.com/smartcontractkit/libocr/quorumhelper" "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/services" "github.com/smartcontractkit/chainlink-common/pkg/settings/limits" ) @@ -16,83 +17,87 @@ var _ ocr3_1types.ReportingPluginFactory[[]byte] = &consensusQueuePluginFactory{ type consensusQueuePluginFactory struct { lggr logger.Logger + cfg *PluginConfig } -func NewConsensusQueuePluginFactory(lggr logger.Logger, limitsFactory limits.Factory) (ocr3_1types.ReportingPluginFactory[[]byte], error) { +func NewConsensusQueuePluginFactory(lggr logger.Logger, cfg *PluginConfig, limitsFactory limits.Factory) (ocr3_1types.ReportingPluginFactory[[]byte], error) { // TODO pass CentralTriggerQueue, CapacityReporter, EngineRegistry // TODO construct limiters - return &consensusQueuePluginFactory{lggr: lggr}, nil + return &consensusQueuePluginFactory{lggr: lggr, cfg: cfg}, nil } func (c *consensusQueuePluginFactory) NewReportingPlugin(ctx context.Context, config ocr3types.ReportingPluginConfig, fetcher ocr3_1types.BlobBroadcastFetcher) (ocr3_1types.ReportingPlugin[[]byte], ocr3_1types.ReportingPluginInfo, error) { - plugin := newConsensusQueuePlugin(c.lggr) + plugin := newConsensusQueuePlugin(c.lggr, config) pluginInfo := ocr3_1types.ReportingPluginInfo1{ - Name: "ConsensusQueueReportingPlugin", - Limits: ocr3_1types.ReportingPluginLimits{ - // TODO limits - MaxQueryBytes: 0, - MaxObservationBytes: 0, - MaxReportsPlusPrecursorBytes: 0, - MaxReportBytes: 0, - MaxReportCount: 0, - MaxKeyValueModifiedKeys: 0, - MaxKeyValueModifiedKeysPlusValuesBytes: 0, - MaxBlobPayloadBytes: 0, - MaxPerOracleUnexpiredBlobCumulativePayloadBytes: 0, - MaxPerOracleUnexpiredBlobCount: 0, - }, + Name: "ConsensusQueueReportingPlugin", + Limits: c.cfg.Limits, } - return plugin, pluginInfo, nil + return plugin, pluginInfo, plugin.Start(ctx) } var _ ocr3_1types.ReportingPlugin[[]byte] = &consensusQueuePlugin{} type consensusQueuePlugin struct { - lggr logger.Logger + services.Service + eng *services.Engine + lggr logger.Logger + onchainCfg ocr3types.ReportingPluginConfig } -func newConsensusQueuePlugin(lggr logger.Logger) ocr3_1types.ReportingPlugin[[]byte] { - return &consensusQueuePlugin{lggr: logger.Named(lggr, "ConsensusQueuePlugin")} +func newConsensusQueuePlugin(lggr logger.Logger, onchainCfg ocr3types.ReportingPluginConfig) *consensusQueuePlugin { + c := &consensusQueuePlugin{lggr: logger.Named(lggr, "ConsensusQueuePlugin"), onchainCfg: onchainCfg} + c.Service, c.eng = services.Config{ + Name: "ConsensusQueueReportingPlugin", + Close: c.Close, + }.NewServiceEngine(lggr) + + return c } -func (c *consensusQueuePlugin) Query(ctx context.Context, seqNr uint64, keyValueStateReader ocr3_1types.KeyValueStateReader, blobBroadcastFetcher ocr3_1types.BlobBroadcastFetcher) (ocrtypes.Query, error) { - return nil, errors.ErrUnsupported +func (c *consensusQueuePlugin) Query(_ context.Context, _ uint64, _ ocr3_1types.KeyValueStateReader, _ ocr3_1types.BlobBroadcastFetcher) (ocrtypes.Query, error) { + return nil, nil } -func (c *consensusQueuePlugin) Observation(ctx context.Context, seqNr uint64, aq ocrtypes.AttributedQuery, keyValueStateReader ocr3_1types.KeyValueStateReader, blobBroadcastFetcher ocr3_1types.BlobBroadcastFetcher) (ocrtypes.Observation, error) { - // TODO observe queue via c.CentralTriggerQueue.TakeForObservation() - return nil, errors.ErrUnsupported +func (c *consensusQueuePlugin) Observation( + ctx context.Context, seqNr uint64, _ ocrtypes.AttributedQuery, kvState ocr3_1types.KeyValueStateReader, _ ocr3_1types.BlobBroadcastFetcher, +) (ocrtypes.Observation, error) { + return nil, nil } -func (c *consensusQueuePlugin) ValidateObservation(ctx context.Context, seqNr uint64, aq ocrtypes.AttributedQuery, ao ocrtypes.AttributedObservation, keyValueStateReader ocr3_1types.KeyValueStateReader, blobFetcher ocr3_1types.BlobFetcher) error { - return errors.ErrUnsupported +func (c *consensusQueuePlugin) ValidateObservation( + ctx context.Context, seqNr uint64, _ ocrtypes.AttributedQuery, ao ocrtypes.AttributedObservation, + _ ocr3_1types.KeyValueStateReader, _ ocr3_1types.BlobFetcher, +) error { + //TODO validate + return nil } -func (c *consensusQueuePlugin) ObservationQuorum(ctx context.Context, seqNr uint64, aq ocrtypes.AttributedQuery, aos []ocrtypes.AttributedObservation, keyValueStateReader ocr3_1types.KeyValueStateReader, blobFetcher ocr3_1types.BlobFetcher) (quorumReached bool, err error) { - return false, errors.ErrUnsupported +func (c *consensusQueuePlugin) ObservationQuorum( + ctx context.Context, seqNr uint64, _ ocrtypes.AttributedQuery, aos []ocrtypes.AttributedObservation, + _ ocr3_1types.KeyValueStateReader, _ ocr3_1types.BlobFetcher, +) (quorumReached bool, err error) { + return quorumhelper.ObservationCountReachesObservationQuorum(quorumhelper.QuorumTwoFPlusOne, c.onchainCfg.N, c.onchainCfg.F, aos), nil } -func (c *consensusQueuePlugin) StateTransition(ctx context.Context, seqNr uint64, aq ocrtypes.AttributedQuery, aos []ocrtypes.AttributedObservation, keyValueStateReadWriter ocr3_1types.KeyValueStateReadWriter, blobFetcher ocr3_1types.BlobFetcher) (ocr3_1types.ReportsPlusPrecursor, error) { - // TODO write to KV store - return nil, errors.ErrUnsupported +func (c *consensusQueuePlugin) StateTransition( + ctx context.Context, seqNr uint64, aq ocrtypes.AttributedQuery, aos []ocrtypes.AttributedObservation, + kvState ocr3_1types.KeyValueStateReadWriter, _ ocr3_1types.BlobFetcher, +) (ocr3_1types.ReportsPlusPrecursor, error) { + return ocr3_1types.ReportsPlusPrecursor{}, nil } func (c *consensusQueuePlugin) Committed(ctx context.Context, seqNr uint64, keyValueStateReader ocr3_1types.KeyValueStateReader) error { - return nil // no-op + return nil } func (c *consensusQueuePlugin) Reports(ctx context.Context, seqNr uint64, reportsPlusPrecursor ocr3_1types.ReportsPlusPrecursor) ([]ocr3types.ReportPlus[[]byte], error) { - return nil, errors.ErrUnsupported + return nil, nil } func (c *consensusQueuePlugin) ShouldAcceptAttestedReport(ctx context.Context, seqNr uint64, reportWithInfo ocr3types.ReportWithInfo[[]byte]) (bool, error) { - return false, errors.ErrUnsupported + return true, nil } func (c *consensusQueuePlugin) ShouldTransmitAcceptedReport(ctx context.Context, seqNr uint64, reportWithInfo ocr3types.ReportWithInfo[[]byte]) (bool, error) { - return false, errors.ErrUnsupported -} - -func (c *consensusQueuePlugin) Close() error { - return nil + return true, nil } diff --git a/core/services/ocr3_1/plugins/queue/transmitter.go b/core/services/ocr3_1/plugins/queue/transmitter.go new file mode 100644 index 00000000000..69ad7a77d04 --- /dev/null +++ b/core/services/ocr3_1/plugins/queue/transmitter.go @@ -0,0 +1,33 @@ +package queue + +import ( + "context" + + "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" + ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink/v2/core/services/workflows/v2/triggers" +) + +type contractTransmitter struct { + lggr logger.Logger + fromAccount ocrtypes.Account + eventSink triggers.EventSink +} + +func NewTransmitter(lggr logger.Logger, fromAccount ocrtypes.Account, eventSink triggers.EventSink) ocr3types.ContractTransmitter[[]byte] { + return &contractTransmitter{ + lggr: lggr, + fromAccount: fromAccount, + eventSink: eventSink, + } +} + +func (c *contractTransmitter) Transmit(ctx context.Context, digest ocrtypes.ConfigDigest, seqNum uint64, rpi ocr3types.ReportWithInfo[[]byte], signatures []ocrtypes.AttributedOnchainSignature) error { + return nil +} + +func (c *contractTransmitter) FromAccount(ctx context.Context) (ocrtypes.Account, error) { + return c.fromAccount, nil +} diff --git a/core/services/workflows/v2/capability_executor.go b/core/services/workflows/v2/capability_executor.go index c290d0095f5..a99de9f579b 100644 --- a/core/services/workflows/v2/capability_executor.go +++ b/core/services/workflows/v2/capability_executor.go @@ -23,6 +23,7 @@ import ( protoevents "github.com/smartcontractkit/chainlink-protos/workflows/go/events" eventsv2 "github.com/smartcontractkit/chainlink-protos/workflows/go/v2" "github.com/smartcontractkit/chainlink/v2/core/platform" + "github.com/smartcontractkit/chainlink/v2/core/services/internal" "github.com/smartcontractkit/chainlink/v2/core/services/workflows/metering" "github.com/smartcontractkit/chainlink/v2/core/services/workflows/store" ) @@ -411,16 +412,13 @@ func (c *ExecutionHelper) EmitUserMetric(ctx context.Context, metric *eventsv2.W return c.base.cfg.EventEmitter.EmitUserMetric(ctx, c.base.eventLabels(), metric) } -// dontimeCapabilityID matches the capability ID registered by the OCR2 delegate -// (core/services/ocr2/delegate.go). -const dontimeCapabilityID = "dontime@1.0.0" - // systemCapabilities lists capability IDs that are internal plumbing and must // not be callable from user workflow steps. var systemCapabilities = map[string]bool{ - confidentialWorkflowsCapabilityID: true, - vaultcommon.CapabilityID: true, - dontimeCapabilityID: true, + confidentialWorkflowsCapabilityID: true, + internal.VaultCapabilityID: true, + internal.DontimeCapabilityID: true, + internal.ConsensusQueueCapabilityID: true, } func isSystemCapability(capID string) bool { diff --git a/core/services/workflows/v2/capability_executor_test.go b/core/services/workflows/v2/capability_executor_test.go index 2ed9173b250..a99e5109b5f 100644 --- a/core/services/workflows/v2/capability_executor_test.go +++ b/core/services/workflows/v2/capability_executor_test.go @@ -14,10 +14,11 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/settings" "github.com/smartcontractkit/chainlink-common/pkg/settings/cresettings" "github.com/smartcontractkit/chainlink-common/pkg/settings/limits" - core "github.com/smartcontractkit/chainlink-common/pkg/types/core" + "github.com/smartcontractkit/chainlink-common/pkg/types/core" "github.com/smartcontractkit/chainlink-protos/cre/go/sdk" eventsv2 "github.com/smartcontractkit/chainlink-protos/workflows/go/v2" "github.com/smartcontractkit/chainlink/v2/core/logger" + "github.com/smartcontractkit/chainlink/v2/core/services/internal" ) func TestExecutionHelper_SystemCapabilityBlocked(t *testing.T) { @@ -157,8 +158,9 @@ func TestIsSystemCapability(t *testing.T) { want bool }{ {"confidential-workflows registered ID", confidentialWorkflowsCapabilityID, true}, - {"vault registered ID", vault.CapabilityID, true}, - {"dontime registered ID", dontimeCapabilityID, true}, + {"vault registered ID", internal.VaultCapabilityID, true}, + {"dontime registered ID", internal.DontimeCapabilityID, true}, + {"consensus queue registered ID", internal.ConsensusQueueCapabilityID, true}, {"confidential-workflows other version", "confidential-workflows@1.0.0", false}, {"vault other version", "vault@2.0.0", false}, {"vault unversioned", "vault", false}, diff --git a/core/services/workflows/v2/triggers/triggers.go b/core/services/workflows/v2/triggers/triggers.go index 74da564ed38..2b04f4a8761 100644 --- a/core/services/workflows/v2/triggers/triggers.go +++ b/core/services/workflows/v2/triggers/triggers.go @@ -12,8 +12,10 @@ import ( "golang.org/x/sync/errgroup" "google.golang.org/protobuf/encoding/protojson" "google.golang.org/protobuf/types/known/anypb" + "google.golang.org/protobuf/types/known/timestamppb" "github.com/smartcontractkit/chainlink-common/pkg/capabilities" + "github.com/smartcontractkit/chainlink-common/pkg/capabilities/pb" "github.com/smartcontractkit/chainlink-common/pkg/capabilities/registry" "github.com/smartcontractkit/chainlink-common/pkg/contexts" "github.com/smartcontractkit/chainlink-common/pkg/logger" @@ -151,6 +153,29 @@ type CoordinatedEvent struct { Event capabilities.TriggerResponse } +func (e *CoordinatedEvent) ToProto() *pb.CoordinatedEvent { + return &pb.CoordinatedEvent{ + WorkflowID: e.WorkflowID, + TriggerCapID: e.TriggerCapID, + TriggerIndex: int64(e.TriggerIndex), + ObservedAt: timestamppb.New(e.ObservedAt), + Deadline: timestamppb.New(e.Deadline), + SequenceNumber: e.SequenceNumber, + Event: pb.TriggerResponseToProto(e.Event), + } +} + +func (e *CoordinatedEvent) FromProto(p *pb.CoordinatedEvent) (err error) { + e.WorkflowID = p.WorkflowID + e.TriggerCapID = p.TriggerCapID + e.TriggerIndex = int(p.TriggerIndex) + e.ObservedAt = p.ObservedAt.AsTime() + e.Deadline = p.Deadline.AsTime() + e.SequenceNumber = p.SequenceNumber + e.Event, err = pb.TriggerResponseFromProto(p.Event) + return +} + // ReadLoop consumes triggerEventCh until it closes or ctx is done, // converting each received capabilities.TriggerResponse into a // CoordinatedEvent and handing it to deliver. diff --git a/deployment/cre/jobs/pkg/templates/consensus-queue.tmpl b/deployment/cre/jobs/pkg/templates/consensus-queue.tmpl new file mode 100644 index 00000000000..9f7d38356d8 --- /dev/null +++ b/deployment/cre/jobs/pkg/templates/consensus-queue.tmpl @@ -0,0 +1,14 @@ +type = "offchainreporting2" +schemaVersion = 1 +externalJobID = "{{ .ExternalJobID }}" +name = "{{ .JobName }}" +contractID = "{{ .ContractID }}" +ocrKeyBundleID = "{{ .OCR2EVMKeyBundleID }}" +p2pv2Bootstrappers = [ +{{ range .P2Pv2Bootstrappers }} "{{ . }}", +{{ end }}] +pluginType = "consensus-queue" +transmitterID = "{{ .TransmitterID }}" +relay = "evm" +[relayConfig] +chainID = "{{ .ChainID }}" diff --git a/deployment/cre/jobs/propose_job_spec_test.go b/deployment/cre/jobs/propose_job_spec_test.go index 8182079d7b5..4d25ebe9f6d 100644 --- a/deployment/cre/jobs/propose_job_spec_test.go +++ b/deployment/cre/jobs/propose_job_spec_test.go @@ -31,6 +31,7 @@ import ( "github.com/smartcontractkit/chainlink/deployment/cre/test" ) +// TODO add a subtest for ConsensusQueue func TestProposeJobSpec_VerifyPreconditions(t *testing.T) { j := jobs.ProposeJobSpec{} var env cldf.Environment @@ -508,6 +509,7 @@ func TestProposeJobSpec_VerifyPreconditions_Aptos(t *testing.T) { } } +// TODO add a subtest for ConsensusQueue func TestProposeJobSpec_Apply(t *testing.T) { h := test.NewTestHarness(t) env := new(h.Runtime.Environment()) diff --git a/system-tests/lib/cre/don.go b/system-tests/lib/cre/don.go index 46d0ed9d43e..585abd6b2e3 100644 --- a/system-tests/lib/cre/don.go +++ b/system-tests/lib/cre/don.go @@ -946,7 +946,7 @@ func HasFlag(values []string, capability string) bool { } for _, value := range values { - if strings.HasPrefix(value, capability+"-") { + if strings.HasPrefix(value, capability+"-") { //TODO collisions? return true } } diff --git a/system-tests/lib/cre/environment/environment.go b/system-tests/lib/cre/environment/environment.go index bcd91e893f2..51e01805129 100644 --- a/system-tests/lib/cre/environment/environment.go +++ b/system-tests/lib/cre/environment/environment.go @@ -288,6 +288,49 @@ func SetupTestEnvironment( // allow to pass custom job spec factories for extensibility jobSpecFactoryFunctions = append(jobSpecFactoryFunctions, input.JobSpecFactoryFunctions...) + // ConsensusQueue + //TODO remove - replaced by feature + //jobSpecFactoryFunctions = append(jobSpecFactoryFunctions, func(input *cre.JobSpecInput) (cre.DonJobs, error) { + // chainID, err := chainselectors.GetChainIDFromSelector(deployedBlockchains.RegistryChain().ChainSelector()) + // if err != nil { + // return nil, fmt.Errorf("failed to get chain ID from selector: %w", err) + // } + // evmChainID, err := strconv.ParseUint(chainID, 10, 64) + // if err != nil { + // return nil, fmt.Errorf("non-integer chain ID: %s: %w", chainID, err) + // } + // + // don := dons.MustWorkflowDON() + // + // bs, ok := dons.Bootstrap() + // if !ok { + // return nil, fmt.Errorf("failed to look up bootstrap node") + // } + // jobConfig := pkg.OCR3JobConfig{ + // JobName: "consensus-queue-test", + // ChainID: chainID, + // ContractID: "0x0000000000000000000000000000000000000000", // TODO + // P2Pv2Bootstrappers: []string{bs.Keys.P2PKey.PeerID.Raw() + "@" + bs.Host + ":" + strconv.Itoa(cre.OCRPeeringPort)}, + // ExternalJobID: uuid.NewV4().String(), // TODO deterministic? + // TemplateName: "consensus-queue", + // } + // + // var donJobs cre.DonJobs + // for _, node := range don.Nodes { + // jobConfig.P2PID = node.PeerID() + // jobConfig.OCR2EVMKeyBundleID = node.Keys.OCR2BundleIDs["evm"] + // jobConfig.TransmitterID = node.Keys.EVM[evmChainID].PublicAddress.String() + // + // jobSpec, err := jobConfig.ResolveJob() + // if err != nil { + // return nil, fmt.Errorf("failed to resolve OCR3 job spec: %w", err) + // } + // nodeID := node.JobDistributorDetails.NodeID + // donJobs = append(donJobs, &job.ProposeJobRequest{NodeId: nodeID, Spec: jobSpec}) + // } + // return donJobs, nil + //}) + createJobsDeps := CreateJobsWithJdOpDeps{ Logger: testLogger, SingleFileLogger: singleFileLogger, diff --git a/system-tests/lib/cre/features/queue/queue.go b/system-tests/lib/cre/features/queue/queue.go new file mode 100644 index 00000000000..eff5f9b3b5e --- /dev/null +++ b/system-tests/lib/cre/features/queue/queue.go @@ -0,0 +1,146 @@ +package queue + +import ( + "context" + "fmt" + "strconv" + + "dario.cat/mergo" + "github.com/google/uuid" + "github.com/pkg/errors" + "github.com/rs/zerolog" + + capabilitiespb "github.com/smartcontractkit/chainlink-common/pkg/capabilities/pb" + kcr "github.com/smartcontractkit/chainlink-evm/gethwrappers/keystone/generated/capabilities_registry_1_1_0" + cre_jobs "github.com/smartcontractkit/chainlink/deployment/cre/jobs" + cre_jobs_ops "github.com/smartcontractkit/chainlink/deployment/cre/jobs/operations" + job_types "github.com/smartcontractkit/chainlink/deployment/cre/jobs/types" + "github.com/smartcontractkit/chainlink/deployment/cre/ocr3" + "github.com/smartcontractkit/chainlink/deployment/cre/pkg/offchain" + keystone_changeset "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" + "github.com/smartcontractkit/chainlink/system-tests/lib/cre" + "github.com/smartcontractkit/chainlink/system-tests/lib/cre/contracts" + "github.com/smartcontractkit/chainlink/system-tests/lib/cre/don/jobs" +) + +const flag = cre.ConsensusQueueCapability + +const consensusQueueLabelledName = cre.ConsensusQueueCapability + +type ConsensusQueue struct{} + +func (o *ConsensusQueue) Flag() cre.CapabilityFlag { return flag } +func (o *ConsensusQueue) PreEnvStartup( + ctx context.Context, + testLogger zerolog.Logger, + don *cre.DonMetadata, + topology *cre.Topology, + creEnv *cre.Environment, +) (*cre.PreEnvStartupOutput, error) { + if !don.HasFlag(flag) { + return nil, nil + } + + return &cre.PreEnvStartupOutput{ + DONCapabilityWithConfig: []keystone_changeset.DONCapabilityWithConfig{{ + Capability: kcr.CapabilitiesRegistryCapability{ + LabelledName: consensusQueueLabelledName, + Version: "1.0.0", + CapabilityType: 2, // CONSENSUS + ResponseType: 0, // REPORT (not used) + }, + Config: &capabilitiespb.CapabilityConfig{ + LocalOnly: don.HasOnlyLocalCapabilities(), + }, + UseCapRegOCRConfig: true, + }}, + CapabilityToOCR3Config: map[string]*ocr3.OracleConfig{ + //TODO don't we need DefaultOCR3_1Config? + consensusQueueLabelledName: contracts.DefaultOCR3Config(), + }, + }, nil +} + +func (o *ConsensusQueue) PostEnvStartup( + ctx context.Context, + testLogger zerolog.Logger, + don *cre.Don, + dons *cre.Dons, + creEnv *cre.Environment, +) error { + if !don.HasFlag(flag) { + return nil + } + + err := createJobs(ctx, creEnv, don, dons) + if err != nil { + return fmt.Errorf("failed to create consensusQueue jobs: %w", err) + } + //TODO more? + return nil +} + +func createJobs( + ctx context.Context, + creEnv *cre.Environment, + don *cre.Don, + dons *cre.Dons, +) error { + bootstrap, isBootstrap := dons.Bootstrap() + if !isBootstrap { + return errors.New("could not find bootstrap node in topology, exactly one bootstrap node is required") + } + + peeringCfg, err := cre.PeeringCfgs(bootstrap) + if err != nil { + return errors.Wrap(err, "failed to get peering configs") + } + + input := cre_jobs.ProposeJobSpecInput{ + Domain: offchain.ProductLabel, + Environment: creEnv.CldfEnvironment.Name, + DONName: don.Name, + JobName: cre.ConsensusQueueCapability + "-worker", + ExtraLabels: map[string]string{cre.CapabilityLabelKey: cre.ConsensusQueueCapability}, + DONFilters: []offchain.TargetDONFilter{ + {Key: offchain.FilterKeyDONName, Value: don.Name}, + }, + Template: job_types.OCR3, + Inputs: job_types.JobSpecInput{ + "chainSelectorEVM": creEnv.RegistryChainSelector, + "contractQualifier": cre.ConsensusQueueCapability, + "templateName": cre.ConsensusQueueCapability, + "bootstrapperOCR3Urls": []string{peeringCfg.BootstrapperPeerID + "@" + peeringCfg.BootstrapperHost + ":" + strconv.Itoa(peeringCfg.Port)}, + }, + } + if creEnv.FreshExternalJobIDs { + input.Inputs["externalJobID"] = uuid.NewString() + } + if err := (cre_jobs.ProposeJobSpec{}).VerifyPreconditions(*creEnv.CldfEnvironment, input); err != nil { + return errors.Wrapf(err, "precondition verification failed for %s worker job", flag) + } + + report, err := (cre_jobs.ProposeJobSpec{}).Apply(*creEnv.CldfEnvironment, input) + if err != nil { + return errors.Wrapf(err, "failed to propose %s worker job spec", flag) + } + + // Proposing only queues the spec in Job Distributor; without approval the + // nodes never run it and the capability never registers locally. + specs := make(map[string][]string) + for _, r := range report.Reports { + out, ok := r.Output.(cre_jobs_ops.ProposeOCR3JobOutput) + if !ok { + return fmt.Errorf("unable to cast to ProposeOCR3JobOutput, actual type: %T", r.Output) + } + if mErr := mergo.Merge(&specs, out.Specs, mergo.WithAppendSlice); mErr != nil { + return errors.Wrapf(mErr, "failed to merge %s worker job specs", flag) + } + } + + if aErr := jobs.Approve(ctx, creEnv.CldfEnvironment.Offchain, dons, specs); aErr != nil { + return errors.Wrapf(aErr, "failed to approve %s worker jobs", flag) + } + + return nil +} diff --git a/system-tests/lib/cre/features/sets/sets.go b/system-tests/lib/cre/features/sets/sets.go index 8db4cb51b28..90c4bc8e9e7 100644 --- a/system-tests/lib/cre/features/sets/sets.go +++ b/system-tests/lib/cre/features/sets/sets.go @@ -11,6 +11,7 @@ import ( evm_feature "github.com/smartcontractkit/chainlink/system-tests/lib/cre/features/evm/v2" http_actions_feature "github.com/smartcontractkit/chainlink/system-tests/lib/cre/features/http_action" http_trigger_feature "github.com/smartcontractkit/chainlink/system-tests/lib/cre/features/http_trigger" + consensus_queue_feature "github.com/smartcontractkit/chainlink/system-tests/lib/cre/features/queue" solana_feature "github.com/smartcontractkit/chainlink/system-tests/lib/cre/features/solana/v2" stellar_feature "github.com/smartcontractkit/chainlink/system-tests/lib/cre/features/stellar" vault_feature "github.com/smartcontractkit/chainlink/system-tests/lib/cre/features/vault" @@ -30,5 +31,6 @@ func New() cre.Features { &vault_feature.Vault{}, &confidential_relay_feature.ConfidentialRelay{}, &confidential_workflows_feature.ConfidentialWorkflows{}, + &consensus_queue_feature.ConsensusQueue{}, ) } diff --git a/system-tests/lib/cre/flags/provider.go b/system-tests/lib/cre/flags/provider.go index e045aef025d..635af1e0021 100644 --- a/system-tests/lib/cre/flags/provider.go +++ b/system-tests/lib/cre/flags/provider.go @@ -21,6 +21,7 @@ func NewDefaultCapabilityFlagsProvider() *DefaultCapbilityFlagsProvider { cre.StellarCapability, cre.ConfidentialRelayCapability, cre.ConfidentialWorkflowsCapability, + cre.ConsensusQueueCapability, }, } } @@ -44,6 +45,7 @@ func NewExtensibleCapabilityFlagsProvider(extraGlobalFlags []string) *Extensible cre.HTTPActionCapability, cre.ConfidentialRelayCapability, cre.ConfidentialWorkflowsCapability, + cre.ConsensusQueueCapability, }, extraGlobalFlags...), chainSpecificCapabilities: []cre.CapabilityFlag{ cre.EVMCapability, diff --git a/system-tests/lib/cre/types.go b/system-tests/lib/cre/types.go index ae28fa68b2a..156befa9d2c 100644 --- a/system-tests/lib/cre/types.go +++ b/system-tests/lib/cre/types.go @@ -66,6 +66,7 @@ const ( ConfidentialRelayCapability CapabilityFlag = "confidential-relay" // ConfidentialWorkflowsCapability doubles as the enclave application name. ConfidentialWorkflowsCapability CapabilityFlag = "confidential-workflows" + ConsensusQueueCapability CapabilityFlag = "consensus-queue" AptosCapability CapabilityFlag = "aptos" StellarCapability CapabilityFlag = "stellar" // Add more capabilities as needed @@ -777,7 +778,7 @@ func (m *DonMetadata) StellarChains() []string { func (m *DonMetadata) RequiresOCR() bool { return slices.Contains(m.Flags, ConsensusCapability) || - slices.Contains(m.Flags, VaultCapability) || slices.Contains(m.Flags, EVMCapability) || slices.Contains(m.Flags, SolanaCapability) + slices.Contains(m.Flags, VaultCapability) || slices.Contains(m.Flags, ConsensusQueueCapability) || slices.Contains(m.Flags, EVMCapability) || slices.Contains(m.Flags, SolanaCapability) } func (m *DonMetadata) RequiresGateway() bool { From a2b6326bffc56988f50a7404eea65f0693d774ad Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Thu, 29 Oct 2026 07:08:19 -0500 Subject: [PATCH 02/13] core/services/ocr3_1/plugins/queue: ReportingPlugin implementation --- core/scripts/go.mod | 2 +- core/scripts/go.sum | 4 +- core/services/ocr3_1/plugins/queue/kvstate.go | 103 +++++++++++ core/services/ocr3_1/plugins/queue/queue.go | 175 +++++++++++++++++- .../ocr3_1/plugins/queue/transmitter.go | 26 +++ deployment/go.mod | 2 +- deployment/go.sum | 4 +- go.mod | 2 +- go.sum | 4 +- integration-tests/go.mod | 2 +- integration-tests/go.sum | 4 +- integration-tests/load/go.mod | 2 +- integration-tests/load/go.sum | 4 +- system-tests/lib/go.mod | 2 +- system-tests/lib/go.sum | 4 +- system-tests/tests/go.mod | 2 +- system-tests/tests/go.sum | 4 +- 17 files changed, 324 insertions(+), 22 deletions(-) create mode 100644 core/services/ocr3_1/plugins/queue/kvstate.go diff --git a/core/scripts/go.mod b/core/scripts/go.mod index 06e0341d330..433daf2ab63 100644 --- a/core/scripts/go.mod +++ b/core/scripts/go.mod @@ -29,7 +29,7 @@ require ( github.com/shopspring/decimal v1.4.0 github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261022195454-600e2b321c7a diff --git a/core/scripts/go.sum b/core/scripts/go.sum index a7b2fc3f3af..d09e43690ea 100644 --- a/core/scripts/go.sum +++ b/core/scripts/go.sum @@ -1686,8 +1686,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5 h1:mpb2dy2Cr3/J3d09u5L0vjOeA4SVPvk2VZcuOEWUopY= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5/go.mod h1:QeHe1mlcVzzg+awYAkRfl/8mDLRAhsl18IIOg4MVZec= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d h1:PmhBu41LVNATLXKNX+bzuRShPexHj2H4Ryi4HH1VBbc= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d/go.mod h1:ZRHl1hjJyTPrnv669e3thza3U7Z2as5zKCDZP0kJXuw= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= diff --git a/core/services/ocr3_1/plugins/queue/kvstate.go b/core/services/ocr3_1/plugins/queue/kvstate.go new file mode 100644 index 00000000000..39175f4bce3 --- /dev/null +++ b/core/services/ocr3_1/plugins/queue/kvstate.go @@ -0,0 +1,103 @@ +package queue + +import ( + "cmp" + "container/heap" + + "google.golang.org/protobuf/proto" + + "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3_1types" + + "github.com/smartcontractkit/chainlink-common/pkg/capabilities/pb" +) + +// KV store Keys +const ( + proposedEventsKey = "proposed_events::index" // proposed events waiting for consensus ( maxObservationSize { // too large, end of batch + // remove this one + obs.Events = obs.Events[:len(obs.Events)-1] + if addedCap { + delete(obs.WorkflowCapacities, id) + } + break + } + } + return protoOpts.Marshal(obs) } func (c *consensusQueuePlugin) ValidateObservation( @@ -83,13 +127,142 @@ func (c *consensusQueuePlugin) StateTransition( ctx context.Context, seqNr uint64, aq ocrtypes.AttributedQuery, aos []ocrtypes.AttributedObservation, kvState ocr3_1types.KeyValueStateReadWriter, _ ocr3_1types.BlobFetcher, ) (ocr3_1types.ReportsPlusPrecursor, error) { + var wg sync.WaitGroup + + // TODO In parallel: + var capacity int + var wfCapacity map[string]int + var observedProposals map[string][]uint8 // trigger event ID -> observer node IDs + var observedEvents map[string]*pb.CoordinatedEvent // trigger event ID -> event + go func() { + defer wg.Done() + + // - Aggregate each node’s view of how many trigger events we can pop from the KV store queue (i.e. how many executions we can start) + // - Aggregate the per workflow free capacity + // - Achieve quorum on observations -> any item with F+1 observations goes into the queue + // - Medianize the logical clock value in the observations to order events + }() + + // Deserialize the KV store into memory + state := newStateReadWriter(kvState) + proposedEvents, err := state.readProposedEvents() + if err != nil { + return nil, err + } + priorityQueue, err := state.readPriorityQueue() + if err != nil { + return nil, err + } + heap.Init(&priorityQueue) //TODO or can we trust it? + + //TODO prune expired events from proposed and priorityQueue + + wg.Wait() + + // Collect observed proposals and promote to priority queue on f+1 + for id, nodes := range observedProposals { + if obs, ok := proposedEvents.Observers[id]; !ok && len(nodes) >= c.onchainCfg.F+1 { + // new proposal straight to priority queue + heap.Push(&priorityQueue, proposedEvents.Events[id]) + continue + } else if !ok { + // new proposal < f + 1 + proposedEvents.Observers[id] = &pb.NodeIDList{Ids: nodes} + proposedEvents.Events[id] = observedEvents[id] + continue + } else if len(nodes) < c.onchainCfg.F+1 { + // update proposal + // TODO opt: build a map to avoid n^2? or nbd since n < f+1 + for _, node := range nodes { + if !slices.Contains(obs.Ids, node) { + obs.Ids = append(obs.Ids, node) + } + } + if len(obs.Ids) < c.onchainCfg.F+1 { + continue + } + } + // f+1 - promote proposal to priority queue + delete(proposedEvents.Observers, id) + delete(proposedEvents.Events, id) + heap.Push(&priorityQueue, proposedEvents.Events[id]) + } + + // Select items from queue based on priority and capacity + var consensusEvents []*pb.CoordinatedEvent + var workflowLimited []*pb.CoordinatedEvent // omitted due to workflow limit + for len(consensusEvents) < capacity { + if len(priorityQueue) == 0 { + break + } + next, ok := heap.Pop(&priorityQueue).(*pb.CoordinatedEvent) + if !ok { + return nil, fmt.Errorf("failed to cast *pb.CoordinatedEvent: got type %T", next) + } + if wfCapacity[next.WorkflowID] == 0 { + workflowLimited = append(workflowLimited, next) + continue + } + wfCapacity[next.WorkflowID]-- + consensusEvents = append(consensusEvents, next) + } + // restore omitted for next time + for _, event := range workflowLimited { + heap.Push(&priorityQueue, event) + } + + // Updated KV Store + err = state.writeProposedEvents(proposedEvents) + if err != nil { + return nil, err + } + err = state.writePriorityQueue(priorityQueue) + if err != nil { + return nil, err + } + err = state.writeConsensusEvents(&pb.CoordinatedEventList{Events: consensusEvents}) + if err != nil { + return nil, err + } + + // no report to return, executions start when committed return ocr3_1types.ReportsPlusPrecursor{}, nil } func (c *consensusQueuePlugin) Committed(ctx context.Context, seqNr uint64, keyValueStateReader ocr3_1types.KeyValueStateReader) error { + c.tryStartExecutions(keyValueStateReader) return nil } +// tryStartExecutions calls StartExecution asynchronously on the corresponding engine for each trigger event. +// It is idempotent, thus safe to call from Observation and Committed. +func (c *consensusQueuePlugin) tryStartExecutions(reader ocr3_1types.KeyValueStateReader) { + state := stateReader{reader} + pbs, err := state.readConsensusEvents() + if err != nil { + //TODO log? + return + } + errs := make([]error, len(pbs.Events)) + var wg sync.WaitGroup + for i, pbEvent := range pbs.Events { + var event triggers.CoordinatedEvent + if err := event.FromProto(pbEvent); err != nil { + errs[i] = fmt.Errorf("failed to unmarshal event: %s: %w", pbEvent, err) + continue + } + wg.Add(1) + c.eng.Go(func(ctx context.Context) { + defer wg.Done() + // TODO fetch workflow engine instance + // TODO execute StartExecution + errs[i] = nil + }) + } + wg.Wait() + //TODO process errors? or just log as we go? +} + func (c *consensusQueuePlugin) Reports(ctx context.Context, seqNr uint64, reportsPlusPrecursor ocr3_1types.ReportsPlusPrecursor) ([]ocr3types.ReportPlus[[]byte], error) { return nil, nil } diff --git a/core/services/ocr3_1/plugins/queue/transmitter.go b/core/services/ocr3_1/plugins/queue/transmitter.go index 69ad7a77d04..42c3ddeae95 100644 --- a/core/services/ocr3_1/plugins/queue/transmitter.go +++ b/core/services/ocr3_1/plugins/queue/transmitter.go @@ -2,10 +2,13 @@ package queue import ( "context" + "fmt" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + "google.golang.org/protobuf/proto" + "github.com/smartcontractkit/chainlink-common/pkg/capabilities/pb" "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink/v2/core/services/workflows/v2/triggers" ) @@ -25,6 +28,29 @@ func NewTransmitter(lggr logger.Logger, fromAccount ocrtypes.Account, eventSink } func (c *contractTransmitter) Transmit(ctx context.Context, digest ocrtypes.ConfigDigest, seqNum uint64, rpi ocr3types.ReportWithInfo[[]byte], signatures []ocrtypes.AttributedOnchainSignature) error { + //TODO relocate & replace with no-op? + var report pb.CoordinatedEventList + err := proto.Unmarshal(rpi.Report, &report) + if err != nil { + return fmt.Errorf("failed to unmarshal report: %w", err) + } + // Execute each event + for _, message := range report.Events { + var event triggers.CoordinatedEvent + if err := event.FromProto(message); err != nil { + c.lggr.Errorw("Failed to convert trigger event proto", "err", err) + continue + } + if c.eventSink == nil { + c.lggr.Warnw("Unable to execute trigger - no event sink configured", "event", event) + continue + } + err := c.eventSink.ExecuteTrigger(ctx, event) + if err != nil { + c.lggr.Errorw("Failed to execute trigger", "event", event, "err", err) + } + } + return nil } diff --git a/deployment/go.mod b/deployment/go.mod index aad81685f37..2d3cfc9be94 100644 --- a/deployment/go.mod +++ b/deployment/go.mod @@ -41,7 +41,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/solana/deployment v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-data-streams v1.1.2-0.20261009064810-68424c714170 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 diff --git a/deployment/go.sum b/deployment/go.sum index 84a162998f0..7c18de10579 100644 --- a/deployment/go.sum +++ b/deployment/go.sum @@ -1411,8 +1411,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5 h1:mpb2dy2Cr3/J3d09u5L0vjOeA4SVPvk2VZcuOEWUopY= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5/go.mod h1:QeHe1mlcVzzg+awYAkRfl/8mDLRAhsl18IIOg4MVZec= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d h1:PmhBu41LVNATLXKNX+bzuRShPexHj2H4Ryi4HH1VBbc= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d/go.mod h1:ZRHl1hjJyTPrnv669e3thza3U7Z2as5zKCDZP0kJXuw= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= diff --git a/go.mod b/go.mod index 7e8aca189bc..1ad05c537a6 100644 --- a/go.mod +++ b/go.mod @@ -82,7 +82,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260908155618-50f521d70e62 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260908155618-50f521d70e62 github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260903141829-ef07b52a737d github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 github.com/smartcontractkit/chainlink-data-streams v1.1.2-0.20261009064810-68424c714170 diff --git a/go.sum b/go.sum index 349c3b414ac..356fa153750 100644 --- a/go.sum +++ b/go.sum @@ -1104,8 +1104,8 @@ github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260908155618-50f521d70e62/go.mod h1:c++Ed0jeYn4w8WIfiAboRwN6ClRRVGglL0qwB/QjJvM= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5 h1:mpb2dy2Cr3/J3d09u5L0vjOeA4SVPvk2VZcuOEWUopY= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5/go.mod h1:QeHe1mlcVzzg+awYAkRfl/8mDLRAhsl18IIOg4MVZec= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d h1:PmhBu41LVNATLXKNX+bzuRShPexHj2H4Ryi4HH1VBbc= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d/go.mod h1:ZRHl1hjJyTPrnv669e3thza3U7Z2as5zKCDZP0kJXuw= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260903141829-ef07b52a737d h1:M9xuiIvdiHtim4nlxCVajyC/Mk63tAg9ESWb/biAhNA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260903141829-ef07b52a737d/go.mod h1:rI2njmTlyTvh+xhmORmK6qX3+V1ycDAqGJLu8LS8WpU= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 9a70720706c..2001d2f6a45 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -30,7 +30,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260916222901-720a003dab50 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261022195454-600e2b321c7a diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 2aa7365670c..a8818091a1e 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1396,8 +1396,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5 h1:mpb2dy2Cr3/J3d09u5L0vjOeA4SVPvk2VZcuOEWUopY= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5/go.mod h1:QeHe1mlcVzzg+awYAkRfl/8mDLRAhsl18IIOg4MVZec= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d h1:PmhBu41LVNATLXKNX+bzuRShPexHj2H4Ryi4HH1VBbc= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d/go.mod h1:ZRHl1hjJyTPrnv669e3thza3U7Z2as5zKCDZP0kJXuw= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= diff --git a/integration-tests/load/go.mod b/integration-tests/load/go.mod index fc6d035f840..2094bc06a45 100644 --- a/integration-tests/load/go.mod +++ b/integration-tests/load/go.mod @@ -20,7 +20,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260916222901-720a003dab50 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261022195454-600e2b321c7a github.com/smartcontractkit/chainlink-testing-framework/framework v0.16.9 diff --git a/integration-tests/load/go.sum b/integration-tests/load/go.sum index 6bb93b929ad..c1fdd13aa85 100644 --- a/integration-tests/load/go.sum +++ b/integration-tests/load/go.sum @@ -1636,8 +1636,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5 h1:mpb2dy2Cr3/J3d09u5L0vjOeA4SVPvk2VZcuOEWUopY= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5/go.mod h1:QeHe1mlcVzzg+awYAkRfl/8mDLRAhsl18IIOg4MVZec= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d h1:PmhBu41LVNATLXKNX+bzuRShPexHj2H4Ryi4HH1VBbc= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d/go.mod h1:ZRHl1hjJyTPrnv669e3thza3U7Z2as5zKCDZP0kJXuw= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= diff --git a/system-tests/lib/go.mod b/system-tests/lib/go.mod index 4c6466ddef2..670ac65dd03 100644 --- a/system-tests/lib/go.mod +++ b/system-tests/lib/go.mod @@ -32,7 +32,7 @@ require ( github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-aptos v0.0.0-20260923062809-ca886ade4d26 github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260916222901-720a003dab50 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-confidential-compute v1.3.0 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 diff --git a/system-tests/lib/go.sum b/system-tests/lib/go.sum index 957b3b0f077..533893e83bf 100644 --- a/system-tests/lib/go.sum +++ b/system-tests/lib/go.sum @@ -1657,8 +1657,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5 h1:mpb2dy2Cr3/J3d09u5L0vjOeA4SVPvk2VZcuOEWUopY= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5/go.mod h1:QeHe1mlcVzzg+awYAkRfl/8mDLRAhsl18IIOg4MVZec= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d h1:PmhBu41LVNATLXKNX+bzuRShPexHj2H4Ryi4HH1VBbc= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d/go.mod h1:ZRHl1hjJyTPrnv669e3thza3U7Z2as5zKCDZP0kJXuw= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= diff --git a/system-tests/tests/go.mod b/system-tests/tests/go.mod index 391187922bb..e24d08d9de5 100644 --- a/system-tests/tests/go.mod +++ b/system-tests/tests/go.mod @@ -73,7 +73,7 @@ require ( github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-aptos v0.0.0-20260923062809-ca886ade4d26 github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260916222901-720a003dab50 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 github.com/smartcontractkit/chainlink-confidential-compute v1.3.0 diff --git a/system-tests/tests/go.sum b/system-tests/tests/go.sum index 6eb14ec54a0..063fffac0ae 100644 --- a/system-tests/tests/go.sum +++ b/system-tests/tests/go.sum @@ -1836,8 +1836,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5 h1:mpb2dy2Cr3/J3d09u5L0vjOeA4SVPvk2VZcuOEWUopY= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261020093734-0127cb4d6ae5/go.mod h1:QeHe1mlcVzzg+awYAkRfl/8mDLRAhsl18IIOg4MVZec= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d h1:PmhBu41LVNATLXKNX+bzuRShPexHj2H4Ryi4HH1VBbc= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d/go.mod h1:ZRHl1hjJyTPrnv669e3thza3U7Z2as5zKCDZP0kJXuw= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= From 8e8882484a5c2d5108efca0b1fc114ebdcb99b69 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Fri, 30 Oct 2026 09:00:43 -0500 Subject: [PATCH 03/13] inject triggers.Coordinator; implement more StateTransition --- core/services/chainlink/application.go | 1 + core/services/cre/cre.go | 43 ++++--- core/services/ocr2/delegate.go | 6 +- core/services/ocr3_1/plugins/queue/queue.go | 132 +++++++++++++------- 4 files changed, 117 insertions(+), 65 deletions(-) diff --git a/core/services/chainlink/application.go b/core/services/chainlink/application.go index 3b3f4cadaa3..a5b915678f8 100644 --- a/core/services/chainlink/application.go +++ b/core/services/chainlink/application.go @@ -820,6 +820,7 @@ func NewApplication(ctx context.Context, opts ApplicationOpts) (Application, err OrgResolver: creServices.OrgResolver, LimitsFactory: limitsFactory, OCRConfigService: creServices.OCRConfigService, + TriggerCoordinator: creServices.TriggerCoordinator, DefaultBootstrappers: safeDefaultBootstrappers(cfg), CapRegistryAddress: safeExternalRegistryAddress(cfg), CapRegistryChainID: safeExternalRegistryChainID(cfg), diff --git a/core/services/cre/cre.go b/core/services/cre/cre.go index 8574312e4d4..566d45126d9 100644 --- a/core/services/cre/cre.go +++ b/core/services/cre/cre.go @@ -134,6 +134,8 @@ type Services struct { WorkflowRegistrySyncer syncerV2.WorkflowRegistrySyncer + TriggerCoordinator triggers.Coordinator + OrgResolver orgresolver.OrgResolver OCRConfigService capregconfig.OCRConfigService @@ -280,7 +282,7 @@ func (s *Services) newSubservices( // the handler resolves the workflow DON id later from the don notifier. meterIdentity := newSyncerMeterIdentity(cfg) - wfSyncer, billingClient, wfSyncerSrvcs, err := newWorkflowRegistrySyncer( + wfSyncer, triggerCoordinator, billingClient, wfSyncerSrvcs, err := newWorkflowRegistrySyncer( cfg, relayerChainInterops, opts, @@ -302,6 +304,7 @@ func (s *Services) newSubservices( } s.BillingClient = billingClient s.WorkflowRegistrySyncer = wfSyncer + s.TriggerCoordinator = triggerCoordinator srvs = append(srvs, wfSyncerSrvcs...) return srvs, nil @@ -866,14 +869,14 @@ func newWorkflowRegistrySyncerV2( meterIdentity resourcemanager.ResourceIdentity, dispatcher remotetypes.Dispatcher, shardIndexMapper *shardownership.ShardIndexMapper, -) (syncerV2.WorkflowRegistrySyncer, []commonsrv.Service, error) { +) (syncerV2.WorkflowRegistrySyncer, triggers.Coordinator, []commonsrv.Service, error) { capCfg := cfg.Capabilities() wfReg := capCfg.WorkflowRegistry() key := opts.WorkflowKey fetcherFunc, retrieverFunc, srvcs, err := newFetcherServiceV2(opts, capCfg, lggr, gatewayConnectorWrapper) if err != nil { - return nil, nil, err + return nil, nil, nil, err } artifactsStore, err := artifactsV2.NewStore( @@ -890,29 +893,29 @@ func newWorkflowRegistrySyncerV2( }), ) if err != nil { - return nil, nil, fmt.Errorf("unable to create artifact store: %w", err) + return nil, nil, nil, fmt.Errorf("unable to create artifact store: %w", err) } engineRegistry := syncerV2.NewEngineRegistry() engineLimiters, err := v2.NewLimiters(lf, nil) if err != nil { - return nil, nil, fmt.Errorf("could not instantiate engine limiters: %w", err) + return nil, nil, nil, fmt.Errorf("could not instantiate engine limiters: %w", err) } featureFlags, err := v2.NewFeatureFlags(lf, nil) if err != nil { - return nil, nil, fmt.Errorf("could not instantiate engine feature flags: %w", err) + return nil, nil, nil, fmt.Errorf("could not instantiate engine feature flags: %w", err) } selector, err := chainSelector(wfReg.ChainID(), wfReg.NetworkID()) if err != nil { - return nil, nil, err + return nil, nil, nil, err } crFactory, err := newContractReaderFactory(capCfg, relayerChainInterops) if err != nil { - return nil, nil, fmt.Errorf("failed to instantiate contract reader factory: %w", err) + return nil, nil, nil, fmt.Errorf("failed to instantiate contract reader factory: %w", err) } var shardOrchestratorClient shardorchestrator.ClientInterface @@ -921,7 +924,7 @@ func newWorkflowRegistrySyncerV2( } else { c, clientErr := newShardOrchestratorClient(cfg, lggr) if clientErr != nil { - return nil, nil, clientErr + return nil, nil, nil, clientErr } if c != nil { shardOrchestratorClient = c @@ -968,7 +971,7 @@ func newWorkflowRegistrySyncerV2( coordinatorMetrics, err := wfmonitoring.InitMonitoringResources() if err != nil { - return nil, nil, fmt.Errorf("unable to init trigger coordinator metrics: %w", err) + return nil, nil, nil, fmt.Errorf("unable to init trigger coordinator metrics: %w", err) } triggerCoordinator := triggers.NewCoordinator( triggers.RegisterDeps{ @@ -1018,7 +1021,7 @@ func newWorkflowRegistrySyncerV2( }) specMeter, smErr := syncerV2.NewSpecMeter(lggr, rm, meterIdentity, artifactsStore, orgResolver) if smErr != nil { - return nil, nil, fmt.Errorf("unable to create workflow spec meter: %w", smErr) + return nil, nil, nil, fmt.Errorf("unable to create workflow spec meter: %w", smErr) } handlerOpts = append(handlerOpts, syncerV2.WithSpecMeter(specMeter)) } @@ -1039,7 +1042,7 @@ func newWorkflowRegistrySyncerV2( if diskMonitorEnabled { fileStore, fsErr := artifactsV2.NewFileModuleStore(mc.CacheDir(), cacheEnabled) if fsErr != nil { - return nil, nil, fmt.Errorf("unable to create file module store: %w", fsErr) + return nil, nil, nil, fmt.Errorf("unable to create file module store: %w", fsErr) } if diskMonitorEnabled { @@ -1049,7 +1052,7 @@ func newWorkflowRegistrySyncerV2( syncerV2.WorkflowModuleCacheDiskMonitorTickInterval, ) if dmErr != nil { - return nil, nil, fmt.Errorf("unable to create module cache disk monitor: %w", dmErr) + return nil, nil, nil, fmt.Errorf("unable to create module cache disk monitor: %w", dmErr) } srvcs = append(srvcs, dm) @@ -1059,7 +1062,7 @@ func newWorkflowRegistrySyncerV2( if cacheEnabled { cm, cmErr := syncerV2.NewCacheMetrics() if cmErr != nil { - return nil, nil, fmt.Errorf("unable to create module cache metrics: %w", cmErr) + return nil, nil, nil, fmt.Errorf("unable to create module cache metrics: %w", cmErr) } var idleTimeout time.Duration @@ -1109,7 +1112,7 @@ func newWorkflowRegistrySyncerV2( handlerOpts..., ) if err != nil { - return nil, nil, fmt.Errorf("unable to create workflow registry event handler: %w", err) + return nil, nil, nil, fmt.Errorf("unable to create workflow registry event handler: %w", err) } addSources := wfReg.AdditionalSources() @@ -1162,12 +1165,12 @@ func newWorkflowRegistrySyncerV2( registryOpts..., ) if err != nil { - return nil, nil, fmt.Errorf("unable to create workflow registry syncer: %w", err) + return nil, nil, nil, fmt.Errorf("unable to create workflow registry syncer: %w", err) } srvcs = append(srvcs, workflowRegistrySyncerV2) lggr.Debugw("Created WorkflowRegistrySyncer V2") - return workflowRegistrySyncerV2, srvcs, nil + return workflowRegistrySyncerV2, triggerCoordinator, srvcs, nil } // newWorkflowRegistrySyncer creates a workflow registry syncer. @@ -1187,7 +1190,7 @@ func newWorkflowRegistrySyncer( meterIdentity resourcemanager.ResourceIdentity, dispatcher remotetypes.Dispatcher, shardIndexMapper *shardownership.ShardIndexMapper, -) (syncerV2.WorkflowRegistrySyncer, metering.BillingClient, []commonsrv.Service, error) { +) (syncerV2.WorkflowRegistrySyncer, triggers.Coordinator, metering.BillingClient, []commonsrv.Service, error) { lggr.Debugw("Creating WorkflowRegistrySyncer") lggr = logger.Named(lggr, "WorkflowRegistrySyncer") @@ -1196,7 +1199,7 @@ func newWorkflowRegistrySyncer( lggr.Infof("failed to create billing client: %s", err) } - syncer, srvcs, err := newWorkflowRegistrySyncerV2( + syncer, triggerCoordinator, srvcs, err := newWorkflowRegistrySyncerV2( cfg, relayerChainInterops, billingClient, @@ -1214,7 +1217,7 @@ func newWorkflowRegistrySyncer( dispatcher, shardIndexMapper, ) - return syncer, billingClient, srvcs, err + return syncer, triggerCoordinator, billingClient, srvcs, err } // NewServices creates and initializes all CRE services diff --git a/core/services/ocr2/delegate.go b/core/services/ocr2/delegate.go index faa8c5befc5..fd6aaf65896 100644 --- a/core/services/ocr2/delegate.go +++ b/core/services/ocr2/delegate.go @@ -82,6 +82,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/synchronization" "github.com/smartcontractkit/chainlink/v2/core/services/telemetry" syncerV2 "github.com/smartcontractkit/chainlink/v2/core/services/workflows/syncer/v2" + "github.com/smartcontractkit/chainlink/v2/core/services/workflows/v2/triggers" "github.com/smartcontractkit/chainlink/v2/core/utils" "github.com/smartcontractkit/chainlink/v2/plugins" ) @@ -157,6 +158,7 @@ type Delegate struct { OrgResolver orgresolver.OrgResolver limitsFactory limits.Factory ocrConfigService capregconfig.OCRConfigService + triggerCoordinator triggers.Coordinator // Registry-driven launch support: when the delegate is used via // LocalCapabilityManager (no job spec), these fields provide the @@ -297,6 +299,7 @@ type DelegateOpts struct { OrgResolver orgresolver.OrgResolver LimitsFactory limits.Factory OCRConfigService capregconfig.OCRConfigService + TriggerCoordinator triggers.Coordinator // Registry-driven launch support: defaults for capabilities launched // via LocalCapabilityManager (no job spec). @@ -339,6 +342,7 @@ func NewDelegate( OrgResolver: opts.OrgResolver, limitsFactory: opts.LimitsFactory, ocrConfigService: opts.OCRConfigService, + triggerCoordinator: opts.TriggerCoordinator, defaultBootstrappers: opts.DefaultBootstrappers, capRegistryAddress: opts.CapRegistryAddress, capRegistryChainID: opts.CapRegistryChainID, @@ -886,7 +890,7 @@ func (d *Delegate) newServicesConsensusQueue( MetricsRegisterer: prometheus.WrapRegistererWith(map[string]string{"job_name": jb.Name.ValueOrZero()}, prometheus.DefaultRegisterer), } - rpf, err := queue.NewConsensusQueuePluginFactory(lggr, cfg, d.limitsFactory) + rpf, err := queue.NewConsensusQueuePluginFactory(lggr, cfg, d.limitsFactory, d.triggerCoordinator) if err != nil { return nil, err } diff --git a/core/services/ocr3_1/plugins/queue/queue.go b/core/services/ocr3_1/plugins/queue/queue.go index 24dfa624ba4..21e3275a0bd 100644 --- a/core/services/ocr3_1/plugins/queue/queue.go +++ b/core/services/ocr3_1/plugins/queue/queue.go @@ -4,9 +4,11 @@ import ( "container/heap" "context" "fmt" + "math" "slices" "sync" + "golang.org/x/exp/constraints" "google.golang.org/protobuf/proto" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3_1types" @@ -25,18 +27,19 @@ import ( var _ ocr3_1types.ReportingPluginFactory[[]byte] = &consensusQueuePluginFactory{} type consensusQueuePluginFactory struct { - lggr logger.Logger - cfg *PluginConfig + lggr logger.Logger + cfg *PluginConfig + triggerCoordinator triggers.Coordinator } -func NewConsensusQueuePluginFactory(lggr logger.Logger, cfg *PluginConfig, limitsFactory limits.Factory) (ocr3_1types.ReportingPluginFactory[[]byte], error) { - // TODO pass CentralTriggerQueue, CapacityReporter, EngineRegistry +func NewConsensusQueuePluginFactory(lggr logger.Logger, cfg *PluginConfig, limitsFactory limits.Factory, triggerCoordinator triggers.Coordinator) (ocr3_1types.ReportingPluginFactory[[]byte], error) { + // TODO inject CapacityReporter // TODO construct limiters - return &consensusQueuePluginFactory{lggr: lggr, cfg: cfg}, nil + return &consensusQueuePluginFactory{lggr: lggr, cfg: cfg, triggerCoordinator: triggerCoordinator}, nil } func (c *consensusQueuePluginFactory) NewReportingPlugin(ctx context.Context, config ocr3types.ReportingPluginConfig, fetcher ocr3_1types.BlobBroadcastFetcher) (ocr3_1types.ReportingPlugin[[]byte], ocr3_1types.ReportingPluginInfo, error) { - plugin := newConsensusQueuePlugin(c.lggr, config) + plugin := newConsensusQueuePlugin(c.lggr, config, c.triggerCoordinator) pluginInfo := ocr3_1types.ReportingPluginInfo1{ Name: "ConsensusQueueReportingPlugin", Limits: c.cfg.Limits, @@ -48,13 +51,18 @@ var _ ocr3_1types.ReportingPlugin[[]byte] = &consensusQueuePlugin{} type consensusQueuePlugin struct { services.Service - eng *services.Engine - lggr logger.Logger - onchainCfg ocr3types.ReportingPluginConfig + eng *services.Engine + lggr logger.Logger + onchainCfg ocr3types.ReportingPluginConfig + triggerCoordinator triggers.Coordinator } -func newConsensusQueuePlugin(lggr logger.Logger, onchainCfg ocr3types.ReportingPluginConfig) *consensusQueuePlugin { - c := &consensusQueuePlugin{lggr: logger.Named(lggr, "ConsensusQueuePlugin"), onchainCfg: onchainCfg} +func newConsensusQueuePlugin(lggr logger.Logger, onchainCfg ocr3types.ReportingPluginConfig, triggerCoordinator triggers.Coordinator) *consensusQueuePlugin { + c := &consensusQueuePlugin{ + lggr: logger.Named(lggr, "ConsensusQueuePlugin"), + onchainCfg: onchainCfg, + triggerCoordinator: triggerCoordinator, + } c.Service, c.eng = services.Config{ Name: "ConsensusQueueReportingPlugin", Close: c.Close, @@ -74,30 +82,40 @@ func (c *consensusQueuePlugin) Observation( // tryStartExecutions is idempotent. c.tryStartExecutions(kvState) - // TODO Fetch limits from node + capacity, err := c.triggerCoordinator.AvailableCapacity(ctx) + if err != nil { + //TODO or just log and make a best effort to observe events regardless? + return nil, fmt.Errorf("failed to get available capacity: %w", err) + } // Build Observation var events []triggers.CoordinatedEvent // TODO observe queue via c.CentralTriggerQueue.TakeForObservation()... one at at time? obs := &pb.ConsensusQueueObservation{ Events: make([]*pb.CoordinatedEvent, 0, len(events)), - Capacity: 0, //TODO set - WorkflowCapacities: nil, //TODO for everything proposed and queued in the KV store? + Capacity: uint32(min(capacity.Global, math.MaxUint32)), + WorkflowCapacities: make(map[string]uint32), + } + for wf, c := range capacity.PerWorkflow { + //TODO only for events proposed and queued in the KV store? + obs.WorkflowCapacities[wf] = uint32(min(c, math.MaxUint32)) } const maxObservationSize = 0 //TODO protoOpts := proto.MarshalOptions{Deterministic: true} for _, e := range events { m := e.ToProto() + // Try adding to batch obs.Events = append(obs.Events, m) id := e.Event.Event.ID var addedCap bool - if _, ok := obs.WorkflowCapacities[id]; !ok { + if _, ok := obs.WorkflowCapacities[e.WorkflowID]; !ok { addedCap = true - //TODO set it + obs.WorkflowCapacities[e.WorkflowID] = uint32(min(capacity.PerWorkflow[e.WorkflowID], math.MaxUint32)) } - if protoOpts.Size(obs) > maxObservationSize { // too large, end of batch - // remove this one + // Check size + if protoOpts.Size(obs) > maxObservationSize { + // too large, remove this one obs.Events = obs.Events[:len(obs.Events)-1] if addedCap { delete(obs.WorkflowCapacities, id) @@ -112,7 +130,11 @@ func (c *consensusQueuePlugin) ValidateObservation( ctx context.Context, seqNr uint64, _ ocrtypes.AttributedQuery, ao ocrtypes.AttributedObservation, _ ocr3_1types.KeyValueStateReader, _ ocr3_1types.BlobFetcher, ) error { - //TODO validate + var obs pb.ConsensusQueueObservation + err := proto.Unmarshal(ao.Observation, &obs) + if err != nil { + return fmt.Errorf("failed to unmarshal observation: %w", err) + } return nil } @@ -129,18 +151,36 @@ func (c *consensusQueuePlugin) StateTransition( ) (ocr3_1types.ReportsPlusPrecursor, error) { var wg sync.WaitGroup - // TODO In parallel: - var capacity int - var wfCapacity map[string]int - var observedProposals map[string][]uint8 // trigger event ID -> observer node IDs + //TODO is median only logical option for capacity? what if honest nodes have less, don't we ideally want execute min(honest)? + var medianCap uint32 + var medianCapPerWF map[string]uint32 // wf ID -> capacity + var observedProposals map[string][]uint8 // trigger event ID -> observer OracleIDs var observedEvents map[string]*pb.CoordinatedEvent // trigger event ID -> event go func() { defer wg.Done() - // - Aggregate each node’s view of how many trigger events we can pop from the KV store queue (i.e. how many executions we can start) - // - Aggregate the per workflow free capacity - // - Achieve quorum on observations -> any item with F+1 observations goes into the queue - // - Medianize the logical clock value in the observations to order events + capacities := make([]uint32, 0, len(aos)) + wfCapacities := make(map[string][]uint32) + for _, ao := range aos { + var obs pb.ConsensusQueueObservation + err := proto.Unmarshal(ao.Observation, &obs) + if err != nil { + c.lggr.Errorw("Failed to unmarshal observation", "err", err) + continue + } + capacities = append(capacities, obs.Capacity) + for wf, c := range obs.WorkflowCapacities { + wfCapacities[wf] = append(wfCapacities[wf], c) + } + for _, event := range obs.Events { + observedProposals[event.Event.Event.Id] = append(observedProposals[event.Event.Event.Id], uint8(ao.Observer)) + observedEvents[event.Event.Event.Id] = event //TODO last value is not sufficient - must handle disagreement + } + } + medianCap = median(capacities) + for wf, c := range wfCapacities { + medianCapPerWF[wf] = median(c) + } }() // Deserialize the KV store into memory @@ -157,7 +197,7 @@ func (c *consensusQueuePlugin) StateTransition( //TODO prune expired events from proposed and priorityQueue - wg.Wait() + wg.Wait() // TODO also wait if we return early for error // Collect observed proposals and promote to priority queue on f+1 for id, nodes := range observedProposals { @@ -191,7 +231,7 @@ func (c *consensusQueuePlugin) StateTransition( // Select items from queue based on priority and capacity var consensusEvents []*pb.CoordinatedEvent var workflowLimited []*pb.CoordinatedEvent // omitted due to workflow limit - for len(consensusEvents) < capacity { + for len(consensusEvents) < int(medianCap) { if len(priorityQueue) == 0 { break } @@ -199,11 +239,11 @@ func (c *consensusQueuePlugin) StateTransition( if !ok { return nil, fmt.Errorf("failed to cast *pb.CoordinatedEvent: got type %T", next) } - if wfCapacity[next.WorkflowID] == 0 { + if medianCapPerWF[next.WorkflowID] == 0 { workflowLimited = append(workflowLimited, next) continue } - wfCapacity[next.WorkflowID]-- + medianCapPerWF[next.WorkflowID]-- consensusEvents = append(consensusEvents, next) } // restore omitted for next time @@ -240,27 +280,26 @@ func (c *consensusQueuePlugin) tryStartExecutions(reader ocr3_1types.KeyValueSta state := stateReader{reader} pbs, err := state.readConsensusEvents() if err != nil { - //TODO log? + c.lggr.Errorw("Failed to read consensus events", "err", err) return } - errs := make([]error, len(pbs.Events)) + var wg sync.WaitGroup - for i, pbEvent := range pbs.Events { + for _, pbEvent := range pbs.Events { var event triggers.CoordinatedEvent - if err := event.FromProto(pbEvent); err != nil { - errs[i] = fmt.Errorf("failed to unmarshal event: %s: %w", pbEvent, err) - continue - } wg.Add(1) c.eng.Go(func(ctx context.Context) { defer wg.Done() - // TODO fetch workflow engine instance + + if err := event.FromProto(pbEvent); err != nil { + c.lggr.Errorw("Failed to unmarshal CoordinatedEvent", "pb", pbEvent.String(), "err", err) + } + // TODO execute StartExecution - errs[i] = nil + // c.triggerCoordinator.tryStartExecution(ctx, event) }) } - wg.Wait() - //TODO process errors? or just log as we go? + wg.Wait() //TODO do we need to wait? } func (c *consensusQueuePlugin) Reports(ctx context.Context, seqNr uint64, reportsPlusPrecursor ocr3_1types.ReportsPlusPrecursor) ([]ocr3types.ReportPlus[[]byte], error) { @@ -268,9 +307,14 @@ func (c *consensusQueuePlugin) Reports(ctx context.Context, seqNr uint64, report } func (c *consensusQueuePlugin) ShouldAcceptAttestedReport(ctx context.Context, seqNr uint64, reportWithInfo ocr3types.ReportWithInfo[[]byte]) (bool, error) { - return true, nil + return false, nil } func (c *consensusQueuePlugin) ShouldTransmitAcceptedReport(ctx context.Context, seqNr uint64, reportWithInfo ocr3types.ReportWithInfo[[]byte]) (bool, error) { - return true, nil + return false, nil +} + +func median[N constraints.Integer, S []N](s S) N { + slices.Sort(s) + return (s[len(s)/2-1] + s[len(s)/2]) / 2 } From 18675698bd65fe6e2085e3ad0966491c6543a5ab Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Sun, 1 Nov 2026 09:19:36 -0600 Subject: [PATCH 04/13] simplify --- core/services/ocr3_1/plugins/queue/kvstate.go | 63 +++++++++++++++++++ core/services/ocr3_1/plugins/queue/queue.go | 62 ++++-------------- 2 files changed, 75 insertions(+), 50 deletions(-) diff --git a/core/services/ocr3_1/plugins/queue/kvstate.go b/core/services/ocr3_1/plugins/queue/kvstate.go index 39175f4bce3..31fdd63bcca 100644 --- a/core/services/ocr3_1/plugins/queue/kvstate.go +++ b/core/services/ocr3_1/plugins/queue/kvstate.go @@ -3,6 +3,8 @@ package queue import ( "cmp" "container/heap" + "fmt" + "slices" "google.golang.org/protobuf/proto" @@ -101,3 +103,64 @@ func (p *priorityQueue) Push(x any) { func (p *priorityQueue) Pop() any { return (*p)[len(*p)-1] } + +// PopCap pops up to capacity events from the queue, each of which must have wf capacity. Mutates capPerWF. +func (p *priorityQueue) PopCap(capacity uint32, capPerWF map[string]uint32) ([]*pb.CoordinatedEvent, error) { + var events []*pb.CoordinatedEvent + var wfLimited []*pb.CoordinatedEvent // omitted due to workflow limit + for len(events) < int(capacity) { + if len(*p) == 0 { + break + } + next, ok := heap.Pop(p).(*pb.CoordinatedEvent) + if !ok { + return nil, fmt.Errorf("failed to cast *pb.CoordinatedEvent: got type %T", next) + } + if capPerWF[next.WorkflowID] == 0 { + wfLimited = append(wfLimited, next) + continue + } + capPerWF[next.WorkflowID]-- + events = append(events, next) + } + // restore omitted for next time + for _, event := range wfLimited { + heap.Push(p, event) + } + return events, nil +} + +type proposedAndQueued struct { + proposedEvents *pb.ConsensusQueueProposals + queuedEvents *priorityQueue +} + +func (s proposedAndQueued) processObserved(f int, observedProposals map[string][]uint8, observedEvents map[string]*pb.CoordinatedEvent) { + for id, nodes := range observedProposals { + if observers, ok := s.proposedEvents.Observers[id]; !ok && len(nodes) >= f+1 { + // new proposal straight to priority queue + heap.Push(s.queuedEvents, s.proposedEvents.Events[id]) + continue + } else if !ok { + // new proposal < f + 1 + s.proposedEvents.Observers[id] = &pb.NodeIDList{Ids: nodes} + s.proposedEvents.Events[id] = observedEvents[id] + continue + } else if len(nodes) < f+1 { + // update proposal + // TODO opt: build a map to avoid n^2? or nbd since n < f+1 + for _, node := range nodes { + if !slices.Contains(observers.Ids, node) { + observers.Ids = append(observers.Ids, node) + } + } + if len(observers.Ids) < f+1 { + continue + } + } + // f+1 - promote proposal to priority queue + delete(s.proposedEvents.Observers, id) + delete(s.proposedEvents.Events, id) + heap.Push(s.queuedEvents, s.proposedEvents.Events[id]) + } +} diff --git a/core/services/ocr3_1/plugins/queue/queue.go b/core/services/ocr3_1/plugins/queue/queue.go index 21e3275a0bd..40582cb8e34 100644 --- a/core/services/ocr3_1/plugins/queue/queue.go +++ b/core/services/ocr3_1/plugins/queue/queue.go @@ -152,6 +152,7 @@ func (c *consensusQueuePlugin) StateTransition( var wg sync.WaitGroup //TODO is median only logical option for capacity? what if honest nodes have less, don't we ideally want execute min(honest)? + // consider some configurable x% var medianCap uint32 var medianCapPerWF map[string]uint32 // wf ID -> capacity var observedProposals map[string][]uint8 // trigger event ID -> observer OracleIDs @@ -184,71 +185,32 @@ func (c *consensusQueuePlugin) StateTransition( }() // Deserialize the KV store into memory + //TODO package in a constructor for propsoedAndQueued? state := newStateReadWriter(kvState) proposedEvents, err := state.readProposedEvents() if err != nil { return nil, err } - priorityQueue, err := state.readPriorityQueue() + queuedEvents, err := state.readPriorityQueue() if err != nil { return nil, err } - heap.Init(&priorityQueue) //TODO or can we trust it? + heap.Init(&queuedEvents) //TODO or can we trust it? //TODO prune expired events from proposed and priorityQueue wg.Wait() // TODO also wait if we return early for error // Collect observed proposals and promote to priority queue on f+1 - for id, nodes := range observedProposals { - if obs, ok := proposedEvents.Observers[id]; !ok && len(nodes) >= c.onchainCfg.F+1 { - // new proposal straight to priority queue - heap.Push(&priorityQueue, proposedEvents.Events[id]) - continue - } else if !ok { - // new proposal < f + 1 - proposedEvents.Observers[id] = &pb.NodeIDList{Ids: nodes} - proposedEvents.Events[id] = observedEvents[id] - continue - } else if len(nodes) < c.onchainCfg.F+1 { - // update proposal - // TODO opt: build a map to avoid n^2? or nbd since n < f+1 - for _, node := range nodes { - if !slices.Contains(obs.Ids, node) { - obs.Ids = append(obs.Ids, node) - } - } - if len(obs.Ids) < c.onchainCfg.F+1 { - continue - } - } - // f+1 - promote proposal to priority queue - delete(proposedEvents.Observers, id) - delete(proposedEvents.Events, id) - heap.Push(&priorityQueue, proposedEvents.Events[id]) - } + proposedAndQueued{ + proposedEvents: proposedEvents, + queuedEvents: &queuedEvents, + }.processObserved(c.onchainCfg.F, observedProposals, observedEvents) // Select items from queue based on priority and capacity - var consensusEvents []*pb.CoordinatedEvent - var workflowLimited []*pb.CoordinatedEvent // omitted due to workflow limit - for len(consensusEvents) < int(medianCap) { - if len(priorityQueue) == 0 { - break - } - next, ok := heap.Pop(&priorityQueue).(*pb.CoordinatedEvent) - if !ok { - return nil, fmt.Errorf("failed to cast *pb.CoordinatedEvent: got type %T", next) - } - if medianCapPerWF[next.WorkflowID] == 0 { - workflowLimited = append(workflowLimited, next) - continue - } - medianCapPerWF[next.WorkflowID]-- - consensusEvents = append(consensusEvents, next) - } - // restore omitted for next time - for _, event := range workflowLimited { - heap.Push(&priorityQueue, event) + consensusEvents, err := queuedEvents.PopCap(medianCap, medianCapPerWF) + if err != nil { + return nil, err } // Updated KV Store @@ -256,7 +218,7 @@ func (c *consensusQueuePlugin) StateTransition( if err != nil { return nil, err } - err = state.writePriorityQueue(priorityQueue) + err = state.writePriorityQueue(queuedEvents) if err != nil { return nil, err } From 7482bef0575b56c6c31ac783e205bbd488b3ba52 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Mon, 9 Nov 2026 07:34:27 -0600 Subject: [PATCH 05/13] blob support --- core/scripts/go.mod | 8 +- core/scripts/go.sum | 16 +-- core/services/ocr3_1/plugins/queue/kvstate.go | 106 +++++++++++------- core/services/ocr3_1/plugins/queue/queue.go | 106 ++++++++++++++---- .../workflows/v2/triggers/triggers.go | 18 ++- deployment/go.mod | 8 +- deployment/go.sum | 16 +-- go.mod | 8 +- go.sum | 16 +-- integration-tests/go.mod | 8 +- integration-tests/go.sum | 16 +-- integration-tests/load/go.mod | 8 +- integration-tests/load/go.sum | 16 +-- system-tests/lib/go.mod | 8 +- system-tests/lib/go.sum | 16 +-- system-tests/tests/go.mod | 8 +- system-tests/tests/go.sum | 16 +-- 17 files changed, 242 insertions(+), 156 deletions(-) diff --git a/core/scripts/go.mod b/core/scripts/go.mod index 433daf2ab63..c232ee4d810 100644 --- a/core/scripts/go.mod +++ b/core/scripts/go.mod @@ -29,7 +29,7 @@ require ( github.com/shopspring/decimal v1.4.0 github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261022195454-600e2b321c7a @@ -133,7 +133,7 @@ require ( github.com/buger/goterm v1.0.4 // indirect github.com/buger/jsonparser v1.2.0 // indirect github.com/buraksezer/consistent v0.10.0 // indirect - github.com/bytecodealliance/wasmtime-go/v47 v47.0.0 // indirect + github.com/bytecodealliance/wasmtime-go/v50 v50.0.0 // indirect github.com/bytedance/gopkg v0.1.3 // indirect github.com/bytedance/sonic v1.15.0 // indirect github.com/bytedance/sonic/loader v0.5.0 // indirect @@ -515,7 +515,7 @@ require ( github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-discovery v0.0.0-20251211142334-5c3421fe2c8d // indirect github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0-20260505131349-78e491b80735 // indirect github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d // indirect - github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b // indirect + github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c // indirect github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36 // indirect github.com/smartcontractkit/chainlink-protos/linking-service/go v0.0.0-20260512230622-65f10f4cd305 // indirect github.com/smartcontractkit/chainlink-protos/metering/go v0.0.0-20260729184203-90b4cdd48536 // indirect @@ -525,7 +525,7 @@ require ( github.com/smartcontractkit/chainlink-protos/rmn/v1.6/go v0.0.0-20250131130834-15e0d4cde2a6 // indirect github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0 // indirect github.com/smartcontractkit/chainlink-protos/svr v1.3.0 // indirect - github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138 // indirect + github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a // indirect github.com/smartcontractkit/chainlink-solana/contracts v0.0.0-20260513123719-d347eaf314e1 // indirect github.com/smartcontractkit/chainlink-stellar/bindings v0.0.0-20261005072841-71e45e418098 // indirect github.com/smartcontractkit/chainlink-stellar/deployment v0.0.0-20261005072841-71e45e418098 // indirect diff --git a/core/scripts/go.sum b/core/scripts/go.sum index d09e43690ea..eb80205180c 100644 --- a/core/scripts/go.sum +++ b/core/scripts/go.sum @@ -316,8 +316,8 @@ github.com/bxcodec/faker v2.0.1+incompatible h1:P0KUpUw5w6WJXwrPfv35oc91i4d8nf40 github.com/bxcodec/faker v2.0.1+incompatible/go.mod h1:BNzfpVdTwnFJ6GtfYTcQu6l6rHShT+veBxNCnjCx5XM= github.com/bytecodealliance/wasmtime-go/v39 v39.0.1 h1:RibaT47yiyCRxMOj/l2cvL8cWiWBSqDXHyqsa9sGcCE= github.com/bytecodealliance/wasmtime-go/v39 v39.0.1/go.mod h1:miR4NYIEBXeDNamZIzpskhJ0z/p8al+lwMWylQ/ZJb4= -github.com/bytecodealliance/wasmtime-go/v47 v47.0.0 h1:PAe4o7Mq1VjSx81Dc+V4w1XvxLouFTB384N4ZT4o+7k= -github.com/bytecodealliance/wasmtime-go/v47 v47.0.0/go.mod h1:icJLhTDV7EyKlZpeuBuJl4yoTMqhjUvNv1mewMJUvr4= +github.com/bytecodealliance/wasmtime-go/v50 v50.0.0 h1:oC7otiLbHEIDiL+7otXozGw+hnwD4WihronoKYU3drM= +github.com/bytecodealliance/wasmtime-go/v50 v50.0.0/go.mod h1:xWTHNOKHkN8YVWrTRZpmb1eUOkWPMEXTaVtm3AOEWWE= github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M= github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM= github.com/bytedance/sonic v1.15.0 h1:/PXeWFaR5ElNcVE84U0dOHjiMHQOwNIx3K4ymzh/uSE= @@ -1686,8 +1686,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d h1:PmhBu41LVNATLXKNX+bzuRShPexHj2H4Ryi4HH1VBbc= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d/go.mod h1:ZRHl1hjJyTPrnv669e3thza3U7Z2as5zKCDZP0kJXuw= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 h1:2APdbnh8Uf/h/THKSZM3g2IW/10ah+ygqwMZltOlBqU= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360/go.mod h1:hdp2bQBzIDJt3UhXKnLz4OMHpsOW54Z9E9Txx4SVC8w= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= @@ -1726,8 +1726,8 @@ github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0- github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0-20260505131349-78e491b80735/go.mod h1:zAJq6Tpkx5AdFUwW67dIYnW+Bdf50drCCpMR81Qxb4E= github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d h1:AJy55QJ/pBhXkZjc7N+ATnWfxrcjq9BI9DmdtdjwDUQ= github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d/go.mod h1:5JdppgngCOUS76p61zCinSCgOhPeYQ+OcDUuome5THQ= -github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b h1:tlxPkVQ6ZpJIElqUWc4lU5VH4BB6OzhckG/gHwpaaa0= -github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b/go.mod h1:/i8hjTPFdVWHiY+QjeSiVS2Z3GB3WAZznGgXHstC02E= +github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c h1:vt2LhimyZm6zPN46kGKlaRUmIiVbv+8VrPT7Hh4raAI= +github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c/go.mod h1:/i8hjTPFdVWHiY+QjeSiVS2Z3GB3WAZznGgXHstC02E= github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36 h1:SG+wAsNyAcA6Kk19ljuxi3HK9Ll2lpHik8OKoY4x7A0= github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36/go.mod h1:vL1bDgPSJjV0EqHYs4dDlR+EEE0cJchgvGLYXhwIjXY= github.com/smartcontractkit/chainlink-protos/job-distributor v0.20.1-0.20260701185448-696c075849ea h1:gdA7tZgcRYMq3ryi7uNopYgn6s26g04Haw9SdmLRHzE= @@ -1750,8 +1750,8 @@ github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0 h1:B7itmjy+C github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0/go.mod h1:h6kqaGajbNRrezm56zhx03p0mVmmA2xxj7E/M4ytLUA= github.com/smartcontractkit/chainlink-protos/svr v1.3.0 h1:vOw+MbXtkPK8l/hA7uLASIgCwv05YzmuoIMuOXPa+g0= github.com/smartcontractkit/chainlink-protos/svr v1.3.0/go.mod h1:TcOliTQU6r59DwG4lo3U+mFM9WWyBHGuFkkxQpvSujo= -github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138 h1:8c/R1dHoAeGTV3/s3ELHjCFuPGuStx5VlJCqe9X0gcM= -github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138/go.mod h1:Oz1I5l+jsFc+YWPjLIrYdn5XUtjA3Iw/E6Z2G6pq5Q0= +github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a h1:CzHgJU/57hwO0Cm7Ev+S8UvuTZjIXDqSGRBM9z++Mck= +github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a/go.mod h1:9cjvCME22gVZthWieZDmjWbdWvwOzv0RPfPjAkqZ0oc= github.com/smartcontractkit/chainlink-solana v1.3.1-0.20260605202330-b5a89c32fdc1 h1:e4vdi3czYy+eK2j/eO5r3ceMxxkx4Qq5IsiAeSAQ9uc= github.com/smartcontractkit/chainlink-solana v1.3.1-0.20260605202330-b5a89c32fdc1/go.mod h1:wi1QdXqhSJnADt9YRaRtEWomqknLcrdkTS0JotupuOQ= github.com/smartcontractkit/chainlink-solana/contracts v0.0.0-20260513123719-d347eaf314e1 h1:/xvuNFI7DwOoTQnmAdYPDdY+sConn3RgZ2rMy/8AXlo= diff --git a/core/services/ocr3_1/plugins/queue/kvstate.go b/core/services/ocr3_1/plugins/queue/kvstate.go index 31fdd63bcca..604ea37dd2c 100644 --- a/core/services/ocr3_1/plugins/queue/kvstate.go +++ b/core/services/ocr3_1/plugins/queue/kvstate.go @@ -5,8 +5,10 @@ import ( "container/heap" "fmt" "slices" + "time" "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/timestamppb" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3_1types" @@ -15,21 +17,21 @@ import ( // KV store Keys const ( - proposedEventsKey = "proposed_events::index" // proposed events waiting for consensus (= f+1 { +func (s observedAndQueued) addObservedEvents(f int, observedEvents map[string]*pb.ConsensusQueueObservedEvent) { + for id, event := range observedEvents { + obs, ok := s.observedEvents.Observations[id] + if !ok && len(event.NodeIds) >= f+1 { // new proposal straight to priority queue - heap.Push(s.queuedEvents, s.proposedEvents.Events[id]) - continue + heap.Push(s.queuedEvents, &pb.ConsensusQueueEvent{ + WorkflowID: "", //TODO parse? + TriggerEventID: "", //TODO parse? + Deadline: medianTimestamp(event.Deadlines), + Blobs: event.Blobs, + }) } else if !ok { // new proposal < f + 1 - s.proposedEvents.Observers[id] = &pb.NodeIDList{Ids: nodes} - s.proposedEvents.Events[id] = observedEvents[id] - continue - } else if len(nodes) < f+1 { + s.observedEvents.Observations[id] = event + } else { // update proposal - // TODO opt: build a map to avoid n^2? or nbd since n < f+1 - for _, node := range nodes { - if !slices.Contains(observers.Ids, node) { - observers.Ids = append(observers.Ids, node) - } + // TODO opt: build a map to avoid n^2? + for i, node := range event.NodeIds { + if !slices.Contains(obs.NodeIds, node) { + obs.NodeIds = append(obs.NodeIds, node) + obs.Deadlines = append(obs.Deadlines, event.Deadlines[i]) + obs.Blobs = append(obs.Blobs, event.Blobs[i]) + } //TODO what if a node reports twice with different deadline or nodeID? do we need to overwrite? } - if len(observers.Ids) < f+1 { - continue + if len(obs.NodeIds) >= f+1 { + // promote proposal to priority queue + delete(s.observedEvents.Observations, id) + heap.Push(s.queuedEvents, &pb.ConsensusQueueEvent{ + WorkflowID: "", //TODO + TriggerEventID: "", //TODO + Deadline: medianTimestamp(event.Deadlines), + Blobs: event.Blobs, + }) } } - // f+1 - promote proposal to priority queue - delete(s.proposedEvents.Observers, id) - delete(s.proposedEvents.Events, id) - heap.Push(s.queuedEvents, s.proposedEvents.Events[id]) } } + +func medianTimestamp(s []*timestamppb.Timestamp) *timestamppb.Timestamp { + var times []time.Time + for _, t := range s { + times = append(times, time.Unix(t.Seconds, int64(t.Nanos))) + } + slices.SortFunc(times, time.Time.Compare) + + a, b := times[len(times)/2], times[len(times)/2-1] + diff := a.Sub(b) + return timestamppb.New(a.Add(diff / 2)) +} diff --git a/core/services/ocr3_1/plugins/queue/queue.go b/core/services/ocr3_1/plugins/queue/queue.go index 40582cb8e34..b9eed61a0b5 100644 --- a/core/services/ocr3_1/plugins/queue/queue.go +++ b/core/services/ocr3_1/plugins/queue/queue.go @@ -9,7 +9,9 @@ import ( "sync" "golang.org/x/exp/constraints" + "golang.org/x/sync/errgroup" "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/timestamppb" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3_1types" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" @@ -38,8 +40,8 @@ func NewConsensusQueuePluginFactory(lggr logger.Logger, cfg *PluginConfig, limit return &consensusQueuePluginFactory{lggr: lggr, cfg: cfg, triggerCoordinator: triggerCoordinator}, nil } -func (c *consensusQueuePluginFactory) NewReportingPlugin(ctx context.Context, config ocr3types.ReportingPluginConfig, fetcher ocr3_1types.BlobBroadcastFetcher) (ocr3_1types.ReportingPlugin[[]byte], ocr3_1types.ReportingPluginInfo, error) { - plugin := newConsensusQueuePlugin(c.lggr, config, c.triggerCoordinator) +func (c *consensusQueuePluginFactory) NewReportingPlugin(ctx context.Context, config ocr3types.ReportingPluginConfig, blobs ocr3_1types.BlobBroadcastFetcher) (ocr3_1types.ReportingPlugin[[]byte], ocr3_1types.ReportingPluginInfo, error) { + plugin := newConsensusQueuePlugin(c.lggr, config, c.triggerCoordinator, blobs) pluginInfo := ocr3_1types.ReportingPluginInfo1{ Name: "ConsensusQueueReportingPlugin", Limits: c.cfg.Limits, @@ -55,13 +57,15 @@ type consensusQueuePlugin struct { lggr logger.Logger onchainCfg ocr3types.ReportingPluginConfig triggerCoordinator triggers.Coordinator + blobs ocr3_1types.BlobBroadcastFetcher } -func newConsensusQueuePlugin(lggr logger.Logger, onchainCfg ocr3types.ReportingPluginConfig, triggerCoordinator triggers.Coordinator) *consensusQueuePlugin { +func newConsensusQueuePlugin(lggr logger.Logger, onchainCfg ocr3types.ReportingPluginConfig, triggerCoordinator triggers.Coordinator, blobs ocr3_1types.BlobBroadcastFetcher) *consensusQueuePlugin { c := &consensusQueuePlugin{ lggr: logger.Named(lggr, "ConsensusQueuePlugin"), onchainCfg: onchainCfg, triggerCoordinator: triggerCoordinator, + blobs: blobs, } c.Service, c.eng = services.Config{ Name: "ConsensusQueueReportingPlugin", @@ -76,7 +80,7 @@ func (c *consensusQueuePlugin) Query(_ context.Context, _ uint64, _ ocr3_1types. } func (c *consensusQueuePlugin) Observation( - ctx context.Context, seqNr uint64, _ ocrtypes.AttributedQuery, kvState ocr3_1types.KeyValueStateReader, _ ocr3_1types.BlobBroadcastFetcher, + ctx context.Context, seqNr uint64, _ ocrtypes.AttributedQuery, kvState ocr3_1types.KeyValueStateReader, blobs ocr3_1types.BlobBroadcastFetcher, ) (ocrtypes.Observation, error) { // Always attempt to start any executions from the KV Store in the event Committed was not called. // tryStartExecutions is idempotent. @@ -92,7 +96,7 @@ func (c *consensusQueuePlugin) Observation( var events []triggers.CoordinatedEvent // TODO observe queue via c.CentralTriggerQueue.TakeForObservation()... one at at time? obs := &pb.ConsensusQueueObservation{ - Events: make([]*pb.CoordinatedEvent, 0, len(events)), + Events: make([]*pb.ConsensusQueueEvent, 0, len(events)), Capacity: uint32(min(capacity.Global, math.MaxUint32)), WorkflowCapacities: make(map[string]uint32), } @@ -106,7 +110,19 @@ func (c *consensusQueuePlugin) Observation( for _, e := range events { m := e.ToProto() // Try adding to batch - obs.Events = append(obs.Events, m) + + //TODO broadcast now synchronously? or earlier so it's already available now? + //TODO pb.CoordinatedEvent? or could omit wfID, eventID, deadline + // handle, err := blobs.BroadcastBlob(ctx, []byte{}, ocr3_1types.BlobExpirationHintSequenceNumber{SeqNr: 0}) + obs.Events = append(obs.Events, &pb.ConsensusQueueEvent{ + WorkflowID: m.WorkflowID, + TriggerEventID: m.Event.Event.Id, + Deadline: m.Deadline, + Blobs: []*pb.CoordinatedEventBlobHandle{{ + Handle: nil, //TODO + Index: 0, //TODO + }}, + }) id := e.Event.Event.ID var addedCap bool if _, ok := obs.WorkflowCapacities[e.WorkflowID]; !ok { @@ -135,6 +151,8 @@ func (c *consensusQueuePlugin) ValidateObservation( if err != nil { return fmt.Errorf("failed to unmarshal observation: %w", err) } + //TODO ensure each event has single blob+deadline + //TODO ensure blobs exist? return nil } @@ -147,16 +165,16 @@ func (c *consensusQueuePlugin) ObservationQuorum( func (c *consensusQueuePlugin) StateTransition( ctx context.Context, seqNr uint64, aq ocrtypes.AttributedQuery, aos []ocrtypes.AttributedObservation, - kvState ocr3_1types.KeyValueStateReadWriter, _ ocr3_1types.BlobFetcher, + kvState ocr3_1types.KeyValueStateReadWriter, fetcher ocr3_1types.BlobFetcher, ) (ocr3_1types.ReportsPlusPrecursor, error) { var wg sync.WaitGroup //TODO is median only logical option for capacity? what if honest nodes have less, don't we ideally want execute min(honest)? // consider some configurable x% var medianCap uint32 - var medianCapPerWF map[string]uint32 // wf ID -> capacity - var observedProposals map[string][]uint8 // trigger event ID -> observer OracleIDs - var observedEvents map[string]*pb.CoordinatedEvent // trigger event ID -> event + var medianCapPerWF map[string]uint32 // wf ID -> capacity + //TODO key on eventID+workflowID? + var newObservedEvents map[string]*pb.ConsensusQueueObservedEvent // trigger event ID -> event go func() { defer wg.Done() @@ -174,8 +192,20 @@ func (c *consensusQueuePlugin) StateTransition( wfCapacities[wf] = append(wfCapacities[wf], c) } for _, event := range obs.Events { - observedProposals[event.Event.Event.Id] = append(observedProposals[event.Event.Event.Id], uint8(ao.Observer)) - observedEvents[event.Event.Event.Id] = event //TODO last value is not sufficient - must handle disagreement + //TODO key=WFID+eventID? + mergedEvent, ok := newObservedEvents[event.TriggerEventID] + if !ok { + mergedEvent = &pb.ConsensusQueueObservedEvent{ + Deadlines: []*timestamppb.Timestamp{event.Deadline}, + NodeIds: []uint8{uint8(ao.Observer)}, + Blobs: []*pb.CoordinatedEventBlobHandle{event.Blobs[0]}, + } + } else { + mergedEvent.Deadlines = append(mergedEvent.Deadlines, event.Deadline) + mergedEvent.Blobs = append(mergedEvent.Blobs, event.Blobs...) + } + + newObservedEvents[event.TriggerEventID] = mergedEvent } } medianCap = median(capacities) @@ -185,9 +215,9 @@ func (c *consensusQueuePlugin) StateTransition( }() // Deserialize the KV store into memory - //TODO package in a constructor for propsoedAndQueued? + //TODO package in a constructor for observedAndQueued? state := newStateReadWriter(kvState) - proposedEvents, err := state.readProposedEvents() + observedEvents, err := state.readObservedEvents() if err != nil { return nil, err } @@ -202,10 +232,10 @@ func (c *consensusQueuePlugin) StateTransition( wg.Wait() // TODO also wait if we return early for error // Collect observed proposals and promote to priority queue on f+1 - proposedAndQueued{ - proposedEvents: proposedEvents, + observedAndQueued{ + observedEvents: observedEvents, queuedEvents: &queuedEvents, - }.processObserved(c.onchainCfg.F, observedProposals, observedEvents) + }.addObservedEvents(c.onchainCfg.F, newObservedEvents) // Select items from queue based on priority and capacity consensusEvents, err := queuedEvents.PopCap(medianCap, medianCapPerWF) @@ -214,7 +244,9 @@ func (c *consensusQueuePlugin) StateTransition( } // Updated KV Store - err = state.writeProposedEvents(proposedEvents) + //TODO might we hit a KV size limit in the middle of these? then what? can't just drop proposals + // alternative: proposals only valid when there is definitely enough space + err = state.writeObservedEvents(observedEvents) if err != nil { return nil, err } @@ -222,7 +254,7 @@ func (c *consensusQueuePlugin) StateTransition( if err != nil { return nil, err } - err = state.writeConsensusEvents(&pb.CoordinatedEventList{Events: consensusEvents}) + err = state.writeConsensusEvents(&pb.ConsensusQueueEventList{Events: consensusEvents}) if err != nil { return nil, err } @@ -253,7 +285,41 @@ func (c *consensusQueuePlugin) tryStartExecutions(reader ocr3_1types.KeyValueSta c.eng.Go(func(ctx context.Context) { defer wg.Done() - if err := event.FromProto(pbEvent); err != nil { + // fetch blobs with observed events + errGrp := new(errgroup.Group) + observedEvents := make([]*pb.CoordinatedEvent, len(pbEvent.Blobs)) + for i, blob := range pbEvent.Blobs { + errGrp.Go(func() error { + var handle ocr3_1types.BlobHandle + if err := handle.UnmarshalBinary(blob.Handle); err != nil { + return fmt.Errorf("failed to unmarshal blob handle: %w", err) + } + b, err := c.blobs.FetchBlob(ctx, handle) + if err != nil { + return fmt.Errorf("failed to fetch blob: %w", err) + } + //TODO allocate element first? + if err := proto.Unmarshal(b, observedEvents[i]); err != nil { + return fmt.Errorf("failed to unmarshal CoordinatedEvent from blob: %w", err) + } + return nil + }) + } + if err := errGrp.Wait(); err != nil { + c.lggr.Errorw("Failed to fetch blob for event; unable to execute", "eventID", pbEvent.TriggerEventID, "err", err) + return + } + + //TODO we don't always want a continuous median, e.g. IDs + // maybe mode if it exists, otherwise fallback to each node using its own observed value? + if err := event.FromProto(&pb.CoordinatedEvent{ + WorkflowID: pbEvent.WorkflowID, + TriggerCapID: "", //TODO from blob median? + TriggerIndex: 0, //TODO from blob median? + ObservedAt: nil, //TODO from blob median? + Deadline: pbEvent.Deadline, + Event: nil, //TODO from blob ....piecewise median? + }); err != nil { c.lggr.Errorw("Failed to unmarshal CoordinatedEvent", "pb", pbEvent.String(), "err", err) } diff --git a/core/services/workflows/v2/triggers/triggers.go b/core/services/workflows/v2/triggers/triggers.go index 2b04f4a8761..7d80431c24e 100644 --- a/core/services/workflows/v2/triggers/triggers.go +++ b/core/services/workflows/v2/triggers/triggers.go @@ -148,20 +148,17 @@ type CoordinatedEvent struct { // A settings change after dispatch does not affect already-queued events Deadline time.Time - // SequenceNumber determines the execution order of trigger events across the DON. - SequenceNumber uint64 - Event capabilities.TriggerResponse + Event capabilities.TriggerResponse } func (e *CoordinatedEvent) ToProto() *pb.CoordinatedEvent { return &pb.CoordinatedEvent{ - WorkflowID: e.WorkflowID, - TriggerCapID: e.TriggerCapID, - TriggerIndex: int64(e.TriggerIndex), - ObservedAt: timestamppb.New(e.ObservedAt), - Deadline: timestamppb.New(e.Deadline), - SequenceNumber: e.SequenceNumber, - Event: pb.TriggerResponseToProto(e.Event), + WorkflowID: e.WorkflowID, + TriggerCapID: e.TriggerCapID, + TriggerIndex: int64(e.TriggerIndex), + ObservedAt: timestamppb.New(e.ObservedAt), + Deadline: timestamppb.New(e.Deadline), + Event: pb.TriggerResponseToProto(e.Event), } } @@ -171,7 +168,6 @@ func (e *CoordinatedEvent) FromProto(p *pb.CoordinatedEvent) (err error) { e.TriggerIndex = int(p.TriggerIndex) e.ObservedAt = p.ObservedAt.AsTime() e.Deadline = p.Deadline.AsTime() - e.SequenceNumber = p.SequenceNumber e.Event, err = pb.TriggerResponseFromProto(p.Event) return } diff --git a/deployment/go.mod b/deployment/go.mod index 2d3cfc9be94..dd2995105e0 100644 --- a/deployment/go.mod +++ b/deployment/go.mod @@ -41,14 +41,14 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/solana/deployment v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-data-streams v1.1.2-0.20261009064810-68424c714170 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261022195454-600e2b321c7a github.com/smartcontractkit/chainlink-evm/contracts/cre/gobindings v0.0.0-20260403151002-2c91155b5501 github.com/smartcontractkit/chainlink-evm/gethwrappers v0.0.0-20261005112317-b723176adfe8 - github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b + github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c github.com/smartcontractkit/chainlink-protos/job-distributor v0.20.1-0.20260701185448-696c075849ea github.com/smartcontractkit/chainlink-protos/orchestrator v0.11.0 github.com/smartcontractkit/chainlink-solana v1.3.1-0.20260605202330-b5a89c32fdc1 @@ -163,7 +163,7 @@ require ( github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect github.com/buger/jsonparser v1.2.0 // indirect github.com/buraksezer/consistent v0.10.0 // indirect - github.com/bytecodealliance/wasmtime-go/v47 v47.0.0 // indirect + github.com/bytecodealliance/wasmtime-go/v50 v50.0.0 // indirect github.com/bytedance/gopkg v0.1.3 // indirect github.com/bytedance/sonic v1.15.0 // indirect github.com/bytedance/sonic/loader v0.5.0 // indirect @@ -451,7 +451,7 @@ require ( github.com/smartcontractkit/chainlink-protos/rmn/v1.6/go v0.0.0-20250131130834-15e0d4cde2a6 // indirect github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0 // indirect github.com/smartcontractkit/chainlink-protos/svr v1.3.0 // indirect - github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138 // indirect + github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a // indirect github.com/smartcontractkit/chainlink-testing-framework/parrot v0.6.2 // indirect github.com/smartcontractkit/chainlink-testing-framework/seth v1.51.5 // indirect github.com/smartcontractkit/chainlink-ton/cciplib v0.1.1-0.20260925185547-7ea74de84cb2 // indirect diff --git a/deployment/go.sum b/deployment/go.sum index 7c18de10579..6e188fc630e 100644 --- a/deployment/go.sum +++ b/deployment/go.sum @@ -282,8 +282,8 @@ github.com/buraksezer/consistent v0.10.0 h1:hqBgz1PvNLC5rkWcEBVAL9dFMBWz6I0VgUCW github.com/buraksezer/consistent v0.10.0/go.mod h1:6BrVajWq7wbKZlTOUPs/XVfR8c0maujuPowduSpZqmw= github.com/bxcodec/faker v2.0.1+incompatible h1:P0KUpUw5w6WJXwrPfv35oc91i4d8nf40Nwln+M/+faA= github.com/bxcodec/faker v2.0.1+incompatible/go.mod h1:BNzfpVdTwnFJ6GtfYTcQu6l6rHShT+veBxNCnjCx5XM= -github.com/bytecodealliance/wasmtime-go/v47 v47.0.0 h1:PAe4o7Mq1VjSx81Dc+V4w1XvxLouFTB384N4ZT4o+7k= -github.com/bytecodealliance/wasmtime-go/v47 v47.0.0/go.mod h1:icJLhTDV7EyKlZpeuBuJl4yoTMqhjUvNv1mewMJUvr4= +github.com/bytecodealliance/wasmtime-go/v50 v50.0.0 h1:oC7otiLbHEIDiL+7otXozGw+hnwD4WihronoKYU3drM= +github.com/bytecodealliance/wasmtime-go/v50 v50.0.0/go.mod h1:xWTHNOKHkN8YVWrTRZpmb1eUOkWPMEXTaVtm3AOEWWE= github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M= github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM= github.com/bytedance/sonic v1.15.0 h1:/PXeWFaR5ElNcVE84U0dOHjiMHQOwNIx3K4ymzh/uSE= @@ -1411,8 +1411,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d h1:PmhBu41LVNATLXKNX+bzuRShPexHj2H4Ryi4HH1VBbc= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d/go.mod h1:ZRHl1hjJyTPrnv669e3thza3U7Z2as5zKCDZP0kJXuw= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 h1:2APdbnh8Uf/h/THKSZM3g2IW/10ah+ygqwMZltOlBqU= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360/go.mod h1:hdp2bQBzIDJt3UhXKnLz4OMHpsOW54Z9E9Txx4SVC8w= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= @@ -1449,8 +1449,8 @@ github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0- github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0-20260505131349-78e491b80735/go.mod h1:zAJq6Tpkx5AdFUwW67dIYnW+Bdf50drCCpMR81Qxb4E= github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d h1:AJy55QJ/pBhXkZjc7N+ATnWfxrcjq9BI9DmdtdjwDUQ= github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d/go.mod h1:5JdppgngCOUS76p61zCinSCgOhPeYQ+OcDUuome5THQ= -github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b h1:tlxPkVQ6ZpJIElqUWc4lU5VH4BB6OzhckG/gHwpaaa0= -github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b/go.mod h1:/i8hjTPFdVWHiY+QjeSiVS2Z3GB3WAZznGgXHstC02E= +github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c h1:vt2LhimyZm6zPN46kGKlaRUmIiVbv+8VrPT7Hh4raAI= +github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c/go.mod h1:/i8hjTPFdVWHiY+QjeSiVS2Z3GB3WAZznGgXHstC02E= github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36 h1:SG+wAsNyAcA6Kk19ljuxi3HK9Ll2lpHik8OKoY4x7A0= github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36/go.mod h1:vL1bDgPSJjV0EqHYs4dDlR+EEE0cJchgvGLYXhwIjXY= github.com/smartcontractkit/chainlink-protos/job-distributor v0.20.1-0.20260701185448-696c075849ea h1:gdA7tZgcRYMq3ryi7uNopYgn6s26g04Haw9SdmLRHzE= @@ -1473,8 +1473,8 @@ github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0 h1:B7itmjy+C github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0/go.mod h1:h6kqaGajbNRrezm56zhx03p0mVmmA2xxj7E/M4ytLUA= github.com/smartcontractkit/chainlink-protos/svr v1.3.0 h1:vOw+MbXtkPK8l/hA7uLASIgCwv05YzmuoIMuOXPa+g0= github.com/smartcontractkit/chainlink-protos/svr v1.3.0/go.mod h1:TcOliTQU6r59DwG4lo3U+mFM9WWyBHGuFkkxQpvSujo= -github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138 h1:8c/R1dHoAeGTV3/s3ELHjCFuPGuStx5VlJCqe9X0gcM= -github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138/go.mod h1:Oz1I5l+jsFc+YWPjLIrYdn5XUtjA3Iw/E6Z2G6pq5Q0= +github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a h1:CzHgJU/57hwO0Cm7Ev+S8UvuTZjIXDqSGRBM9z++Mck= +github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a/go.mod h1:9cjvCME22gVZthWieZDmjWbdWvwOzv0RPfPjAkqZ0oc= github.com/smartcontractkit/chainlink-solana v1.3.1-0.20260605202330-b5a89c32fdc1 h1:e4vdi3czYy+eK2j/eO5r3ceMxxkx4Qq5IsiAeSAQ9uc= github.com/smartcontractkit/chainlink-solana v1.3.1-0.20260605202330-b5a89c32fdc1/go.mod h1:wi1QdXqhSJnADt9YRaRtEWomqknLcrdkTS0JotupuOQ= github.com/smartcontractkit/chainlink-solana/contracts v0.0.0-20260513123719-d347eaf314e1 h1:/xvuNFI7DwOoTQnmAdYPDdY+sConn3RgZ2rMy/8AXlo= diff --git a/go.mod b/go.mod index 1ad05c537a6..833e8bd1f11 100644 --- a/go.mod +++ b/go.mod @@ -82,7 +82,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260908155618-50f521d70e62 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260908155618-50f521d70e62 github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260903141829-ef07b52a737d github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 github.com/smartcontractkit/chainlink-data-streams v1.1.2-0.20261009064810-68424c714170 @@ -93,7 +93,7 @@ require ( github.com/smartcontractkit/chainlink-framework/chains v0.0.0-20261009212658-df7dcfcb7a77 github.com/smartcontractkit/chainlink-framework/multinode v0.0.0-20260625152110-9afcf56e4053 github.com/smartcontractkit/chainlink-protos/billing/go v0.0.0-20251024234028-0988426d98f4 - github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b + github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36 github.com/smartcontractkit/chainlink-protos/linking-service/go v0.0.0-20260512230622-65f10f4cd305 github.com/smartcontractkit/chainlink-protos/metering/go v0.0.0-20260729184203-90b4cdd48536 @@ -101,7 +101,7 @@ require ( github.com/smartcontractkit/chainlink-protos/orchestrator v0.11.0 github.com/smartcontractkit/chainlink-protos/ring/go v0.0.0-20260904122233-4d79005babd9 github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0 - github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138 + github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a github.com/smartcontractkit/chainlink-sui/codec v0.0.0-20260720132736-e99278bfdc96 github.com/smartcontractkit/chainlink-ton/cciplib v0.1.1-0.20260716214810-db5ecc877490 github.com/smartcontractkit/cre-sdk-go v1.17.0-capdev.1 @@ -179,7 +179,7 @@ require ( github.com/blendle/zapdriver v1.3.1 // indirect github.com/block-vision/sui-go-sdk v1.2.1 // indirect github.com/btcsuite/btcd/btcec/v2 v2.3.4 // indirect - github.com/bytecodealliance/wasmtime-go/v47 v47.0.0 // indirect + github.com/bytecodealliance/wasmtime-go/v50 v50.0.0 // indirect github.com/bytedance/sonic v1.12.3 // indirect github.com/bytedance/sonic/loader v0.2.0 // indirect github.com/cenkalti/backoff v2.2.1+incompatible // indirect diff --git a/go.sum b/go.sum index 356fa153750..2b0279f5ca4 100644 --- a/go.sum +++ b/go.sum @@ -167,8 +167,8 @@ github.com/buger/jsonparser v1.2.0 h1:4EFcvK1kD4jyj6YqNK6skK6w+y7FHHBR+XBCtxwu/6 github.com/buger/jsonparser v1.2.0/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0= github.com/buraksezer/consistent v0.10.0 h1:hqBgz1PvNLC5rkWcEBVAL9dFMBWz6I0VgUCW25rrZlU= github.com/buraksezer/consistent v0.10.0/go.mod h1:6BrVajWq7wbKZlTOUPs/XVfR8c0maujuPowduSpZqmw= -github.com/bytecodealliance/wasmtime-go/v47 v47.0.0 h1:PAe4o7Mq1VjSx81Dc+V4w1XvxLouFTB384N4ZT4o+7k= -github.com/bytecodealliance/wasmtime-go/v47 v47.0.0/go.mod h1:icJLhTDV7EyKlZpeuBuJl4yoTMqhjUvNv1mewMJUvr4= +github.com/bytecodealliance/wasmtime-go/v50 v50.0.0 h1:oC7otiLbHEIDiL+7otXozGw+hnwD4WihronoKYU3drM= +github.com/bytecodealliance/wasmtime-go/v50 v50.0.0/go.mod h1:xWTHNOKHkN8YVWrTRZpmb1eUOkWPMEXTaVtm3AOEWWE= github.com/bytedance/sonic v1.12.3 h1:W2MGa7RCU1QTeYRTPE3+88mVC0yXmsRQRChiyVocVjU= github.com/bytedance/sonic v1.12.3/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= @@ -1104,8 +1104,8 @@ github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260908155618-50f521d70e62/go.mod h1:c++Ed0jeYn4w8WIfiAboRwN6ClRRVGglL0qwB/QjJvM= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d h1:PmhBu41LVNATLXKNX+bzuRShPexHj2H4Ryi4HH1VBbc= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d/go.mod h1:ZRHl1hjJyTPrnv669e3thza3U7Z2as5zKCDZP0kJXuw= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 h1:2APdbnh8Uf/h/THKSZM3g2IW/10ah+ygqwMZltOlBqU= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360/go.mod h1:hdp2bQBzIDJt3UhXKnLz4OMHpsOW54Z9E9Txx4SVC8w= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260903141829-ef07b52a737d h1:M9xuiIvdiHtim4nlxCVajyC/Mk63tAg9ESWb/biAhNA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260903141829-ef07b52a737d/go.mod h1:rI2njmTlyTvh+xhmORmK6qX3+V1ycDAqGJLu8LS8WpU= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= @@ -1140,8 +1140,8 @@ github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0- github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0-20260505131349-78e491b80735/go.mod h1:zAJq6Tpkx5AdFUwW67dIYnW+Bdf50drCCpMR81Qxb4E= github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d h1:AJy55QJ/pBhXkZjc7N+ATnWfxrcjq9BI9DmdtdjwDUQ= github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d/go.mod h1:5JdppgngCOUS76p61zCinSCgOhPeYQ+OcDUuome5THQ= -github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b h1:tlxPkVQ6ZpJIElqUWc4lU5VH4BB6OzhckG/gHwpaaa0= -github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b/go.mod h1:/i8hjTPFdVWHiY+QjeSiVS2Z3GB3WAZznGgXHstC02E= +github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c h1:vt2LhimyZm6zPN46kGKlaRUmIiVbv+8VrPT7Hh4raAI= +github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c/go.mod h1:/i8hjTPFdVWHiY+QjeSiVS2Z3GB3WAZznGgXHstC02E= github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36 h1:SG+wAsNyAcA6Kk19ljuxi3HK9Ll2lpHik8OKoY4x7A0= github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36/go.mod h1:vL1bDgPSJjV0EqHYs4dDlR+EEE0cJchgvGLYXhwIjXY= github.com/smartcontractkit/chainlink-protos/linking-service/go v0.0.0-20260512230622-65f10f4cd305 h1:NJdGFhzT6zMaTod4QkBqVD2sg0I25iw1boOYtTpEwRo= @@ -1160,8 +1160,8 @@ github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0 h1:B7itmjy+C github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0/go.mod h1:h6kqaGajbNRrezm56zhx03p0mVmmA2xxj7E/M4ytLUA= github.com/smartcontractkit/chainlink-protos/svr v1.3.0 h1:vOw+MbXtkPK8l/hA7uLASIgCwv05YzmuoIMuOXPa+g0= github.com/smartcontractkit/chainlink-protos/svr v1.3.0/go.mod h1:TcOliTQU6r59DwG4lo3U+mFM9WWyBHGuFkkxQpvSujo= -github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138 h1:8c/R1dHoAeGTV3/s3ELHjCFuPGuStx5VlJCqe9X0gcM= -github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138/go.mod h1:Oz1I5l+jsFc+YWPjLIrYdn5XUtjA3Iw/E6Z2G6pq5Q0= +github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a h1:CzHgJU/57hwO0Cm7Ev+S8UvuTZjIXDqSGRBM9z++Mck= +github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a/go.mod h1:9cjvCME22gVZthWieZDmjWbdWvwOzv0RPfPjAkqZ0oc= github.com/smartcontractkit/chainlink-sui/codec v0.0.0-20260720132736-e99278bfdc96 h1:3R9f6pguDIjei+nKx5dUT9j6fX8urGmlZA7Ad3x9UBs= github.com/smartcontractkit/chainlink-sui/codec v0.0.0-20260720132736-e99278bfdc96/go.mod h1:pSW9q0/YqQE5R65Z/2zsyD9c50JZf+yRJJvN6Jo3LCU= github.com/smartcontractkit/chainlink-ton/cciplib v0.1.1-0.20260716214810-db5ecc877490 h1:ots2WddFOQJL/tDFGmvrhRrVu2iRXCd0XEAxhpkAE/Y= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 2001d2f6a45..490c471a243 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -30,7 +30,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260916222901-720a003dab50 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261022195454-600e2b321c7a @@ -129,7 +129,7 @@ require ( github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect github.com/buger/jsonparser v1.2.0 // indirect github.com/buraksezer/consistent v0.10.0 // indirect - github.com/bytecodealliance/wasmtime-go/v47 v47.0.0 // indirect + github.com/bytecodealliance/wasmtime-go/v50 v50.0.0 // indirect github.com/bytedance/gopkg v0.1.3 // indirect github.com/bytedance/sonic v1.15.0 // indirect github.com/bytedance/sonic/loader v0.5.0 // indirect @@ -419,7 +419,7 @@ require ( github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-discovery v0.0.0-20251211142334-5c3421fe2c8d // indirect github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0-20260505131349-78e491b80735 // indirect github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d // indirect - github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b // indirect + github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c // indirect github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36 // indirect github.com/smartcontractkit/chainlink-protos/linking-service/go v0.0.0-20260512230622-65f10f4cd305 // indirect github.com/smartcontractkit/chainlink-protos/metering/go v0.0.0-20260729184203-90b4cdd48536 // indirect @@ -430,7 +430,7 @@ require ( github.com/smartcontractkit/chainlink-protos/rmn/v1.6/go v0.0.0-20250131130834-15e0d4cde2a6 // indirect github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0 // indirect github.com/smartcontractkit/chainlink-protos/svr v1.3.0 // indirect - github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138 // indirect + github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a // indirect github.com/smartcontractkit/chainlink-solana v1.3.1-0.20260605202330-b5a89c32fdc1 // indirect github.com/smartcontractkit/chainlink-stellar/bindings v0.0.0-20261005072841-71e45e418098 // indirect github.com/smartcontractkit/chainlink-testing-framework/framework v0.16.9 // indirect diff --git a/integration-tests/go.sum b/integration-tests/go.sum index a8818091a1e..af21626863c 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -269,8 +269,8 @@ github.com/buraksezer/consistent v0.10.0 h1:hqBgz1PvNLC5rkWcEBVAL9dFMBWz6I0VgUCW github.com/buraksezer/consistent v0.10.0/go.mod h1:6BrVajWq7wbKZlTOUPs/XVfR8c0maujuPowduSpZqmw= github.com/bxcodec/faker v2.0.1+incompatible h1:P0KUpUw5w6WJXwrPfv35oc91i4d8nf40Nwln+M/+faA= github.com/bxcodec/faker v2.0.1+incompatible/go.mod h1:BNzfpVdTwnFJ6GtfYTcQu6l6rHShT+veBxNCnjCx5XM= -github.com/bytecodealliance/wasmtime-go/v47 v47.0.0 h1:PAe4o7Mq1VjSx81Dc+V4w1XvxLouFTB384N4ZT4o+7k= -github.com/bytecodealliance/wasmtime-go/v47 v47.0.0/go.mod h1:icJLhTDV7EyKlZpeuBuJl4yoTMqhjUvNv1mewMJUvr4= +github.com/bytecodealliance/wasmtime-go/v50 v50.0.0 h1:oC7otiLbHEIDiL+7otXozGw+hnwD4WihronoKYU3drM= +github.com/bytecodealliance/wasmtime-go/v50 v50.0.0/go.mod h1:xWTHNOKHkN8YVWrTRZpmb1eUOkWPMEXTaVtm3AOEWWE= github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M= github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM= github.com/bytedance/sonic v1.15.0 h1:/PXeWFaR5ElNcVE84U0dOHjiMHQOwNIx3K4ymzh/uSE= @@ -1396,8 +1396,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d h1:PmhBu41LVNATLXKNX+bzuRShPexHj2H4Ryi4HH1VBbc= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d/go.mod h1:ZRHl1hjJyTPrnv669e3thza3U7Z2as5zKCDZP0kJXuw= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 h1:2APdbnh8Uf/h/THKSZM3g2IW/10ah+ygqwMZltOlBqU= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360/go.mod h1:hdp2bQBzIDJt3UhXKnLz4OMHpsOW54Z9E9Txx4SVC8w= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= @@ -1434,8 +1434,8 @@ github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0- github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0-20260505131349-78e491b80735/go.mod h1:zAJq6Tpkx5AdFUwW67dIYnW+Bdf50drCCpMR81Qxb4E= github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d h1:AJy55QJ/pBhXkZjc7N+ATnWfxrcjq9BI9DmdtdjwDUQ= github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d/go.mod h1:5JdppgngCOUS76p61zCinSCgOhPeYQ+OcDUuome5THQ= -github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b h1:tlxPkVQ6ZpJIElqUWc4lU5VH4BB6OzhckG/gHwpaaa0= -github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b/go.mod h1:/i8hjTPFdVWHiY+QjeSiVS2Z3GB3WAZznGgXHstC02E= +github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c h1:vt2LhimyZm6zPN46kGKlaRUmIiVbv+8VrPT7Hh4raAI= +github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c/go.mod h1:/i8hjTPFdVWHiY+QjeSiVS2Z3GB3WAZznGgXHstC02E= github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36 h1:SG+wAsNyAcA6Kk19ljuxi3HK9Ll2lpHik8OKoY4x7A0= github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36/go.mod h1:vL1bDgPSJjV0EqHYs4dDlR+EEE0cJchgvGLYXhwIjXY= github.com/smartcontractkit/chainlink-protos/job-distributor v0.20.1-0.20260701185448-696c075849ea h1:gdA7tZgcRYMq3ryi7uNopYgn6s26g04Haw9SdmLRHzE= @@ -1458,8 +1458,8 @@ github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0 h1:B7itmjy+C github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0/go.mod h1:h6kqaGajbNRrezm56zhx03p0mVmmA2xxj7E/M4ytLUA= github.com/smartcontractkit/chainlink-protos/svr v1.3.0 h1:vOw+MbXtkPK8l/hA7uLASIgCwv05YzmuoIMuOXPa+g0= github.com/smartcontractkit/chainlink-protos/svr v1.3.0/go.mod h1:TcOliTQU6r59DwG4lo3U+mFM9WWyBHGuFkkxQpvSujo= -github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138 h1:8c/R1dHoAeGTV3/s3ELHjCFuPGuStx5VlJCqe9X0gcM= -github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138/go.mod h1:Oz1I5l+jsFc+YWPjLIrYdn5XUtjA3Iw/E6Z2G6pq5Q0= +github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a h1:CzHgJU/57hwO0Cm7Ev+S8UvuTZjIXDqSGRBM9z++Mck= +github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a/go.mod h1:9cjvCME22gVZthWieZDmjWbdWvwOzv0RPfPjAkqZ0oc= github.com/smartcontractkit/chainlink-solana v1.3.1-0.20260605202330-b5a89c32fdc1 h1:e4vdi3czYy+eK2j/eO5r3ceMxxkx4Qq5IsiAeSAQ9uc= github.com/smartcontractkit/chainlink-solana v1.3.1-0.20260605202330-b5a89c32fdc1/go.mod h1:wi1QdXqhSJnADt9YRaRtEWomqknLcrdkTS0JotupuOQ= github.com/smartcontractkit/chainlink-stellar/bindings v0.0.0-20261005072841-71e45e418098 h1:gFe6t6i9283xHx2nsBA604rpKxn932504sbxPERpe24= diff --git a/integration-tests/load/go.mod b/integration-tests/load/go.mod index 2094bc06a45..3a48b7ec505 100644 --- a/integration-tests/load/go.mod +++ b/integration-tests/load/go.mod @@ -20,7 +20,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260916222901-720a003dab50 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261022195454-600e2b321c7a github.com/smartcontractkit/chainlink-testing-framework/framework v0.16.9 @@ -120,7 +120,7 @@ require ( github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce // indirect github.com/buger/jsonparser v1.2.0 // indirect github.com/buraksezer/consistent v0.10.0 // indirect - github.com/bytecodealliance/wasmtime-go/v47 v47.0.0 // indirect + github.com/bytecodealliance/wasmtime-go/v50 v50.0.0 // indirect github.com/bytedance/gopkg v0.1.3 // indirect github.com/bytedance/sonic v1.15.0 // indirect github.com/bytedance/sonic/loader v0.5.0 // indirect @@ -491,7 +491,7 @@ require ( github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-discovery v0.0.0-20251211142334-5c3421fe2c8d // indirect github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0-20260505131349-78e491b80735 // indirect github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d // indirect - github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b // indirect + github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c // indirect github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36 // indirect github.com/smartcontractkit/chainlink-protos/job-distributor v0.20.1-0.20260701185448-696c075849ea // indirect github.com/smartcontractkit/chainlink-protos/linking-service/go v0.0.0-20260512230622-65f10f4cd305 // indirect @@ -503,7 +503,7 @@ require ( github.com/smartcontractkit/chainlink-protos/rmn/v1.6/go v0.0.0-20250131130834-15e0d4cde2a6 // indirect github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0 // indirect github.com/smartcontractkit/chainlink-protos/svr v1.3.0 // indirect - github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138 // indirect + github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a // indirect github.com/smartcontractkit/chainlink-solana v1.3.1-0.20260605202330-b5a89c32fdc1 // indirect github.com/smartcontractkit/chainlink-stellar/bindings v0.0.0-20261005072841-71e45e418098 // indirect github.com/smartcontractkit/chainlink-sui v0.0.0-20260922143238-46cc062ae5a3 // indirect diff --git a/integration-tests/load/go.sum b/integration-tests/load/go.sum index c1fdd13aa85..96d4c66a9d8 100644 --- a/integration-tests/load/go.sum +++ b/integration-tests/load/go.sum @@ -324,8 +324,8 @@ github.com/buraksezer/consistent v0.10.0 h1:hqBgz1PvNLC5rkWcEBVAL9dFMBWz6I0VgUCW github.com/buraksezer/consistent v0.10.0/go.mod h1:6BrVajWq7wbKZlTOUPs/XVfR8c0maujuPowduSpZqmw= github.com/bxcodec/faker v2.0.1+incompatible h1:P0KUpUw5w6WJXwrPfv35oc91i4d8nf40Nwln+M/+faA= github.com/bxcodec/faker v2.0.1+incompatible/go.mod h1:BNzfpVdTwnFJ6GtfYTcQu6l6rHShT+veBxNCnjCx5XM= -github.com/bytecodealliance/wasmtime-go/v47 v47.0.0 h1:PAe4o7Mq1VjSx81Dc+V4w1XvxLouFTB384N4ZT4o+7k= -github.com/bytecodealliance/wasmtime-go/v47 v47.0.0/go.mod h1:icJLhTDV7EyKlZpeuBuJl4yoTMqhjUvNv1mewMJUvr4= +github.com/bytecodealliance/wasmtime-go/v50 v50.0.0 h1:oC7otiLbHEIDiL+7otXozGw+hnwD4WihronoKYU3drM= +github.com/bytecodealliance/wasmtime-go/v50 v50.0.0/go.mod h1:xWTHNOKHkN8YVWrTRZpmb1eUOkWPMEXTaVtm3AOEWWE= github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M= github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM= github.com/bytedance/sonic v1.15.0 h1:/PXeWFaR5ElNcVE84U0dOHjiMHQOwNIx3K4ymzh/uSE= @@ -1636,8 +1636,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d h1:PmhBu41LVNATLXKNX+bzuRShPexHj2H4Ryi4HH1VBbc= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d/go.mod h1:ZRHl1hjJyTPrnv669e3thza3U7Z2as5zKCDZP0kJXuw= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 h1:2APdbnh8Uf/h/THKSZM3g2IW/10ah+ygqwMZltOlBqU= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360/go.mod h1:hdp2bQBzIDJt3UhXKnLz4OMHpsOW54Z9E9Txx4SVC8w= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= @@ -1674,8 +1674,8 @@ github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0- github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0-20260505131349-78e491b80735/go.mod h1:zAJq6Tpkx5AdFUwW67dIYnW+Bdf50drCCpMR81Qxb4E= github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d h1:AJy55QJ/pBhXkZjc7N+ATnWfxrcjq9BI9DmdtdjwDUQ= github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d/go.mod h1:5JdppgngCOUS76p61zCinSCgOhPeYQ+OcDUuome5THQ= -github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b h1:tlxPkVQ6ZpJIElqUWc4lU5VH4BB6OzhckG/gHwpaaa0= -github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b/go.mod h1:/i8hjTPFdVWHiY+QjeSiVS2Z3GB3WAZznGgXHstC02E= +github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c h1:vt2LhimyZm6zPN46kGKlaRUmIiVbv+8VrPT7Hh4raAI= +github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c/go.mod h1:/i8hjTPFdVWHiY+QjeSiVS2Z3GB3WAZznGgXHstC02E= github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36 h1:SG+wAsNyAcA6Kk19ljuxi3HK9Ll2lpHik8OKoY4x7A0= github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36/go.mod h1:vL1bDgPSJjV0EqHYs4dDlR+EEE0cJchgvGLYXhwIjXY= github.com/smartcontractkit/chainlink-protos/job-distributor v0.20.1-0.20260701185448-696c075849ea h1:gdA7tZgcRYMq3ryi7uNopYgn6s26g04Haw9SdmLRHzE= @@ -1698,8 +1698,8 @@ github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0 h1:B7itmjy+C github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0/go.mod h1:h6kqaGajbNRrezm56zhx03p0mVmmA2xxj7E/M4ytLUA= github.com/smartcontractkit/chainlink-protos/svr v1.3.0 h1:vOw+MbXtkPK8l/hA7uLASIgCwv05YzmuoIMuOXPa+g0= github.com/smartcontractkit/chainlink-protos/svr v1.3.0/go.mod h1:TcOliTQU6r59DwG4lo3U+mFM9WWyBHGuFkkxQpvSujo= -github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138 h1:8c/R1dHoAeGTV3/s3ELHjCFuPGuStx5VlJCqe9X0gcM= -github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138/go.mod h1:Oz1I5l+jsFc+YWPjLIrYdn5XUtjA3Iw/E6Z2G6pq5Q0= +github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a h1:CzHgJU/57hwO0Cm7Ev+S8UvuTZjIXDqSGRBM9z++Mck= +github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a/go.mod h1:9cjvCME22gVZthWieZDmjWbdWvwOzv0RPfPjAkqZ0oc= github.com/smartcontractkit/chainlink-solana v1.3.1-0.20260605202330-b5a89c32fdc1 h1:e4vdi3czYy+eK2j/eO5r3ceMxxkx4Qq5IsiAeSAQ9uc= github.com/smartcontractkit/chainlink-solana v1.3.1-0.20260605202330-b5a89c32fdc1/go.mod h1:wi1QdXqhSJnADt9YRaRtEWomqknLcrdkTS0JotupuOQ= github.com/smartcontractkit/chainlink-stellar/bindings v0.0.0-20261005072841-71e45e418098 h1:gFe6t6i9283xHx2nsBA604rpKxn932504sbxPERpe24= diff --git a/system-tests/lib/go.mod b/system-tests/lib/go.mod index 670ac65dd03..4d2ec1df93b 100644 --- a/system-tests/lib/go.mod +++ b/system-tests/lib/go.mod @@ -32,16 +32,16 @@ require ( github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-aptos v0.0.0-20260923062809-ca886ade4d26 github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260916222901-720a003dab50 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-confidential-compute v1.3.0 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261022195454-600e2b321c7a github.com/smartcontractkit/chainlink-evm/gethwrappers v0.0.0-20261005112317-b723176adfe8 - github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b + github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c github.com/smartcontractkit/chainlink-protos/job-distributor v0.20.1-0.20260701185448-696c075849ea github.com/smartcontractkit/chainlink-protos/linking-service/go v0.0.0-20260512230622-65f10f4cd305 - github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138 + github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a github.com/smartcontractkit/chainlink-stellar/bindings v0.0.0-20261005072841-71e45e418098 github.com/smartcontractkit/chainlink-stellar/deployment v0.0.0-20261005072841-71e45e418098 github.com/smartcontractkit/chainlink-testing-framework/framework v0.16.9 @@ -146,7 +146,7 @@ require ( github.com/buger/goterm v1.0.4 // indirect github.com/buger/jsonparser v1.2.0 // indirect github.com/buraksezer/consistent v0.10.0 // indirect - github.com/bytecodealliance/wasmtime-go/v47 v47.0.0 // indirect + github.com/bytecodealliance/wasmtime-go/v50 v50.0.0 // indirect github.com/bytedance/gopkg v0.1.3 // indirect github.com/bytedance/sonic v1.15.0 // indirect github.com/bytedance/sonic/loader v0.5.0 // indirect diff --git a/system-tests/lib/go.sum b/system-tests/lib/go.sum index 533893e83bf..48828ac54a2 100644 --- a/system-tests/lib/go.sum +++ b/system-tests/lib/go.sum @@ -313,8 +313,8 @@ github.com/bxcodec/faker v2.0.1+incompatible h1:P0KUpUw5w6WJXwrPfv35oc91i4d8nf40 github.com/bxcodec/faker v2.0.1+incompatible/go.mod h1:BNzfpVdTwnFJ6GtfYTcQu6l6rHShT+veBxNCnjCx5XM= github.com/bytecodealliance/wasmtime-go/v39 v39.0.1 h1:RibaT47yiyCRxMOj/l2cvL8cWiWBSqDXHyqsa9sGcCE= github.com/bytecodealliance/wasmtime-go/v39 v39.0.1/go.mod h1:miR4NYIEBXeDNamZIzpskhJ0z/p8al+lwMWylQ/ZJb4= -github.com/bytecodealliance/wasmtime-go/v47 v47.0.0 h1:PAe4o7Mq1VjSx81Dc+V4w1XvxLouFTB384N4ZT4o+7k= -github.com/bytecodealliance/wasmtime-go/v47 v47.0.0/go.mod h1:icJLhTDV7EyKlZpeuBuJl4yoTMqhjUvNv1mewMJUvr4= +github.com/bytecodealliance/wasmtime-go/v50 v50.0.0 h1:oC7otiLbHEIDiL+7otXozGw+hnwD4WihronoKYU3drM= +github.com/bytecodealliance/wasmtime-go/v50 v50.0.0/go.mod h1:xWTHNOKHkN8YVWrTRZpmb1eUOkWPMEXTaVtm3AOEWWE= github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M= github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM= github.com/bytedance/sonic v1.15.0 h1:/PXeWFaR5ElNcVE84U0dOHjiMHQOwNIx3K4ymzh/uSE= @@ -1657,8 +1657,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d h1:PmhBu41LVNATLXKNX+bzuRShPexHj2H4Ryi4HH1VBbc= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d/go.mod h1:ZRHl1hjJyTPrnv669e3thza3U7Z2as5zKCDZP0kJXuw= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 h1:2APdbnh8Uf/h/THKSZM3g2IW/10ah+ygqwMZltOlBqU= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360/go.mod h1:hdp2bQBzIDJt3UhXKnLz4OMHpsOW54Z9E9Txx4SVC8w= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= @@ -1697,8 +1697,8 @@ github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0- github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0-20260505131349-78e491b80735/go.mod h1:zAJq6Tpkx5AdFUwW67dIYnW+Bdf50drCCpMR81Qxb4E= github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d h1:AJy55QJ/pBhXkZjc7N+ATnWfxrcjq9BI9DmdtdjwDUQ= github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d/go.mod h1:5JdppgngCOUS76p61zCinSCgOhPeYQ+OcDUuome5THQ= -github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b h1:tlxPkVQ6ZpJIElqUWc4lU5VH4BB6OzhckG/gHwpaaa0= -github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b/go.mod h1:/i8hjTPFdVWHiY+QjeSiVS2Z3GB3WAZznGgXHstC02E= +github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c h1:vt2LhimyZm6zPN46kGKlaRUmIiVbv+8VrPT7Hh4raAI= +github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c/go.mod h1:/i8hjTPFdVWHiY+QjeSiVS2Z3GB3WAZznGgXHstC02E= github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36 h1:SG+wAsNyAcA6Kk19ljuxi3HK9Ll2lpHik8OKoY4x7A0= github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36/go.mod h1:vL1bDgPSJjV0EqHYs4dDlR+EEE0cJchgvGLYXhwIjXY= github.com/smartcontractkit/chainlink-protos/job-distributor v0.20.1-0.20260701185448-696c075849ea h1:gdA7tZgcRYMq3ryi7uNopYgn6s26g04Haw9SdmLRHzE= @@ -1721,8 +1721,8 @@ github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0 h1:B7itmjy+C github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0/go.mod h1:h6kqaGajbNRrezm56zhx03p0mVmmA2xxj7E/M4ytLUA= github.com/smartcontractkit/chainlink-protos/svr v1.3.0 h1:vOw+MbXtkPK8l/hA7uLASIgCwv05YzmuoIMuOXPa+g0= github.com/smartcontractkit/chainlink-protos/svr v1.3.0/go.mod h1:TcOliTQU6r59DwG4lo3U+mFM9WWyBHGuFkkxQpvSujo= -github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138 h1:8c/R1dHoAeGTV3/s3ELHjCFuPGuStx5VlJCqe9X0gcM= -github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138/go.mod h1:Oz1I5l+jsFc+YWPjLIrYdn5XUtjA3Iw/E6Z2G6pq5Q0= +github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a h1:CzHgJU/57hwO0Cm7Ev+S8UvuTZjIXDqSGRBM9z++Mck= +github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a/go.mod h1:9cjvCME22gVZthWieZDmjWbdWvwOzv0RPfPjAkqZ0oc= github.com/smartcontractkit/chainlink-solana v1.3.1-0.20260605202330-b5a89c32fdc1 h1:e4vdi3czYy+eK2j/eO5r3ceMxxkx4Qq5IsiAeSAQ9uc= github.com/smartcontractkit/chainlink-solana v1.3.1-0.20260605202330-b5a89c32fdc1/go.mod h1:wi1QdXqhSJnADt9YRaRtEWomqknLcrdkTS0JotupuOQ= github.com/smartcontractkit/chainlink-solana/contracts v0.0.0-20260513123719-d347eaf314e1 h1:/xvuNFI7DwOoTQnmAdYPDdY+sConn3RgZ2rMy/8AXlo= diff --git a/system-tests/tests/go.mod b/system-tests/tests/go.mod index e24d08d9de5..ad2b048379f 100644 --- a/system-tests/tests/go.mod +++ b/system-tests/tests/go.mod @@ -73,7 +73,7 @@ require ( github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-aptos v0.0.0-20260923062809-ca886ade4d26 github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260916222901-720a003dab50 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 github.com/smartcontractkit/chainlink-confidential-compute v1.3.0 @@ -82,10 +82,10 @@ require ( github.com/smartcontractkit/chainlink-evm/contracts/cre/gobindings v0.0.0-20260403151002-2c91155b5501 github.com/smartcontractkit/chainlink-evm/gethwrappers v0.0.0-20261005112317-b723176adfe8 github.com/smartcontractkit/chainlink-framework/capabilities v0.0.0-20260423135514-5b1a7565a99c - github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b + github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c github.com/smartcontractkit/chainlink-protos/ring/go v0.0.0-20260904122233-4d79005babd9 github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0 - github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138 + github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a github.com/smartcontractkit/chainlink-testing-framework/framework v0.16.9 github.com/smartcontractkit/chainlink-testing-framework/framework/components/chiprouter v1.0.4 github.com/smartcontractkit/chainlink-testing-framework/framework/components/fake v0.15.0 @@ -218,7 +218,7 @@ require ( github.com/buger/goterm v1.0.4 // indirect github.com/buger/jsonparser v1.2.0 // indirect github.com/buraksezer/consistent v0.10.0 // indirect - github.com/bytecodealliance/wasmtime-go/v47 v47.0.0 // indirect + github.com/bytecodealliance/wasmtime-go/v50 v50.0.0 // indirect github.com/bytedance/gopkg v0.1.3 // indirect github.com/bytedance/sonic v1.15.0 // indirect github.com/bytedance/sonic/loader v0.5.0 // indirect diff --git a/system-tests/tests/go.sum b/system-tests/tests/go.sum index 063fffac0ae..997f758cb2d 100644 --- a/system-tests/tests/go.sum +++ b/system-tests/tests/go.sum @@ -357,8 +357,8 @@ github.com/bxcodec/faker v2.0.1+incompatible h1:P0KUpUw5w6WJXwrPfv35oc91i4d8nf40 github.com/bxcodec/faker v2.0.1+incompatible/go.mod h1:BNzfpVdTwnFJ6GtfYTcQu6l6rHShT+veBxNCnjCx5XM= github.com/bytecodealliance/wasmtime-go/v39 v39.0.1 h1:RibaT47yiyCRxMOj/l2cvL8cWiWBSqDXHyqsa9sGcCE= github.com/bytecodealliance/wasmtime-go/v39 v39.0.1/go.mod h1:miR4NYIEBXeDNamZIzpskhJ0z/p8al+lwMWylQ/ZJb4= -github.com/bytecodealliance/wasmtime-go/v47 v47.0.0 h1:PAe4o7Mq1VjSx81Dc+V4w1XvxLouFTB384N4ZT4o+7k= -github.com/bytecodealliance/wasmtime-go/v47 v47.0.0/go.mod h1:icJLhTDV7EyKlZpeuBuJl4yoTMqhjUvNv1mewMJUvr4= +github.com/bytecodealliance/wasmtime-go/v50 v50.0.0 h1:oC7otiLbHEIDiL+7otXozGw+hnwD4WihronoKYU3drM= +github.com/bytecodealliance/wasmtime-go/v50 v50.0.0/go.mod h1:xWTHNOKHkN8YVWrTRZpmb1eUOkWPMEXTaVtm3AOEWWE= github.com/bytedance/gopkg v0.1.3 h1:TPBSwH8RsouGCBcMBktLt1AymVo2TVsBVCY4b6TnZ/M= github.com/bytedance/gopkg v0.1.3/go.mod h1:576VvJ+eJgyCzdjS+c4+77QF3p7ubbtiKARP3TxducM= github.com/bytedance/sonic v1.15.0 h1:/PXeWFaR5ElNcVE84U0dOHjiMHQOwNIx3K4ymzh/uSE= @@ -1836,8 +1836,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d h1:PmhBu41LVNATLXKNX+bzuRShPexHj2H4Ryi4HH1VBbc= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261028234412-602b80b4cf8d/go.mod h1:ZRHl1hjJyTPrnv669e3thza3U7Z2as5zKCDZP0kJXuw= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 h1:2APdbnh8Uf/h/THKSZM3g2IW/10ah+ygqwMZltOlBqU= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360/go.mod h1:hdp2bQBzIDJt3UhXKnLz4OMHpsOW54Z9E9Txx4SVC8w= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= @@ -1880,8 +1880,8 @@ github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0- github.com/smartcontractkit/chainlink-protos/chainlink-ccv/message-rules v0.0.0-20260505131349-78e491b80735/go.mod h1:zAJq6Tpkx5AdFUwW67dIYnW+Bdf50drCCpMR81Qxb4E= github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d h1:AJy55QJ/pBhXkZjc7N+ATnWfxrcjq9BI9DmdtdjwDUQ= github.com/smartcontractkit/chainlink-protos/chainlink-ccv/verifier v0.0.0-20251211142334-5c3421fe2c8d/go.mod h1:5JdppgngCOUS76p61zCinSCgOhPeYQ+OcDUuome5THQ= -github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b h1:tlxPkVQ6ZpJIElqUWc4lU5VH4BB6OzhckG/gHwpaaa0= -github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261013212015-e622e8b83b6b/go.mod h1:/i8hjTPFdVWHiY+QjeSiVS2Z3GB3WAZznGgXHstC02E= +github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c h1:vt2LhimyZm6zPN46kGKlaRUmIiVbv+8VrPT7Hh4raAI= +github.com/smartcontractkit/chainlink-protos/cre/go v0.0.0-20261103151748-aa8c64acc53c/go.mod h1:/i8hjTPFdVWHiY+QjeSiVS2Z3GB3WAZznGgXHstC02E= github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36 h1:SG+wAsNyAcA6Kk19ljuxi3HK9Ll2lpHik8OKoY4x7A0= github.com/smartcontractkit/chainlink-protos/data-feeds v0.1.1-0.20260501174546-2e8846986b36/go.mod h1:vL1bDgPSJjV0EqHYs4dDlR+EEE0cJchgvGLYXhwIjXY= github.com/smartcontractkit/chainlink-protos/job-distributor v0.20.1-0.20260701185448-696c075849ea h1:gdA7tZgcRYMq3ryi7uNopYgn6s26g04Haw9SdmLRHzE= @@ -1904,8 +1904,8 @@ github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0 h1:B7itmjy+C github.com/smartcontractkit/chainlink-protos/storage-service v0.3.0/go.mod h1:h6kqaGajbNRrezm56zhx03p0mVmmA2xxj7E/M4ytLUA= github.com/smartcontractkit/chainlink-protos/svr v1.3.0 h1:vOw+MbXtkPK8l/hA7uLASIgCwv05YzmuoIMuOXPa+g0= github.com/smartcontractkit/chainlink-protos/svr v1.3.0/go.mod h1:TcOliTQU6r59DwG4lo3U+mFM9WWyBHGuFkkxQpvSujo= -github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138 h1:8c/R1dHoAeGTV3/s3ELHjCFuPGuStx5VlJCqe9X0gcM= -github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20260821155228-fa1d775e2138/go.mod h1:Oz1I5l+jsFc+YWPjLIrYdn5XUtjA3Iw/E6Z2G6pq5Q0= +github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a h1:CzHgJU/57hwO0Cm7Ev+S8UvuTZjIXDqSGRBM9z++Mck= +github.com/smartcontractkit/chainlink-protos/workflows/go v0.0.0-20261028174148-0d48af26262a/go.mod h1:9cjvCME22gVZthWieZDmjWbdWvwOzv0RPfPjAkqZ0oc= github.com/smartcontractkit/chainlink-solana v1.3.1-0.20260605202330-b5a89c32fdc1 h1:e4vdi3czYy+eK2j/eO5r3ceMxxkx4Qq5IsiAeSAQ9uc= github.com/smartcontractkit/chainlink-solana v1.3.1-0.20260605202330-b5a89c32fdc1/go.mod h1:wi1QdXqhSJnADt9YRaRtEWomqknLcrdkTS0JotupuOQ= github.com/smartcontractkit/chainlink-solana/contracts v0.0.0-20260513123719-d347eaf314e1 h1:/xvuNFI7DwOoTQnmAdYPDdY+sConn3RgZ2rMy/8AXlo= From 21514f362173049d0627837e621a9f01d1d52642 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Thu, 12 Nov 2026 14:48:15 -0600 Subject: [PATCH 06/13] blob helpers; kv cleanup; more validation; more methods --- core/scripts/go.mod | 4 +- core/scripts/go.sum | 8 +- core/services/ocr3_1/plugins/queue/blobs.go | 47 +++ core/services/ocr3_1/plugins/queue/kvstate.go | 151 ++++--- core/services/ocr3_1/plugins/queue/queue.go | 379 +++++++++++------- deployment/go.mod | 4 +- deployment/go.sum | 8 +- go.mod | 4 +- go.sum | 8 +- integration-tests/go.mod | 4 +- integration-tests/go.sum | 8 +- integration-tests/load/go.mod | 4 +- integration-tests/load/go.sum | 8 +- system-tests/lib/go.mod | 4 +- system-tests/lib/go.sum | 8 +- system-tests/tests/go.mod | 4 +- system-tests/tests/go.sum | 8 +- 17 files changed, 431 insertions(+), 230 deletions(-) create mode 100644 core/services/ocr3_1/plugins/queue/blobs.go diff --git a/core/scripts/go.mod b/core/scripts/go.mod index c232ee4d810..53e0b3320f5 100644 --- a/core/scripts/go.mod +++ b/core/scripts/go.mod @@ -29,7 +29,7 @@ require ( github.com/shopspring/decimal v1.4.0 github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261022195454-600e2b321c7a @@ -500,7 +500,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260916222901-720a003dab50 // indirect github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca // indirect github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 // indirect - github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 // indirect + github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 // indirect github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa // indirect github.com/smartcontractkit/chainlink-confidential-compute v1.3.0 // indirect github.com/smartcontractkit/chainlink-data-streams v1.1.2-0.20261009064810-68424c714170 // indirect diff --git a/core/scripts/go.sum b/core/scripts/go.sum index eb80205180c..d5cf426b16e 100644 --- a/core/scripts/go.sum +++ b/core/scripts/go.sum @@ -1686,12 +1686,12 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 h1:2APdbnh8Uf/h/THKSZM3g2IW/10ah+ygqwMZltOlBqU= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360/go.mod h1:hdp2bQBzIDJt3UhXKnLz4OMHpsOW54Z9E9Txx4SVC8w= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 h1:nzm+zgN1C6kNVlQnlp3XlzqFl7g9K5h63mRyctvGNRE= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= -github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= -github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549/go.mod h1:Scyk7O80fde5rJF3Ty3fEE3xiS6j84eWbu8/2gl3pIY= +github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= +github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9/go.mod h1:Scyk7O80fde5rJF3Ty3fEE3xiS6j84eWbu8/2gl3pIY= github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa h1:7yIjZpk1mYYu630yXcGR7N+a+pcAHvn4OHlfhJK8GGY= github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa/go.mod h1:nfT8vdE44iAlhDWDV6PaBWucxZZAcDsgGkZ+D0kHpAI= github.com/smartcontractkit/chainlink-confidential-compute v1.3.0 h1:y64hOzM9H61E4EYRzQDtRwqunDBlKpsZc1SvFEUlSLE= diff --git a/core/services/ocr3_1/plugins/queue/blobs.go b/core/services/ocr3_1/plugins/queue/blobs.go new file mode 100644 index 00000000000..492b0d2c9fb --- /dev/null +++ b/core/services/ocr3_1/plugins/queue/blobs.go @@ -0,0 +1,47 @@ +package queue + +import ( + "context" + "fmt" + + "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3_1types" + "google.golang.org/protobuf/proto" + + "github.com/smartcontractkit/chainlink-common/pkg/capabilities/pb" +) + +func fetchFromBlob(ctx context.Context, fetcher ocr3_1types.BlobFetcher, handle []byte, idx int) (*pb.CoordinatedEvent, []byte, error) { + var blobHandle ocr3_1types.BlobHandle + if err := blobHandle.UnmarshalBinary(handle); err != nil { + return nil, nil, fmt.Errorf("failed to unmarshal blob handle: %w", err) + } + //TODO cache to fetch just once + b, err := fetcher.FetchBlob(ctx, blobHandle) + if err != nil { + return nil, nil, fmt.Errorf("failed to fetch blob: %w", err) + } + //TODO optimize using protowire to avoid unmarshalling the entire blob + var coordEvents *pb.CoordinatedEventList + if err := proto.Unmarshal(b, coordEvents); err != nil { + return nil, nil, fmt.Errorf("failed to unmarshal blob: %w", err) + } + if idx >= len(coordEvents.Events) { + return nil, nil, fmt.Errorf("blob index %d is out of range for blob with %d events", idx, len(coordEvents.Events)) + } + coordEvent := coordEvents.Events[idx] + return coordEvent, nil, nil +} + +// broadcastAsBlob broadcasts a list of coordinated events and returns a blob handle. +func broadcastAsBlob(ctx context.Context, broadcaster ocr3_1types.BlobBroadcastFetcher, events []*pb.CoordinatedEvent, expSeq uint64) ([]byte, error) { + // TODO return a slice of hashes too; encode list with protowire to hash them along the way - w/ ZERO timestamps + data, err := proto.MarshalOptions{Deterministic: true}.Marshal(&pb.CoordinatedEventList{Events: events}) + if err != nil { + return nil, fmt.Errorf("failed to marshal blob: %w", err) + } + blobHandle, err := broadcaster.BroadcastBlob(ctx, data, ocr3_1types.BlobExpirationHintSequenceNumber{SeqNr: expSeq}) + if err != nil { + return nil, fmt.Errorf("failed to broadcast blob: %w", err) + } + return blobHandle.MarshalBinary() +} diff --git a/core/services/ocr3_1/plugins/queue/kvstate.go b/core/services/ocr3_1/plugins/queue/kvstate.go index 604ea37dd2c..63c9ca955ac 100644 --- a/core/services/ocr3_1/plugins/queue/kvstate.go +++ b/core/services/ocr3_1/plugins/queue/kvstate.go @@ -4,6 +4,7 @@ import ( "cmp" "container/heap" "fmt" + "maps" "slices" "time" @@ -17,53 +18,63 @@ import ( // KV store Keys const ( - observedEventsKey = "observed_events::index" // observed events waiting for consensus (= f+1 { +func (s *observedAndQueued) pruneExpiredObservations(expiration time.Time) { + unexpiredFn := func(t *timestamppb.Timestamp) bool { return t.AsTime().After(expiration) } + maps.DeleteFunc(s.observedEvents, func(k string, v *pb.ConsensusQueueObservedEvent) bool { + if !slices.ContainsFunc(v.Deadlines, unexpiredFn) { + return false // no unexpired deadlines, so delete the whole thing + } + + // some expired, so prune them + var toDelete []int + for i, d := range v.Deadlines { + if !unexpiredFn(d) { + toDelete = append(toDelete, i) + } + } + for _, i := range toDelete { + v.Deadlines = slices.Delete(v.Deadlines, i, i+1) + v.ObservedAts = slices.Delete(v.ObservedAts, i, i+1) + v.NodeIds = slices.Delete(v.NodeIds, i, i+1) + } + + return false + }) +} + +// TODO on promotion to priority queue, ack the trigger coordinator +func (s *observedAndQueued) addObservedEvents(f int, observedEvents map[string]*pb.ConsensusQueueObservedEvent) { + for blobHash, event := range observedEvents { + obs, ok := s.observedEvents[blobHash] + if !ok && len(event.NodeIds) >= 2*f+1 { // new proposal straight to priority queue - heap.Push(s.queuedEvents, &pb.ConsensusQueueEvent{ - WorkflowID: "", //TODO parse? - TriggerEventID: "", //TODO parse? + s.queuedEvents.push(&pb.ConsensusQueueEvent{ + WorkflowID: event.WorkflowID, + TriggerEventID: event.TriggerEventID, + ObservedAt: medianTimestamp(event.ObservedAts), Deadline: medianTimestamp(event.Deadlines), Blobs: event.Blobs, }) } else if !ok { // new proposal < f + 1 - s.observedEvents.Observations[id] = event + s.observedEvents[blobHash] = event } else { // update proposal // TODO opt: build a map to avoid n^2? @@ -163,12 +211,13 @@ func (s observedAndQueued) addObservedEvents(f int, observedEvents map[string]*p obs.Blobs = append(obs.Blobs, event.Blobs[i]) } //TODO what if a node reports twice with different deadline or nodeID? do we need to overwrite? } - if len(obs.NodeIds) >= f+1 { + if len(obs.NodeIds) >= 2*f+1 { // promote proposal to priority queue - delete(s.observedEvents.Observations, id) - heap.Push(s.queuedEvents, &pb.ConsensusQueueEvent{ - WorkflowID: "", //TODO - TriggerEventID: "", //TODO + delete(s.observedEvents, blobHash) + s.queuedEvents.push(&pb.ConsensusQueueEvent{ + WorkflowID: event.WorkflowID, + TriggerEventID: event.TriggerEventID, + ObservedAt: medianTimestamp(event.ObservedAts), Deadline: medianTimestamp(event.Deadlines), Blobs: event.Blobs, }) diff --git a/core/services/ocr3_1/plugins/queue/queue.go b/core/services/ocr3_1/plugins/queue/queue.go index b9eed61a0b5..d248cb9a1c2 100644 --- a/core/services/ocr3_1/plugins/queue/queue.go +++ b/core/services/ocr3_1/plugins/queue/queue.go @@ -1,12 +1,15 @@ package queue import ( - "container/heap" + "bytes" "context" + "crypto/sha256" + "errors" "fmt" "math" "slices" "sync" + "time" "golang.org/x/exp/constraints" "golang.org/x/sync/errgroup" @@ -21,6 +24,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/capabilities/pb" "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/services" + "github.com/smartcontractkit/chainlink-common/pkg/settings/cresettings" "github.com/smartcontractkit/chainlink-common/pkg/settings/limits" "github.com/smartcontractkit/chainlink/v2/core/services/workflows/v2/triggers" @@ -32,16 +36,22 @@ type consensusQueuePluginFactory struct { lggr logger.Logger cfg *PluginConfig triggerCoordinator triggers.Coordinator + expirationDur func(context.Context) (time.Duration, error) } func NewConsensusQueuePluginFactory(lggr logger.Logger, cfg *PluginConfig, limitsFactory limits.Factory, triggerCoordinator triggers.Coordinator) (ocr3_1types.ReportingPluginFactory[[]byte], error) { - // TODO inject CapacityReporter - // TODO construct limiters - return &consensusQueuePluginFactory{lggr: lggr, cfg: cfg, triggerCoordinator: triggerCoordinator}, nil + return &consensusQueuePluginFactory{ + lggr: lggr, + cfg: cfg, + triggerCoordinator: triggerCoordinator, + expirationDur: func(ctx context.Context) (time.Duration, error) { + return cresettings.Default.ConsensusQueueExpirationInterval.GetOrDefault(ctx, limitsFactory.Settings) + }, + }, nil } func (c *consensusQueuePluginFactory) NewReportingPlugin(ctx context.Context, config ocr3types.ReportingPluginConfig, blobs ocr3_1types.BlobBroadcastFetcher) (ocr3_1types.ReportingPlugin[[]byte], ocr3_1types.ReportingPluginInfo, error) { - plugin := newConsensusQueuePlugin(c.lggr, config, c.triggerCoordinator, blobs) + plugin := newConsensusQueuePlugin(c.lggr, config, c.triggerCoordinator, c.expirationDur, blobs) pluginInfo := ocr3_1types.ReportingPluginInfo1{ Name: "ConsensusQueueReportingPlugin", Limits: c.cfg.Limits, @@ -58,13 +68,15 @@ type consensusQueuePlugin struct { onchainCfg ocr3types.ReportingPluginConfig triggerCoordinator triggers.Coordinator blobs ocr3_1types.BlobBroadcastFetcher + expirationDur func(context.Context) (time.Duration, error) } -func newConsensusQueuePlugin(lggr logger.Logger, onchainCfg ocr3types.ReportingPluginConfig, triggerCoordinator triggers.Coordinator, blobs ocr3_1types.BlobBroadcastFetcher) *consensusQueuePlugin { +func newConsensusQueuePlugin(lggr logger.Logger, onchainCfg ocr3types.ReportingPluginConfig, triggerCoordinator triggers.Coordinator, expirationGraceDur func(context.Context) (time.Duration, error), blobs ocr3_1types.BlobBroadcastFetcher) *consensusQueuePlugin { c := &consensusQueuePlugin{ lggr: logger.Named(lggr, "ConsensusQueuePlugin"), onchainCfg: onchainCfg, triggerCoordinator: triggerCoordinator, + expirationDur: expirationGraceDur, blobs: blobs, } c.Service, c.eng = services.Config{ @@ -92,50 +104,74 @@ func (c *consensusQueuePlugin) Observation( return nil, fmt.Errorf("failed to get available capacity: %w", err) } - // Build Observation var events []triggers.CoordinatedEvent - // TODO observe queue via c.CentralTriggerQueue.TakeForObservation()... one at at time? + // TODO observe queue - but can't "take" - need to confirm during StateTransition + + expirationGraceDur, err := c.expirationDur(ctx) + if err != nil { + c.lggr.Warnw("Failed to get expiration grace duration - using default", "err", err) + } + expiration := time.Now().Add(expirationGraceDur) + obs := &pb.ConsensusQueueObservation{ Events: make([]*pb.ConsensusQueueEvent, 0, len(events)), + Expiration: timestamppb.New(expiration), Capacity: uint32(min(capacity.Global, math.MaxUint32)), WorkflowCapacities: make(map[string]uint32), } - for wf, c := range capacity.PerWorkflow { + for wf, wfCap := range capacity.PerWorkflow { //TODO only for events proposed and queued in the KV store? - obs.WorkflowCapacities[wf] = uint32(min(c, math.MaxUint32)) + obs.WorkflowCapacities[wf] = uint32(min(wfCap, math.MaxUint32)) + } + + const roundDur = 10 * time.Second //TODO dynamic calibration? + expSeqNr := seqNr + uint64(expirationGraceDur/roundDur) //TODO pad extra time and/or rounds + + pbEvents := make([]*pb.CoordinatedEvent, 0, len(events)) + for _, e := range events { + pbEvents = append(pbEvents, e.ToProto()) + } + blobHandle, err := broadcastAsBlob(ctx, blobs, pbEvents, expSeqNr) + if err != nil { + return nil, err } const maxObservationSize = 0 //TODO protoOpts := proto.MarshalOptions{Deterministic: true} - for _, e := range events { - m := e.ToProto() + for i, m := range pbEvents { // Try adding to batch - //TODO broadcast now synchronously? or earlier so it's already available now? - //TODO pb.CoordinatedEvent? or could omit wfID, eventID, deadline - // handle, err := blobs.BroadcastBlob(ctx, []byte{}, ocr3_1types.BlobExpirationHintSequenceNumber{SeqNr: 0}) + protoBytes, err := protoOpts.Marshal(m) //TODO opt: don't marshal again, get hash from broadcast helper + if err != nil { + //TODO log + continue + } + blobHash := sha256.Sum256(protoBytes) + obs.Events = append(obs.Events, &pb.ConsensusQueueEvent{ WorkflowID: m.WorkflowID, TriggerEventID: m.Event.Event.Id, Deadline: m.Deadline, + BlobHash: blobHash[:], Blobs: []*pb.CoordinatedEventBlobHandle{{ - Handle: nil, //TODO - Index: 0, //TODO + Handle: blobHandle, + Index: uint32(i), }}, }) - id := e.Event.Event.ID + var addedCap bool - if _, ok := obs.WorkflowCapacities[e.WorkflowID]; !ok { + if _, ok := obs.WorkflowCapacities[m.WorkflowID]; !ok { addedCap = true - obs.WorkflowCapacities[e.WorkflowID] = uint32(min(capacity.PerWorkflow[e.WorkflowID], math.MaxUint32)) + obs.WorkflowCapacities[m.WorkflowID] = uint32(min(capacity.PerWorkflow[m.WorkflowID], math.MaxUint32)) } // Check size if protoOpts.Size(obs) > maxObservationSize { // too large, remove this one obs.Events = obs.Events[:len(obs.Events)-1] if addedCap { - delete(obs.WorkflowCapacities, id) + delete(obs.WorkflowCapacities, m.WorkflowID) } + //TODO opt: remember the blobHandle to avoid rebroadcasting events break } } @@ -144,15 +180,73 @@ func (c *consensusQueuePlugin) Observation( func (c *consensusQueuePlugin) ValidateObservation( ctx context.Context, seqNr uint64, _ ocrtypes.AttributedQuery, ao ocrtypes.AttributedObservation, - _ ocr3_1types.KeyValueStateReader, _ ocr3_1types.BlobFetcher, + _ ocr3_1types.KeyValueStateReader, blobs ocr3_1types.BlobFetcher, ) error { var obs pb.ConsensusQueueObservation err := proto.Unmarshal(ao.Observation, &obs) if err != nil { return fmt.Errorf("failed to unmarshal observation: %w", err) } - //TODO ensure each event has single blob+deadline - //TODO ensure blobs exist? + var eg errgroup.Group + for i, event := range obs.Events { + eg.Go(func() error { + if err := validateObservedEvent(ctx, blobs, event); err != nil { + return fmt.Errorf("event %d failed validation: %w", i, err) + } + return nil + }) + } + return nil +} + +func validateObservedEvent(ctx context.Context, blobs ocr3_1types.BlobFetcher, event *pb.ConsensusQueueEvent) error { + if event.WorkflowID == "" { + return errors.New("event workflow id is missing") + } + if event.TriggerEventID == "" { + return errors.New("event trigger event id is missing") + } + if event.ObservedAt == nil { + return errors.New("event observation ts is missing") + } + if event.Deadline == nil { + return errors.New("event deadline is missing") + } + if event.BlobHash == nil { + return fmt.Errorf("event blob hash is missing") + } + + if len(event.Blobs) == 0 { + return fmt.Errorf("event blob is missing") + } + if len(event.Blobs) > 1 { + return fmt.Errorf("event has more than one blob") + } + + coordEvent, pbBytes, err := fetchFromBlob(ctx, blobs, event.Blobs[0].Handle, int(event.Blobs[0].Index)) + if err != nil { + return fmt.Errorf("failed to fetch event from blob: %w", err) + } + + if coordEvent.WorkflowID != event.WorkflowID { + return fmt.Errorf("blob workflow ID %s does not match event workflow ID %s", coordEvent.WorkflowID, event.WorkflowID) + } + if coordEvent.GetEvent().GetEvent().Id != event.TriggerEventID { + return fmt.Errorf("blob event ID %s does not match event trigger event ID %s", coordEvent.GetEvent().GetEvent().Id, event.TriggerEventID) + } + + if coordEvent.ObservedAt != nil { + return fmt.Errorf("blob observation timestamp is not nil: %v", coordEvent.ObservedAt) + } + if coordEvent.Deadline != nil { + return fmt.Errorf("blob deadline timestamp is not nil: %v", coordEvent.Deadline) + } + + //TODO reduce allocations with a pool? + if shaSum := sha256.Sum256(pbBytes); !bytes.Equal(shaSum[:], event.BlobHash) { + return fmt.Errorf("blob hash %x does not match observation hash %x", shaSum, event.BlobHash) + } + return nil } @@ -167,78 +261,36 @@ func (c *consensusQueuePlugin) StateTransition( ctx context.Context, seqNr uint64, aq ocrtypes.AttributedQuery, aos []ocrtypes.AttributedObservation, kvState ocr3_1types.KeyValueStateReadWriter, fetcher ocr3_1types.BlobFetcher, ) (ocr3_1types.ReportsPlusPrecursor, error) { - var wg sync.WaitGroup + var done chan struct{} + var obs observations - //TODO is median only logical option for capacity? what if honest nodes have less, don't we ideally want execute min(honest)? - // consider some configurable x% - var medianCap uint32 - var medianCapPerWF map[string]uint32 // wf ID -> capacity - //TODO key on eventID+workflowID? - var newObservedEvents map[string]*pb.ConsensusQueueObservedEvent // trigger event ID -> event go func() { - defer wg.Done() - - capacities := make([]uint32, 0, len(aos)) - wfCapacities := make(map[string][]uint32) - for _, ao := range aos { - var obs pb.ConsensusQueueObservation - err := proto.Unmarshal(ao.Observation, &obs) - if err != nil { - c.lggr.Errorw("Failed to unmarshal observation", "err", err) - continue - } - capacities = append(capacities, obs.Capacity) - for wf, c := range obs.WorkflowCapacities { - wfCapacities[wf] = append(wfCapacities[wf], c) - } - for _, event := range obs.Events { - //TODO key=WFID+eventID? - mergedEvent, ok := newObservedEvents[event.TriggerEventID] - if !ok { - mergedEvent = &pb.ConsensusQueueObservedEvent{ - Deadlines: []*timestamppb.Timestamp{event.Deadline}, - NodeIds: []uint8{uint8(ao.Observer)}, - Blobs: []*pb.CoordinatedEventBlobHandle{event.Blobs[0]}, - } - } else { - mergedEvent.Deadlines = append(mergedEvent.Deadlines, event.Deadline) - mergedEvent.Blobs = append(mergedEvent.Blobs, event.Blobs...) - } - - newObservedEvents[event.TriggerEventID] = mergedEvent - } - } - medianCap = median(capacities) - for wf, c := range wfCapacities { - medianCapPerWF[wf] = median(c) + defer close(done) + if warn := obs.aggregate(ctx, aos); warn != nil { + c.lggr.Warnw("Failed to aggregate some observations", "err", warn) } }() - // Deserialize the KV store into memory - //TODO package in a constructor for observedAndQueued? - state := newStateReadWriter(kvState) - observedEvents, err := state.readObservedEvents() - if err != nil { - return nil, err - } - queuedEvents, err := state.readPriorityQueue() + stateRW := newStateReadWriter(kvState) + state, err := stateRW.readObservedAndQueued() if err != nil { return nil, err } - heap.Init(&queuedEvents) //TODO or can we trust it? - - //TODO prune expired events from proposed and priorityQueue - wg.Wait() // TODO also wait if we return early for error - - // Collect observed proposals and promote to priority queue on f+1 - observedAndQueued{ - observedEvents: observedEvents, - queuedEvents: &queuedEvents, - }.addObservedEvents(c.onchainCfg.F, newObservedEvents) + // wait for aggregation + select { + case <-ctx.Done(): + return nil, ctx.Err() + case <-done: + if err = ctx.Err(); err != nil { + return nil, err + } + } - // Select items from queue based on priority and capacity - consensusEvents, err := queuedEvents.PopCap(medianCap, medianCapPerWF) + // update state + state.pruneExpiredObservations(obs.medianExpiration) + state.addObservedEvents(c.onchainCfg.F, obs.newObservedEvents) + consensusEvents, err := state.queuedEvents.popLimited(obs.medianCap, obs.medianCapPerWF, obs.medianExpiration) if err != nil { return nil, err } @@ -246,15 +298,7 @@ func (c *consensusQueuePlugin) StateTransition( // Updated KV Store //TODO might we hit a KV size limit in the middle of these? then what? can't just drop proposals // alternative: proposals only valid when there is definitely enough space - err = state.writeObservedEvents(observedEvents) - if err != nil { - return nil, err - } - err = state.writePriorityQueue(queuedEvents) - if err != nil { - return nil, err - } - err = state.writeConsensusEvents(&pb.ConsensusQueueEventList{Events: consensusEvents}) + err = stateRW.update(state, consensusEvents) if err != nil { return nil, err } @@ -263,6 +307,66 @@ func (c *consensusQueuePlugin) StateTransition( return ocr3_1types.ReportsPlusPrecursor{}, nil } +type observations struct { + medianExpiration time.Time + medianCap uint32 + medianCapPerWF map[string]uint32 // wf ID -> capacity + newObservedEvents map[string]*pb.ConsensusQueueObservedEvent // key: blobHash +} + +// TODO consider some configurable x% of capacity since some honest nodes have less +func (res *observations) aggregate(ctx context.Context, aos []ocrtypes.AttributedObservation) (warn error) { + res.medianCapPerWF = make(map[string]uint32) + res.newObservedEvents = make(map[string]*pb.ConsensusQueueObservedEvent) + + expirations := make([]*timestamppb.Timestamp, 0, len(aos)) + capacities := make([]uint32, 0, len(aos)) + wfCapacities := make(map[string][]uint32) + for _, ao := range aos { + var obs pb.ConsensusQueueObservation + err := proto.Unmarshal(ao.Observation, &obs) + if err != nil { + warn = errors.Join(warn, fmt.Errorf("failed to unmarshal observation from oracle %d: %w", ao.Observation, err)) + continue + } + expirations = append(expirations, obs.Expiration) + capacities = append(capacities, obs.Capacity) + for wf, c := range obs.WorkflowCapacities { + wfCapacities[wf] = append(wfCapacities[wf], c) + } + for _, event := range obs.Events { + if ctx.Err() != nil { + return + } + aggregated, ok := res.newObservedEvents[string(event.BlobHash)] + if !ok { + aggregated = &pb.ConsensusQueueObservedEvent{ + TriggerEventID: event.TriggerEventID, + WorkflowID: event.WorkflowID, + NodeIds: []uint8{uint8(ao.Observer)}, + ObservedAts: []*timestamppb.Timestamp{event.ObservedAt}, + Deadlines: []*timestamppb.Timestamp{event.Deadline}, + Blobs: []*pb.CoordinatedEventBlobHandle{event.Blobs[0]}, + } + } else { + // note: trigger event and workflow ID alignment is ensured by ValidateObservation + aggregated.NodeIds = append(aggregated.NodeIds, uint8(ao.Observer)) + aggregated.ObservedAts = append(aggregated.ObservedAts, event.ObservedAt) + aggregated.Deadlines = append(aggregated.Deadlines, event.Deadline) + aggregated.Blobs = append(aggregated.Blobs, event.Blobs...) + } + + res.newObservedEvents[string(event.BlobHash)] = aggregated + } + } + res.medianExpiration = medianTimestamp(expirations).AsTime() + res.medianCap = median(capacities) + for wf, c := range wfCapacities { + res.medianCapPerWF[wf] = median(c) + } + return +} + func (c *consensusQueuePlugin) Committed(ctx context.Context, seqNr uint64, keyValueStateReader ocr3_1types.KeyValueStateReader) error { c.tryStartExecutions(keyValueStateReader) return nil @@ -271,63 +375,64 @@ func (c *consensusQueuePlugin) Committed(ctx context.Context, seqNr uint64, keyV // tryStartExecutions calls StartExecution asynchronously on the corresponding engine for each trigger event. // It is idempotent, thus safe to call from Observation and Committed. func (c *consensusQueuePlugin) tryStartExecutions(reader ocr3_1types.KeyValueStateReader) { - state := stateReader{reader} - pbs, err := state.readConsensusEvents() + v, err := reader.Read([]byte(consensusEventsKey)) if err != nil { c.lggr.Errorw("Failed to read consensus events", "err", err) return } + var consensusEvents []*pb.ConsensusQueueEvent + if v != nil { + var pbs *pb.ConsensusQueueEventList + if err := proto.Unmarshal(v, pbs); err != nil { + c.lggr.Errorw("Failed to unmarshal consensus events", "err", err) + return + } + } var wg sync.WaitGroup - for _, pbEvent := range pbs.Events { - var event triggers.CoordinatedEvent + for _, consensusEvent := range consensusEvents { wg.Add(1) c.eng.Go(func(ctx context.Context) { defer wg.Done() - // fetch blobs with observed events - errGrp := new(errgroup.Group) - observedEvents := make([]*pb.CoordinatedEvent, len(pbEvent.Blobs)) - for i, blob := range pbEvent.Blobs { - errGrp.Go(func() error { - var handle ocr3_1types.BlobHandle - if err := handle.UnmarshalBinary(blob.Handle); err != nil { - return fmt.Errorf("failed to unmarshal blob handle: %w", err) - } - b, err := c.blobs.FetchBlob(ctx, handle) - if err != nil { - return fmt.Errorf("failed to fetch blob: %w", err) - } - //TODO allocate element first? - if err := proto.Unmarshal(b, observedEvents[i]); err != nil { - return fmt.Errorf("failed to unmarshal CoordinatedEvent from blob: %w", err) - } - return nil - }) - } - if err := errGrp.Wait(); err != nil { - c.lggr.Errorw("Failed to fetch blob for event; unable to execute", "eventID", pbEvent.TriggerEventID, "err", err) + if err2 := c.tryStartExecution(ctx, consensusEvent); err2 != nil { + c.lggr.Errorw("Failed to execute event", "eventID", consensusEvent.TriggerEventID, "err", err2) return } + }) + } + wg.Wait() +} - //TODO we don't always want a continuous median, e.g. IDs - // maybe mode if it exists, otherwise fallback to each node using its own observed value? - if err := event.FromProto(&pb.CoordinatedEvent{ - WorkflowID: pbEvent.WorkflowID, - TriggerCapID: "", //TODO from blob median? - TriggerIndex: 0, //TODO from blob median? - ObservedAt: nil, //TODO from blob median? - Deadline: pbEvent.Deadline, - Event: nil, //TODO from blob ....piecewise median? - }); err != nil { - c.lggr.Errorw("Failed to unmarshal CoordinatedEvent", "pb", pbEvent.String(), "err", err) - } +func (c *consensusQueuePlugin) tryStartExecution(ctx context.Context, consensusEvent *pb.ConsensusQueueEvent) error { + // any blob will do, first that exists + var pbEvent *pb.CoordinatedEvent + var errs []error + for _, blob := range consensusEvent.Blobs { + var err error + pbEvent, _, err = fetchFromBlob(ctx, c.blobs, blob.Handle, int(blob.Index)) + if err != nil { + errs = append(errs, fmt.Errorf("failed to fetch blob: %w", err)) + c.lggr.Warnw("Failed to fetch blob", "handle", blob.Handle, "index", blob.Index, "err", err) + continue // try next blob + } + break + } + if pbEvent == nil { + return fmt.Errorf("failed to fetch blob from all %d handles: %w", len(consensusEvent.Blobs), errors.Join(errs...)) + } + // fill in medianized timestamps + pbEvent.ObservedAt = consensusEvent.ObservedAt + pbEvent.Deadline = consensusEvent.Deadline - // TODO execute StartExecution - // c.triggerCoordinator.tryStartExecution(ctx, event) - }) + var event triggers.CoordinatedEvent + if err := event.FromProto(pbEvent); err != nil { + return fmt.Errorf("failed to convert CoordinatedEvent from proto: %w", err) } - wg.Wait() //TODO do we need to wait? + + // TODO execute StartExecution + // c.triggerCoordinator.tryStartExecution(ctx, event) + return nil } func (c *consensusQueuePlugin) Reports(ctx context.Context, seqNr uint64, reportsPlusPrecursor ocr3_1types.ReportsPlusPrecursor) ([]ocr3types.ReportPlus[[]byte], error) { diff --git a/deployment/go.mod b/deployment/go.mod index dd2995105e0..d3be9e9c97e 100644 --- a/deployment/go.mod +++ b/deployment/go.mod @@ -41,7 +41,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/solana/deployment v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-data-streams v1.1.2-0.20261009064810-68424c714170 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 @@ -430,7 +430,7 @@ require ( github.com/smartcontractkit/chainlink-canton/authentication v1.0.0 // indirect github.com/smartcontractkit/chainlink-canton/contracts/v2 v2.1.0 // indirect github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 // indirect - github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 // indirect + github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 // indirect github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa // indirect github.com/smartcontractkit/chainlink-feeds v0.1.2-0.20250227211209-7cd000095135 // indirect github.com/smartcontractkit/chainlink-framework/chains v0.0.0-20261009212658-df7dcfcb7a77 // indirect diff --git a/deployment/go.sum b/deployment/go.sum index 6e188fc630e..e1a6402cf6a 100644 --- a/deployment/go.sum +++ b/deployment/go.sum @@ -1411,12 +1411,12 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 h1:2APdbnh8Uf/h/THKSZM3g2IW/10ah+ygqwMZltOlBqU= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360/go.mod h1:hdp2bQBzIDJt3UhXKnLz4OMHpsOW54Z9E9Txx4SVC8w= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 h1:nzm+zgN1C6kNVlQnlp3XlzqFl7g9K5h63mRyctvGNRE= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= -github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= -github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549/go.mod h1:Scyk7O80fde5rJF3Ty3fEE3xiS6j84eWbu8/2gl3pIY= +github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= +github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9/go.mod h1:Scyk7O80fde5rJF3Ty3fEE3xiS6j84eWbu8/2gl3pIY= github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa h1:7yIjZpk1mYYu630yXcGR7N+a+pcAHvn4OHlfhJK8GGY= github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa/go.mod h1:nfT8vdE44iAlhDWDV6PaBWucxZZAcDsgGkZ+D0kHpAI= github.com/smartcontractkit/chainlink-data-streams v1.1.2-0.20261009064810-68424c714170 h1:HeQlHO9MrUXTJmxYCNX4xPX14glLAdwIN3igc9Am/g8= diff --git a/go.mod b/go.mod index 833e8bd1f11..8485ebe8c95 100644 --- a/go.mod +++ b/go.mod @@ -82,9 +82,9 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260908155618-50f521d70e62 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260908155618-50f521d70e62 github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260903141829-ef07b52a737d - github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 + github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 github.com/smartcontractkit/chainlink-data-streams v1.1.2-0.20261009064810-68424c714170 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261022195454-600e2b321c7a github.com/smartcontractkit/chainlink-evm/contracts/cre/gobindings v0.0.0-20260403151002-2c91155b5501 diff --git a/go.sum b/go.sum index 2b0279f5ca4..2bf1e20560a 100644 --- a/go.sum +++ b/go.sum @@ -1104,12 +1104,12 @@ github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260908155618-50f521d70e62/go.mod h1:c++Ed0jeYn4w8WIfiAboRwN6ClRRVGglL0qwB/QjJvM= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 h1:2APdbnh8Uf/h/THKSZM3g2IW/10ah+ygqwMZltOlBqU= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360/go.mod h1:hdp2bQBzIDJt3UhXKnLz4OMHpsOW54Z9E9Txx4SVC8w= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 h1:nzm+zgN1C6kNVlQnlp3XlzqFl7g9K5h63mRyctvGNRE= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260903141829-ef07b52a737d h1:M9xuiIvdiHtim4nlxCVajyC/Mk63tAg9ESWb/biAhNA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260903141829-ef07b52a737d/go.mod h1:rI2njmTlyTvh+xhmORmK6qX3+V1ycDAqGJLu8LS8WpU= -github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= -github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549/go.mod h1:Scyk7O80fde5rJF3Ty3fEE3xiS6j84eWbu8/2gl3pIY= +github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= +github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9/go.mod h1:Scyk7O80fde5rJF3Ty3fEE3xiS6j84eWbu8/2gl3pIY= github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa h1:7yIjZpk1mYYu630yXcGR7N+a+pcAHvn4OHlfhJK8GGY= github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa/go.mod h1:nfT8vdE44iAlhDWDV6PaBWucxZZAcDsgGkZ+D0kHpAI= github.com/smartcontractkit/chainlink-data-streams v1.1.2-0.20261009064810-68424c714170 h1:HeQlHO9MrUXTJmxYCNX4xPX14glLAdwIN3igc9Am/g8= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 490c471a243..3d443a8161e 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -30,7 +30,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260916222901-720a003dab50 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261022195454-600e2b321c7a @@ -405,7 +405,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/solana/deployment v0.0.0-20260916222901-720a003dab50 // indirect github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca // indirect github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 // indirect - github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 // indirect + github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 // indirect github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa // indirect github.com/smartcontractkit/chainlink-data-streams v1.1.2-0.20261009064810-68424c714170 // indirect github.com/smartcontractkit/chainlink-evm/contracts/cre/gobindings v0.0.0-20260403151002-2c91155b5501 // indirect diff --git a/integration-tests/go.sum b/integration-tests/go.sum index af21626863c..3bc11225002 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1396,12 +1396,12 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 h1:2APdbnh8Uf/h/THKSZM3g2IW/10ah+ygqwMZltOlBqU= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360/go.mod h1:hdp2bQBzIDJt3UhXKnLz4OMHpsOW54Z9E9Txx4SVC8w= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 h1:nzm+zgN1C6kNVlQnlp3XlzqFl7g9K5h63mRyctvGNRE= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= -github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= -github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549/go.mod h1:Scyk7O80fde5rJF3Ty3fEE3xiS6j84eWbu8/2gl3pIY= +github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= +github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9/go.mod h1:Scyk7O80fde5rJF3Ty3fEE3xiS6j84eWbu8/2gl3pIY= github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa h1:7yIjZpk1mYYu630yXcGR7N+a+pcAHvn4OHlfhJK8GGY= github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa/go.mod h1:nfT8vdE44iAlhDWDV6PaBWucxZZAcDsgGkZ+D0kHpAI= github.com/smartcontractkit/chainlink-data-streams v1.1.2-0.20261009064810-68424c714170 h1:HeQlHO9MrUXTJmxYCNX4xPX14glLAdwIN3igc9Am/g8= diff --git a/integration-tests/load/go.mod b/integration-tests/load/go.mod index 3a48b7ec505..2747299cb57 100644 --- a/integration-tests/load/go.mod +++ b/integration-tests/load/go.mod @@ -20,7 +20,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260916222901-720a003dab50 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261022195454-600e2b321c7a github.com/smartcontractkit/chainlink-testing-framework/framework v0.16.9 @@ -476,7 +476,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca // indirect github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 // indirect github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd // indirect - github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 // indirect + github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 // indirect github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa // indirect github.com/smartcontractkit/chainlink-data-streams v1.1.2-0.20261009064810-68424c714170 // indirect github.com/smartcontractkit/chainlink-evm/contracts/cre/gobindings v0.0.0-20260403151002-2c91155b5501 // indirect diff --git a/integration-tests/load/go.sum b/integration-tests/load/go.sum index 96d4c66a9d8..57597143855 100644 --- a/integration-tests/load/go.sum +++ b/integration-tests/load/go.sum @@ -1636,12 +1636,12 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 h1:2APdbnh8Uf/h/THKSZM3g2IW/10ah+ygqwMZltOlBqU= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360/go.mod h1:hdp2bQBzIDJt3UhXKnLz4OMHpsOW54Z9E9Txx4SVC8w= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 h1:nzm+zgN1C6kNVlQnlp3XlzqFl7g9K5h63mRyctvGNRE= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= -github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= -github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549/go.mod h1:Scyk7O80fde5rJF3Ty3fEE3xiS6j84eWbu8/2gl3pIY= +github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= +github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9/go.mod h1:Scyk7O80fde5rJF3Ty3fEE3xiS6j84eWbu8/2gl3pIY= github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa h1:7yIjZpk1mYYu630yXcGR7N+a+pcAHvn4OHlfhJK8GGY= github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa/go.mod h1:nfT8vdE44iAlhDWDV6PaBWucxZZAcDsgGkZ+D0kHpAI= github.com/smartcontractkit/chainlink-data-streams v1.1.2-0.20261009064810-68424c714170 h1:HeQlHO9MrUXTJmxYCNX4xPX14glLAdwIN3igc9Am/g8= diff --git a/system-tests/lib/go.mod b/system-tests/lib/go.mod index 4d2ec1df93b..1d0ce30854a 100644 --- a/system-tests/lib/go.mod +++ b/system-tests/lib/go.mod @@ -32,7 +32,7 @@ require ( github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-aptos v0.0.0-20260923062809-ca886ade4d26 github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260916222901-720a003dab50 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-confidential-compute v1.3.0 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 @@ -486,7 +486,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260916222901-720a003dab50 // indirect github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca // indirect github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 // indirect - github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 // indirect + github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 // indirect github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa // indirect github.com/smartcontractkit/chainlink-data-streams v1.1.2-0.20261009064810-68424c714170 // indirect github.com/smartcontractkit/chainlink-evm/contracts/cre/gobindings v0.0.0-20260403151002-2c91155b5501 // indirect diff --git a/system-tests/lib/go.sum b/system-tests/lib/go.sum index 48828ac54a2..203956afb5e 100644 --- a/system-tests/lib/go.sum +++ b/system-tests/lib/go.sum @@ -1657,12 +1657,12 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 h1:2APdbnh8Uf/h/THKSZM3g2IW/10ah+ygqwMZltOlBqU= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360/go.mod h1:hdp2bQBzIDJt3UhXKnLz4OMHpsOW54Z9E9Txx4SVC8w= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 h1:nzm+zgN1C6kNVlQnlp3XlzqFl7g9K5h63mRyctvGNRE= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= -github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= -github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549/go.mod h1:Scyk7O80fde5rJF3Ty3fEE3xiS6j84eWbu8/2gl3pIY= +github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= +github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9/go.mod h1:Scyk7O80fde5rJF3Ty3fEE3xiS6j84eWbu8/2gl3pIY= github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa h1:7yIjZpk1mYYu630yXcGR7N+a+pcAHvn4OHlfhJK8GGY= github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa/go.mod h1:nfT8vdE44iAlhDWDV6PaBWucxZZAcDsgGkZ+D0kHpAI= github.com/smartcontractkit/chainlink-confidential-compute v1.3.0 h1:y64hOzM9H61E4EYRzQDtRwqunDBlKpsZc1SvFEUlSLE= diff --git a/system-tests/tests/go.mod b/system-tests/tests/go.mod index ad2b048379f..bf80ac8f49d 100644 --- a/system-tests/tests/go.mod +++ b/system-tests/tests/go.mod @@ -73,9 +73,9 @@ require ( github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-aptos v0.0.0-20260923062809-ca886ade4d26 github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260916222901-720a003dab50 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd - github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 + github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 github.com/smartcontractkit/chainlink-confidential-compute v1.3.0 github.com/smartcontractkit/chainlink-confidential-compute/tests/testhelpers v0.0.0-20260812145307-d77342c53d7d github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 diff --git a/system-tests/tests/go.sum b/system-tests/tests/go.sum index 997f758cb2d..0abf9c77984 100644 --- a/system-tests/tests/go.sum +++ b/system-tests/tests/go.sum @@ -1836,12 +1836,12 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360 h1:2APdbnh8Uf/h/THKSZM3g2IW/10ah+ygqwMZltOlBqU= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261109132522-ceedd30df360/go.mod h1:hdp2bQBzIDJt3UhXKnLz4OMHpsOW54Z9E9Txx4SVC8w= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 h1:nzm+zgN1C6kNVlQnlp3XlzqFl7g9K5h63mRyctvGNRE= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= -github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549 h1:J4vYRJxkBO8Yf//17wScKjYWmS45VZaFWx0zt+4ETEU= -github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261005132539-b7d63d5fd549/go.mod h1:Scyk7O80fde5rJF3Ty3fEE3xiS6j84eWbu8/2gl3pIY= +github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= +github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9/go.mod h1:Scyk7O80fde5rJF3Ty3fEE3xiS6j84eWbu8/2gl3pIY= github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa h1:7yIjZpk1mYYu630yXcGR7N+a+pcAHvn4OHlfhJK8GGY= github.com/smartcontractkit/chainlink-common/x/config v0.0.0-20260928140953-a9b0d3a04daa/go.mod h1:nfT8vdE44iAlhDWDV6PaBWucxZZAcDsgGkZ+D0kHpAI= github.com/smartcontractkit/chainlink-confidential-compute v1.3.0 h1:y64hOzM9H61E4EYRzQDtRwqunDBlKpsZc1SvFEUlSLE= From 711d0547a2c27220849b4492f232be13add05f4e Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Fri, 13 Nov 2026 05:43:58 -0600 Subject: [PATCH 07/13] cleanup & fixes --- core/services/ocr2/delegate.go | 21 ++- core/services/ocr3_1/plugins/queue/blobs.go | 48 +++++- .../ocr3_1/plugins/queue/blobs_test.go | 80 ++++++++++ core/services/ocr3_1/plugins/queue/kvstate.go | 140 +++++++++--------- core/services/ocr3_1/plugins/queue/math.go | 52 +++++++ core/services/ocr3_1/plugins/queue/queue.go | 135 +++++++++-------- .../ocr3_1/plugins/queue/queue_test.go | 1 + .../ocr3_1/plugins/queue/transmitter.go | 45 +----- 8 files changed, 326 insertions(+), 196 deletions(-) create mode 100644 core/services/ocr3_1/plugins/queue/blobs_test.go create mode 100644 core/services/ocr3_1/plugins/queue/math.go create mode 100644 core/services/ocr3_1/plugins/queue/queue_test.go diff --git a/core/services/ocr2/delegate.go b/core/services/ocr2/delegate.go index fd6aaf65896..4d2bfb273c8 100644 --- a/core/services/ocr2/delegate.go +++ b/core/services/ocr2/delegate.go @@ -877,17 +877,16 @@ func (d *Delegate) newServicesConsensusQueue( BinaryNetworkEndpointFactory: d.peerWrapper.Peer3_1, V2Bootstrappers: bootstrapPeers, ContractConfigTracker: configTracker, - //TODO pass engine as EventSink - ContractTransmitter: queue.NewTransmitter(lggr, ocrtypes.Account(spec.TransmitterID.String), nil), - Database: ocrDB, - KeyValueDatabaseFactory: kvFactory, - LocalConfig: lc, - Logger: ocrLogger, - MonitoringEndpoint: oracleEndpoint, - OffchainConfigDigester: configDigester, - OffchainKeyring: kb, - OnchainKeyring: ocr3shims.OnchainKeyringAsOnchainKeyring2(onchainKeyringAdapter), - MetricsRegisterer: prometheus.WrapRegistererWith(map[string]string{"job_name": jb.Name.ValueOrZero()}, prometheus.DefaultRegisterer), + ContractTransmitter: queue.NewTransmitter(ocrtypes.Account(spec.TransmitterID.String)), + Database: ocrDB, + KeyValueDatabaseFactory: kvFactory, + LocalConfig: lc, + Logger: ocrLogger, + MonitoringEndpoint: oracleEndpoint, + OffchainConfigDigester: configDigester, + OffchainKeyring: kb, + OnchainKeyring: ocr3shims.OnchainKeyringAsOnchainKeyring2(onchainKeyringAdapter), + MetricsRegisterer: prometheus.WrapRegistererWith(map[string]string{"job_name": jb.Name.ValueOrZero()}, prometheus.DefaultRegisterer), } rpf, err := queue.NewConsensusQueuePluginFactory(lggr, cfg, d.limitsFactory, d.triggerCoordinator) diff --git a/core/services/ocr3_1/plugins/queue/blobs.go b/core/services/ocr3_1/plugins/queue/blobs.go index 492b0d2c9fb..df2ef7aa753 100644 --- a/core/services/ocr3_1/plugins/queue/blobs.go +++ b/core/services/ocr3_1/plugins/queue/blobs.go @@ -5,6 +5,7 @@ import ( "fmt" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3_1types" + "google.golang.org/protobuf/encoding/protowire" "google.golang.org/protobuf/proto" "github.com/smartcontractkit/chainlink-common/pkg/capabilities/pb" @@ -20,16 +21,47 @@ func fetchFromBlob(ctx context.Context, fetcher ocr3_1types.BlobFetcher, handle if err != nil { return nil, nil, fmt.Errorf("failed to fetch blob: %w", err) } - //TODO optimize using protowire to avoid unmarshalling the entire blob - var coordEvents *pb.CoordinatedEventList - if err := proto.Unmarshal(b, coordEvents); err != nil { - return nil, nil, fmt.Errorf("failed to unmarshal blob: %w", err) + + coordEvent, err := extractEvent(b, idx) + if err != nil { + return nil, nil, err } - if idx >= len(coordEvents.Events) { - return nil, nil, fmt.Errorf("blob index %d is out of range for blob with %d events", idx, len(coordEvents.Events)) + return coordEvent, b, nil +} + +// extractEvent extracts the idx-th event from the blob, without unmarshaling any other events. +func extractEvent(b []byte, idx int) (*pb.CoordinatedEvent, error) { + //TODO can we lock this in with code? + const fieldNumber = 1 // pb.CoordinatedEventList.Events + i := 0 + for len(b) > 0 { + num, typ, n := protowire.ConsumeTag(b) + if n < 0 { + return nil, protowire.ParseError(n) + } + b = b[n:] + if num == fieldNumber { + if typ != protowire.BytesType { + return nil, fmt.Errorf("expected bytes type for field %d, got %d", fieldNumber, typ) + } + v, m := protowire.ConsumeBytes(b) + if m < 0 { + return nil, protowire.ParseError(m) + } + if i == idx { + var event pb.CoordinatedEvent + if err := proto.Unmarshal(v, &event); err != nil { + return nil, fmt.Errorf("failed to unmarshal event: %w", err) + } + return &event, nil + } + // advance + i++ + b = b[m:] + continue + } } - coordEvent := coordEvents.Events[idx] - return coordEvent, nil, nil + return nil, fmt.Errorf("index %d out of range", idx) } // broadcastAsBlob broadcasts a list of coordinated events and returns a blob handle. diff --git a/core/services/ocr3_1/plugins/queue/blobs_test.go b/core/services/ocr3_1/plugins/queue/blobs_test.go new file mode 100644 index 00000000000..35e5b81028b --- /dev/null +++ b/core/services/ocr3_1/plugins/queue/blobs_test.go @@ -0,0 +1,80 @@ +package queue + +import ( + "testing" + "time" + + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/types/known/anypb" + "google.golang.org/protobuf/types/known/timestamppb" + + "github.com/smartcontractkit/chainlink-common/pkg/capabilities/pb" +) + +func Test_extractEvent(t *testing.T) { + payload, err := anypb.New(timestamppb.New(time.Now())) + require.NoError(t, err) + event := &pb.CoordinatedEvent{ + WorkflowID: "want", + TriggerCapID: "capID", + TriggerIndex: 1, + ObservedAt: ×tamppb.Timestamp{Seconds: 10, Nanos: 42}, + Deadline: timestamppb.New(time.Now()), + Event: &pb.TriggerResponse{ + Event: &pb.TriggerEvent{ + TriggerType: "type", + Id: "id", + Outputs: nil, + Payload: payload, + }, + Error: "asdf", + }, + } + otherPayload, err := anypb.New(&pb.CapabilityResponse{}) + require.NoError(t, err) + others := &pb.CoordinatedEvent{ + WorkflowID: "foo", + TriggerCapID: "bar", + TriggerIndex: 99, + ObservedAt: ×tamppb.Timestamp{Nanos: 99}, + Deadline: ×tamppb.Timestamp{Seconds: 1000}, + Event: &pb.TriggerResponse{ + Event: &pb.TriggerEvent{ + TriggerType: "baz", + Id: "trigger-id", + Outputs: nil, + Payload: otherPayload, + }, + Error: "none", + }, + } + for _, tt := range []struct { + name string + len, idx int + }{ + {"first", 4, 0}, + {"last", 4, 3}, + {"middle", 4, 2}, + {"bounds", 4, 4}, + } { + t.Run(tt.name, func(t *testing.T) { + var events []*pb.CoordinatedEvent + for i := range tt.len { + if i == tt.idx { + events = append(events, event) + } else { + events = append(events, others) + } + } + b, err := proto.MarshalOptions{Deterministic: true}.Marshal(&pb.CoordinatedEventList{Events: events}) + require.NoError(t, err) + got, err := extractEvent(b, tt.idx) + if tt.idx < tt.len { + require.True(t, proto.Equal(event, got)) + } else { + require.Error(t, err) + } + }) + } +} diff --git a/core/services/ocr3_1/plugins/queue/kvstate.go b/core/services/ocr3_1/plugins/queue/kvstate.go index 63c9ca955ac..d999b8edd26 100644 --- a/core/services/ocr3_1/plugins/queue/kvstate.go +++ b/core/services/ocr3_1/plugins/queue/kvstate.go @@ -16,46 +16,70 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/capabilities/pb" ) -// KV store Keys +// KV store keys const ( - observedEventsKey = "observed_events::index" // observed events waiting for consensus (<2f+1 observers) - priorityQueueKey = "priority_queue::index" // priority queue of events waiting for capacity - consensusEventsKey = "consensus_events::index" // events the plugin committed to sending to nodes + // observed events waiting for consensus (<2f+1 observers) + observedEventsKey = "observed_events::index" // pb.ConsensusQueueObservedEvents { map[string]*pb.ConsensusQueueObservedEvent } + // priority queue of events waiting for capacity + priorityQueueKey = "priority_queue::index" // pb.ConsensusQueueEventList { []*pb.ConsensusQueueEvent } + // events the plugin committed to sending to nodes + consensusEventsKey = "consensus_events::index" // pb.ConsensusQueueEventList { []*pb.ConsensusQueueEvent } ) +type stateReader struct { + kv ocr3_1types.KeyValueStateReader +} + +type stateReadWriter struct { + stateReader + kv ocr3_1types.KeyValueStateReadWriter +} + +func newStateReadWriter(kv ocr3_1types.KeyValueStateReadWriter) stateReadWriter { + return stateReadWriter{stateReader: stateReader{kv: kv}, kv: kv} +} + +func (s stateReadWriter) writeValue[M proto.Message](key string, m M) error { + val, err := proto.MarshalOptions{Deterministic: true}.Marshal(m) + if err != nil { + return fmt.Errorf("failed to marshal %T: %w", m, err) + } + return s.kv.Write([]byte(key), val) +} + // readObservedAndQueued reads both observed events and priority queue events from the KV store. func (s stateReader) readObservedAndQueued() (*observedAndQueued, error) { var obsQ observedAndQueued v, err := s.kv.Read([]byte(observedEventsKey)) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to read observed events: %w", err) } if v != nil { - var queued *pb.ConsensusQueueObservedEvents - if err = proto.Unmarshal(v, queued); err != nil { + var observed *pb.ConsensusQueueObservedEvents + if err = proto.Unmarshal(v, observed); err != nil { return nil, err } - obsQ.observedEvents = queued.Observations + obsQ.observedEvents = observed.GetObservations() } else { obsQ.observedEvents = make(map[string]*pb.ConsensusQueueObservedEvent) } v, err = s.kv.Read([]byte(priorityQueueKey)) if err != nil { - return nil, err + return nil, fmt.Errorf("failed to read queued events: %w", err) } if v != nil { - var consensus *pb.ConsensusQueueEventList - if err = proto.Unmarshal(v, consensus); err != nil { + var queued *pb.ConsensusQueueEventList + if err = proto.Unmarshal(v, queued); err != nil { return nil, err } - obsQ.queuedEvents = new(priorityQueue(consensus.Events)) + obsQ.queuedEvents = new(priorityQueue(queued.GetEvents())) } return &obsQ, nil } -func (s stateReadWriter) update(state *observedAndQueued, consensus []*pb.ConsensusQueueEvent) error { +func (s stateReadWriter) writeAll(state *observedAndQueued, consensus []*pb.ConsensusQueueEvent) error { err := s.writeValue(observedEventsKey, &pb.ConsensusQueueObservedEvents{Observations: state.observedEvents}) if err != nil { return fmt.Errorf("failed to write observed events: %w", err) @@ -71,27 +95,6 @@ func (s stateReadWriter) update(state *observedAndQueued, consensus []*pb.Consen return nil } -type stateReader struct { - kv ocr3_1types.KeyValueStateReader -} - -type stateReadWriter struct { - stateReader - kv ocr3_1types.KeyValueStateReadWriter -} - -func newStateReadWriter(kv ocr3_1types.KeyValueStateReadWriter) stateReadWriter { - return stateReadWriter{stateReader: stateReader{kv: kv}, kv: kv} -} - -func (s stateReadWriter) writeValue[M proto.Message](key string, m M) error { - val, err := proto.MarshalOptions{Deterministic: true}.Marshal(m) - if err != nil { - return err - } - return s.kv.Write([]byte(key), val) -} - var _ heap.Interface = (*priorityQueue)(nil) // priorityQueue is a heap of coordinated events, ordered by deadline and then event ID. @@ -121,6 +124,19 @@ func (p *priorityQueue) Pop() any { func (p *priorityQueue) push(x *pb.ConsensusQueueEvent) { heap.Push(p, x) } +func (p *priorityQueue) pushObservations(blobHash string, event *pb.ConsensusQueueObservedEvent) { + p.push(&pb.ConsensusQueueEvent{ + WorkflowID: event.WorkflowID, + TriggerEventID: event.TriggerEventID, + ObservedAt: medianTimestamp(event.ObservedAts), + Deadline: medianTimestamp(event.Deadlines), + BlobHash: []byte(blobHash), + Blobs: event.Blobs, + }) +} + +// mustPop pops the next event from the queue, or returns nil if the queue is empty. +// The value must be of type *pb.ConsensusQueueEvent. Use push to ensure this. func (p *priorityQueue) mustPop() *pb.ConsensusQueueEvent { if len(*p) == 0 { return nil @@ -176,9 +192,10 @@ func (s *observedAndQueued) pruneExpiredObservations(expiration time.Time) { } } for _, i := range toDelete { - v.Deadlines = slices.Delete(v.Deadlines, i, i+1) - v.ObservedAts = slices.Delete(v.ObservedAts, i, i+1) v.NodeIds = slices.Delete(v.NodeIds, i, i+1) + v.ObservedAts = slices.Delete(v.ObservedAts, i, i+1) + v.Deadlines = slices.Delete(v.Deadlines, i, i+1) + v.Blobs = slices.Delete(v.Blobs, i, i+1) } return false @@ -186,54 +203,31 @@ func (s *observedAndQueued) pruneExpiredObservations(expiration time.Time) { } // TODO on promotion to priority queue, ack the trigger coordinator -func (s *observedAndQueued) addObservedEvents(f int, observedEvents map[string]*pb.ConsensusQueueObservedEvent) { - for blobHash, event := range observedEvents { - obs, ok := s.observedEvents[blobHash] - if !ok && len(event.NodeIds) >= 2*f+1 { +func (s *observedAndQueued) addObservedEvents(f int, toAdd map[string]*pb.ConsensusQueueObservedEvent) { + for blobHash, eventToAdd := range toAdd { + obsEvent, ok := s.observedEvents[blobHash] + if !ok && len(eventToAdd.NodeIds) >= 2*f+1 { // new proposal straight to priority queue - s.queuedEvents.push(&pb.ConsensusQueueEvent{ - WorkflowID: event.WorkflowID, - TriggerEventID: event.TriggerEventID, - ObservedAt: medianTimestamp(event.ObservedAts), - Deadline: medianTimestamp(event.Deadlines), - Blobs: event.Blobs, - }) + s.queuedEvents.pushObservations(blobHash, eventToAdd) } else if !ok { // new proposal < f + 1 - s.observedEvents[blobHash] = event + s.observedEvents[blobHash] = eventToAdd } else { // update proposal // TODO opt: build a map to avoid n^2? - for i, node := range event.NodeIds { - if !slices.Contains(obs.NodeIds, node) { - obs.NodeIds = append(obs.NodeIds, node) - obs.Deadlines = append(obs.Deadlines, event.Deadlines[i]) - obs.Blobs = append(obs.Blobs, event.Blobs[i]) + for i, node := range eventToAdd.NodeIds { + if !slices.Contains(obsEvent.NodeIds, node) { + obsEvent.NodeIds = append(obsEvent.NodeIds, node) + obsEvent.ObservedAts = append(obsEvent.ObservedAts, eventToAdd.ObservedAts[i]) + obsEvent.Deadlines = append(obsEvent.Deadlines, eventToAdd.Deadlines[i]) + obsEvent.Blobs = append(obsEvent.Blobs, eventToAdd.Blobs[i]) } //TODO what if a node reports twice with different deadline or nodeID? do we need to overwrite? } - if len(obs.NodeIds) >= 2*f+1 { + if len(obsEvent.NodeIds) >= 2*f+1 { // promote proposal to priority queue delete(s.observedEvents, blobHash) - s.queuedEvents.push(&pb.ConsensusQueueEvent{ - WorkflowID: event.WorkflowID, - TriggerEventID: event.TriggerEventID, - ObservedAt: medianTimestamp(event.ObservedAts), - Deadline: medianTimestamp(event.Deadlines), - Blobs: event.Blobs, - }) + s.queuedEvents.pushObservations(blobHash, obsEvent) } } } } - -func medianTimestamp(s []*timestamppb.Timestamp) *timestamppb.Timestamp { - var times []time.Time - for _, t := range s { - times = append(times, time.Unix(t.Seconds, int64(t.Nanos))) - } - slices.SortFunc(times, time.Time.Compare) - - a, b := times[len(times)/2], times[len(times)/2-1] - diff := a.Sub(b) - return timestamppb.New(a.Add(diff / 2)) -} diff --git a/core/services/ocr3_1/plugins/queue/math.go b/core/services/ocr3_1/plugins/queue/math.go new file mode 100644 index 00000000000..57962d67750 --- /dev/null +++ b/core/services/ocr3_1/plugins/queue/math.go @@ -0,0 +1,52 @@ +package queue + +import ( + "slices" + "time" + + "golang.org/x/exp/constraints" + "google.golang.org/protobuf/types/known/timestamppb" +) + +// median returns the median value of a slice of integers. +// len must be greater than 0. +func median[N constraints.Integer, S []N](s S) N { + switch len(s) { + case 0: + panic("median: len must be greater than 0") + case 1: + return s[0] + } + slices.Sort(s) + if len(s)%2 == 1 { + return s[len(s)/2] + } + // avg of two + a, b := s[len(s)/2], s[len(s)/2-1] + diff := a - b + return b + diff/2 +} + +// medianTimestamp returns the median value of a slice of timestamps. +// len must be greater than 0. +func medianTimestamp(s []*timestamppb.Timestamp) *timestamppb.Timestamp { + switch len(s) { + case 0: + panic("median: len must be greater than 0") + case 1: + return s[0] + } + times := make([]time.Time, len(s)) + for i, t := range s { + times[i] = time.Unix(t.Seconds, int64(t.Nanos)) + } + slices.SortFunc(times, time.Time.Compare) + + if len(times)%2 == 1 { + return timestamppb.New(times[len(times)/2]) + } + // avg of two + a, b := times[len(times)/2], times[len(times)/2-1] + diff := a.Sub(b) + return timestamppb.New(b.Add(diff / 2)) +} diff --git a/core/services/ocr3_1/plugins/queue/queue.go b/core/services/ocr3_1/plugins/queue/queue.go index d248cb9a1c2..bbb27901ad4 100644 --- a/core/services/ocr3_1/plugins/queue/queue.go +++ b/core/services/ocr3_1/plugins/queue/queue.go @@ -7,11 +7,10 @@ import ( "errors" "fmt" "math" - "slices" "sync" "time" - "golang.org/x/exp/constraints" + "github.com/smartcontractkit/libocr/commontypes" "golang.org/x/sync/errgroup" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/timestamppb" @@ -26,7 +25,6 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/services" "github.com/smartcontractkit/chainlink-common/pkg/settings/cresettings" "github.com/smartcontractkit/chainlink-common/pkg/settings/limits" - "github.com/smartcontractkit/chainlink/v2/core/services/workflows/v2/triggers" ) @@ -45,6 +43,7 @@ func NewConsensusQueuePluginFactory(lggr logger.Logger, cfg *PluginConfig, limit cfg: cfg, triggerCoordinator: triggerCoordinator, expirationDur: func(ctx context.Context) (time.Duration, error) { + //TODO also allow this grace period in the trigger coordinator return cresettings.Default.ConsensusQueueExpirationInterval.GetOrDefault(ctx, limitsFactory.Settings) }, }, nil @@ -71,19 +70,20 @@ type consensusQueuePlugin struct { expirationDur func(context.Context) (time.Duration, error) } -func newConsensusQueuePlugin(lggr logger.Logger, onchainCfg ocr3types.ReportingPluginConfig, triggerCoordinator triggers.Coordinator, expirationGraceDur func(context.Context) (time.Duration, error), blobs ocr3_1types.BlobBroadcastFetcher) *consensusQueuePlugin { +func newConsensusQueuePlugin( + lggr logger.Logger, onchainCfg ocr3types.ReportingPluginConfig, triggerCoordinator triggers.Coordinator, + expirationGraceDur func(context.Context) (time.Duration, error), blobs ocr3_1types.BlobBroadcastFetcher, +) *consensusQueuePlugin { c := &consensusQueuePlugin{ lggr: logger.Named(lggr, "ConsensusQueuePlugin"), onchainCfg: onchainCfg, triggerCoordinator: triggerCoordinator, - expirationDur: expirationGraceDur, blobs: blobs, + expirationDur: expirationGraceDur, } c.Service, c.eng = services.Config{ - Name: "ConsensusQueueReportingPlugin", - Close: c.Close, + Name: "ConsensusQueueReportingPlugin", }.NewServiceEngine(lggr) - return c } @@ -92,7 +92,8 @@ func (c *consensusQueuePlugin) Query(_ context.Context, _ uint64, _ ocr3_1types. } func (c *consensusQueuePlugin) Observation( - ctx context.Context, seqNr uint64, _ ocrtypes.AttributedQuery, kvState ocr3_1types.KeyValueStateReader, blobs ocr3_1types.BlobBroadcastFetcher, + ctx context.Context, seqNr uint64, _ ocrtypes.AttributedQuery, kvState ocr3_1types.KeyValueStateReader, + blobs ocr3_1types.BlobBroadcastFetcher, ) (ocrtypes.Observation, error) { // Always attempt to start any executions from the KV Store in the event Committed was not called. // tryStartExecutions is idempotent. @@ -127,23 +128,25 @@ func (c *consensusQueuePlugin) Observation( const roundDur = 10 * time.Second //TODO dynamic calibration? expSeqNr := seqNr + uint64(expirationGraceDur/roundDur) //TODO pad extra time and/or rounds - pbEvents := make([]*pb.CoordinatedEvent, 0, len(events)) - for _, e := range events { - pbEvents = append(pbEvents, e.ToProto()) + pbEvents := make([]*pb.CoordinatedEvent, len(events)) + for i, e := range events { + pbEvents[i] = e.ToProto() } blobHandle, err := broadcastAsBlob(ctx, blobs, pbEvents, expSeqNr) if err != nil { return nil, err } - const maxObservationSize = 0 //TODO + const maxObservationSize = 0 //TODO from where? protoOpts := proto.MarshalOptions{Deterministic: true} for i, m := range pbEvents { // Try adding to batch - protoBytes, err := protoOpts.Marshal(m) //TODO opt: don't marshal again, get hash from broadcast helper - if err != nil { - //TODO log + observedAt, deadline := m.ObservedAt, m.Deadline + m.ObservedAt, m.Deadline = nil, nil // for consistent hashing + protoBytes, err2 := protoOpts.Marshal(m) //TODO opt: don't marshal again, get hash from broadcast helper + if err2 != nil { + c.lggr.Errorw("failed to marshal event", "eventID", m.Event.Event.Id, "err", err2) continue } blobHash := sha256.Sum256(protoBytes) @@ -151,7 +154,8 @@ func (c *consensusQueuePlugin) Observation( obs.Events = append(obs.Events, &pb.ConsensusQueueEvent{ WorkflowID: m.WorkflowID, TriggerEventID: m.Event.Event.Id, - Deadline: m.Deadline, + ObservedAt: observedAt, + Deadline: deadline, BlobHash: blobHash[:], Blobs: []*pb.CoordinatedEventBlobHandle{{ Handle: blobHandle, @@ -179,7 +183,7 @@ func (c *consensusQueuePlugin) Observation( } func (c *consensusQueuePlugin) ValidateObservation( - ctx context.Context, seqNr uint64, _ ocrtypes.AttributedQuery, ao ocrtypes.AttributedObservation, + ctx context.Context, _ uint64, _ ocrtypes.AttributedQuery, ao ocrtypes.AttributedObservation, _ ocr3_1types.KeyValueStateReader, blobs ocr3_1types.BlobFetcher, ) error { var obs pb.ConsensusQueueObservation @@ -196,7 +200,7 @@ func (c *consensusQueuePlugin) ValidateObservation( return nil }) } - return nil + return eg.Wait() } func validateObservedEvent(ctx context.Context, blobs ocr3_1types.BlobFetcher, event *pb.ConsensusQueueEvent) error { @@ -251,30 +255,28 @@ func validateObservedEvent(ctx context.Context, blobs ocr3_1types.BlobFetcher, e } func (c *consensusQueuePlugin) ObservationQuorum( - ctx context.Context, seqNr uint64, _ ocrtypes.AttributedQuery, aos []ocrtypes.AttributedObservation, + _ context.Context, _ uint64, _ ocrtypes.AttributedQuery, aos []ocrtypes.AttributedObservation, _ ocr3_1types.KeyValueStateReader, _ ocr3_1types.BlobFetcher, ) (quorumReached bool, err error) { return quorumhelper.ObservationCountReachesObservationQuorum(quorumhelper.QuorumTwoFPlusOne, c.onchainCfg.N, c.onchainCfg.F, aos), nil } func (c *consensusQueuePlugin) StateTransition( - ctx context.Context, seqNr uint64, aq ocrtypes.AttributedQuery, aos []ocrtypes.AttributedObservation, - kvState ocr3_1types.KeyValueStateReadWriter, fetcher ocr3_1types.BlobFetcher, + ctx context.Context, _ uint64, _ ocrtypes.AttributedQuery, aos []ocrtypes.AttributedObservation, + kvState ocr3_1types.KeyValueStateReadWriter, _ ocr3_1types.BlobFetcher, ) (ocr3_1types.ReportsPlusPrecursor, error) { var done chan struct{} var obs observations go func() { defer close(done) - if warn := obs.aggregate(ctx, aos); warn != nil { - c.lggr.Warnw("Failed to aggregate some observations", "err", warn) - } + obs.aggregate(ctx, aos) }() stateRW := newStateReadWriter(kvState) state, err := stateRW.readObservedAndQueued() if err != nil { - return nil, err + return nil, fmt.Errorf("failed to read state: %w", err) } // wait for aggregation @@ -286,6 +288,12 @@ func (c *consensusQueuePlugin) StateTransition( return nil, err } } + if obs.err != nil { + return nil, fmt.Errorf("failed to aggregate observations: %w", obs.err) + } + if obs.warn != nil { + c.lggr.Warnw("Failed to aggregate some observations", "err", obs.warn) + } // update state state.pruneExpiredObservations(obs.medianExpiration) @@ -294,11 +302,9 @@ func (c *consensusQueuePlugin) StateTransition( if err != nil { return nil, err } - - // Updated KV Store //TODO might we hit a KV size limit in the middle of these? then what? can't just drop proposals // alternative: proposals only valid when there is definitely enough space - err = stateRW.update(state, consensusEvents) + err = stateRW.writeAll(state, consensusEvents) if err != nil { return nil, err } @@ -312,10 +318,12 @@ type observations struct { medianCap uint32 medianCapPerWF map[string]uint32 // wf ID -> capacity newObservedEvents map[string]*pb.ConsensusQueueObservedEvent // key: blobHash + warn error + err error } // TODO consider some configurable x% of capacity since some honest nodes have less -func (res *observations) aggregate(ctx context.Context, aos []ocrtypes.AttributedObservation) (warn error) { +func (res *observations) aggregate(ctx context.Context, aos []ocrtypes.AttributedObservation) { res.medianCapPerWF = make(map[string]uint32) res.newObservedEvents = make(map[string]*pb.ConsensusQueueObservedEvent) @@ -326,7 +334,7 @@ func (res *observations) aggregate(ctx context.Context, aos []ocrtypes.Attribute var obs pb.ConsensusQueueObservation err := proto.Unmarshal(ao.Observation, &obs) if err != nil { - warn = errors.Join(warn, fmt.Errorf("failed to unmarshal observation from oracle %d: %w", ao.Observation, err)) + res.warn = errors.Join(res.warn, fmt.Errorf("failed to unmarshal observation from oracle %d: %w", ao.Observation, err)) continue } expirations = append(expirations, obs.Expiration) @@ -338,44 +346,48 @@ func (res *observations) aggregate(ctx context.Context, aos []ocrtypes.Attribute if ctx.Err() != nil { return } - aggregated, ok := res.newObservedEvents[string(event.BlobHash)] - if !ok { - aggregated = &pb.ConsensusQueueObservedEvent{ - TriggerEventID: event.TriggerEventID, - WorkflowID: event.WorkflowID, - NodeIds: []uint8{uint8(ao.Observer)}, - ObservedAts: []*timestamppb.Timestamp{event.ObservedAt}, - Deadlines: []*timestamppb.Timestamp{event.Deadline}, - Blobs: []*pb.CoordinatedEventBlobHandle{event.Blobs[0]}, - } - } else { - // note: trigger event and workflow ID alignment is ensured by ValidateObservation - aggregated.NodeIds = append(aggregated.NodeIds, uint8(ao.Observer)) - aggregated.ObservedAts = append(aggregated.ObservedAts, event.ObservedAt) - aggregated.Deadlines = append(aggregated.Deadlines, event.Deadline) - aggregated.Blobs = append(aggregated.Blobs, event.Blobs...) - } - - res.newObservedEvents[string(event.BlobHash)] = aggregated + res.addEvent(ao.Observer, event) } } res.medianExpiration = medianTimestamp(expirations).AsTime() res.medianCap = median(capacities) - for wf, c := range wfCapacities { - res.medianCapPerWF[wf] = median(c) + for wf, caps := range wfCapacities { + res.medianCapPerWF[wf] = median(caps) } return } -func (c *consensusQueuePlugin) Committed(ctx context.Context, seqNr uint64, keyValueStateReader ocr3_1types.KeyValueStateReader) error { - c.tryStartExecutions(keyValueStateReader) +func (res *observations) addEvent(obs commontypes.OracleID, event *pb.ConsensusQueueEvent) { + aggregated, ok := res.newObservedEvents[string(event.BlobHash)] + if !ok { + aggregated = &pb.ConsensusQueueObservedEvent{ + TriggerEventID: event.TriggerEventID, + WorkflowID: event.WorkflowID, + NodeIds: []uint8{uint8(obs)}, + ObservedAts: []*timestamppb.Timestamp{event.ObservedAt}, + Deadlines: []*timestamppb.Timestamp{event.Deadline}, + Blobs: []*pb.CoordinatedEventBlobHandle{event.Blobs[0]}, + } + } else { + // note: trigger event and workflow ID alignment is ensured by ValidateObservation + aggregated.NodeIds = append(aggregated.NodeIds, uint8(obs)) + aggregated.ObservedAts = append(aggregated.ObservedAts, event.ObservedAt) + aggregated.Deadlines = append(aggregated.Deadlines, event.Deadline) + aggregated.Blobs = append(aggregated.Blobs, event.Blobs...) + } + + res.newObservedEvents[string(event.BlobHash)] = aggregated +} + +func (c *consensusQueuePlugin) Committed(ctx context.Context, _ uint64, kvState ocr3_1types.KeyValueStateReader) error { + c.tryStartExecutions(kvState) return nil } // tryStartExecutions calls StartExecution asynchronously on the corresponding engine for each trigger event. // It is idempotent, thus safe to call from Observation and Committed. -func (c *consensusQueuePlugin) tryStartExecutions(reader ocr3_1types.KeyValueStateReader) { - v, err := reader.Read([]byte(consensusEventsKey)) +func (c *consensusQueuePlugin) tryStartExecutions(kvState ocr3_1types.KeyValueStateReader) { + v, err := kvState.Read([]byte(consensusEventsKey)) if err != nil { c.lggr.Errorw("Failed to read consensus events", "err", err) return @@ -435,19 +447,14 @@ func (c *consensusQueuePlugin) tryStartExecution(ctx context.Context, consensusE return nil } -func (c *consensusQueuePlugin) Reports(ctx context.Context, seqNr uint64, reportsPlusPrecursor ocr3_1types.ReportsPlusPrecursor) ([]ocr3types.ReportPlus[[]byte], error) { +func (c *consensusQueuePlugin) Reports(ctx context.Context, _ uint64, _ ocr3_1types.ReportsPlusPrecursor) ([]ocr3types.ReportPlus[[]byte], error) { return nil, nil } -func (c *consensusQueuePlugin) ShouldAcceptAttestedReport(ctx context.Context, seqNr uint64, reportWithInfo ocr3types.ReportWithInfo[[]byte]) (bool, error) { +func (c *consensusQueuePlugin) ShouldAcceptAttestedReport(ctx context.Context, _ uint64, _ ocr3types.ReportWithInfo[[]byte]) (bool, error) { return false, nil } -func (c *consensusQueuePlugin) ShouldTransmitAcceptedReport(ctx context.Context, seqNr uint64, reportWithInfo ocr3types.ReportWithInfo[[]byte]) (bool, error) { +func (c *consensusQueuePlugin) ShouldTransmitAcceptedReport(ctx context.Context, _ uint64, _ ocr3types.ReportWithInfo[[]byte]) (bool, error) { return false, nil } - -func median[N constraints.Integer, S []N](s S) N { - slices.Sort(s) - return (s[len(s)/2-1] + s[len(s)/2]) / 2 -} diff --git a/core/services/ocr3_1/plugins/queue/queue_test.go b/core/services/ocr3_1/plugins/queue/queue_test.go new file mode 100644 index 00000000000..c969bad24a4 --- /dev/null +++ b/core/services/ocr3_1/plugins/queue/queue_test.go @@ -0,0 +1 @@ +package queue diff --git a/core/services/ocr3_1/plugins/queue/transmitter.go b/core/services/ocr3_1/plugins/queue/transmitter.go index 42c3ddeae95..4c43d022f08 100644 --- a/core/services/ocr3_1/plugins/queue/transmitter.go +++ b/core/services/ocr3_1/plugins/queue/transmitter.go @@ -2,58 +2,23 @@ package queue import ( "context" - "fmt" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" - "google.golang.org/protobuf/proto" - - "github.com/smartcontractkit/chainlink-common/pkg/capabilities/pb" - "github.com/smartcontractkit/chainlink-common/pkg/logger" - "github.com/smartcontractkit/chainlink/v2/core/services/workflows/v2/triggers" ) -type contractTransmitter struct { - lggr logger.Logger +type noopTransmitter struct { fromAccount ocrtypes.Account - eventSink triggers.EventSink } -func NewTransmitter(lggr logger.Logger, fromAccount ocrtypes.Account, eventSink triggers.EventSink) ocr3types.ContractTransmitter[[]byte] { - return &contractTransmitter{ - lggr: lggr, - fromAccount: fromAccount, - eventSink: eventSink, - } +func NewTransmitter(fromAccount ocrtypes.Account) ocr3types.ContractTransmitter[[]byte] { + return &noopTransmitter{fromAccount: fromAccount} } -func (c *contractTransmitter) Transmit(ctx context.Context, digest ocrtypes.ConfigDigest, seqNum uint64, rpi ocr3types.ReportWithInfo[[]byte], signatures []ocrtypes.AttributedOnchainSignature) error { - //TODO relocate & replace with no-op? - var report pb.CoordinatedEventList - err := proto.Unmarshal(rpi.Report, &report) - if err != nil { - return fmt.Errorf("failed to unmarshal report: %w", err) - } - // Execute each event - for _, message := range report.Events { - var event triggers.CoordinatedEvent - if err := event.FromProto(message); err != nil { - c.lggr.Errorw("Failed to convert trigger event proto", "err", err) - continue - } - if c.eventSink == nil { - c.lggr.Warnw("Unable to execute trigger - no event sink configured", "event", event) - continue - } - err := c.eventSink.ExecuteTrigger(ctx, event) - if err != nil { - c.lggr.Errorw("Failed to execute trigger", "event", event, "err", err) - } - } - +func (c *noopTransmitter) Transmit(ctx context.Context, digest ocrtypes.ConfigDigest, seqNum uint64, rpi ocr3types.ReportWithInfo[[]byte], signatures []ocrtypes.AttributedOnchainSignature) error { return nil } -func (c *contractTransmitter) FromAccount(ctx context.Context) (ocrtypes.Account, error) { +func (c *noopTransmitter) FromAccount(ctx context.Context) (ocrtypes.Account, error) { return c.fromAccount, nil } From 90768bd230e30e11f2395d9dc855922e011435ba Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Mon, 16 Nov 2026 20:40:10 -0600 Subject: [PATCH 08/13] dedupe blobs --- core/scripts/go.mod | 2 +- core/scripts/go.sum | 4 +- core/services/ocr3_1/plugins/queue/blobs.go | 71 +++- .../ocr3_1/plugins/queue/blobs_test.go | 7 + core/services/ocr3_1/plugins/queue/config.go | 11 + core/services/ocr3_1/plugins/queue/kvstate.go | 336 +++++++++++++----- core/services/ocr3_1/plugins/queue/queue.go | 234 +++++++----- deployment/go.mod | 2 +- deployment/go.sum | 4 +- go.mod | 2 +- go.sum | 4 +- integration-tests/go.mod | 2 +- integration-tests/go.sum | 4 +- integration-tests/load/go.mod | 2 +- integration-tests/load/go.sum | 4 +- system-tests/lib/go.mod | 2 +- system-tests/lib/go.sum | 4 +- system-tests/tests/go.mod | 2 +- system-tests/tests/go.sum | 4 +- 19 files changed, 487 insertions(+), 214 deletions(-) diff --git a/core/scripts/go.mod b/core/scripts/go.mod index 53e0b3320f5..27d8a774e65 100644 --- a/core/scripts/go.mod +++ b/core/scripts/go.mod @@ -29,7 +29,7 @@ require ( github.com/shopspring/decimal v1.4.0 github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261022195454-600e2b321c7a diff --git a/core/scripts/go.sum b/core/scripts/go.sum index d5cf426b16e..8bce6ac7ebb 100644 --- a/core/scripts/go.sum +++ b/core/scripts/go.sum @@ -1686,8 +1686,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 h1:nzm+zgN1C6kNVlQnlp3XlzqFl7g9K5h63mRyctvGNRE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012 h1:7GCOxs3dYlwdm1lW+SI8hPXH0BC/uyUHkX9l8twglcM= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/core/services/ocr3_1/plugins/queue/blobs.go b/core/services/ocr3_1/plugins/queue/blobs.go index df2ef7aa753..b3516ab8832 100644 --- a/core/services/ocr3_1/plugins/queue/blobs.go +++ b/core/services/ocr3_1/plugins/queue/blobs.go @@ -3,21 +3,51 @@ package queue import ( "context" "fmt" + "sync" - "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3_1types" "google.golang.org/protobuf/encoding/protowire" "google.golang.org/protobuf/proto" + "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3_1types" + "github.com/smartcontractkit/chainlink-common/pkg/capabilities/pb" ) -func fetchFromBlob(ctx context.Context, fetcher ocr3_1types.BlobFetcher, handle []byte, idx int) (*pb.CoordinatedEvent, []byte, error) { - var blobHandle ocr3_1types.BlobHandle - if err := blobHandle.UnmarshalBinary(handle); err != nil { - return nil, nil, fmt.Errorf("failed to unmarshal blob handle: %w", err) +// blobCache is a short-lived cache for coordinating concurrent fetches of event blobs. +type blobCache struct { + fetcher ocr3_1types.BlobFetcher + + mu sync.RWMutex + cache map[string]func() ([]byte, error) // blob handle -> blob +} + +func (c *blobCache) fetchBlob(ctx context.Context, handle []byte) ([]byte, error) { + c.mu.RLock() + if fn, ok := c.cache[string(handle)]; ok { + c.mu.RUnlock() + return fn() } - //TODO cache to fetch just once - b, err := fetcher.FetchBlob(ctx, blobHandle) + c.mu.RUnlock() + + c.mu.Lock() + if fn, ok := c.cache[string(handle)]; ok { + c.mu.Unlock() + return fn() + } + fn := sync.OnceValues(func() ([]byte, error) { + var blobHandle ocr3_1types.BlobHandle + if err := blobHandle.UnmarshalBinary(handle); err != nil { + return nil, fmt.Errorf("failed to unmarshal blob handle: %w", err) + } + return c.fetcher.FetchBlob(ctx, blobHandle) + }) + c.cache[string(handle)] = fn + return fn() +} + +// fetchCoordinatedEventFromBlob fetches and extracts the idx-th event from the blob, without unmarshaling any other events. +func fetchCoordinatedEventFromBlob(ctx context.Context, fetcher *blobCache, handle []byte, idx int) (*pb.CoordinatedEvent, []byte, error) { + b, err := fetcher.fetchBlob(ctx, handle) if err != nil { return nil, nil, fmt.Errorf("failed to fetch blob: %w", err) } @@ -29,10 +59,10 @@ func fetchFromBlob(ctx context.Context, fetcher ocr3_1types.BlobFetcher, handle return coordEvent, b, nil } +const coordinatedEventsFieldNumber = 1 // pb.CoordinatedEventList.Events + // extractEvent extracts the idx-th event from the blob, without unmarshaling any other events. func extractEvent(b []byte, idx int) (*pb.CoordinatedEvent, error) { - //TODO can we lock this in with code? - const fieldNumber = 1 // pb.CoordinatedEventList.Events i := 0 for len(b) > 0 { num, typ, n := protowire.ConsumeTag(b) @@ -40,9 +70,9 @@ func extractEvent(b []byte, idx int) (*pb.CoordinatedEvent, error) { return nil, protowire.ParseError(n) } b = b[n:] - if num == fieldNumber { + if num == coordinatedEventsFieldNumber { if typ != protowire.BytesType { - return nil, fmt.Errorf("expected bytes type for field %d, got %d", fieldNumber, typ) + return nil, fmt.Errorf("expected bytes type for field %d, got %d", coordinatedEventsFieldNumber, typ) } v, m := protowire.ConsumeBytes(b) if m < 0 { @@ -65,15 +95,20 @@ func extractEvent(b []byte, idx int) (*pb.CoordinatedEvent, error) { } // broadcastAsBlob broadcasts a list of coordinated events and returns a blob handle. -func broadcastAsBlob(ctx context.Context, broadcaster ocr3_1types.BlobBroadcastFetcher, events []*pb.CoordinatedEvent, expSeq uint64) ([]byte, error) { - // TODO return a slice of hashes too; encode list with protowire to hash them along the way - w/ ZERO timestamps - data, err := proto.MarshalOptions{Deterministic: true}.Marshal(&pb.CoordinatedEventList{Events: events}) +func broadcastAsBlob(ctx context.Context, broadcaster ocr3_1types.BlobBroadcastFetcher, events []*pb.CoordinatedEvent, expSeq uint64) (blobHandle []byte, n int, err error) { + protoOpts := proto.MarshalOptions{Deterministic: true} + for ; protoOpts.Size(&pb.CoordinatedEventList{Events: events}) > maxBlobPayloadBytes; events = events[:len(events)-1] { + //TODO opt: binary search for largest fit instead.... + } + n = len(events) + data, err := protoOpts.Marshal(&pb.CoordinatedEventList{Events: events}) if err != nil { - return nil, fmt.Errorf("failed to marshal blob: %w", err) + return nil, -1, fmt.Errorf("failed to marshal blob: %w", err) } - blobHandle, err := broadcaster.BroadcastBlob(ctx, data, ocr3_1types.BlobExpirationHintSequenceNumber{SeqNr: expSeq}) + bh, err := broadcaster.BroadcastBlob(ctx, data, ocr3_1types.BlobExpirationHintSequenceNumber{SeqNr: expSeq}) if err != nil { - return nil, fmt.Errorf("failed to broadcast blob: %w", err) + return nil, -1, fmt.Errorf("failed to broadcast blob: %w", err) } - return blobHandle.MarshalBinary() + blobHandle, err = bh.MarshalBinary() + return } diff --git a/core/services/ocr3_1/plugins/queue/blobs_test.go b/core/services/ocr3_1/plugins/queue/blobs_test.go index 35e5b81028b..8a9041e5cf4 100644 --- a/core/services/ocr3_1/plugins/queue/blobs_test.go +++ b/core/services/ocr3_1/plugins/queue/blobs_test.go @@ -5,6 +5,7 @@ import ( "time" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/encoding/protowire" "google.golang.org/protobuf/proto" "google.golang.org/protobuf/types/known/anypb" "google.golang.org/protobuf/types/known/timestamppb" @@ -78,3 +79,9 @@ func Test_extractEvent(t *testing.T) { }) } } + +func Test_coordinatedEventsFieldNumber(t *testing.T) { + fd := (&pb.CoordinatedEventList{}).ProtoReflect().Descriptor().Fields().ByName("events") + require.NotNil(t, fd) + require.Equal(t, protowire.Number(coordinatedEventsFieldNumber), fd.Number()) +} diff --git a/core/services/ocr3_1/plugins/queue/config.go b/core/services/ocr3_1/plugins/queue/config.go index b63436ca646..66486a55afa 100644 --- a/core/services/ocr3_1/plugins/queue/config.go +++ b/core/services/ocr3_1/plugins/queue/config.go @@ -4,6 +4,17 @@ import ( "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3_1types" ) +const ( + maxObservedBlobHandles = 10 // sanity check on blobs in an observation + maxObservedEvents = 1000 // sanity check events in an observation + + //TODO reduce these? connect to cre settings? + maxObservationBytes = ocr3_1types.MaxMaxObservationBytes + maxKeyValueValueBytes = ocr3_1types.MaxMaxKeyValueKeyBytes + maxKeyValueModifiedKeysPlusValuesBytes = ocr3_1types.MaxMaxKeyValueModifiedKeysPlusValuesBytes + maxBlobPayloadBytes = ocr3_1types.MaxMaxBlobPayloadBytes +) + type PluginConfig struct { Limits ocr3_1types.ReportingPluginLimits `json:"limits,omitzero"` } diff --git a/core/services/ocr3_1/plugins/queue/kvstate.go b/core/services/ocr3_1/plugins/queue/kvstate.go index d999b8edd26..1866b6d0472 100644 --- a/core/services/ocr3_1/plugins/queue/kvstate.go +++ b/core/services/ocr3_1/plugins/queue/kvstate.go @@ -19,27 +19,24 @@ import ( // KV store keys const ( // observed events waiting for consensus (<2f+1 observers) - observedEventsKey = "observed_events::index" // pb.ConsensusQueueObservedEvents { map[string]*pb.ConsensusQueueObservedEvent } + observedEventsKey = "observed_events::index" // pb.ConsensusQueueObservedEvents { map[string]*pb.ConsensusQueueObservedEvent; [][]byte } // priority queue of events waiting for capacity - priorityQueueKey = "priority_queue::index" // pb.ConsensusQueueEventList { []*pb.ConsensusQueueEvent } + queuedEventsKey = "queued_events::index" // pb.ConsensusQueueEventList { []*pb.ConsensusQueueEvent } // events the plugin committed to sending to nodes consensusEventsKey = "consensus_events::index" // pb.ConsensusQueueEventList { []*pb.ConsensusQueueEvent } + // blob handles referenced from events in the PQ and consensus set + blobHandlesKey = "blob_handles::index" // pb.ConsensusQueueBlobHandleList{ [][]byte } ) type stateReader struct { kv ocr3_1types.KeyValueStateReader } -type stateReadWriter struct { - stateReader +type stateWriter struct { kv ocr3_1types.KeyValueStateReadWriter } -func newStateReadWriter(kv ocr3_1types.KeyValueStateReadWriter) stateReadWriter { - return stateReadWriter{stateReader: stateReader{kv: kv}, kv: kv} -} - -func (s stateReadWriter) writeValue[M proto.Message](key string, m M) error { +func (s *stateWriter) writeValue[M proto.Message](key string, m M) error { val, err := proto.MarshalOptions{Deterministic: true}.Marshal(m) if err != nil { return fmt.Errorf("failed to marshal %T: %w", m, err) @@ -47,54 +44,6 @@ func (s stateReadWriter) writeValue[M proto.Message](key string, m M) error { return s.kv.Write([]byte(key), val) } -// readObservedAndQueued reads both observed events and priority queue events from the KV store. -func (s stateReader) readObservedAndQueued() (*observedAndQueued, error) { - var obsQ observedAndQueued - v, err := s.kv.Read([]byte(observedEventsKey)) - if err != nil { - return nil, fmt.Errorf("failed to read observed events: %w", err) - } - if v != nil { - var observed *pb.ConsensusQueueObservedEvents - if err = proto.Unmarshal(v, observed); err != nil { - return nil, err - } - obsQ.observedEvents = observed.GetObservations() - } else { - obsQ.observedEvents = make(map[string]*pb.ConsensusQueueObservedEvent) - } - - v, err = s.kv.Read([]byte(priorityQueueKey)) - if err != nil { - return nil, fmt.Errorf("failed to read queued events: %w", err) - } - if v != nil { - var queued *pb.ConsensusQueueEventList - if err = proto.Unmarshal(v, queued); err != nil { - return nil, err - } - obsQ.queuedEvents = new(priorityQueue(queued.GetEvents())) - } - - return &obsQ, nil -} - -func (s stateReadWriter) writeAll(state *observedAndQueued, consensus []*pb.ConsensusQueueEvent) error { - err := s.writeValue(observedEventsKey, &pb.ConsensusQueueObservedEvents{Observations: state.observedEvents}) - if err != nil { - return fmt.Errorf("failed to write observed events: %w", err) - } - err = s.writeValue(priorityQueueKey, &pb.ConsensusQueueEventList{Events: *state.queuedEvents}) - if err != nil { - return fmt.Errorf("failed to write queued events: %w", err) - } - err = s.writeValue(consensusEventsKey, &pb.ConsensusQueueEventList{Events: consensus}) - if err != nil { - return fmt.Errorf("failed to write consensus events: %w", err) - } - return nil -} - var _ heap.Interface = (*priorityQueue)(nil) // priorityQueue is a heap of coordinated events, ordered by deadline and then event ID. @@ -104,10 +53,13 @@ func (p *priorityQueue) Len() int { return len(*p) } func (p *priorityQueue) Less(i, j int) bool { a, b := (*p)[i], (*p)[j] + return cmpConsensusQueueEvents(a, b) < 0 +} +func cmpConsensusQueueEvents(a, b *pb.ConsensusQueueEvent) int { return cmp.Or(cmp.Compare(a.Deadline.Seconds, b.Deadline.Seconds), cmp.Compare(a.Deadline.Nanos, b.Deadline.Nanos), - cmp.Compare(a.TriggerEventID, b.TriggerEventID)) < 0 + cmp.Compare(a.TriggerEventID, b.TriggerEventID)) } func (p *priorityQueue) Swap(i, j int) { @@ -124,15 +76,17 @@ func (p *priorityQueue) Pop() any { func (p *priorityQueue) push(x *pb.ConsensusQueueEvent) { heap.Push(p, x) } -func (p *priorityQueue) pushObservations(blobHash string, event *pb.ConsensusQueueObservedEvent) { - p.push(&pb.ConsensusQueueEvent{ - WorkflowID: event.WorkflowID, - TriggerEventID: event.TriggerEventID, - ObservedAt: medianTimestamp(event.ObservedAts), - Deadline: medianTimestamp(event.Deadlines), - BlobHash: []byte(blobHash), - Blobs: event.Blobs, - }) +func (p *priorityQueue) pushObservations(timelessHash string, obs *pb.ConsensusQueueObservedEvent) *pb.ConsensusQueueEvent { + event := &pb.ConsensusQueueEvent{ + WorkflowID: obs.WorkflowID, + TriggerEventID: obs.TriggerEventID, + ObservedAt: medianTimestamp(obs.ObservedAts), + Deadline: medianTimestamp(obs.Deadlines), + TimelessHash: []byte(timelessHash), + Blobs: obs.Blobs, + } + p.push(event) + return event } // mustPop pops the next event from the queue, or returns nil if the queue is empty. @@ -146,7 +100,7 @@ func (p *priorityQueue) mustPop() *pb.ConsensusQueueEvent { // popLimited pops up to capacity events from the queue, each of which must also have sufficient wf capacity. // Note: capPerWF is mutated. -func (p *priorityQueue) popLimited(capacity uint32, capPerWF map[string]uint32, expiration time.Time) ([]*pb.ConsensusQueueEvent, error) { +func (p *priorityQueue) popLimited(capacity uint32, capPerWF map[string]uint32, expiration time.Time) []*pb.ConsensusQueueEvent { var events []*pb.ConsensusQueueEvent var wfLimited []*pb.ConsensusQueueEvent // omitted due to workflow limit for len(events) < int(capacity) { @@ -169,15 +123,185 @@ func (p *priorityQueue) popLimited(capacity uint32, capPerWF map[string]uint32, for _, event := range wfLimited { p.push(event) } - return events, nil + return events +} + +type blobHandleMap map[string]map[string]uint32 // eventHash -> blobHandle -> idx + +func (m blobHandleMap) add(eventHash string, blobHandle string, element uint32) { + if _, ok := m[eventHash]; !ok { + m[eventHash] = make(map[string]uint32) + } + m[eventHash][blobHandle] = element } -type observedAndQueued struct { - observedEvents map[string]*pb.ConsensusQueueObservedEvent // key: blobHash - queuedEvents *priorityQueue +func (m blobHandleMap) addAll(eventHash string, blobHandles map[string]uint32) { + if _, ok := m[eventHash]; !ok { + m[eventHash] = make(map[string]uint32) + } + for blobHandle, elementIndex := range blobHandles { + m[eventHash][blobHandle] = elementIndex + } +} + +type kvState struct { + // observedEventsKey + observedEvents map[string]*pb.ConsensusQueueObservedEvent // key: timeless hash + observedBlobs blobHandleMap + observedBlobHandles [][]byte // only populated before write + + // priorityQueueKey + queuedEvents *priorityQueue + // consensusEventsKey + consensusEvents []*pb.ConsensusQueueEvent + // blobHandlesKey + queuedBlobs blobHandleMap + queuedBlobHandles [][]byte // only populated before write } -func (s *observedAndQueued) pruneExpiredObservations(expiration time.Time) { +// loadFrom loads the kvState from the KV store, excluding consensus events, which are not required to transition. +func (s *kvState) loadFrom(kv ocr3_1types.KeyValueStateReadWriter) error { + v, err := kv.Read([]byte(observedEventsKey)) + if err != nil { + return fmt.Errorf("failed to read observed events: %w", err) + } + s.observedBlobs = make(blobHandleMap) + if v != nil { + var observed *pb.ConsensusQueueObservedEvents + if err = proto.Unmarshal(v, observed); err != nil { + return fmt.Errorf("failed to unmarshal observed events: %w", err) + } + s.observedEvents = observed.GetObservations() + blobHandles := observed.GetBlobHandles() + for eventHash, event := range s.observedEvents { + for _, b := range event.GetBlobs() { + s.observedBlobs.add(eventHash, string(blobHandles[b.Blob]), b.Element) + } + } + } else { + s.observedEvents = make(map[string]*pb.ConsensusQueueObservedEvent) + } + + v, err = kv.Read([]byte(queuedEventsKey)) + if err != nil { + return fmt.Errorf("failed to read queued events: %w", err) + } + if v != nil { + var queued *pb.ConsensusQueueEventList + if err = proto.Unmarshal(v, queued); err != nil { + return fmt.Errorf("failed to unmarshal queued events: %w", err) + } + s.queuedEvents = new(priorityQueue(queued.GetEvents())) + } + + s.queuedBlobs = make(blobHandleMap) + queuedBlobs, err := readBlobHandles(kv) + if err != nil { + return err + } + for _, event := range []*pb.ConsensusQueueEvent(*s.queuedEvents) { + for _, blob := range event.GetBlobs() { + s.queuedBlobs.add(string(event.TimelessHash), string(queuedBlobs[blob.Blob]), blob.Element) + } + } + + return nil +} + +// sizeOf returns the size of the state when serialized and written to the KV store via writeAll. +func (s *kvState) sizeOf() (size int) { + s.prepareWrite() + + //TODO check maxKeyValueValueBytes too? + + protoOpts := proto.MarshalOptions{Deterministic: true} + size += len(observedEventsKey) + len(queuedEventsKey) + len(consensusEventsKey) + len(blobHandlesKey) + size += protoOpts.Size(&pb.ConsensusQueueObservedEvents{Observations: s.observedEvents, BlobHandles: s.observedBlobHandles}) + size += protoOpts.Size(&pb.ConsensusQueueEventList{Events: *s.queuedEvents}) + size += protoOpts.Size(&pb.ConsensusQueueEventList{Events: s.consensusEvents}) + size += protoOpts.Size(&pb.ConsensusQueueBlobHandleList{BlobHandles: s.queuedBlobHandles}) + + return +} + +// prepareWrite initializes observed and queued blob handles and updates the event references. +func (s *kvState) prepareWrite() { + // gather blob handles and update events + s.observedBlobHandles = nil + observedBlobIndexes := make(map[string]int) + for _, eventHash := range slices.Sorted(maps.Keys(s.observedEvents)) { + event := s.observedEvents[eventHash] + event.Blobs = nil // replace all + for blobHandle, ei := range s.observedBlobs[eventHash] { + idx, ok := observedBlobIndexes[blobHandle] + if !ok { + idx = len(s.observedBlobHandles) + observedBlobIndexes[blobHandle] = idx + s.observedBlobHandles = append(s.observedBlobHandles, []byte(blobHandle)) + } + event.Blobs = append(event.Blobs, &pb.CoordinatedEventBlobHandle{ + Blob: uint32(idx), + Element: ei, + }) + } + } + + // gather blob handles and update events + s.queuedBlobHandles = nil + queuedBlobIndexes := make(map[string]int) + addBlobs := func(blobs map[string]uint32) []*pb.CoordinatedEventBlobHandle { + var blobHandles []*pb.CoordinatedEventBlobHandle + for blobHandle, ei := range blobs { + idx, ok := queuedBlobIndexes[blobHandle] + if !ok { + idx = len(s.queuedBlobHandles) + queuedBlobIndexes[blobHandle] = idx + s.queuedBlobHandles = append(s.queuedBlobHandles, []byte(blobHandle)) + } + blobHandles = append(blobHandles, &pb.CoordinatedEventBlobHandle{ + Blob: uint32(idx), + Element: ei, + }) + } + return blobHandles + } + for _, event := range []*pb.ConsensusQueueEvent(*s.queuedEvents) { + event.Blobs = addBlobs(s.queuedBlobs[string(event.TimelessHash)]) + } + for _, event := range s.consensusEvents { + event.Blobs = addBlobs(s.queuedBlobs[string(event.TimelessHash)]) + } +} + +// writeAll writes full state to the KV store, including consensus events. +// prepareWrite must be called to include blob handles. +func (s *kvState) writeTo(w *stateWriter) error { + //TODO MarshalOptions{UseCachedSize}? + + err := w.writeValue(observedEventsKey, &pb.ConsensusQueueObservedEvents{Observations: s.observedEvents, BlobHandles: s.observedBlobHandles}) + if err != nil { + return fmt.Errorf("failed to write observed events: %w", err) + } + + err = w.writeValue(queuedEventsKey, &pb.ConsensusQueueEventList{Events: *s.queuedEvents}) + if err != nil { + return fmt.Errorf("failed to write queued events: %w", err) + } + + err = w.writeValue(consensusEventsKey, &pb.ConsensusQueueEventList{Events: s.consensusEvents}) + if err != nil { + return fmt.Errorf("failed to write consensus events: %w", err) + } + + err = w.writeValue(blobHandlesKey, &pb.ConsensusQueueBlobHandleList{BlobHandles: s.queuedBlobHandles}) + if err != nil { + return fmt.Errorf("failed to write blob handles: %w", err) + } + + return nil +} + +func (s *kvState) pruneExpiredObservations(expiration time.Time) { unexpiredFn := func(t *timestamppb.Timestamp) bool { return t.AsTime().After(expiration) } maps.DeleteFunc(s.observedEvents, func(k string, v *pb.ConsensusQueueObservedEvent) bool { if !slices.ContainsFunc(v.Deadlines, unexpiredFn) { @@ -202,16 +326,19 @@ func (s *observedAndQueued) pruneExpiredObservations(expiration time.Time) { }) } -// TODO on promotion to priority queue, ack the trigger coordinator -func (s *observedAndQueued) addObservedEvents(f int, toAdd map[string]*pb.ConsensusQueueObservedEvent) { - for blobHash, eventToAdd := range toAdd { - obsEvent, ok := s.observedEvents[blobHash] +// addObserved adds the observed events to the set, promoting to the priority queue on 2f+1 and calling onQueued. +func (s *kvState) addObservedEvents(f int, toAdd map[string]*pb.ConsensusQueueObservedEvent, observedBlobs blobHandleMap, onQueued func(event *pb.ConsensusQueueEvent)) { + for eventHash, eventToAdd := range toAdd { + obsEvent, ok := s.observedEvents[eventHash] if !ok && len(eventToAdd.NodeIds) >= 2*f+1 { // new proposal straight to priority queue - s.queuedEvents.pushObservations(blobHash, eventToAdd) + s.queuedBlobs.addAll(eventHash, observedBlobs[eventHash]) + event := s.queuedEvents.pushObservations(eventHash, eventToAdd) + onQueued(event) } else if !ok { // new proposal < f + 1 - s.observedEvents[blobHash] = eventToAdd + s.observedBlobs.addAll(eventHash, observedBlobs[eventHash]) + s.observedEvents[eventHash] = eventToAdd } else { // update proposal // TODO opt: build a map to avoid n^2? @@ -221,13 +348,58 @@ func (s *observedAndQueued) addObservedEvents(f int, toAdd map[string]*pb.Consen obsEvent.ObservedAts = append(obsEvent.ObservedAts, eventToAdd.ObservedAts[i]) obsEvent.Deadlines = append(obsEvent.Deadlines, eventToAdd.Deadlines[i]) obsEvent.Blobs = append(obsEvent.Blobs, eventToAdd.Blobs[i]) - } //TODO what if a node reports twice with different deadline or nodeID? do we need to overwrite? + } //TODO what if a node reports twice with different deadline or observation? do we need to overwrite? } + if len(obsEvent.NodeIds) >= 2*f+1 { // promote proposal to priority queue - delete(s.observedEvents, blobHash) - s.queuedEvents.pushObservations(blobHash, obsEvent) + delete(s.observedEvents, eventHash) + s.queuedBlobs[eventHash] = s.observedBlobs[eventHash] + delete(s.observedBlobs, eventHash) + event := s.queuedEvents.pushObservations(eventHash, obsEvent) + onQueued(event) } } } } + +// readConsensusState reads the consensus events and blob handles from the kvReader. +func readConsensusState(kvReader ocr3_1types.KeyValueStateReader) ([]*pb.ConsensusQueueEvent, [][]byte, error) { + v, err := kvReader.Read([]byte(consensusEventsKey)) + if err != nil { + return nil, nil, fmt.Errorf("failed to read consensus events: %w", err) + } + + var consensusEvents []*pb.ConsensusQueueEvent + if v != nil { + var pbs *pb.ConsensusQueueEventList + if err := proto.Unmarshal(v, pbs); err != nil { + return nil, nil, fmt.Errorf("failed to unmarshal consensus events: %w", err) + } + consensusEvents = pbs.GetEvents() + } + + blobHandles, err := readBlobHandles(kvReader) + if err != nil { + return nil, nil, err + } + return consensusEvents, blobHandles, nil +} + +// readBlobHandles reads the blob handles from the kvReader. +func readBlobHandles(kvReader ocr3_1types.KeyValueStateReader) ([][]byte, error) { + v, err := kvReader.Read([]byte(blobHandlesKey)) + if err != nil { + return nil, fmt.Errorf("failed to read blob handles: %w", err) + } + + var blobHandles [][]byte + if v != nil { + var bs *pb.ConsensusQueueBlobHandleList + if err := proto.Unmarshal(v, bs); err != nil { + return nil, fmt.Errorf("failed to unmarshal consensus blob handles: %w", err) + } + blobHandles = bs.GetBlobHandles() + } + return blobHandles, err +} diff --git a/core/services/ocr3_1/plugins/queue/queue.go b/core/services/ocr3_1/plugins/queue/queue.go index bbb27901ad4..295392b6a9f 100644 --- a/core/services/ocr3_1/plugins/queue/queue.go +++ b/core/services/ocr3_1/plugins/queue/queue.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "math" + "slices" "sync" "time" @@ -62,12 +63,13 @@ var _ ocr3_1types.ReportingPlugin[[]byte] = &consensusQueuePlugin{} type consensusQueuePlugin struct { services.Service - eng *services.Engine - lggr logger.Logger - onchainCfg ocr3types.ReportingPluginConfig - triggerCoordinator triggers.Coordinator - blobs ocr3_1types.BlobBroadcastFetcher - expirationDur func(context.Context) (time.Duration, error) + eng *services.Engine + lggr logger.Logger + onchainCfg ocr3types.ReportingPluginConfig + blobHandleMarshalledBytesUpperBound int + triggerCoordinator triggers.Coordinator + blobBroadcastFetcher ocr3_1types.BlobBroadcastFetcher + expirationDur func(context.Context) (time.Duration, error) } func newConsensusQueuePlugin( @@ -75,11 +77,12 @@ func newConsensusQueuePlugin( expirationGraceDur func(context.Context) (time.Duration, error), blobs ocr3_1types.BlobBroadcastFetcher, ) *consensusQueuePlugin { c := &consensusQueuePlugin{ - lggr: logger.Named(lggr, "ConsensusQueuePlugin"), - onchainCfg: onchainCfg, - triggerCoordinator: triggerCoordinator, - blobs: blobs, - expirationDur: expirationGraceDur, + lggr: logger.Named(lggr, "ConsensusQueuePlugin"), + onchainCfg: onchainCfg, + blobHandleMarshalledBytesUpperBound: ocr3_1types.BlobHandleMarshalledBytesUpperBound(onchainCfg.F, onchainCfg.N), + triggerCoordinator: triggerCoordinator, + blobBroadcastFetcher: blobs, + expirationDur: expirationGraceDur, } c.Service, c.eng = services.Config{ Name: "ConsensusQueueReportingPlugin", @@ -92,31 +95,33 @@ func (c *consensusQueuePlugin) Query(_ context.Context, _ uint64, _ ocr3_1types. } func (c *consensusQueuePlugin) Observation( - ctx context.Context, seqNr uint64, _ ocrtypes.AttributedQuery, kvState ocr3_1types.KeyValueStateReader, - blobs ocr3_1types.BlobBroadcastFetcher, + ctx context.Context, seqNr uint64, _ ocrtypes.AttributedQuery, kvReader ocr3_1types.KeyValueStateReader, + blobBroadcaster ocr3_1types.BlobBroadcastFetcher, ) (ocrtypes.Observation, error) { // Always attempt to start any executions from the KV Store in the event Committed was not called. // tryStartExecutions is idempotent. - c.tryStartExecutions(kvState) + c.tryStartExecutions(kvReader) capacity, err := c.triggerCoordinator.AvailableCapacity(ctx) if err != nil { - //TODO or just log and make a best effort to observe events regardless? return nil, fmt.Errorf("failed to get available capacity: %w", err) } var events []triggers.CoordinatedEvent // TODO observe queue - but can't "take" - need to confirm during StateTransition + // ignore if observed in kv state already expirationGraceDur, err := c.expirationDur(ctx) if err != nil { c.lggr.Warnw("Failed to get expiration grace duration - using default", "err", err) } - expiration := time.Now().Add(expirationGraceDur) + emptyBlobHandle := make([]byte, c.blobHandleMarshalledBytesUpperBound) obs := &pb.ConsensusQueueObservation{ - Events: make([]*pb.ConsensusQueueEvent, 0, len(events)), - Expiration: timestamppb.New(expiration), + Events: make([]*pb.ConsensusQueueEvent, 0, len(events)), + // placeholder for accurate size calculation + BlobHandles: slices.Repeat([][]byte{emptyBlobHandle}, maxObservedBlobHandles), + Expiration: timestamppb.New(time.Now().Add(-expirationGraceDur)), Capacity: uint32(min(capacity.Global, math.MaxUint32)), WorkflowCapacities: make(map[string]uint32), } @@ -125,76 +130,111 @@ func (c *consensusQueuePlugin) Observation( obs.WorkflowCapacities[wf] = uint32(min(wfCap, math.MaxUint32)) } - const roundDur = 10 * time.Second //TODO dynamic calibration? - expSeqNr := seqNr + uint64(expirationGraceDur/roundDur) //TODO pad extra time and/or rounds - - pbEvents := make([]*pb.CoordinatedEvent, len(events)) + coordEvents := make([]*pb.CoordinatedEvent, len(events)) for i, e := range events { - pbEvents[i] = e.ToProto() + coordEvents[i] = e.ToProto() } - blobHandle, err := broadcastAsBlob(ctx, blobs, pbEvents, expSeqNr) - if err != nil { - return nil, err - } - - const maxObservationSize = 0 //TODO from where? protoOpts := proto.MarshalOptions{Deterministic: true} - for i, m := range pbEvents { + for i, coord := range coordEvents { //TODO iter.Seq from trigger coordinator // Try adding to batch - observedAt, deadline := m.ObservedAt, m.Deadline - m.ObservedAt, m.Deadline = nil, nil // for consistent hashing - protoBytes, err2 := protoOpts.Marshal(m) //TODO opt: don't marshal again, get hash from broadcast helper + observedAt, deadline := coord.ObservedAt, coord.Deadline + coord.ObservedAt, coord.Deadline = nil, nil // for consistent hashing + protoBytes, err2 := protoOpts.Marshal(coord) // TODO opt: avoid remarshalling if err2 != nil { - c.lggr.Errorw("failed to marshal event", "eventID", m.Event.Event.Id, "err", err2) + c.lggr.Errorw("failed to marshal event", "eventID", coord.Event.Event.Id, "err", err2) continue } - blobHash := sha256.Sum256(protoBytes) + timelessHash := sha256.Sum256(protoBytes) obs.Events = append(obs.Events, &pb.ConsensusQueueEvent{ - WorkflowID: m.WorkflowID, - TriggerEventID: m.Event.Event.Id, + WorkflowID: coord.WorkflowID, + TriggerEventID: coord.Event.Event.Id, ObservedAt: observedAt, Deadline: deadline, - BlobHash: blobHash[:], + TimelessHash: timelessHash[:], Blobs: []*pb.CoordinatedEventBlobHandle{{ - Handle: blobHandle, - Index: uint32(i), + Blob: 0, + Element: uint32(i), }}, }) var addedCap bool - if _, ok := obs.WorkflowCapacities[m.WorkflowID]; !ok { + if _, ok := obs.WorkflowCapacities[coord.WorkflowID]; !ok { addedCap = true - obs.WorkflowCapacities[m.WorkflowID] = uint32(min(capacity.PerWorkflow[m.WorkflowID], math.MaxUint32)) + obs.WorkflowCapacities[coord.WorkflowID] = uint32(min(capacity.PerWorkflow[coord.WorkflowID], math.MaxUint32)) } + // Check size - if protoOpts.Size(obs) > maxObservationSize { + if protoOpts.Size(obs) > maxObservationBytes { // too large, remove this one obs.Events = obs.Events[:len(obs.Events)-1] if addedCap { - delete(obs.WorkflowCapacities, m.WorkflowID) + delete(obs.WorkflowCapacities, coord.WorkflowID) } - //TODO opt: remember the blobHandle to avoid rebroadcasting events break } } + + roundDur := c.onchainCfg.EstimatedRoundInterval //TODO OK? + expSeqNr := seqNr + uint64(expirationGraceDur/roundDur) //TODO pad extra time and/or rounds? + + obs.BlobHandles = nil // remove the placeholders + if len(coordEvents) > 0 { + blobHandle, n, err2 := broadcastAsBlob(ctx, blobBroadcaster, coordEvents, expSeqNr) + if err2 != nil { + return nil, err2 + } + obs.BlobHandles = append(obs.BlobHandles, blobHandle) + // note: elements already reference blob 0 and natural element index is aligned + + var offset int + for batch := 1; n < len(coordEvents); batch++ { + offset += n + coordEvents = coordEvents[n:] + blobHandle, n, err2 = broadcastAsBlob(ctx, blobBroadcaster, coordEvents, expSeqNr) + if err2 != nil { + return nil, err2 + } + obs.BlobHandles = append(obs.BlobHandles, blobHandle) + for i := n; i < n; i++ { // update indices + obs.Events[offset+i].Blobs[0].Blob = uint32(batch) + obs.Events[offset+i].Blobs[0].Element = uint32(i) + } + } + } + return protoOpts.Marshal(obs) } func (c *consensusQueuePlugin) ValidateObservation( ctx context.Context, _ uint64, _ ocrtypes.AttributedQuery, ao ocrtypes.AttributedObservation, - _ ocr3_1types.KeyValueStateReader, blobs ocr3_1types.BlobFetcher, + _ ocr3_1types.KeyValueStateReader, blobFetcher ocr3_1types.BlobFetcher, ) error { var obs pb.ConsensusQueueObservation err := proto.Unmarshal(ao.Observation, &obs) if err != nil { return fmt.Errorf("failed to unmarshal observation: %w", err) } + if len(obs.BlobHandles) > maxObservedBlobHandles { + return fmt.Errorf("blob handles are limited to %d but got %d", maxObservedBlobHandles, len(obs.BlobHandles)) + } + if obs.Expiration == nil { + return errors.New("expiration is missing") + } + //TODO what do we expect from WF capacities? check KV state and insist 100% match? or subset - none extra? + + if len(obs.Events) > maxObservedEvents { + return fmt.Errorf("events are limited to %d but got %d", maxObservedEvents, len(obs.Events)) + } + if !slices.IsSortedFunc(obs.Events, cmpConsensusQueueEvents) { + return fmt.Errorf("events must be sorted") + } var eg errgroup.Group + fetcher := blobCache{fetcher: blobFetcher, cache: make(map[string]func() ([]byte, error))} for i, event := range obs.Events { eg.Go(func() error { - if err := validateObservedEvent(ctx, blobs, event); err != nil { + if err := validateObservedEvent(ctx, &fetcher, event, obs.BlobHandles); err != nil { return fmt.Errorf("event %d failed validation: %w", i, err) } return nil @@ -203,22 +243,22 @@ func (c *consensusQueuePlugin) ValidateObservation( return eg.Wait() } -func validateObservedEvent(ctx context.Context, blobs ocr3_1types.BlobFetcher, event *pb.ConsensusQueueEvent) error { +func validateObservedEvent(ctx context.Context, fetcher *blobCache, event *pb.ConsensusQueueEvent, blobHandles [][]byte) error { if event.WorkflowID == "" { return errors.New("event workflow id is missing") - } + } ///TODO check not too long - exact length? if event.TriggerEventID == "" { return errors.New("event trigger event id is missing") - } + } ///TODO check not too long - exact length? if event.ObservedAt == nil { return errors.New("event observation ts is missing") } if event.Deadline == nil { return errors.New("event deadline is missing") } - if event.BlobHash == nil { + if event.TimelessHash == nil { return fmt.Errorf("event blob hash is missing") - } + } ///TODO check not too long - exact length? if len(event.Blobs) == 0 { return fmt.Errorf("event blob is missing") @@ -227,7 +267,13 @@ func validateObservedEvent(ctx context.Context, blobs ocr3_1types.BlobFetcher, e return fmt.Errorf("event has more than one blob") } - coordEvent, pbBytes, err := fetchFromBlob(ctx, blobs, event.Blobs[0].Handle, int(event.Blobs[0].Index)) + blobIdx := int(event.Blobs[0].Blob) + if blobIdx >= len(blobHandles) { + return fmt.Errorf("event blob index %d is out of range", blobIdx) + } + blobHandle := blobHandles[blobIdx] + + coordEvent, pbBytes, err := fetchCoordinatedEventFromBlob(ctx, fetcher, blobHandle, int(event.Blobs[0].Element)) if err != nil { return fmt.Errorf("failed to fetch event from blob: %w", err) } @@ -246,9 +292,9 @@ func validateObservedEvent(ctx context.Context, blobs ocr3_1types.BlobFetcher, e return fmt.Errorf("blob deadline timestamp is not nil: %v", coordEvent.Deadline) } - //TODO reduce allocations with a pool? - if shaSum := sha256.Sum256(pbBytes); !bytes.Equal(shaSum[:], event.BlobHash) { - return fmt.Errorf("blob hash %x does not match observation hash %x", shaSum, event.BlobHash) + //TODO opt: reduce allocations with a pool + if shaSum := sha256.Sum256(pbBytes); !bytes.Equal(shaSum[:], event.TimelessHash) { + return fmt.Errorf("blob hash %x does not match observation hash %x", shaSum, event.TimelessHash) } return nil @@ -263,7 +309,7 @@ func (c *consensusQueuePlugin) ObservationQuorum( func (c *consensusQueuePlugin) StateTransition( ctx context.Context, _ uint64, _ ocrtypes.AttributedQuery, aos []ocrtypes.AttributedObservation, - kvState ocr3_1types.KeyValueStateReadWriter, _ ocr3_1types.BlobFetcher, + kvReaderWriter ocr3_1types.KeyValueStateReadWriter, _ ocr3_1types.BlobFetcher, ) (ocr3_1types.ReportsPlusPrecursor, error) { var done chan struct{} var obs observations @@ -273,8 +319,8 @@ func (c *consensusQueuePlugin) StateTransition( obs.aggregate(ctx, aos) }() - stateRW := newStateReadWriter(kvState) - state, err := stateRW.readObservedAndQueued() + var state kvState + err := state.loadFrom(kvReaderWriter) if err != nil { return nil, fmt.Errorf("failed to read state: %w", err) } @@ -297,27 +343,32 @@ func (c *consensusQueuePlugin) StateTransition( // update state state.pruneExpiredObservations(obs.medianExpiration) - state.addObservedEvents(c.onchainCfg.F, obs.newObservedEvents) - consensusEvents, err := state.queuedEvents.popLimited(obs.medianCap, obs.medianCapPerWF, obs.medianExpiration) - if err != nil { - return nil, err + state.addObservedEvents(c.onchainCfg.F, obs.newObservedEvents, obs.observedBlobs, func(queued *pb.ConsensusQueueEvent) { + //TODO ack the trigger coordinator - no longer need to observe this event + }) + state.consensusEvents = state.queuedEvents.popLimited(obs.medianCap, obs.medianCapPerWF, obs.medianExpiration) + + // prune observations until we fit + for state.sizeOf() > maxKeyValueModifiedKeysPlusValuesBytes { + //TODO drop observations (must be deterministic, fair, efficient) + // prefer farthest future deadlines and fewest observations } - //TODO might we hit a KV size limit in the middle of these? then what? can't just drop proposals - // alternative: proposals only valid when there is definitely enough space - err = stateRW.writeAll(state, consensusEvents) + + err = state.writeTo(&stateWriter{kv: kvReaderWriter}) if err != nil { return nil, err } // no report to return, executions start when committed - return ocr3_1types.ReportsPlusPrecursor{}, nil + return nil, nil } type observations struct { medianExpiration time.Time medianCap uint32 medianCapPerWF map[string]uint32 // wf ID -> capacity - newObservedEvents map[string]*pb.ConsensusQueueObservedEvent // key: blobHash + newObservedEvents map[string]*pb.ConsensusQueueObservedEvent // key: timeless hash + observedBlobs blobHandleMap warn error err error } @@ -346,7 +397,7 @@ func (res *observations) aggregate(ctx context.Context, aos []ocrtypes.Attribute if ctx.Err() != nil { return } - res.addEvent(ao.Observer, event) + res.addEvent(ao.Observer, event, obs.BlobHandles) } } res.medianExpiration = medianTimestamp(expirations).AsTime() @@ -357,57 +408,49 @@ func (res *observations) aggregate(ctx context.Context, aos []ocrtypes.Attribute return } -func (res *observations) addEvent(obs commontypes.OracleID, event *pb.ConsensusQueueEvent) { - aggregated, ok := res.newObservedEvents[string(event.BlobHash)] +func (res *observations) addEvent(obs commontypes.OracleID, event *pb.ConsensusQueueEvent, blobHandles [][]byte) { + res.observedBlobs.add(string(event.TimelessHash), string(blobHandles[event.Blobs[0].Blob]), event.Blobs[0].Element) + aggregated, ok := res.newObservedEvents[string(event.TimelessHash)] if !ok { - aggregated = &pb.ConsensusQueueObservedEvent{ + res.newObservedEvents[string(event.TimelessHash)] = &pb.ConsensusQueueObservedEvent{ TriggerEventID: event.TriggerEventID, WorkflowID: event.WorkflowID, NodeIds: []uint8{uint8(obs)}, ObservedAts: []*timestamppb.Timestamp{event.ObservedAt}, Deadlines: []*timestamppb.Timestamp{event.Deadline}, - Blobs: []*pb.CoordinatedEventBlobHandle{event.Blobs[0]}, + Blobs: nil, // res.observedBlobs tracks these while in memory } } else { // note: trigger event and workflow ID alignment is ensured by ValidateObservation aggregated.NodeIds = append(aggregated.NodeIds, uint8(obs)) aggregated.ObservedAts = append(aggregated.ObservedAts, event.ObservedAt) aggregated.Deadlines = append(aggregated.Deadlines, event.Deadline) - aggregated.Blobs = append(aggregated.Blobs, event.Blobs...) + // note: res.observedBlobs tracks blobs while in memory } - - res.newObservedEvents[string(event.BlobHash)] = aggregated } -func (c *consensusQueuePlugin) Committed(ctx context.Context, _ uint64, kvState ocr3_1types.KeyValueStateReader) error { - c.tryStartExecutions(kvState) +func (c *consensusQueuePlugin) Committed(ctx context.Context, _ uint64, kvReader ocr3_1types.KeyValueStateReader) error { + c.tryStartExecutions(kvReader) return nil } // tryStartExecutions calls StartExecution asynchronously on the corresponding engine for each trigger event. // It is idempotent, thus safe to call from Observation and Committed. -func (c *consensusQueuePlugin) tryStartExecutions(kvState ocr3_1types.KeyValueStateReader) { - v, err := kvState.Read([]byte(consensusEventsKey)) +func (c *consensusQueuePlugin) tryStartExecutions(kvReader ocr3_1types.KeyValueStateReader) { + consensusEvents, blobHandles, err := readConsensusState(kvReader) if err != nil { - c.lggr.Errorw("Failed to read consensus events", "err", err) + c.lggr.Errorw("Failed to read consensus state. Unable to execute events", "err", err) return } - var consensusEvents []*pb.ConsensusQueueEvent - if v != nil { - var pbs *pb.ConsensusQueueEventList - if err := proto.Unmarshal(v, pbs); err != nil { - c.lggr.Errorw("Failed to unmarshal consensus events", "err", err) - return - } - } + fetcher := blobCache{fetcher: c.blobBroadcastFetcher, cache: make(map[string]func() ([]byte, error))} var wg sync.WaitGroup for _, consensusEvent := range consensusEvents { wg.Add(1) c.eng.Go(func(ctx context.Context) { defer wg.Done() - if err2 := c.tryStartExecution(ctx, consensusEvent); err2 != nil { + if err2 := c.tryStartExecution(ctx, &fetcher, consensusEvent, blobHandles); err2 != nil { c.lggr.Errorw("Failed to execute event", "eventID", consensusEvent.TriggerEventID, "err", err2) return } @@ -416,16 +459,21 @@ func (c *consensusQueuePlugin) tryStartExecutions(kvState ocr3_1types.KeyValueSt wg.Wait() } -func (c *consensusQueuePlugin) tryStartExecution(ctx context.Context, consensusEvent *pb.ConsensusQueueEvent) error { +func (c *consensusQueuePlugin) tryStartExecution(ctx context.Context, fetcher *blobCache, consensusEvent *pb.ConsensusQueueEvent, blobHandles [][]byte) error { // any blob will do, first that exists var pbEvent *pb.CoordinatedEvent var errs []error for _, blob := range consensusEvent.Blobs { var err error - pbEvent, _, err = fetchFromBlob(ctx, c.blobs, blob.Handle, int(blob.Index)) + if int(blob.Blob) > len(blobHandles) { + c.lggr.Errorw("Blob handle index out of bounds", "index", int(blob.Blob), "len", len(blobHandles)) + continue + } + blobHandle := blobHandles[int(blob.Blob)] + pbEvent, _, err = fetchCoordinatedEventFromBlob(ctx, fetcher, blobHandle, int(blob.Element)) if err != nil { errs = append(errs, fmt.Errorf("failed to fetch blob: %w", err)) - c.lggr.Warnw("Failed to fetch blob", "handle", blob.Handle, "index", blob.Index, "err", err) + c.lggr.Errorw("Failed to fetch blob", "handle", blobHandle, "index", blob.Element, "err", err) continue // try next blob } break diff --git a/deployment/go.mod b/deployment/go.mod index d3be9e9c97e..dd62620f2b2 100644 --- a/deployment/go.mod +++ b/deployment/go.mod @@ -41,7 +41,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/solana/deployment v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-data-streams v1.1.2-0.20261009064810-68424c714170 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 diff --git a/deployment/go.sum b/deployment/go.sum index e1a6402cf6a..24a7a64efeb 100644 --- a/deployment/go.sum +++ b/deployment/go.sum @@ -1411,8 +1411,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 h1:nzm+zgN1C6kNVlQnlp3XlzqFl7g9K5h63mRyctvGNRE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012 h1:7GCOxs3dYlwdm1lW+SI8hPXH0BC/uyUHkX9l8twglcM= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/go.mod b/go.mod index 8485ebe8c95..45b546755e3 100644 --- a/go.mod +++ b/go.mod @@ -82,7 +82,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260908155618-50f521d70e62 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260908155618-50f521d70e62 github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260903141829-ef07b52a737d github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 github.com/smartcontractkit/chainlink-data-streams v1.1.2-0.20261009064810-68424c714170 diff --git a/go.sum b/go.sum index 2bf1e20560a..f290b59aaad 100644 --- a/go.sum +++ b/go.sum @@ -1104,8 +1104,8 @@ github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260908155618-50f521d70e62/go.mod h1:c++Ed0jeYn4w8WIfiAboRwN6ClRRVGglL0qwB/QjJvM= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 h1:nzm+zgN1C6kNVlQnlp3XlzqFl7g9K5h63mRyctvGNRE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012 h1:7GCOxs3dYlwdm1lW+SI8hPXH0BC/uyUHkX9l8twglcM= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260903141829-ef07b52a737d h1:M9xuiIvdiHtim4nlxCVajyC/Mk63tAg9ESWb/biAhNA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260903141829-ef07b52a737d/go.mod h1:rI2njmTlyTvh+xhmORmK6qX3+V1ycDAqGJLu8LS8WpU= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 3d443a8161e..9abd4744c11 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -30,7 +30,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260916222901-720a003dab50 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261022195454-600e2b321c7a diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 3bc11225002..0388798fb35 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1396,8 +1396,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 h1:nzm+zgN1C6kNVlQnlp3XlzqFl7g9K5h63mRyctvGNRE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012 h1:7GCOxs3dYlwdm1lW+SI8hPXH0BC/uyUHkX9l8twglcM= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/integration-tests/load/go.mod b/integration-tests/load/go.mod index 2747299cb57..42e3c7558a4 100644 --- a/integration-tests/load/go.mod +++ b/integration-tests/load/go.mod @@ -20,7 +20,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260916222901-720a003dab50 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261022195454-600e2b321c7a github.com/smartcontractkit/chainlink-testing-framework/framework v0.16.9 diff --git a/integration-tests/load/go.sum b/integration-tests/load/go.sum index 57597143855..45bba0ba2c8 100644 --- a/integration-tests/load/go.sum +++ b/integration-tests/load/go.sum @@ -1636,8 +1636,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 h1:nzm+zgN1C6kNVlQnlp3XlzqFl7g9K5h63mRyctvGNRE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012 h1:7GCOxs3dYlwdm1lW+SI8hPXH0BC/uyUHkX9l8twglcM= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/system-tests/lib/go.mod b/system-tests/lib/go.mod index 1d0ce30854a..475ce862d16 100644 --- a/system-tests/lib/go.mod +++ b/system-tests/lib/go.mod @@ -32,7 +32,7 @@ require ( github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-aptos v0.0.0-20260923062809-ca886ade4d26 github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260916222901-720a003dab50 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-confidential-compute v1.3.0 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 diff --git a/system-tests/lib/go.sum b/system-tests/lib/go.sum index 203956afb5e..47ec29cc611 100644 --- a/system-tests/lib/go.sum +++ b/system-tests/lib/go.sum @@ -1657,8 +1657,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 h1:nzm+zgN1C6kNVlQnlp3XlzqFl7g9K5h63mRyctvGNRE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012 h1:7GCOxs3dYlwdm1lW+SI8hPXH0BC/uyUHkX9l8twglcM= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/system-tests/tests/go.mod b/system-tests/tests/go.mod index bf80ac8f49d..b0943c93185 100644 --- a/system-tests/tests/go.mod +++ b/system-tests/tests/go.mod @@ -73,7 +73,7 @@ require ( github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-aptos v0.0.0-20260923062809-ca886ade4d26 github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260916222901-720a003dab50 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 github.com/smartcontractkit/chainlink-confidential-compute v1.3.0 diff --git a/system-tests/tests/go.sum b/system-tests/tests/go.sum index 0abf9c77984..64aef864d85 100644 --- a/system-tests/tests/go.sum +++ b/system-tests/tests/go.sum @@ -1836,8 +1836,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37 h1:eZj3cJUTFmbpuRMsUwAM99QYPRiD4udbfcuRLWZ2WWg= github.com/smartcontractkit/chainlink-ccv v0.15.1-0.20261020204039-1a47492cdb37/go.mod h1:A107VkPT8sqCjZJ/2GULxEQOaky70t5tkcE7hK9NDpI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49 h1:nzm+zgN1C6kNVlQnlp3XlzqFl7g9K5h63mRyctvGNRE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261112195848-86be69f83e49/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012 h1:7GCOxs3dYlwdm1lW+SI8hPXH0BC/uyUHkX9l8twglcM= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117023719-a7ac77a0c012/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd h1:5pkLw8ZJwMPc27ccq335YullY+kHYiPCIqCvk6zJvBA= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20260923164324-86cd57d9fdbd/go.mod h1:r8u2d+ZpMweYchIytSRmkRFR+aKQ5c7/HoNv2hzuoTY= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= From 0a0595caeca194aaf21accaccdf2b269d3230df3 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Tue, 17 Nov 2026 17:57:44 -0600 Subject: [PATCH 09/13] cleanup; medianization; swap map for entries --- core/scripts/go.mod | 2 +- core/scripts/go.sum | 4 +- core/services/ocr3_1/plugins/queue/kvstate.go | 64 ++++++++++------- core/services/ocr3_1/plugins/queue/math.go | 25 +++++-- core/services/ocr3_1/plugins/queue/queue.go | 69 ++++++++++++++----- deployment/go.mod | 2 +- deployment/go.sum | 4 +- go.mod | 2 +- go.sum | 4 +- integration-tests/go.mod | 2 +- integration-tests/go.sum | 4 +- integration-tests/load/go.mod | 2 +- integration-tests/load/go.sum | 4 +- .../lib/cre/environment/environment.go | 43 ------------ system-tests/lib/go.mod | 2 +- system-tests/lib/go.sum | 4 +- system-tests/tests/go.mod | 2 +- system-tests/tests/go.sum | 4 +- 18 files changed, 133 insertions(+), 110 deletions(-) diff --git a/core/scripts/go.mod b/core/scripts/go.mod index 833acd8fcd6..b1bee600bdd 100644 --- a/core/scripts/go.mod +++ b/core/scripts/go.mod @@ -29,7 +29,7 @@ require ( github.com/shopspring/decimal v1.4.0 github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261112211734-e640e1c12078 diff --git a/core/scripts/go.sum b/core/scripts/go.sum index 50ecabb3aef..fddbfc28b6b 100644 --- a/core/scripts/go.sum +++ b/core/scripts/go.sum @@ -1686,8 +1686,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.16.0 h1:WhDQEEI2Kb5A4C0PNAa+nyGLDvG0H+uT6h4y1NwmkYg= github.com/smartcontractkit/chainlink-ccv v0.16.0/go.mod h1:oaSLVHiJVbJ9aCcUQnoRuVONACWzA/DWVqvUnLAe9bE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337 h1:pD5MmKg+G52nkA4ghoVFqUtkAtZsUyGOSBY+P3JFE+M= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 h1:V+IBcXmheTxfYQb8gX/2KFjcIwiPSz6hvJ5MmOh9hjI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb h1:9rVrSeVOAwZsVe2pOpeVRp9XjhtMyjndgeROFglvOhg= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb/go.mod h1:WcOKzF6HkTDrkQ96aBHhcJ2IIYE7iK7M2tdt58ea2qc= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/core/services/ocr3_1/plugins/queue/kvstate.go b/core/services/ocr3_1/plugins/queue/kvstate.go index 1866b6d0472..0344ed52ddd 100644 --- a/core/services/ocr3_1/plugins/queue/kvstate.go +++ b/core/services/ocr3_1/plugins/queue/kvstate.go @@ -146,9 +146,10 @@ func (m blobHandleMap) addAll(eventHash string, blobHandles map[string]uint32) { type kvState struct { // observedEventsKey - observedEvents map[string]*pb.ConsensusQueueObservedEvent // key: timeless hash - observedBlobs blobHandleMap - observedBlobHandles [][]byte // only populated before write + observedEvents map[string]*pb.ConsensusQueueObservedEvent // key: timeless hash + observedEventEntries []*pb.ConsensusQueueObservedEventEntry // only populated before write + observedBlobs blobHandleMap + observedBlobHandles [][]byte // only populated before write // priorityQueueKey queuedEvents *priorityQueue @@ -161,28 +162,13 @@ type kvState struct { // loadFrom loads the kvState from the KV store, excluding consensus events, which are not required to transition. func (s *kvState) loadFrom(kv ocr3_1types.KeyValueStateReadWriter) error { - v, err := kv.Read([]byte(observedEventsKey)) + var err error + s.observedEvents, s.observedBlobs, err = readObservedEvents(kv) if err != nil { - return fmt.Errorf("failed to read observed events: %w", err) - } - s.observedBlobs = make(blobHandleMap) - if v != nil { - var observed *pb.ConsensusQueueObservedEvents - if err = proto.Unmarshal(v, observed); err != nil { - return fmt.Errorf("failed to unmarshal observed events: %w", err) - } - s.observedEvents = observed.GetObservations() - blobHandles := observed.GetBlobHandles() - for eventHash, event := range s.observedEvents { - for _, b := range event.GetBlobs() { - s.observedBlobs.add(eventHash, string(blobHandles[b.Blob]), b.Element) - } - } - } else { - s.observedEvents = make(map[string]*pb.ConsensusQueueObservedEvent) + return err } - v, err = kv.Read([]byte(queuedEventsKey)) + v, err := kv.Read([]byte(queuedEventsKey)) if err != nil { return fmt.Errorf("failed to read queued events: %w", err) } @@ -208,6 +194,33 @@ func (s *kvState) loadFrom(kv ocr3_1types.KeyValueStateReadWriter) error { return nil } +func readObservedEvents(kv ocr3_1types.KeyValueStateReader) (observedEvents map[string]*pb.ConsensusQueueObservedEvent, observedBlobs blobHandleMap, err error) { + v, err := kv.Read([]byte(observedEventsKey)) + if err != nil { + return nil, nil, fmt.Errorf("failed to read observed events: %w", err) + } + observedBlobs = make(blobHandleMap) + if v != nil { + var observed *pb.ConsensusQueueObservedEvents + if err = proto.Unmarshal(v, observed); err != nil { + return nil, nil, fmt.Errorf("failed to unmarshal observed events: %w", err) + } + observedEvents = make(map[string]*pb.ConsensusQueueObservedEvent) + for _, e := range observed.GetObservations() { + observedEvents[string(e.TimelessHash)] = e.Event + } + blobHandles := observed.GetBlobHandles() + for eventHash, event := range observedEvents { + for _, b := range event.GetBlobs() { + observedBlobs.add(eventHash, string(blobHandles[b.Blob]), b.Element) + } + } + } else { + observedEvents = make(map[string]*pb.ConsensusQueueObservedEvent) + } + return +} + // sizeOf returns the size of the state when serialized and written to the KV store via writeAll. func (s *kvState) sizeOf() (size int) { s.prepareWrite() @@ -216,7 +229,7 @@ func (s *kvState) sizeOf() (size int) { protoOpts := proto.MarshalOptions{Deterministic: true} size += len(observedEventsKey) + len(queuedEventsKey) + len(consensusEventsKey) + len(blobHandlesKey) - size += protoOpts.Size(&pb.ConsensusQueueObservedEvents{Observations: s.observedEvents, BlobHandles: s.observedBlobHandles}) + size += protoOpts.Size(&pb.ConsensusQueueObservedEvents{Observations: s.observedEventEntries, BlobHandles: s.observedBlobHandles}) size += protoOpts.Size(&pb.ConsensusQueueEventList{Events: *s.queuedEvents}) size += protoOpts.Size(&pb.ConsensusQueueEventList{Events: s.consensusEvents}) size += protoOpts.Size(&pb.ConsensusQueueBlobHandleList{BlobHandles: s.queuedBlobHandles}) @@ -229,6 +242,7 @@ func (s *kvState) prepareWrite() { // gather blob handles and update events s.observedBlobHandles = nil observedBlobIndexes := make(map[string]int) + s.observedEventEntries = nil for _, eventHash := range slices.Sorted(maps.Keys(s.observedEvents)) { event := s.observedEvents[eventHash] event.Blobs = nil // replace all @@ -244,6 +258,8 @@ func (s *kvState) prepareWrite() { Element: ei, }) } + s.observedEventEntries = append(s.observedEventEntries, &pb.ConsensusQueueObservedEventEntry{ + TimelessHash: []byte(eventHash), Event: event}) } // gather blob handles and update events @@ -278,7 +294,7 @@ func (s *kvState) prepareWrite() { func (s *kvState) writeTo(w *stateWriter) error { //TODO MarshalOptions{UseCachedSize}? - err := w.writeValue(observedEventsKey, &pb.ConsensusQueueObservedEvents{Observations: s.observedEvents, BlobHandles: s.observedBlobHandles}) + err := w.writeValue(observedEventsKey, &pb.ConsensusQueueObservedEvents{Observations: s.observedEventEntries, BlobHandles: s.observedBlobHandles}) if err != nil { return fmt.Errorf("failed to write observed events: %w", err) } diff --git a/core/services/ocr3_1/plugins/queue/math.go b/core/services/ocr3_1/plugins/queue/math.go index 57962d67750..b67cd83cb08 100644 --- a/core/services/ocr3_1/plugins/queue/math.go +++ b/core/services/ocr3_1/plugins/queue/math.go @@ -8,23 +8,38 @@ import ( "google.golang.org/protobuf/types/known/timestamppb" ) -// median returns the median value of a slice of integers. +// median returns the median value of a slice of integers, as well as a count of the number of occurrences of the median. // len must be greater than 0. -func median[N constraints.Integer, S []N](s S) N { +func median[N constraints.Integer, S []N](s S) (N, int) { switch len(s) { case 0: panic("median: len must be greater than 0") case 1: - return s[0] + return s[0], 1 } slices.Sort(s) if len(s)%2 == 1 { - return s[len(s)/2] + m := s[len(s)/2] + return m, count(s, m) } // avg of two a, b := s[len(s)/2], s[len(s)/2-1] diff := a - b - return b + diff/2 + m := b + diff/2 + return m, count(s, m) +} + +// count returns the number of occurrences of e in s, but s must be sorted. +func count[N comparable, S []N](s S, e N) int { + firstIndex := slices.Index(s, e) + if firstIndex == -1 { + return 0 + } + var c int + for i := firstIndex; i < len(s) && s[i] == e; i++ { + c++ + } + return c } // medianTimestamp returns the median value of a slice of timestamps. diff --git a/core/services/ocr3_1/plugins/queue/queue.go b/core/services/ocr3_1/plugins/queue/queue.go index 295392b6a9f..4f1d02f6d95 100644 --- a/core/services/ocr3_1/plugins/queue/queue.go +++ b/core/services/ocr3_1/plugins/queue/queue.go @@ -6,6 +6,7 @@ import ( "crypto/sha256" "errors" "fmt" + "iter" "math" "slices" "sync" @@ -107,10 +108,6 @@ func (c *consensusQueuePlugin) Observation( return nil, fmt.Errorf("failed to get available capacity: %w", err) } - var events []triggers.CoordinatedEvent - // TODO observe queue - but can't "take" - need to confirm during StateTransition - // ignore if observed in kv state already - expirationGraceDur, err := c.expirationDur(ctx) if err != nil { c.lggr.Warnw("Failed to get expiration grace duration - using default", "err", err) @@ -118,7 +115,6 @@ func (c *consensusQueuePlugin) Observation( emptyBlobHandle := make([]byte, c.blobHandleMarshalledBytesUpperBound) obs := &pb.ConsensusQueueObservation{ - Events: make([]*pb.ConsensusQueueEvent, 0, len(events)), // placeholder for accurate size calculation BlobHandles: slices.Repeat([][]byte{emptyBlobHandle}, maxObservedBlobHandles), Expiration: timestamppb.New(time.Now().Add(-expirationGraceDur)), @@ -130,12 +126,17 @@ func (c *consensusQueuePlugin) Observation( obs.WorkflowCapacities[wf] = uint32(min(wfCap, math.MaxUint32)) } - coordEvents := make([]*pb.CoordinatedEvent, len(events)) - for i, e := range events { - coordEvents[i] = e.ToProto() + var events iter.Seq[*triggers.CoordinatedEvent] + //TODO events iter from triggerCoordinator, to be acked later during StateTransition + + observedEvents, _, err := readObservedEvents(kvReader) + if err != nil { + return nil, err } + protoOpts := proto.MarshalOptions{Deterministic: true} - for i, coord := range coordEvents { //TODO iter.Seq from trigger coordinator + var coordEvents []*pb.CoordinatedEvent + for coord := range toProtoSeq(events) { // Try adding to batch observedAt, deadline := coord.ObservedAt, coord.Deadline @@ -147,6 +148,13 @@ func (c *consensusQueuePlugin) Observation( } timelessHash := sha256.Sum256(protoBytes) + // skip if kv observation exists already + if obsEvent, ok := observedEvents[string(timelessHash[:])]; ok { + if slices.Contains(obsEvent.NodeIds, uint8(c.onchainCfg.OracleID)) { + continue + } + } + obs.Events = append(obs.Events, &pb.ConsensusQueueEvent{ WorkflowID: coord.WorkflowID, TriggerEventID: coord.Event.Event.Id, @@ -155,9 +163,10 @@ func (c *consensusQueuePlugin) Observation( TimelessHash: timelessHash[:], Blobs: []*pb.CoordinatedEventBlobHandle{{ Blob: 0, - Element: uint32(i), + Element: uint32(len(coordEvents)), }}, }) + coordEvents = append(coordEvents, coord) var addedCap bool if _, ok := obs.WorkflowCapacities[coord.WorkflowID]; !ok { @@ -207,6 +216,16 @@ func (c *consensusQueuePlugin) Observation( return protoOpts.Marshal(obs) } +func toProtoSeq(in iter.Seq[*triggers.CoordinatedEvent]) iter.Seq[*pb.CoordinatedEvent] { + return func(yield func(*pb.CoordinatedEvent) bool) { + for event := range in { + if !yield(event.ToProto()) { + return + } + } + } +} + func (c *consensusQueuePlugin) ValidateObservation( ctx context.Context, _ uint64, _ ocrtypes.AttributedQuery, ao ocrtypes.AttributedObservation, _ ocr3_1types.KeyValueStateReader, blobFetcher ocr3_1types.BlobFetcher, @@ -316,7 +335,7 @@ func (c *consensusQueuePlugin) StateTransition( go func() { defer close(done) - obs.aggregate(ctx, aos) + obs.aggregate(ctx, c.onchainCfg.F, aos) }() var state kvState @@ -343,6 +362,7 @@ func (c *consensusQueuePlugin) StateTransition( // update state state.pruneExpiredObservations(obs.medianExpiration) + //TODO must not promote to PQ and ack until we are sure we can write the kv state.addObservedEvents(c.onchainCfg.F, obs.newObservedEvents, obs.observedBlobs, func(queued *pb.ConsensusQueueEvent) { //TODO ack the trigger coordinator - no longer need to observe this event }) @@ -373,8 +393,7 @@ type observations struct { err error } -// TODO consider some configurable x% of capacity since some honest nodes have less -func (res *observations) aggregate(ctx context.Context, aos []ocrtypes.AttributedObservation) { +func (res *observations) aggregate(ctx context.Context, f int, aos []ocrtypes.AttributedObservation) { res.medianCapPerWF = make(map[string]uint32) res.newObservedEvents = make(map[string]*pb.ConsensusQueueObservedEvent) @@ -401,9 +420,18 @@ func (res *observations) aggregate(ctx context.Context, aos []ocrtypes.Attribute } } res.medianExpiration = medianTimestamp(expirations).AsTime() - res.medianCap = median(capacities) + + // Medianize capacities, and when there is disagreement among honest nodes, scale back to 90%. + var medianCount int + res.medianCap, medianCount = median(capacities) + if medianCount < 2*f+1 { + res.medianCap = (res.medianCap * 9) / 10 + } for wf, caps := range wfCapacities { - res.medianCapPerWF[wf] = median(caps) + res.medianCapPerWF[wf], medianCount = median(caps) + if medianCount < 2*f+1 { + res.medianCapPerWF[wf] = (res.medianCapPerWF[wf] * 9) / 10 + } } return } @@ -490,8 +518,15 @@ func (c *consensusQueuePlugin) tryStartExecution(ctx context.Context, fetcher *b return fmt.Errorf("failed to convert CoordinatedEvent from proto: %w", err) } - // TODO execute StartExecution - // c.triggerCoordinator.tryStartExecution(ctx, event) + // TODO c.triggerCoordinator.tryStartExecution(ctx, event) + + // only log metadata, not outputs and payload + event.Event.Event.Outputs = nil + event.Event.Event.Payload = nil + latency := time.Since(event.ObservedAt) + c.lggr.Infow("Consensus event dry run completed", "observedAt", event.ObservedAt, "latency", latency, "event", event) + //TODO emit latency metric + return nil } diff --git a/deployment/go.mod b/deployment/go.mod index 6ed8052da22..54f75a1bbf0 100644 --- a/deployment/go.mod +++ b/deployment/go.mod @@ -41,7 +41,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/solana/deployment v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260922043016-517a12a4220e github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb github.com/smartcontractkit/chainlink-data-streams v1.1.3 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 diff --git a/deployment/go.sum b/deployment/go.sum index e006400c0cc..d0629af5562 100644 --- a/deployment/go.sum +++ b/deployment/go.sum @@ -1411,8 +1411,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.16.0 h1:WhDQEEI2Kb5A4C0PNAa+nyGLDvG0H+uT6h4y1NwmkYg= github.com/smartcontractkit/chainlink-ccv v0.16.0/go.mod h1:oaSLVHiJVbJ9aCcUQnoRuVONACWzA/DWVqvUnLAe9bE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337 h1:pD5MmKg+G52nkA4ghoVFqUtkAtZsUyGOSBY+P3JFE+M= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 h1:V+IBcXmheTxfYQb8gX/2KFjcIwiPSz6hvJ5MmOh9hjI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb h1:9rVrSeVOAwZsVe2pOpeVRp9XjhtMyjndgeROFglvOhg= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb/go.mod h1:WcOKzF6HkTDrkQ96aBHhcJ2IIYE7iK7M2tdt58ea2qc= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/go.mod b/go.mod index 8d1d041d86f..e3738e1879a 100644 --- a/go.mod +++ b/go.mod @@ -82,7 +82,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260908155618-50f521d70e62 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260908155618-50f521d70e62 github.com/smartcontractkit/chainlink-ccv v0.16.0 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 github.com/smartcontractkit/chainlink-data-streams v1.1.3 diff --git a/go.sum b/go.sum index 0c95cce576b..49f1a8f32e4 100644 --- a/go.sum +++ b/go.sum @@ -1102,8 +1102,8 @@ github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260908155618-50f521d70e62/go.mod h1:c++Ed0jeYn4w8WIfiAboRwN6ClRRVGglL0qwB/QjJvM= github.com/smartcontractkit/chainlink-ccv v0.16.0 h1:WhDQEEI2Kb5A4C0PNAa+nyGLDvG0H+uT6h4y1NwmkYg= github.com/smartcontractkit/chainlink-ccv v0.16.0/go.mod h1:oaSLVHiJVbJ9aCcUQnoRuVONACWzA/DWVqvUnLAe9bE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337 h1:pD5MmKg+G52nkA4ghoVFqUtkAtZsUyGOSBY+P3JFE+M= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 h1:V+IBcXmheTxfYQb8gX/2KFjcIwiPSz6hvJ5MmOh9hjI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb h1:9rVrSeVOAwZsVe2pOpeVRp9XjhtMyjndgeROFglvOhg= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb/go.mod h1:WcOKzF6HkTDrkQ96aBHhcJ2IIYE7iK7M2tdt58ea2qc= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index 3d19f9ed0fe..c81ab483f74 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -30,7 +30,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260922043016-517a12a4220e github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260922043016-517a12a4220e - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261112211734-e640e1c12078 diff --git a/integration-tests/go.sum b/integration-tests/go.sum index c5b5399c9fb..3e5085b8781 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1396,8 +1396,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.16.0 h1:WhDQEEI2Kb5A4C0PNAa+nyGLDvG0H+uT6h4y1NwmkYg= github.com/smartcontractkit/chainlink-ccv v0.16.0/go.mod h1:oaSLVHiJVbJ9aCcUQnoRuVONACWzA/DWVqvUnLAe9bE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337 h1:pD5MmKg+G52nkA4ghoVFqUtkAtZsUyGOSBY+P3JFE+M= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 h1:V+IBcXmheTxfYQb8gX/2KFjcIwiPSz6hvJ5MmOh9hjI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb h1:9rVrSeVOAwZsVe2pOpeVRp9XjhtMyjndgeROFglvOhg= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb/go.mod h1:WcOKzF6HkTDrkQ96aBHhcJ2IIYE7iK7M2tdt58ea2qc= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/integration-tests/load/go.mod b/integration-tests/load/go.mod index 33d0953e1ad..45f92ef98e1 100644 --- a/integration-tests/load/go.mod +++ b/integration-tests/load/go.mod @@ -20,7 +20,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260922043016-517a12a4220e github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260922043016-517a12a4220e - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261112211734-e640e1c12078 github.com/smartcontractkit/chainlink-testing-framework/framework v0.16.9 diff --git a/integration-tests/load/go.sum b/integration-tests/load/go.sum index 04d7bf8de40..c39f1ee6333 100644 --- a/integration-tests/load/go.sum +++ b/integration-tests/load/go.sum @@ -1636,8 +1636,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.16.0 h1:WhDQEEI2Kb5A4C0PNAa+nyGLDvG0H+uT6h4y1NwmkYg= github.com/smartcontractkit/chainlink-ccv v0.16.0/go.mod h1:oaSLVHiJVbJ9aCcUQnoRuVONACWzA/DWVqvUnLAe9bE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337 h1:pD5MmKg+G52nkA4ghoVFqUtkAtZsUyGOSBY+P3JFE+M= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 h1:V+IBcXmheTxfYQb8gX/2KFjcIwiPSz6hvJ5MmOh9hjI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb h1:9rVrSeVOAwZsVe2pOpeVRp9XjhtMyjndgeROFglvOhg= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb/go.mod h1:WcOKzF6HkTDrkQ96aBHhcJ2IIYE7iK7M2tdt58ea2qc= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/system-tests/lib/cre/environment/environment.go b/system-tests/lib/cre/environment/environment.go index 43b16cbfde6..e0fe5a5a420 100644 --- a/system-tests/lib/cre/environment/environment.go +++ b/system-tests/lib/cre/environment/environment.go @@ -291,49 +291,6 @@ func SetupTestEnvironment( // allow to pass custom job spec factories for extensibility jobSpecFactoryFunctions = append(jobSpecFactoryFunctions, input.JobSpecFactoryFunctions...) - // ConsensusQueue - //TODO remove - replaced by feature - //jobSpecFactoryFunctions = append(jobSpecFactoryFunctions, func(input *cre.JobSpecInput) (cre.DonJobs, error) { - // chainID, err := chainselectors.GetChainIDFromSelector(deployedBlockchains.RegistryChain().ChainSelector()) - // if err != nil { - // return nil, fmt.Errorf("failed to get chain ID from selector: %w", err) - // } - // evmChainID, err := strconv.ParseUint(chainID, 10, 64) - // if err != nil { - // return nil, fmt.Errorf("non-integer chain ID: %s: %w", chainID, err) - // } - // - // don := dons.MustWorkflowDON() - // - // bs, ok := dons.Bootstrap() - // if !ok { - // return nil, fmt.Errorf("failed to look up bootstrap node") - // } - // jobConfig := pkg.OCR3JobConfig{ - // JobName: "consensus-queue-test", - // ChainID: chainID, - // ContractID: "0x0000000000000000000000000000000000000000", // TODO - // P2Pv2Bootstrappers: []string{bs.Keys.P2PKey.PeerID.Raw() + "@" + bs.Host + ":" + strconv.Itoa(cre.OCRPeeringPort)}, - // ExternalJobID: uuid.NewV4().String(), // TODO deterministic? - // TemplateName: "consensus-queue", - // } - // - // var donJobs cre.DonJobs - // for _, node := range don.Nodes { - // jobConfig.P2PID = node.PeerID() - // jobConfig.OCR2EVMKeyBundleID = node.Keys.OCR2BundleIDs["evm"] - // jobConfig.TransmitterID = node.Keys.EVM[evmChainID].PublicAddress.String() - // - // jobSpec, err := jobConfig.ResolveJob() - // if err != nil { - // return nil, fmt.Errorf("failed to resolve OCR3 job spec: %w", err) - // } - // nodeID := node.JobDistributorDetails.NodeID - // donJobs = append(donJobs, &job.ProposeJobRequest{NodeId: nodeID, Spec: jobSpec}) - // } - // return donJobs, nil - //}) - createJobsDeps := CreateJobsWithJdOpDeps{ Logger: testLogger, SingleFileLogger: singleFileLogger, diff --git a/system-tests/lib/go.mod b/system-tests/lib/go.mod index 754057b3aeb..e43c92856e0 100644 --- a/system-tests/lib/go.mod +++ b/system-tests/lib/go.mod @@ -32,7 +32,7 @@ require ( github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-aptos v0.0.0-20260923062809-ca886ade4d26 github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260922043016-517a12a4220e - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb github.com/smartcontractkit/chainlink-confidential-compute v1.3.0 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 diff --git a/system-tests/lib/go.sum b/system-tests/lib/go.sum index e5685f2b0e1..cf457822624 100644 --- a/system-tests/lib/go.sum +++ b/system-tests/lib/go.sum @@ -1657,8 +1657,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.16.0 h1:WhDQEEI2Kb5A4C0PNAa+nyGLDvG0H+uT6h4y1NwmkYg= github.com/smartcontractkit/chainlink-ccv v0.16.0/go.mod h1:oaSLVHiJVbJ9aCcUQnoRuVONACWzA/DWVqvUnLAe9bE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337 h1:pD5MmKg+G52nkA4ghoVFqUtkAtZsUyGOSBY+P3JFE+M= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 h1:V+IBcXmheTxfYQb8gX/2KFjcIwiPSz6hvJ5MmOh9hjI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb h1:9rVrSeVOAwZsVe2pOpeVRp9XjhtMyjndgeROFglvOhg= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb/go.mod h1:WcOKzF6HkTDrkQ96aBHhcJ2IIYE7iK7M2tdt58ea2qc= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/system-tests/tests/go.mod b/system-tests/tests/go.mod index ada4371cb0c..097a1c9e70a 100644 --- a/system-tests/tests/go.mod +++ b/system-tests/tests/go.mod @@ -73,7 +73,7 @@ require ( github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-aptos v0.0.0-20260923062809-ca886ade4d26 github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260922043016-517a12a4220e - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 github.com/smartcontractkit/chainlink-confidential-compute v1.3.0 diff --git a/system-tests/tests/go.sum b/system-tests/tests/go.sum index 80afe63ceaa..6b9a4b494b3 100644 --- a/system-tests/tests/go.sum +++ b/system-tests/tests/go.sum @@ -1836,8 +1836,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.16.0 h1:WhDQEEI2Kb5A4C0PNAa+nyGLDvG0H+uT6h4y1NwmkYg= github.com/smartcontractkit/chainlink-ccv v0.16.0/go.mod h1:oaSLVHiJVbJ9aCcUQnoRuVONACWzA/DWVqvUnLAe9bE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337 h1:pD5MmKg+G52nkA4ghoVFqUtkAtZsUyGOSBY+P3JFE+M= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117161043-d7bfae650337/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 h1:V+IBcXmheTxfYQb8gX/2KFjcIwiPSz6hvJ5MmOh9hjI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb h1:9rVrSeVOAwZsVe2pOpeVRp9XjhtMyjndgeROFglvOhg= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb/go.mod h1:WcOKzF6HkTDrkQ96aBHhcJ2IIYE7iK7M2tdt58ea2qc= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= From 51c55f96fe707d2570f9eb5ab3de3175c1786d04 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Tue, 17 Nov 2026 22:45:19 -0600 Subject: [PATCH 10/13] wire trigger.Queue; implement SortedFunc & Remove --- core/services/chainlink/application.go | 1 + core/services/cre/cre.go | 41 ++++----- core/services/ocr2/delegate.go | 5 +- core/services/ocr3_1/plugins/queue/kvstate.go | 5 +- core/services/ocr3_1/plugins/queue/queue.go | 42 ++++++---- .../workflows/v2/triggers/coordinator.go | 2 + core/services/workflows/v2/triggers/queue.go | 83 +++++++++++++++++++ 7 files changed, 141 insertions(+), 38 deletions(-) diff --git a/core/services/chainlink/application.go b/core/services/chainlink/application.go index 8270739b91f..855f6313efb 100644 --- a/core/services/chainlink/application.go +++ b/core/services/chainlink/application.go @@ -842,6 +842,7 @@ func NewApplication(ctx context.Context, opts ApplicationOpts) (Application, err LimitsFactory: limitsFactory, OCRConfigService: creServices.OCRConfigService, TriggerCoordinator: creServices.TriggerCoordinator, + TriggerQueue: creServices.TriggerQueue, DefaultBootstrappers: safeDefaultBootstrappers(cfg), CapRegistryAddress: safeExternalRegistryAddress(cfg), CapRegistryChainID: safeExternalRegistryChainID(cfg), diff --git a/core/services/cre/cre.go b/core/services/cre/cre.go index 065cdbe5df8..8bff553b1eb 100644 --- a/core/services/cre/cre.go +++ b/core/services/cre/cre.go @@ -137,6 +137,8 @@ type Services struct { TriggerCoordinator triggers.Coordinator + TriggerQueue triggers.Queue + OrgResolver orgresolver.OrgResolver OCRConfigService capregconfig.OCRConfigService @@ -299,7 +301,7 @@ func (s *Services) newSubservices( wfSyncerLggr.Infof("failed to create billing client: %s", err) } - wfSyncer, triggerCoordinator, wfSyncerSrvcs, err := newWorkflowRegistrySyncerV2( + wfSyncer, triggerCoordinator, triggerQueue, wfSyncerSrvcs, err := newWorkflowRegistrySyncerV2( cfg, relayerChainInterops, billingClient, @@ -323,6 +325,7 @@ func (s *Services) newSubservices( s.BillingClient = billingClient s.WorkflowRegistrySyncer = wfSyncer s.TriggerCoordinator = triggerCoordinator + s.TriggerQueue = triggerQueue srvs = append(srvs, wfSyncerSrvcs...) return srvs, nil @@ -803,14 +806,14 @@ func newWorkflowRegistrySyncerV2( meterIdentity resourcemanager.ResourceIdentity, dispatcher remotetypes.Dispatcher, shardIndexMapper *shardownership.ShardIndexMapper, -) (syncerV2.WorkflowRegistrySyncer, triggers.Coordinator, []commonsrv.Service, error) { +) (syncerV2.WorkflowRegistrySyncer, triggers.Coordinator, triggers.Queue, []commonsrv.Service, error) { capCfg := cfg.Capabilities() wfReg := capCfg.WorkflowRegistry() key := opts.WorkflowKey fetcherFunc, retrieverFunc, srvcs, err := newFetcherServiceV2(opts, capCfg, lggr, gatewayConnectorWrapper) if err != nil { - return nil, nil, nil, err + return nil, nil, nil, nil, err } artifactsStore, err := artifactsV2.NewStore( @@ -827,29 +830,29 @@ func newWorkflowRegistrySyncerV2( }), ) if err != nil { - return nil, nil, nil, fmt.Errorf("unable to create artifact store: %w", err) + return nil, nil, nil, nil, fmt.Errorf("unable to create artifact store: %w", err) } engineRegistry := syncerV2.NewEngineRegistry() engineLimiters, err := v2.NewLimiters(lf, nil) if err != nil { - return nil, nil, nil, fmt.Errorf("could not instantiate engine limiters: %w", err) + return nil, nil, nil, nil, fmt.Errorf("could not instantiate engine limiters: %w", err) } featureFlags, err := v2.NewFeatureFlags(lf, nil) if err != nil { - return nil, nil, nil, fmt.Errorf("could not instantiate engine feature flags: %w", err) + return nil, nil, nil, nil, fmt.Errorf("could not instantiate engine feature flags: %w", err) } selector, err := chainSelector(wfReg.ChainID(), wfReg.NetworkID()) if err != nil { - return nil, nil, nil, err + return nil, nil, nil, nil, err } crFactory, err := newContractReaderFactory(capCfg, relayerChainInterops) if err != nil { - return nil, nil, nil, fmt.Errorf("failed to instantiate contract reader factory: %w", err) + return nil, nil, nil, nil, fmt.Errorf("failed to instantiate contract reader factory: %w", err) } var shardOrchestratorClient shardorchestrator.ClientInterface @@ -858,7 +861,7 @@ func newWorkflowRegistrySyncerV2( } else { c, clientErr := newShardOrchestratorClient(cfg, lggr) if clientErr != nil { - return nil, nil, nil, clientErr + return nil, nil, nil, nil, clientErr } if c != nil { shardOrchestratorClient = c @@ -905,15 +908,15 @@ func newWorkflowRegistrySyncerV2( coordinatorMetrics, err := wfmonitoring.InitMonitoringResources() if err != nil { - return nil, nil, nil, fmt.Errorf("unable to init trigger coordinator metrics: %w", err) + return nil, nil, nil, nil, fmt.Errorf("unable to init trigger coordinator metrics: %w", err) } centralQueueMetrics, err := wfmonitoring.InitCentralTriggerQueueMetrics() if err != nil { - return nil, nil, nil, fmt.Errorf("unable to init central trigger queue metrics: %w", err) + return nil, nil, nil, nil, fmt.Errorf("unable to init central trigger queue metrics: %w", err) } drainerMetrics, err := wfmonitoring.InitTriggerDrainerMetrics() if err != nil { - return nil, nil, nil, fmt.Errorf("unable to init central trigger queue drainer metrics: %w", err) + return nil, nil, nil, nil, fmt.Errorf("unable to init central trigger queue drainer metrics: %w", err) } coordinatorClock := clockwork.NewRealClock() @@ -974,7 +977,7 @@ func newWorkflowRegistrySyncerV2( }) specMeter, smErr := syncerV2.NewSpecMeter(lggr, rm, meterIdentity, artifactsStore, orgResolver) if smErr != nil { - return nil, nil, nil, fmt.Errorf("unable to create workflow spec meter: %w", smErr) + return nil, nil, nil, nil, fmt.Errorf("unable to create workflow spec meter: %w", smErr) } handlerOpts = append(handlerOpts, syncerV2.WithSpecMeter(specMeter)) } @@ -995,7 +998,7 @@ func newWorkflowRegistrySyncerV2( if diskMonitorEnabled { fileStore, fsErr := artifactsV2.NewFileModuleStore(mc.CacheDir(), cacheEnabled) if fsErr != nil { - return nil, nil, nil, fmt.Errorf("unable to create file module store: %w", fsErr) + return nil, nil, nil, nil, fmt.Errorf("unable to create file module store: %w", fsErr) } dm, dmErr := syncerV2.NewWorkflowModuleCacheDiskMonitor( @@ -1004,7 +1007,7 @@ func newWorkflowRegistrySyncerV2( syncerV2.WorkflowModuleCacheDiskMonitorTickInterval, ) if dmErr != nil { - return nil, nil, nil, fmt.Errorf("unable to create module cache disk monitor: %w", dmErr) + return nil, nil, nil, nil, fmt.Errorf("unable to create module cache disk monitor: %w", dmErr) } srvcs = append(srvcs, dm) @@ -1013,7 +1016,7 @@ func newWorkflowRegistrySyncerV2( if cacheEnabled { cm, cmErr := syncerV2.NewCacheMetrics() if cmErr != nil { - return nil, nil, nil, fmt.Errorf("unable to create module cache metrics: %w", cmErr) + return nil, nil, nil, nil, fmt.Errorf("unable to create module cache metrics: %w", cmErr) } var idleTimeout time.Duration @@ -1063,7 +1066,7 @@ func newWorkflowRegistrySyncerV2( handlerOpts..., ) if err != nil { - return nil, nil, nil, fmt.Errorf("unable to create workflow registry event handler: %w", err) + return nil, nil, nil, nil, fmt.Errorf("unable to create workflow registry event handler: %w", err) } addSources := wfReg.AdditionalSources() @@ -1116,12 +1119,12 @@ func newWorkflowRegistrySyncerV2( registryOpts..., ) if err != nil { - return nil, nil, nil, fmt.Errorf("unable to create workflow registry syncer: %w", err) + return nil, nil, nil, nil, fmt.Errorf("unable to create workflow registry syncer: %w", err) } srvcs = append(srvcs, workflowRegistrySyncerV2) lggr.Debugw("Created WorkflowRegistrySyncer V2") - return workflowRegistrySyncerV2, triggerCoordinator, srvcs, nil + return workflowRegistrySyncerV2, triggerCoordinator, centralQueue, srvcs, nil } // NewServices creates and initializes all CRE services diff --git a/core/services/ocr2/delegate.go b/core/services/ocr2/delegate.go index eee9f2a56c7..3f55eee07b8 100644 --- a/core/services/ocr2/delegate.go +++ b/core/services/ocr2/delegate.go @@ -160,6 +160,7 @@ type Delegate struct { limitsFactory limits.Factory ocrConfigService capregconfig.OCRConfigService triggerCoordinator triggers.Coordinator + triggerQueue triggers.Queue // Registry-driven launch support: when the delegate is used via // LocalCapabilityManager (no job spec), these fields provide the @@ -314,6 +315,7 @@ type DelegateOpts struct { LimitsFactory limits.Factory OCRConfigService capregconfig.OCRConfigService TriggerCoordinator triggers.Coordinator + TriggerQueue triggers.Queue // Registry-driven launch support: defaults for capabilities launched // via LocalCapabilityManager (no job spec). @@ -364,6 +366,7 @@ func NewDelegate( limitsFactory: opts.LimitsFactory, ocrConfigService: opts.OCRConfigService, triggerCoordinator: opts.TriggerCoordinator, + triggerQueue: opts.TriggerQueue, defaultBootstrappers: opts.DefaultBootstrappers, capRegistryAddress: opts.CapRegistryAddress, capRegistryChainID: opts.CapRegistryChainID, @@ -912,7 +915,7 @@ func (d *Delegate) newServicesConsensusQueue( MetricsRegisterer: prometheus.WrapRegistererWith(map[string]string{"job_name": jb.Name.ValueOrZero()}, prometheus.DefaultRegisterer), } - rpf, err := queue.NewConsensusQueuePluginFactory(lggr, cfg, d.limitsFactory, d.triggerCoordinator) + rpf, err := queue.NewConsensusQueuePluginFactory(lggr, cfg, d.limitsFactory, d.triggerCoordinator, d.triggerQueue) if err != nil { return nil, err } diff --git a/core/services/ocr3_1/plugins/queue/kvstate.go b/core/services/ocr3_1/plugins/queue/kvstate.go index 0344ed52ddd..25dcddd18c9 100644 --- a/core/services/ocr3_1/plugins/queue/kvstate.go +++ b/core/services/ocr3_1/plugins/queue/kvstate.go @@ -28,10 +28,6 @@ const ( blobHandlesKey = "blob_handles::index" // pb.ConsensusQueueBlobHandleList{ [][]byte } ) -type stateReader struct { - kv ocr3_1types.KeyValueStateReader -} - type stateWriter struct { kv ocr3_1types.KeyValueStateReadWriter } @@ -243,6 +239,7 @@ func (s *kvState) prepareWrite() { s.observedBlobHandles = nil observedBlobIndexes := make(map[string]int) s.observedEventEntries = nil + //TODO deadline order so that we can drop efficiently for _, eventHash := range slices.Sorted(maps.Keys(s.observedEvents)) { event := s.observedEvents[eventHash] event.Blobs = nil // replace all diff --git a/core/services/ocr3_1/plugins/queue/queue.go b/core/services/ocr3_1/plugins/queue/queue.go index 4f1d02f6d95..06040b1a131 100644 --- a/core/services/ocr3_1/plugins/queue/queue.go +++ b/core/services/ocr3_1/plugins/queue/queue.go @@ -2,6 +2,7 @@ package queue import ( "bytes" + "cmp" "context" "crypto/sha256" "errors" @@ -36,14 +37,22 @@ type consensusQueuePluginFactory struct { lggr logger.Logger cfg *PluginConfig triggerCoordinator triggers.Coordinator + triggerQueue triggers.Queue expirationDur func(context.Context) (time.Duration, error) } -func NewConsensusQueuePluginFactory(lggr logger.Logger, cfg *PluginConfig, limitsFactory limits.Factory, triggerCoordinator triggers.Coordinator) (ocr3_1types.ReportingPluginFactory[[]byte], error) { +func NewConsensusQueuePluginFactory( + lggr logger.Logger, + cfg *PluginConfig, + limitsFactory limits.Factory, + triggerCoordinator triggers.Coordinator, + triggerQueue triggers.Queue, +) (ocr3_1types.ReportingPluginFactory[[]byte], error) { return &consensusQueuePluginFactory{ lggr: lggr, cfg: cfg, triggerCoordinator: triggerCoordinator, + triggerQueue: triggerQueue, expirationDur: func(ctx context.Context) (time.Duration, error) { //TODO also allow this grace period in the trigger coordinator return cresettings.Default.ConsensusQueueExpirationInterval.GetOrDefault(ctx, limitsFactory.Settings) @@ -52,7 +61,7 @@ func NewConsensusQueuePluginFactory(lggr logger.Logger, cfg *PluginConfig, limit } func (c *consensusQueuePluginFactory) NewReportingPlugin(ctx context.Context, config ocr3types.ReportingPluginConfig, blobs ocr3_1types.BlobBroadcastFetcher) (ocr3_1types.ReportingPlugin[[]byte], ocr3_1types.ReportingPluginInfo, error) { - plugin := newConsensusQueuePlugin(c.lggr, config, c.triggerCoordinator, c.expirationDur, blobs) + plugin := newConsensusQueuePlugin(c.lggr, config, c.triggerCoordinator, c.triggerQueue, c.expirationDur, blobs) pluginInfo := ocr3_1types.ReportingPluginInfo1{ Name: "ConsensusQueueReportingPlugin", Limits: c.cfg.Limits, @@ -69,19 +78,22 @@ type consensusQueuePlugin struct { onchainCfg ocr3types.ReportingPluginConfig blobHandleMarshalledBytesUpperBound int triggerCoordinator triggers.Coordinator + triggerQueue triggers.Queue blobBroadcastFetcher ocr3_1types.BlobBroadcastFetcher expirationDur func(context.Context) (time.Duration, error) } func newConsensusQueuePlugin( lggr logger.Logger, onchainCfg ocr3types.ReportingPluginConfig, triggerCoordinator triggers.Coordinator, - expirationGraceDur func(context.Context) (time.Duration, error), blobs ocr3_1types.BlobBroadcastFetcher, + triggerQueue triggers.Queue, expirationGraceDur func(context.Context) (time.Duration, error), + blobs ocr3_1types.BlobBroadcastFetcher, ) *consensusQueuePlugin { c := &consensusQueuePlugin{ lggr: logger.Named(lggr, "ConsensusQueuePlugin"), onchainCfg: onchainCfg, blobHandleMarshalledBytesUpperBound: ocr3_1types.BlobHandleMarshalledBytesUpperBound(onchainCfg.F, onchainCfg.N), triggerCoordinator: triggerCoordinator, + triggerQueue: triggerQueue, blobBroadcastFetcher: blobs, expirationDur: expirationGraceDur, } @@ -126,19 +138,18 @@ func (c *consensusQueuePlugin) Observation( obs.WorkflowCapacities[wf] = uint32(min(wfCap, math.MaxUint32)) } - var events iter.Seq[*triggers.CoordinatedEvent] - //TODO events iter from triggerCoordinator, to be acked later during StateTransition - observedEvents, _, err := readObservedEvents(kvReader) if err != nil { return nil, err } protoOpts := proto.MarshalOptions{Deterministic: true} - var coordEvents []*pb.CoordinatedEvent - for coord := range toProtoSeq(events) { - // Try adding to batch + // Assemble an observation up to maxObservationBytes + var coordEvents []*pb.CoordinatedEvent + for coord := range toProtoSeq(c.triggerQueue.SortedFunc(func(a, b triggers.CoordinatedEvent) int { + return cmp.Or(a.Deadline.Compare(b.Deadline), cmp.Compare(a.Event.Event.ID, b.Event.Event.ID)) + })) { observedAt, deadline := coord.ObservedAt, coord.Deadline coord.ObservedAt, coord.Deadline = nil, nil // for consistent hashing protoBytes, err2 := protoOpts.Marshal(coord) // TODO opt: avoid remarshalling @@ -216,7 +227,7 @@ func (c *consensusQueuePlugin) Observation( return protoOpts.Marshal(obs) } -func toProtoSeq(in iter.Seq[*triggers.CoordinatedEvent]) iter.Seq[*pb.CoordinatedEvent] { +func toProtoSeq(in iter.Seq[triggers.CoordinatedEvent]) iter.Seq[*pb.CoordinatedEvent] { return func(yield func(*pb.CoordinatedEvent) bool) { for event := range in { if !yield(event.ToProto()) { @@ -362,9 +373,9 @@ func (c *consensusQueuePlugin) StateTransition( // update state state.pruneExpiredObservations(obs.medianExpiration) - //TODO must not promote to PQ and ack until we are sure we can write the kv - state.addObservedEvents(c.onchainCfg.F, obs.newObservedEvents, obs.observedBlobs, func(queued *pb.ConsensusQueueEvent) { - //TODO ack the trigger coordinator - no longer need to observe this event + var queuedTriggerEventIDs []string // to be removed from the trigger.Queue + state.addObservedEvents(c.onchainCfg.F, obs.newObservedEvents, obs.observedBlobs, func(event *pb.ConsensusQueueEvent) { + queuedTriggerEventIDs = append(queuedTriggerEventIDs, event.TriggerEventID) }) state.consensusEvents = state.queuedEvents.popLimited(obs.medianCap, obs.medianCapPerWF, obs.medianExpiration) @@ -372,12 +383,14 @@ func (c *consensusQueuePlugin) StateTransition( for state.sizeOf() > maxKeyValueModifiedKeysPlusValuesBytes { //TODO drop observations (must be deterministic, fair, efficient) // prefer farthest future deadlines and fewest observations + //TODO use sorted state.observedEventEntries } err = state.writeTo(&stateWriter{kv: kvReaderWriter}) if err != nil { return nil, err } + c.triggerQueue.Remove(ctx, queuedTriggerEventIDs) // no report to return, executions start when committed return nil, nil @@ -436,6 +449,7 @@ func (res *observations) aggregate(ctx context.Context, f int, aos []ocrtypes.At return } +// addEvent adds the observed event to the observation set, either merging it into an existing event or creating a new one. func (res *observations) addEvent(obs commontypes.OracleID, event *pb.ConsensusQueueEvent, blobHandles [][]byte) { res.observedBlobs.add(string(event.TimelessHash), string(blobHandles[event.Blobs[0].Blob]), event.Blobs[0].Element) aggregated, ok := res.newObservedEvents[string(event.TimelessHash)] @@ -518,7 +532,7 @@ func (c *consensusQueuePlugin) tryStartExecution(ctx context.Context, fetcher *b return fmt.Errorf("failed to convert CoordinatedEvent from proto: %w", err) } - // TODO c.triggerCoordinator.tryStartExecution(ctx, event) + // TODO c.triggerCoordinator.Deliver(ctx, event) // only log metadata, not outputs and payload event.Event.Event.Outputs = nil diff --git a/core/services/workflows/v2/triggers/coordinator.go b/core/services/workflows/v2/triggers/coordinator.go index 02ecf62a528..27a7691ac74 100644 --- a/core/services/workflows/v2/triggers/coordinator.go +++ b/core/services/workflows/v2/triggers/coordinator.go @@ -83,6 +83,8 @@ type Coordinator interface { // Returns ErrCapacityNotSupported if the shared ExecutionConcurrency // limiter does not break down by scope. AvailableCapacity(ctx context.Context) (Capacity, error) + + //TODO Deliver(context.Context, CoordinatedEvent } // RegisteredEngine is what EngineRegistry.Get returns: a sink the coordinator diff --git a/core/services/workflows/v2/triggers/queue.go b/core/services/workflows/v2/triggers/queue.go index cfa3d0089cd..e7b85e8fafc 100644 --- a/core/services/workflows/v2/triggers/queue.go +++ b/core/services/workflows/v2/triggers/queue.go @@ -1,9 +1,12 @@ package triggers import ( + "container/heap" "context" "errors" + "iter" "maps" + "slices" "sync" "github.com/smartcontractkit/chainlink-common/pkg/logger" @@ -29,6 +32,13 @@ type Queue interface { // Stats reports current length, capacity, and cumulative drops. Stats(context.Context) (Stats, error) + + // SortedFunc returns an iterator over all events sorted with cmp. + // It does not drain the queue. Events remain but can be removed via Remove. + SortedFunc(cmp func(a, b CoordinatedEvent) int) iter.Seq[CoordinatedEvent] + + // Remove removes events from the queue. + Remove(ctx context.Context, triggerEventIDs []string) } // Stats is a point-in-time view of a Queue. @@ -113,6 +123,79 @@ func (q *CentralQueue) Drain(ctx context.Context) ([]CoordinatedEvent, error) { return events, nil } +func (q *CentralQueue) Remove(ctx context.Context, triggerEventIDs []string) { + triggerEventIDSet := map[string]struct{}{} + for _, triggerEventID := range triggerEventIDs { + triggerEventIDSet[triggerEventID] = struct{}{} + } + + capacity := q.capacity(ctx) + + q.mu.Lock() + defer q.mu.Unlock() + + var deleted int + q.events = slices.DeleteFunc(q.events, func(e CoordinatedEvent) bool { + _, ok := triggerEventIDSet[e.Event.Event.ID] + if ok { + deleted++ + q.depthByWorkflow[e.WorkflowID]-- + q.depthByTriggerType[e.TriggerCapID]-- + } + return ok + }) + q.metrics.IncrementDrainedEventsCounter(ctx, deleted) + q.metrics.RecordDepth(ctx, len(q.events)) + q.metrics.RecordCapacity(ctx, q.effectiveCapacity(capacity)) + return +} + +// SortedFunc returns an iterator over all events sorted by cmp. +func (q *CentralQueue) SortedFunc(cmp func(a, b CoordinatedEvent) int) iter.Seq[CoordinatedEvent] { + q.mu.Lock() + events := slices.Clone(q.events) + q.mu.Unlock() + + eventHeap := &coordinatedEventHeap{events: events, cmp: cmp} + heap.Init(eventHeap) + + return func(yield func(CoordinatedEvent) bool) { + for eventHeap.Len() > 0 { + if !yield(eventHeap.events[0]) { + return + } + heap.Pop(eventHeap) + } + } +} + +type coordinatedEventHeap struct { + events []CoordinatedEvent + cmp func(a, b CoordinatedEvent) int +} + +func (c *coordinatedEventHeap) Len() int { + return len(c.events) +} + +func (c *coordinatedEventHeap) Less(i, j int) bool { + return c.cmp(c.events[i], c.events[j]) < 0 +} + +func (c *coordinatedEventHeap) Swap(i, j int) { + c.events[i], c.events[j] = c.events[j], c.events[i] +} + +func (c *coordinatedEventHeap) Push(x any) { + c.events = append(c.events, x.(CoordinatedEvent)) +} + +func (c *coordinatedEventHeap) Pop() any { + e := c.events[len(c.events)-1] + c.events = c.events[:len(c.events)-1] + return e +} + // Stats returns copies of the queue's maps, so callers may keep or change them. func (q *CentralQueue) Stats(ctx context.Context) (Stats, error) { capacity := q.capacity(ctx) From e7bc3da5351fbe70e4c9664055e3db089f76d6a6 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Wed, 18 Nov 2026 08:48:35 -0600 Subject: [PATCH 11/13] docs --- core/services/ocr3_1/plugins/queue/kvstate.go | 2 +- core/services/ocr3_1/plugins/queue/queue.go | 6 ++++++ core/services/workflows/v2/triggers/queue.go | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/services/ocr3_1/plugins/queue/kvstate.go b/core/services/ocr3_1/plugins/queue/kvstate.go index 25dcddd18c9..63119c41987 100644 --- a/core/services/ocr3_1/plugins/queue/kvstate.go +++ b/core/services/ocr3_1/plugins/queue/kvstate.go @@ -42,7 +42,7 @@ func (s *stateWriter) writeValue[M proto.Message](key string, m M) error { var _ heap.Interface = (*priorityQueue)(nil) -// priorityQueue is a heap of coordinated events, ordered by deadline and then event ID. +// priorityQueue is a heap of coordinated events, ordered by deadline and then trigger event ID. type priorityQueue []*pb.ConsensusQueueEvent func (p *priorityQueue) Len() int { return len(*p) } diff --git a/core/services/ocr3_1/plugins/queue/queue.go b/core/services/ocr3_1/plugins/queue/queue.go index 06040b1a131..8b045d6cfe3 100644 --- a/core/services/ocr3_1/plugins/queue/queue.go +++ b/core/services/ocr3_1/plugins/queue/queue.go @@ -1,3 +1,9 @@ +// Package queue contains the consensus queue OCR 3.1 reporting plugin, for coordinating execution of triggered events. +// Each node has a local [triggers.Queue] of [triggers.CoordinatedEvent], which are observed (and broadcast) by the plugin. +// When consensus is reached, events are put in to the KeyValueState priority queue (and removed from the [triggers.Queue]). +// The priority queue is ordered by deadline (with nanosecond precision) and then by trigger event ID. +// Each round, as many events as possible are popped from the priority queue and then (fetched and) executed via [triggers.Coordinator.Deliver]. +// Capacity, both overall and per-workflow, limits what may execute. Capacities are observed and medianized. package queue import ( diff --git a/core/services/workflows/v2/triggers/queue.go b/core/services/workflows/v2/triggers/queue.go index e7b85e8fafc..08f1c0a6505 100644 --- a/core/services/workflows/v2/triggers/queue.go +++ b/core/services/workflows/v2/triggers/queue.go @@ -141,6 +141,7 @@ func (q *CentralQueue) Remove(ctx context.Context, triggerEventIDs []string) { deleted++ q.depthByWorkflow[e.WorkflowID]-- q.depthByTriggerType[e.TriggerCapID]-- + //TODO emit metric for time.Since(e.ObservedAt) } return ok }) From 0fcadd79099157f0b35cd7b843a8821428a194db Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Wed, 18 Nov 2026 09:17:15 -0600 Subject: [PATCH 12/13] CompareDeadline methods and cleanup --- core/scripts/go.mod | 2 +- core/scripts/go.sum | 4 +- core/services/ocr3_1/plugins/queue/kvstate.go | 9 +- core/services/ocr3_1/plugins/queue/queue.go | 7 +- .../ocr3_1/plugins/queue/queue_test.go | 2 +- .../v2/triggers/coordinator_shadow_test.go | 7 ++ .../workflows/v2/triggers/drainer_test.go | 82 +++++++++++++------ core/services/workflows/v2/triggers/queue.go | 28 +++---- .../workflows/v2/triggers/triggers.go | 5 ++ deployment/go.mod | 2 +- deployment/go.sum | 4 +- go.mod | 2 +- go.sum | 4 +- integration-tests/go.mod | 2 +- integration-tests/go.sum | 4 +- integration-tests/load/go.mod | 2 +- integration-tests/load/go.sum | 4 +- system-tests/lib/go.mod | 2 +- system-tests/lib/go.sum | 4 +- system-tests/tests/go.mod | 2 +- system-tests/tests/go.sum | 4 +- 21 files changed, 108 insertions(+), 74 deletions(-) diff --git a/core/scripts/go.mod b/core/scripts/go.mod index b1bee600bdd..c394aed57b8 100644 --- a/core/scripts/go.mod +++ b/core/scripts/go.mod @@ -29,7 +29,7 @@ require ( github.com/shopspring/decimal v1.4.0 github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261112211734-e640e1c12078 diff --git a/core/scripts/go.sum b/core/scripts/go.sum index fddbfc28b6b..a6f2331b734 100644 --- a/core/scripts/go.sum +++ b/core/scripts/go.sum @@ -1686,8 +1686,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.16.0 h1:WhDQEEI2Kb5A4C0PNAa+nyGLDvG0H+uT6h4y1NwmkYg= github.com/smartcontractkit/chainlink-ccv v0.16.0/go.mod h1:oaSLVHiJVbJ9aCcUQnoRuVONACWzA/DWVqvUnLAe9bE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 h1:V+IBcXmheTxfYQb8gX/2KFjcIwiPSz6hvJ5MmOh9hjI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087 h1:QQpXxddXoJi7b200xLaTI8yO8iKOukebi8WctQotQmY= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb h1:9rVrSeVOAwZsVe2pOpeVRp9XjhtMyjndgeROFglvOhg= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb/go.mod h1:WcOKzF6HkTDrkQ96aBHhcJ2IIYE7iK7M2tdt58ea2qc= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/core/services/ocr3_1/plugins/queue/kvstate.go b/core/services/ocr3_1/plugins/queue/kvstate.go index 63119c41987..8354cd96ff0 100644 --- a/core/services/ocr3_1/plugins/queue/kvstate.go +++ b/core/services/ocr3_1/plugins/queue/kvstate.go @@ -1,7 +1,6 @@ package queue import ( - "cmp" "container/heap" "fmt" "maps" @@ -49,13 +48,7 @@ func (p *priorityQueue) Len() int { return len(*p) } func (p *priorityQueue) Less(i, j int) bool { a, b := (*p)[i], (*p)[j] - return cmpConsensusQueueEvents(a, b) < 0 -} - -func cmpConsensusQueueEvents(a, b *pb.ConsensusQueueEvent) int { - return cmp.Or(cmp.Compare(a.Deadline.Seconds, b.Deadline.Seconds), - cmp.Compare(a.Deadline.Nanos, b.Deadline.Nanos), - cmp.Compare(a.TriggerEventID, b.TriggerEventID)) + return a.CompareDeadline(b) < 0 } func (p *priorityQueue) Swap(i, j int) { diff --git a/core/services/ocr3_1/plugins/queue/queue.go b/core/services/ocr3_1/plugins/queue/queue.go index 8b045d6cfe3..04c9676021a 100644 --- a/core/services/ocr3_1/plugins/queue/queue.go +++ b/core/services/ocr3_1/plugins/queue/queue.go @@ -8,7 +8,6 @@ package queue import ( "bytes" - "cmp" "context" "crypto/sha256" "errors" @@ -153,9 +152,7 @@ func (c *consensusQueuePlugin) Observation( // Assemble an observation up to maxObservationBytes var coordEvents []*pb.CoordinatedEvent - for coord := range toProtoSeq(c.triggerQueue.SortedFunc(func(a, b triggers.CoordinatedEvent) int { - return cmp.Or(a.Deadline.Compare(b.Deadline), cmp.Compare(a.Event.Event.ID, b.Event.Event.ID)) - })) { + for coord := range toProtoSeq(c.triggerQueue.Sorted()) { observedAt, deadline := coord.ObservedAt, coord.Deadline coord.ObservedAt, coord.Deadline = nil, nil // for consistent hashing protoBytes, err2 := protoOpts.Marshal(coord) // TODO opt: avoid remarshalling @@ -263,7 +260,7 @@ func (c *consensusQueuePlugin) ValidateObservation( if len(obs.Events) > maxObservedEvents { return fmt.Errorf("events are limited to %d but got %d", maxObservedEvents, len(obs.Events)) } - if !slices.IsSortedFunc(obs.Events, cmpConsensusQueueEvents) { + if !slices.IsSortedFunc(obs.Events, (*pb.ConsensusQueueEvent).CompareDeadline) { return fmt.Errorf("events must be sorted") } var eg errgroup.Group diff --git a/core/services/ocr3_1/plugins/queue/queue_test.go b/core/services/ocr3_1/plugins/queue/queue_test.go index c986ab517ac..5f5173eca06 100644 --- a/core/services/ocr3_1/plugins/queue/queue_test.go +++ b/core/services/ocr3_1/plugins/queue/queue_test.go @@ -18,7 +18,7 @@ func TestConsensusQueuePluginFactory_NewReportingPlugin(t *testing.T) { t.Parallel() cfg := &PluginConfig{Limits: ocr3_1types.ReportingPluginLimits{MaxKeyValueModifiedKeys: 1}} - factory, err := NewConsensusQueuePluginFactory(logger.Test(t), cfg, limits.Factory{}, nil) + factory, err := NewConsensusQueuePluginFactory(logger.Test(t), cfg, limits.Factory{}, nil, nil) require.NoError(t, err) plugin, info, err := factory.NewReportingPlugin(t.Context(), ocr3types.ReportingPluginConfig{N: 4, F: 1}, nil) diff --git a/core/services/workflows/v2/triggers/coordinator_shadow_test.go b/core/services/workflows/v2/triggers/coordinator_shadow_test.go index a05d1c804c7..960ec5e8e73 100644 --- a/core/services/workflows/v2/triggers/coordinator_shadow_test.go +++ b/core/services/workflows/v2/triggers/coordinator_shadow_test.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "iter" "strings" "sync" "sync/atomic" @@ -333,6 +334,12 @@ type failingQueue struct { puts atomic.Int32 } +func (q *failingQueue) Sorted() iter.Seq[CoordinatedEvent] { + return func(yield func(CoordinatedEvent) bool) {} +} + +func (q *failingQueue) Remove(ctx context.Context, triggerEventIDs []string) {} + func (q *failingQueue) Put(context.Context, CoordinatedEvent) error { q.puts.Add(1) return errors.New("boom") diff --git a/core/services/workflows/v2/triggers/drainer_test.go b/core/services/workflows/v2/triggers/drainer_test.go index c499af946b7..03c6f990094 100644 --- a/core/services/workflows/v2/triggers/drainer_test.go +++ b/core/services/workflows/v2/triggers/drainer_test.go @@ -1,8 +1,11 @@ package triggers import ( + "container/heap" "context" "errors" + "iter" + "slices" "sync" "sync/atomic" "testing" @@ -53,9 +56,42 @@ func findMetric(t *testing.T, reader *sdkmetric.ManualReader, name string) *metr // fakeQueue is a minimal Queue whose Observe pops a scripted sequence of // results and counts calls. Once the script is exhausted it returns empty. type fakeQueue struct { - mu sync.Mutex - results []observeResult - calls int + mu sync.Mutex + results []*observeResult + drainCalls int +} + +func (q *fakeQueue) Sorted() iter.Seq[CoordinatedEvent] { + q.mu.Lock() + events := slices.Clone(q.results[0].events) + q.mu.Unlock() + + eventHeap := new(coordinatedEventHeap(events)) + heap.Init(eventHeap) + return func(yield func(CoordinatedEvent) bool) { + for eventHeap.Len() > 0 { + e := heap.Pop(eventHeap).(CoordinatedEvent) + if !yield(e) { + return + } + } + } +} + +func (q *fakeQueue) Remove(ctx context.Context, triggerEventIDs []string) { + triggerEventIDSet := map[string]struct{}{} + for _, triggerEventID := range triggerEventIDs { + triggerEventIDSet[triggerEventID] = struct{}{} + } + q.mu.Lock() + defer q.mu.Unlock() + for _, r := range q.results { + r.events = slices.DeleteFunc(r.events, func(e CoordinatedEvent) bool { + _, ok := triggerEventIDSet[e.Event.Event.ID] + return ok + }) + // note: empty results remain + } } type observeResult struct { @@ -70,7 +106,7 @@ func (q *fakeQueue) Stats(context.Context) (Stats, error) { return Stats{}, nil func (q *fakeQueue) Drain(context.Context) ([]CoordinatedEvent, error) { q.mu.Lock() defer q.mu.Unlock() - q.calls++ + q.drainCalls++ if len(q.results) == 0 { return nil, nil } @@ -79,10 +115,10 @@ func (q *fakeQueue) Drain(context.Context) ([]CoordinatedEvent, error) { return r.events, r.err } -func (q *fakeQueue) observeCalls() int { +func (q *fakeQueue) getDrainCalls() int { q.mu.Lock() defer q.mu.Unlock() - return q.calls + return q.drainCalls } func (q *fakeQueue) remaining() int { @@ -115,25 +151,25 @@ func TestDrainer_Drain(t *testing.T) { tests := []struct { name string - results []observeResult // one per drain call + results []*observeResult // one per drain call want [][]CoordinatedEvent }{ { name: "queues an observed batch", - results: []observeResult{{events: batchOf("a")}}, + results: []*observeResult{{events: batchOf("a")}}, want: [][]CoordinatedEvent{batchOf("a")}, }, { name: "empty observe queues nothing", - results: []observeResult{{}}, + results: []*observeResult{{}}, }, { name: "observe error queues nothing, even with events", - results: []observeResult{{events: batchOf("ignored"), err: errors.New("boom")}}, + results: []*observeResult{{events: batchOf("ignored"), err: errors.New("boom")}}, }, { name: "full buffer drops the overflow and keeps the oldest", - results: []observeResult{{events: batchOf("a")}, {events: batchOf("b")}}, + results: []*observeResult{{events: batchOf("a")}, {events: batchOf("b")}}, want: [][]CoordinatedEvent{batchOf("a")}, }, } @@ -151,7 +187,7 @@ func TestDrainer_Drain(t *testing.T) { d.drain(t.Context()) // must return even when the buffer is full } - assert.Equal(t, len(tt.results), q.observeCalls(), "one Observe per drain") + assert.Equal(t, len(tt.results), q.getDrainCalls(), "one Observe per drain") assert.Equal(t, tt.want, queued(d)) assert.False(t, hookCalled.Load(), "drain never calls the hook itself; only the worker does") }) @@ -164,7 +200,7 @@ func TestDrainer_DroppedEventsMetric(t *testing.T) { t.Parallel() dm, reader := testDrainerMetrics(t) - q := &fakeQueue{results: []observeResult{ + q := &fakeQueue{results: []*observeResult{ {events: batchOf("a")}, {events: append(batchOf("b"), batchOf("c")...)}, // dropped: the buffer holds "a" }} @@ -188,7 +224,7 @@ func TestDrainer_HookDurationMetric(t *testing.T) { t.Parallel() dm, reader := testDrainerMetrics(t) - q := &fakeQueue{results: []observeResult{{events: batchOf("a")}}} + q := &fakeQueue{results: []*observeResult{{events: batchOf("a")}}} d := NewDrainer(q, limits.NewUpperBoundLimiter(minDrainInterval), drainerHooks{}, dm, clockwork.NewRealClock(), logger.Test(t)) require.NoError(t, d.Start(t.Context())) t.Cleanup(func() { assert.NoError(t, d.Close()) }) @@ -209,17 +245,17 @@ func TestDrainer_Running(t *testing.T) { tests := []struct { name string - results []observeResult + results []*observeResult want []string // workflow IDs the hook should see }{ { name: "hook receives an observed batch", - results: []observeResult{{events: batchOf("a")}}, + results: []*observeResult{{events: batchOf("a")}}, want: []string{"a"}, }, { name: "loop survives an observe error", - results: []observeResult{{err: errors.New("boom")}, {events: batchOf("a")}}, + results: []*observeResult{{err: errors.New("boom")}, {events: batchOf("a")}}, want: []string{"a"}, }, } @@ -269,9 +305,9 @@ func TestDrainer_BlockedHook(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Parallel() - results := make([]observeResult, tt.batches) + results := make([]*observeResult, tt.batches) for i := range results { - results[i] = observeResult{events: batchOf("x")} + results[i] = &observeResult{events: batchOf("x")} } q := &fakeQueue{results: results} @@ -349,12 +385,12 @@ func TestDrainer_IntervalReRead(t *testing.T) { drainsAfter := func(wait time.Duration) { t.Helper() waiting() - before := q.observeCalls() + before := q.getDrainCalls() clock.Advance(wait - time.Millisecond) - assert.Never(t, func() bool { return q.observeCalls() > before }, 50*time.Millisecond, 5*time.Millisecond, + assert.Never(t, func() bool { return q.getDrainCalls() > before }, 50*time.Millisecond, 5*time.Millisecond, "drained before %s", wait) clock.Advance(time.Millisecond) - require.Eventually(t, func() bool { return q.observeCalls() == before+1 }, 5*time.Second, 5*time.Millisecond, + require.Eventually(t, func() bool { return q.getDrainCalls() == before+1 }, 5*time.Second, 5*time.Millisecond, "no drain at %s", wait) } @@ -390,7 +426,7 @@ func TestNewCentralQueueDrainer_LogsDrainedEvents(t *testing.T) { t.Parallel() clock := clockwork.NewFakeClock() batch := append(append(batchOf("wf-a"), batchOf("wf-b")...), batchOf("wf-a")...) - q := &fakeQueue{results: []observeResult{{events: batch}}} + q := &fakeQueue{results: []*observeResult{{events: batch}}} dm, _ := testDrainerMetrics(t) lggr, logs := logger.TestObserved(t, zapcore.DebugLevel) d := NewCentralQueueDrainer(q, limits.NewUpperBoundLimiter(minDrainInterval), dm, clock, lggr) diff --git a/core/services/workflows/v2/triggers/queue.go b/core/services/workflows/v2/triggers/queue.go index 08f1c0a6505..a8f9585ef0f 100644 --- a/core/services/workflows/v2/triggers/queue.go +++ b/core/services/workflows/v2/triggers/queue.go @@ -33,9 +33,9 @@ type Queue interface { // Stats reports current length, capacity, and cumulative drops. Stats(context.Context) (Stats, error) - // SortedFunc returns an iterator over all events sorted with cmp. + // Sorted returns an iterator over all events, ordered by deadline and then trigger event ID. // It does not drain the queue. Events remain but can be removed via Remove. - SortedFunc(cmp func(a, b CoordinatedEvent) int) iter.Seq[CoordinatedEvent] + Sorted() iter.Seq[CoordinatedEvent] // Remove removes events from the queue. Remove(ctx context.Context, triggerEventIDs []string) @@ -151,18 +151,17 @@ func (q *CentralQueue) Remove(ctx context.Context, triggerEventIDs []string) { return } -// SortedFunc returns an iterator over all events sorted by cmp. -func (q *CentralQueue) SortedFunc(cmp func(a, b CoordinatedEvent) int) iter.Seq[CoordinatedEvent] { +func (q *CentralQueue) Sorted() iter.Seq[CoordinatedEvent] { q.mu.Lock() events := slices.Clone(q.events) q.mu.Unlock() - eventHeap := &coordinatedEventHeap{events: events, cmp: cmp} + eventHeap := new(coordinatedEventHeap(events)) heap.Init(eventHeap) return func(yield func(CoordinatedEvent) bool) { for eventHeap.Len() > 0 { - if !yield(eventHeap.events[0]) { + if !yield((*eventHeap)[0]) { return } heap.Pop(eventHeap) @@ -170,30 +169,27 @@ func (q *CentralQueue) SortedFunc(cmp func(a, b CoordinatedEvent) int) iter.Seq[ } } -type coordinatedEventHeap struct { - events []CoordinatedEvent - cmp func(a, b CoordinatedEvent) int -} +type coordinatedEventHeap []CoordinatedEvent func (c *coordinatedEventHeap) Len() int { - return len(c.events) + return len(*c) } func (c *coordinatedEventHeap) Less(i, j int) bool { - return c.cmp(c.events[i], c.events[j]) < 0 + return (*c)[i].CompareDeadline(&(*c)[j]) < 0 } func (c *coordinatedEventHeap) Swap(i, j int) { - c.events[i], c.events[j] = c.events[j], c.events[i] + (*c)[i], (*c)[j] = (*c)[j], (*c)[i] } func (c *coordinatedEventHeap) Push(x any) { - c.events = append(c.events, x.(CoordinatedEvent)) + *c = append(*c, x.(CoordinatedEvent)) } func (c *coordinatedEventHeap) Pop() any { - e := c.events[len(c.events)-1] - c.events = c.events[:len(c.events)-1] + e := (*c)[len(*c)-1] + *c = (*c)[:len(*c)-1] return e } diff --git a/core/services/workflows/v2/triggers/triggers.go b/core/services/workflows/v2/triggers/triggers.go index 665c0d106d4..b653de95539 100644 --- a/core/services/workflows/v2/triggers/triggers.go +++ b/core/services/workflows/v2/triggers/triggers.go @@ -1,6 +1,7 @@ package triggers import ( + "cmp" "context" "errors" "fmt" @@ -185,6 +186,10 @@ type CoordinatedEvent struct { Event capabilities.TriggerResponse } +func (e *CoordinatedEvent) CompareDeadline(o *CoordinatedEvent) int { + return cmp.Or(e.Deadline.Compare(o.Deadline), cmp.Compare(e.Event.Event.ID, o.Event.Event.ID)) +} + func (e *CoordinatedEvent) ToProto() *pb.CoordinatedEvent { return &pb.CoordinatedEvent{ WorkflowID: e.WorkflowID, diff --git a/deployment/go.mod b/deployment/go.mod index 54f75a1bbf0..52fcdcb2041 100644 --- a/deployment/go.mod +++ b/deployment/go.mod @@ -41,7 +41,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/solana/deployment v0.0.0-20260916222901-720a003dab50 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260922043016-517a12a4220e github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb github.com/smartcontractkit/chainlink-data-streams v1.1.3 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 diff --git a/deployment/go.sum b/deployment/go.sum index d0629af5562..52da3f4f005 100644 --- a/deployment/go.sum +++ b/deployment/go.sum @@ -1411,8 +1411,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.16.0 h1:WhDQEEI2Kb5A4C0PNAa+nyGLDvG0H+uT6h4y1NwmkYg= github.com/smartcontractkit/chainlink-ccv v0.16.0/go.mod h1:oaSLVHiJVbJ9aCcUQnoRuVONACWzA/DWVqvUnLAe9bE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 h1:V+IBcXmheTxfYQb8gX/2KFjcIwiPSz6hvJ5MmOh9hjI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087 h1:QQpXxddXoJi7b200xLaTI8yO8iKOukebi8WctQotQmY= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb h1:9rVrSeVOAwZsVe2pOpeVRp9XjhtMyjndgeROFglvOhg= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb/go.mod h1:WcOKzF6HkTDrkQ96aBHhcJ2IIYE7iK7M2tdt58ea2qc= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/go.mod b/go.mod index e3738e1879a..f8de929717a 100644 --- a/go.mod +++ b/go.mod @@ -82,7 +82,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260908155618-50f521d70e62 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260908155618-50f521d70e62 github.com/smartcontractkit/chainlink-ccv v0.16.0 - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 github.com/smartcontractkit/chainlink-data-streams v1.1.3 diff --git a/go.sum b/go.sum index 49f1a8f32e4..e5ba383d77a 100644 --- a/go.sum +++ b/go.sum @@ -1102,8 +1102,8 @@ github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260 github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260908155618-50f521d70e62/go.mod h1:c++Ed0jeYn4w8WIfiAboRwN6ClRRVGglL0qwB/QjJvM= github.com/smartcontractkit/chainlink-ccv v0.16.0 h1:WhDQEEI2Kb5A4C0PNAa+nyGLDvG0H+uT6h4y1NwmkYg= github.com/smartcontractkit/chainlink-ccv v0.16.0/go.mod h1:oaSLVHiJVbJ9aCcUQnoRuVONACWzA/DWVqvUnLAe9bE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 h1:V+IBcXmheTxfYQb8gX/2KFjcIwiPSz6hvJ5MmOh9hjI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087 h1:QQpXxddXoJi7b200xLaTI8yO8iKOukebi8WctQotQmY= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb h1:9rVrSeVOAwZsVe2pOpeVRp9XjhtMyjndgeROFglvOhg= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb/go.mod h1:WcOKzF6HkTDrkQ96aBHhcJ2IIYE7iK7M2tdt58ea2qc= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index c81ab483f74..404dddb6f4b 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -30,7 +30,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260922043016-517a12a4220e github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260922043016-517a12a4220e - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261112211734-e640e1c12078 diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 3e5085b8781..fb9330cb328 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1396,8 +1396,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.16.0 h1:WhDQEEI2Kb5A4C0PNAa+nyGLDvG0H+uT6h4y1NwmkYg= github.com/smartcontractkit/chainlink-ccv v0.16.0/go.mod h1:oaSLVHiJVbJ9aCcUQnoRuVONACWzA/DWVqvUnLAe9bE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 h1:V+IBcXmheTxfYQb8gX/2KFjcIwiPSz6hvJ5MmOh9hjI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087 h1:QQpXxddXoJi7b200xLaTI8yO8iKOukebi8WctQotQmY= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb h1:9rVrSeVOAwZsVe2pOpeVRp9XjhtMyjndgeROFglvOhg= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb/go.mod h1:WcOKzF6HkTDrkQ96aBHhcJ2IIYE7iK7M2tdt58ea2qc= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/integration-tests/load/go.mod b/integration-tests/load/go.mod index 45f92ef98e1..e6c25a18c78 100644 --- a/integration-tests/load/go.mod +++ b/integration-tests/load/go.mod @@ -20,7 +20,7 @@ require ( github.com/smartcontractkit/chainlink-ccip/chains/evm v0.0.0-20261001213322-a2d686f610ca github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260922043016-517a12a4220e github.com/smartcontractkit/chainlink-ccip/chains/solana/gobindings v0.0.0-20260922043016-517a12a4220e - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 github.com/smartcontractkit/chainlink-evm v0.3.4-0.20261112211734-e640e1c12078 github.com/smartcontractkit/chainlink-testing-framework/framework v0.16.9 diff --git a/integration-tests/load/go.sum b/integration-tests/load/go.sum index c39f1ee6333..591c6c77cb0 100644 --- a/integration-tests/load/go.sum +++ b/integration-tests/load/go.sum @@ -1636,8 +1636,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.16.0 h1:WhDQEEI2Kb5A4C0PNAa+nyGLDvG0H+uT6h4y1NwmkYg= github.com/smartcontractkit/chainlink-ccv v0.16.0/go.mod h1:oaSLVHiJVbJ9aCcUQnoRuVONACWzA/DWVqvUnLAe9bE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 h1:V+IBcXmheTxfYQb8gX/2KFjcIwiPSz6hvJ5MmOh9hjI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087 h1:QQpXxddXoJi7b200xLaTI8yO8iKOukebi8WctQotQmY= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb h1:9rVrSeVOAwZsVe2pOpeVRp9XjhtMyjndgeROFglvOhg= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb/go.mod h1:WcOKzF6HkTDrkQ96aBHhcJ2IIYE7iK7M2tdt58ea2qc= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/system-tests/lib/go.mod b/system-tests/lib/go.mod index e43c92856e0..2ab485d707f 100644 --- a/system-tests/lib/go.mod +++ b/system-tests/lib/go.mod @@ -32,7 +32,7 @@ require ( github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-aptos v0.0.0-20260923062809-ca886ade4d26 github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260922043016-517a12a4220e - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb github.com/smartcontractkit/chainlink-confidential-compute v1.3.0 github.com/smartcontractkit/chainlink-deployments-framework v0.126.0 diff --git a/system-tests/lib/go.sum b/system-tests/lib/go.sum index cf457822624..bd08182f238 100644 --- a/system-tests/lib/go.sum +++ b/system-tests/lib/go.sum @@ -1657,8 +1657,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.16.0 h1:WhDQEEI2Kb5A4C0PNAa+nyGLDvG0H+uT6h4y1NwmkYg= github.com/smartcontractkit/chainlink-ccv v0.16.0/go.mod h1:oaSLVHiJVbJ9aCcUQnoRuVONACWzA/DWVqvUnLAe9bE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 h1:V+IBcXmheTxfYQb8gX/2KFjcIwiPSz6hvJ5MmOh9hjI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087 h1:QQpXxddXoJi7b200xLaTI8yO8iKOukebi8WctQotQmY= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb h1:9rVrSeVOAwZsVe2pOpeVRp9XjhtMyjndgeROFglvOhg= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb/go.mod h1:WcOKzF6HkTDrkQ96aBHhcJ2IIYE7iK7M2tdt58ea2qc= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= diff --git a/system-tests/tests/go.mod b/system-tests/tests/go.mod index 097a1c9e70a..f4cbd125a58 100644 --- a/system-tests/tests/go.mod +++ b/system-tests/tests/go.mod @@ -73,7 +73,7 @@ require ( github.com/smartcontractkit/chain-selectors v1.0.112 github.com/smartcontractkit/chainlink-aptos v0.0.0-20260923062809-ca886ade4d26 github.com/smartcontractkit/chainlink-ccip/chains/solana v0.0.0-20260922043016-517a12a4220e - github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 + github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087 github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 github.com/smartcontractkit/chainlink-confidential-compute v1.3.0 diff --git a/system-tests/tests/go.sum b/system-tests/tests/go.sum index 6b9a4b494b3..4616835de7d 100644 --- a/system-tests/tests/go.sum +++ b/system-tests/tests/go.sum @@ -1836,8 +1836,8 @@ github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d6 github.com/smartcontractkit/chainlink-ccip/deployment v0.0.0-20261001213322-a2d686f610ca/go.mod h1:Dm/Abz0vr7F2v9TygUX947q8HIwJEJikDfSdanX1Cic= github.com/smartcontractkit/chainlink-ccv v0.16.0 h1:WhDQEEI2Kb5A4C0PNAa+nyGLDvG0H+uT6h4y1NwmkYg= github.com/smartcontractkit/chainlink-ccv v0.16.0/go.mod h1:oaSLVHiJVbJ9aCcUQnoRuVONACWzA/DWVqvUnLAe9bE= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5 h1:V+IBcXmheTxfYQb8gX/2KFjcIwiPSz6hvJ5MmOh9hjI= -github.com/smartcontractkit/chainlink-common v0.11.2-0.20261117234947-4423d67da5d5/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087 h1:QQpXxddXoJi7b200xLaTI8yO8iKOukebi8WctQotQmY= +github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118150912-05caa74bd087/go.mod h1:81DIRjlxA+Nq4sugpyD0zofdXg46owE/N3eter3+EkI= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb h1:9rVrSeVOAwZsVe2pOpeVRp9XjhtMyjndgeROFglvOhg= github.com/smartcontractkit/chainlink-common/keystore v1.3.1-0.20261111193935-c83f8e2996fb/go.mod h1:WcOKzF6HkTDrkQ96aBHhcJ2IIYE7iK7M2tdt58ea2qc= github.com/smartcontractkit/chainlink-common/pkg/chipingress v0.0.11-0.20261106154152-9426766b30a9 h1:rs2zmGoDw4AHaJ2Y76J46slPPE3iL801sWPgOTCyDZc= From 60e3b4d84876d42756cb4623e3aa13fc33c26de1 Mon Sep 17 00:00:00 2001 From: Jordan Krage Date: Thu, 19 Nov 2026 15:39:53 -0600 Subject: [PATCH 13/13] review feedback; reorder StateTransition to limit KV data; fill gaps --- core/services/ocr3_1/plugins/queue/blobs.go | 45 ++++-- .../ocr3_1/plugins/queue/blobs_test.go | 2 +- core/services/ocr3_1/plugins/queue/kvstate.go | 126 +++++++++++----- core/services/ocr3_1/plugins/queue/math.go | 35 ----- core/services/ocr3_1/plugins/queue/queue.go | 141 ++++++++++++------ .../ocr3_1/plugins/queue/queue_test.go | 67 ++++++++- .../workflows/v2/triggers/coordinator.go | 34 ++++- core/services/workflows/v2/triggers/queue.go | 3 + 8 files changed, 316 insertions(+), 137 deletions(-) diff --git a/core/services/ocr3_1/plugins/queue/blobs.go b/core/services/ocr3_1/plugins/queue/blobs.go index b3516ab8832..1bde88bc86c 100644 --- a/core/services/ocr3_1/plugins/queue/blobs.go +++ b/core/services/ocr3_1/plugins/queue/blobs.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "sync" + "time" "google.golang.org/protobuf/encoding/protowire" "google.golang.org/protobuf/proto" @@ -42,70 +43,88 @@ func (c *blobCache) fetchBlob(ctx context.Context, handle []byte) ([]byte, error return c.fetcher.FetchBlob(ctx, blobHandle) }) c.cache[string(handle)] = fn + c.mu.Unlock() return fn() } // fetchCoordinatedEventFromBlob fetches and extracts the idx-th event from the blob, without unmarshaling any other events. func fetchCoordinatedEventFromBlob(ctx context.Context, fetcher *blobCache, handle []byte, idx int) (*pb.CoordinatedEvent, []byte, error) { - b, err := fetcher.fetchBlob(ctx, handle) + bb, err := fetcher.fetchBlob(ctx, handle) if err != nil { return nil, nil, fmt.Errorf("failed to fetch blob: %w", err) } - coordEvent, err := extractEvent(b, idx) + coordEvent, eb, err := extractEvent(bb, idx) if err != nil { return nil, nil, err } - return coordEvent, b, nil + return coordEvent, eb, nil } const coordinatedEventsFieldNumber = 1 // pb.CoordinatedEventList.Events // extractEvent extracts the idx-th event from the blob, without unmarshaling any other events. -func extractEvent(b []byte, idx int) (*pb.CoordinatedEvent, error) { +func extractEvent(b []byte, idx int) (*pb.CoordinatedEvent, []byte, error) { i := 0 for len(b) > 0 { num, typ, n := protowire.ConsumeTag(b) if n < 0 { - return nil, protowire.ParseError(n) + return nil, nil, protowire.ParseError(n) } b = b[n:] if num == coordinatedEventsFieldNumber { if typ != protowire.BytesType { - return nil, fmt.Errorf("expected bytes type for field %d, got %d", coordinatedEventsFieldNumber, typ) + return nil, nil, fmt.Errorf("expected bytes type for field %d, got %d", coordinatedEventsFieldNumber, typ) } v, m := protowire.ConsumeBytes(b) if m < 0 { - return nil, protowire.ParseError(m) + return nil, nil, protowire.ParseError(m) } if i == idx { var event pb.CoordinatedEvent if err := proto.Unmarshal(v, &event); err != nil { - return nil, fmt.Errorf("failed to unmarshal event: %w", err) + return nil, v, fmt.Errorf("failed to unmarshal event: %w", err) } - return &event, nil + return &event, v, nil } // advance i++ b = b[m:] continue + } else { + n := protowire.ConsumeFieldValue(num, typ, b) + if n < 0 { + return nil, nil, protowire.ParseError(n) + } + b = b[n:] } } - return nil, fmt.Errorf("index %d out of range", idx) + return nil, nil, fmt.Errorf("index %d out of range", idx) } -// broadcastAsBlob broadcasts a list of coordinated events and returns a blob handle. -func broadcastAsBlob(ctx context.Context, broadcaster ocr3_1types.BlobBroadcastFetcher, events []*pb.CoordinatedEvent, expSeq uint64) (blobHandle []byte, n int, err error) { +// broadcastAsBlob broadcasts a blob with as many coordinated events as possible, returning the blob handle and count of events included. +func broadcastAsBlob(ctx context.Context, broadcaster ocr3_1types.BlobBroadcastFetcher, events []*pb.CoordinatedEvent, + seqNr uint64, estimatedRoundInterval time.Duration) (blobHandle []byte, n int, err error) { protoOpts := proto.MarshalOptions{Deterministic: true} for ; protoOpts.Size(&pb.CoordinatedEventList{Events: events}) > maxBlobPayloadBytes; events = events[:len(events)-1] { //TODO opt: binary search for largest fit instead.... } n = len(events) + var maxDeadline time.Time + for _, event := range events { + if t := event.Deadline.AsTime(); t.After(maxDeadline) { + maxDeadline = t + } + } + roundDur := estimatedRoundInterval //TODO OK? pad? + //TODO pad extra time and/or rounds? + expSeqNr := seqNr + uint64(time.Until(maxDeadline)/roundDur) + data, err := protoOpts.Marshal(&pb.CoordinatedEventList{Events: events}) if err != nil { return nil, -1, fmt.Errorf("failed to marshal blob: %w", err) } - bh, err := broadcaster.BroadcastBlob(ctx, data, ocr3_1types.BlobExpirationHintSequenceNumber{SeqNr: expSeq}) + bh, err := broadcaster.BroadcastBlob(ctx, data, ocr3_1types.BlobExpirationHintSequenceNumber{SeqNr: expSeqNr}) if err != nil { return nil, -1, fmt.Errorf("failed to broadcast blob: %w", err) } diff --git a/core/services/ocr3_1/plugins/queue/blobs_test.go b/core/services/ocr3_1/plugins/queue/blobs_test.go index 8a9041e5cf4..eaa8e74fb50 100644 --- a/core/services/ocr3_1/plugins/queue/blobs_test.go +++ b/core/services/ocr3_1/plugins/queue/blobs_test.go @@ -70,7 +70,7 @@ func Test_extractEvent(t *testing.T) { } b, err := proto.MarshalOptions{Deterministic: true}.Marshal(&pb.CoordinatedEventList{Events: events}) require.NoError(t, err) - got, err := extractEvent(b, tt.idx) + got, _, err := extractEvent(b, tt.idx) if tt.idx < tt.len { require.True(t, proto.Equal(event, got)) } else { diff --git a/core/services/ocr3_1/plugins/queue/kvstate.go b/core/services/ocr3_1/plugins/queue/kvstate.go index 8354cd96ff0..dbdea067ed4 100644 --- a/core/services/ocr3_1/plugins/queue/kvstate.go +++ b/core/services/ocr3_1/plugins/queue/kvstate.go @@ -1,6 +1,7 @@ package queue import ( + "cmp" "container/heap" "fmt" "maps" @@ -44,7 +45,12 @@ var _ heap.Interface = (*priorityQueue)(nil) // priorityQueue is a heap of coordinated events, ordered by deadline and then trigger event ID. type priorityQueue []*pb.ConsensusQueueEvent -func (p *priorityQueue) Len() int { return len(*p) } +func (p *priorityQueue) Len() int { + if p == nil { + return 0 + } + return len(*p) +} func (p *priorityQueue) Less(i, j int) bool { a, b := (*p)[i], (*p)[j] @@ -60,7 +66,9 @@ func (p *priorityQueue) Push(x any) { } func (p *priorityQueue) Pop() any { - return (*p)[len(*p)-1] + e := (*p)[len(*p)-1] + *p = (*p)[:len(*p)-1] + return e } func (p *priorityQueue) push(x *pb.ConsensusQueueEvent) { heap.Push(p, x) } @@ -89,30 +97,39 @@ func (p *priorityQueue) mustPop() *pb.ConsensusQueueEvent { // popLimited pops up to capacity events from the queue, each of which must also have sufficient wf capacity. // Note: capPerWF is mutated. -func (p *priorityQueue) popLimited(capacity uint32, capPerWF map[string]uint32, expiration time.Time) []*pb.ConsensusQueueEvent { - var events []*pb.ConsensusQueueEvent +func (p *priorityQueue) popLimited(capPerWF map[string]uint32, expiration time.Time) (event *pb.ConsensusQueueEvent) { var wfLimited []*pb.ConsensusQueueEvent // omitted due to workflow limit - for len(events) < int(capacity) { - next := p.mustPop() - if next == nil { + for { + event = p.mustPop() + if event == nil { break } - if next.Deadline.AsTime().Before(expiration) { + if event.Deadline.AsTime().Before(expiration) { // drop expired continue } - if capPerWF[next.WorkflowID] == 0 { - wfLimited = append(wfLimited, next) + if capPerWF[event.WorkflowID] == 0 { + // ignore but restore after + wfLimited = append(wfLimited, event) continue } - capPerWF[next.WorkflowID]-- - events = append(events, next) + capPerWF[event.WorkflowID]-- + break } // restore omitted for next time - for _, event := range wfLimited { - p.push(event) + for _, limited := range wfLimited { + p.push(limited) } - return events + return +} + +type revPriorityQueue struct { + *priorityQueue +} + +func (r *revPriorityQueue) Less(i, j int) bool { + a, b := (*r.priorityQueue)[i], (*r.priorityQueue)[j] + return b.CompareDeadline(a) < 0 } type blobHandleMap map[string]map[string]uint32 // eventHash -> blobHandle -> idx @@ -162,8 +179,8 @@ func (s *kvState) loadFrom(kv ocr3_1types.KeyValueStateReadWriter) error { return fmt.Errorf("failed to read queued events: %w", err) } if v != nil { - var queued *pb.ConsensusQueueEventList - if err = proto.Unmarshal(v, queued); err != nil { + var queued pb.ConsensusQueueEventList + if err = proto.Unmarshal(v, &queued); err != nil { return fmt.Errorf("failed to unmarshal queued events: %w", err) } s.queuedEvents = new(priorityQueue(queued.GetEvents())) @@ -190,8 +207,8 @@ func readObservedEvents(kv ocr3_1types.KeyValueStateReader) (observedEvents map[ } observedBlobs = make(blobHandleMap) if v != nil { - var observed *pb.ConsensusQueueObservedEvents - if err = proto.Unmarshal(v, observed); err != nil { + var observed pb.ConsensusQueueObservedEvents + if err = proto.Unmarshal(v, &observed); err != nil { return nil, nil, fmt.Errorf("failed to unmarshal observed events: %w", err) } observedEvents = make(map[string]*pb.ConsensusQueueObservedEvent) @@ -212,31 +229,49 @@ func readObservedEvents(kv ocr3_1types.KeyValueStateReader) (observedEvents map[ // sizeOf returns the size of the state when serialized and written to the KV store via writeAll. func (s *kvState) sizeOf() (size int) { - s.prepareWrite() - - //TODO check maxKeyValueValueBytes too? - protoOpts := proto.MarshalOptions{Deterministic: true} size += len(observedEventsKey) + len(queuedEventsKey) + len(consensusEventsKey) + len(blobHandlesKey) - size += protoOpts.Size(&pb.ConsensusQueueObservedEvents{Observations: s.observedEventEntries, BlobHandles: s.observedBlobHandles}) - size += protoOpts.Size(&pb.ConsensusQueueEventList{Events: *s.queuedEvents}) - size += protoOpts.Size(&pb.ConsensusQueueEventList{Events: s.consensusEvents}) - size += protoOpts.Size(&pb.ConsensusQueueBlobHandleList{BlobHandles: s.queuedBlobHandles}) - + size += s.sizeOfObservedEvents() + s.sizeOfQueuedEvents() + s.sizeOfConsensusEvents() + s.sizeOfBlobHandles() + //TODO opt: proto.MarshalOptions.UseCachedSize return } -// prepareWrite initializes observed and queued blob handles and updates the event references. -func (s *kvState) prepareWrite() { +func (s *kvState) sizeOfObservedEvents() int { + s.prepareWriteObservedEvents() + return proto.MarshalOptions{Deterministic: true}.Size(&pb.ConsensusQueueObservedEvents{Observations: s.observedEventEntries, BlobHandles: s.observedBlobHandles}) +} + +func (s *kvState) sizeOfQueuedEvents() int { + return proto.MarshalOptions{Deterministic: true}.Size(&pb.ConsensusQueueEventList{Events: *s.queuedEvents}) +} + +func (s *kvState) sizeOfConsensusEvents() int { + return proto.MarshalOptions{Deterministic: true}.Size(&pb.ConsensusQueueEventList{Events: s.consensusEvents}) +} + +func (s *kvState) sizeOfBlobHandles() int { + s.prepareWriteBlobHandles() + return proto.MarshalOptions{Deterministic: true}.Size(&pb.ConsensusQueueBlobHandleList{BlobHandles: s.queuedBlobHandles}) +} + +// prepareWrite initializes observed blob handles & entries, and updates the event references. +func (s *kvState) prepareWriteObservedEvents() { // gather blob handles and update events s.observedBlobHandles = nil observedBlobIndexes := make(map[string]int) s.observedEventEntries = nil - //TODO deadline order so that we can drop efficiently - for _, eventHash := range slices.Sorted(maps.Keys(s.observedEvents)) { + + // sort so that we can drop lowest priority efficiently + for _, eventHash := range slices.SortedFunc(maps.Keys(s.observedEvents), func(a string, b string) int { + ea, eb := s.observedEvents[a], s.observedEvents[b] + //TODO can we use deadline here? is median valid & best option? + return cmp.Or(cmp.Compare(len(ea.NodeIds), len(eb.NodeIds)), + cmp.Compare(ea.TriggerEventID, eb.TriggerEventID)) + }) { event := s.observedEvents[eventHash] event.Blobs = nil // replace all - for blobHandle, ei := range s.observedBlobs[eventHash] { + for _, blobHandle := range slices.Sorted(maps.Keys(s.observedBlobs[eventHash])) { + ei := s.observedBlobs[eventHash][blobHandle] idx, ok := observedBlobIndexes[blobHandle] if !ok { idx = len(s.observedBlobHandles) @@ -251,13 +286,17 @@ func (s *kvState) prepareWrite() { s.observedEventEntries = append(s.observedEventEntries, &pb.ConsensusQueueObservedEventEntry{ TimelessHash: []byte(eventHash), Event: event}) } +} +// prepareWrite initializes queued blob handles and updates the event references. +func (s *kvState) prepareWriteBlobHandles() { // gather blob handles and update events s.queuedBlobHandles = nil queuedBlobIndexes := make(map[string]int) addBlobs := func(blobs map[string]uint32) []*pb.CoordinatedEventBlobHandle { var blobHandles []*pb.CoordinatedEventBlobHandle - for blobHandle, ei := range blobs { + for _, blobHandle := range slices.Sorted(maps.Keys(blobs)) { + ei := blobs[blobHandle] idx, ok := queuedBlobIndexes[blobHandle] if !ok { idx = len(s.queuedBlobHandles) @@ -334,7 +373,8 @@ func (s *kvState) pruneExpiredObservations(expiration time.Time) { // addObserved adds the observed events to the set, promoting to the priority queue on 2f+1 and calling onQueued. func (s *kvState) addObservedEvents(f int, toAdd map[string]*pb.ConsensusQueueObservedEvent, observedBlobs blobHandleMap, onQueued func(event *pb.ConsensusQueueEvent)) { - for eventHash, eventToAdd := range toAdd { + for _, eventHash := range slices.Sorted(maps.Keys(toAdd)) { + eventToAdd := toAdd[eventHash] obsEvent, ok := s.observedEvents[eventHash] if !ok && len(eventToAdd.NodeIds) >= 2*f+1 { // new proposal straight to priority queue @@ -349,12 +389,16 @@ func (s *kvState) addObservedEvents(f int, toAdd map[string]*pb.ConsensusQueueOb // update proposal // TODO opt: build a map to avoid n^2? for i, node := range eventToAdd.NodeIds { - if !slices.Contains(obsEvent.NodeIds, node) { + if prev := slices.Index(obsEvent.NodeIds, node); prev == -1 { obsEvent.NodeIds = append(obsEvent.NodeIds, node) obsEvent.ObservedAts = append(obsEvent.ObservedAts, eventToAdd.ObservedAts[i]) obsEvent.Deadlines = append(obsEvent.Deadlines, eventToAdd.Deadlines[i]) obsEvent.Blobs = append(obsEvent.Blobs, eventToAdd.Blobs[i]) - } //TODO what if a node reports twice with different deadline or observation? do we need to overwrite? + } else { // overwrite previous observation + obsEvent.ObservedAts[prev] = eventToAdd.ObservedAts[i] + obsEvent.Deadlines[prev] = eventToAdd.Deadlines[i] + obsEvent.Blobs[prev] = eventToAdd.Blobs[i] + } } if len(obsEvent.NodeIds) >= 2*f+1 { @@ -378,8 +422,8 @@ func readConsensusState(kvReader ocr3_1types.KeyValueStateReader) ([]*pb.Consens var consensusEvents []*pb.ConsensusQueueEvent if v != nil { - var pbs *pb.ConsensusQueueEventList - if err := proto.Unmarshal(v, pbs); err != nil { + var pbs pb.ConsensusQueueEventList + if err := proto.Unmarshal(v, &pbs); err != nil { return nil, nil, fmt.Errorf("failed to unmarshal consensus events: %w", err) } consensusEvents = pbs.GetEvents() @@ -401,8 +445,8 @@ func readBlobHandles(kvReader ocr3_1types.KeyValueStateReader) ([][]byte, error) var blobHandles [][]byte if v != nil { - var bs *pb.ConsensusQueueBlobHandleList - if err := proto.Unmarshal(v, bs); err != nil { + var bs pb.ConsensusQueueBlobHandleList + if err := proto.Unmarshal(v, &bs); err != nil { return nil, fmt.Errorf("failed to unmarshal consensus blob handles: %w", err) } blobHandles = bs.GetBlobHandles() diff --git a/core/services/ocr3_1/plugins/queue/math.go b/core/services/ocr3_1/plugins/queue/math.go index b67cd83cb08..400276f25df 100644 --- a/core/services/ocr3_1/plugins/queue/math.go +++ b/core/services/ocr3_1/plugins/queue/math.go @@ -4,44 +4,9 @@ import ( "slices" "time" - "golang.org/x/exp/constraints" "google.golang.org/protobuf/types/known/timestamppb" ) -// median returns the median value of a slice of integers, as well as a count of the number of occurrences of the median. -// len must be greater than 0. -func median[N constraints.Integer, S []N](s S) (N, int) { - switch len(s) { - case 0: - panic("median: len must be greater than 0") - case 1: - return s[0], 1 - } - slices.Sort(s) - if len(s)%2 == 1 { - m := s[len(s)/2] - return m, count(s, m) - } - // avg of two - a, b := s[len(s)/2], s[len(s)/2-1] - diff := a - b - m := b + diff/2 - return m, count(s, m) -} - -// count returns the number of occurrences of e in s, but s must be sorted. -func count[N comparable, S []N](s S, e N) int { - firstIndex := slices.Index(s, e) - if firstIndex == -1 { - return 0 - } - var c int - for i := firstIndex; i < len(s) && s[i] == e; i++ { - c++ - } - return c -} - // medianTimestamp returns the median value of a slice of timestamps. // len must be greater than 0. func medianTimestamp(s []*timestamppb.Timestamp) *timestamppb.Timestamp { diff --git a/core/services/ocr3_1/plugins/queue/queue.go b/core/services/ocr3_1/plugins/queue/queue.go index 04c9676021a..895c19d9a50 100644 --- a/core/services/ocr3_1/plugins/queue/queue.go +++ b/core/services/ocr3_1/plugins/queue/queue.go @@ -8,6 +8,7 @@ package queue import ( "bytes" + "container/heap" "context" "crypto/sha256" "errors" @@ -53,6 +54,15 @@ func NewConsensusQueuePluginFactory( triggerCoordinator triggers.Coordinator, triggerQueue triggers.Queue, ) (ocr3_1types.ReportingPluginFactory[[]byte], error) { + if cfg == nil { + return nil, errors.New("cfg cannot be nil") + } + if triggerCoordinator == nil { + return nil, errors.New("triggerCoordinator cannot be nil") + } + if triggerQueue == nil { + return nil, errors.New("triggerQueue cannot be nil") + } return &consensusQueuePluginFactory{ lggr: lggr, cfg: cfg, @@ -96,7 +106,7 @@ func newConsensusQueuePlugin( c := &consensusQueuePlugin{ lggr: logger.Named(lggr, "ConsensusQueuePlugin"), onchainCfg: onchainCfg, - blobHandleMarshalledBytesUpperBound: ocr3_1types.BlobHandleMarshalledBytesUpperBound(onchainCfg.F, onchainCfg.N), + blobHandleMarshalledBytesUpperBound: ocr3_1types.BlobHandleMarshalledBytesUpperBound(onchainCfg.N, onchainCfg.F), triggerCoordinator: triggerCoordinator, triggerQueue: triggerQueue, blobBroadcastFetcher: blobs, @@ -199,12 +209,9 @@ func (c *consensusQueuePlugin) Observation( } } - roundDur := c.onchainCfg.EstimatedRoundInterval //TODO OK? - expSeqNr := seqNr + uint64(expirationGraceDur/roundDur) //TODO pad extra time and/or rounds? - obs.BlobHandles = nil // remove the placeholders if len(coordEvents) > 0 { - blobHandle, n, err2 := broadcastAsBlob(ctx, blobBroadcaster, coordEvents, expSeqNr) + blobHandle, n, err2 := broadcastAsBlob(ctx, blobBroadcaster, coordEvents, seqNr, c.onchainCfg.EstimatedRoundInterval) if err2 != nil { return nil, err2 } @@ -212,15 +219,16 @@ func (c *consensusQueuePlugin) Observation( // note: elements already reference blob 0 and natural element index is aligned var offset int + //TODO stop after batch maxObservedBlobHandles for batch := 1; n < len(coordEvents); batch++ { offset += n coordEvents = coordEvents[n:] - blobHandle, n, err2 = broadcastAsBlob(ctx, blobBroadcaster, coordEvents, expSeqNr) + blobHandle, n, err2 = broadcastAsBlob(ctx, blobBroadcaster, coordEvents, seqNr, c.onchainCfg.EstimatedRoundInterval) if err2 != nil { return nil, err2 } obs.BlobHandles = append(obs.BlobHandles, blobHandle) - for i := n; i < n; i++ { // update indices + for i := offset; i < n; i++ { // update indices obs.Events[offset+i].Blobs[0].Blob = uint32(batch) obs.Events[offset+i].Blobs[0].Element = uint32(i) } @@ -260,9 +268,6 @@ func (c *consensusQueuePlugin) ValidateObservation( if len(obs.Events) > maxObservedEvents { return fmt.Errorf("events are limited to %d but got %d", maxObservedEvents, len(obs.Events)) } - if !slices.IsSortedFunc(obs.Events, (*pb.ConsensusQueueEvent).CompareDeadline) { - return fmt.Errorf("events must be sorted") - } var eg errgroup.Group fetcher := blobCache{fetcher: blobFetcher, cache: make(map[string]func() ([]byte, error))} for i, event := range obs.Events { @@ -273,7 +278,16 @@ func (c *consensusQueuePlugin) ValidateObservation( return nil }) } - return eg.Wait() + if err = eg.Wait(); err != nil { + return err + } + + // wait to do this since we depend on every event being valid + if !slices.IsSortedFunc(obs.Events, (*pb.ConsensusQueueEvent).CompareDeadline) { + return fmt.Errorf("events must be sorted") + } + + return nil } func validateObservedEvent(ctx context.Context, fetcher *blobCache, event *pb.ConsensusQueueEvent, blobHandles [][]byte) error { @@ -344,7 +358,7 @@ func (c *consensusQueuePlugin) StateTransition( ctx context.Context, _ uint64, _ ocrtypes.AttributedQuery, aos []ocrtypes.AttributedObservation, kvReaderWriter ocr3_1types.KeyValueStateReadWriter, _ ocr3_1types.BlobFetcher, ) (ocr3_1types.ReportsPlusPrecursor, error) { - var done chan struct{} + done := make(chan struct{}) var obs observations go func() { @@ -370,9 +384,6 @@ func (c *consensusQueuePlugin) StateTransition( if obs.err != nil { return nil, fmt.Errorf("failed to aggregate observations: %w", obs.err) } - if obs.warn != nil { - c.lggr.Warnw("Failed to aggregate some observations", "err", obs.warn) - } // update state state.pruneExpiredObservations(obs.medianExpiration) @@ -380,20 +391,71 @@ func (c *consensusQueuePlugin) StateTransition( state.addObservedEvents(c.onchainCfg.F, obs.newObservedEvents, obs.observedBlobs, func(event *pb.ConsensusQueueEvent) { queuedTriggerEventIDs = append(queuedTriggerEventIDs, event.TriggerEventID) }) - state.consensusEvents = state.queuedEvents.popLimited(obs.medianCap, obs.medianCapPerWF, obs.medianExpiration) + // pop as many queuedEvents as possible in to consensusEvents (up to capacity or KV limits) + for len(*state.queuedEvents) > 0 && len(state.consensusEvents) < int(obs.medianCap) { + event := state.queuedEvents.popLimited(obs.medianCapPerWF, obs.medianExpiration) + if event == nil { + break + } + state.consensusEvents = append(state.consensusEvents, event) + // stop when either value or the overall size is too large + if events, blobs := state.sizeOfConsensusEvents(), state.sizeOfBlobHandles(); events > maxKeyValueValueBytes || + blobs > maxKeyValueValueBytes || events+blobs > maxKeyValueModifiedKeysPlusValuesBytes/2 { + state.consensusEvents = state.consensusEvents[:len(state.consensusEvents)-1] + break + } + } - // prune observations until we fit - for state.sizeOf() > maxKeyValueModifiedKeysPlusValuesBytes { - //TODO drop observations (must be deterministic, fair, efficient) - // prefer farthest future deadlines and fewest observations - //TODO use sorted state.observedEventEntries + // prune observations if that value or the overall size is too large + for len(state.observedEventEntries) > 0 && + (state.sizeOfObservedEvents() > maxKeyValueValueBytes || + state.sizeOf() > maxKeyValueModifiedKeysPlusValuesBytes) { + // sorted by decreasing priority, so prune the last + toRemove := state.observedEventEntries[len(state.observedEventEntries)-1] + delete(state.observedEvents, toRemove.Event.TriggerEventID) + //TODO opt: drop more than one each time? + } + + // prune queuedEvents if that value, blob handles, or the overall size is too large + if len(*state.queuedEvents) > 0 && + (state.sizeOfQueuedEvents() > maxKeyValueValueBytes || + state.sizeOfBlobHandles() > maxKeyValueValueBytes || + state.sizeOf() > maxKeyValueModifiedKeysPlusValuesBytes) { + // prune lowest priority queuedEvents from newly added queuedTriggerEventIDs + queuedTriggerEventIDSet := map[string]struct{}{} + for _, id := range queuedTriggerEventIDs { + queuedTriggerEventIDSet[id] = struct{}{} + } + eligibleEvents := make([]*pb.ConsensusQueueEvent, 0, len(*state.queuedEvents)) + for _, e := range *state.queuedEvents { + if _, ok := queuedTriggerEventIDSet[e.TriggerEventID]; ok { + eligibleEvents = append(eligibleEvents, e) + } + } + backwardsQueuedEvents := &revPriorityQueue{priorityQueue: new(priorityQueue(eligibleEvents))} + heap.Init(backwardsQueuedEvents) + + // prune until we fit + for backwardsQueuedEvents.Len() > 0 && + (state.sizeOfQueuedEvents() > maxKeyValueValueBytes || + state.sizeOfBlobHandles() > maxKeyValueValueBytes || + state.sizeOf() > maxKeyValueModifiedKeysPlusValuesBytes) { + toRemove := heap.Pop(backwardsQueuedEvents).(*pb.ConsensusQueueEvent) + //TODO opt: faster delete...but need to maintain state.queuedEvents (though not order)...map indices? + *state.queuedEvents = slices.DeleteFunc(*state.queuedEvents, func(e *pb.ConsensusQueueEvent) bool { return e.TriggerEventID == toRemove.TriggerEventID }) + //TODO opt: drop more than one each time? + } + // rebuild the priority queue + heap.Init(state.queuedEvents) } + // note: no need to prune consensus events, since already limited what we collected + err = state.writeTo(&stateWriter{kv: kvReaderWriter}) if err != nil { return nil, err } - c.triggerQueue.Remove(ctx, queuedTriggerEventIDs) + c.triggerQueue.Remove(ctx, queuedTriggerEventIDs) //TODO move to committed - do we need to write it through KV? or can we Remove the whole PQ every time? // no report to return, executions start when committed return nil, nil @@ -405,8 +467,8 @@ type observations struct { medianCapPerWF map[string]uint32 // wf ID -> capacity newObservedEvents map[string]*pb.ConsensusQueueObservedEvent // key: timeless hash observedBlobs blobHandleMap - warn error - err error + + err error } func (res *observations) aggregate(ctx context.Context, f int, aos []ocrtypes.AttributedObservation) { @@ -420,8 +482,8 @@ func (res *observations) aggregate(ctx context.Context, f int, aos []ocrtypes.At var obs pb.ConsensusQueueObservation err := proto.Unmarshal(ao.Observation, &obs) if err != nil { - res.warn = errors.Join(res.warn, fmt.Errorf("failed to unmarshal observation from oracle %d: %w", ao.Observation, err)) - continue + res.err = fmt.Errorf("failed to unmarshal observation from oracle %d: %w", ao.Observer, err) + return } expirations = append(expirations, obs.Expiration) capacities = append(capacities, obs.Capacity) @@ -437,16 +499,16 @@ func (res *observations) aggregate(ctx context.Context, f int, aos []ocrtypes.At } res.medianExpiration = medianTimestamp(expirations).AsTime() - // Medianize capacities, and when there is disagreement among honest nodes, scale back to 90%. + // If we used median, then honest nodes reporting reduced capacity would not be able to keep up. + // Instead, we use the F+1th lowest value - the least honest value. var medianCount int - res.medianCap, medianCount = median(capacities) - if medianCount < 2*f+1 { - res.medianCap = (res.medianCap * 9) / 10 - } + res.medianCap = slices.Sorted(slices.Values(capacities))[f] for wf, caps := range wfCapacities { - res.medianCapPerWF[wf], medianCount = median(caps) - if medianCount < 2*f+1 { - res.medianCapPerWF[wf] = (res.medianCapPerWF[wf] * 9) / 10 + if len(caps) > 2*f+1 { + res.medianCapPerWF[wf] = slices.Sorted(slices.Values(caps))[f] + if medianCount < 2*f+1 { + res.medianCapPerWF[wf] = (res.medianCapPerWF[wf] * 9) / 10 + } } } return @@ -535,16 +597,7 @@ func (c *consensusQueuePlugin) tryStartExecution(ctx context.Context, fetcher *b return fmt.Errorf("failed to convert CoordinatedEvent from proto: %w", err) } - // TODO c.triggerCoordinator.Deliver(ctx, event) - - // only log metadata, not outputs and payload - event.Event.Event.Outputs = nil - event.Event.Event.Payload = nil - latency := time.Since(event.ObservedAt) - c.lggr.Infow("Consensus event dry run completed", "observedAt", event.ObservedAt, "latency", latency, "event", event) - //TODO emit latency metric - - return nil + return c.triggerCoordinator.StartExecution(ctx, event) } func (c *consensusQueuePlugin) Reports(ctx context.Context, _ uint64, _ ocr3_1types.ReportsPlusPrecursor) ([]ocr3types.ReportPlus[[]byte], error) { diff --git a/core/services/ocr3_1/plugins/queue/queue_test.go b/core/services/ocr3_1/plugins/queue/queue_test.go index 5f5173eca06..9ce9228d4fa 100644 --- a/core/services/ocr3_1/plugins/queue/queue_test.go +++ b/core/services/ocr3_1/plugins/queue/queue_test.go @@ -1,6 +1,8 @@ package queue import ( + "context" + "iter" "testing" "github.com/stretchr/testify/require" @@ -10,6 +12,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/settings/limits" + "github.com/smartcontractkit/chainlink/v2/core/services/workflows/v2/triggers" ) // libocr calls NewReportingPlugin with no recover, so a panic here takes down @@ -18,7 +21,7 @@ func TestConsensusQueuePluginFactory_NewReportingPlugin(t *testing.T) { t.Parallel() cfg := &PluginConfig{Limits: ocr3_1types.ReportingPluginLimits{MaxKeyValueModifiedKeys: 1}} - factory, err := NewConsensusQueuePluginFactory(logger.Test(t), cfg, limits.Factory{}, nil, nil) + factory, err := NewConsensusQueuePluginFactory(logger.Test(t), cfg, limits.Factory{}, noopCoordinator{}, noopQueue{}) require.NoError(t, err) plugin, info, err := factory.NewReportingPlugin(t.Context(), ocr3types.ReportingPluginConfig{N: 4, F: 1}, nil) @@ -32,3 +35,65 @@ func TestConsensusQueuePluginFactory_NewReportingPlugin(t *testing.T) { require.NoError(t, plugin.Close()) } + +type noopCoordinator struct{} + +func (n noopCoordinator) Start(ctx context.Context) error { + return nil +} + +func (n noopCoordinator) Close() error { + return nil +} + +func (n noopCoordinator) Ready() error { + return nil +} + +func (n noopCoordinator) HealthReport() map[string]error { + return map[string]error{} +} + +func (n noopCoordinator) Name() string { + return "NoopTriggerCoordinator" +} + +func (n noopCoordinator) Ack(ctx context.Context, triggerCapID, triggerRegistrationID, eventID string) error { + return nil +} + +func (n noopCoordinator) RegisterTriggers(ctx context.Context, subscriber triggers.Subscriber, params triggers.RegistrationParams) ([]string, error) { + return nil, nil +} + +func (n noopCoordinator) UnregisterTriggers(ctx context.Context, workflowID string) error { + return nil +} + +func (n noopCoordinator) AvailableCapacity(ctx context.Context) (triggers.Capacity, error) { + return triggers.Capacity{}, nil +} + +func (n noopCoordinator) StartExecution(ctx context.Context, event triggers.CoordinatedEvent) error { + return nil +} + +type noopQueue struct{} + +func (n noopQueue) Put(ctx context.Context, event triggers.CoordinatedEvent) error { + return nil +} + +func (n noopQueue) Drain(ctx context.Context) ([]triggers.CoordinatedEvent, error) { + return nil, nil +} + +func (n noopQueue) Stats(ctx context.Context) (triggers.Stats, error) { + return triggers.Stats{}, nil +} + +func (n noopQueue) Sorted() iter.Seq[triggers.CoordinatedEvent] { + return func(yield func(triggers.CoordinatedEvent) bool) {} +} + +func (n noopQueue) Remove(ctx context.Context, triggerEventIDs []string) {} diff --git a/core/services/workflows/v2/triggers/coordinator.go b/core/services/workflows/v2/triggers/coordinator.go index 27a7691ac74..f12ced66992 100644 --- a/core/services/workflows/v2/triggers/coordinator.go +++ b/core/services/workflows/v2/triggers/coordinator.go @@ -84,7 +84,8 @@ type Coordinator interface { // limiter does not break down by scope. AvailableCapacity(ctx context.Context) (Capacity, error) - //TODO Deliver(context.Context, CoordinatedEvent + // StartExecution starts execution of the triggered event or returns an error. + StartExecution(context.Context, CoordinatedEvent) error } // RegisteredEngine is what EngineRegistry.Get returns: a sink the coordinator @@ -478,6 +479,35 @@ func (c *coordinator) Ack(ctx context.Context, triggerCapID, triggerRegistration return Ack(ctx, lggr, wfMetrics, triggerCapID, triggerRegistrationID, eventID, handle) } +func (c *coordinator) StartExecution(ctx context.Context, event CoordinatedEvent) error { + wfID, err := types.WorkflowIDFromHex(event.WorkflowID) + if err != nil { + return err + } + + //TODO share code with admitEvent? + + eng, ok := c.engines.Get(wfID) + if !ok { + return fmt.Errorf("workflow %s: engine not found", wfID) + } + if !eng.IsCoordinated() { + return fmt.Errorf("workflow %s: engine not coordinated", wfID) + } + + //TODO more admission checks? + // c.admission.ExecutionConcurrency.Wait(ctx, 1)? + + _ = time.Since(event.ObservedAt) //TODO emit latency metric + + if err = eng.ExecuteTrigger(ctx, event); err != nil { + //TODO handle errors, ack? + return fmt.Errorf("workflow %s: failed to execute trigger %s: %w", wfID, event.Event.Event.ID, err) + } + + return nil +} + // close runs after the reader and release goroutines exit. // It unregisters any triggers still in a pending state before returning. func (c *coordinator) close() error { @@ -634,7 +664,7 @@ func (c *coordinator) admit(ctx context.Context, cw *coordinatedWorkflow) { eventAge := now.Sub(event.ObservedAt) cw.lggr.Debugw("Popped a trigger event from the queue", "eventID", event.Event.Event.ID, "eventAgeMs", eventAge.Milliseconds()) tm.RecordTriggerEventQueueWaitSeconds(ctx, eventAge.Seconds()) - if now.After(event.Deadline) { + if now.After(event.Deadline) { //TODO grace period cw.lggr.Warnw("Trigger event is too old, skipping execution", "triggerID", event.TriggerCapID, "eventID", event.Event.Event.ID, "eventAgeMs", eventAge.Milliseconds()) tm.IncrementTriggerEventExpiredCounter(ctx) tm.IncrementTriggerEventDroppedTotal(ctx, monitoring.TriggerDropReasonExpired) diff --git a/core/services/workflows/v2/triggers/queue.go b/core/services/workflows/v2/triggers/queue.go index a8f9585ef0f..35643d60577 100644 --- a/core/services/workflows/v2/triggers/queue.go +++ b/core/services/workflows/v2/triggers/queue.go @@ -172,6 +172,9 @@ func (q *CentralQueue) Sorted() iter.Seq[CoordinatedEvent] { type coordinatedEventHeap []CoordinatedEvent func (c *coordinatedEventHeap) Len() int { + if c == nil { + return 0 + } return len(*c) }