Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Redesign fee market payment (#169)
Browse files Browse the repository at this point in the history
* Add basic solution

* Refactor Slash Report

* Refactor Slash Report 2

* Add other changes

* Add tests

* Self review

* Rename to `message_and_confirm_reward`

* Rename to `previous_relayers`

* Rename to AssignedRelayer

* Add more comments

* Add more comments

* Add new reward implementation

* Rename and clean the code, needs more test

* Add more docs here

* Prepare for tests

* Fix broken tests

* Refactor

* Rename

* Remove RewardBook

* Self review

* Save one storage

* Try fix ci
  • Loading branch information
boundless-forest authored Aug 1, 2022
1 parent 8e05770 commit 78d02d4
Show file tree
Hide file tree
Showing 4 changed files with 437 additions and 218 deletions.
17 changes: 12 additions & 5 deletions modules/fee-market/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,18 @@ pub mod pallet {

/// Reward parameters
#[pallet::constant]
type AssignedRelayersRewardRatio: Get<Permill>;
type GuardRelayersRewardRatio: Get<Permill>;
#[pallet::constant]
type MessageRelayersRewardRatio: Get<Permill>;
#[pallet::constant]
type ConfirmRelayersRewardRatio: Get<Permill>;

/// The slash rule
/// The slash ratio for assigned relayers.
#[pallet::constant]
type AssignedRelayerSlashRatio: Get<Permill>;
type Slasher: Slasher<Self, I>;
type Currency: LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>;

type Currency: LockableCurrency<Self::AccountId, Moment = Self::BlockNumber>;
type Event: From<Event<Self, I>> + IsType<<Self as frame_system::Config>::Event>;
type WeightInfo: WeightInfo;
}
Expand Down Expand Up @@ -474,7 +476,8 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
let mut count = 0u32;
let mut orders_locked_collateral = BalanceOf::<T, I>::zero();
for (_, order) in <Orders<T, I>>::iter() {
if order.relayers_slice().iter().any(|r| r.id == *who) && !order.is_confirmed() {
if order.assigned_relayers_slice().iter().any(|r| r.id == *who) && !order.is_confirmed()
{
count += 1;
orders_locked_collateral =
orders_locked_collateral.saturating_add(order.locked_collateral);
Expand Down Expand Up @@ -504,6 +507,10 @@ impl<T: Config<I>, I: 'static> Pallet<T, I> {
}
}

/// The assigned relayers slash trait
pub trait Slasher<T: Config<I>, I: 'static> {
fn slash(locked_collateral: BalanceOf<T, I>, timeout: T::BlockNumber) -> BalanceOf<T, I>;
fn cal_slash_amount(
collateral_per_order: BalanceOf<T, I>,
timeout: T::BlockNumber,
) -> BalanceOf<T, I>;
}
Loading

0 comments on commit 78d02d4

Please sign in to comment.