Skip to content

Commit 4451c8b

Browse files
DeepBrainChainclaude
andcommitted
feat: GPU租赁平台上链规则调整
规则一:租金分配 - 销毁比例固定为5%(95%归卡主,5%公开销毁) - 禁用动态调整(原30%/70%/100%阶梯逻辑) - 新增卡主额外定价功能(MachineExtraPrice Storage + set_machine_extra_price Extrinsic) - 系统自动定价 + 卡主额外加价统一按95%/5%分配 规则二:质押调整 - 起步质押从1,000 DBC提高到10,000 DBC per GPU - 封顶值改为min(100,000 DBC, $300等值) - 达到封顶后在线奖励不再自动转质押 规则三:年度核算 - restake_online_machine改为多退少不补 - 质押超过封顶值:退还差额 - 质押不足封顶值:不强制补差,由在线奖励自动填充 链上操作(部署后需sudo执行): - set_rentfee_destroy_percent(Perbill::from_percent(5)) - set_online_stake_params(online_stake_usd_limit=300_000_000) - set_rent_fee_pot(独立销毁钱包地址) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent cfd4cf7 commit 4451c8b

3 files changed

Lines changed: 77 additions & 31 deletions

File tree

‎pallets/online-profile/src/lib.rs‎

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub mod pallet {
106106

107107
#[pallet::type_value]
108108
pub(super) fn RentFeeDestroyPercentDefault<T: Config>() -> Perbill {
109-
Perbill::from_percent(30)
109+
Perbill::from_percent(5)
110110
}
111111

112112
/// Statistics of gpu and stake
@@ -1032,18 +1032,24 @@ pub mod pallet {
10321032
let stake_need = stake_per_gpu
10331033
.checked_mul(&machine_info.gpu_num().saturated_into::<BalanceOf<T>>())
10341034
.ok_or(Error::<T>::CalcStakeAmountFailed)?;
1035-
ensure!(machine_info.stake_amount > stake_need, Error::<T>::NoStakeToReduce);
10361035

1037-
let extra_stake = machine_info
1038-
.stake_amount
1039-
.checked_sub(&stake_need)
1040-
.ok_or(Error::<T>::ReduceStakeFailed)?;
1036+
// 年度核算:多退少不补
1037+
if machine_info.stake_amount > stake_need {
1038+
// 多退:退还多余质押
1039+
let extra_stake = machine_info
1040+
.stake_amount
1041+
.checked_sub(&stake_need)
1042+
.ok_or(Error::<T>::ReduceStakeFailed)?;
1043+
1044+
Self::change_stake(&machine_info.machine_stash, extra_stake, false)
1045+
.map_err(|_| Error::<T>::ReduceStakeFailed)?;
1046+
machine_info.stake_amount = stake_need;
1047+
}
1048+
// 少不补:如果 stake_amount <= stake_need,不要求卡主补差额
1049+
// 质押不足的部分继续由在线奖励自动填充(fulfill_machine_stake)
10411050

1042-
machine_info.stake_amount = stake_need;
10431051
machine_info.last_machine_restake = now;
10441052
machine_info.init_stake_per_gpu = stake_per_gpu;
1045-
Self::change_stake(&machine_info.machine_stash, extra_stake, false)
1046-
.map_err(|_| Error::<T>::ReduceStakeFailed)?;
10471053

10481054
MachinesInfo::<T>::insert(&machine_id, machine_info.clone());
10491055

@@ -1650,17 +1656,8 @@ impl<T: Config> Pallet<T> {
16501656
}
16511657
}
16521658

1653-
RentFeeDestroyPercent::<T>::mutate(|percent| {
1654-
let destroy_percent = match gpu_num {
1655-
0..=4999 => Perbill::from_percent(30),
1656-
5000..=9999 => Perbill::from_percent(70),
1657-
_ => Perbill::from_percent(100),
1658-
};
1659-
1660-
if destroy_percent > *percent {
1661-
*percent = destroy_percent;
1662-
}
1663-
});
1659+
// 租金销毁比例固定5%,不再根据GPU数量动态调整
1660+
// 可通过 sudo 调用 set_rentfee_destroy_percent 手动修改
16641661
}
16651662

16661663
// 当租金转给该stash账户,或者领取在线奖励后,会检查机器奖励是否足够

‎pallets/online-profile/src/online_reward.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ impl<T: Config> Pallet<T> {
4444
}
4545
}
4646

