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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
nodes
rust
Duniter v2S
Merge requests
!105
Distance Oracle
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Distance Oracle
distance
into
master
Overview
66
Commits
15
Pipelines
76
Changes
41
Merged
Pascal Engélibert
requested to merge
distance
into
master
2 years ago
Overview
66
Commits
15
Pipelines
76
Changes
41
Expand
close
#10 (closed)
Edited
1 year ago
by
Pascal Engélibert
0
0
Merge request reports
Compare
master
version 41
f8152c2b
1 year ago
version 40
4f3ce079
1 year ago
version 39
f4d83ddc
1 year ago
version 38
0c9b0270
1 year ago
version 37
aacf2d6a
1 year ago
version 36
e2bc1620
1 year ago
version 35
b96b83dd
1 year ago
version 34
1f42850a
1 year ago
version 33
543e62b7
1 year ago
version 32
a38d6d63
1 year ago
version 31
fb26546b
1 year ago
version 30
a22eca60
1 year ago
version 29
4cca3fd7
1 year ago
version 28
af6ef24b
1 year ago
version 27
3a8f30d1
1 year ago
version 26
7554e564
1 year ago
version 25
47256e57
1 year ago
version 24
2dc0ffb8
1 year ago
version 23
75b06534
1 year ago
version 22
238413c2
1 year ago
version 21
bca4b9e2
1 year ago
version 20
d6c7e33b
1 year ago
version 19
a6469127
1 year ago
version 18
56e35456
1 year ago
version 17
b04cc3f6
1 year ago
version 16
8b5c107c
1 year ago
version 15
3d7ec21e
1 year ago
version 14
d9acc281
2 years ago
version 13
a840fd8e
2 years ago
version 12
e4509c08
2 years ago
version 11
2b9fc019
2 years ago
version 10
77efb022
2 years ago
version 9
4012f146
2 years ago
version 8
83206465
2 years ago
version 7
3ffc2f00
2 years ago
version 6
c05977f9
2 years ago
version 5
f4f998aa
2 years ago
version 4
c093337c
2 years ago
version 3
327b2ece
2 years ago
version 2
fa1291d4
2 years ago
version 1
3c9a1964
2 years ago
master (base)
and
version 25
latest version
03b858a7
15 commits,
1 year ago
version 41
f8152c2b
14 commits,
1 year ago
version 40
4f3ce079
13 commits,
1 year ago
version 39
f4d83ddc
12 commits,
1 year ago
version 38
0c9b0270
9 commits,
1 year ago
version 37
aacf2d6a
8 commits,
1 year ago
version 36
e2bc1620
7 commits,
1 year ago
version 35
b96b83dd
7 commits,
1 year ago
version 34
1f42850a
7 commits,
1 year ago
version 33
543e62b7
7 commits,
1 year ago
version 32
a38d6d63
7 commits,
1 year ago
version 31
fb26546b
7 commits,
1 year ago
version 30
a22eca60
7 commits,
1 year ago
version 29
4cca3fd7
6 commits,
1 year ago
version 28
af6ef24b
5 commits,
1 year ago
version 27
3a8f30d1
5 commits,
1 year ago
version 26
7554e564
5 commits,
1 year ago
version 25
47256e57
5 commits,
1 year ago
version 24
2dc0ffb8
4 commits,
1 year ago
version 23
75b06534
3 commits,
1 year ago
version 22
238413c2
2 commits,
1 year ago
version 21
bca4b9e2
1 commit,
1 year ago
version 20
d6c7e33b
1 commit,
1 year ago
version 19
a6469127
1 commit,
1 year ago
version 18
56e35456
1 commit,
1 year ago
version 17
b04cc3f6
1 commit,
1 year ago
version 16
8b5c107c
1 commit,
1 year ago
version 15
3d7ec21e
1 commit,
1 year ago
version 14
d9acc281
1 commit,
2 years ago
version 13
a840fd8e
1 commit,
2 years ago
version 12
e4509c08
1 commit,
2 years ago
version 11
2b9fc019
1 commit,
2 years ago
version 10
77efb022
1 commit,
2 years ago
version 9
4012f146
1 commit,
2 years ago
version 8
83206465
1 commit,
2 years ago
version 7
3ffc2f00
1 commit,
2 years ago
version 6
c05977f9
1 commit,
2 years ago
version 5
f4f998aa
1 commit,
2 years ago
version 4
c093337c
1 commit,
2 years ago
version 3
327b2ece
1 commit,
2 years ago
version 2
fa1291d4
1 commit,
2 years ago
version 1
3c9a1964
1 commit,
2 years ago
41 files
+
2307
−
414
Side-by-side
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
41
Search (e.g. *.vue) (Ctrl+P)
client/distance/src/lib.rs
0 → 100644
+
107
−
0
Options
// Copyright 2022 Axiom-Team
//
// This file is part of Substrate-Libre-Currency.
//
// Substrate-Libre-Currency is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, version 3 of the License.
//
// Substrate-Libre-Currency is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with Substrate-Libre-Currency. If not, see <https://www.gnu.org/licenses/>.
use
codec
::{
Decode
,
Encode
};
use
frame_support
::
pallet_prelude
::
*
;
use
sc_client_api
::{
ProvideUncles
,
StorageKey
,
StorageProvider
};
use
scale_info
::
TypeInfo
;
use
sp_runtime
::{
generic
::
BlockId
,
traits
::
Block
as
BlockT
,
AccountId32
};
use
std
::
path
::
PathBuf
;
type
IdtyIndex
=
u32
;
#[derive(Debug,
thiserror::Error)]
pub
enum
Error
<
B
:
BlockT
>
{
#[error(
"Could not retrieve the block hash for block id: {0:?}"
)]
NoHashForBlockId
(
BlockId
<
B
>
),
}
/// Create a new [`sp_distance::InherentDataProvider`] at the given block.
pub
fn
create_distance_inherent_data_provider
<
B
,
C
,
Backend
>
(
client
:
&
C
,
parent
:
B
::
Hash
,
distance_dir
:
PathBuf
,
owner_keys
:
&
[
sp_core
::
sr25519
::
Public
],
)
->
Result
<
sp_distance
::
InherentDataProvider
<
IdtyIndex
>
,
sc_client_api
::
blockchain
::
Error
>
where
B
:
BlockT
,
C
:
ProvideUncles
<
B
>
+
StorageProvider
<
B
,
Backend
>
,
Backend
:
sc_client_api
::
Backend
<
B
>
,
IdtyIndex
:
Decode
+
Encode
+
PartialEq
+
TypeInfo
,
{
let
&
[
owner_key
]
=
owner_keys
else
{
return
Ok
(
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
None
))
};
let
owner_key
=
sp_runtime
::
AccountId32
::
new
(
owner_key
.0
);
let
session_index
=
client
.storage
(
&
parent
,
&
StorageKey
(
frame_support
::
storage
::
storage_prefix
(
b"Session"
,
b"CurrentIndex"
)
.to_vec
(),
),
)
.expect
(
"CurrentIndex is Err"
)
.map_or
(
0
,
|
raw
|
{
u32
::
decode
(
&
mut
&
raw
.0
[
..
])
.expect
(
"cannot decode CurrentIndex"
)
});
let
published_results
=
client
.storage
(
&
parent
,
&
StorageKey
(
frame_support
::
storage
::
storage_prefix
(
b"Distance"
,
match
session_index
%
3
{
0
=>
b"StoragePublishedResults1"
,
1
=>
b"StoragePublishedResults2"
,
2
=>
b"StoragePublishedResults0"
,
_
=>
unreachable!
(
"n%3<3"
),
},
)
.to_vec
(),
),
)
?
.map_or_else
(
Default
::
default
,
|
raw
|
{
pallet_distance
::
EvaluationPool
::
<
AccountId32
,
IdtyIndex
>
::
decode
(
&
mut
&
raw
.0
[
..
])
.expect
(
"cannot decode EvaluationPool"
)
});
// Have we already published a result for this session?
if
published_results
.evaluators
.contains
(
&
owner_key
)
{
return
Ok
(
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
None
));
}
// Read evaluation result from file, if it exists
let
evaluation_result
=
match
std
::
fs
::
read
(
distance_dir
.join
(
session_index
.to_string
()))
{
Ok
(
data
)
=>
data
,
Err
(
e
)
=>
{
match
e
.kind
()
{
std
::
io
::
ErrorKind
::
NotFound
=>
{}
_
=>
{
log
::
error!
(
"Cannot read distance evaluation result file: {e:?}"
);
}
}
return
Ok
(
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
None
));
}
};
Ok
(
sp_distance
::
InherentDataProvider
::
<
IdtyIndex
>
::
new
(
Some
(
sp_distance
::
ComputationResult
::
decode
(
&
mut
evaluation_result
.as_slice
())
.unwrap
(),
)))
}
Loading