From 1e624115c4bdbdcd81e040095e538881ef42ecfb Mon Sep 17 00:00:00 2001 From: Ilja Pavlovs Date: Thu, 23 May 2024 15:59:59 +0300 Subject: [PATCH] VRF-1109: Add Fulfillment Response Time in 90, 95 Percentiles to VRF v2 Plus superscript --- core/scripts/vrfv2plus/testnet/main.go | 4 ++ .../vrfv2plus/testnet/v2plusscripts/util.go | 39 +++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/core/scripts/vrfv2plus/testnet/main.go b/core/scripts/vrfv2plus/testnet/main.go index 7b47a2f8529..1fabd20b60f 100644 --- a/core/scripts/vrfv2plus/testnet/main.go +++ b/core/scripts/vrfv2plus/testnet/main.go @@ -960,6 +960,10 @@ func main() { fastestResponseTimeInSeconds, err := consumer.SFastestResponseTimeInBlocks(nil) helpers.PanicErr(err) fmt.Println("Fastest Response Time In Seconds: ", fastestResponseTimeInSeconds) + p90FulfillmentBlockTime, p95FulfillmentBlockTime, err := v2plusscripts.CalculateFulfillmentResponseTimePercentiles(e, consumer) + helpers.PanicErr(err) + fmt.Println("P90 Fulfillment Block Time: ", p90FulfillmentBlockTime) + fmt.Println("P95 Fulfillment Block Time: ", p95FulfillmentBlockTime) case "eoa-load-test-reset-metrics": request := flag.NewFlagSet("eoa-load-test-reset-metrics", flag.ExitOnError) consumerAddress := request.String("consumer-address", "", "consumer address") diff --git a/core/scripts/vrfv2plus/testnet/v2plusscripts/util.go b/core/scripts/vrfv2plus/testnet/v2plusscripts/util.go index 3d511605811..091b324443a 100644 --- a/core/scripts/vrfv2plus/testnet/v2plusscripts/util.go +++ b/core/scripts/vrfv2plus/testnet/v2plusscripts/util.go @@ -6,6 +6,8 @@ import ( "fmt" "math/big" + "github.com/montanaflynn/stats" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/vrf_v2plus_load_test_with_metrics" "github.com/ethereum/go-ethereum/accounts/abi/bind" @@ -316,3 +318,40 @@ func EoaV2PlusLoadTestConsumerWithMetricsDeploy(e helpers.Environment, consumerC helpers.PanicErr(err) return helpers.ConfirmContractDeployed(context.Background(), e.Ec, tx, e.ChainID) } + +func CalculateFulfillmentResponseTimePercentiles(e helpers.Environment, consumer *vrf_v2plus_load_test_with_metrics.VRFV2PlusLoadTestWithMetrics) (float64, float64, error) { + var responseTimesInBlocks []uint32 + for { + currentResponseTimesInBlocks, err := consumer.GetRequestBlockTimes(&bind.CallOpts{ + From: e.Owner.From, + Context: context.Background(), + }, big.NewInt(int64(len(responseTimesInBlocks))), big.NewInt(1000)) + if err != nil { + return 0, 0, err + } + if len(currentResponseTimesInBlocks) == 0 { + break + } + responseTimesInBlocks = append(responseTimesInBlocks, currentResponseTimesInBlocks...) + } + var p90FulfillmentBlockTime, p95FulfillmentBlockTime float64 + var err error + if len(responseTimesInBlocks) == 0 { + p90FulfillmentBlockTime = 0 + p95FulfillmentBlockTime = 0 + } else { + responseTimesInBlocksFloat64 := make([]float64, len(responseTimesInBlocks)) + for i, value := range responseTimesInBlocks { + responseTimesInBlocksFloat64[i] = float64(value) + } + p90FulfillmentBlockTime, err = stats.Percentile(responseTimesInBlocksFloat64, 90) + if err != nil { + return 0, 0, err + } + p95FulfillmentBlockTime, err = stats.Percentile(responseTimesInBlocksFloat64, 95) + if err != nil { + return 0, 0, err + } + } + return p90FulfillmentBlockTime, p95FulfillmentBlockTime, nil +}