Skip to content

Commit

Permalink
VRF-881: fixed toml config for VRF Load tests; VRF-882: add more cust… (
Browse files Browse the repository at this point in the history
#11991)

* VRF-881: fixed toml config for VRF Load tests; VRF-882: add more customisation options for BHS job in super scripts

* VRF-881: fixing lint

* VRF-881: upgrading ctf library

* VRF-881: adding load test metric calculation in seconds for VRF V2Plus Consumer contract; adding more parametrization options in setup-env script

* VRF-881: PR comments;

* VRF-881: fixing Lint issues

* VRF-881: fixing BHS tests

* VRF-881: adding smoke test type

* VRF-881: PR comments

* VRF-881: fixing load test

* VRF-881: fixing config

* VRF-881: fixing e2e tests

* VRF-881: fixing sonar

* VRF-881: fixing sonar and refactoring

* VRF-881: fixing lint issues
  • Loading branch information
iljapavlovs authored and kidambisrinivas committed Mar 18, 2024
1 parent 3a91c53 commit de99351
Show file tree
Hide file tree
Showing 34 changed files with 1,132 additions and 1,087 deletions.
1 change: 1 addition & 0 deletions .github/workflows/on-demand-vrfv2-performance-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
description: Performance Test Type of test to run
type: choice
options:
- "Smoke"
- "Soak"
- "Load"
- "Stress"
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/on-demand-vrfv2plus-performance-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
description: Performance Test Type of test to run
type: choice
options:
- "Smoke"
- "Soak"
- "Load"
- "Stress"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ import {VRFV2PlusClient} from "../libraries/VRFV2PlusClient.sol";
contract VRFV2PlusLoadTestWithMetrics is VRFConsumerBaseV2Plus {
uint256 public s_responseCount;
uint256 public s_requestCount;
uint256 public s_averageFulfillmentInMillions = 0; // in millions for better precision
uint256 public s_slowestFulfillment = 0;
uint256 public s_fastestFulfillment = 999;
uint256 public s_averageResponseTimeInBlocksMillions = 0; // in millions for better precision
uint256 public s_slowestResponseTimeInBlocks = 0;
uint256 public s_fastestResponseTimeInBlocks = 999;
uint256 public s_slowestResponseTimeInSeconds = 0;
uint256 public s_fastestResponseTimeInSeconds = 999;
uint256 public s_averageResponseTimeInSecondsMillions = 0;

uint256 public s_lastRequestId;
// solhint-disable-next-line chainlink-solidity/prefix-storage-variables-with-s-underscore
mapping(uint256 => uint256) internal requestHeights; // requestIds to block number when rand request was made

struct RequestStatus {
bool fulfilled;
Expand All @@ -34,22 +36,38 @@ contract VRFV2PlusLoadTestWithMetrics is VRFConsumerBaseV2Plus {

// solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore
function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal override {
uint256 fulfilmentBlockNumber = ChainSpecificUtil._getBlockNumber();
uint256 requestDelay = fulfilmentBlockNumber - requestHeights[_requestId];
uint256 requestDelayInMillions = requestDelay * 1_000_000;

if (requestDelay > s_slowestFulfillment) {
s_slowestFulfillment = requestDelay;
}
s_fastestFulfillment = requestDelay < s_fastestFulfillment ? requestDelay : s_fastestFulfillment;
s_averageFulfillmentInMillions = s_responseCount > 0
? (s_averageFulfillmentInMillions * s_responseCount + requestDelayInMillions) / (s_responseCount + 1)
: requestDelayInMillions;

s_requests[_requestId].fulfilled = true;
s_requests[_requestId].randomWords = _randomWords;
s_requests[_requestId].fulfilmentTimestamp = block.timestamp;
s_requests[_requestId].fulfilmentBlockNumber = fulfilmentBlockNumber;
s_requests[_requestId].fulfilmentBlockNumber = ChainSpecificUtil._getBlockNumber();

uint256 responseTimeInBlocks = s_requests[_requestId].fulfilmentBlockNumber -
s_requests[_requestId].requestBlockNumber;
uint256 responseTimeInSeconds = s_requests[_requestId].fulfilmentTimestamp -
s_requests[_requestId].requestTimestamp;

(
s_slowestResponseTimeInBlocks,
s_fastestResponseTimeInBlocks,
s_averageResponseTimeInBlocksMillions
) = _calculateMetrics(
responseTimeInBlocks,
s_fastestResponseTimeInBlocks,
s_slowestResponseTimeInBlocks,
s_averageResponseTimeInBlocksMillions,
s_responseCount
);
(
s_slowestResponseTimeInSeconds,
s_fastestResponseTimeInSeconds,
s_averageResponseTimeInSecondsMillions
) = _calculateMetrics(
responseTimeInSeconds,
s_fastestResponseTimeInSeconds,
s_slowestResponseTimeInSeconds,
s_averageResponseTimeInSecondsMillions,
s_responseCount
);

s_responseCount++;
}
Expand Down Expand Up @@ -86,14 +104,16 @@ contract VRFV2PlusLoadTestWithMetrics is VRFConsumerBaseV2Plus {
fulfilmentBlockNumber: 0
});
s_requestCount++;
requestHeights[requestId] = requestBlockNumber;
}
}

function reset() external {
s_averageFulfillmentInMillions = 0; // in millions for better precision
s_slowestFulfillment = 0;
s_fastestFulfillment = 999;
s_averageResponseTimeInBlocksMillions = 0; // in millions for better precision
s_slowestResponseTimeInBlocks = 0;
s_fastestResponseTimeInBlocks = 999;
s_averageResponseTimeInSecondsMillions = 0; // in millions for better precision
s_slowestResponseTimeInSeconds = 0;
s_fastestResponseTimeInSeconds = 999;
s_requestCount = 0;
s_responseCount = 0;
}
Expand Down Expand Up @@ -122,4 +142,23 @@ contract VRFV2PlusLoadTestWithMetrics is VRFConsumerBaseV2Plus {
request.fulfilmentBlockNumber
);
}

function _calculateMetrics(
uint256 _responseTime,
uint256 _fastestResponseTime,
uint256 _slowestResponseTime,
uint256 _averageInMillions,
uint256 _responseCount
) internal returns (uint256 slowest, uint256 fastest, uint256 average) {
uint256 _requestDelayInMillions = _responseTime * 1_000_000;
if (_responseTime > _slowestResponseTime) {
_slowestResponseTime = _responseTime;
}
_fastestResponseTime = _responseTime < _fastestResponseTime ? _responseTime : _fastestResponseTime;
uint256 _averageInMillions = _responseCount > 0
? (_averageInMillions * _responseCount + _requestDelayInMillions) / (_responseCount + 1)
: _requestDelayInMillions;

return (_slowestResponseTime, _fastestResponseTime, _averageInMillions);
}
}
Loading

0 comments on commit de99351

Please sign in to comment.