Skip to content

Commit

Permalink
0.7.5 test (#267)
Browse files Browse the repository at this point in the history
* update: adjustment param

* fix: add event

* feat: custom expired time

* refactor: cargo version update

* fix: upload file bug fix

* fix: remove invaild param

* fix: adjust base time

* spec version reset
  • Loading branch information
ytqaljn authored Nov 23, 2023
1 parent 565808b commit 516a42d
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 15 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion c-pallets/file-bank/src/constants.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// The average number of bytes that a storage node can transmit within each block
pub(super) const TRANSFER_RATE: u128 = 2_089_446;

pub(super) const CALCULATE_RATE: u128 = 651_088;
pub(super) const CALCULATE_RATE: u128 = 838_860;
5 changes: 3 additions & 2 deletions c-pallets/file-bank/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,12 @@ impl<T: Config> Pallet<T> {

pub(super) fn remove_deal(deal_hash: &Hash) -> DispatchResult {
let deal_info = <DealMap<T>>::try_get(deal_hash).map_err(|_| Error::<T>::NonExistent)?;
let needed_space = Self::cal_file_size(deal_info.segment_list.len() as u128);
let segment_len = deal_info.segment_list.len() as u128;
let needed_space = Self::cal_file_size(segment_len);
T::StorageHandle::unlock_user_space(&deal_info.user.user, needed_space)?;
// unlock mienr space
for complete_info in deal_info.complete_list {
T::MinerControl::unlock_space(&complete_info.miner, FRAGMENT_SIZE * FRAGMENT_COUNT as u128)?;
T::MinerControl::unlock_space(&complete_info.miner, FRAGMENT_SIZE * segment_len)?;
}

<DealMap<T>>::remove(deal_hash);
Expand Down
2 changes: 2 additions & 0 deletions c-pallets/file-bank/src/impls/dealimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ impl<T: Config> DealInfo<T> {
ensure!(index != complete_info.index, Error::<T>::Existed);
ensure!(miner != complete_info.miner, Error::<T>::Existed);
}

T::MinerControl::lock_space(&miner, FRAGMENT_SIZE * self.segment_list.len() as u128)?;

let complete_info = CompleteInfo::<T> {
index,
Expand Down
2 changes: 1 addition & 1 deletion c-pallets/file-bank/src/impls/receptionist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<T: Config> Receptionist<T> {
let max_needed_cal_space = (segment_count as u32).checked_mul(FRAGMENT_SIZE as u32).ok_or(Error::<T>::Overflow)?;
let mut life: u32 = (max_needed_cal_space / TRANSFER_RATE as u32).checked_add(11).ok_or(Error::<T>::Overflow)?;
life = (max_needed_cal_space / CALCULATE_RATE as u32)
.checked_add(30).ok_or(Error::<T>::Overflow)?
.checked_add(100).ok_or(Error::<T>::Overflow)?
.checked_add(life).ok_or(Error::<T>::Overflow)?;
Pallet::<T>::start_second_task(deal_hash.0.to_vec(), deal_hash, life)?;
if <Bucket<T>>::contains_key(&deal_info.user.user, &deal_info.user.bucket_name) {
Expand Down
3 changes: 1 addition & 2 deletions c-pallets/file-bank/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,6 @@ pub mod pallet {
InsufficientReplaceable,
}


#[pallet::storage]
#[pallet::getter(fn deal_map)]
pub(super) type DealMap<T: Config> = StorageMap<_, Blake2_128Concat, Hash, DealInfo<T>>;
Expand Down Expand Up @@ -615,8 +614,8 @@ pub mod pallet {
let _ = ensure_root(origin)?;

let deal_info = <DealMap<T>>::try_get(&deal_hash).map_err(|_| Error::<T>::NonExistent)?;
let count = deal_info.segment_list.len() as u128;
for (index, complete_info) in deal_info.complete_list.iter().enumerate() {
let count = FRAGMENT_COUNT;
let mut hash_list: Vec<Box<[u8; 256]>> = Default::default();
for segment in &deal_info.segment_list {
let fragment_hash = segment.fragment_list[index as usize];
Expand Down
7 changes: 7 additions & 0 deletions c-pallets/sminer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ pub mod pallet {
acc: AccountOf<T>,
staking_val: BalanceOf<T>,
},
RegisterPoisKey {
miner: AccountOf<T>,
},
/// Users to withdraw faucet money
DrawFaucetMoney(),
/// User recharges faucet
Expand Down Expand Up @@ -399,6 +402,10 @@ pub mod pallet {
Ok(())
})?;

Self::deposit_event(Event::<T>::RegisterPoisKey {
miner: sender,
});

Ok(())
}

Expand Down
29 changes: 25 additions & 4 deletions c-pallets/storage-handler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ pub mod pallet {

#[pallet::constant]
type OneDay: Get<BlockNumberOf<Self>>;

#[pallet::constant]
type OneHours: Get<BlockNumberOf<Self>>;
/// pallet address.
#[pallet::constant]
type RewardPalletId: Get<PalletId>;
Expand Down Expand Up @@ -123,9 +126,13 @@ pub mod pallet {

LeaseExpired,

OrderExpired,

RandomErr,

NoOrder,

ParamError,
}

#[pallet::storage]
Expand Down Expand Up @@ -367,9 +374,21 @@ pub mod pallet {
#[pallet::call_index(6)]
#[transactional]
#[pallet::weight(Weight::zero())]
pub fn create_order(origin: OriginFor<T>, target_acc: AccountOf<T>, order_type: OrderType, gib_count: u32, days: u32) -> DispatchResult {
pub fn create_order(
origin: OriginFor<T>,
target_acc: AccountOf<T>,
order_type: OrderType,
gib_count: u32,
days: u32,
// minute
expired: u32,
) -> DispatchResult {
let sender = ensure_signed(origin)?;

let expired: BlockNumberOf<T> = (expired
.checked_mul(6).ok_or(Error::<T>::Overflow)?).saturated_into();
ensure!(expired < T::OneHours::get(), Error::<T>::ParamError);

let price = match order_type {
OrderType::Buy => {
ensure!(!<UserOwnedSpace<T>>::contains_key(&target_acc), Error::<T>::PurchasedSpace);
Expand All @@ -390,17 +409,17 @@ pub mod pallet {
},
};

let now = <frame_system::Pallet<T>>::block_number();
let expired = now.checked_add(&expired.saturated_into()).ok_or(Error::<T>::Overflow)?;
let pay_order = OrderInfo::<T> {
pay: price,
gib_count: gib_count,
days,
expired: 10u32.saturated_into(),
pay_acc: sender,
expired,
target_acc: target_acc,
order_type,
};

let now = <frame_system::Pallet<T>>::block_number();
let (seed, _) =
T::MyRandomness::random(&(T::RewardPalletId::get(), now).encode());
let seed = match seed {
Expand All @@ -424,6 +443,8 @@ pub mod pallet {
let sender = ensure_signed(origin)?;

let order = <PayOrder<T>>::try_get(&order_id).map_err(|_| Error::<T>::NoOrder)?;
let now = <frame_system::Pallet<T>>::block_number();
ensure!(order.expired > now, Error::<T>::OrderExpired);
match order.order_type {
OrderType::Buy => {
ensure!(!<UserOwnedSpace<T>>::contains_key(&order.target_acc), Error::<T>::PurchasedSpace);
Expand Down
1 change: 0 additions & 1 deletion c-pallets/storage-handler/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub struct OrderInfo<T: Config> {
pub(super) gib_count: u32,
pub(super) days: u32,
pub(super) expired: BlockNumberOf<T>,
pub(super) pay_acc: AccountOf<T>,
pub(super) target_acc: AccountOf<T>,
pub(super) order_type: OrderType,
}
Expand Down
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = '2021'
license = 'Unlicense'
name = 'cess-node'
repository = 'https://github.com/CESSProject/cess'
version = '0.7.4'
version = '0.7.5'

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
Expand Down
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ edition = "2021"
license = "Unlicense"
name = "cess-node-runtime"
repository = "https://github.com/CESSProject/cess"
version = "0.7.4"
version = "0.7.5"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]
Expand Down
1 change: 1 addition & 0 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,7 @@ impl pallet_storage_handler::Config for Runtime {
type Currency = Balances;
type WeightInfo = pallet_storage_handler::weights::SubstrateWeight<Runtime>;
type OneDay = OneDay;
type OneHours = OneHours;
type RewardPalletId = RewardPalletId;
type MyRandomness = pallet_rrsc::ParentBlockRandomness<Runtime>;
type StateStringMax = StateStringMax;
Expand Down

0 comments on commit 516a42d

Please sign in to comment.