From 3e5ac2809d9e581675fbf1dc0e59e964bb9fedf9 Mon Sep 17 00:00:00 2001 From: edwardmack Date: Wed, 4 Sep 2024 11:00:18 -0400 Subject: [PATCH] make private functions/structs private --- .../candidate-validation/candidate_validation.go | 8 ++++---- .../candidate-validation/candidate_validation_test.go | 4 ++-- dot/parachain/candidate-validation/host.go | 8 ++++---- dot/parachain/candidate-validation/host_test.go | 4 ++-- dot/parachain/candidate-validation/worker.go | 1 - dot/parachain/candidate-validation/worker_pool.go | 5 +++-- 6 files changed, 15 insertions(+), 15 deletions(-) diff --git a/dot/parachain/candidate-validation/candidate_validation.go b/dot/parachain/candidate-validation/candidate_validation.go index 15f9a51f6e..ff53d3be02 100644 --- a/dot/parachain/candidate-validation/candidate_validation.go +++ b/dot/parachain/candidate-validation/candidate_validation.go @@ -18,7 +18,7 @@ import ( type CandidateValidation struct { SubsystemToOverseer chan<- any BlockState BlockState - pvfHost *Host + pvfHost *host } type BlockState interface { @@ -29,7 +29,7 @@ type BlockState interface { func NewCandidateValidation(overseerChan chan<- any, blockState BlockState) *CandidateValidation { candidateValidation := CandidateValidation{ SubsystemToOverseer: overseerChan, - pvfHost: NewValidationHost(), + pvfHost: newValidationHost(), BlockState: blockState, } return &candidateValidation @@ -86,7 +86,7 @@ func (cv *CandidateValidation) processMessage(msg any) { PvfExecTimeoutKind: msg.PvfExecTimeoutKind, } - result, err := cv.pvfHost.Validate(validationTask) + result, err := cv.pvfHost.validate(validationTask) if err != nil { logger.Errorf("failed to validate from exhaustive: %w", err) @@ -183,7 +183,7 @@ func (cv *CandidateValidation) validateFromChainState(msg ValidateFromChainState PvfExecTimeoutKind: parachaintypes.PvfExecTimeoutKind{}, } - result, err := cv.pvfHost.Validate(validationTask) + result, err := cv.pvfHost.validate(validationTask) if err != nil { msg.Ch <- parachaintypes.OverseerFuncRes[ValidationResult]{ Err: err, diff --git a/dot/parachain/candidate-validation/candidate_validation_test.go b/dot/parachain/candidate-validation/candidate_validation_test.go index cee8513d71..8ddd514a8d 100644 --- a/dot/parachain/candidate-validation/candidate_validation_test.go +++ b/dot/parachain/candidate-validation/candidate_validation_test.go @@ -137,7 +137,7 @@ func TestCandidateValidation_processMessageValidateFromExhaustive(t *testing.T) overseerToSubsystem := make(chan any) sender := make(chan parachaintypes.OverseerFuncRes[ValidationResult]) candidateValidationSubsystem := CandidateValidation{ - pvfHost: NewValidationHost(), + pvfHost: newValidationHost(), } t.Cleanup(candidateValidationSubsystem.Stop) @@ -371,7 +371,7 @@ func TestCandidateValidation_processMessageValidateFromChainState(t *testing.T) sender := make(chan parachaintypes.OverseerFuncRes[ValidationResult]) toSubsystem := make(chan any) candidateValidationSubsystem := CandidateValidation{ - pvfHost: NewValidationHost(), + pvfHost: newValidationHost(), BlockState: mockBlockState, } defer candidateValidationSubsystem.Stop() diff --git a/dot/parachain/candidate-validation/host.go b/dot/parachain/candidate-validation/host.go index 47f9b438aa..62d71a584c 100644 --- a/dot/parachain/candidate-validation/host.go +++ b/dot/parachain/candidate-validation/host.go @@ -10,17 +10,17 @@ import ( var logger = log.NewFromGlobal(log.AddContext("pkg", "pvf"), log.SetLevel(log.Debug)) -type Host struct { +type host struct { workerPool *workerPool } -func NewValidationHost() *Host { - return &Host{ +func newValidationHost() *host { + return &host{ workerPool: newValidationWorkerPool(), } } -func (v *Host) Validate(msg *ValidationTask) (*ValidationResult, error) { +func (v *host) validate(msg *ValidationTask) (*ValidationResult, error) { validationCodeHash := msg.ValidationCode.Hash() // performBasicChecks validationErr, internalErr := performBasicChecks(&msg.CandidateReceipt.Descriptor, diff --git a/dot/parachain/candidate-validation/host_test.go b/dot/parachain/candidate-validation/host_test.go index 5d6d6fff2c..35a00971c1 100644 --- a/dot/parachain/candidate-validation/host_test.go +++ b/dot/parachain/candidate-validation/host_test.go @@ -30,7 +30,7 @@ func TestHost_validate(t *testing.T) { commitmentsHashMismatch := CommitmentsHashMismatch executionError := ExecutionError - pvfHost := NewValidationHost() + pvfHost := newValidationHost() bd, err := scale.Marshal(BlockDataInAdderParachain{ State: uint64(1), @@ -204,7 +204,7 @@ func TestHost_validate(t *testing.T) { t.Run(name, func(t *testing.T) { t.Parallel() - taskResult, err := pvfHost.Validate(tt.validationTask) + taskResult, err := pvfHost.validate(tt.validationTask) require.NoError(t, err) require.Equal(t, tt.want, taskResult) diff --git a/dot/parachain/candidate-validation/worker.go b/dot/parachain/candidate-validation/worker.go index 5c5c4c1b14..a4db27355d 100644 --- a/dot/parachain/candidate-validation/worker.go +++ b/dot/parachain/candidate-validation/worker.go @@ -44,7 +44,6 @@ func (w *worker) executeRequest(task *workerTask) (*ValidationResult, error) { return processed, nil } validationResult, err := w.instance.ValidateBlock(task.work) - if err != nil { logger.Errorf("executing validate_block: %w", err) reasonForInvalidity := ExecutionError diff --git a/dot/parachain/candidate-validation/worker_pool.go b/dot/parachain/candidate-validation/worker_pool.go index 8524dc9ff7..15561a4fc3 100644 --- a/dot/parachain/candidate-validation/worker_pool.go +++ b/dot/parachain/candidate-validation/worker_pool.go @@ -127,8 +127,9 @@ func (v *workerPool) newValidationWorker(validationCode parachaintypes.Validatio return nil } -// submitRequest given a request, the worker pool will get the worker for a given workerID -// a channel in returned that the response will be dispatch on +// submitRequest given a request, the worker pool will get the worker for a given task and submit the request +// to the worker. The worker will execute the request and return the result. If the worker does not exist, a new worker +// will be created and the request will be submitted to the worker. func (v *workerPool) submitRequest(msg *ValidationTask) (*ValidationResult, error) { validationCodeHash := msg.ValidationCode.Hash()