Skip to content

Commit

Permalink
feat: 0.7.7 facuet and fix some bug (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
ytqaljn authored Apr 8, 2024
1 parent 3ffc402 commit e113671
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 18 deletions.
8 changes: 4 additions & 4 deletions crates/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ pub type EndPoint = BoundedVec<u8, ConstU32<100>>;

pub const M_BYTE: u128 = 1_048_576;
pub const G_BYTE: u128 = 1_048_576 * 1024;
pub const T_BYTE: u128 = 1_048_576 * 1024 * 1024;
pub const T_BYTE: u128 = 1_048_576 * 1024 * 1024;
pub const IDLE_SEG_SIZE: u128 = M_BYTE * 64;
pub const SEGMENT_SIZE: u128 = M_BYTE * 64;
pub const FRAGMENT_SIZE: u128 = M_BYTE * 16;
pub const SEGMENT_SIZE: u128 = M_BYTE * 32;
pub const FRAGMENT_SIZE: u128 = M_BYTE * 8;
// The number of fragments contained in a segment
pub const FRAGMENT_COUNT: u32 = (SEGMENT_SIZE * 15 / 10 / FRAGMENT_SIZE) as u32;
pub const FRAGMENT_COUNT: u32 = (SEGMENT_SIZE * 30 / 10 / FRAGMENT_SIZE) as u32;
pub const ASSIGN_MINER_IDEAL_QUANTITY: u32 = FRAGMENT_COUNT;
pub const CHUNK_COUNT: u32 = 1024;

Expand Down
4 changes: 0 additions & 4 deletions pallets/file-bank/src/impls/receptionist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ pub struct Receptionist<T: Config>(PhantomData<T>);

impl<T: Config> Receptionist<T> {
pub fn fly_upload_file(file_hash: Hash, user_brief: UserBrief<T>) -> DispatchResult {


<File<T>>::try_mutate(&file_hash, |file_opt| -> DispatchResult {
let file = file_opt.as_mut().ok_or(Error::<T>::FileNonExistent)?;
let needed_space = SEGMENT_SIZE
Expand All @@ -27,8 +25,6 @@ impl<T: Config> Receptionist<T> {
Ok(())
})?;



Ok(())
}

Expand Down
5 changes: 5 additions & 0 deletions pallets/file-bank/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ pub mod pallet {
MalformedSignature,
/// Error in comparing miner account information
MinerError,
/// Does not comply with the rules: fragments of a segment need to be stored on different miners
RulesNotAllowed,
}

#[pallet::storage]
Expand Down Expand Up @@ -1088,6 +1090,9 @@ pub mod pallet {
for segment in &mut file.segment_list {
for fragment in &mut segment.fragment_list {
if &fragment.hash == &fragment_hash {
if &fragment.miner == &sender {
Err(Error::<T>::RulesNotAllowed)?
}
if &fragment.miner == &order.origin_miner {
let binary = fragment.hash.binary().map_err(|_| Error::<T>::BugInvalid)?;
T::MinerControl::insert_service_bloom(&sender, vec![binary.clone()])?;
Expand Down
4 changes: 0 additions & 4 deletions pallets/oss/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ use frame_system::{ensure_signed, Origin};
#[pallet::getter(fn oss)]
pub(super) type Oss<T: Config> = StorageMap<_, Blake2_128Concat, AccountOf<T>, OssInfo>;

#[pallet::storage]
#[pallet::getter(fn test_storage)]
pub(super) type TestStorage<T: Config> = StorageValue<_, AccountOf<T>>;

#[pallet::pallet]
pub struct Pallet<T>(PhantomData<T>);

Expand Down
55 changes: 49 additions & 6 deletions pallets/sminer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ type BalanceOf<T> =
pub mod pallet {
use super::*;
use frame_support::{
pallet_prelude::{ValueQuery, *},
traits::Get,
pallet_prelude::{StorageValue, ValueQuery, *},
traits::Get, Blake2_128Concat,
};
use frame_system::{ensure_signed, pallet_prelude::*};

Expand All @@ -105,6 +105,9 @@ pub mod pallet {
#[pallet::constant]
type StakingLockBlock: Get<BlockNumberFor<Self>>;

#[pallet::constant]
type MaximumRelease: Get<u128>;

/// The WeightInfo.
type WeightInfo: WeightInfo;

Expand Down Expand Up @@ -230,6 +233,13 @@ pub mod pallet {
InsufficientReplaceable,
/// Conversion tee signature error
MalformedSignature,
/// Chain does not initialize whitelist
NotSetWhite,
/// Wrong signature source
WrongOrigin,
/// Exceeding the maximum release volume of the faucet in one day
ExceedRelease,

}

/// The hashmap for info of storage miners.
Expand Down Expand Up @@ -291,6 +301,10 @@ pub mod pallet {
#[pallet::getter(fn pending_replacements)]
pub(super) type PendingReplacements<T: Config> =
StorageMap<_, Blake2_128Concat, AccountOf<T>, u128, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn facuet_release_record)]
pub(super) type FacuetReleaseRecord<T: Config> = StorageValue<_, BalanceOf<T>, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn return_staking_schedule)]
Expand Down Expand Up @@ -325,6 +339,10 @@ pub mod pallet {
ValueQuery,
>;

#[pallet::storage]
#[pallet::getter(fn facuet_whitelist)]
pub(super) type FacuetWhitelist<T: Config> = StorageValue<_, AccountOf<T>>;

#[pallet::pallet]
pub struct Pallet<T>(_);

Expand Down Expand Up @@ -748,7 +766,12 @@ pub mod pallet {
#[transactional]
#[pallet::weight(Weight::zero())]
pub fn faucet(origin: OriginFor<T>, to: AccountOf<T>) -> DispatchResult {
let _ = ensure_signed(origin)?;
let sender = ensure_signed(origin)?;

let white = <FacuetWhitelist<T>>::try_get().map_err(|_| Error::<T>::NotSetWhite)?;
ensure!(sender == white, Error::<T>::WrongOrigin);

let facuet_value: BalanceOf<T> = FAUCET_VALUE.try_into().map_err(|_e| Error::<T>::ConversionError)?;

if !<FaucetRecordMap<T>>::contains_key(&to) {
<FaucetRecordMap<T>>::insert(
Expand All @@ -764,7 +787,7 @@ pub mod pallet {
<T as pallet::Config>::Currency::transfer(
&reward_pot,
&to,
FAUCET_VALUE.try_into().map_err(|_e| Error::<T>::ConversionError)?,
facuet_value,
KeepAlive,
)?;
<FaucetRecordMap<T>>::insert(
Expand All @@ -780,7 +803,7 @@ pub mod pallet {
let now = <frame_system::Pallet<T>>::block_number();

let mut flag: bool = true;
if now >= BlockNumberFor::<T>::from(one_day) {
if now >= one_day.into() {
if !(faucet_record.last_claim_time
<= now
.checked_sub(&BlockNumberFor::<T>::from(one_day))
Expand All @@ -804,12 +827,21 @@ pub mod pallet {
ensure!(flag, Error::<T>::LessThan24Hours);

let reward_pot = T::FaucetId::get().into_account_truncating();
<FacuetReleaseRecord<T>>::try_mutate(|release_amount| -> DispatchResult {
let max: BalanceOf<T> = T::MaximumRelease::get().try_into().map_err(|_| Error::<T>::ConversionError)?;
*release_amount = release_amount.checked_add(&facuet_value).ok_or(Error::<T>::Overflow)?;
ensure!(*release_amount <= max, Error::<T>::ExceedRelease);

Ok(())
})?;

<T as pallet::Config>::Currency::transfer(
&reward_pot,
&to,
FAUCET_VALUE.try_into().map_err(|_e| Error::<T>::ConversionError)?,
facuet_value,
KeepAlive,
)?;

<FaucetRecordMap<T>>::insert(
&to,
FaucetRecord::<BlockNumberFor<T>> { last_claim_time: now },
Expand Down Expand Up @@ -1013,6 +1045,17 @@ pub mod pallet {

Ok(())
}

#[pallet::call_index(20)]
#[transactional]
#[pallet::weight(Weight::zero())]
pub fn set_facuet_whitelist(origin: OriginFor<T>, acc: AccountOf<T>) -> DispatchResult {
let _ = ensure_root(origin)?;

<FacuetWhitelist<T>>::put(acc);

Ok(())
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions standalone/chain/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,6 +1093,7 @@ parameter_types! {
pub const FaucetId: PalletId = PalletId(*b"facuetid");
#[derive(Clone, Eq, PartialEq)]
pub const StakingLockBlock: BlockNumber = DAYS * 180;
pub const MaximumRelease: u128 = 5_000_000_000_000_000_000_000_000;
}

impl pallet_sminer::Config for Runtime {
Expand All @@ -1112,6 +1113,7 @@ impl pallet_sminer::Config for Runtime {
type StorageHandle = StorageHandler;
type RewardPool = CessTreasury;
type CessTreasuryHandle = CessTreasury;
type MaximumRelease = MaximumRelease;
}

parameter_types! {
Expand Down

0 comments on commit e113671

Please sign in to comment.