Skip to content

Commit

Permalink
VRF-1109: Add Fulfillment Response Time in 90, 95 Percentiles to VRF …
Browse files Browse the repository at this point in the history
…v2 Plus superscript (#13302)
  • Loading branch information
iljapavlovs authored Jun 12, 2024
1 parent 0d305d7 commit e0f2553
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
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
}

0 comments on commit e0f2553

Please sign in to comment.