Skip to content

Commit

Permalink
VRF-666: perform rand request and check that it was fulfilled for set…
Browse files Browse the repository at this point in the history
…up-env script
  • Loading branch information
iljapavlovs committed Oct 11, 2023
1 parent a4154c7 commit 5692621
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 128 deletions.
4 changes: 4 additions & 0 deletions core/scripts/common/vrf/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ var (
//vrfv2plus
FlatFeeLinkPPM = int64(500)
FlatFeeNativePPM = int64(500)

//consumer
CallBackGasLimit = uint(1_000_000)
IsNativePayment = false
)
92 changes: 68 additions & 24 deletions core/scripts/common/vrf/setup-envs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"math/big"
"os"
"strings"
"sync"
"time"
)

func newApp(remoteNodeURL string, writer io.Writer) (*clcmd.Shell, *cli.App) {
Expand Down Expand Up @@ -171,7 +173,7 @@ func main() {
}

var jobSpecs model.JobSpecs

var randRequestConfig v2plusscripts.RandRequestConfig
switch *vrfVersion {
case "v2":
feeConfigV2 := vrf_coordinator_v2.VRFCoordinatorV2FeeConfig{
Expand Down Expand Up @@ -218,7 +220,7 @@ func main() {
FeeConfig: feeConfigV2Plus,
}

jobSpecs = v2plusscripts.VRFV2PlusDeployUniverse(
jobSpecs, randRequestConfig = v2plusscripts.VRFV2PlusDeployUniverse(
e,
subscriptionBalanceJuels,
subscriptionBalanceNativeWei,
Expand All @@ -230,34 +232,76 @@ func main() {
)
}

for key, node := range nodesMap {
client, app := connectToNode(&node.URL, output, node.CredsFile)
createJobs(nodesMap, output, jobSpecs)
if *vrfVersion == "v2plus" {
verifyRandomnessRequestFulfills(e, randRequestConfig)
}
}
}

//GET ALL JOBS
jobIDs := getAllJobIDs(client, app, output)
func createJobs(nodesMap map[string]model.Node, output *bytes.Buffer, jobSpecs model.JobSpecs) {
for key, node := range nodesMap {
client, app := connectToNode(&node.URL, output, node.CredsFile)

//DELETE ALL EXISTING JOBS
for _, jobID := range jobIDs {
deleteJob(jobID, client, app, output)
}
//CREATE JOBS

switch key {
case model.VRFPrimaryNodeName:
createJob(jobSpecs.VRFPrimaryNode, client, app, output)
case model.VRFBackupNodeName:
createJob(jobSpecs.VRFBackupyNode, client, app, output)
case model.BHSNodeName:
createJob(jobSpecs.BHSNode, client, app, output)
case model.BHSBackupNodeName:
createJob(jobSpecs.BHSBackupNode, client, app, output)
case model.BHFNodeName:
createJob(jobSpecs.BHFNode, client, app, output)
}
//GET ALL JOBS
jobIDs := getAllJobIDs(client, app, output)

//DELETE ALL EXISTING JOBS
for _, jobID := range jobIDs {
deleteJob(jobID, client, app, output)
}
//CREATE JOBS

switch key {
case model.VRFPrimaryNodeName:
createJob(jobSpecs.VRFPrimaryNode, client, app, output)
case model.VRFBackupNodeName:
createJob(jobSpecs.VRFBackupyNode, client, app, output)
case model.BHSNodeName:
createJob(jobSpecs.BHSNode, client, app, output)
case model.BHSBackupNodeName:
createJob(jobSpecs.BHSBackupNode, client, app, output)
case model.BHFNodeName:
createJob(jobSpecs.BHFNode, client, app, output)
}
}
}

func verifyRandomnessRequestFulfills(e helpers.Environment, randRequestConfig v2plusscripts.RandRequestConfig) {

time.Sleep(10 * time.Second)
v2plusscripts.LoadTestRequestRandomness(
e,
randRequestConfig.ConsumerAddress,
randRequestConfig.SubID,
randRequestConfig.MinConfs,
randRequestConfig.KeyHash,
constants.CallBackGasLimit,
false,
1,
1,
1,
)
//
//v2plusscripts.LoadTestRequestRandomness(
// e,
// randRequestConfig.ConsumerAddress,
// randRequestConfig.SubID,
// randRequestConfig.MinConfs,
// randRequestConfig.KeyHash,
// constants.CallBackGasLimit,
// false,
// 1,
// 1,
// 1,
//)
var wg sync.WaitGroup
wg.Add(1)
_, _, err := v2plusscripts.WaitForRequestCountEqualToFulfilmentCount(e, randRequestConfig.ConsumerAddress, 30*time.Second, &wg)
helpers.PanicErr(err)
wg.Wait()
}

func fundNodesIfNeeded(node model.Node, key string, e helpers.Environment) {
if node.SendingKeyFundingAmount.Cmp(big.NewInt(0)) == 1 {
fmt.Println("\nFunding", key, "Node's Sending Keys. Need to fund each key with", node.SendingKeyFundingAmount, "wei")
Expand Down
55 changes: 12 additions & 43 deletions core/scripts/vrfv2plus/testnet/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -869,54 +869,23 @@ func main() {
runs := request.Uint("runs", 1, "number of runs to do. total randomness requests will be (requests * runs).")
helpers.ParseArgs(request, os.Args[2:], "consumer-address", "sub-id", "key-hash")
keyHashBytes := common.HexToHash(*keyHash)
consumer, err := vrf_v2plus_load_test_with_metrics.NewVRFV2PlusLoadTestWithMetrics(
v2plusscripts.LoadTestRequestRandomness(
e,
common.HexToAddress(*consumerAddress),
e.Ec)
helpers.PanicErr(err)
var txes []*types.Transaction
for i := 0; i < int(*runs); i++ {
tx, err := consumer.RequestRandomWords(
e.Owner,
decimal.RequireFromString(*subID).BigInt(),
uint16(*requestConfirmations),
keyHashBytes,
uint32(*cbGasLimit),
*nativePaymentEnabled,
uint32(*numWords),
uint16(*requests),
)
helpers.PanicErr(err)
fmt.Printf("TX %d: %s\n", i+1, helpers.ExplorerLink(e.ChainID, tx.Hash()))
txes = append(txes, tx)
}
fmt.Println("Total number of requests sent:", (*requests)*(*runs))
fmt.Println("fetching receipts for all transactions")
for i, tx := range txes {
helpers.ConfirmTXMined(context.Background(), e.Ec, tx, e.ChainID, fmt.Sprintf("load test %d", i+1))
}
decimal.RequireFromString(*subID).BigInt(),
*requestConfirmations,
keyHashBytes,
*cbGasLimit,
*nativePaymentEnabled,
*numWords,
*requests,
*runs,
)
case "eoa-load-test-read-metrics":
request := flag.NewFlagSet("eoa-load-test-read-metrics", flag.ExitOnError)
consumerAddress := request.String("consumer-address", "", "consumer address")
helpers.ParseArgs(request, os.Args[2:], "consumer-address")
consumer, err := vrf_v2plus_load_test_with_metrics.NewVRFV2PlusLoadTestWithMetrics(
common.HexToAddress(*consumerAddress),
e.Ec)
helpers.PanicErr(err)
responseCount, err := consumer.SResponseCount(nil)
helpers.PanicErr(err)
fmt.Println("Response Count: ", responseCount)
requestCount, err := consumer.SRequestCount(nil)
helpers.PanicErr(err)
fmt.Println("Request Count: ", requestCount)
averageFulfillmentInMillions, err := consumer.SAverageFulfillmentInMillions(nil)
helpers.PanicErr(err)
fmt.Println("Average Fulfillment In Millions: ", averageFulfillmentInMillions)
slowestFulfillment, err := consumer.SSlowestFulfillment(nil)
helpers.PanicErr(err)
fmt.Println("Slowest Fulfillment: ", slowestFulfillment)
fastestFulfillment, err := consumer.SFastestFulfillment(nil)
helpers.PanicErr(err)
fmt.Println("Fastest Fulfillment: ", fastestFulfillment)
v2plusscripts.GetLoadTestMetricsFromConsumer(common.HexToAddress(*consumerAddress), e)
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
43 changes: 28 additions & 15 deletions core/scripts/vrfv2plus/testnet/v2plusscripts/super_scripts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import (
"encoding/hex"
"flag"
"fmt"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/shopspring/decimal"
"github.com/smartcontractkit/chainlink/core/scripts/common/vrf/constants"
"github.com/smartcontractkit/chainlink/core/scripts/common/vrf/jobs"
"github.com/smartcontractkit/chainlink/core/scripts/common/vrf/model"
Expand All @@ -16,13 +22,6 @@ import (
"os"
"strings"

"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/shopspring/decimal"

helpers "github.com/smartcontractkit/chainlink/core/scripts/common"
evmclient "github.com/smartcontractkit/chainlink/v2/core/chains/evm/client"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/batch_blockhash_store"
Expand All @@ -46,6 +45,13 @@ type CoordinatorConfigV2Plus struct {
FeeConfig vrf_coordinator_v2_5.VRFCoordinatorV25FeeConfig
}

type RandRequestConfig struct {
ConsumerAddress common.Address
SubID *big.Int
KeyHash common.Hash
MinConfs uint
}

func SmokeTestVRF(e helpers.Environment) {
smokeCmd := flag.NewFlagSet("smoke", flag.ExitOnError)

Expand Down Expand Up @@ -554,15 +560,16 @@ func DeployUniverseViaCLI(e helpers.Environment) {
}
}

func VRFV2PlusDeployUniverse(e helpers.Environment,
func VRFV2PlusDeployUniverse(
e helpers.Environment,
subscriptionBalanceJuels *big.Int,
subscriptionBalanceNativeWei *big.Int,
registerKeyUncompressedPubKey *string,
contractAddresses model.ContractAddresses,
coordinatorConfig CoordinatorConfigV2Plus,
batchFulfillmentEnabled bool,
nodesMap map[string]model.Node,
) model.JobSpecs {
) (model.JobSpecs, RandRequestConfig) {
// Put key in ECDSA format
if strings.HasPrefix(*registerKeyUncompressedPubKey, "0x") {
*registerKeyUncompressedPubKey = strings.Replace(*registerKeyUncompressedPubKey, "0x", "04", 1)
Expand Down Expand Up @@ -758,12 +765,18 @@ func VRFV2PlusDeployUniverse(e helpers.Environment,
)

return model.JobSpecs{
VRFPrimaryNode: formattedVrfV2PlusPrimaryJobSpec,
VRFBackupyNode: formattedVrfV2PlusBackupJobSpec,
BHSNode: formattedBHSJobSpec,
BHSBackupNode: formattedBHSBackupJobSpec,
BHFNode: formattedBHFJobSpec,
}
VRFPrimaryNode: formattedVrfV2PlusPrimaryJobSpec,
VRFBackupyNode: formattedVrfV2PlusBackupJobSpec,
BHSNode: formattedBHSJobSpec,
BHSBackupNode: formattedBHSBackupJobSpec,
BHFNode: formattedBHFJobSpec,
},
RandRequestConfig{
ConsumerAddress: consumerAddress,
SubID: subID,
KeyHash: keyHash,
MinConfs: uint(*coordinatorConfig.MinConfs),
}
}

func DeployWrapperUniverse(e helpers.Environment) {
Expand Down
Loading

0 comments on commit 5692621

Please sign in to comment.