Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VRF-1109: Add Fulfillment Response Time in 90, 95 Percentiles to VRF … #13302

Merged
merged 7 commits into from
Jun 12, 2024
Merged
4 changes: 4 additions & 0 deletions core/scripts/vrfv2plus/testnet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
39 changes: 39 additions & 0 deletions core/scripts/vrfv2plus/testnet/v2plusscripts/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Loading