From e4c072c0b283354596c34b9287587e1e188cdf78 Mon Sep 17 00:00:00 2001 From: 1xstj <106580853+1xstj@users.noreply.github.com> Date: Mon, 8 Jan 2024 10:36:55 +0000 Subject: [PATCH 1/2] fix : remove custom prefix for testnet (#406) * update staking and token supply * update staking params * fix distribution * fix distribution * fix : remove custom prefix for testnet --- node/src/chainspec/testnet.rs | 4 ++-- runtime/testnet/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/node/src/chainspec/testnet.rs b/node/src/chainspec/testnet.rs index 334aa7aeb..639ef9efc 100644 --- a/node/src/chainspec/testnet.rs +++ b/node/src/chainspec/testnet.rs @@ -93,7 +93,7 @@ pub fn local_testnet_config(chain_id: u64) -> Result { let mut properties = sc_chain_spec::Properties::new(); properties.insert("tokenSymbol".into(), "tTNT".into()); properties.insert("tokenDecimals".into(), 18u32.into()); - properties.insert("ss58Format".into(), tangle_primitives::TESTNET_SS58_PREFIX.into()); + properties.insert("ss58Format".into(), 42.into()); Ok(ChainSpec::from_genesis( // Name @@ -151,7 +151,7 @@ pub fn tangle_testnet_config(chain_id: u64) -> Result { let mut properties = sc_chain_spec::Properties::new(); properties.insert("tokenSymbol".into(), "tTNT".into()); properties.insert("tokenDecimals".into(), 18u32.into()); - properties.insert("ss58Format".into(), tangle_primitives::TESTNET_SS58_PREFIX.into()); + properties.insert("ss58Format".into(), 42.into()); Ok(ChainSpec::from_genesis( "Tangle Testnet", diff --git a/runtime/testnet/src/lib.rs b/runtime/testnet/src/lib.rs index c2d053dac..9af39bbea 100644 --- a/runtime/testnet/src/lib.rs +++ b/runtime/testnet/src/lib.rs @@ -179,7 +179,7 @@ parameter_types! { ::with_sensible_defaults(MAXIMUM_BLOCK_WEIGHT, NORMAL_DISPATCH_RATIO); pub BlockLength: frame_system::limits::BlockLength = frame_system::limits::BlockLength ::max_with_normal_ratio(MAXIMUM_BLOCK_LENGTH, NORMAL_DISPATCH_RATIO); - pub const SS58Prefix: u16 = tangle_primitives::TESTNET_SS58_PREFIX; + pub const SS58Prefix: u8 = 42; } /// Opaque types. These are used by the CLI to instantiate machinery that don't need to know From af3548e391351aa6a9b635e1bb95174bbdc8bf95 Mon Sep 17 00:00:00 2001 From: shekohex Date: Mon, 8 Jan 2024 14:44:49 +0200 Subject: [PATCH 2/2] feat: Jobs TTL and Expiry (#404) * feat: Jobs TTL and Expiry * fix: remove unused events and hooks * fix typo using GitHub for mobile. * Update SlashDeferDuration * Update SlashDeferDuration. * fix CI --- pallets/jobs/rpc/runtime-api/src/lib.rs | 11 ++-- pallets/jobs/rpc/src/lib.rs | 20 +++--- pallets/jobs/src/functions.rs | 48 +++++++------- pallets/jobs/src/lib.rs | 15 ++--- pallets/jobs/src/rpc.rs | 84 ++++++------------------- pallets/jobs/src/tests.rs | 18 ++++-- precompiles/jobs/src/lib.rs | 20 ++++-- precompiles/jobs/src/tests.rs | 6 +- primitives/src/jobs/mod.rs | 44 ++++++++----- runtime/mainnet/src/lib.rs | 4 +- runtime/testnet/src/lib.rs | 11 ++-- 11 files changed, 138 insertions(+), 143 deletions(-) diff --git a/pallets/jobs/rpc/runtime-api/src/lib.rs b/pallets/jobs/rpc/runtime-api/src/lib.rs index 6959ee811..4a95cab71 100644 --- a/pallets/jobs/rpc/runtime-api/src/lib.rs +++ b/pallets/jobs/rpc/runtime-api/src/lib.rs @@ -25,6 +25,9 @@ use tangle_primitives::{ roles::RoleType, }; +pub type BlockNumberOf = + <::HeaderT as sp_runtime::traits::Header>::Number; + sp_api::decl_runtime_apis! { pub trait JobsApi where AccountId: Codec + MaybeDisplay + Serialize, @@ -33,7 +36,7 @@ sp_api::decl_runtime_apis! { /// /// This function takes a `validator` parameter of type `AccountId` and attempts /// to retrieve a list of jobs associated with the provided validator. If successful, - /// it constructs a vector of `RpcResponseJobsData` containing information + /// it constructs a vector of `RpcResponseJobsData` containing information /// about the jobs and returns it as a `Result`. /// /// # Arguments @@ -43,7 +46,7 @@ sp_api::decl_runtime_apis! { /// # Returns /// /// An optional vec of `RpcResponseJobsData` of jobs assigned to validator - fn query_jobs_by_validator(validator: AccountId) -> Option>>; + fn query_jobs_by_validator(validator: AccountId) -> Option>>>; /// Queries a job by its key and ID. /// /// # Arguments @@ -54,7 +57,7 @@ sp_api::decl_runtime_apis! { /// # Returns /// /// An optional `RpcResponseJobsData` containing the account ID of the job. - fn query_job_by_id(role_type: RoleType, job_id: JobId) -> Option>; + fn query_job_by_id(role_type: RoleType, job_id: JobId) -> Option>>; /// Queries the phase one result of a job by its key and ID. /// @@ -66,7 +69,7 @@ sp_api::decl_runtime_apis! { /// # Returns /// /// An `Option` containing the phase one result of the job, wrapped in an `RpcResponsePhaseOneResult`. - fn query_phase_one_by_id(role_type: RoleType, job_id: JobId) -> Option>; + fn query_phase_one_by_id(role_type: RoleType, job_id: JobId) -> Option>>; /// Queries next job ID. /// diff --git a/pallets/jobs/rpc/src/lib.rs b/pallets/jobs/rpc/src/lib.rs index e4f32b7fa..0abe1f084 100644 --- a/pallets/jobs/rpc/src/lib.rs +++ b/pallets/jobs/rpc/src/lib.rs @@ -34,15 +34,18 @@ use tangle_primitives::{ roles::RoleType, }; +type BlockNumberOf = + <::HeaderT as sp_runtime::traits::Header>::Number; + /// JobsClient RPC methods. #[rpc(client, server)] -pub trait JobsApi { +pub trait JobsApi { #[method(name = "jobs_queryJobsByValidator")] fn query_jobs_by_validator( &self, at: Option, validator: AccountId, - ) -> RpcResult>>>; + ) -> RpcResult>>>; #[method(name = "jobs_queryJobById")] fn query_job_by_id( @@ -50,7 +53,7 @@ pub trait JobsApi { at: Option, role_type: RoleType, job_id: JobId, - ) -> RpcResult>>; + ) -> RpcResult>>; #[method(name = "jobs_queryPhaseOneById")] fn query_phase_one_by_id( @@ -58,7 +61,7 @@ pub trait JobsApi { at: Option, role_type: RoleType, job_id: JobId, - ) -> RpcResult>>; + ) -> RpcResult>>; #[method(name = "jobs_queryNextJobId")] fn query_next_job_id(&self, at: Option) -> RpcResult; @@ -77,7 +80,7 @@ impl JobsClient { } } -impl JobsApiServer<::Hash, AccountId> +impl JobsApiServer<::Hash, AccountId, BlockNumberOf> for JobsClient where Block: BlockT, @@ -89,7 +92,7 @@ where &self, at: Option<::Hash>, validator: AccountId, - ) -> RpcResult>>> { + ) -> RpcResult>>>> { let api = self.client.runtime_api(); let at = at.unwrap_or_else(|| self.client.info().best_hash); @@ -104,10 +107,9 @@ where at: Option<::Hash>, role_type: RoleType, job_id: JobId, - ) -> RpcResult>> { + ) -> RpcResult>>> { let api = self.client.runtime_api(); let at = at.unwrap_or_else(|| self.client.info().best_hash); - match api.query_job_by_id(at, role_type, job_id) { Ok(res) => Ok(res), Err(e) => Err(runtime_error_into_rpc_err(e)), @@ -119,7 +121,7 @@ where at: Option<::Hash>, role_type: RoleType, job_id: JobId, - ) -> RpcResult>> { + ) -> RpcResult>>> { let api = self.client.runtime_api(); let at = at.unwrap_or_else(|| self.client.info().best_hash); diff --git a/pallets/jobs/src/functions.rs b/pallets/jobs/src/functions.rs index bad9eed69..af7037108 100644 --- a/pallets/jobs/src/functions.rs +++ b/pallets/jobs/src/functions.rs @@ -179,7 +179,8 @@ impl Pallet { // charge the validator fee for job submission let job = JobSubmissionOf:: { - expiry: phase1.expiry, + expiry: job_info.expiry, + ttl: job_info.ttl, job_type: job_type.clone(), }; @@ -193,7 +194,8 @@ impl Pallet { let job_info = JobInfo { owner: phase1.owner.clone(), - expiry: phase1.expiry, + expiry: job_info.expiry, + ttl: job_info.ttl, job_type, fee, }; @@ -232,7 +234,8 @@ impl Pallet { // charge the validator fee for job submission let job = JobSubmissionOf:: { - expiry: phase1.expiry, + expiry: job_info.expiry, + ttl: job_info.ttl, job_type: job_type.clone(), }; @@ -246,7 +249,8 @@ impl Pallet { let job_info = JobInfo { owner: phase1.owner.clone(), - expiry: phase1.expiry, + expiry: job_info.expiry, + ttl: job_info.ttl, job_type, fee, }; @@ -297,15 +301,15 @@ impl Pallet { T::MPCHandler::verify(JobWithResult { job_type: job_info.job_type.clone(), phase_one_job_type: None, - result: job_result, + result: job_result.clone(), })?; let result = PhaseResult { owner: job_info.owner.clone(), - expiry: job_info.expiry, job_type: job_info.job_type.clone(), + ttl: job_info.ttl, permitted_caller: job_info.job_type.clone().get_permitted_caller(), - result: info.key, + result: job_result, }; Ok(result) } @@ -330,7 +334,7 @@ impl Pallet { .ok_or(Error::::PreviousResultNotFound)?; // Validate existing result - ensure!(phase_one_result.expiry >= now, Error::::ResultExpired); + ensure!(phase_one_result.ttl >= now, Error::::ResultExpired); // ensure the participants are the expected participants from job let mut participant_keys: Vec = Default::default(); @@ -345,11 +349,14 @@ impl Pallet { .map_err(|_| Error::::InvalidValidator)?; participant_keys.push(pub_key); } - + let signing_key = match phase_one_result.result { + JobResult::DKGPhaseOne(result) => result.key, + _ => return Err(Error::::InvalidJobPhase.into()), + }; let job_result = JobResult::DKGPhaseTwo(DKGTSSSignatureResult { signature: info.signature.clone(), data: info.data, - signing_key: phase_one_result.result, + signing_key, signature_type: info.signature_type, }); @@ -361,15 +368,15 @@ impl Pallet { T::MPCHandler::verify(JobWithResult { job_type: job_info.job_type.clone(), phase_one_job_type: Some(phase_one_job_info.job_type), - result: job_result, + result: job_result.clone(), })?; let result = PhaseResult { owner: job_info.owner.clone(), - expiry: job_info.expiry, + ttl: job_info.ttl, job_type: job_info.job_type.clone(), permitted_caller: job_info.job_type.clone().get_permitted_caller(), - result: info.signature, + result: job_result, }; Ok(result) } @@ -409,15 +416,14 @@ impl Pallet { T::MPCHandler::verify(JobWithResult { job_type: job_info.job_type.clone(), phase_one_job_type: None, - result: job_result, + result: job_result.clone(), })?; let result = PhaseResult { owner: job_info.owner.clone(), - expiry: job_info.expiry, + ttl: job_info.ttl, job_type: job_info.job_type.clone(), - // No data in the result - result: Vec::new(), + result: job_result, permitted_caller: job_info.job_type.clone().get_permitted_caller(), }; Ok(result) @@ -444,7 +450,7 @@ impl Pallet { .ok_or(Error::::PreviousResultNotFound)?; // Validate existing result - ensure!(phase_one_result.expiry >= now, Error::::ResultExpired); + ensure!(phase_one_result.ttl >= now, Error::::ResultExpired); let job_result = JobResult::ZkSaaSPhaseTwo(info.clone()); @@ -456,14 +462,14 @@ impl Pallet { T::MPCHandler::verify(JobWithResult { job_type: job_info.job_type.clone(), phase_one_job_type: Some(phase_one_job_info.job_type), - result: job_result, + result: job_result.clone(), })?; let result = PhaseResult { owner: job_info.owner.clone(), - expiry: job_info.expiry, + ttl: job_info.ttl, job_type: job_info.job_type.clone(), - result: info.proof(), + result: job_result, permitted_caller: job_info.job_type.clone().get_permitted_caller(), }; Ok(result) diff --git a/pallets/jobs/src/lib.rs b/pallets/jobs/src/lib.rs index 92c943af9..fad071a33 100644 --- a/pallets/jobs/src/lib.rs +++ b/pallets/jobs/src/lib.rs @@ -126,7 +126,7 @@ pub mod module { } #[pallet::event] - #[pallet::generate_deposit(fn deposit_event)] + #[pallet::generate_deposit(pub(crate) fn deposit_event)] pub enum Event { /// A new job has been submitted JobSubmitted { job_id: JobId, role_type: RoleType, details: JobSubmissionOf }, @@ -148,14 +148,8 @@ pub mod module { #[pallet::storage] #[pallet::getter(fn known_results)] - pub type KnownResults = StorageDoubleMap< - _, - Twox64Concat, - RoleType, - Blake2_128Concat, - JobId, - PhaseResult>, - >; + pub type KnownResults = + StorageDoubleMap<_, Twox64Concat, RoleType, Blake2_128Concat, JobId, PhaseResultOf>; #[pallet::storage] #[pallet::getter(fn validator_job_id_lookup)] @@ -244,7 +238,7 @@ pub mod module { .ok_or(Error::::PreviousResultNotFound)?; // Validate existing result - ensure!(result.expiry >= now, Error::::ResultExpired); + ensure!(result.ttl >= now, Error::::ResultExpired); // Ensure the phase one participants are still validators let participants = result.participants().ok_or(Error::::InvalidJobPhase)?; @@ -279,6 +273,7 @@ pub mod module { // store the job to pallet let job_info = JobInfo { owner: caller.clone(), + ttl: job.ttl, expiry: job.expiry, job_type: job.job_type.clone(), fee, diff --git a/pallets/jobs/src/rpc.rs b/pallets/jobs/src/rpc.rs index 453ddc622..0c1867291 100644 --- a/pallets/jobs/src/rpc.rs +++ b/pallets/jobs/src/rpc.rs @@ -7,7 +7,7 @@ impl Pallet { /// /// This function takes a `validator` parameter of type `T::AccountId` and attempts /// to retrieve a list of jobs associated with the provided validator. If successful, - /// it constructs a vector of `RpcResponseJobsData` containing information + /// it constructs a vector of `RpcResponseJobsData` containing information /// about the jobs and returns it as a `Result`. /// /// # Arguments @@ -20,38 +20,18 @@ impl Pallet { /// operation is successful, or an error message as a `String` if there is an issue. pub fn query_jobs_by_validator( validator: T::AccountId, - ) -> Option>> { - let mut jobs: Vec> = vec![]; + ) -> Option>>> { + let mut jobs: Vec> = vec![]; if let Some(jobs_list) = ValidatorJobIdLookup::::get(validator) { for (role_type, job_id) in jobs_list.iter() { if let Some(job_info) = SubmittedJobs::::get(role_type, job_id) { - if !job_info.job_type.is_phase_one() { - let result = KnownResults::::get( - job_info.job_type.get_role_type(), - job_info.job_type.clone().get_phase_one_id().unwrap(), - ) - .unwrap(); - - let info = RpcResponseJobsData:: { - job_id: *job_id, - job_type: job_info.job_type, - participants: result.participants(), - threshold: result.threshold(), - key: Some(result.result), - }; - - jobs.push(info); - } else { - let info = RpcResponseJobsData:: { - job_id: *job_id, - job_type: job_info.job_type, - participants: None, - threshold: None, - key: None, - }; - - jobs.push(info); - } + let info = RpcResponseJobsData::> { + job_id: *job_id, + job_type: job_info.job_type, + ttl: job_info.ttl, + expiry: job_info.expiry, + }; + jobs.push(info); } else { continue } @@ -74,38 +54,13 @@ impl Pallet { pub fn query_job_by_id( role_type: RoleType, job_id: JobId, - ) -> Option> { - if let Some(job_info) = SubmittedJobs::::get(role_type, job_id) { - if !job_info.job_type.is_phase_one() { - let result = KnownResults::::get( - job_info.job_type.get_role_type(), - job_info.job_type.clone().get_phase_one_id().unwrap(), - ) - .unwrap(); - - let info = RpcResponseJobsData:: { - job_id, - job_type: job_info.job_type, - participants: result.participants(), - threshold: result.threshold(), - key: Some(result.result), - }; - - return Some(info) - } else { - let info = RpcResponseJobsData:: { - job_id, - job_type: job_info.job_type, - participants: None, - threshold: None, - key: None, - }; - - return Some(info) - } - } - - None + ) -> Option>> { + SubmittedJobs::::get(role_type, job_id).map(|job_info| RpcResponseJobsData { + job_id, + job_type: job_info.job_type, + ttl: job_info.ttl, + expiry: job_info.expiry, + }) } /// Queries the phase one result of a job by its key and ID. @@ -122,7 +77,7 @@ impl Pallet { pub fn query_phase_one_by_id( role_type: RoleType, job_id: JobId, - ) -> Option> { + ) -> Option>> { if let Some(job_info) = SubmittedJobs::::get(role_type, job_id) { if !job_info.job_type.is_phase_one() { let result = KnownResults::::get( @@ -131,10 +86,11 @@ impl Pallet { ) .unwrap(); - let info = RpcResponsePhaseOneResult:: { + let info = RpcResponsePhaseOneResult { owner: job_info.owner, result: result.result, job_type: job_info.job_type, + ttl: job_info.ttl, }; return Some(info) diff --git a/pallets/jobs/src/tests.rs b/pallets/jobs/src/tests.rs index 1a8e5969d..3cb948313 100644 --- a/pallets/jobs/src/tests.rs +++ b/pallets/jobs/src/tests.rs @@ -45,7 +45,8 @@ fn jobs_submission_e2e_works_for_dkg() { let threshold_signature_role_type = ThresholdSignatureRoleType::TssGG20; let submission = JobSubmission { - expiry: 100, + expiry: 10, + ttl: 200, job_type: JobType::DKGTSSPhaseOne(DKGTSSPhaseOneJobType { participants: vec![HUNDRED, BOB, CHARLIE, DAVE, EVE], threshold: 3, @@ -61,7 +62,8 @@ fn jobs_submission_e2e_works_for_dkg() { ); let submission = JobSubmission { - expiry: 100, + expiry: 10, + ttl: 200, job_type: JobType::DKGTSSPhaseOne(DKGTSSPhaseOneJobType { participants: vec![ALICE, BOB, CHARLIE, DAVE, EVE], threshold: 5, @@ -78,7 +80,8 @@ fn jobs_submission_e2e_works_for_dkg() { // should fail when caller has no balance let submission = JobSubmission { - expiry: 100, + expiry: 10, + ttl: 200, job_type: JobType::DKGTSSPhaseOne(DKGTSSPhaseOneJobType { participants: vec![ALICE, BOB, CHARLIE, DAVE, EVE], threshold: 3, @@ -92,7 +95,8 @@ fn jobs_submission_e2e_works_for_dkg() { ); let submission = JobSubmission { - expiry: 100, + expiry: 10, + ttl: 200, job_type: JobType::DKGTSSPhaseOne(DKGTSSPhaseOneJobType { participants: vec![ALICE, BOB, CHARLIE, DAVE, EVE], threshold: 3, @@ -139,7 +143,8 @@ fn jobs_submission_e2e_works_for_dkg() { // another account cannot use solution let submission = JobSubmission { - expiry: 100, + expiry: 10, + ttl: 0, job_type: JobType::DKGTSSPhaseTwo(DKGTSSPhaseTwoJobType { phase_one_id: 0, submission: vec![], @@ -152,7 +157,8 @@ fn jobs_submission_e2e_works_for_dkg() { ); let submission = JobSubmission { - expiry: 100, + expiry: 10, + ttl: 0, job_type: JobType::DKGTSSPhaseTwo(DKGTSSPhaseTwoJobType { phase_one_id: 0, submission: vec![], diff --git a/precompiles/jobs/src/lib.rs b/precompiles/jobs/src/lib.rs index acb9bf2d5..08937777e 100644 --- a/precompiles/jobs/src/lib.rs +++ b/precompiles/jobs/src/lib.rs @@ -66,6 +66,7 @@ where /// /// - `handle`: A mutable reference to the `PrecompileHandle` implementation. /// - `expiry`: The expiration period for the submitted job + /// - `ttl`: The time-to-live period for the submitted job /// - `participants`: A vector containing Ethereum addresses of the participants in the DKG. /// - `threshold`: The threshold number of participants required for the DKG to succeed (u8). /// - `permitted_caller`: The Ethereum address of the permitted caller. @@ -73,10 +74,11 @@ where /// # Returns /// /// Returns an `EvmResult`, indicating the success or failure of the operation. - #[precompile::public("submitDkgPhaseOneJob(uint64,address[],uint8,uint16,address)")] + #[precompile::public("submitDkgPhaseOneJob(uint64,uint64,address[],uint8,uint16,address)")] fn submit_dkg_phase_one_job( handle: &mut impl PrecompileHandle, - expiry: u64, + expiry: BlockNumber, + ttl: BlockNumber, participants: Vec
, threshold: u8, role_type: u16, @@ -121,10 +123,14 @@ where // Convert expiration period to Substrate block number let expiry_block: BlockNumberFor = expiry.into(); + let ttl_block: BlockNumberFor = ttl.into(); // Create job submission object - let job = - JobSubmission { expiry: expiry_block, job_type: JobType::DKGTSSPhaseOne(job_type) }; + let job = JobSubmission { + expiry: expiry_block, + ttl: ttl_block, + job_type: JobType::DKGTSSPhaseOne(job_type), + }; // Convert caller's Ethereum address to Substrate account ID let origin = Runtime::AddressMapping::into_account_id(handle.context().caller); @@ -145,6 +151,7 @@ where /// /// - `handle`: A mutable reference to the `PrecompileHandle` implementation. /// - `expiry`: The expiration period for the submitted job + /// - `ttl`: The time-to-live period for the submitted job /// - `phase_one_id`: The identifier of the corresponding phase one DKG job (u32). /// - `submission`: The signature submission for the DKG phase two, represented as /// `BoundedBytes`. @@ -152,10 +159,11 @@ where /// # Returns /// /// Returns an `EvmResult`, indicating the success or failure of the operation. - #[precompile::public("submitDkgPhaseTwoJob(uint64,uint64,bytes)")] + #[precompile::public("submitDkgPhaseTwoJob(uint64,uint64,uint64,bytes)")] fn submit_dkg_phase_two_job( handle: &mut impl PrecompileHandle, expiry: BlockNumber, + ttl: BlockNumber, phase_one_id: JobId, submission: BoundedBytes, ) -> EvmResult { @@ -167,6 +175,7 @@ where // Convert expiration period to Substrate block number let expiry_block: BlockNumberFor = expiry.into(); + let ttl_block: BlockNumberFor = ttl.into(); // Create DKG signature job type with the provided parameters match pallet_jobs::SubmittedJobsRole::::get(phase_one_id) { @@ -191,6 +200,7 @@ where // Create job submission object let job = JobSubmission { expiry: expiry_block, + ttl: ttl_block, job_type: JobType::DKGTSSPhaseTwo(job_type), }; diff --git a/precompiles/jobs/src/tests.rs b/precompiles/jobs/src/tests.rs index 3a7139aaa..31c790818 100644 --- a/precompiles/jobs/src/tests.rs +++ b/precompiles/jobs/src/tests.rs @@ -30,7 +30,8 @@ fn submit_dkg_phase_one_job() { Precompile1, PCall::submit_dkg_phase_one_job { role_type: RoleType::Tss(ThresholdSignatureRoleType::TssGG20).to_u16(), - expiry: 100, + expiry: 5, + ttl: 200, participants: vec![], threshold: 2, permitted_caller: Address(CryptoAlith.into()), @@ -49,7 +50,8 @@ fn submit_dkg_phase_two_job() { Address(CryptoAlith.into()), Precompile1, PCall::submit_dkg_phase_two_job { - expiry: 100, + expiry: 5, + ttl: 0, phase_one_id: 1, submission: vec![].into(), }, diff --git a/primitives/src/jobs/mod.rs b/primitives/src/jobs/mod.rs index 98482cdb2..b172c0654 100644 --- a/primitives/src/jobs/mod.rs +++ b/primitives/src/jobs/mod.rs @@ -33,9 +33,14 @@ pub use zksaas::*; /// Represents a job submission with specified `AccountId` and `BlockNumber`. #[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo, Clone)] pub struct JobSubmission { - /// The time to live for the submitted job. + /// Represents the maximum allowed submission time for a job result. + /// Once this time has passed, the result cannot be submitted. pub expiry: BlockNumber, + /// The time-to-live (TTL) for the job, which determines the maximum allowed time for this job + /// to be available. After the TTL expires, the job can no longer be used. + pub ttl: BlockNumber, + /// The type of the job submission. pub job_type: JobType, } @@ -46,9 +51,14 @@ pub struct JobInfo { /// The caller that requested the job pub owner: AccountId, - /// The expiry block number. + /// Represents the maximum allowed submission time for a job result. + /// Once this time has passed, the result cannot be submitted. pub expiry: BlockNumber, + /// The time-to-live (TTL) for the job, which determines the maximum allowed time for this job + /// to be available. After the TTL expires, the job can no longer be used. + pub ttl: BlockNumber, + /// The type of the job submission. pub job_type: JobType, @@ -187,10 +197,11 @@ pub enum JobState { pub struct PhaseResult { /// The owner's account ID. pub owner: AccountId, - /// The time to live as a block number. - pub expiry: BlockNumber, /// The type of the job submission. - pub result: Vec, + pub result: JobResult, + /// The time-to-live (TTL) for the job, which determines the maximum allowed time for this job + /// to be available. After the TTL expires, the job can no longer be used. + pub ttl: BlockNumber, /// permitted caller to use this result pub permitted_caller: Option, /// The type of the job submission. @@ -229,32 +240,35 @@ pub enum ValidatorOffence { #[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo, Clone)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct RpcResponseJobsData { +pub struct RpcResponseJobsData { /// The job id of the job pub job_id: JobId, /// The type of the job submission. pub job_type: JobType, - /// (Optional) List of participants' account IDs. - pub participants: Option>, - - /// threshold if any for the original set - pub threshold: Option, + /// Represents the maximum allowed submission time for a job result. + /// Once this time has passed, the result cannot be submitted. + pub expiry: BlockNumber, - /// previous phase key if any - pub key: Option>, + /// The time-to-live (TTL) for the job, which determines the maximum allowed time for this job + /// to be available. After the TTL expires, the job can no longer be used. + pub ttl: BlockNumber, } #[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo, Clone)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] -pub struct RpcResponsePhaseOneResult { +pub struct RpcResponsePhaseOneResult { /// The owner's account ID. pub owner: AccountId, /// The type of the job result. - pub result: Vec, + pub result: JobResult, /// The type of the job submission. pub job_type: JobType, + + /// The time-to-live (TTL) for the job, which determines the maximum allowed time for this job + /// to be available. After the TTL expires, the job can no longer be used. + pub ttl: BlockNumber, } #[derive(PartialEq, Eq, Encode, Decode, RuntimeDebug, TypeInfo, Clone)] diff --git a/runtime/mainnet/src/lib.rs b/runtime/mainnet/src/lib.rs index 914f52eac..ce885bbb7 100644 --- a/runtime/mainnet/src/lib.rs +++ b/runtime/mainnet/src/lib.rs @@ -418,8 +418,8 @@ parameter_types! { pub const SessionsPerEra: sp_staking::SessionIndex = 6; // 28 eras for unbonding (28 days). pub const BondingDuration: sp_staking::EraIndex = 28; - // 28 eras for slash defer duration (28 days). - pub const SlashDeferDuration: sp_staking::EraIndex = 28; + // 27 eras for slash defer duration (27 days). + pub const SlashDeferDuration: sp_staking::EraIndex = 27; pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE; pub const MaxNominatorRewardedPerValidator: u32 = 256; pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17); diff --git a/runtime/testnet/src/lib.rs b/runtime/testnet/src/lib.rs index 9af39bbea..5df6fcf2b 100644 --- a/runtime/testnet/src/lib.rs +++ b/runtime/testnet/src/lib.rs @@ -434,8 +434,8 @@ parameter_types! { pub const SessionsPerEra: sp_staking::SessionIndex = 6; // 28 eras for unbonding (28 days). pub const BondingDuration: sp_staking::EraIndex = 28; - // 28 eras for slash defer duration (28 days). - pub const SlashDeferDuration: sp_staking::EraIndex = 28; + // 27 eras for slash defer duration (27 days). + pub const SlashDeferDuration: sp_staking::EraIndex = 27; pub const RewardCurve: &'static PiecewiseLinear<'static> = &REWARD_CURVE; pub const MaxNominatorRewardedPerValidator: u32 = 256; pub const OffendingValidatorsThreshold: Perbill = Perbill::from_percent(17); @@ -1351,6 +1351,7 @@ mod benches { ); } +use pallet_jobs_rpc_runtime_api::BlockNumberOf; impl_runtime_apis! { impl sp_api::Core for Runtime { fn version() -> RuntimeVersion { @@ -1404,15 +1405,15 @@ impl_runtime_apis! { impl pallet_jobs_rpc_runtime_api::JobsApi for Runtime { fn query_jobs_by_validator( validator: AccountId, - ) -> Option>> { + ) -> Option>>> { Jobs::query_jobs_by_validator(validator) } - fn query_job_by_id(role_type: RoleType, job_id: JobId) -> Option> { + fn query_job_by_id(role_type: RoleType, job_id: JobId) -> Option>> { Jobs::query_job_by_id(role_type, job_id) } - fn query_phase_one_by_id(role_type: RoleType, job_id: JobId) -> Option> { + fn query_phase_one_by_id(role_type: RoleType, job_id: JobId) -> Option>> { Jobs::query_phase_one_by_id(role_type, job_id) }