Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Duniter v2S
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Monitor
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
Duniter v2S
Commits
93fa7b69
Commit
93fa7b69
authored
2 years ago
by
Cédric Moreau
Browse files
Options
Downloads
Patches
Plain Diff
wip: compilation ok (pallet_certification)
parent
2a1ae954
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
pallets/distance/src/lib.rs
+78
-81
78 additions, 81 deletions
pallets/distance/src/lib.rs
pallets/distance/src/mock.rs
+22
-22
22 additions, 22 deletions
pallets/distance/src/mock.rs
pallets/distance/src/types.rs
+2
-7
2 additions, 7 deletions
pallets/distance/src/types.rs
with
102 additions
and
110 deletions
pallets/distance/src/lib.rs
+
78
−
81
View file @
93fa7b69
...
...
@@ -60,7 +60,7 @@ pub mod pallet {
pub
trait
Config
<
I
:
'static
=
()
>
:
frame_system
::
Config
+
pallet_authorship
::
Config
//
+ pallet_certification::Config<I, IdtyIndex = IdtyIndex>
+
pallet_certification
::
Config
<
I
,
IdtyIndex
=
IdtyIndex
>
+
pallet_identity
::
Config
<
IdtyIndex
=
IdtyIndex
>
+
pallet_session
::
Config
{
...
...
@@ -91,7 +91,7 @@ pub mod pallet {
_
,
EvaluationPool
<
<
T
as
frame_system
::
Config
>
::
AccountId
,
//
<T as pallet_certification::Config<I>>::IdtyIndex,
<
T
as
pallet_certification
::
Config
<
I
>>
::
IdtyIndex
,
<
T
as
Config
<
I
>>
::
MaxEvaluationsPerSession
,
<
T
as
Config
<
I
>>
::
MaxEvaluatorsPerSession
,
>
,
...
...
@@ -103,7 +103,7 @@ pub mod pallet {
_
,
EvaluationPool
<
<
T
as
frame_system
::
Config
>
::
AccountId
,
//
<T as pallet_certification::Config<I>>::IdtyIndex,
<
T
as
pallet_certification
::
Config
<
I
>>
::
IdtyIndex
,
<
T
as
Config
<
I
>>
::
MaxEvaluationsPerSession
,
<
T
as
Config
<
I
>>
::
MaxEvaluatorsPerSession
,
>
,
...
...
@@ -115,7 +115,7 @@ pub mod pallet {
_
,
EvaluationPool
<
<
T
as
frame_system
::
Config
>
::
AccountId
,
//
<T as pallet_certification::Config<I>>::IdtyIndex,
<
T
as
pallet_certification
::
Config
<
I
>>
::
IdtyIndex
,
<
T
as
Config
<
I
>>
::
MaxEvaluationsPerSession
,
<
T
as
Config
<
I
>>
::
MaxEvaluatorsPerSession
,
>
,
...
...
@@ -233,38 +233,37 @@ pub mod pallet {
!
DidUpdate
::
<
T
,
I
>
::
exists
(),
Error
::
<
T
,
I
>
::
ManyEvaluationsInBlock
,
);
Ok
(())
//
Pallet::<T, I>::mutate_current_pool(
//
pallet_session::CurrentIndex::<T>::get().wrapping_add(1),
//
|result_pool| {
//
ensure!(
//
computation_result.distances.len() == result_pool.0.len(),
//
Error::<T, I>::WrongResultLength
//
);
//
//
let author =
//
pallet_authorship::Pallet::<T>::author().ok_or(Error::<T, I>::NoAuthor)?;
//
//
if result_pool
//
.1
//
.try_insert(author)
//
.map_err(|_| Error::<T, I>::TooManyEvaluators)?
//
{
//
for (distance_value, (_identity, median_acc)) in computation_result
//
.distances
//
.into_iter()
//
.zip(result_pool.0.iter_mut())
//
{
//
median_acc.push(distance_value);
//
}
//
//
Ok(())
//
} else {
//
Err(Error::<T, I>::ManyEvaluationsByAuthor.into())
//
}
//
},
//
)
Pallet
::
<
T
,
I
>
::
mutate_current_pool
(
pallet_session
::
CurrentIndex
::
<
T
>
::
get
()
.wrapping_add
(
1
),
|
result_pool
|
{
ensure!
(
computation_result
.distances
.len
()
==
result_pool
.0
.len
(),
Error
::
<
T
,
I
>
::
WrongResultLength
);
let
author
=
pallet_authorship
::
Pallet
::
<
T
>
::
author
()
.ok_or
(
Error
::
<
T
,
I
>
::
NoAuthor
)
?
;
if
result_pool
.1
.try_insert
(
author
)
.map_err
(|
_
|
Error
::
<
T
,
I
>
::
TooManyEvaluators
)
?
{
for
(
distance_value
,
(
_identity
,
median_acc
))
in
computation_result
.distances
.into_iter
()
.zip
(
result_pool
.0
.iter_mut
())
{
median_acc
.push
(
distance_value
);
}
Ok
(())
}
else
{
Err
(
Error
::
<
T
,
I
>
::
ManyEvaluationsByAuthor
.into
())
}
},
)
}
}
...
...
@@ -273,29 +272,27 @@ pub mod pallet {
impl
<
T
:
Config
<
I
>
,
I
:
'static
>
Pallet
<
T
,
I
>
{
pub
fn
do_evaluate_distance
(
who
:
T
::
AccountId
,
idty_index
:
u64
,
// idty_index: <T as pallet_certification::Config<I>>::IdtyIndex,
idty_index
:
<
T
as
pallet_certification
::
Config
<
I
>>
::
IdtyIndex
,
)
->
Result
<
(),
DispatchError
>
{
// Pallet::<T, I>::mutate_current_pool(
// pallet_session::CurrentIndex::<T>::get(),
// |current_pool| {
// ensure!(
// current_pool.0.len()
// < (<T as Config<I>>::MaxEvaluationsPerSession::get() as usize),
// Error::<T, I>::QueueFull
// );
//
// T::Currency::reserve(&who, <T as Config<I>>::EvaluationPrice::get())?;
//
// current_pool
// .0
// .try_push((idty_index, median::MedianAcc::new()))
// .map_err(|_| Error::<T, I>::QueueFull)?;
//
// Ok(())
// },
// )
Pallet
::
<
T
,
I
>
::
mutate_current_pool
(
pallet_session
::
CurrentIndex
::
<
T
>
::
get
(),
|
current_pool
|
{
ensure!
(
current_pool
.0
.len
()
<
(
<
T
as
Config
<
I
>>
::
MaxEvaluationsPerSession
::
get
()
as
usize
),
Error
::
<
T
,
I
>
::
QueueFull
);
T
::
Currency
::
reserve
(
&
who
,
<
T
as
Config
<
I
>>
::
EvaluationPrice
::
get
())
?
;
current_pool
.0
.try_push
((
idty_index
,
median
::
MedianAcc
::
new
()))
.map_err
(|
_
|
Error
::
<
T
,
I
>
::
QueueFull
)
?
;
Ok
(())
},
)
}
}
...
...
@@ -303,27 +300,27 @@ pub mod pallet {
impl
<
T
:
Config
<
I
>
,
I
:
'static
>
Pallet
<
T
,
I
>
{
/// Mutate the evaluation pool containing the results to be applied on this session.
//
fn mutate_current_pool<
//
R,
//
F: FnOnce(
//
&mut EvaluationPool<
//
<T as frame_system::Config>::AccountId,
//
<T as pallet_certification::Config<I>>::IdtyIndex,
//
<T as Config<I>>::MaxEvaluationsPerSession,
//
<T as Config<I>>::MaxEvaluatorsPerSession,
//
>,
//
) -> R,
//
>(
//
index: SessionIndex,
//
f: F,
//
) -> R {
//
match index % 3 {
//
0 => EvaluationPool2::<T, I>::mutate(f),
//
1 => EvaluationPool0::<T, I>::mutate(f),
//
2 => EvaluationPool1::<T, I>::mutate(f),
//
_ => panic!("index % 3 < 3"),
//
}
//
}
fn
mutate_current_pool
<
R
,
F
:
FnOnce
(
&
mut
EvaluationPool
<
<
T
as
frame_system
::
Config
>
::
AccountId
,
<
T
as
pallet_certification
::
Config
<
I
>>
::
IdtyIndex
,
<
T
as
Config
<
I
>>
::
MaxEvaluationsPerSession
,
<
T
as
Config
<
I
>>
::
MaxEvaluatorsPerSession
,
>
,
)
->
R
,
>
(
index
:
SessionIndex
,
f
:
F
,
)
->
R
{
match
index
%
3
{
0
=>
EvaluationPool2
::
<
T
,
I
>
::
mutate
(
f
),
1
=>
EvaluationPool0
::
<
T
,
I
>
::
mutate
(
f
),
2
=>
EvaluationPool1
::
<
T
,
I
>
::
mutate
(
f
),
_
=>
panic!
(
"index % 3 < 3"
),
}
}
/// Take the evaluation pool containing the results to be applied on this session.
#[allow(clippy::type_complexity)]
...
...
@@ -331,7 +328,7 @@ pub mod pallet {
index
:
SessionIndex
,
)
->
EvaluationPool
<
<
T
as
frame_system
::
Config
>
::
AccountId
,
//
<T as pallet_certification::Config<I>>::IdtyIndex,
<
T
as
pallet_certification
::
Config
<
I
>>
::
IdtyIndex
,
<
T
as
Config
<
I
>>
::
MaxEvaluationsPerSession
,
<
T
as
Config
<
I
>>
::
MaxEvaluatorsPerSession
,
>
{
...
...
@@ -353,7 +350,7 @@ pub mod pallet {
#[allow(clippy::type_complexity)]
let
current_pool
:
EvaluationPool
<
<
T
as
frame_system
::
Config
>
::
AccountId
,
//
<T as pallet_certification::Config<I>>::IdtyIndex,
<
T
as
pallet_certification
::
Config
<
I
>>
::
IdtyIndex
,
<
T
as
Config
<
I
>>
::
MaxEvaluationsPerSession
,
<
T
as
Config
<
I
>>
::
MaxEvaluatorsPerSession
,
>
=
Pallet
::
<
T
,
I
>
::
take_current_pool
(
index
);
...
...
This diff is collapsed.
Click to expand it.
pallets/distance/src/mock.rs
+
22
−
22
View file @
93fa7b69
...
...
@@ -56,7 +56,7 @@ frame_support::construct_runtime!(
Authorship
:
pallet_authorship
::{
Pallet
,
Call
,
Storage
},
Distance
:
pallet_distance
::{
Pallet
,
Call
,
Config
<
T
>
,
Storage
,
Event
<
T
>
},
Identity
:
pallet_identity
::{
Pallet
,
Call
,
Config
<
T
>
,
Storage
,
Event
<
T
>
},
//
Cert: pallet_certification::{Pallet, Call, Config<T>, Storage, Event<T>},
Cert
:
pallet_certification
::{
Pallet
,
Call
,
Config
<
T
>
,
Storage
,
Event
<
T
>
},
AuthorityMembers
:
pallet_authority_members
::{
Pallet
,
Call
,
Storage
,
Config
<
T
>
,
Event
<
T
>
},
}
);
...
...
@@ -182,26 +182,26 @@ impl pallet_identity::Config for Test {
type
WeightInfo
=
();
}
//
parameter_types! {
//
pub const MaxByIssuer: u32 = 4;
//
pub const MinReceivedCertToBeAbleToIssueCert: u32 = 2;
//
pub const CertPeriod: u64 = 2;
//
pub const ValidityPeriod: u64 = 10;
//
}
//
//
impl pallet_certification::Config for Test {
//
type CertPeriod = CertPeriod;
//
type IdtyIndex = IdtyIndex;
//
type OwnerKeyOf = sp_runtime::traits::ConvertInto;
//
type CheckCertAllowed = ();
//
type MaxByIssuer = MaxByIssuer;
//
type MinReceivedCertToBeAbleToIssueCert = MinReceivedCertToBeAbleToIssueCert;
//
type OnNewcert = ();
//
type OnRemovedCert = ();
//
type RuntimeEvent = RuntimeEvent;
//
type WeightInfo = ();
//
type ValidityPeriod = ValidityPeriod;
//
}
parameter_types!
{
pub
const
MaxByIssuer
:
u32
=
4
;
pub
const
MinReceivedCertToBeAbleToIssueCert
:
u32
=
2
;
pub
const
CertPeriod
:
u64
=
2
;
pub
const
ValidityPeriod
:
u64
=
10
;
}
impl
pallet_certification
::
Config
for
Test
{
type
CertPeriod
=
CertPeriod
;
type
IdtyIndex
=
IdtyIndex
;
type
OwnerKeyOf
=
sp_runtime
::
traits
::
ConvertInto
;
type
CheckCertAllowed
=
();
type
MaxByIssuer
=
MaxByIssuer
;
type
MinReceivedCertToBeAbleToIssueCert
=
MinReceivedCertToBeAbleToIssueCert
;
type
OnNewcert
=
();
type
OnRemovedCert
=
();
type
RuntimeEvent
=
RuntimeEvent
;
type
WeightInfo
=
();
type
ValidityPeriod
=
ValidityPeriod
;
}
impl
pallet_authorship
::
Config
for
Test
{
type
FindAuthor
=
();
...
...
@@ -248,7 +248,7 @@ pub fn new_test_ext() -> sp_io::TestExternalities {
GenesisConfig
{
system
:
SystemConfig
::
default
(),
authority_members
:
pallet_authority_members
::
GenesisConfig
::
default
(),
//
cert: pallet_certification::GenesisConfig::default(),
cert
:
pallet_certification
::
GenesisConfig
::
default
(),
distance
:
pallet_distance
::
GenesisConfig
::
default
(),
identity
:
pallet_identity
::
GenesisConfig
::
default
(),
session
:
pallet_session
::
GenesisConfig
::
default
(),
...
...
This diff is collapsed.
Click to expand it.
pallets/distance/src/types.rs
+
2
−
7
View file @
93fa7b69
...
...
@@ -30,13 +30,8 @@ pub enum DistanceStatus {
Valid
,
}
pub
type
EvaluationPool
<
AccountId
,
// IdtyIndex,
MaxEvaluationsPerSession
,
MaxEvaluatorsPerSession
,
>
=
(
BoundedVec
<
(
u64
,
MedianAcc
<
Perbill
,
MaxEvaluatorsPerSession
>
),
MaxEvaluationsPerSession
>
,
pub
type
EvaluationPool
<
AccountId
,
IdtyIndex
,
MaxEvaluationsPerSession
,
MaxEvaluatorsPerSession
>
=
(
BoundedVec
<
(
IdtyIndex
,
MedianAcc
<
Perbill
,
MaxEvaluatorsPerSession
>
),
MaxEvaluationsPerSession
>
,
BoundedBTreeSet
<
AccountId
,
MaxEvaluatorsPerSession
>
,
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment