Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.20261117180805-a2fb88ff3710
github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118204812-c2cd552dc1f2
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
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 33 additions & 15 deletions core/services/workflows/v2/base_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ type baseEngine struct {
// tracer is the OTel tracer for this engine. It's a noop tracer when DebugMode is false.
tracer trace.Tracer

usageMeter *resourcemanager.ResourceManager
usageIdentity resourcemanager.ResourceIdentity
orgID string
usageMeter *resourcemanager.ResourceManager
baseUsageIdentity resourcemanager.ResourceIdentity
orgID string
// orgIDMissingReason records why orgID is empty ("resolver_nil",
// "resolver_error", or "empty_response"). It is set once in startWith() and
// read by startExecution() to label the org_id_missing counter. It is only
Expand Down Expand Up @@ -197,9 +197,7 @@ func newBaseEngine(cfg *EngineConfig, engineMode string) (*baseEngine, logger.Su
engine.metrics = metricsLabeler
// Disabled metering is a no-op inside the resource manager.
engine.usageMeter = resourcemanager.NewResourceManager(cfg.Lggr, resourcemanager.ResourceManagerConfig{MeterRecordsEnabled: cfg.MeterRecordsEnabled, Emitter: cfg.UsageEmitter, Settings: cfg.LocalLimiters.Settings})
engine.usageIdentity = resourcemanager.WithWorkflowUsagePool(
resourcemanager.NewBaseIdentity(cfg.MeteringIdentity, resourcemanager.EmittingServiceWorkflowEngine, ""),
resourcemanager.ResourceTypeWorkflowCompute)
engine.baseUsageIdentity = resourcemanager.NewBaseIdentity(cfg.MeteringIdentity, resourcemanager.EmittingServiceWorkflowEngine, "")
engine.loggerLabels.Store(&labelsMap)
engine.localNode.Store(&localNode)

Expand Down Expand Up @@ -811,7 +809,7 @@ func (e *baseEngine) startExecution(ctx context.Context, event triggers.Coordina
computeDuration = time.Duration(result.GetComputeDurationMs()) * time.Millisecond
}

e.emitComputeUsage(ctx, executionLogger, executionID, computeDuration)
e.emitComputeUsage(ctx, executionLogger, tid, executionID, computeDuration)

if isMetering {
computeUnit := billing.ResourceType_name[int32(billing.ResourceType_RESOURCE_TYPE_COMPUTE)]
Expand Down Expand Up @@ -1161,11 +1159,18 @@ func resolveOrgID(ctx context.Context, resolver orgresolver.OrgResolver, workflo
return resolvedOrg{ID: orgID}
}

// emitComputeUsage emits the cre:workflow:compute usage MeterRecord for one
// execution and logs the emission. The log line is a contract consumed by the
// billing reconciler (fields: executionID, eventID, resourceType, value, orgID)
// and must stay stable. Fail-open: never returns an error to the execution.
func (e *baseEngine) emitComputeUsage(ctx context.Context, lggr logger.Logger, executionID string, computeDuration time.Duration) {
// computeResourceTyper is implemented by modules whose executions bill under
// a non-default compute resource type.
type computeResourceTyper interface {
ComputeResourceType() string
}

// emitComputeUsage emits the compute usage MeterRecord for one execution and
// logs the emission. The record carries the routed runner's usage identity
// when it declares one. The log line is a contract consumed by the billing
// reconciler (fields: executionID, eventID, resourceType, value, orgID) and
// must stay stable. Fail-open: never returns an error to the execution.
func (e *baseEngine) emitComputeUsage(ctx context.Context, lggr logger.Logger, triggerIndex uint64, executionID string, computeDuration time.Duration) {
Comment thread
DylanTinianov marked this conversation as resolved.
Resolved
if !e.cfg.MeterRecordsEnabled {
return
}
Expand All @@ -1174,21 +1179,34 @@ func (e *baseEngine) emitComputeUsage(ctx context.Context, lggr logger.Logger, e
lggr.Errorw("Compute usage meter record not emitted", "err", err)
return
}
identity := e.usageIdentity
// The routed module's compute resource type, when it declares one.
resourceType := resourcemanager.ResourceTypeWorkflowCompute
Comment thread
DylanTinianov marked this conversation as resolved.
Resolved
if router, ok := e.cfg.Module.(workflowhost.TriggerRouter); ok {
if m, found := router.RoutedModule(triggerIndex); found {
if t, ok := m.(computeResourceTyper); ok {
resourceType = t.ComputeResourceType()
}
} else {
// Trigger events only flow after Subscribe, so this should be
// unreachable; a miss would mislabel the record as ordinary compute.
lggr.Errorw("Execution's trigger has no routed module; metering as ordinary compute", "triggerIndex", triggerIndex)
}
}
identity := resourcemanager.WithWorkflowUsagePool(e.baseUsageIdentity, resourceType)
if node := e.localNode.Load(); node != nil {
identity = identity.WithDonID(strconv.FormatUint(uint64(node.WorkflowDON.ID), 10))
}
valueMs := computeDuration.Milliseconds()
// The capability event id for compute is the execution id itself: one
// compute record per execution, identical on every node of the DON.
e.usageMeter.EmitUsage(ctx, identity, executionID, valueMs, resourcemanager.UtilizationFields{
ResourceType: resourcemanager.ResourceTypeWorkflowCompute,
ResourceType: resourceType,
ResourceID: resourceID,
OrgID: e.orgID,
})
lggr.Infow("Emitted capability usage meter record",
"eventID", executionID,
"resourceType", resourcemanager.ResourceTypeWorkflowCompute,
"resourceType", resourceType,
"value", valueMs,
"orgID", e.orgID,
)
Expand Down
2 changes: 2 additions & 0 deletions core/services/workflows/v2/compute_usage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ func TestEngine_ComputeUsageMeterRecord_ConfidentialRun(t *testing.T) {
records := emitter.all()
require.Len(t, records, 1)
u := records[0].GetUtilizations()[0]
require.Equal(t, resourcemanager.ResourceTypeWorkflowConfidentialCompute, u.GetResourceType())
require.Equal(t, resourcemanager.ResourceTypeWorkflowConfidentialCompute, records[0].GetIdentity().GetResourcePoolId())
require.Equal(t, cfg.WorkflowID+":"+executionID, u.GetResourceId())
require.Equal(t, "1234", u.GetValue(), "enclave-measured duration, not the round trip")
}
7 changes: 7 additions & 0 deletions core/services/workflows/v2/confidential_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/capabilities/registry"
confworkflowtypes "github.com/smartcontractkit/chainlink-common/pkg/capabilities/v2/actions/confidentialworkflow"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/resourcemanager"
"github.com/smartcontractkit/chainlink-common/pkg/settings"
"github.com/smartcontractkit/chainlink-common/pkg/settings/cresettings"
"github.com/smartcontractkit/chainlink-common/pkg/settings/limits"
Expand Down Expand Up @@ -94,6 +95,12 @@ func errorTypeFor(err error) string {

var _ host.RequirementEnforcingModule = (*ConfidentialModule)(nil)
var _ host.RestrictionAwareModule = (*ConfidentialModule)(nil)
var _ computeResourceTyper = (*ConfidentialModule)(nil)

// ComputeResourceType is the resource type the module's executions bill under.
func (m *ConfidentialModule) ComputeResourceType() string {
return resourcemanager.ResourceTypeWorkflowConfidentialCompute
}

func NewConfidentialModule(capRegistry registry.CapabilitiesRegistry, executionHandlers *confidentialrelay.ExecutionHandlers, binaryURL string, binaryHash []byte, workflowID, workflowOwner, workflowName, workflowTag string, resolveOrgID func(ctx context.Context, owner string) (string, error), enabledGate limits.GateLimiter, creSettingsGetter settings.Getter, lggr logger.Logger) (*ConfidentialModule, error) {
if enabledGate == nil {
Expand Down
2 changes: 1 addition & 1 deletion deployment/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.20261117180805-a2fb88ff3710
github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118204812-c2cd552dc1f2
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
Expand Down
4 changes: 2 additions & 2 deletions deployment/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.20261117180805-a2fb88ff3710
github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118204812-c2cd552dc1f2
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
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.20261117180805-a2fb88ff3710
github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118204812-c2cd552dc1f2
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
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion integration-tests/load/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.20261117180805-a2fb88ff3710
github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118204812-c2cd552dc1f2
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
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/load/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion system-tests/lib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.20261117180805-a2fb88ff3710
github.com/smartcontractkit/chainlink-common v0.11.2-0.20261118204812-c2cd552dc1f2
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
Expand Down
4 changes: 2 additions & 2 deletions system-tests/lib/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading