Skip to content

Commit

Permalink
Tt 562 functions + gateway performance tests, chaos suite (#10397)
Browse files Browse the repository at this point in the history
* TT-562 s4 tdh2 setup and tests

* chaos suite

* update deps

* fix wrapper generation

* encrypt s4 secrets

* bump godeltaprof for go 1.21.0

* uniq IDs for secrets

* gateway test for secrets_set

* gateway test for secrets_set/secrets_list

* more throughput through batch calls

* update go.mod

* load modes for gateway

* finalize docs

* decouple from env

* update README

* update go.sum
  • Loading branch information
skudasov authored Sep 1, 2023
1 parent fc522f9 commit a65e238
Show file tree
Hide file tree
Showing 21 changed files with 1,297 additions and 212 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ contract FunctionsLoadTestClient is FunctionsClient, ConfirmedOwner {

uint32 public constant MAX_CALLBACK_GAS = 70_000;

bytes32 public s_lastRequestId;
bytes32 public s_lastResponse;
bytes32 public s_lastError;
uint32 public s_lastResponseLength;
uint32 public s_lastErrorLength;
bytes32 public lastRequestID;
bytes32 public lastResponse;
bytes32 public lastError;
uint32 public totalRequests;
uint32 public totalEmptyResponses;
uint32 public totalSucceededResponses;
uint32 public totalFailedResponses;

constructor(address router) FunctionsClient(router) ConfirmedOwner(msg.sender) {}

Expand All @@ -29,6 +31,7 @@ contract FunctionsLoadTestClient is FunctionsClient, ConfirmedOwner {
* @param subscriptionId Billing ID
*/
function sendRequest(
uint32 times,
string calldata source,
bytes calldata encryptedSecretsReferences,
string[] calldata args,
Expand All @@ -39,7 +42,33 @@ contract FunctionsLoadTestClient is FunctionsClient, ConfirmedOwner {
req.initializeRequestForInlineJavaScript(source);
if (encryptedSecretsReferences.length > 0) req.addSecretsReference(encryptedSecretsReferences);
if (args.length > 0) req.setArgs(args);
s_lastRequestId = _sendRequest(req.encodeCBOR(), subscriptionId, MAX_CALLBACK_GAS, jobId);
uint i = 0;
for (i = 0; i < times; i++) {
lastRequestID = _sendRequest(req.encodeCBOR(), subscriptionId, MAX_CALLBACK_GAS, jobId);
totalRequests += 1;
}
}

function resetStats() external onlyOwner {
lastRequestID = "";
lastResponse = "";
lastError = "";
totalRequests = 0;
totalSucceededResponses = 0;
totalFailedResponses = 0;
totalEmptyResponses = 0;
}

function getStats() public view onlyOwner returns (bytes32, bytes32, bytes32, uint32, uint32, uint32, uint32) {
return (
lastRequestID,
lastResponse,
lastError,
totalRequests,
totalSucceededResponses,
totalFailedResponses,
totalEmptyResponses
);
}

/**
Expand All @@ -51,11 +80,18 @@ contract FunctionsLoadTestClient is FunctionsClient, ConfirmedOwner {
*/
function fulfillRequest(bytes32 requestId, bytes memory response, bytes memory err) internal override {
// Save only the first 32 bytes of response/error to always fit within MAX_CALLBACK_GAS
s_lastRequestId = requestId;
s_lastResponse = bytesToBytes32(response);
s_lastResponseLength = uint32(response.length);
s_lastError = bytesToBytes32(err);
s_lastErrorLength = uint32(err.length);
lastRequestID = requestId;
lastResponse = bytesToBytes32(response);
lastError = bytesToBytes32(err);
if (response.length == 0) {
totalEmptyResponses += 1;
}
if (err.length != 0) {
totalFailedResponses += 1;
}
if (response.length != 0 && err.length == 0) {
totalSucceededResponses += 1;
}
}

function bytesToBytes32(bytes memory b) private pure returns (bytes32 out) {
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ functions_billing_registry_events_mock: ../../../contracts/solc/v0.8.6/functions
functions_client: ../../../contracts/solc/v0.8.19/functions/1_0_0/FunctionsClient.abi ../../../contracts/solc/v0.8.19/functions/1_0_0/FunctionsClient.bin 2368f537a04489c720a46733f8596c4fc88a31062ecfa966d05f25dd98608aca
functions_client_example: ../../../contracts/solc/v0.8.19/functions/1_0_0/FunctionsClientExample.abi ../../../contracts/solc/v0.8.19/functions/1_0_0/FunctionsClientExample.bin 25036bdb94a50a81df4222418bf9aa1e0c8540d5834b7e6e639aa63a2a2c8206
functions_coordinator: ../../../contracts/solc/v0.8.19/functions/1_0_0/FunctionsCoordinator.abi ../../../contracts/solc/v0.8.19/functions/1_0_0/FunctionsCoordinator.bin e453fd45029ff99658d029bfbb8711b748c432323f12585c039a30977e801a79
functions_load_test_client: ../../../contracts/solc/v0.8.19/functions/1_0_0/FunctionsLoadTestClient.abi ../../../contracts/solc/v0.8.19/functions/1_0_0/FunctionsLoadTestClient.bin 28f2834dea12b3aefa7c696b64ca5272a1ab5cdf33365c9f7fafdc0b7d5669e8
functions_load_test_client: ../../../contracts/solc/v0.8.19/functions/1_0_0/FunctionsLoadTestClient.abi ../../../contracts/solc/v0.8.19/functions/1_0_0/FunctionsLoadTestClient.bin 08b0ba467a0d2913ad146c293cc92ed1e0e5f25398bc8185addf9c4c1a41df2c
functions_oracle_events_mock: ../../../contracts/solc/v0.8.6/functions/0_0_0/FunctionsOracleEventsMock.abi ../../../contracts/solc/v0.8.6/functions/0_0_0/FunctionsOracleEventsMock.bin 3ca70f966f8fe751987f0ccb50bebb6aa5be77e4a9f835d1ae99e0e9bfb7d52c
functions_router: ../../../contracts/solc/v0.8.19/functions/1_0_0/FunctionsRouter.abi ../../../contracts/solc/v0.8.19/functions/1_0_0/FunctionsRouter.bin dd1d3527e19d65efe029c4a131ded44dc0ca961e5c4f459743992435431ec478
functions_v1_events_mock: ../../../contracts/solc/v0.8.19/functions/1_0_0/FunctionsV1EventsMock.abi ../../../contracts/solc/v0.8.19/functions/1_0_0/FunctionsV1EventsMock.bin 0f0ba42e0cc33c7abc8b8fd4fdfce903748a169886dd5f16cfdd56e75bcf708d
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ require (
github.com/prometheus/procfs v0.11.0 // indirect
github.com/prometheus/prometheus v0.46.0 // indirect
github.com/pyroscope-io/client v0.7.1 // indirect
github.com/pyroscope-io/godeltaprof v0.1.0 // indirect
github.com/pyroscope-io/godeltaprof v0.1.2 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rjeczalik/notify v0.9.3 // indirect
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1310,8 +1310,8 @@ github.com/prometheus/prometheus v0.46.0/go.mod h1:10L5IJE5CEsjee1FnOcVswYXlPIsc
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/pyroscope-io/client v0.7.1 h1:yFRhj3vbgjBxehvxQmedmUWJQ4CAfCHhn+itPsuWsHw=
github.com/pyroscope-io/client v0.7.1/go.mod h1:4h21iOU4pUOq0prKyDlvYRL+SCKsBc5wKiEtV+rJGqU=
github.com/pyroscope-io/godeltaprof v0.1.0 h1:UBqtjt0yZi4jTxqZmLAs34XG6ycS3vUTlhEUSq4NHLE=
github.com/pyroscope-io/godeltaprof v0.1.0/go.mod h1:psMITXp90+8pFenXkKIpNhrfmI9saQnPbba27VIaiQE=
github.com/pyroscope-io/godeltaprof v0.1.2 h1:MdlEmYELd5w+lvIzmZvXGNMVzW2Qc9jDMuJaPOR75g4=
github.com/pyroscope-io/godeltaprof v0.1.2/go.mod h1:psMITXp90+8pFenXkKIpNhrfmI9saQnPbba27VIaiQE=
github.com/rakyll/statik v0.1.7 h1:OF3QCZUuyPxuGEP7B4ypUa7sB/iHtqOTDYZXGM8KOdQ=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
Expand Down
232 changes: 232 additions & 0 deletions integration-tests/chaos/functions/full.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,232 @@
apiVersion: chaos-mesh.org/v1alpha1
kind: Workflow
metadata:
namespace: chainlink
name: chainlink-flow
spec:
entry: entry
templates:
# root entry
- name: entry
templateType: Serial
deadline: 1h
children:
- killing
- network-delay-internal
# - external-deps-failure
# children chaos group
- name: killing
templateType: Serial
children:
- gateway-kill
- don-minority-kill
- don-majority-kill
- adapters-minority-kill
- adapters-majority-kill
# children chaos group
- name: network-delay-internal
templateType: Serial
children:
- gateway-delay
- don-minority-delay
- don-majority-delay
- adapters-minority-delay
- adapters-majority-delay
# children chaos group
- name: external-deps-failure
templateType: Serial
children:
- ea-url-resolve-failure

# experiments (killing)
- name: gateway-kill
templateType: PodChaos
deadline: 1m
podChaos:
selector:
namespaces:
- chainlink
labelSelectors:
'app.kubernetes.io/instance': cln-gateway-staging1-node
mode: one
action: pod-kill
- name: don-minority-kill
templateType: PodChaos
deadline: 1m
podChaos:
selector:
namespaces:
- chainlink
expressionSelectors:
- key: app.kubernetes.io/instance
operator: In
values:
- clc-ocr2-dr-matic-testnet-nodes-0
- clc-ocr2-dr-matic-testnet-boot
mode: all
action: pod-kill
- name: don-majority-kill
templateType: PodChaos
deadline: 1m
podChaos:
selector:
namespaces:
- chainlink
expressionSelectors:
- key: app.kubernetes.io/instance
operator: In
values:
- clc-ocr2-dr-matic-testnet-nodes-1
- clc-ocr2-dr-matic-testnet-nodes-0
- clc-ocr2-dr-matic-testnet-boot
mode: all
action: pod-kill
- name: adapters-minority-kill
templateType: PodChaos
deadline: 1m
podChaos:
selector:
namespaces:
- adapters
expressionSelectors:
- key: app.kubernetes.io/instance
operator: In
values:
- universal-mumbai-0
mode: all
action: pod-kill
- name: adapters-majority-kill
templateType: PodChaos
deadline: 1m
podChaos:
selector:
namespaces:
- adapters
expressionSelectors:
- key: app.kubernetes.io/instance
operator: In
values:
- universal-mumbai-1
- universal-mumbai-0
mode: all
action: pod-kill

# TODO: enable when chaosd is installed on all the nodes
# experiments (delays)
- name: gateway-delay
templateType: NetworkChaos
deadline: 1m
networkChaos:
selector:
namespaces:
- chainlink
labelSelectors:
'app.kubernetes.io/instance': cln-gateway-staging1-node
mode: all
action: delay
delay:
latency: 200ms
correlation: '0'
jitter: 0ms
direction: to
- name: don-minority-delay
templateType: NetworkChaos
deadline: 1m
networkChaos:
selector:
namespaces:
- chainlink
expressionSelectors:
- key: app.kubernetes.io/instance
operator: In
values:
- clc-ocr2-dr-matic-testnet-nodes-0
- clc-ocr2-dr-matic-testnet-boot
mode: all
action: delay
delay:
latency: 200ms
correlation: '0'
jitter: 0ms
direction: to
- name: don-majority-delay
templateType: NetworkChaos
deadline: 1m
networkChaos:
selector:
namespaces:
- chainlink
expressionSelectors:
- key: app.kubernetes.io/instance
operator: In
values:
- clc-ocr2-dr-matic-testnet-nodes-1
- clc-ocr2-dr-matic-testnet-nodes-0
- clc-ocr2-dr-matic-testnet-boot
mode: all
action: delay
delay:
latency: 200ms
correlation: '0'
jitter: 0ms
direction: to
- name: adapters-minority-delay
templateType: NetworkChaos
deadline: 1m
networkChaos:
selector:
namespaces:
- adapters
expressionSelectors:
- key: app.kubernetes.io/instance
operator: In
values:
- universal-mumbai-0
mode: all
action: delay
delay:
latency: 200ms
correlation: '0'
jitter: 0ms
direction: to
- name: adapters-majority-delay
templateType: NetworkChaos
deadline: 1m
networkChaos:
selector:
namespaces:
- adapters
expressionSelectors:
- key: app.kubernetes.io/instance
operator: In
values:
- universal-mumbai-1
- universal-mumbai-0
mode: all
action: delay
delay:
latency: 200ms
correlation: '0'
jitter: 0ms
direction: to

# experiments (external deps failure)
# - name: ea-url-resolve-failure
# templateType: NetworkChaos
# deadline: 3m
# networkChaos:
# selector:
# namespaces:
# - chainlink
# mode: all
# action: partition
# direction: to
# target:
# selector:
# namespaces:
# - chainlink
# mode: all
# externalTargets:
# - >-
# my-url.com

6 changes: 5 additions & 1 deletion integration-tests/contracts/contract_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ type AuthorizedForwarder interface {

type FunctionsCoordinator interface {
Address() string
GetThresholdPublicKey() ([]byte, error)
GetDONPublicKey() ([]byte, error)
}

type FunctionsRouter interface {
Expand All @@ -360,5 +362,7 @@ type FunctionsRouter interface {

type FunctionsLoadTestClient interface {
Address() string
SendRequest(source string, encryptedSecretsReferences []byte, args []string, subscriptionId uint64, jobId [32]byte) error
ResetStats() error
GetStats() (*EthereumFunctionsLoadStats, error)
SendRequest(times uint32, source string, encryptedSecretsReferences []byte, args []string, subscriptionId uint64, jobId [32]byte) error
}
Loading

0 comments on commit a65e238

Please sign in to comment.