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 531d18eeaa4..cc9cacfb536 100644 --- a/core/services/ocr2/delegate.go +++ b/core/services/ocr2/delegate.go @@ -61,6 +61,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" @@ -87,18 +88,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" - consensusQueueOCRConfigKey = "consensus-queue" + consensusQueueCapabilityID = internal.ConsensusQueueCapabilityID gaugeConsensusQueueBytes = "platform_consensus_queue_usage_bytes" consensusQueueDiskMonitorTickInterval = time.Minute ) @@ -821,7 +821,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 { @@ -849,7 +853,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) { @@ -882,8 +886,7 @@ 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) + configTracker, configDigester, lc, err := d.maybeWrapConfigService(consensusQueueCapabilityID, capabilitiespb.OCR3ConfigDefaultKey, lggr, provider.ContractConfigTracker(), provider.OffchainConfigDigester(), lc) if err != nil { return nil, err } @@ -892,7 +895,7 @@ func (d *Delegate) newServicesConsensusQueue( BinaryNetworkEndpointFactory: d.peerWrapper.Peer3_1, V2Bootstrappers: bootstrapPeers, ContractConfigTracker: configTracker, - ContractTransmitter: nil, // TODO ticket transmitter + ContractTransmitter: queue.NewTransmitter(lggr, ocrtypes.Account(spec.TransmitterID.String)), Database: ocrDB, KeyValueDatabaseFactory: kvFactory, LocalConfig: lc, @@ -904,7 +907,7 @@ func (d *Delegate) newServicesConsensusQueue( 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..0cdf2ec0086 --- /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..c5060f5fead 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,86 @@ 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", + }.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/queue_test.go b/core/services/ocr3_1/plugins/queue/queue_test.go new file mode 100644 index 00000000000..f5b83690325 --- /dev/null +++ b/core/services/ocr3_1/plugins/queue/queue_test.go @@ -0,0 +1,34 @@ +package queue + +import ( + "testing" + + "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3_1types" + "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/settings/limits" +) + +// libocr calls NewReportingPlugin with no recover, so a panic here takes down +// the whole node. This guards the constructor and the plugin lifecycle. +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{}) + require.NoError(t, err) + + plugin, info, err := factory.NewReportingPlugin(t.Context(), ocr3types.ReportingPluginConfig{N: 4, F: 1}, nil) + require.NoError(t, err) + require.NotNil(t, plugin) + + info1, ok := info.(ocr3_1types.ReportingPluginInfo1) + require.True(t, ok, "unexpected ReportingPluginInfo type %T", info) + require.Equal(t, "ConsensusQueueReportingPlugin", info1.Name) + require.Equal(t, cfg.Limits, info1.Limits) + + require.NoError(t, plugin.Close()) +} 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..4c9b94187c5 --- /dev/null +++ b/core/services/ocr3_1/plugins/queue/transmitter.go @@ -0,0 +1,30 @@ +package queue + +import ( + "context" + + "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" + ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" +) + +type contractTransmitter struct { + lggr logger.Logger + fromAccount ocrtypes.Account +} + +func NewTransmitter(lggr logger.Logger, fromAccount ocrtypes.Account) ocr3types.ContractTransmitter[[]byte] { + return &contractTransmitter{ + lggr: lggr, + fromAccount: fromAccount, + } +} + +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 735a2fc2836..3d584f10079 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" @@ -185,6 +187,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..898fc65f1fd 100644 --- a/deployment/cre/jobs/propose_job_spec_test.go +++ b/deployment/cre/jobs/propose_job_spec_test.go @@ -231,6 +231,28 @@ func TestProposeJobSpec_VerifyPreconditions(t *testing.T) { expectError: true, errorMsg: "unsupported template", }, + { + name: "valid consensus-queue job", + input: jobs.ProposeJobSpecInput{ + Environment: test.EnvironmentName, + JobName: "consensus-queue-worker", + Domain: "cre", + DONName: "test-don", + DONFilters: []offchain.TargetDONFilter{ + {Key: offchain.FilterKeyDONName, Value: "d"}, + {Key: "environment", Value: "e"}, + {Key: "product", Value: offchain.ProductLabel}, + }, + Template: job_types.OCR3, + Inputs: job_types.JobSpecInput{ + "templateName": "consensus-queue", + "contractQualifier": "consensus-queue", + "chainSelectorEVM": "3379446385462418246", + "bootstrapperOCR3Urls": []string{"12D3KooWHfYFQ8hGttAYbMCevQVESEQhzJAqFZokMVtom8bNxwGq@127.0.0.1:5001"}, + }, + }, + expectError: false, + }, { name: "missing inputs", input: jobs.ProposeJobSpecInput{ @@ -1386,6 +1408,70 @@ func TestProposeJobSpec_Apply(t *testing.T) { } }) + t.Run("successful consensus-queue ocr3 job distribution", func(t *testing.T) { + h2 := test.NewTestHarness(t) + env2 := new(h2.Runtime.Environment()) + + chainSelector := h2.RegistrySelector + ds := datastore.NewMemoryDataStore() + err := ds.Addresses().Add(datastore.AddressRef{ + ChainSelector: chainSelector, + Type: datastore.ContractType(ocr3.OCR3Capability), + Version: semver.MustParse("1.0.0"), + Address: "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B", + Qualifier: "consensus-queue", + }) + require.NoError(t, err) + env2.DataStore = ds.Seal() + + input := jobs.ProposeJobSpecInput{ + Environment: test.EnvironmentName, + Domain: "cre", + JobName: "consensus-queue-worker", + DONName: test.DONName, + Template: job_types.OCR3, + DONFilters: []offchain.TargetDONFilter{ + {Key: offchain.FilterKeyDONName, Value: test.DONName}, + {Key: "environment", Value: test.EnvironmentName}, + {Key: "product", Value: offchain.ProductLabel}, + }, + Inputs: job_types.JobSpecInput{ + "templateName": "consensus-queue", + "contractQualifier": "consensus-queue", + "chainSelectorEVM": strconv.FormatUint(chainSelector, 10), + "bootstrapperOCR3Urls": []string{ + "12D3KooWHfYFQ8hGttAYbMCevQVESEQhzJAqFZokMVtom8bNxwGq@127.0.0.1:5001", + }, + }, + } + + out, err := jobs.ProposeJobSpec{}.Apply(*env2, input) + require.NoError(t, err) + assert.Len(t, out.Reports, 1) + + reqs, err := h2.TestJD.ListProposedJobRequests() + require.NoError(t, err) + + found := 0 + for _, req := range reqs { + if !strings.Contains(req.Spec, `pluginType = "consensus-queue"`) { + continue + } + found++ + assert.Contains(t, req.Spec, `type = "offchainreporting2"`) + assert.Contains(t, req.Spec, `name = "consensus-queue-worker`) + assert.Contains(t, req.Spec, `contractID = "0xAb5801a7D398351b8bE11C439e05C5B3259aeC9B"`) + assert.Contains(t, req.Spec, `p2pv2Bootstrappers = [ + "12D3KooWHfYFQ8hGttAYbMCevQVESEQhzJAqFZokMVtom8bNxwGq@127.0.0.1:5001", +]`) + assert.Contains(t, req.Spec, `relay = "evm"`) + assert.Contains(t, req.Spec, fmt.Sprintf(`chainID = "%d"`, chainsel.TEST_90000001.EvmChainID)) + assert.Contains(t, req.Spec, `ocrKeyBundleID = "`) + assert.Contains(t, req.Spec, `transmitterID = "`) + } + require.Positive(t, found, "no consensus-queue job spec was proposed") + }) + t.Run("successful consensus job distribution", func(t *testing.T) { chainSelector := h.RegistrySelector ds := datastore.NewMemoryDataStore() diff --git a/system-tests/lib/cre/contracts/keystone.go b/system-tests/lib/cre/contracts/keystone.go index 3f50c05a8b7..94d930b8796 100644 --- a/system-tests/lib/cre/contracts/keystone.go +++ b/system-tests/lib/cre/contracts/keystone.go @@ -29,6 +29,7 @@ import ( cap_reg_v2_seq "github.com/smartcontractkit/chainlink/deployment/cre/capabilities_registry/v2/changeset/sequences" cre_contracts "github.com/smartcontractkit/chainlink/deployment/cre/contracts" "github.com/smartcontractkit/chainlink/deployment/cre/ocr3" + "github.com/smartcontractkit/chainlink/deployment/cre/ocr3/ocr3_1" keystone_changeset "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" ks_contracts_op "github.com/smartcontractkit/chainlink/deployment/keystone/changeset/operations/contracts" libc "github.com/smartcontractkit/chainlink/system-tests/lib/conversions" @@ -126,6 +127,49 @@ func (d *dons) donsOrderedByID() []donConfig { func (d *dons) embedOCR3Config(capConfig *capabilitiespb.CapabilityConfig, don donConfig, registryChainSelector uint64, oracleConfig *ocr3.OracleConfig, extraSignerFamilies []string) error { oracleConfig.TransmissionSchedule = []int{len(don.Nops[0].Nodes)} + nodes, err := d.donNodeInfo(don) + if err != nil { + return err + } + + ocrConfig, err := ocr3.GenerateOCR3ConfigFromNodes(*oracleConfig, nodes, registryChainSelector, d.env.OCRSecrets, nil, extraSignerFamilies) + if err != nil { + return fmt.Errorf("failed to generate OCR3 config: %w", err) + } + + setDefaultOCR3ConfigProto(capConfig, ocrConfig) + return nil +} + +// embedOCR3_1Config is the OCR 3.1 version of embedOCR3Config. +// The node's OCR 3.1 oracle only accepts offchain config version 310, which is +// what GenerateOCR3_1ConfigFromNodes writes. +func (d *dons) embedOCR3_1Config(capConfig *capabilitiespb.CapabilityConfig, don donConfig, registryChainSelector uint64, oracleConfig *ocr3_1.V3_1OracleConfig, extraSignerFamilies []string) error { + oracleConfig.TransmissionSchedule = []int{len(don.Nops[0].Nodes)} + + nodes, err := d.donNodeInfo(don) + if err != nil { + return err + } + + // Vault and DKG carry their plugin config in the OCR offchain config. + // Other OCR 3.1 plugins read it from the job spec, so it stays empty here. + // Empty but not nil, because nil makes the generator ask for a Vault or DKG config. + var pluginConfig []byte + if oracleConfig.VaultOffchainConfig == nil && oracleConfig.DKGOffchainConfig == nil { + pluginConfig = []byte{} + } + + ocrConfig, err := ocr3_1.GenerateOCR3_1ConfigFromNodes(*oracleConfig, nodes, registryChainSelector, d.env.OCRSecrets, pluginConfig, extraSignerFamilies) + if err != nil { + return fmt.Errorf("failed to generate OCR3_1 config: %w", err) + } + + setDefaultOCR3ConfigProto(capConfig, ocrConfig) + return nil +} + +func (d *dons) donNodeInfo(don donConfig) ([]deployment.Node, error) { var allNodeIDs []string for _, nop := range don.Nops { allNodeIDs = append(allNodeIDs, nop.Nodes...) @@ -133,20 +177,23 @@ func (d *dons) embedOCR3Config(capConfig *capabilitiespb.CapabilityConfig, don d nodes, err := deployment.NodeInfo(allNodeIDs, d.offChain) if err != nil { - return fmt.Errorf("failed to get node info: %w", err) - } - - ocrConfig, err := ocr3.GenerateOCR3ConfigFromNodes(*oracleConfig, nodes, registryChainSelector, d.env.OCRSecrets, nil, extraSignerFamilies) - if err != nil { - return fmt.Errorf("failed to generate OCR3 config: %w", err) + return nil, fmt.Errorf("failed to get node info: %w", err) } + return nodes, nil +} +// setDefaultOCR3ConfigProto writes ocrConfig under the default key, which is the +// key the node reads for single-instance capabilities. +func setDefaultOCR3ConfigProto(capConfig *capabilitiespb.CapabilityConfig, ocrConfig ocr3.OCR2OracleConfig) { transmitterBytes := make([][]byte, len(ocrConfig.Transmitters)) for i, t := range ocrConfig.Transmitters { transmitterBytes[i] = t.Bytes() } - ocr3Proto := &capabilitiespb.OCR3Config{ + if capConfig.Ocr3Configs == nil { + capConfig.Ocr3Configs = make(map[string]*capabilitiespb.OCR3Config) + } + capConfig.Ocr3Configs[capabilitiespb.OCR3ConfigDefaultKey] = &capabilitiespb.OCR3Config{ Signers: ocrConfig.Signers, Transmitters: transmitterBytes, F: uint32(ocrConfig.F), @@ -155,16 +202,9 @@ func (d *dons) embedOCR3Config(capConfig *capabilitiespb.CapabilityConfig, don d OffchainConfig: ocrConfig.OffchainConfig, ConfigCount: 1, } - - if capConfig.Ocr3Configs == nil { - capConfig.Ocr3Configs = make(map[string]*capabilitiespb.OCR3Config) - } - capConfig.Ocr3Configs[capabilitiespb.OCR3ConfigDefaultKey] = ocr3Proto - - return nil } -func (d *dons) mustToV2ConfigureInput(chainSelector uint64, contractAddress string, capabilityToOCR3Config map[string]*ocr3.OracleConfig, capabilityToExtraSignerFamilies map[string][]string) cap_reg_v2_seq.ConfigureCapabilitiesRegistryInput { +func (d *dons) mustToV2ConfigureInput(chainSelector uint64, contractAddress string, capabilityToOCR3Config map[string]*ocr3.OracleConfig, capabilityToOCR3_1Config map[string]*ocr3_1.V3_1OracleConfig, capabilityToExtraSignerFamilies map[string][]string) cap_reg_v2_seq.ConfigureCapabilitiesRegistryInput { nodes := make([]contracts.NodesInput, 0) orderedDons := d.donsOrderedByID() donParams := make([]capabilities_registry_v2.CapabilitiesRegistryNewDONParams, len(orderedDons)) @@ -253,12 +293,21 @@ func (d *dons) mustToV2ConfigureInput(chainSelector uint64, contractAddress stri } shouldMarshalProtoConfig = true - ocrConfig := capabilityToOCR3Config[cap.Capability.LabelledName] - if ocrConfig == nil { - panic("no OCR3 config found for capability " + cap.Capability.LabelledName) - } - if err := d.embedOCR3Config(capConfig, don, chainSelector, ocrConfig, capabilityToExtraSignerFamilies[cap.Capability.LabelledName]); err != nil { - panic(fmt.Sprintf("failed to embed OCR3 config for capability %s: %s", cap.Capability.LabelledName, err)) + name := cap.Capability.LabelledName + extraSignerFamilies := capabilityToExtraSignerFamilies[name] + ocr3_1Config := capabilityToOCR3_1Config[name] + ocrConfig := capabilityToOCR3Config[name] + switch { + case ocr3_1Config != nil: + if err := d.embedOCR3_1Config(capConfig, don, chainSelector, ocr3_1Config, extraSignerFamilies); err != nil { + panic(fmt.Sprintf("failed to embed OCR3_1 config for capability %s: %s", name, err)) + } + case ocrConfig != nil: + if err := d.embedOCR3Config(capConfig, don, chainSelector, ocrConfig, extraSignerFamilies); err != nil { + panic(fmt.Sprintf("failed to embed OCR3 config for capability %s: %s", name, err)) + } + default: + panic("no OCR3 or OCR3_1 config found for capability " + name) } } @@ -467,7 +516,7 @@ func ExecuteConfigureCapabilitiesRegistry(input cre.ConfigureCapabilityRegistryI if dErr != nil { return nil, errors.Wrap(dErr, "failed to map input to dons") } - contractInput := dons.mustToV2ConfigureInput(input.ChainSelector, input.CapabilitiesRegistryAddress.Hex(), input.CapabilityToOCR3Config, input.CapabilityToExtraSignerFamilies) + contractInput := dons.mustToV2ConfigureInput(input.ChainSelector, input.CapabilitiesRegistryAddress.Hex(), input.CapabilityToOCR3Config, input.CapabilityToOCR3_1Config, input.CapabilityToExtraSignerFamilies) _, seqErr := operations.ExecuteSequence( input.CldEnv.OperationsBundle, cap_reg_v2_seq.ConfigureCapabilitiesRegistry, diff --git a/system-tests/lib/cre/contracts/keystone_test.go b/system-tests/lib/cre/contracts/keystone_test.go index c2e07df5f97..abd1a689402 100644 --- a/system-tests/lib/cre/contracts/keystone_test.go +++ b/system-tests/lib/cre/contracts/keystone_test.go @@ -216,7 +216,7 @@ func TestToV2ConfigureInput(t *testing.T) { }, } - result := d.mustToV2ConfigureInput(chainSel, "0x1234567890abcdef", nil, nil) + result := d.mustToV2ConfigureInput(chainSel, "0x1234567890abcdef", nil, nil, nil) require.Equal(t, chainSel, result.RegistryChainSel) diff --git a/system-tests/lib/cre/don.go b/system-tests/lib/cre/don.go index 46d0ed9d43e..ef145b2177c 100644 --- a/system-tests/lib/cre/don.go +++ b/system-tests/lib/cre/don.go @@ -939,14 +939,19 @@ func LinkToJobDistributor(ctx context.Context, input *LinkDonsToJDInput) error { return nil } -// copied from flags package to avoid circular dependency +// HasFlag reports whether values holds capability, either bare or with a +// chain ID suffix such as "evm-1337". The suffix must be numeric, so +// "consensus" does not match "consensus-queue". func HasFlag(values []string, capability string) bool { - if slices.Contains(values, capability) { - return true - } - for _, value := range values { - if strings.HasPrefix(value, capability+"-") { + if value == capability { + return true + } + suffix, ok := strings.CutPrefix(value, capability+"-") + if !ok { + continue + } + if _, err := strconv.ParseUint(suffix, 10, 64); err == nil { return true } } diff --git a/system-tests/lib/cre/environment/environment.go b/system-tests/lib/cre/environment/environment.go index bcd91e893f2..e0fe5a5a420 100644 --- a/system-tests/lib/cre/environment/environment.go +++ b/system-tests/lib/cre/environment/environment.go @@ -24,6 +24,7 @@ import ( "github.com/smartcontractkit/chainlink-testing-framework/framework/components/jd" "github.com/smartcontractkit/chainlink-testing-framework/framework/components/s3provider" "github.com/smartcontractkit/chainlink/deployment/cre/ocr3" + "github.com/smartcontractkit/chainlink/deployment/cre/ocr3/ocr3_1" keystone_changeset "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" "github.com/smartcontractkit/chainlink/system-tests/lib/cre" crecontracts "github.com/smartcontractkit/chainlink/system-tests/lib/cre/contracts" @@ -180,6 +181,7 @@ func SetupTestEnvironment( fmt.Print(libformat.PurpleText("%s", input.StageGen.Wrap("Applying Features before environment startup"))) var donsCapabilities = make(map[uint64][]keystone_changeset.DONCapabilityWithConfig) var capabilityToOCR3Config = make(map[string]*ocr3.OracleConfig) + capabilityToOCR3_1Config := make(map[string]*ocr3_1.V3_1OracleConfig) capabilityToExtraSignerFamilies := make(map[string][]string) for _, feature := range input.Features.List() { for _, donMetadata := range topology.DonsMetadataWithFlag(feature.Flag()) { @@ -200,6 +202,7 @@ func SetupTestEnvironment( } donsCapabilities[donMetadata.ID] = append(donsCapabilities[donMetadata.ID], output.DONCapabilityWithConfig...) maps.Copy(capabilityToOCR3Config, output.CapabilityToOCR3Config) + maps.Copy(capabilityToOCR3_1Config, output.CapabilityToOCR3_1Config) for capability, families := range output.CapabilityToExtraSignerFamilies { capabilityToExtraSignerFamilies[capability] = append([]string(nil), families...) } @@ -347,6 +350,7 @@ func SetupTestEnvironment( NodeSets: input.NodeSets, DONCapabilityWithConfigs: make(map[uint64][]keystone_changeset.DONCapabilityWithConfig), CapabilityToOCR3Config: capabilityToOCR3Config, + CapabilityToOCR3_1Config: capabilityToOCR3_1Config, CapabilityToExtraSignerFamilies: capabilityToExtraSignerFamilies, } 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..34b595d5891 --- /dev/null +++ b/system-tests/lib/cre/features/queue/queue.go @@ -0,0 +1,184 @@ +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" + "github.com/smartcontractkit/chainlink/deployment/cre/jobs/pkg" + job_types "github.com/smartcontractkit/chainlink/deployment/cre/jobs/types" + "github.com/smartcontractkit/chainlink/deployment/cre/ocr3/ocr3_1" + ocr3_changeset "github.com/smartcontractkit/chainlink/deployment/cre/ocr3/v2/changeset" + "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 + } + + workers, err := don.Workers() + if err != nil { + return nil, fmt.Errorf("failed to get workers for DON %s: %w", don.Name, err) + } + + 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, + }}, + // The plugin runs on the OCR 3.1 oracle, which rejects OCR3 (version 30) offchain configs. + CapabilityToOCR3_1Config: map[string]*ocr3_1.V3_1OracleConfig{ + consensusQueueLabelledName: contracts.DefaultOCR3_1Config(len(workers)), + }, + }, 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 + } + + if err := deployContract(creEnv, testLogger); err != nil { + return fmt.Errorf("failed to deploy consensusQueue OCR3 contract: %w", err) + } + + err := createJobs(ctx, creEnv, don, dons) + if err != nil { + return fmt.Errorf("failed to create consensusQueue jobs: %w", err) + } + // TODO more? + return nil +} + +// deployContract deploys the OCR3 contract the job spec uses as its contractID. +// The OCR config itself comes from the Capabilities Registry. +func deployContract(creEnv *cre.Environment, testLogger zerolog.Logger) error { + input := ocr3_changeset.DeployOCR3Input{ + ChainSelector: creEnv.RegistryChainSelector, + Qualifier: cre.ConsensusQueueCapability, + Labels: []string{cre.ConsensusQueueCapability}, + } + if err := (ocr3_changeset.DeployOCR3{}).VerifyPreconditions(*creEnv.CldfEnvironment, input); err != nil { + return errors.Wrap(err, "precondition verification failed") + } + out, err := (ocr3_changeset.DeployOCR3{}).Apply(*creEnv.CldfEnvironment, input) + if err != nil { + return err + } + contracts.MergeAllDataStores(creEnv, out) + + refKey := pkg.GetOCR3CapabilityAddressRefKey(creEnv.RegistryChainSelector, cre.ConsensusQueueCapability) + addrRef, err := creEnv.CldfEnvironment.DataStore.Addresses().Get(refKey) + if err != nil { + return errors.Wrap(err, "failed to get deployed contract address") + } + testLogger.Info().Msgf("Deployed consensus-queue OCR3 contract on chain %d at %s", creEnv.RegistryChainSelector, addrRef.Address) + 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() + } + err = (cre_jobs.ProposeJobSpec{}).VerifyPreconditions(*creEnv.CldfEnvironment, input) + if 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/flags.go b/system-tests/lib/cre/flags/flags.go index 126dd44c01f..5532161f200 100644 --- a/system-tests/lib/cre/flags/flags.go +++ b/system-tests/lib/cre/flags/flags.go @@ -3,7 +3,6 @@ package flags import ( "slices" "strconv" - "strings" "github.com/pkg/errors" @@ -28,17 +27,7 @@ func HasFlagForChain(values []string, capability string, chainID uint64) bool { } func HasFlagForAnyChain(values []string, capability string) bool { - if slices.Contains(values, capability) { - return true - } - - for _, value := range values { - if strings.HasPrefix(value, capability+"-") { - return true - } - } - - return false + return cre.HasFlag(values, capability) } func RequiresForwarderContract(values []string, chainID uint64) bool { diff --git a/system-tests/lib/cre/flags/flags_test.go b/system-tests/lib/cre/flags/flags_test.go index d9d74d146b1..557d4089a9f 100644 --- a/system-tests/lib/cre/flags/flags_test.go +++ b/system-tests/lib/cre/flags/flags_test.go @@ -23,3 +23,28 @@ func TestRequiresForwarderContract(t *testing.T) { require.True(t, RequiresForwarderContract([]string{cre.StellarCapability}, 0)) }) } + +func TestHasFlagForAnyChain(t *testing.T) { + t.Parallel() + + values := []string{cre.ConsensusQueueCapability, cre.EVMCapability + "-1337", cre.CronCapability} + + tests := []struct { + name string + capability string + want bool + }{ + {"exact match", cre.CronCapability, true}, + {"exact match with a hyphen in the name", cre.ConsensusQueueCapability, true}, + {"chain ID suffix", cre.EVMCapability, true}, + {"non-numeric suffix is a different flag", cre.ConsensusCapability, false}, + {"absent", cre.VaultCapability, false}, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + require.Equal(t, tt.want, HasFlagForAnyChain(values, tt.capability)) + require.Equal(t, tt.want, cre.HasFlag(values, tt.capability)) + }) + } +} 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..d2ff5236f4e 100644 --- a/system-tests/lib/cre/types.go +++ b/system-tests/lib/cre/types.go @@ -31,6 +31,7 @@ import ( ks_sol "github.com/smartcontractkit/chainlink/deployment/cre/forwarder/solana" ks_stellar "github.com/smartcontractkit/chainlink/deployment/cre/forwarder/stellar" "github.com/smartcontractkit/chainlink/deployment/cre/ocr3" + "github.com/smartcontractkit/chainlink/deployment/cre/ocr3/ocr3_1" keystone_changeset "github.com/smartcontractkit/chainlink/deployment/keystone/changeset" "github.com/smartcontractkit/chainlink/system-tests/lib/cre/don/secrets" "github.com/smartcontractkit/chainlink/system-tests/lib/cre/environment/blockchains" @@ -66,6 +67,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 @@ -366,6 +368,10 @@ type ConfigureCapabilityRegistryInput struct { // keyed by LabelledName CapabilityToOCR3Config map[string]*ocr3.OracleConfig + // keyed by LabelledName. For capabilities that run an OCR 3.1 plugin. + // An entry here is used instead of CapabilityToOCR3Config. + CapabilityToOCR3_1Config map[string]*ocr3_1.V3_1OracleConfig + // keyed by LabelledName. Non-EVM chain families whose signing keys should be // included in OCR3 config signers for that capability (e.g. ["solana"]). // EVM is always included. @@ -777,7 +783,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 { @@ -1744,6 +1750,8 @@ type PreEnvStartupOutput struct { DONCapabilityWithConfig []keystone_changeset.DONCapabilityWithConfig // keyed by LabelledName CapabilityToOCR3Config map[string]*ocr3.OracleConfig + // keyed by LabelledName. For capabilities that run an OCR 3.1 plugin. + CapabilityToOCR3_1Config map[string]*ocr3_1.V3_1OracleConfig // keyed by LabelledName. Non-EVM chain families whose signing keys should be // included in OCR3 config signers for that capability (e.g. ["solana"]). // EVM is always included.