forked from moondance-labs/tanssi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:task management pallet and spec upgrade
- Loading branch information
Showing
11 changed files
with
1,203 additions
and
1 deletion.
There are no files selected for viewing
File renamed without changes.
Binary file not shown.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
[package] | ||
name = "pallet-task-management" | ||
description = "Creation and management of tasks for workers to consume" | ||
version = "0.1.0" | ||
authors.workspace = true | ||
repository.workspace = true | ||
edition = "2021" | ||
publish = false | ||
|
||
[package.metadata.docs.rs] | ||
targets = ["x86_64-unknown-linux-gnu"] | ||
|
||
[dependencies] | ||
parity-scale-codec = { workspace = true, default-features = false, features = [ | ||
"derive", | ||
] } | ||
scale-info = { workspace = true , default-features = false, features = ["derive"] } | ||
|
||
# frame deps | ||
frame-benchmarking = { vworkspace = true, optional = true } | ||
frame-support = { workspace = true } | ||
frame-system = { workspace = true } | ||
|
||
# Local | ||
pallet-edge-connect = { verson = "0.1.0", default-features = false, path = "../edge-connect" } | ||
|
||
sp-core = { workspace = true } | ||
sp-io = { workspace = true } | ||
log = { workspace = true } | ||
|
||
[dev-dependencies] | ||
sp-runtime = { workspace = true } | ||
sp-std = { workspace = true } | ||
|
||
[features] | ||
default = ["std"] | ||
runtime-benchmarks = [ | ||
"frame-benchmarking/runtime-benchmarks", | ||
"frame-support/runtime-benchmarks", | ||
"frame-system/runtime-benchmarks", | ||
] | ||
std = [ | ||
"parity-scale-codec/std", | ||
"frame-benchmarking?/std", | ||
"frame-support/std", | ||
"frame-system/std", | ||
"scale-info/std", | ||
"pallet-edge-connect/std", | ||
] | ||
try-runtime = [ | ||
"frame-support/try-runtime", | ||
"frame-system/try-runtime", | ||
] |
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 |
---|---|---|
@@ -0,0 +1,158 @@ | ||
//! Benchmarking setup for pallet-task-management | ||
use super::*; | ||
use crate::{Pallet as TaskManagementModule, Config}; | ||
use frame_benchmarking::{benchmarks, account, whitelisted_caller}; | ||
use frame_support::BoundedVec; | ||
use sp_core::H256; | ||
use frame_system::RawOrigin; | ||
|
||
benchmarks! { | ||
task_scheduler { | ||
let s in 0 .. 100; | ||
let caller: T::AccountId = whitelisted_caller(); | ||
|
||
// Register a worker for the caller | ||
let api_info = pallet_edge_connect::types::WorkerAPI { | ||
ip: None, | ||
domain: Some(BoundedVec::try_from(b"https://api-worker.testing".to_vec()).unwrap()) | ||
}; | ||
pallet_edge_connect::Pallet::<T>::register_worker(RawOrigin::Signed(caller.clone()).into(), api_info.ip, api_info.domain)?; | ||
|
||
let task_data = BoundedVec::try_from(b"some-docker-imgv.0".to_vec()).unwrap(); | ||
}: _(RawOrigin::Signed(caller.clone()), task_data.clone()) | ||
verify { | ||
let task_id = TaskManagementModule::<T>::next_task_id() - 1; | ||
let task_info = TaskManagementModule::<T>::get_tasks(task_id).unwrap(); | ||
assert_eq!(task_info.metadata, task_data); | ||
assert_eq!(task_info.task_owner, caller); | ||
} | ||
|
||
submit_completed_task { | ||
let s in 0 .. 100; | ||
let caller: T::AccountId = whitelisted_caller(); | ||
|
||
// Register a worker for the executor | ||
let executor: T::AccountId = account("executor", 0, 0); | ||
let api_info = pallet_edge_connect::types::WorkerAPI { | ||
ip: None, | ||
domain: Some(BoundedVec::try_from(b"https://api-worker.testing".to_vec()).unwrap()) | ||
}; | ||
pallet_edge_connect::Pallet::<T>::register_worker(RawOrigin::Signed(executor.clone()).into(), api_info.ip, api_info.domain)?; | ||
|
||
// Create a task data | ||
let task_data = BoundedVec::try_from(b"some-docker-imgv.0".to_vec()).unwrap(); | ||
TaskManagementModule::<T>::task_scheduler(RawOrigin::Signed(caller.clone()).into(), task_data.clone())?; | ||
|
||
// Register a worker for the verifier | ||
let verifier: T::AccountId = account("verifier", 0, 0); | ||
let api_info_verifier = pallet_edge_connect::types::WorkerAPI { | ||
ip: None, | ||
domain: Some(BoundedVec::try_from(b"https://api-worker2.testing".to_vec()).unwrap()) | ||
}; | ||
pallet_edge_connect::Pallet::<T>::register_worker(RawOrigin::Signed(verifier.clone()).into(), api_info_verifier.ip, api_info_verifier.domain)?; | ||
|
||
let task_id = TaskManagementModule::<T>::next_task_id() - 1; | ||
let completed_hash = H256([123; 32]); | ||
}: _(RawOrigin::Signed(executor.clone()), task_id, completed_hash) | ||
verify { | ||
let task_status = TaskManagementModule::<T>::task_status(task_id).unwrap(); | ||
assert_eq!(task_status, TaskStatusType::PendingValidation); | ||
|
||
let verifications = TaskManagementModule::<T>::task_verifications(task_id).unwrap(); | ||
assert_eq!(verifications.executor.account, executor); | ||
assert_eq!(verifications.executor.completed_hash, Some(completed_hash)); | ||
assert_eq!(verifications.verifier.clone().unwrap().account, verifier); | ||
assert_eq!(verifications.verifier.clone().unwrap().completed_hash, None); | ||
} | ||
|
||
verify_completed_task { | ||
let s in 0 .. 100; | ||
let caller: T::AccountId = whitelisted_caller(); | ||
let executor: T::AccountId = account("executor", 0, 0); | ||
let verifier: T::AccountId = account("verifier", 0, 0); | ||
|
||
// Register a worker for the executor | ||
let api_info_executor = pallet_edge_connect::types::WorkerAPI { | ||
ip: None, | ||
domain: Some(BoundedVec::try_from(b"https://api-worker.testing".to_vec()).unwrap()) | ||
}; | ||
pallet_edge_connect::Pallet::<T>::register_worker(RawOrigin::Signed(executor.clone()).into(), api_info_executor.ip, api_info_executor.domain)?; | ||
|
||
// Create a task data | ||
let task_data = BoundedVec::try_from(b"some-docker-imgv.0".to_vec()).unwrap(); | ||
TaskManagementModule::<T>::task_scheduler(RawOrigin::Signed(caller.clone()).into(), task_data.clone())?; | ||
|
||
// Register a worker for the verifier | ||
let api_info_verifier = pallet_edge_connect::types::WorkerAPI { | ||
ip: None, | ||
domain: Some(BoundedVec::try_from(b"https://api-worker2.testing".to_vec()).unwrap()) | ||
}; | ||
pallet_edge_connect::Pallet::<T>::register_worker(RawOrigin::Signed(verifier.clone()).into(), api_info_verifier.ip, api_info_verifier.domain)?; | ||
|
||
let task_id = TaskManagementModule::<T>::next_task_id() - 1; | ||
|
||
let completed_hash = H256([123; 32]); | ||
TaskManagementModule::<T>::submit_completed_task(RawOrigin::Signed(executor.clone()).into(), task_id, completed_hash)?; | ||
|
||
}: _(RawOrigin::Signed(verifier.clone()), task_id, completed_hash) | ||
verify { | ||
let task_status = TaskManagementModule::<T>::task_status(task_id).unwrap(); | ||
assert_eq!(task_status, TaskStatusType::Completed); | ||
} | ||
|
||
resolve_completed_task { | ||
let s in 0 .. 100; | ||
let caller: T::AccountId = whitelisted_caller(); | ||
|
||
let executor: T::AccountId = account("executor", 0, 0); | ||
let verifier: T::AccountId = account("verifier", 0, 0); | ||
let resolver: T::AccountId = account("resolver", 0, 0); | ||
|
||
// Register a worker for the executor | ||
let api_info_executor = pallet_edge_connect::types::WorkerAPI { | ||
ip: None, | ||
domain: Some(BoundedVec::try_from(b"https://api-worker.testing".to_vec()).unwrap()) | ||
}; | ||
pallet_edge_connect::Pallet::<T>::register_worker(RawOrigin::Signed(executor.clone()).into(), api_info_executor.ip, api_info_executor.domain)?; | ||
|
||
// Create a task data | ||
let task_data = BoundedVec::try_from(b"some-docker-imgv.0".to_vec()).unwrap(); | ||
TaskManagementModule::<T>::task_scheduler(RawOrigin::Signed(caller.clone()).into(), task_data.clone())?; | ||
let task_id = TaskManagementModule::<T>::next_task_id() - 1; | ||
|
||
// Register a worker for the verifier | ||
let api_info_verifier = pallet_edge_connect::types::WorkerAPI { | ||
ip: None, | ||
domain: Some(BoundedVec::try_from(b"https://api-worker2.testing".to_vec()).unwrap()) | ||
}; | ||
pallet_edge_connect::Pallet::<T>::register_worker(RawOrigin::Signed(verifier.clone()).into(), api_info_verifier.ip, api_info_verifier.domain)?; | ||
|
||
// Submit completed task by the executor | ||
let completed_hash = H256([4; 32]); | ||
TaskManagementModule::<T>::submit_completed_task(RawOrigin::Signed(executor.clone()).into(), task_id, completed_hash)?; | ||
|
||
// Register a worker for the resolver | ||
let api_info_resolver = pallet_edge_connect::types::WorkerAPI { | ||
ip: None, | ||
domain: Some(BoundedVec::try_from(b"https://api-worker3.testing".to_vec()).unwrap()) | ||
}; | ||
pallet_edge_connect::Pallet::<T>::register_worker(RawOrigin::Signed(resolver.clone()).into(), api_info_resolver.ip, api_info_resolver.domain)?; | ||
|
||
let completed_differing_hash = H256([123; 32]); | ||
// Verify completed task by the verifier | ||
TaskManagementModule::<T>::verify_completed_task(RawOrigin::Signed(verifier.clone()).into(), task_id, completed_differing_hash)?; | ||
|
||
let verifications = TaskManagementModule::<T>::task_verifications(task_id).unwrap(); | ||
assert_eq!(verifications.executor.account, executor); | ||
assert_eq!(verifications.executor.completed_hash, Some(completed_hash)); | ||
assert_eq!(verifications.verifier.clone().unwrap().account, verifier); | ||
assert_eq!(verifications.verifier.clone().unwrap().completed_hash, Some(completed_differing_hash)); | ||
|
||
}: _(RawOrigin::Signed(resolver.clone()), task_id, completed_differing_hash) | ||
verify { | ||
let task_status = TaskManagementModule::<T>::task_status(task_id).unwrap(); | ||
assert_eq!(task_status, TaskStatusType::Completed); | ||
} | ||
|
||
impl_benchmark_test_suite!(TaskManagementModule, crate::mock::new_test_ext(), crate::mock::Test); | ||
} |
Oops, something went wrong.