1919
2020use crate :: {
2121 types:: { PageIndex , VoterOf } ,
22- AllVoterPagesOf , Config , SolutionTargetIndexOf , SolutionVoterIndexOf , VoteWeight ,
22+ unsigned:: miner:: MinerConfig ,
23+ AllVoterPagesOf , SolutionTargetIndexOf , SolutionVoterIndexOf , VoteWeight ,
2324} ;
2425use frame_support:: { traits:: Get , BoundedVec } ;
2526use sp_runtime:: SaturatedConversion ;
@@ -35,6 +36,7 @@ macro_rules! log {
3536 } ;
3637}
3738
39+ #[ macro_export]
3840macro_rules! sublog {
3941 ( $level: tt, $sub_pallet: tt, $pattern: expr $( , $values: expr) * $( , ) ?) => {
4042 #[ cfg( not( feature = "std" ) ) ]
@@ -47,8 +49,18 @@ macro_rules! sublog {
4749 } ;
4850}
4951
52+ #[ macro_export]
53+ macro_rules! miner_log {
54+ ( $level: tt, $pattern: expr $( , $values: expr) * $( , ) ?) => {
55+ log:: $level!(
56+ target: $crate:: LOG_PREFIX ,
57+ concat!( "[⛏️miner] 🗳🗳🗳 " , $pattern) $( , $values) *
58+ )
59+ } ;
60+ }
61+
5062/// Generate an `efficient closure of voters and the page in which they live in.
51- pub fn generate_voter_page_fn < T : Config > (
63+ pub fn generate_voter_page_fn < T : MinerConfig > (
5264 paged_snapshot : & AllVoterPagesOf < T > ,
5365) -> impl Fn ( & T :: AccountId ) -> Option < PageIndex > {
5466 let mut cache: BTreeMap < T :: AccountId , PageIndex > = BTreeMap :: new ( ) ;
@@ -73,7 +85,7 @@ pub fn generate_voter_page_fn<T: Config>(
7385/// voters.
7486///
7587/// This can be used to efficiently build index getter closures.
76- pub fn generate_voter_cache < T : Config , AnyBound : Get < u32 > > (
88+ pub fn generate_voter_cache < T : MinerConfig , AnyBound : Get < u32 > > (
7789 snapshot : & BoundedVec < VoterOf < T > , AnyBound > ,
7890) -> BTreeMap < T :: AccountId , usize > {
7991 let mut cache: BTreeMap < T :: AccountId , usize > = BTreeMap :: new ( ) ;
@@ -94,7 +106,7 @@ pub fn generate_voter_cache<T: Config, AnyBound: Get<u32>>(
94106/// ## Warning
95107///
96108/// Note that this will represent the snapshot data from which the `cache` is generated.
97- pub fn voter_index_fn < T : Config > (
109+ pub fn voter_index_fn < T : MinerConfig > (
98110 cache : & BTreeMap < T :: AccountId , usize > ,
99111) -> impl Fn ( & T :: AccountId ) -> Option < SolutionVoterIndexOf < T > > + ' _ {
100112 move |who| {
@@ -108,7 +120,7 @@ pub fn voter_index_fn<T: Config>(
108120///
109121/// Same as [`voter_index_fn`] but the returned function owns all its necessary data; nothing is
110122/// borrowed.
111- pub fn voter_index_fn_owned < T : Config > (
123+ pub fn voter_index_fn_owned < T : MinerConfig > (
112124 cache : BTreeMap < T :: AccountId , usize > ,
113125) -> impl Fn ( & T :: AccountId ) -> Option < SolutionVoterIndexOf < T > > {
114126 move |who| {
@@ -123,7 +135,7 @@ pub fn voter_index_fn_owned<T: Config>(
123135/// ## Warning
124136///
125137/// Note that this will represent the snapshot data from which the `cache` is generated.
126- pub fn voter_index_fn_usize < T : Config > (
138+ pub fn voter_index_fn_usize < T : MinerConfig > (
127139 cache : & BTreeMap < T :: AccountId , usize > ,
128140) -> impl Fn ( & T :: AccountId ) -> Option < usize > + ' _ {
129141 move |who| cache. get ( who) . cloned ( )
@@ -136,7 +148,7 @@ pub fn voter_index_fn_usize<T: Config>(
136148///
137149/// Not meant to be used in production.
138150#[ cfg( test) ]
139- pub fn voter_index_fn_linear < T : Config > (
151+ pub fn voter_index_fn_linear < T : MinerConfig > (
140152 snapshot : & Vec < VoterOf < T > > ,
141153) -> impl Fn ( & T :: AccountId ) -> Option < SolutionVoterIndexOf < T > > + ' _ {
142154 move |who| {
@@ -154,7 +166,7 @@ pub fn voter_index_fn_linear<T: Config>(
154166/// Note: to the extent possible, the returned function should be cached and reused. Producing that
155167/// function requires a `O(n log n)` data transform. Each invocation of that function completes
156168/// in `O(log n)`.
157- pub fn target_index_fn < T : Config > (
169+ pub fn target_index_fn < T : MinerConfig > (
158170 snapshot : & Vec < T :: AccountId > ,
159171) -> impl Fn ( & T :: AccountId ) -> Option < SolutionTargetIndexOf < T > > + ' _ {
160172 let cache: BTreeMap < _ , _ > =
@@ -174,7 +186,7 @@ pub fn target_index_fn<T: Config>(
174186///
175187/// Not meant to be used in production.
176188#[ cfg( test) ]
177- pub fn target_index_fn_linear < T : Config > (
189+ pub fn target_index_fn_linear < T : MinerConfig > (
178190 snapshot : & Vec < T :: AccountId > ,
179191) -> impl Fn ( & T :: AccountId ) -> Option < SolutionTargetIndexOf < T > > + ' _ {
180192 move |who| {
@@ -187,7 +199,7 @@ pub fn target_index_fn_linear<T: Config>(
187199
188200/// Create a function that can map a voter index ([`SolutionVoterIndexOf`]) to the actual voter
189201/// account using a linearly indexible snapshot.
190- pub fn voter_at_fn < T : Config > (
202+ pub fn voter_at_fn < T : MinerConfig > (
191203 snapshot : & Vec < VoterOf < T > > ,
192204) -> impl Fn ( SolutionVoterIndexOf < T > ) -> Option < T :: AccountId > + ' _ {
193205 move |i| {
@@ -199,7 +211,7 @@ pub fn voter_at_fn<T: Config>(
199211
200212/// Create a function that can map a target index ([`SolutionTargetIndexOf`]) to the actual target
201213/// account using a linearly indexible snapshot.
202- pub fn target_at_fn < T : Config > (
214+ pub fn target_at_fn < T : MinerConfig > (
203215 snapshot : & Vec < T :: AccountId > ,
204216) -> impl Fn ( SolutionTargetIndexOf < T > ) -> Option < T :: AccountId > + ' _ {
205217 move |i| {
@@ -213,7 +225,7 @@ pub fn target_at_fn<T: Config>(
213225///
214226/// This is not optimized and uses a linear search.
215227#[ cfg( test) ]
216- pub fn stake_of_fn_linear < T : Config > (
228+ pub fn stake_of_fn_linear < T : MinerConfig > (
217229 snapshot : & Vec < VoterOf < T > > ,
218230) -> impl Fn ( & T :: AccountId ) -> VoteWeight + ' _ {
219231 move |who| {
@@ -231,7 +243,7 @@ pub fn stake_of_fn_linear<T: Config>(
231243///
232244/// The cache need must be derived from the same snapshot. Zero is returned if a voter is
233245/// non-existent.
234- pub fn stake_of_fn < ' a , T : Config , AnyBound : Get < u32 > > (
246+ pub fn stake_of_fn < ' a , T : MinerConfig , AnyBound : Get < u32 > > (
235247 snapshot : & ' a BoundedVec < VoterOf < T > , AnyBound > ,
236248 cache : & ' a BTreeMap < T :: AccountId , usize > ,
237249) -> impl Fn ( & T :: AccountId ) -> VoteWeight + ' a {
0 commit comments