@@ -56,6 +56,8 @@ pub use pallet::*;
5656#[ cfg( feature = "runtime-benchmarks" ) ]
5757pub mod benchmarking;
5858
59+ pub mod weights;
60+
5961use sp_runtime:: {
6062 traits:: { CheckedAdd , SaturatedConversion } ,
6163 RuntimeDebug , Permill ,
@@ -94,7 +96,6 @@ use sp_std::{
9496 } ;
9597use cp_enclave_verify:: verify_rsa;
9698use cp_cess_common:: * ;
97- pub mod weights;
9899pub use weights:: WeightInfo ;
99100use cp_bloom_filter:: BloomFilter ;
100101use cp_scheduler_credit:: SchedulerCreditCounter ;
@@ -152,7 +153,7 @@ pub mod pallet {
152153 use super :: * ;
153154 // use frame_benchmarking::baseline::Config;
154155 use frame_support:: { traits:: Get } ;
155- use frame_system:: { ensure_signed, pallet_prelude:: * } ;
156+ use frame_system:: { ensure_signed, pallet_prelude:: { * , OriginFor } } ;
156157
157158 ///18446744073709551615
158159 pub const LIMIT : u64 = u64:: MAX ;
@@ -353,6 +354,10 @@ pub mod pallet {
353354 #[ pallet:: getter( fn verify_reassign_count) ]
354355 pub ( super ) type VerifyReassignCount < T : Config > = StorageValue < _ , u8 , ValueQuery > ;
355356
357+ #[ pallet:: storage]
358+ #[ pallet:: getter( fn exec_block) ]
359+ pub ( super ) type ExecBlock < T : Config > = StorageValue < _ , BlockNumberOf < T > , ValueQuery > ;
360+
356361 // FOR TESTING
357362 #[ pallet:: storage]
358363 #[ pallet:: getter( fn lock) ]
@@ -380,6 +385,8 @@ pub mod pallet {
380385 if now > deadline {
381386 //Determine whether to trigger a challenge
382387 // if Self::trigger_challenge(now) {
388+ let exec_block = <ExecBlock < T > >:: get ( ) ;
389+ if now == exec_block {
383390 log:: info!( "offchain worker random challenge start" ) ;
384391 if let Err ( e) = Self :: offchain_work_start ( now) {
385392 match e {
@@ -388,6 +395,7 @@ pub mod pallet {
388395 } ;
389396 }
390397 log:: info!( "offchain worker random challenge end" ) ;
398+ }
391399 // }
392400 }
393401 }
@@ -418,31 +426,36 @@ pub mod pallet {
418426 . checked_mul ( 2 ) . ok_or ( Error :: < T > :: Overflow ) ?
419427 . checked_div ( 3 ) . ok_or ( Error :: < T > :: Overflow ) ?;
420428 let now = <frame_system:: Pallet < T > >:: block_number ( ) ;
429+
430+ let cur_block = <VerifyDuration < T > >:: get ( ) ;
431+
432+ if now <= cur_block {
433+ return Ok ( ( ) ) ;
434+ }
421435
422436 if ChallengeProposal :: < T > :: contains_key ( & hash) {
423- let proposal = ChallengeProposal :: < T > :: get ( & hash) . unwrap ( ) ;
424- if proposal. 0 + 1 >= limit {
425- let cur_blcok = <ChallengeDuration < T > >:: get ( ) ;
426-
427- if now > cur_blcok {
428- let duration = now. checked_add ( & proposal. 1 . net_snap_shot . life ) . ok_or ( Error :: < T > :: Overflow ) ?;
429- <ChallengeDuration < T > >:: put ( duration) ;
430- let idle_duration = duration;
431- let one_hour = T :: OneHours :: get ( ) ;
432- let tee_length = T :: TeeWorkerHandler :: get_controller_list ( ) . len ( ) ;
433- let duration: u32 = ( proposal. 1 . net_snap_shot . total_idle_space
434- . checked_add ( proposal. 1 . net_snap_shot . total_service_space ) . ok_or ( Error :: < T > :: Overflow ) ?
435- . checked_div ( IDLE_VERIFY_RATE ) . ok_or ( Error :: < T > :: Overflow ) ?
436- . checked_div ( tee_length as u128 ) . ok_or ( Error :: < T > :: Overflow ) ?
437- ) as u32 ;
438- let v_duration = idle_duration
439- . checked_add ( & duration. saturated_into ( ) ) . ok_or ( Error :: < T > :: Overflow ) ?
440- . checked_add ( & one_hour) . ok_or ( Error :: < T > :: Overflow ) ?;
441- <VerifyDuration < T > >:: put ( v_duration) ;
442- <ChallengeSnapShot < T > >:: put ( proposal. 1 ) ;
443- let _ = ChallengeProposal :: < T > :: clear ( ChallengeProposal :: < T > :: count ( ) , None ) ;
444- Self :: deposit_event ( Event :: < T > :: GenerateChallenge ) ;
445- }
437+ let mut proposal = ChallengeProposal :: < T > :: get ( & hash) . unwrap ( ) ;
438+ proposal. 0 += 1 ;
439+ if proposal. 0 >= limit {
440+ let duration = now. checked_add ( & proposal. 1 . net_snap_shot . life ) . ok_or ( Error :: < T > :: Overflow ) ?;
441+ <ChallengeDuration < T > >:: put ( duration) ;
442+ let idle_duration = duration;
443+ let one_hour = T :: OneHours :: get ( ) ;
444+ let tee_length = T :: TeeWorkerHandler :: get_controller_list ( ) . len ( ) ;
445+ let duration: u32 = ( proposal. 1 . net_snap_shot . total_idle_space
446+ . checked_add ( proposal. 1 . net_snap_shot . total_service_space ) . ok_or ( Error :: < T > :: Overflow ) ?
447+ . checked_div ( IDLE_VERIFY_RATE ) . ok_or ( Error :: < T > :: Overflow ) ?
448+ . checked_div ( tee_length as u128 ) . ok_or ( Error :: < T > :: Overflow ) ?
449+ ) as u32 ;
450+ let v_duration = idle_duration
451+ . checked_add ( & duration. saturated_into ( ) ) . ok_or ( Error :: < T > :: Overflow ) ?
452+ . checked_add ( & one_hour) . ok_or ( Error :: < T > :: Overflow ) ?;
453+ <VerifyDuration < T > >:: put ( v_duration) ;
454+ <ChallengeSnapShot < T > >:: put ( proposal. 1 ) ;
455+ let _ = ChallengeProposal :: < T > :: clear ( ChallengeProposal :: < T > :: count ( ) , None ) ;
456+ Self :: deposit_event ( Event :: < T > :: GenerateChallenge ) ;
457+ } else {
458+ ChallengeProposal :: < T > :: insert ( & hash, proposal) ;
446459 }
447460 } else {
448461 if ChallengeProposal :: < T > :: count ( ) > count {
@@ -461,7 +474,7 @@ pub mod pallet {
461474
462475 #[ pallet:: call_index( 1 ) ]
463476 #[ transactional]
464- #[ pallet:: weight( 100_000_000 ) ]
477+ #[ pallet:: weight( < T as pallet :: Config > :: WeightInfo :: submit_idle_proof ( ) ) ]
465478 pub fn submit_idle_proof (
466479 origin : OriginFor < T > ,
467480 idle_prove : BoundedVec < u8 , T :: IdleTotalHashLength > ,
@@ -516,7 +529,7 @@ pub mod pallet {
516529
517530 #[ pallet:: call_index( 2 ) ]
518531 #[ transactional]
519- #[ pallet:: weight( 100_000_000 ) ]
532+ #[ pallet:: weight( < T as pallet :: Config > :: WeightInfo :: submit_service_proof ( ) ) ]
520533 pub fn submit_service_proof (
521534 origin : OriginFor < T > ,
522535 service_prove : BoundedVec < u8 , T :: SigmaMax > ,
@@ -573,7 +586,7 @@ pub mod pallet {
573586
574587 #[ pallet:: call_index( 3 ) ]
575588 #[ transactional]
576- #[ pallet:: weight( 100_000_000 ) ]
589+ #[ pallet:: weight( < T as pallet :: Config > :: WeightInfo :: submit_verify_idle_result ( ) ) ]
577590 pub fn submit_verify_idle_result (
578591 origin : OriginFor < T > ,
579592 total_prove_hash : BoundedVec < u8 , T :: IdleTotalHashLength > ,
@@ -657,7 +670,7 @@ pub mod pallet {
657670
658671 #[ pallet:: call_index( 4 ) ]
659672 #[ transactional]
660- #[ pallet:: weight( 100_000_000 ) ]
673+ #[ pallet:: weight( < T as pallet :: Config > :: WeightInfo :: submit_verify_service_result ( ) ) ]
661674 pub fn submit_verify_service_result (
662675 origin : OriginFor < T > ,
663676 service_result : bool ,
@@ -789,6 +802,17 @@ pub mod pallet {
789802
790803 Ok ( ( ) )
791804 }
805+
806+ #[ pallet:: call_index( 9 ) ]
807+ #[ transactional]
808+ #[ pallet:: weight( 100_000_000 ) ]
809+ pub fn update_exec_block ( origin : OriginFor < T > , target : BlockNumberOf < T > ) -> DispatchResult {
810+ let _ = ensure_root ( origin) ?;
811+
812+ <ExecBlock < T > >:: put ( target) ;
813+
814+ Ok ( ( ) )
815+ }
792816 }
793817
794818 #[ pallet:: validate_unsigned]
0 commit comments