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
Commits
ebf74667
Commit
ebf74667
authored
7 months ago
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
add convenient info
parent
1e1a5641
No related branches found
No related tags found
1 merge request
!280
Draft: (paused) distance result precomputation
Pipeline
#38133
failed
7 months ago
Stage: labels
Stage: quality
Stage: build
Stage: tests
Stage: deploy
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
distance-oracle/src/bin/distance_precompute.rs
+32
-19
32 additions, 19 deletions
distance-oracle/src/bin/distance_precompute.rs
with
32 additions
and
19 deletions
distance-oracle/src/bin/distance_precompute.rs
+
32
−
19
View file @
ebf74667
...
@@ -4,8 +4,12 @@ use fnv::{FnvHashMap, FnvHashSet};
...
@@ -4,8 +4,12 @@ use fnv::{FnvHashMap, FnvHashSet};
use
log
::
debug
;
use
log
::
debug
;
use
std
::{
io
::
Write
,
path
::
PathBuf
};
use
std
::{
io
::
Write
,
path
::
PathBuf
};
// computes distance result for all identities with status other than Revoked
// this script is mainly copied from distance oracle code
// this allows to have a recent estimate of the distance computation
// it adds values not necessary in distance computation but convenient to have
// it allows to have a recent estimate of the distance computation
// intended use:
// - compute distance result for all identities with received certifications
// - put the result in a json file to be served publicly
use
clap
::
Parser
;
use
clap
::
Parser
;
...
@@ -20,12 +24,15 @@ struct Cli {
...
@@ -20,12 +24,15 @@ struct Cli {
log
:
log
::
LevelFilter
,
log
:
log
::
LevelFilter
,
}
}
//
//
/ computation result as it will be serialized in json
#[derive(serde::Serialize)]
#[derive(serde::Serialize)]
struct
PrecomputationResult
{
struct
PrecomputationResult
{
height
:
u32
,
block
:
sp_core
::
H256
,
block
:
sp_core
::
H256
,
referees_count
:
u32
,
member_count
:
u32
,
min_certs_for_referee
:
u32
,
results
:
FnvHashMap
<
IdtyIndex
,
u32
>
,
results
:
FnvHashMap
<
IdtyIndex
,
u32
>
,
referees
:
u32
,
}
}
#[tokio::main]
#[tokio::main]
...
@@ -38,13 +45,13 @@ async fn main() {
...
@@ -38,13 +45,13 @@ async fn main() {
.unwrap
();
.unwrap
();
let
client
=
&
distance_oracle
::
api
::
client
(
cli
.rpc_url
.clone
())
.await
;
let
client
=
&
distance_oracle
::
api
::
client
(
cli
.rpc_url
.clone
())
.await
;
let
parent_hash
=
api
::
parent_hash
(
client
)
.await
;
// get hash of recent block
let
block_hash
=
api
::
parent_hash
(
client
)
.await
;
// get hash of recent block
let
block_height
=
client
.blocks
()
.at
(
block_hash
)
.await
.unwrap
()
.number
();
let
max_depth
=
api
::
max_referee_distance
(
client
)
.await
;
// get param
let
max_depth
=
api
::
max_referee_distance
(
client
)
.await
;
// get param
let
evaluation_block
=
parent_hash
;
// get certs and member iterators
// get certs and member iterators
let
mut
certs_iter
=
api
::
cert_iter
(
client
,
evaluation_
block
)
.await
;
let
mut
certs_iter
=
api
::
cert_iter
(
client
,
block
_hash
)
.await
;
let
mut
members_iter
=
api
::
member_iter
(
client
,
evaluation_
block
)
.await
;
let
mut
members_iter
=
api
::
member_iter
(
client
,
block
_hash
)
.await
;
// initialize hashmaps
// initialize hashmaps
// member idty -> issued certs count (will only retain referees)
// member idty -> issued certs count (will only retain referees)
...
@@ -61,9 +68,10 @@ async fn main() {
...
@@ -61,9 +68,10 @@ async fn main() {
{
{
members
.insert
(
member_idty
,
0
);
members
.insert
(
member_idty
,
0
);
}
}
let
member_count
=
members
.len
();
// compute certification threshold as a function of the total member count
// compute certification threshold as a function of the total member count
let
min_certs_for_referee
=
(
member
s
.len
()
as
f32
)
.powf
(
1.
/
(
max_depth
as
f32
))
.ceil
()
as
u32
;
let
min_certs_for_referee
=
(
member
_count
as
f32
)
.powf
(
1.
/
(
max_depth
as
f32
))
.ceil
()
as
u32
;
// collect certifications and updates members map at the same time
// collect certifications and updates members map at the same time
while
let
Some
((
receiver
,
issuers
))
=
certs_iter
while
let
Some
((
receiver
,
issuers
))
=
certs_iter
...
@@ -94,32 +102,37 @@ async fn main() {
...
@@ -94,32 +102,37 @@ async fn main() {
// Only retain referees
// Only retain referees
members
.retain
(|
_idty
,
issued_certs
|
*
issued_certs
>=
min_certs_for_referee
);
members
.retain
(|
_idty
,
issued_certs
|
*
issued_certs
>=
min_certs_for_referee
);
let
referees
=
members
;
let
referees
=
members
;
let
referees_count
=
referees
.len
();
// initialize map of distance results
// initialize map of distance results
let
mut
results
=
FnvHashMap
::
<
IdtyIndex
,
u32
>
::
default
();
let
mut
results
=
FnvHashMap
::
<
IdtyIndex
,
u32
>
::
default
();
// compute all distances
// compute all distances
(optimization: parallel)
received_certs
.keys
()
.
into_iter
()
.
for_each
(|
idty
|
{
received_certs
.keys
()
.for_each
(|
idty
|
{
results
.insert
(
results
.insert
(
*
idty
,
*
idty
,
distance_rule
(
&
received_certs
,
&
referees
,
max_depth
,
*
idty
)
as
u32
,
distance_rule
(
&
received_certs
,
&
referees
,
max_depth
,
*
idty
)
as
u32
,
);
);
});
});
//
structure
//
put results in a struct for serialization
let
precomputation_result
=
PrecomputationResult
{
let
precomputation_result
=
PrecomputationResult
{
block
:
evaluation_block
,
height
:
block_height
,
results
:
results
,
block
:
block_hash
,
referees
:
referees
.len
()
as
u32
,
min_certs_for_referee
,
referees_count
:
referees_count
as
u32
,
member_count
:
member_count
as
u32
,
results
,
};
};
// ---- SAVE
// ---- SAVE
let
evaluation_result_path
=
const
FILENAME
:
&
str
=
"latest_distance.json"
;
Into
::
<
PathBuf
>
::
into
(
cli
.evaluation_result_dir
)
.join
(
"todo-block-number"
.to_string
()
);
let
evaluation_result_path
=
Into
::
<
PathBuf
>
::
into
(
cli
.evaluation_result_dir
)
.join
(
FILENAME
);
debug!
(
"Saving distance evaluation result to file `{evaluation_result_path:?}`"
);
debug!
(
"Saving distance evaluation result to file `{evaluation_result_path:?}`"
);
let
mut
evaluation_result_file
=
std
::
fs
::
OpenOptions
::
new
()
let
mut
evaluation_result_file
=
std
::
fs
::
OpenOptions
::
new
()
.write
(
true
)
.write
(
true
)
.create_new
(
true
)
.create
(
true
)
.truncate
(
true
)
.open
(
&
evaluation_result_path
)
.open
(
&
evaluation_result_path
)
.unwrap_or_else
(|
e
|
{
.unwrap_or_else
(|
e
|
{
panic!
(
panic!
(
...
@@ -137,7 +150,7 @@ async fn main() {
...
@@ -137,7 +150,7 @@ async fn main() {
});
});
}
}
// alternative function which returns number of reached referees
// alternative function which returns number of reached referees
instead of percentage
fn
distance_rule
(
fn
distance_rule
(
received_certs
:
&
FnvHashMap
<
IdtyIndex
,
Vec
<
IdtyIndex
>>
,
received_certs
:
&
FnvHashMap
<
IdtyIndex
,
Vec
<
IdtyIndex
>>
,
referees
:
&
FnvHashMap
<
IdtyIndex
,
u32
>
,
referees
:
&
FnvHashMap
<
IdtyIndex
,
u32
>
,
...
...
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