Skip to content

Commit

Permalink
Addressed feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
KuphJr committed Oct 9, 2023
1 parent 5038d78 commit b09f6d1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 32 deletions.
35 changes: 10 additions & 25 deletions core/services/functions/external_adapter_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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",
Expand All @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion core/services/functions/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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{
Expand Down Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit b09f6d1

Please sign in to comment.