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

Fix delegator vote #1060

Merged
merged 7 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions integration-tests/bifrost-kusama/src/vtoken_voting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ fn vote_works() {
assert_ok!(VtokenVoting::set_delegator_role(
RuntimeOrigin::root(),
vtoken,
poll_index,
5,
VoteRole::Standard { aye: true, conviction: Conviction::Locked5x },
));
Expand Down
5 changes: 5 additions & 0 deletions pallets/flexible-fee/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,10 @@ impl VTokenSupplyProvider<CurrencyId, Balance> for SimpleVTokenSupplyProvider {
}
}

parameter_types! {
pub const ReferendumCheckInterval: BlockNumber = 300;
}

impl bifrost_vtoken_voting::Config for Test {
type RuntimeEvent = RuntimeEvent;
type RuntimeOrigin = RuntimeOrigin;
Expand All @@ -527,6 +531,7 @@ impl bifrost_vtoken_voting::Config for Test {
type MaxVotes = ConstU32<256>;
type ParachainId = ParaInfo;
type QueryTimeout = QueryTimeout;
type ReferendumCheckInterval = ReferendumCheckInterval;
type WeightInfo = ();
}

Expand Down
45 changes: 35 additions & 10 deletions pallets/vtoken-voting/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ fn account_vote<T: Config>(b: BalanceOf<T>) -> AccountVote<BalanceOf<T>> {
AccountVote::Standard { vote: v, balance: b }
}

fn init_vote<T: Config>(vtoken: CurrencyIdOf<T>) -> Result<(), BenchmarkError> {
fn init_vote<T: Config>(
vtoken: CurrencyIdOf<T>,
poll_index: PollIndex,
) -> Result<(), BenchmarkError> {
let derivative_index = 0;
let token = CurrencyId::to_token(&vtoken).unwrap();
T::XcmDestWeightAndFee::set_xcm_dest_weight_and_fee(
Expand All @@ -58,6 +61,7 @@ fn init_vote<T: Config>(vtoken: CurrencyIdOf<T>) -> Result<(), BenchmarkError> {
Pallet::<T>::set_delegator_role(
RawOrigin::Root.into(),
vtoken,
poll_index,
derivative_index,
VoteRole::Standard { aye: true, conviction: Conviction::Locked1x },
)?;
Expand All @@ -79,10 +83,18 @@ mod benchmarks {
let control_origin =
T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;

init_vote::<T>(vtoken)?;
init_vote::<T>(vtoken, poll_index)?;
let derivative_index = 0;
let r = T::MaxVotes::get() - 1;
let response = Response::DispatchResult(MaybeErrorCode::Success);
for (i, index) in (0..T::MaxVotes::get()).collect::<Vec<_>>().iter().skip(1).enumerate() {
Pallet::<T>::set_delegator_role(
RawOrigin::Root.into(),
vtoken,
*index,
derivative_index,
VoteRole::Standard { aye: true, conviction: Conviction::Locked1x },
)?;
Pallet::<T>::on_idle(Zero::zero(), Weight::MAX);
Pallet::<T>::vote(RawOrigin::Signed(caller.clone()).into(), vtoken, *index, vote)?;
Pallet::<T>::notify_vote(
Expand Down Expand Up @@ -113,14 +125,25 @@ mod benchmarks {
let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);
let vtoken = VKSM;
let poll_index = 0u32;
let old_vote = account_vote::<T>(100u32.into());
let control_origin =
T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;

init_vote::<T>(vtoken)?;
init_vote::<T>(vtoken, poll_index)?;
let derivative_index = 0;
let r = 50;
let response = Response::DispatchResult(MaybeErrorCode::Success);
for index in (0..r).collect::<Vec<_>>().iter() {
if *index != 0 {
Pallet::<T>::set_delegator_role(
RawOrigin::Root.into(),
vtoken,
*index,
derivative_index,
VoteRole::Standard { aye: true, conviction: Conviction::Locked1x },
)?;
}
Pallet::<T>::vote(RawOrigin::Signed(caller.clone()).into(), vtoken, *index, old_vote)?;
Pallet::<T>::notify_vote(
control_origin.clone() as <T as frame_system::Config>::RuntimeOrigin,
Expand Down Expand Up @@ -156,7 +179,7 @@ mod benchmarks {
let poll_index = 0u32;
let vote = account_vote::<T>(100u32.into());

init_vote::<T>(vtoken)?;
init_vote::<T>(vtoken, poll_index)?;
Pallet::<T>::vote(origin.clone().into(), vtoken, poll_index, vote)?;
Pallet::<T>::set_referendum_status(
RawOrigin::Root.into(),
Expand All @@ -182,7 +205,7 @@ mod benchmarks {
let vote = account_vote::<T>(100u32.into());
let derivative_index = 0u16;

init_vote::<T>(vtoken)?;
init_vote::<T>(vtoken, poll_index)?;
Pallet::<T>::vote(origin.clone().into(), vtoken, poll_index, vote)?;
Pallet::<T>::set_referendum_status(
RawOrigin::Root.into(),
Expand Down Expand Up @@ -212,7 +235,7 @@ mod benchmarks {
let poll_index = 0u32;
let vote = account_vote::<T>(100u32.into());

init_vote::<T>(vtoken)?;
init_vote::<T>(vtoken, poll_index)?;
let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);
let origin_caller = RawOrigin::Signed(caller);
Expand All @@ -235,10 +258,11 @@ mod benchmarks {
let origin =
T::ControlOrigin::try_successful_origin().map_err(|_| BenchmarkError::Weightless)?;
let vtoken = VKSM;
let poll_index = 0u32;
let derivative_index = 10;
let vote_role = VoteRole::SplitAbstain;

init_vote::<T>(vtoken)?;
init_vote::<T>(vtoken, poll_index)?;
T::DerivativeAccount::add_delegator(
CurrencyId::to_token(&vtoken).unwrap(),
derivative_index,
Expand All @@ -249,6 +273,7 @@ mod benchmarks {
_(
origin as <T as frame_system::Config>::RuntimeOrigin,
vtoken,
poll_index,
derivative_index,
vote_role,
);
Expand All @@ -264,7 +289,7 @@ mod benchmarks {
let poll_index = 0u32;
let info = ReferendumInfo::Completed(<frame_system::Pallet<T>>::block_number());

init_vote::<T>(vtoken)?;
init_vote::<T>(vtoken, poll_index)?;
let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);
let origin_caller = RawOrigin::Signed(caller);
Expand Down Expand Up @@ -312,7 +337,7 @@ mod benchmarks {
let query_id = 1u64;
let response = Response::DispatchResult(MaybeErrorCode::Success);

init_vote::<T>(vtoken)?;
init_vote::<T>(vtoken, poll_index)?;
let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);
let origin_caller = RawOrigin::Signed(caller);
Expand All @@ -334,7 +359,7 @@ mod benchmarks {
let query_id = 1u64;
let response = Response::DispatchResult(MaybeErrorCode::Success);

init_vote::<T>(vtoken)?;
init_vote::<T>(vtoken, poll_index)?;
let caller = funded_account::<T>("caller", 0);
whitelist_account!(caller);
let origin_caller = RawOrigin::Signed(caller);
Expand Down
Loading
Loading