Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
25bddc9
mockup
kianenigma Sep 11, 2020
7bef52f
Add files
kianenigma Sep 11, 2020
4f3dfa4
Merge branch 'master' of github.com:paritytech/substrate into kiz-ele…
kianenigma Sep 23, 2020
bc30ce1
More mockup
kianenigma Sep 24, 2020
9e52fbc
Merge branch 'master' of github.com:paritytech/substrate into kiz-ele…
kianenigma Oct 1, 2020
14ebc95
Lots more changes and tests. Initial design of signed is forseable now.
kianenigma Oct 2, 2020
0587fc9
Merge branch 'master' of github.com:paritytech/substrate into kiz-ele…
kianenigma Oct 8, 2020
233d4e1
More changes for the signed phase, now going to the cluster-fu*k of g…
kianenigma Oct 9, 2020
9c880f3
Finally decoupled solution from the pallet.. such a PITA.
kianenigma Oct 9, 2020
0cb35eb
Much simplifications and cleanups.
kianenigma Oct 9, 2020
c1ff3ec
A skeleton for the unsigned version.
kianenigma Oct 9, 2020
85a346e
Master.into()
kianenigma Oct 13, 2020
6a2542d
Staking builds and tests compile, some tests fail
kianenigma Oct 13, 2020
c361911
All staking tests work
kianenigma Oct 14, 2020
218db10
Unsigned almost done, primitive crate added.
kianenigma Oct 15, 2020
5e21a79
Merge branch 'master' of github.com:paritytech/substrate into kiz-ele…
kianenigma Oct 15, 2020
25c1bc3
Use decl_error
kianenigma Oct 15, 2020
d53785c
Add basic benchmark setup, needs more work
kianenigma Oct 16, 2020
525f6e0
Comment.
kianenigma Oct 16, 2020
3026316
Checkpoint.
kianenigma Oct 20, 2020
9841e3b
node-runtime builds.
kianenigma Oct 20, 2020
16c0550
Builds and all good?
kianenigma Dec 3, 2020
f197b6b
Undo some formatting mistakes
kianenigma Dec 3, 2020
5005281
Working on benchmarks'
kianenigma Dec 7, 2020
bd0d331
Fix bench
kianenigma Dec 8, 2020
67dd4d1
Strange merge -- everything builds.
kianenigma Dec 8, 2020
eac4571
Everything compiles and good -- need to fix benches.
kianenigma Dec 8, 2020
a7c4841
Some Staking stuff left to do.
kianenigma Dec 9, 2020
2ca3dcf
Master.into()
kianenigma Dec 14, 2020
4922897
Split the snapshot; type for CompactSolution and MaxNominations
kianenigma Dec 15, 2020
ef593a7
Fix a bunch more issues.
kianenigma Dec 15, 2020
8661814
check new design
kianenigma Dec 18, 2020
57f7294
Everything within the module works and compiles.
kianenigma Dec 21, 2020
af304d1
Stkaing also builds
kianenigma Dec 21, 2020
80e7450
Everything builds with the new scheme.
kianenigma Dec 25, 2020
4b4712a
Master.into()
kianenigma Dec 26, 2020
206933a
Simplify elect API.
kianenigma Dec 26, 2020
af9b97d
Fix all other tests.
kianenigma Dec 26, 2020
9663fea
make the staking api better and well tested.
kianenigma Jan 4, 2021
7f4f5b7
Almost done with conversion
kianenigma Jan 4, 2021
8fb11f1
Move to pallet V2 + construct_runtime
kianenigma Jan 5, 2021
bd6d4d9
Master.into()
kianenigma Jan 5, 2021
65f5ac1
Revert staking changes;
kianenigma Jan 5, 2021
3860885
Revert Staking fuzzer.
kianenigma Jan 5, 2021
392f35a
Fix fuzzers
kianenigma Jan 5, 2021
1337e1b
Update frame/election-providers/src/two_phase/mod.rs
kianenigma Jan 6, 2021
4f6ec0d
a round of self review
kianenigma Jan 6, 2021
b3113f7
A large number of bugfixes after local test and self-review
kianenigma Jan 7, 2021
abca039
Upstream.into()
kianenigma Jan 7, 2021
6bc578a
Master.into()
kianenigma Jan 7, 2021
876f666
Apply suggestions from code review
kianenigma Jan 7, 2021
81df1df
Update frame/election-providers/src/two_phase/benchmarking.rs
kianenigma Jan 7, 2021
e3862ce
Fix some review grumbles.
kianenigma Jan 8, 2021
ca06f8e
Fix some docs
kianenigma Jan 8, 2021
6206c32
Merge branch 'kiz-election-provider' of github.com:paritytech/substra…
kianenigma Jan 8, 2021
95d7a3c
Master.into()
kianenigma Jan 8, 2021
63776ff
Maybe relocalte the code?
kianenigma Jan 8, 2021
4732854
Master.into()
kianenigma Jan 8, 2021
a922f0b
Witness -> SoltionSize
kianenigma Jan 8, 2021
6d8247a
cargo run --release --features=runtime-benchmarks --manifest-path=bin…
Jan 8, 2021
e9f4437
cargo run --release --features=runtime-benchmarks --manifest-path=bin…
Jan 8, 2021
02069e1
Update frame/session/src/lib.rs
kianenigma Jan 12, 2021
000ecdc
Revamp macros
kianenigma Jan 12, 2021
cb6f156
Merge branch 'kiz-election-provider' of github.com:paritytech/substra…
kianenigma Jan 12, 2021
df04ef3
Merge remote-tracking branch 'origin/master' into kiz-election-provider
Jan 12, 2021
ee2a316
Master.into()
kianenigma Jan 12, 2021
0d92ed5
Merge branch 'kiz-election-provider' of github.com:paritytech/substra…
kianenigma Jan 12, 2021
88a96a0
Fix build
kianenigma Jan 12, 2021
6480ce1
Merge remote-tracking branch 'origin/master' into kiz-election-provider
Jan 12, 2021
8a68915
cargo run --release --features=runtime-benchmarks --manifest-path=bin…
Jan 12, 2021
f4e2c03
Merge branch 'master' of github.com:paritytech/substrate into kiz-ele…
kianenigma Jan 12, 2021
c41ecb0
fix all the tests.
kianenigma Jan 13, 2021
b42336a
Merge branch 'kiz-election-provider' of github.com:paritytech/substra…
kianenigma Jan 13, 2021
f5e23f9
Fix the strange issue with cargo lock
kianenigma Jan 13, 2021
56bb93c
revamp closures.
kianenigma Jan 14, 2021
257795c
Update frame/two-phase-election-provider/src/benchmarking.rs
kianenigma Jan 14, 2021
9c114bc
Merge remote-tracking branch 'origin/master' into kiz-election-provider
Jan 14, 2021
1ac97f5
Some review grumbles.
kianenigma Jan 14, 2021
366b15b
Merge branch 'master' of github.com:paritytech/substrate into kiz-ele…
kianenigma Jan 14, 2021
afa5507
Upstream.into()
kianenigma Jan 14, 2021
5d206ab
Fix build
kianenigma Jan 14, 2021
ea193c7
Bring back benches
kianenigma Jan 14, 2021
60e57d7
cargo run --release --features=runtime-benchmarks --manifest-path=bin…
Jan 14, 2021
77f53a3
Add a bunch of more fixes: signed weight check, tests etc.
kianenigma Jan 15, 2021
9ce9d6b
Merge branch 'kiz-election-provider' of github.com:paritytech/substra…
kianenigma Jan 15, 2021
b30dfb3
Fix build
kianenigma Jan 15, 2021
6001d7d
Master.into()
kianenigma Jan 15, 2021
a066e4a
Last small tweaks
kianenigma Jan 15, 2021
10f6e7b
Fix all tests.
kianenigma Jan 15, 2021
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
Prev Previous commit
Next Next commit
Maybe relocalte the code?
  • Loading branch information
kianenigma committed Jan 8, 2021
commit 63776ff8d14fddc0b33c129bbf33b4f887a2a1c7
885 changes: 447 additions & 438 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ members = [
"frame/staking",
"frame/staking/fuzzer",
"frame/staking/reward-curve",
"frame/election-providers",
"frame/two-phase-election-provider",
"frame/sudo",
"frame/support",
"frame/support/procedural",
Expand Down
6 changes: 3 additions & 3 deletions bin/node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ frame-executive = { version = "2.0.0", default-features = false, path = "../../.
frame-benchmarking = { version = "2.0.0", default-features = false, path = "../../../frame/benchmarking", optional = true }
frame-support = { version = "2.0.0", default-features = false, path = "../../../frame/support" }
frame-system = { version = "2.0.0", default-features = false, path = "../../../frame/system" }
frame-election-providers = { version = "2.0.0", default-features = false, path = "../../../frame/election-providers/" }
frame-system-benchmarking = { version = "2.0.0", default-features = false, path = "../../../frame/system/benchmarking", optional = true }
frame-system-rpc-runtime-api = { version = "2.0.0", default-features = false, path = "../../../frame/system/rpc/runtime-api/" }
pallet-assets = { version = "2.0.0", default-features = false, path = "../../../frame/assets" }
Expand Down Expand Up @@ -73,6 +72,7 @@ pallet-recovery = { version = "2.0.0", default-features = false, path = "../../.
pallet-session = { version = "2.0.0", features = ["historical"], path = "../../../frame/session", default-features = false }
pallet-session-benchmarking = { version = "2.0.0", path = "../../../frame/session/benchmarking", default-features = false, optional = true }
pallet-staking = { version = "2.0.0", default-features = false, path = "../../../frame/staking" }
pallet-two-phase-election-provider = { version = "2.0.0", default-features = false, path = "../../../frame/two-phase-election-provider/" }
pallet-staking-reward-curve = { version = "2.0.0", default-features = false, path = "../../../frame/staking/reward-curve" }
pallet-scheduler = { version = "2.0.0", default-features = false, path = "../../../frame/scheduler" }
pallet-society = { version = "2.0.0", default-features = false, path = "../../../frame/society" }
Expand Down Expand Up @@ -143,7 +143,7 @@ std = [
"frame-benchmarking/std",
"frame-system-rpc-runtime-api/std",
"frame-system/std",
"frame-election-providers/std",
"pallet-two-phase-election-provider/std",
"pallet-timestamp/std",
"pallet-tips/std",
"pallet-transaction-payment-rpc-runtime-api/std",
Expand All @@ -160,7 +160,7 @@ runtime-benchmarks = [
"frame-benchmarking",
"frame-support/runtime-benchmarks",
"frame-system/runtime-benchmarks",
"frame-election-providers/runtime-benchmarks",
"pallet-two-phase-election-provider/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
"pallet-assets/runtime-benchmarks",
"pallet-babe/runtime-benchmarks",
Expand Down
1 change: 0 additions & 1 deletion bin/node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ use pallet_session::{historical as pallet_session_historical};
use sp_inherents::{InherentData, CheckInherentsResult};
use static_assertions::const_assert;
use pallet_contracts::WeightInfo;
use frame_election_providers::two_phase as pallet_two_phase_election_provider;

#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
Expand Down
49 changes: 0 additions & 49 deletions frame/election-providers/src/lib.rs

This file was deleted.

1 change: 0 additions & 1 deletion frame/staking/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ sp-storage = { version = "2.0.0", path = "../../primitives/storage" }
sp-tracing = { version = "2.0.0", path = "../../primitives/tracing" }
pallet-balances = { version = "2.0.0", path = "../balances" }
pallet-timestamp = { version = "2.0.0", path = "../timestamp" }
frame-election-providers = { version = "2.0.0", path = "../election-providers" }
pallet-staking-reward-curve = { version = "2.0.0", path = "../staking/reward-curve" }
substrate-test-utils = { version = "2.0.0", path = "../../test-utils" }
frame-benchmarking = { version = "2.0.0", path = "../benchmarking" }
Expand Down
2 changes: 1 addition & 1 deletion frame/staking/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use sp_runtime::{
};
use sp_staking::offence::{OffenceDetails, OnOffenceHandler};
use std::{cell::RefCell, collections::HashSet};
use frame_election_providers::onchain;
use sp_election_providers::onchain;

pub const INIT_TIMESTAMP: u64 = 30_000;
pub const BLOCK_TIME: u64 = 1000;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "frame-election-providers"
name = "pallet-two-phase-election-provider"
version = "2.0.0"
authors = ["Parity Technologies <[email protected]>"]
edition = "2018"
license = "Apache-2.0"
homepage = "https://substrate.dev"
repository = "https://github.com/paritytech/substrate/"
description = "FRAME election providers"
description = "PALLET two phase election providers"
readme = "README.md"

[package.metadata.docs.rs]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//! Two phase election pallet benchmarking.

use super::*;
use crate::two_phase::{Module as TwoPhase};
use crate::Module as TwoPhase;

pub use frame_benchmarking::{account, benchmarks, whitelist_account, whitelisted_caller};
use frame_support::{assert_ok, traits::OnInitialize};
Expand Down Expand Up @@ -311,7 +311,7 @@ benchmarks! {
#[cfg(test)]
mod test {
use super::*;
use crate::two_phase::mock::*;
use crate::mock::*;

#[test]
fn test_benchmarks() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file is part of Substrate.

// Copyright (C) 2020 Parity Technologies (UK) Ltd.
// Copyright (C) 2021 Parity Technologies (UK) Ltd.
// SPDX-License-Identifier: Apache-2.0

// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -36,10 +36,9 @@
//! ```
//!
//! Note that the unsigned phase starts [`pallet::Config::UnsignedPhase`] blocks before the
//! `next_election_prediction`, but only ends when a call to
//! [`pallet::Config::ElectionProvider::elect`] happens.
//! `next_election_prediction`, but only ends when a call to [`ElectionProvider::elect`] happens.
//!
//! > Given this, it is rather important for the user of this pallet to ensure it alwasy terminates
//! > Given this, it is rather important for the user of this pallet to ensure it always terminates
//! election via `elect` before requesting a new one.
//!
//! Each of the phases can be disabled by essentially setting their length to zero. If both phases
Expand Down Expand Up @@ -120,7 +119,7 @@
//!
//! 0. **all** of the used indices must be correct.
//! 1. present *exactly* correct number of winners.
//! 2. any assignment is checked to match with [`Snapshot::voters`].
//! 2. any assignment is checked to match with [`RoundSnapshot::voters`].
//! 3. the claimed score is valid, based on the fixed point arithmetic accuracy.
//!
//! ## Accuracy
Expand Down Expand Up @@ -163,14 +162,15 @@
//!
//! **Recursive Fallback**: Currently, the fallback is a separate enum. A different and fancier way
//! of doing this would be to have the fallback be another
//! [`sp_election_provider::ElectionProvider`]. In this case, this pallet can even have the on-chain
//! [`sp_election_providers::ElectionProvider`]. In this case, this pallet can even have the on-chain
//! election provider as fallback, or special _noop_ fallback that simply returns an error, thus
//! replicating [`FallbackStrategy::Nothing`].
//!
//! **Score based on size**: We should always prioritize small solutions over bigger ones, if there
//! is a tie. Even more harsh should be to enforce the bound of the `reduce` algorithm.

use crate::onchain::OnChainSequentialPhragmen;
#![cfg_attr(not(feature = "std"), no_std)]

use codec::{Decode, Encode, HasCompact};
use frame_support::{
dispatch::DispatchResultWithPostInfo,
Expand All @@ -179,7 +179,7 @@ use frame_support::{
weights::Weight,
};
use frame_system::{ensure_none, ensure_signed, offchain::SendTransactionTypes};
use sp_election_providers::{ElectionDataProvider, ElectionProvider};
use sp_election_providers::{ElectionDataProvider, ElectionProvider, onchain};
use sp_npos_elections::{
assignment_ratio_to_staked_normalized, is_score_better, CompactSolution, ElectionScore,
EvaluateSupport, ExtendedBalance, PerThing128, Supports, VoteWeight,
Expand All @@ -191,7 +191,7 @@ use sp_runtime::{
},
DispatchError, InnerOf, PerThing, Perbill, RuntimeDebug, SaturatedConversion,
};
use sp_std::{convert::TryInto, prelude::*};
use sp_std::prelude::*;
use sp_arithmetic::{
UpperOf,
traits::{Zero, CheckedAdd},
Expand All @@ -204,6 +204,14 @@ mod mock;
#[macro_use]
pub(crate) mod macros;

const LOG_TARGET: &'static str = "election-provider";

// for the helper macros
#[doc(hidden)]
pub use sp_runtime::traits::UniqueSaturatedInto;
#[doc(hidden)]
pub use sp_std::convert::TryInto;

pub mod signed;
pub mod unsigned;
pub mod weights;
Expand Down Expand Up @@ -236,7 +244,7 @@ struct OnChainConfig<T: Config>(sp_std::marker::PhantomData<T>)
where
ExtendedBalance: From<InnerOf<CompactAccuracyOf<T>>>,
ExtendedBalance: From<InnerOf<OnChainAccuracyOf<T>>>;
impl<T: Config> crate::onchain::Config for OnChainConfig<T>
impl<T: Config> onchain::Config for OnChainConfig<T>
where
ExtendedBalance: From<InnerOf<CompactAccuracyOf<T>>>,
ExtendedBalance: From<InnerOf<OnChainAccuracyOf<T>>>,
Expand Down Expand Up @@ -429,7 +437,7 @@ pub enum ElectionError {
/// A feasibility error.
Feasibility(FeasibilityError),
/// An error in the on-chain fallback.
OnChainFallback(crate::onchain::Error),
OnChainFallback(onchain::Error),
/// No fallback is configured
NoFallbackConfigured,
/// An internal error in the NPoS elections crate.
Expand All @@ -442,8 +450,8 @@ pub enum ElectionError {
PoolSubmissionFailed,
}

impl From<crate::onchain::Error> for ElectionError {
fn from(e: crate::onchain::Error) -> Self {
impl From<onchain::Error> for ElectionError {
fn from(e: onchain::Error) -> Self {
ElectionError::OnChainFallback(e)
}
}
Expand Down Expand Up @@ -726,7 +734,7 @@ pub mod pallet {

/// Submit a solution for the unsigned phase.
///
/// The dispatch origin fo this call must be __signed__.
/// The dispatch origin fo this call must be __none__.
///
/// This submission is checked on the fly, thus it is likely yo be more limited and smaller.
/// Moreover, this unsigned solution is only validated when submitted to the pool from the
Expand Down Expand Up @@ -848,23 +856,18 @@ pub mod pallet {
log!(error, "unsigned transaction validation failed due to {:?}", err);
err
})
.map_err(dispatch_error_to_invalid)
.map(Into::into)?;
.map_err(dispatch_error_to_invalid)?;

ValidTransaction::with_tag_prefix("OffchainElection")
// The higher the score[0], the better a solution is.
.priority(
T::UnsignedPriority::get()
.saturating_add(solution.score[0].saturated_into()),
T::UnsignedPriority::get().saturating_add(solution.score[0].saturated_into()),
)
// used to deduplicate unsigned solutions: each validator should produce one
// solution per round at most, and solutions are not propagate.
.and_provides(solution.round)
// transaction should stay in the pool for the duration of the unsigned phase.
.longevity(
TryInto::<u64>::try_into(T::UnsignedPhase::get())
.unwrap_or(crate::two_phase::unsigned::DEFAULT_LONGEVITY),
)
.longevity(T::UnsignedPhase::get().saturated_into::<u64>())
// We don't propagate this. This can never the validated at a remote node.
.propagate(false)
.build()
Expand Down Expand Up @@ -949,7 +952,7 @@ where
ExtendedBalance: From<InnerOf<CompactAccuracyOf<T>>>,
ExtendedBalance: From<InnerOf<OnChainAccuracyOf<T>>>,
{
/// Logic for [`Pallet::on_initialize`] when signed phase is being opened.
/// Logic for `<Pallet as Hooks>::on_initialize` when signed phase is being opened.
///
/// This is decoupled for easy weight calculation.
pub fn on_initialize_open_signed() {
Expand All @@ -958,7 +961,7 @@ where
Self::deposit_event(Event::SignedPhaseStarted(Self::round()));
}

/// Logic for [`Pallet::on_initialize`] when unsigned phase is being opened.
/// Logic for `<Pallet as Hooks<T>>::on_initialize` when unsigned phase is being opened.
///
/// This is decoupled for easy weight calculation. Note that the default weight benchmark of
/// this function will assume an empty signed queue for `finalize_signed_phase`.
Expand Down Expand Up @@ -1147,7 +1150,7 @@ where
where
ExtendedBalance: From<<T::OnChainAccuracy as PerThing>::Inner>,
{
<OnChainSequentialPhragmen<OnChainConfig<T>> as ElectionProvider<
<onchain::OnChainSequentialPhragmen<OnChainConfig<T>> as ElectionProvider<
T::AccountId,
T::BlockNumber,
>>::elect()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that this will fetch new targets and voters from ElectionDataProvider, so it will not work on the same election data. It is fine to me though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this was questionable to me as well. Initially, I didn't do this and manually did the onchain fallback. In that case, the data was accurate, but the downside was that there was some code duplication.

So I decided to use the OnChainSequentialPhragmen, but then this one fetches its own data. It does look strange, but note that this is how current staking is also working.

I am not fully satisfied with the current state either. Ideally, I think the fallback should itself be (yet) another ElectionProvider, which is fulfilled by OnChainSequentialPhragmen, but with the current trait system we don't have the means to ensure that the other election provider is stateless. Although, we could just document that type Fallback: ElectionProvider must be sensible.

See here:
https://github.com/paritytech/substrate/pull/7319/files#diff-8aa90a5dc4d515d8a2afb5556bc1970077fc321351f228a304b722b6a193457eR163-R167

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,32 +30,32 @@ macro_rules! log {
#[macro_export]
macro_rules! voter_index_fn {
($voters:ident, $acc:ty, $t:ident) => {
|who: &$acc| -> Option<$crate::two_phase::CompactVoterIndexOf<$t>> {
|who: &$acc| -> Option<$crate::CompactVoterIndexOf<$t>> {
$voters
.iter()
.position(|(x, _, _)| x == who)
.and_then(|i| <usize as $crate::TryInto<$crate::two_phase::CompactVoterIndexOf<$t>>>::try_into(i).ok())
.and_then(|i| <usize as $crate::TryInto<$crate::CompactVoterIndexOf<$t>>>::try_into(i).ok())
}
};
}

#[macro_export]
macro_rules! target_index_fn {
($targets:ident, $acc:ty, $t:ident) => {
|who: &$acc| -> Option<$crate::two_phase::CompactTargetIndexOf<$t>> {
|who: &$acc| -> Option<$crate::CompactTargetIndexOf<$t>> {
$targets
.iter()
.position(|x| x == who)
.and_then(|i| <usize as $crate::TryInto<$crate::two_phase::CompactTargetIndexOf<$t>>>::try_into(i).ok())
.and_then(|i| <usize as $crate::TryInto<$crate::CompactTargetIndexOf<$t>>>::try_into(i).ok())
}
};
}

#[macro_export]
macro_rules! voter_at_fn {
($snap:ident, $acc:ty, $t:ident) => {
|i: $crate::two_phase::CompactVoterIndexOf<$t>| -> Option<$acc> {
<$crate::two_phase::CompactVoterIndexOf<$t> as $crate::TryInto<usize>>::try_into(i)
|i: $crate::CompactVoterIndexOf<$t>| -> Option<$acc> {
<$crate::CompactVoterIndexOf<$t> as $crate::TryInto<usize>>::try_into(i)
.ok()
.and_then(|i| $snap
.get(i)
Expand All @@ -69,8 +69,8 @@ macro_rules! voter_at_fn {
#[macro_export]
macro_rules! target_at_fn {
($snap:ident, $acc:ty, $t:ident) => {
|i: $crate::two_phase::CompactTargetIndexOf<$t>| -> Option<$acc> {
<$crate::two_phase::CompactTargetIndexOf<$t> as $crate::TryInto<usize>>::try_into(i)
|i: $crate::CompactTargetIndexOf<$t>| -> Option<$acc> {
<$crate::CompactTargetIndexOf<$t> as $crate::TryInto<usize>>::try_into(i)
.ok()
.and_then(|i| $snap
.get(i)
Expand Down
Loading