Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random xor-fee remint #1305

Merged
merged 6 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 8 additions & 15 deletions pallets/kensetsu/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,13 +285,11 @@ pub mod pallet {
// known problem. The purpose of the code is not to protect from the attack but to
// make choosing of CDP to liquidate more 'fair' then incremental order.
let (randomness, _) = T::Randomness::random(&b"kensetsu"[..]);
match randomness {
Some(randomness) => {
match u32::decode(&mut randomness.as_ref()) {
Ok(random_number) => {
// Random bias by modulus operation is acceptable here
let random_id = random_number as usize % unsafe_cdp_ids.len();
unsafe_cdp_ids
match u32::decode(&mut randomness.as_ref()) {
Ok(random_number) => {
// Random bias by modulus operation is acceptable here
let random_id = random_number as usize % unsafe_cdp_ids.len();
unsafe_cdp_ids
.get(random_id)
.map_or_else(
|| {
Expand All @@ -311,14 +309,9 @@ pub mod pallet {
);
}
});
}
Err(error) => {
warn!("Failed to get randomness during liquidation: {}", error);
}
}
}
None => {
warn!("No randomness provided.");
Err(error) => {
warn!("Failed to get randomness during liquidation: {}", error);
}
}
}
Expand All @@ -333,7 +326,7 @@ pub mod pallet {
+ SendTransactionTypes<Call<Self>>
{
type RuntimeEvent: From<Event<Self>> + IsType<<Self as frame_system::Config>::RuntimeEvent>;
type Randomness: Randomness<Option<Self::Hash>, Self::BlockNumber>;
type Randomness: Randomness<Self::Hash, Self::BlockNumber>;
type AssetInfoProvider: AssetInfoProvider<
AssetIdOf<Self>,
Self::AccountId,
Expand Down
4 changes: 2 additions & 2 deletions pallets/kensetsu/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<TestRunt

pub struct MockRandomness;

impl Randomness<Option<Hash>, BlockNumber> for MockRandomness {
fn random(_subject: &[u8]) -> (Option<Hash>, BlockNumber) {
impl Randomness<Hash, BlockNumber> for MockRandomness {
fn random(_subject: &[u8]) -> (Hash, BlockNumber) {
unimplemented!()
}
}
Expand Down
7 changes: 7 additions & 0 deletions pallets/xor-fee/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,12 @@ benchmarks! {
}
}

set_random_remint_period {
let new_period = 500_u32;
}: _(RawOrigin::Root, new_period)
verify {
assert_eq!(<RemintPeriod<T>>::get(), new_period);
}

impl_benchmark_test_suite!(Pallet, mock::ExtBuilder::build(), mock::Runtime);
}
Loading