47-
// DBC单卡质押数量计算:
48-
// dbc单卡质押数量 = min(100000, 800 $ 等值数量)
47+
// DBC单卡质押数量计算(封顶值):
48+
// dbc单卡质押数量 = min(100000, 300 $ 等值数量)
4949
pub fn stake_per_gpu() -> Option<BalanceOf<T>> {
5050
let online_stake_params = Self::online_stake_params()?;
5151

@@ -55,11 +55,11 @@ impl<T: Config> Pallet<T> {
5555
Some(stake_per_gpu_limit_by_num.min(stake_limit_by_value))
5656
}
5757

58-
// 起始质押1000 DBC,租金和奖励收益最多质押到300美金/10万个DBC
58+
// 起始质押10000 DBC,租金和奖励收益最多质押到300美金/10万个DBC
5959
pub fn stake_per_gpu_v2() -> Option<BalanceOf<T>> {
6060
let online_stake_params = Self::online_stake_params()?;
6161
let stake_per_gpu_limit_by_num =
62-
Perbill::from_rational(1_000u32, 100_000u32) * online_stake_params.online_stake_per_gpu;
62+
Perbill::from_rational(10_000u32, 100_000u32) * online_stake_params.online_stake_per_gpu;
6363

6464
Some(stake_per_gpu_limit_by_num)
6565
}

‎pallets/rent-machine/src/lib.rs‎

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,12 @@ pub mod pallet {
159159
pub(super) type EvmAddress2Account<T: Config> =
160160
StorageMap<_, Blake2_128Concat, H160, T::AccountId>;
161161

162+
/// 卡主自定义额外加价(USD×10^6 per day per GPU),在系统自动定价基础上叠加
163+
#[pallet::storage]
164+
#[pallet::getter(fn machine_extra_price)]
165+
pub(super) type MachineExtraPrice<T: Config> =
166+
StorageMap<_, Blake2_128Concat, MachineId, u64, ValueQuery>;
167+
162168
// The current storage version.
163169
#[pallet::storage]
164170
#[pallet::getter(fn storage_version)]
@@ -178,6 +184,29 @@ pub mod pallet {
178184
Ok(().into())
179185
}
180186

187+
/// 卡主设置机器额外加价(在系统自动定价基础上叠加)
188+
/// 单位:USD×10^6 per day per GPU,与 get_machine_price 返回值单位一致
189+
/// 设置为 0 表示不额外加价
190+
#[pallet::call_index(10)]
191+
#[pallet::weight(frame_support::weights::Weight::from_parts(10000, 0))]
192+
pub fn set_machine_extra_price(
193+
origin: OriginFor<T>,
194+
machine_id: MachineId,
195+
extra_price: u64,
196+
) -> DispatchResultWithPostInfo {
197+
let who = ensure_signed(origin)?;
198+
let machine_info = <online_profile::Pallet<T>>::machines_info(&machine_id)
199+
.ok_or(Error::<T>::Unknown)?;
200+
// 只有卡主(stash)或控制者(controller)可以设置
201+
ensure!(
202+
machine_info.machine_stash == who || machine_info.controller == who,
203+
Error::<T>::NoPermission
204+
);
205+
MachineExtraPrice::<T>::insert(&machine_id, extra_price);
206+
Self::deposit_event(Event::MachineExtraPriceSet(machine_id, extra_price));
207+
Ok(().into())
208+
}
209+
181210
/// 用户租用机器(按天租用)
182211
#[pallet::call_index(1)]
183212
#[pallet::weight(frame_support::weights::Weight::from_parts(10000, 0))]
@@ -322,6 +351,8 @@ pub mod pallet {
322351
Relet(RentOrderId, T::AccountId, MachineId, u32, T::BlockNumber, BalanceOf<T>),
323352

324353
SetEvmAddress(H160, T::AccountId),
354+
// machine_id, extra_price (USD×10^6 per day per GPU)
355+
MachineExtraPriceSet(MachineId, u64),
325356
}
326357

327358
#[pallet::error]
@@ -348,6 +379,7 @@ pub mod pallet {
348379
MachineNotRented,
349380
MachineNotFound,
350381
MoreThanOneRenter,
382+
NoPermission,
351383
}
352384
}
353385

@@ -389,11 +421,16 @@ impl<T: Config> Pallet<T> {
389421
<generic_func::Pallet<T>>::pay_fixed_tx_fee(renter.clone())
390422
.map_err(|_| Error::<T>::PayTxFeeFailed)?;
391423

392-
// 获得machine_price(每天的价格)
424+
// 获得machine_price(每天的价格) = 系统自动定价 + 卡主额外加价
393425
// 根据租用GPU数量计算价格
394-
let machine_price =
426+
let system_price =
395427
T::RTOps::get_machine_price(machine_info.calc_point(), rent_gpu_num, gpu_num)
396428
.ok_or(Error::<T>::GetMachinePriceFailed)?;
429+
let extra_price_per_gpu = Self::machine_extra_price(&machine_id);
430+
let extra_price = extra_price_per_gpu
431+
.checked_mul(rent_gpu_num as u64)
432+
.unwrap_or(0);
433+
let machine_price = system_price.checked_add(extra_price).unwrap_or(system_price);
397434

398435
// 根据租用时长计算rent_fee
399436
let rent_fee_value = machine_price
@@ -496,10 +533,13 @@ impl<T: Config> Pallet<T> {
496533
return Ok(().into())
497534
}
498535

499-
// 计算rent_fee
500-
let machine_price =
536+
// 计算rent_fee = 系统自动定价 + 卡主额外加价
537+
let system_price =
501538
T::RTOps::get_machine_price(calc_point, gpu_num, machine_info.gpu_num())
502539
.ok_or(Error::<T>::GetMachinePriceFailed)?;
540+
let extra_price = Self::machine_extra_price(&machine_id)
541+
.checked_mul(gpu_num as u64).unwrap_or(0);
542+
let machine_price = system_price.checked_add(extra_price).unwrap_or(system_price);
503543
let rent_fee_value = machine_price
504544
.checked_mul(add_duration.saturated_into::<u64>())
505545
.ok_or(Error::<T>::Overflow)?
@@ -865,12 +905,15 @@ impl<T: Config> MachineInfoTrait for Pallet<T> {
865905
let machine_info = <online_profile::Pallet<T>>::machines_info(&machine_id)
866906
.ok_or(Error::<T>::Unknown.as_str())?;
867907

868-
let machine_price = T::RTOps::get_machine_price(
908+
let system_price = T::RTOps::get_machine_price(
869909
machine_info.calc_point(),
870910
rent_gpu_num,
871911
machine_info.gpu_num(),
872912
)
873913
.ok_or(Error::<T>::GetMachinePriceFailed)?;
914+
let extra_price = Self::machine_extra_price(&machine_id)
915+
.checked_mul(rent_gpu_num as u64).unwrap_or(0);
916+
let machine_price = system_price.checked_add(extra_price).unwrap_or(system_price);
874917

875918
// 根据租用时长计算rent_fee
876919
let rent_fee_value = machine_price
@@ -888,12 +931,15 @@ impl<T: Config> MachineInfoTrait for Pallet<T> {
888931
let machine_info = <online_profile::Pallet<T>>::machines_info(&machine_id)
889932
.ok_or(Error::<T>::Unknown.as_str())?;
890933

891-
let machine_price = T::RTOps::get_machine_price(
934+
let system_price = T::RTOps::get_machine_price(
892935
machine_info.calc_point(),
893936
rent_gpu_num,
894937
machine_info.gpu_num(),
895938
)
896939
.ok_or(Error::<T>::GetMachinePriceFailed)?;
940+
let extra_price = Self::machine_extra_price(&machine_id)
941+
.checked_mul(rent_gpu_num as u64).unwrap_or(0);
942+
let machine_price = system_price.checked_add(extra_price).unwrap_or(system_price);
897943

898944
// 根据租用时长计算rent_fee
899945
let rent_fee_value = machine_price
@@ -937,12 +983,15 @@ impl<T: Config> MachineInfoTrait for Pallet<T> {
937983
let machine_info = <online_profile::Pallet<T>>::machines_info(&machine_id)
938984
.ok_or(Error::<T>::Unknown.as_str())?;
939985

940-
let machine_price = T::RTOps::get_machine_price(
986+
let system_price = T::RTOps::get_machine_price(
941987
machine_info.calc_point(),
942988
rent_gpu_num,
943989
machine_info.gpu_num(),
944990
)
945991
.ok_or(Error::<T>::GetMachinePriceFailed)?;
992+
let extra_price = Self::machine_extra_price(&machine_id)
993+
.checked_mul(rent_gpu_num as u64).unwrap_or(0);
994+
let machine_price = system_price.checked_add(extra_price).unwrap_or(system_price);
946995

947996
// 根据租用时长计算rent_fee
948997
let rent_fee_value = machine_price

0 commit comments

Comments
 (0)