pub fn start_mining(miner: T::AccountId, stake: BalanceOf<T>) -> DispatchResult {
			let worker = MinerBindings::<T>::get(&miner).ok_or(Error::<T>::MinerNotFound)?;
			ensure!(
				Miners::<T>::get(&miner).unwrap().state == MinerState::Ready,
				Error::<T>::MinerNotReady
			);
			// Double check the Stake shouldn't be overrode
			ensure!(
				Stakes::<T>::get(&miner) == None,
				Error::<T>::InternalErrorCannotStartWithExistingStake,
			);

			let worker_info =
				registry::Workers::<T>::get(&worker).expect("Bounded worker must exist; qed.");
			let p = worker_info
				.initial_score
				.ok_or(Error::<T>::BenchmarkMissing)?;
			// Disallow some weird benchmark score.
			ensure!(p >= T::MinInitP::get(), Error::<T>::BenchmarkTooLow);

			let tokenomic = Self::tokenomic()?;
			let min_stake = tokenomic.minimal_stake(p);
			ensure!(stake >= min_stake, Error::<T>::InsufficientStake);

			let ve = tokenomic.ve(stake, p, worker_info.confidence_level);
			let v_max = tokenomic.v_max();
			ensure!(ve <= v_max, Error::<T>::TooMuchStake);

			let now = Self::now_sec();

			Stakes::<T>::insert(&miner, stake);
			Miners::<T>::mutate(&miner, |info| {
				if let Some(info) = info {
					info.state = MinerState::MiningIdle;
					info.ve = ve.to_bits();
					info.v = ve.to_bits();
					info.v_updated_at = now;
					info.benchmark.p_init = p;
				}
			});
			OnlineMiners::<T>::mutate(|v| *v += 1);

			let session_id = NextSessionId::<T>::get();
			NextSessionId::<T>::put(session_id + 1);
			Self::push_message(SystemEvent::new_worker_event(
				worker,
				WorkerEvent::MiningStart {
					session_id,
					init_v: ve.to_bits(),
					init_p: p,
				},
			));
			Self::deposit_event(Event::<T>::MinerStarted(miner));
			Ok(())
		}
/// Starts mining with the given `stake`, assuming the stake is already locked externally
///
/// A minimal P is required to avoid some edge case (e.g. miner not getting full benchmark
/// with a close-to-zero score).
Starts mining with the given `stake`, assuming the stake is already locked externally
A minimal P is required to avoid some edge case .
Starts mining with the given ` stake ` assuming the stake is already locked externally A minimal P is required to avoid some edge case .
pub fn start_mining(miner: T::AccountId, stake: BalanceOf<T>) -> DispatchResult {
			let worker = MinerBindings::<T>::get(&miner).ok_or(Error::<T>::MinerNotFound)?;
			ensure!(
				Miners::<T>::get(&miner).unwrap().state == MinerState::Ready,
				Error::<T>::MinerNotReady
			);
			// Double check the Stake shouldn't be overrode
			ensure!(
				Stakes::<T>::get(&miner) == None,
				Error::<T>::InternalErrorCannotStartWithExistingStake,
			);
			let worker_info =
				registry::Workers::<T>::get(&worker).expect("Bounded worker must exist; qed.");
			let p = worker_info
				.initial_score
				.ok_or(Error::<T>::BenchmarkMissing)?;
			// Disallow some weird benchmark score.
			ensure!(p >= T::MinInitP::get(), Error::<T>::BenchmarkTooLow);
			let tokenomic = Self::tokenomic()?;
			let min_stake = tokenomic.minimal_stake(p);
			ensure!(stake >= min_stake, Error::<T>::InsufficientStake);
			let ve = tokenomic.ve(stake, p, worker_info.confidence_level);
			let v_max = tokenomic.v_max();
			ensure!(ve <= v_max, Error::<T>::TooMuchStake);
			let now = Self::now_sec();
			Stakes::<T>::insert(&miner, stake);
			Miners::<T>::mutate(&miner, |info| {
				if let Some(info) = info {
					info.state = MinerState::MiningIdle;
					info.ve = ve.to_bits();
					info.v = ve.to_bits();
					info.v_updated_at = now;
					info.benchmark.p_init = p;
				}
			});
			OnlineMiners::<T>::mutate(|v| *v += 1);
			let session_id = NextSessionId::<T>::get();
			NextSessionId::<T>::put(session_id + 1);
			Self::push_message(SystemEvent::new_worker_event(
				worker,
				WorkerEvent::MiningStart {
					session_id,
					init_v: ve.to_bits(),
					init_p: p,
				},
			));
			Self::deposit_event(Event::<T>::MinerStarted(miner));
			Ok(())
		}
pub fn start_mining ( miner : T :: AccountId , stake : BalanceOf < T > ) -> DispatchResult { let worker = MinerBindings :: < T > :: get ( & miner ) . ok_or ( Error :: < T > :: MinerNotFound ) ? ; ensure ! ( Miners T get ( miner ) unwrap ( ) state MinerState Ready Error T MinerNotReady ) ; // Double check the Stake shouldn't be overrode ensure ! ( Stakes T get ( miner ) None Error T InternalErrorCannotStartWithExistingStake ) ; let worker_info = registry :: Workers :: < T > :: get ( & worker ) . expect ( " " ) ; let p = worker_info . initial_score . ok_or ( Error :: < T > :: BenchmarkMissing ) ? ; // Disallow some weird benchmark score. ensure ! ( p T MinInitP get ( ) Error T BenchmarkTooLow ) ; let tokenomic = Self :: tokenomic ( ) ? ; let min_stake = tokenomic . minimal_stake ( p ) ; ensure ! ( stake min_stake Error T InsufficientStake ) ; let ve = tokenomic . ve ( stake , p , worker_info . confidence_level ) ; let v_max = tokenomic . v_max ( ) ; ensure ! ( ve v_max Error T TooMuchStake ) ; let now = Self :: now_sec ( ) ; Stakes :: < T > :: insert ( & miner , stake ) ; Miners :: < T > :: mutate ( & miner , | info | { if let Some ( info ) = info { info . state = MinerState :: MiningIdle ; info . ve = ve . to_bits ( ) ; info . v = ve . to_bits ( ) ; info . v_updated_at = now ; info . benchmark . p_init = p ; } } ) ; OnlineMiners :: < T > :: mutate ( | v | * v += 1 ) ; let session_id = NextSessionId :: < T > :: get ( ) ; NextSessionId :: < T > :: put ( session_id + 1 ) ; Self :: push_message ( SystemEvent :: new_worker_event ( worker , WorkerEvent :: MiningStart { session_id , init_v : ve . to_bits ( ) , init_p : p , } , ) ) ; Self :: deposit_event ( Event :: < T > :: MinerStarted ( miner ) ) ; Ok ( ( ) ) }
Starts mining with the given `stake`, assuming the stake is already locked externally
A minimal P is required to avoid some edge case (e.g.
Starts mining with the given ` stake ` assuming the stake is already locked externally A minimal P is required to avoid some edge case ( e . g .
miner
T::AccountId
stake
BalanceOf<T>
miner
T::AccountId
stake
BalanceOf<T>