Skip to content

Commit

Permalink
0.7.6 miner staking (#270)
Browse files Browse the repository at this point in the history
* update readme

* feat: miner staking

* feat: storage node expansion and staking function
  • Loading branch information
ytqaljn authored Dec 7, 2023
1 parent a2c7ab2 commit 7d526a9
Show file tree
Hide file tree
Showing 14 changed files with 1,442 additions and 1,075 deletions.
98 changes: 98 additions & 0 deletions pallets/cess-treasury/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# Cess Treasury Module

Manage meta information of cess-treasury.

## Overview

There are three accounts in the CESS treasury that store funds for different purposes. At the same time, in order to adjust the inflation rate of network tokens, this module provides corresponding methods for destroying funds. Users with root authority can control the funds of two of the accounts, and the reward pool of the storage node does not have any authority to operate.

## Terminology

* **PunishTreasuryId:** Used to collect tokens that have been punished by storage nodes. The tokens in their accounts can be controlled by root privileges.

* **SpaceTreasuryId:** Used to collect tokens spent by users to purchase space. This account can control funds with root authority.

* **MinerRewardId:** Collect tokens used to reward storage nodes. Each era is issued tokens to the account by the `staking pallet`. Root privileges do not have the right to control the account's token.

## Extrinsic

* `send_funds_to_pid()` - Can be called with any permissions. Send any number of tokens to **PunishTreasuryId** account.
* `send_funds_to_sid()` - Can be called with any permissions. Send any number of tokens to **SpaceTreasuryId** account.
* `pid_burn_funds()` - Can only be called with root privileges. Destroy any number of tokens in the **PunishTreasuryId** account.
* `sid_burn_funds()` - Can only be called with root privileges. Destroy any number of tokens in the **SpaceTreasuryId** account.
* `pid_send_funds()` Can only be called with root privileges. **PunishTreasuryId** account transfers any number of tokens to the designated account.
* `sid_send_funds()` Can only be called with root privileges. **SpaceTreasuryId** account transfers any number of tokens to the designated account.

## Interface

### RewardPool

The interface used to operate the reward account and perform addition, modification and check on the funds in the reward account. However, it cannot directly manipulate the balance and can only record changes to `CurrencyReward`.

#### Function

* `get_reward()` - Get the current reward amount.
* `get_reward_128()` - Get the current u128 type reward amount.
* `add_reward()` - Increase reward amount. It should be noted that the total amount of rewards must remain unchanged and can only be used in some special circumstances and cannot be directly increased. Otherwise, the amount of bonus pool rewards and the balance in the account will not correspond.
* `sub_reward()` - Reduce reward amount.

#### Usage

in pallet::Config

```rust
pub trait Config: frame_system::Config + sp_std::fmt::Debug {
// ...
type RewardPool: RewardPool<AccountOf<Self>, BalanceOf<Self>>;
// ...
}
```

in runtime.rs
```rust
impl pallet_sminer::Config for Runtime {
// ...
type RewardPool = CessTreasury;
// ...
}
```

### TreasuryHandle

Provides an interface for collecting tokens, through which other pallets transfer tokens to designated accounts.

#### Function

* `send_to_pid()` - Send any number of tokens to **PunishTreasuryId**.
* `send_to_sid()` - Send any number of tokens to **SpaceTreasuryId**.

#### Usage

in pallet::Config

```rust
pub trait Config: frame_system::Config + sp_std::fmt::Debug {
// ...
type CessTreasuryHandle: TreasuryHandle<AccountOf<Self>, BalanceOf<Self>>;
// ...
}
```

in runtime.rs
```rust
impl pallet_sminer::Config for Runtime {
// ...
type CessTreasuryHandle = CessTreasury;
// ...
}
```

## Implementation Details

### Miner Reward

The total issuance of storage node rewards in the first year is 477,000,000 CESS, with an average of 326,488 CESS per era (One era every six hours).
Starting in the second year, the annual reward decreases linearly with an annual decay rate of approximately 0.841, halving every 4 years. For details, please view the CESS Network’s [Reward Mechanism](https://docs.cess.cloud/core/storage-miner/reward).

* **MinerRewardId:** The wallet account of the miner reward pool, in which balance is the real bonus.
* **CurrencyReward:** It is a `StorageValue` type storage pool. The current reward records how many available rewards are available in the bonus account. Change it by issuing rewards each time, or recycling rewards.
20 changes: 0 additions & 20 deletions pallets/cess-treasury/src/README.md

This file was deleted.

12 changes: 7 additions & 5 deletions pallets/file-bank/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
//! * `buyfile` - Buy file with download fee.
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(test)]
mod mock;
// #[cfg(test)]
// mod mock;

#[cfg(test)]
mod tests;
// #[cfg(test)]
// mod tests;

use frame_support::traits::{
FindAuthor, Randomness,
Expand Down Expand Up @@ -673,6 +673,7 @@ pub mod pallet {
&sender,
idle_sig_info.accumulator,
idle_sig_info.front,
idle_sig_info.rear,
tee_sig,
)?;

Expand Down Expand Up @@ -753,6 +754,7 @@ pub mod pallet {
let idle_space = T::MinerControl::add_miner_idle_space(
&sender,
idle_sig_info.accumulator,
idle_sig_info.front,
idle_sig_info.rear,
tee_sig,
)?;
Expand Down Expand Up @@ -1131,4 +1133,4 @@ impl<T: Config> BlockNumberProvider for Pallet<T> {
fn current_block_number() -> Self::BlockNumber {
<frame_system::Pallet<T>>::block_number()
}
}
}
Loading

0 comments on commit 7d526a9

Please sign in to comment.