Skip to content

Commit

Permalink
Audit review
Browse files Browse the repository at this point in the history
  • Loading branch information
AurevoirXavier committed Sep 24, 2024
1 parent 941b687 commit a8a01a8
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 18 deletions.
8 changes: 6 additions & 2 deletions pallet/staking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,10 @@ pub mod pallet {
// let cs_from_contract = Self::elect_from_contract(n1)?;
// let cs_from_pallet = Self::elect(n2)?;
let cs_from_contract = Self::elect_from_contract(n1).unwrap_or_default();
let cs_from_pallet = Self::elect(n2).unwrap_or_default();
let cs_from_pallet = Self::elect(n2).unwrap_or_default()
.into_iter()
.filter(|c| !cs_from_contract.contains(c))
.collect();

log::info!("collators from contract {cs_from_contract:?}");
log::info!("collators from pallet {cs_from_pallet:?}");
Expand Down Expand Up @@ -1356,7 +1359,8 @@ where
PalletId(*b"da/staki").into_account_truncating()
}

fn now<T>() -> Moment
/// The current time in milliseconds.
pub fn now<T>() -> Moment
where
T: Config,
{
Expand Down
10 changes: 6 additions & 4 deletions pallet/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,13 +266,15 @@ impl crate::Election<AccountId> for RingStaking {
.map(|i| {
let who = AccountId(i);

assert_ok!(Session::set_keys(
if Session::set_keys(
RuntimeOrigin::signed(who),
SessionKeys { uint: i.into() },
Vec::new()
));

who
).is_ok() {
who
} else {
AccountId(0)
}
})
.collect(),
)
Expand Down
18 changes: 18 additions & 0 deletions pallet/staking/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,6 +845,24 @@ fn hybrid_election_should_work() {
});
}

#[test]
fn dedup_election_should_work() {
ExtBuilder::default().collator_count(10).build().execute_with(|| {
let who = AccountId(100);
let _ = <pallet_balances::Pallet<Runtime>>::deposit_creating(&who, 100 as _);

assert_ok!(Staking::stake(RuntimeOrigin::signed(who), 100 as _, Vec::new()));
assert_ok!(Staking::collect(RuntimeOrigin::signed(who), Perbill::zero()));
assert_ok!(Staking::nominate(RuntimeOrigin::signed(who), who));

Timestamp::set_timestamp(30 * DAY_IN_MILLIS);
new_session();
new_session();

assert_eq!(vec![who], <pallet_session::Validators<Runtime>>::get());
});
}

#[test]
fn hybrid_payout_should_work() {
ExtBuilder::default().collator_count(10).inflation_type(1).build().execute_with(|| {
Expand Down
11 changes: 0 additions & 11 deletions precompile/deposit/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,4 @@ where

Ok(true)
}

#[precompile::public("migrate(address)")]
fn migrate(handle: &mut impl PrecompileHandle, who: Address) -> EvmResult<bool> {
let origin: AccountIdOf<Runtime> = handle.context().caller.into();
RuntimeHelper::<Runtime>::try_dispatch(
handle,
Some(origin).into(),
darwinia_deposit::Call::<Runtime>::migrate { who: H160::from(who).into() },
)?;
Ok(true)
}
}
1 change: 0 additions & 1 deletion precompile/deposit/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ fn selectors() {
assert!(PCall::lock_selectors().contains(&0x998e4242));
assert!(PCall::claim_selectors().contains(&0x4e71d92d));
assert!(PCall::claim_with_penalty_selectors().contains(&0xfa04a9bf));
assert!(PCall::migrate_selectors().contains(&0xce5494bb));
}

#[test]
Expand Down
2 changes: 2 additions & 0 deletions runtime/crab/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ fn migrate() -> frame_support::weights::Weight {
<darwinia_staking::RingStakingContract<Runtime>>::put(who);
}

darwinia_staking::MigrationStartPoint::put(darwinia_staking::now());

// frame_support::weights::Weight::zero()
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(7, 7)
}
2 changes: 2 additions & 0 deletions runtime/darwinia/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ fn migrate() -> frame_support::weights::Weight {
<darwinia_staking::RingStakingContract<Runtime>>::put(who);
}

darwinia_staking::MigrationStartPoint::put(darwinia_staking::now());

// frame_support::weights::Weight::zero()
<Runtime as frame_system::Config>::DbWeight::get().reads_writes(7, 107)
}

0 comments on commit a8a01a8

Please sign in to comment.