diff --git a/core/services/functions/external_adapter_client.go b/core/services/functions/external_adapter_client.go index 815a6ebf2a6..db4fed30e5f 100644 --- a/core/services/functions/external_adapter_client.go +++ b/core/services/functions/external_adapter_client.go @@ -62,23 +62,14 @@ type bridgeAccessor struct { var _ BridgeAccessor = (*bridgeAccessor)(nil) type requestPayload struct { - Endpoint string `json:"endpoint"` - RequestId string `json:"requestId"` - JobName string `json:"jobName"` - SubscriptionOwner string `json:"subscriptionOwner"` - SubscriptionId uint64 `json:"subscriptionId"` - Flags RequestFlags `json:"flags"` // marshalled as an array of numbers - NodeProvidedSecrets string `json:"nodeProvidedSecrets"` - Data *computationData `json:"data"` -} - -type computationData struct { - Source string `json:"source" cbor:"source"` - Language int `json:"language" cbor:"language"` - CodeLocation int `json:"codeLocation" cbor:"codeLocation"` - SecretsLocation int `json:"secretsLocation" cbor:"secretsLocation"` - Args []string `json:"args,omitempty" cbor:"args"` - BytesArgs [][]byte `json:"bytesArgs,omitempty" cbor:"bytesArgs"` + Endpoint string `json:"endpoint"` + RequestId string `json:"requestId"` + JobName string `json:"jobName"` + SubscriptionOwner string `json:"subscriptionOwner"` + SubscriptionId uint64 `json:"subscriptionId"` + Flags RequestFlags `json:"flags"` // marshalled as an array of numbers + NodeProvidedSecrets string `json:"nodeProvidedSecrets"` + Data *RequestData `json:"data"` } type secretsPayload struct { @@ -138,6 +129,7 @@ func (ea *externalAdapterClient) RunComputation( nodeProvidedSecrets string, requestData *RequestData, ) (userResult, userError []byte, domains []string, err error) { + requestData.Secrets = nil // secrets are passed in nodeProvidedSecrets payload := requestPayload{ Endpoint: "lambda", @@ -147,14 +139,7 @@ func (ea *externalAdapterClient) RunComputation( SubscriptionId: subscriptionId, Flags: flags, NodeProvidedSecrets: nodeProvidedSecrets, - Data: &computationData{ - Source: requestData.Source, - Language: requestData.Language, - CodeLocation: requestData.CodeLocation, - SecretsLocation: requestData.SecretsLocation, - Args: requestData.Args, - BytesArgs: requestData.BytesArgs, - }, + Data: requestData, } userResult, userError, domains, err = ea.request(ctx, payload, requestId, jobName, "run_computation") diff --git a/core/services/functions/request.go b/core/services/functions/request.go index a6715e0a87f..847ca7ac461 100644 --- a/core/services/functions/request.go +++ b/core/services/functions/request.go @@ -22,7 +22,7 @@ type RequestData struct { Source string `json:"source" cbor:"source"` Language int `json:"language" cbor:"language"` CodeLocation int `json:"codeLocation" cbor:"codeLocation"` - Secrets []byte `json:"secrets" cbor:"secrets"` + Secrets []byte `json:"secrets,omitempty" cbor:"secrets"` SecretsLocation int `json:"secretsLocation" cbor:"secretsLocation"` RequestSignature []byte `json:"requestSignature,omitempty" cbor:"requestSignature"` Args []string `json:"args,omitempty" cbor:"args"` diff --git a/core/services/ocr2/plugins/functions/integration_tests/v1/functions_integration_test.go b/core/services/ocr2/plugins/functions/integration_tests/v1/functions_integration_test.go index 36cb9ce2231..e92cbe8bca4 100644 --- a/core/services/ocr2/plugins/functions/integration_tests/v1/functions_integration_test.go +++ b/core/services/ocr2/plugins/functions/integration_tests/v1/functions_integration_test.go @@ -13,7 +13,7 @@ import ( var ( // a batch of 8 max-length results uses around 2M gas (assuming 70k gas per client callback - see FunctionsClientExample.sol) nOracleNodes = 4 - nClients = 1 + nClients = 50 requestLenBytes = 1_000 maxGas = 1_700_000 maxTotalReportGas = 560_000 @@ -27,6 +27,33 @@ func TestIntegration_Functions_MultipleV1Requests_Success(t *testing.T) { utils.SetupRouterRoutes(t, b, owner, routerContract, active.Address, proposed.Address, allowListContractAddress) + _, _, oracleIdentities := utils.CreateFunctionsNodes(t, owner, b, routerAddress, nOracleNodes, maxGas, nil, nil) + + pluginConfig := functionsConfig.ReportingPluginConfig{ + MaxQueryLengthBytes: 10_000, + MaxObservationLengthBytes: 15_000, + MaxReportLengthBytes: 15_000, + MaxRequestBatchSize: uint32(batchSize), + MaxReportTotalCallbackGas: uint32(maxTotalReportGas), + DefaultAggregationMethod: functionsConfig.AggregationMethod_AGGREGATION_MODE, + UniqueReports: true, + } + + // config for oracle contract + utils.SetOracleConfig(t, b, owner, active.Contract, oracleIdentities, batchSize, &pluginConfig) + + subscriptionId := utils.CreateAndFundSubscriptions(t, b, owner, linkToken, routerAddress, routerContract, clientContracts, allowListContract) + b.Commit() + utils.ClientTestRequests(t, owner, b, linkToken, routerAddress, routerContract, allowListContract, clientContracts, requestLenBytes, nil, subscriptionId, 1*time.Minute) +} + +func TestIntegration_Functions_MultipleV1Requests_ThresholdDecryptionSuccess(t *testing.T) { + // simulated chain with all contracts + owner, b, ticker, active, proposed, clientContracts, routerAddress, routerContract, linkToken, allowListContractAddress, allowListContract := utils.StartNewChainWithContracts(t, nClients) + defer ticker.Stop() + + utils.SetupRouterRoutes(t, b, owner, routerContract, active.Address, proposed.Address, allowListContractAddress) + _, _, oracleIdentities := utils.CreateFunctionsNodes(t, owner, b, routerAddress, nOracleNodes, maxGas, utils.ExportedOcr2Keystores, utils.MockThresholdKeyShares) pluginConfig := functionsConfig.ReportingPluginConfig{ @@ -97,5 +124,5 @@ func TestIntegration_Functions_MultipleV1Requests_WithUpgrade(t *testing.T) { _, err := routerContract.UpdateContracts(owner) require.NoError(t, err) b.Commit() - utils.ClientTestRequests(t, owner, b, linkToken, routerAddress, routerContract, allowListContract, clientContracts, requestLenBytes, utils.DefaultSecretsBytes, subscriptionId, 1*time.Minute) + utils.ClientTestRequests(t, owner, b, linkToken, routerAddress, routerContract, allowListContract, clientContracts, requestLenBytes, utils.DefaultSecretsUrlsBytes, subscriptionId, 1*time.Minute) } diff --git a/core/services/ocr2/plugins/functions/integration_tests/v1/internal/testutils.go b/core/services/ocr2/plugins/functions/integration_tests/v1/internal/testutils.go index c376213ed13..fa9e34729f4 100644 --- a/core/services/ocr2/plugins/functions/integration_tests/v1/internal/testutils.go +++ b/core/services/ocr2/plugins/functions/integration_tests/v1/internal/testutils.go @@ -26,7 +26,6 @@ import ( "github.com/smartcontractkit/libocr/commontypes" confighelper2 "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper" ocrtypes2 "github.com/smartcontractkit/libocr/offchainreporting2plus/types" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "github.com/smartcontractkit/chainlink/v2/core/assets" @@ -494,9 +493,9 @@ func mockEALambdaExecutionResponse(t *testing.T, request map[string]any) []byte data := request["data"].(map[string]any) require.Equal(t, functions.LanguageJavaScript, int(data["language"].(float64))) require.Equal(t, functions.LocationInline, int(data["codeLocation"].(float64))) - require.Equal(t, functions.LocationRemote, int(data["secretsLocation"].(float64))) - if data["secrets"] != DefaultSecretsBase64 && request["nodeProvidedSecrets"] != fmt.Sprintf(`{"0x0":"%s"}`, DefaultSecretsBase64) { - assert.Fail(t, "expected secrets or nodeProvidedSecrets to be '%s'", DefaultSecretsBase64) + if data["secrets"] != nil { + require.Equal(t, functions.LocationRemote, int(data["secretsLocation"].(float64))) + require.Equal(t, fmt.Sprintf(`{"0x0":"%s"}`, DefaultSecretsBase64), request["nodeProvidedSecrets"].(string)) } args := data["args"].([]interface{}) require.Equal(t, 2, len(args))