From c96f6e8a2378c5a3b15f75861dea9ba4dfb2c843 Mon Sep 17 00:00:00 2001 From: edwardmack Date: Wed, 11 Sep 2024 08:46:43 -0400 Subject: [PATCH] add addition validation timeout tests --- .../candidate_validation.go | 2 - .../candidate-validation/worker_test.go | 85 ++++++++++++------- 2 files changed, 55 insertions(+), 32 deletions(-) diff --git a/dot/parachain/candidate-validation/candidate_validation.go b/dot/parachain/candidate-validation/candidate_validation.go index 945b31d51f..44882c5aa1 100644 --- a/dot/parachain/candidate-validation/candidate_validation.go +++ b/dot/parachain/candidate-validation/candidate_validation.go @@ -190,8 +190,6 @@ func (cv *CandidateValidation) validateFromChainState(msg ValidateFromChainState CandidateReceipt: &msg.CandidateReceipt, PoV: msg.Pov, ExecutorParams: msg.ExecutorParams, - // todo: implement PvfExecTimeoutKind, so that validate can be called with a timeout see issue: #3429 - PvfExecTimeoutKind: parachaintypes.PvfExecTimeoutKind{}, } result, err := cv.pvfHost.validate(validationTask) diff --git a/dot/parachain/candidate-validation/worker_test.go b/dot/parachain/candidate-validation/worker_test.go index ad1c8e6ddc..e265f82c85 100644 --- a/dot/parachain/candidate-validation/worker_test.go +++ b/dot/parachain/candidate-validation/worker_test.go @@ -21,12 +21,43 @@ func Test_worker_executeRequest(t *testing.T) { ctrl := gomock.NewController(t) t.Cleanup(ctrl.Finish) + expectedValidationResult := &ValidationResult{ + ValidResult: &Valid{ + CandidateCommitments: parachaintypes.CandidateCommitments{ + HeadData: parachaintypes.HeadData{Data: []byte{2, 0, 0, 0, 0, 0, 0, 0, 123, 207, 206, 8, 219, 227, + 136, 82, 236, 169, 14, 100, 45, 100, 31, 177, 154, 160, 220, 245, 59, 106, 76, 168, 122, 109, + 164, 169, 22, 46, 144, 39, 103, 92, 31, 78, 66, 72, 252, 64, 24, 194, 129, 162, 128, 1, 77, 147, + 200, 229, 189, 242, 111, 198, 236, 139, 16, 143, 19, 245, 113, 233, 138, 210}}, + ProcessedDownwardMessages: 0, + HrmpWatermark: 1, + }, + PersistedValidationData: parachaintypes.PersistedValidationData{ + ParentHead: parachaintypes.HeadData{Data: []byte{1, 0, 0, 0, 0, 0, 0, 0, 1, + 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, + 8, 9, 0, 1, 2, 48, 246, 146, 178, 86, 226, 64, 9, + 188, 179, 77, 14, 232, 77, 167, 60, 41, 138, 250, 204, 9, 36, 224, 17, 5, 226, 235, + 15, 1, 168, 127, 226}}, + RelayParentNumber: 1, + RelayParentStorageRoot: common.MustHexToHash( + "0x50c969706800c0e9c3c4565dc2babb25e4a73d1db0dee1bcf7745535a32e7ca1"), + MaxPovSize: 2048, + }, + }, + } + mockValidationInstance := NewMockValidatorInstance(ctrl) - mockValidationInstance.EXPECT().ValidateBlock(gomock.Any()).DoAndReturn(func(params parachain. + mockValidationInstance.EXPECT().ValidateBlock(gomock.Any()).DoAndReturn(func(parachain. ValidationParameters) (*parachain.ValidationResult, error) { - time.Sleep(3 * time.Second) // sleep to simulate long execution time - return ¶chain.ValidationResult{}, nil - }) + time.Sleep(3 * time.Second) // sleep to simulate execution time + return ¶chain.ValidationResult{ + HeadData: parachaintypes.HeadData{Data: []byte{2, 0, 0, 0, 0, 0, 0, 0, 123, 207, 206, 8, 219, 227, + 136, 82, 236, 169, 14, 100, 45, 100, 31, 177, 154, 160, 220, 245, 59, 106, 76, 168, 122, 109, + 164, 169, 22, 46, 144, 39, 103, 92, 31, 78, 66, 72, 252, 64, 24, 194, 129, 162, 128, 1, 77, 147, + 200, 229, 189, 242, 111, 198, 236, 139, 16, 143, 19, 245, 113, 233, 138, 210}}, + ProcessedDownwardMessages: 0, + HrmpWatermark: 1, + }, nil + }).Times(2) candidateReceiptCommitmentsMismatch := candidateReceipt candidateReceiptCommitmentsMismatch.CommitmentsHash = common.MustHexToHash( @@ -52,6 +83,10 @@ func Test_worker_executeRequest(t *testing.T) { }) require.NoError(t, err) + timeoutKind := parachaintypes.NewPvfExecTimeoutKind() + err = timeoutKind.SetValue(parachaintypes.Approval{}) + require.NoError(t, err) + commitmentsHashMismatch := CommitmentsHashMismatch timeout := Timeout @@ -85,6 +120,21 @@ func Test_worker_executeRequest(t *testing.T) { InvalidResult: &timeout, }, }, + "long_timeout_ok": { + instance: mockValidationInstance, + task: &workerTask{ + work: parachain.ValidationParameters{ + ParentHeadData: parachaintypes.HeadData{Data: hd}, + BlockData: blockData, + RelayParentNumber: uint32(1), + RelayParentStorageRoot: common.MustHexToHash("0x50c969706800c0e9c3c4565dc2babb25e4a73d1db0dee1bcf7745535a32e7ca1"), + }, + candidateReceipt: &candidateReceipt, + timeoutKind: timeoutKind, + maxPoVSize: 2048, + }, + want: expectedValidationResult, + }, "happy_path": { instance: validationRuntime, task: &workerTask{ @@ -98,32 +148,7 @@ func Test_worker_executeRequest(t *testing.T) { candidateReceipt: &candidateReceipt, timeoutKind: parachaintypes.PvfExecTimeoutKind{}, }, - want: &ValidationResult{ - ValidResult: &Valid{ - CandidateCommitments: parachaintypes.CandidateCommitments{ - UpwardMessages: nil, - HorizontalMessages: nil, - NewValidationCode: nil, - HeadData: parachaintypes.HeadData{Data: []byte{2, 0, 0, 0, 0, 0, 0, 0, 123, 207, 206, 8, 219, 227, - 136, 82, 236, 169, 14, 100, 45, 100, 31, 177, 154, 160, 220, 245, 59, 106, 76, 168, 122, 109, - 164, 169, 22, 46, 144, 39, 103, 92, 31, 78, 66, 72, 252, 64, 24, 194, 129, 162, 128, 1, 77, 147, - 200, 229, 189, 242, 111, 198, 236, 139, 16, 143, 19, 245, 113, 233, 138, 210}}, - ProcessedDownwardMessages: 0, - HrmpWatermark: 1, - }, - PersistedValidationData: parachaintypes.PersistedValidationData{ - ParentHead: parachaintypes.HeadData{Data: []byte{1, 0, 0, 0, 0, 0, 0, 0, 1, - 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3, 4, 5, 6, 7, - 8, 9, 0, 1, 2, 48, 246, 146, 178, 86, 226, 64, 9, - 188, 179, 77, 14, 232, 77, 167, 60, 41, 138, 250, 204, 9, 36, 224, 17, 5, 226, 235, - 15, 1, 168, 127, 226}}, - RelayParentNumber: 1, - RelayParentStorageRoot: common.MustHexToHash( - "0x50c969706800c0e9c3c4565dc2babb25e4a73d1db0dee1bcf7745535a32e7ca1"), - MaxPovSize: 2048, - }, - }, - }, + want: expectedValidationResult, }, } for name, tt := range tests {