Skip to content

Commit

Permalink
VRF-678:create sub, fund it, deploy consumer and add to sub when usin… (
Browse files Browse the repository at this point in the history
#11086)

* VRF-678:create sub, fund it, deploy consumer and add to sub when using VRFV2 Plus WASP load test with existing env

* VRF-678: cleanup

* VRF-678: fixing smoke test; adding additional logging
  • Loading branch information
iljapavlovs authored Oct 27, 2023
1 parent eabdba0 commit 01200f8
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type VRFV2PlusConfig struct {
UseExistingEnv bool `envconfig:"USE_EXISTING_ENV" default:"false"` // Whether to use an existing environment or create a new one
CoordinatorAddress string `envconfig:"COORDINATOR_ADDRESS" default:""` // Coordinator address
ConsumerAddress string `envconfig:"CONSUMER_ADDRESS" default:""` // Consumer address
LinkAddress string `envconfig:"LINK_ADDRESS" default:""` // Link address
SubID string `envconfig:"SUB_ID" default:""` // Subscription ID
KeyHash string `envconfig:"KEY_HASH" default:""`
}
96 changes: 62 additions & 34 deletions integration-tests/actions/vrfv2plus/vrfv2plus_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,16 @@ func SetupVRFV2_5Environment(
mockNativeLINKFeed contracts.MockETHLINKFeed,
numberOfConsumers int,
numberOfSubToCreate int,
l zerolog.Logger,
) (*VRFV2_5Contracts, []*big.Int, *VRFV2PlusData, error) {

l.Info().Msg("Starting VRFV2 Plus environment setup")
l.Info().Msg("Deploying VRFV2 Plus contracts")
vrfv2_5Contracts, err := DeployVRFV2_5Contracts(env.ContractDeployer, env.EVMClient, numberOfConsumers)
if err != nil {
return nil, nil, nil, errors.Wrap(err, ErrDeployVRFV2_5Contracts)
}

l.Info().Str("Coordinator", vrfv2_5Contracts.Coordinator.Address()).Msg("Setting Coordinator Config")
err = vrfv2_5Contracts.Coordinator.SetConfig(
vrfv2PlusConfig.MinimumConfirmations,
vrfv2PlusConfig.MaxGasLimitCoordinatorConfig,
Expand All @@ -263,6 +266,7 @@ func SetupVRFV2_5Environment(
return nil, nil, nil, errors.Wrap(err, ErrSetVRFCoordinatorConfig)
}

l.Info().Str("Coordinator", vrfv2_5Contracts.Coordinator.Address()).Msg("Setting Link and ETH/LINK feed")
err = vrfv2_5Contracts.Coordinator.SetLINKAndLINKNativeFeed(linkToken.Address(), mockNativeLINKFeed.Address())
if err != nil {
return nil, nil, nil, errors.Wrap(err, ErrSetLinkNativeLinkFeed)
Expand All @@ -271,32 +275,12 @@ func SetupVRFV2_5Environment(
if err != nil {
return nil, nil, nil, errors.Wrap(err, ErrWaitTXsComplete)
}

subIDs, err := CreateSubsAndFund(env, vrfv2PlusConfig, linkToken, vrfv2_5Contracts, numberOfSubToCreate)
if err != nil {
return nil, nil, nil, err
}

subToConsumersMap := map[*big.Int][]contracts.VRFv2PlusLoadTestConsumer{}

//each subscription will have the same consumers
for _, subID := range subIDs {
subToConsumersMap[subID] = vrfv2_5Contracts.LoadTestConsumers
}

err = AddConsumersToSubs(
subToConsumersMap,
vrfv2_5Contracts.Coordinator,
)
l.Info().Str("Coordinator", vrfv2_5Contracts.Coordinator.Address()).Msg("Creating and funding subscriptions, adding consumers")
subIDs, err := CreateFundSubsAndAddConsumers(env, vrfv2PlusConfig, linkToken, vrfv2_5Contracts.Coordinator, vrfv2_5Contracts.LoadTestConsumers, numberOfSubToCreate)
if err != nil {
return nil, nil, nil, err
}

err = env.EVMClient.WaitForEvents()
if err != nil {
return nil, nil, nil, errors.Wrap(err, ErrWaitTXsComplete)
}

l.Info().Str("Node URL", env.ClCluster.NodeAPIs()[0].URL()).Msg("Creating VRF Key on the Node")
vrfKey, err := env.ClCluster.NodeAPIs()[0].MustCreateVRFKey()
if err != nil {
return nil, nil, nil, errors.Wrap(err, ErrCreatingVRFv2PlusKey)
Expand All @@ -307,6 +291,7 @@ func SetupVRFV2_5Environment(
if err != nil {
return nil, nil, nil, errors.Wrap(err, ErrNodePrimaryKey)
}
l.Info().Str("Coordinator", vrfv2_5Contracts.Coordinator.Address()).Msg("Registering Proving Key")
provingKey, err := VRFV2_5RegisterProvingKey(vrfKey, nativeTokenPrimaryKeyAddress, vrfv2_5Contracts.Coordinator)
if err != nil {
return nil, nil, nil, errors.Wrap(err, ErrRegisteringProvingKey)
Expand All @@ -318,6 +303,7 @@ func SetupVRFV2_5Environment(

chainID := env.EVMClient.GetChainID()

l.Info().Msg("Creating VRFV2 Plus Job")
job, err := CreateVRFV2PlusJob(
env.ClCluster.NodeAPIs()[0],
vrfv2_5Contracts.Coordinator.Address(),
Expand All @@ -340,6 +326,7 @@ func SetupVRFV2_5Environment(
nodeConfig := node.NewConfig(env.ClCluster.Nodes[0].NodeConfig,
node.WithVRFv2EVMEstimator(addr),
)
l.Info().Msg("Restarting Node with new sending key PriceMax configuration")
err = env.ClCluster.Nodes[0].Restart(nodeConfig)
if err != nil {
return nil, nil, nil, errors.Wrap(err, ErrRestartCLNode)
Expand All @@ -358,25 +345,60 @@ func SetupVRFV2_5Environment(
chainID,
}

l.Info().Msg("VRFV2 Plus environment setup is finished")
return vrfv2_5Contracts, subIDs, &data, nil
}

func CreateFundSubsAndAddConsumers(
env *test_env.CLClusterTestEnv,
vrfv2PlusConfig *vrfv2plus_config.VRFV2PlusConfig,
linkToken contracts.LinkToken,
coordinator contracts.VRFCoordinatorV2_5,
consumers []contracts.VRFv2PlusLoadTestConsumer,
numberOfSubToCreate int,
) ([]*big.Int, error) {
subIDs, err := CreateSubsAndFund(env, vrfv2PlusConfig, linkToken, coordinator, numberOfSubToCreate)
if err != nil {
return nil, err
}
subToConsumersMap := map[*big.Int][]contracts.VRFv2PlusLoadTestConsumer{}

//each subscription will have the same consumers
for _, subID := range subIDs {
subToConsumersMap[subID] = consumers
}

err = AddConsumersToSubs(
subToConsumersMap,
coordinator,
)
if err != nil {
return nil, err
}

err = env.EVMClient.WaitForEvents()
if err != nil {
return nil, errors.Wrap(err, ErrWaitTXsComplete)
}
return subIDs, nil
}

func CreateSubsAndFund(
env *test_env.CLClusterTestEnv,
vrfv2PlusConfig *vrfv2plus_config.VRFV2PlusConfig,
linkToken contracts.LinkToken,
vrfv2_5Contracts *VRFV2_5Contracts,
coordinator contracts.VRFCoordinatorV2_5,
subAmountToCreate int,
) ([]*big.Int, error) {
subs, err := CreateSubs(env, vrfv2_5Contracts.Coordinator, subAmountToCreate)
subs, err := CreateSubs(env, coordinator, subAmountToCreate)
if err != nil {
return nil, err
}
err = env.EVMClient.WaitForEvents()
if err != nil {
return nil, errors.Wrap(err, ErrWaitTXsComplete)
}
err = FundSubscriptions(env, vrfv2PlusConfig, linkToken, vrfv2_5Contracts.Coordinator, subs)
err = FundSubscriptions(env, vrfv2PlusConfig, linkToken, coordinator, subs)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -503,21 +525,27 @@ func SetupVRFV2PlusWrapperEnvironment(
return wrapperContracts, wrapperSubID, nil
}
func CreateSubAndFindSubID(env *test_env.CLClusterTestEnv, coordinator contracts.VRFCoordinatorV2_5) (*big.Int, error) {
err := coordinator.CreateSubscription()
tx, err := coordinator.CreateSubscription()
if err != nil {
return nil, errors.Wrap(err, ErrCreateVRFSubscription)
}

sub, err := coordinator.WaitForSubscriptionCreatedEvent(time.Second * 10)
err = env.EVMClient.WaitForEvents()
if err != nil {
return nil, errors.Wrap(err, ErrFindSubID)
return nil, errors.Wrap(err, ErrWaitTXsComplete)
}

err = env.EVMClient.WaitForEvents()
receipt, err := env.EVMClient.GetTxReceipt(tx.Hash())

//SubscriptionsCreated Log should be emitted with the subscription ID
subID := receipt.Logs[0].Topics[1].Big()

//verify that the subscription was created
_, err = coordinator.FindSubscriptionID(subID)
if err != nil {
return nil, errors.Wrap(err, ErrWaitTXsComplete)
return nil, errors.Wrap(err, ErrFindSubID)
}
return sub.SubId, nil

return subID, nil
}

func GetUpgradedCoordinatorTotalBalance(coordinator contracts.VRFCoordinatorV2PlusUpgradedVersion) (linkTotalBalance *big.Int, nativeTokenTotalBalance *big.Int, err error) {
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/contracts/contract_vrf_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type VRFCoordinatorV2_5 interface {
publicProvingKey [2]*big.Int,
) error
HashOfKey(ctx context.Context, pubKey [2]*big.Int) ([32]byte, error)
CreateSubscription() error
CreateSubscription() (*types.Transaction, error)
GetActiveSubscriptionIds(ctx context.Context, startIndex *big.Int, maxCount *big.Int) ([]*big.Int, error)
Migrate(subId *big.Int, coordinatorAddress string) error
RegisterMigratableCoordinator(migratableCoordinatorAddress string) error
Expand All @@ -83,7 +83,7 @@ type VRFCoordinatorV2_5 interface {
GetSubscription(ctx context.Context, subID *big.Int) (vrf_coordinator_v2_5.GetSubscription, error)
GetNativeTokenTotalBalance(ctx context.Context) (*big.Int, error)
GetLinkTotalBalance(ctx context.Context) (*big.Int, error)
FindSubscriptionID() (*big.Int, error)
FindSubscriptionID(subID *big.Int) (*big.Int, error)
WaitForSubscriptionCreatedEvent(timeout time.Duration) (*vrf_coordinator_v2_5.VRFCoordinatorV25SubscriptionCreated, error)
WaitForRandomWordsFulfilledEvent(subID []*big.Int, requestID []*big.Int, timeout time.Duration) (*vrf_coordinator_v2_5.VRFCoordinatorV25RandomWordsFulfilled, error)
WaitForRandomWordsRequestedEvent(keyHash [][32]byte, subID []*big.Int, sender []common.Address, timeout time.Duration) (*vrf_coordinator_v2_5.VRFCoordinatorV25RandomWordsRequested, error)
Expand Down
12 changes: 6 additions & 6 deletions integration-tests/contracts/ethereum_vrfv2plus_contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,16 @@ func (v *EthereumVRFCoordinatorV2_5) RegisterProvingKey(
return v.client.ProcessTransaction(tx)
}

func (v *EthereumVRFCoordinatorV2_5) CreateSubscription() error {
func (v *EthereumVRFCoordinatorV2_5) CreateSubscription() (*types.Transaction, error) {
opts, err := v.client.TransactionOpts(v.client.GetDefaultWallet())
if err != nil {
return err
return nil, err
}
tx, err := v.coordinator.CreateSubscription(opts)
if err != nil {
return err
return nil, err
}
return v.client.ProcessTransaction(tx)
return tx, v.client.ProcessTransaction(tx)
}

func (v *EthereumVRFCoordinatorV2_5) Migrate(subId *big.Int, coordinatorAddress string) error {
Expand Down Expand Up @@ -250,11 +250,11 @@ func (v *EthereumVRFCoordinatorV2_5) FundSubscriptionWithNative(subId *big.Int,
return v.client.ProcessTransaction(tx)
}

func (v *EthereumVRFCoordinatorV2_5) FindSubscriptionID() (*big.Int, error) {
func (v *EthereumVRFCoordinatorV2_5) FindSubscriptionID(subID *big.Int) (*big.Int, error) {
owner := v.client.GetDefaultWallet().Address()
subscriptionIterator, err := v.coordinator.FilterSubscriptionCreated(
nil,
nil,
[]*big.Int{subID},
)
if err != nil {
return nil, err
Expand Down
13 changes: 10 additions & 3 deletions integration-tests/load/vrfv2plus/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ type PerformanceConfig struct {
type ExistingEnvConfig struct {
CoordinatorAddress string `toml:"coordinator_address"`
ConsumerAddress string `toml:"consumer_address"`
LinkAddress string `toml:"link_address"`
SubID string `toml:"sub_id"`
KeyHash string `toml:"key_hash"`
SubFunding
CreateFundSubsAndAddConsumers bool `toml:"create_fund_subs_and_add_consumers"`
}

type NewEnvConfig struct {
Expand All @@ -49,9 +52,13 @@ type Common struct {
}

type Funding struct {
NodeFunds float64 `toml:"node_funds"`
SubFundsLink int64 `toml:"sub_funds_link"`
SubFundsNative int64 `toml:"sub_funds_native"`
NodeFunds float64 `toml:"node_funds"`
SubFunding
}

type SubFunding struct {
SubFundsLink int64 `toml:"sub_funds_link"`
SubFundsNative int64 `toml:"sub_funds_native"`
}

type Soak struct {
Expand Down
18 changes: 10 additions & 8 deletions integration-tests/load/vrfv2plus/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
minimum_confirmations = 3

[NewEnvConfig]
sub_funds_link = 1000
sub_funds_native = 1000
sub_funds_link = 1
sub_funds_native = 1
node_funds = 10


[ExistingEnvConfig]
coordinator_address = "0x4931Ce2e341398c8eD8A5D0F6ADb920476D6DaBb"
coordinator_address = "0x27b61f155F772b291D1d9B478BeAd37B2Ae447b0"
consumer_address = "0x087F232165D9bA1A602f148025e5D0666953F64a"
sub_id = "52116875585187328970776211988181422347535732407068188096422095950800466618218"
key_hash = "0x4c422465ed6a06cfc84575a5437fef7b9dc6263133f648afbe6ae7b2c694d3b3"

key_hash = "0x787d74caea10b2b357790d5b5247c2f63d1d91572a9846f780606e4d953677ae"
create_fund_subs_and_add_consumers = true
link_address = "0x779877A7B0D9E8603169DdbD7836e478b4624789"
sub_funds_link = 3
sub_funds_native = 1

# 10 RPM - 1 tx request with 1 rand request in each tx every 6 seconds
[Soak]
Expand All @@ -29,15 +31,15 @@ rate_limit_unit_duration = "3s"
rps = 1
randomness_request_count_per_request = 3 # amount of randomness requests to make per one TX request
randomness_request_count_per_request_deviation = 2 #NOTE - deviation should be less than randomness_request_count_per_request setting
number_of_sub_to_create = 10
number_of_sub_to_create = 5

# approx 540 RPM - 3 tx requests per second with 4 rand requests in each tx
[Stress]
rate_limit_unit_duration = "1s"
rps = 3
randomness_request_count_per_request = 4 # amount of randomness requests to make per one TX request
randomness_request_count_per_request_deviation = 0 #NOTE - deviation should be less than randomness_request_count_per_request setting
number_of_sub_to_create = 20
number_of_sub_to_create = 5

# approx 150 RPM - 1 tx request with 150 rand requests in each tx every 60 seconds
[Spike]
Expand Down
Loading

0 comments on commit 01200f8

Please sign in to comment.