-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6537104
commit 7e314f3
Showing
8 changed files
with
235 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,104 @@ | ||
package pvf | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
|
||
parachainruntime "github.com/ChainSafe/gossamer/dot/parachain/runtime" | ||
parachaintypes "github.com/ChainSafe/gossamer/dot/parachain/types" | ||
"sync" | ||
) | ||
|
||
type worker struct { | ||
workerID parachaintypes.ValidationCodeHash | ||
instance *parachainruntime.Instance | ||
queue chan *workerTask | ||
} | ||
|
||
func newWorker(pID parachaintypes.ValidationCodeHash) *worker { | ||
return &worker{ | ||
workerID: pID, | ||
type workerTask struct { | ||
work parachainruntime.ValidationParameters | ||
maxPoVSize uint32 | ||
ResultCh chan<- *ValidationTaskResult | ||
} | ||
|
||
func newWorker(validationCode parachaintypes.ValidationCode, queue chan *workerTask) (*worker, error) { | ||
validationRuntime, err := parachainruntime.SetupVM(validationCode) | ||
|
||
if err != nil { | ||
return nil, err | ||
} | ||
return &worker{ | ||
workerID: validationCode.Hash(), | ||
instance: validationRuntime, | ||
queue: queue, | ||
}, nil | ||
} | ||
|
||
func (w *worker) run(queue chan *ValidationTask, wg *sync.WaitGroup) { | ||
func (w *worker) run(queue chan *workerTask, wg *sync.WaitGroup) { | ||
defer func() { | ||
logger.Debugf("[STOPPED] worker %x", w.workerID) | ||
wg.Done() | ||
}() | ||
|
||
for task := range queue { | ||
executeRequest(task) | ||
w.executeRequest(task) | ||
} | ||
} | ||
|
||
func executeRequest(task *ValidationTask) { | ||
func (w *worker) executeRequest(task *workerTask) { | ||
// WIP: This is a dummy implementation of the worker execution for the validation task. The logic for | ||
// validating the parachain block request should be implemented here. | ||
request := task.PoV | ||
logger.Debugf("[EXECUTING] worker %x, block request: %s", task.WorkerID, request) | ||
time.Sleep(500 * time.Millisecond) | ||
dummyResult := &ValidationResult{} | ||
logger.Debugf("[EXECUTING] worker %x task %v", w.workerID, task.work) | ||
|
||
// todo do basic checks | ||
|
||
validationResult, err := w.instance.ValidateBlock(task.work) | ||
|
||
/////////////////////////////// | ||
//if err != nil { | ||
// return nil, fmt.Errorf("executing validate_block: %w", err) | ||
//} | ||
|
||
//headDataHash, err := validationResult.HeadData.Hash() | ||
//if err != nil { | ||
// return nil, fmt.Errorf("hashing head data: %w", err) | ||
//} | ||
// | ||
//if headDataHash != candidateReceipt.Descriptor.ParaHead { | ||
// ci := pvf.ParaHeadHashMismatch | ||
// return &pvf.ValidationResult{InvalidResult: &ci}, nil | ||
//} | ||
candidateCommitments := parachaintypes.CandidateCommitments{ | ||
UpwardMessages: validationResult.UpwardMessages, | ||
HorizontalMessages: validationResult.HorizontalMessages, | ||
NewValidationCode: validationResult.NewValidationCode, | ||
HeadData: validationResult.HeadData, | ||
ProcessedDownwardMessages: validationResult.ProcessedDownwardMessages, | ||
HrmpWatermark: validationResult.HrmpWatermark, | ||
} | ||
|
||
// if validation produced a new set of commitments, we treat the candidate as invalid | ||
//if candidateReceipt.CommitmentsHash != candidateCommitments.Hash() { | ||
// ci := CommitmentsHashMismatch | ||
// return &ValidationResult{InvalidResult: &ci}, nil | ||
//} | ||
pvd := parachaintypes.PersistedValidationData{ | ||
ParentHead: task.work.ParentHeadData, | ||
RelayParentNumber: task.work.RelayParentNumber, | ||
RelayParentStorageRoot: task.work.RelayParentStorageRoot, | ||
MaxPovSize: task.maxPoVSize, | ||
} | ||
dummyResilt := &ValidationResult{ | ||
ValidResult: &ValidValidationResult{ | ||
CandidateCommitments: candidateCommitments, | ||
PersistedValidationData: pvd, | ||
}, | ||
} | ||
////////////////////////// | ||
|
||
logger.Debugf("[RESULT] worker %x, result: %v, error: %s", w.workerID, dummyResilt, err) | ||
|
||
task.ResultCh <- &ValidationTaskResult{ | ||
who: *task.WorkerID, | ||
result: dummyResult, | ||
who: w.workerID, | ||
Result: dummyResilt, | ||
} | ||
|
||
logger.Debugf("[FINISHED] worker %x", task.WorkerID) | ||
//logger.Debugf("[FINISHED] worker %v, error: %s", validationResult, err) | ||
} |
Oops, something went wrong.