Skip to content

Commit

Permalink
CTF test for replaying req after node restart (#12410)
Browse files Browse the repository at this point in the history
* CTF test for replaying req after node restart

* Addressed PR comments

* GHA workflow fix

* Code maintenance improvements

* Type failures fix

* Addressed more PR comments

* Dependency fix

* Dependency fix

* Avoid copying config

* Minor change
  • Loading branch information
kidambisrinivas authored Mar 14, 2024
1 parent ebed509 commit caab80d
Show file tree
Hide file tree
Showing 5 changed files with 261 additions and 179 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ jobs:
os: ubuntu-latest
pyroscope_env: ci-smoke-vrf2-evm-simulated
- name: vrfv2plus
nodes: 4
nodes: 5
os: ubuntu-latest
pyroscope_env: ci-smoke-vrf2plus-evm-simulated
- name: forwarder_ocr
Expand Down
1 change: 1 addition & 0 deletions integration-tests/actions/vrf/common/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type VRFKeyData struct {
VRFKey *client.VRFKey
EncodedProvingKey VRFEncodedProvingKey
KeyHash [32]byte
PubKeyCompressed string
}

type VRFNodeType int
Expand Down
129 changes: 43 additions & 86 deletions integration-tests/actions/vrf/vrfv2plus/vrfv2plus_steps.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ func SetupVRFV2_5Environment(
g := errgroup.Group{}
if vrfNode, exists := nodeTypeToNodeMap[vrfcommon.VRF]; exists {
g.Go(func() error {
err := setupVRFNode(vrfContracts, chainID, configGeneral, pubKeyCompressed, l, vrfNode)
err := SetupVRFNode(vrfContracts, chainID, configGeneral, pubKeyCompressed, l, vrfNode)
if err != nil {
return err
}
Expand Down Expand Up @@ -270,6 +270,7 @@ func SetupVRFV2_5Environment(
VRFKey: vrfKey,
EncodedProvingKey: provingKey,
KeyHash: keyHash,
PubKeyCompressed: pubKeyCompressed,
}

l.Info().Msg("VRFV2 Plus environment setup is finished")
Expand Down Expand Up @@ -334,7 +335,7 @@ func SetupVRFV2PlusContracts(
return vrfContracts, subIDs, nil
}

func setupVRFNode(contracts *vrfcommon.VRFContracts, chainID *big.Int, config *vrfv2plus_config.General, pubKeyCompressed string, l zerolog.Logger, vrfNode *vrfcommon.VRFNode) error {
func SetupVRFNode(contracts *vrfcommon.VRFContracts, chainID *big.Int, config *vrfv2plus_config.General, pubKeyCompressed string, l zerolog.Logger, vrfNode *vrfcommon.VRFNode) error {
vrfJobSpecConfig := vrfcommon.VRFJobSpecConfig{
ForwardingAllowed: *config.VRFJobForwardingAllowed,
CoordinatorAddress: contracts.CoordinatorV2Plus.Address(),
Expand Down Expand Up @@ -563,35 +564,26 @@ func RequestRandomnessAndWaitForFulfillment(
vrfKeyData *vrfcommon.VRFKeyData,
subID *big.Int,
isNativeBilling bool,
minimumConfirmations uint16,
callbackGasLimit uint32,
numberOfWords uint32,
randomnessRequestCountPerRequest uint16,
randomnessRequestCountPerRequestDeviation uint16,
randomWordsFulfilledEventTimeout time.Duration,
config *vrfv2plus_config.General,
l zerolog.Logger,
) (*vrf_coordinator_v2_5.VRFCoordinatorV25RandomWordsFulfilled, error) {
logRandRequest(
LogRandRequest(
l,
consumer.Address(),
coordinator.Address(),
subID,
isNativeBilling,
minimumConfirmations,
callbackGasLimit,
numberOfWords,
vrfKeyData.KeyHash,
randomnessRequestCountPerRequest,
randomnessRequestCountPerRequestDeviation,
config,
)
_, err := consumer.RequestRandomness(
vrfKeyData.KeyHash,
subID,
minimumConfirmations,
callbackGasLimit,
*config.MinimumConfirmations,
*config.CallbackGasLimit,
isNativeBilling,
numberOfWords,
randomnessRequestCountPerRequest,
*config.NumberOfWords,
*config.RandomnessRequestCountPerRequest,
)
if err != nil {
return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrRequestRandomness, err)
Expand All @@ -603,7 +595,7 @@ func RequestRandomnessAndWaitForFulfillment(
vrfKeyData,
subID,
isNativeBilling,
randomWordsFulfilledEventTimeout,
config.RandomWordsFulfilledEventTimeout.Duration,
l,
)
}
Expand All @@ -614,35 +606,26 @@ func RequestRandomnessAndWaitForFulfillmentUpgraded(
vrfKeyData *vrfcommon.VRFKeyData,
subID *big.Int,
isNativeBilling bool,
minimumConfirmations uint16,
callbackGasLimit uint32,
numberOfWords uint32,
randomnessRequestCountPerRequest uint16,
randomnessRequestCountPerRequestDeviation uint16,
randomWordsFulfilledEventTimeout time.Duration,
config *vrfv2plus_config.General,
l zerolog.Logger,
) (*vrf_v2plus_upgraded_version.VRFCoordinatorV2PlusUpgradedVersionRandomWordsFulfilled, error) {
logRandRequest(
LogRandRequest(
l,
consumer.Address(),
coordinator.Address(),
subID,
isNativeBilling,
minimumConfirmations,
callbackGasLimit,
numberOfWords,
vrfKeyData.KeyHash,
randomnessRequestCountPerRequest,
randomnessRequestCountPerRequestDeviation,
config,
)
_, err := consumer.RequestRandomness(
vrfKeyData.KeyHash,
subID,
minimumConfirmations,
callbackGasLimit,
*config.MinimumConfirmations,
*config.CallbackGasLimit,
isNativeBilling,
numberOfWords,
randomnessRequestCountPerRequest,
*config.NumberOfWords,
*config.RandomnessRequestCountPerRequest,
)
if err != nil {
return nil, fmt.Errorf("%s, err %w", vrfcommon.ErrRequestRandomness, err)
Expand All @@ -654,7 +637,7 @@ func RequestRandomnessAndWaitForFulfillmentUpgraded(
vrfKeyData,
subID,
isNativeBilling,
randomWordsFulfilledEventTimeout,
config.RandomWordsFulfilledEventTimeout.Duration,
l,
)
}
Expand Down Expand Up @@ -801,41 +784,33 @@ func WrapperRequestRandomness(
vrfKeyData *vrfcommon.VRFKeyData,
subID *big.Int,
isNativeBilling bool,
minimumConfirmations uint16,
callbackGasLimit uint32,
numberOfWords uint32,
randomnessRequestCountPerRequest uint16,
randomnessRequestCountPerRequestDeviation uint16,
config *vrfv2plus_config.General,
l zerolog.Logger) (string, error) {
logRandRequest(
LogRandRequest(
l,
consumer.Address(),
coordinatorAddress,
subID,
isNativeBilling,
minimumConfirmations,
callbackGasLimit,
numberOfWords,
vrfKeyData.KeyHash,
randomnessRequestCountPerRequest,
randomnessRequestCountPerRequestDeviation,
config,
)
if isNativeBilling {
_, err := consumer.RequestRandomnessNative(
minimumConfirmations,
callbackGasLimit,
numberOfWords,
randomnessRequestCountPerRequest,
*config.MinimumConfirmations,
*config.CallbackGasLimit,
*config.NumberOfWords,
*config.RandomnessRequestCountPerRequest,
)
if err != nil {
return "", fmt.Errorf("%s, err %w", ErrRequestRandomnessDirectFundingNativePayment, err)
}
} else {
_, err := consumer.RequestRandomness(
minimumConfirmations,
callbackGasLimit,
numberOfWords,
randomnessRequestCountPerRequest,
*config.MinimumConfirmations,
*config.CallbackGasLimit,
*config.NumberOfWords,
*config.RandomnessRequestCountPerRequest,
)
if err != nil {
return "", fmt.Errorf("%s, err %w", ErrRequestRandomnessDirectFundingLinkPayment, err)
Expand All @@ -854,18 +829,11 @@ func DirectFundingRequestRandomnessAndWaitForFulfillment(
vrfKeyData *vrfcommon.VRFKeyData,
subID *big.Int,
isNativeBilling bool,
minimumConfirmations uint16,
callbackGasLimit uint32,
numberOfWords uint32,
randomnessRequestCountPerRequest uint16,
randomnessRequestCountPerRequestDeviation uint16,
randomWordsFulfilledEventTimeout time.Duration,
config *vrfv2plus_config.General,
l zerolog.Logger,
) (*vrf_coordinator_v2_5.VRFCoordinatorV25RandomWordsFulfilled, error) {
wrapperAddress, err := WrapperRequestRandomness(consumer, coordinator.Address(), vrfKeyData, subID,
isNativeBilling, minimumConfirmations, callbackGasLimit, numberOfWords,
randomnessRequestCountPerRequest, randomnessRequestCountPerRequestDeviation,
l)
isNativeBilling, config, l)
if err != nil {
return nil, fmt.Errorf("error getting wrapper address, err: %w", err)
}
Expand All @@ -875,7 +843,7 @@ func DirectFundingRequestRandomnessAndWaitForFulfillment(
vrfKeyData,
subID,
isNativeBilling,
randomWordsFulfilledEventTimeout,
config.RandomWordsFulfilledEventTimeout.Duration,
l,
)
}
Expand All @@ -886,18 +854,11 @@ func DirectFundingRequestRandomnessAndWaitForFulfillmentUpgraded(
vrfKeyData *vrfcommon.VRFKeyData,
subID *big.Int,
isNativeBilling bool,
minimumConfirmations uint16,
callbackGasLimit uint32,
numberOfWords uint32,
randomnessRequestCountPerRequest uint16,
randomnessRequestCountPerRequestDeviation uint16,
randomWordsFulfilledEventTimeout time.Duration,
config *vrfv2plus_config.General,
l zerolog.Logger,
) (*vrf_v2plus_upgraded_version.VRFCoordinatorV2PlusUpgradedVersionRandomWordsFulfilled, error) {
wrapperAddress, err := WrapperRequestRandomness(consumer, coordinator.Address(), vrfKeyData, subID,
isNativeBilling, minimumConfirmations, callbackGasLimit, numberOfWords,
randomnessRequestCountPerRequest, randomnessRequestCountPerRequestDeviation,
l)
isNativeBilling, config, l)
if err != nil {
return nil, fmt.Errorf("error getting wrapper address, err: %w", err)
}
Expand All @@ -907,7 +868,7 @@ func DirectFundingRequestRandomnessAndWaitForFulfillmentUpgraded(
vrfKeyData,
subID,
isNativeBilling,
randomWordsFulfilledEventTimeout,
config.RandomWordsFulfilledEventTimeout.Duration,
l,
)
}
Expand Down Expand Up @@ -1161,28 +1122,24 @@ func LogFulfillmentDetailsNativeBilling(
Msg("Random Words Request Fulfilment Details For Native Billing")
}

func logRandRequest(
func LogRandRequest(
l zerolog.Logger,
consumer string,
coordinator string,
subID *big.Int,
isNativeBilling bool,
minimumConfirmations uint16,
callbackGasLimit uint32,
numberOfWords uint32,
keyHash [32]byte,
randomnessRequestCountPerRequest uint16,
randomnessRequestCountPerRequestDeviation uint16) {
config *vrfv2plus_config.General) {
l.Info().
Str("Consumer", consumer).
Str("Coordinator", coordinator).
Str("SubID", subID.String()).
Bool("IsNativePayment", isNativeBilling).
Uint16("MinimumConfirmations", minimumConfirmations).
Uint32("CallbackGasLimit", callbackGasLimit).
Uint32("NumberOfWords", numberOfWords).
Uint16("MinimumConfirmations", *config.MinimumConfirmations).
Uint32("CallbackGasLimit", *config.CallbackGasLimit).
Uint32("NumberOfWords", *config.NumberOfWords).
Str("KeyHash", fmt.Sprintf("0x%x", keyHash)).
Uint16("RandomnessRequestCountPerRequest", randomnessRequestCountPerRequest).
Uint16("RandomnessRequestCountPerRequestDeviation", randomnessRequestCountPerRequestDeviation).
Uint16("RandomnessRequestCountPerRequest", *config.RandomnessRequestCountPerRequest).
Uint16("RandomnessRequestCountPerRequestDeviation", *config.RandomnessRequestCountPerRequestDeviation).
Msg("Requesting randomness")
}
10 changes: 3 additions & 7 deletions integration-tests/load/vrfv2plus/gun.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ func (m *SingleHashGun) Call(_ *wasp.Generator) *wasp.Response {
}

//randomly increase/decrease randomness request count per TX
randomnessRequestCountPerRequest := deviateValue(*m.testConfig.GetVRFv2PlusConfig().General.RandomnessRequestCountPerRequest, *m.testConfig.GetVRFv2PlusConfig().General.RandomnessRequestCountPerRequestDeviation)
reqCount := deviateValue(*m.testConfig.GetVRFv2PlusConfig().General.RandomnessRequestCountPerRequest, *m.testConfig.GetVRFv2PlusConfig().General.RandomnessRequestCountPerRequestDeviation)
m.testConfig.GetVRFv2PlusConfig().General.RandomnessRequestCountPerRequest = &reqCount
_, err = vrfv2plus.RequestRandomnessAndWaitForFulfillment(
//the same consumer is used for all requests and in all subs
m.contracts.VRFV2PlusConsumer[0],
Expand All @@ -60,12 +61,7 @@ func (m *SingleHashGun) Call(_ *wasp.Generator) *wasp.Response {
m.subIDs[randInRange(0, len(m.subIDs)-1)],
//randomly pick payment type
billingType,
*m.testConfig.GetVRFv2PlusConfig().General.MinimumConfirmations,
*m.testConfig.GetVRFv2PlusConfig().General.CallbackGasLimit,
*m.testConfig.GetVRFv2PlusConfig().General.NumberOfWords,
randomnessRequestCountPerRequest,
*m.testConfig.GetVRFv2PlusConfig().General.RandomnessRequestCountPerRequestDeviation,
m.testConfig.GetVRFv2PlusConfig().General.RandomWordsFulfilledEventTimeout.Duration,
m.testConfig.GetVRFv2PlusConfig().General,
m.logger,
)
if err != nil {
Expand Down
Loading

0 comments on commit caab80d

Please sign in to comment.