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
effde467
Commit
effde467
authored
6 months ago
by
Hugo Trentesaux
Browse files
Options
Downloads
Patches
Plain Diff
wip fix distance oracle
parent
1ea5bce4
No related branches found
No related tags found
No related merge requests found
Pipeline
#38626
waiting for manual action
Stage: quality
Stage: build
Stage: tests
Stage: deploy
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
distance-oracle/src/api.rs
+22
-0
22 additions, 0 deletions
distance-oracle/src/api.rs
distance-oracle/src/lib.rs
+36
-8
36 additions, 8 deletions
distance-oracle/src/lib.rs
pallets/distance/src/lib.rs
+1
-1
1 addition, 1 deletion
pallets/distance/src/lib.rs
with
59 additions
and
9 deletions
distance-oracle/src/api.rs
+
22
−
0
View file @
effde467
...
@@ -40,6 +40,7 @@ pub async fn parent_hash(client: &Client) -> H256 {
...
@@ -40,6 +40,7 @@ pub async fn parent_hash(client: &Client) -> H256 {
.hash
()
.hash
()
}
}
/// get current pool index (value between 0 and 2)
pub
async
fn
current_pool_index
(
client
:
&
Client
,
parent_hash
:
H256
)
->
u32
{
pub
async
fn
current_pool_index
(
client
:
&
Client
,
parent_hash
:
H256
)
->
u32
{
client
client
.storage
()
.storage
()
...
@@ -50,6 +51,27 @@ pub async fn current_pool_index(client: &Client, parent_hash: H256) -> u32 {
...
@@ -50,6 +51,27 @@ pub async fn current_pool_index(client: &Client, parent_hash: H256) -> u32 {
.unwrap_or_default
()
.unwrap_or_default
()
}
}
/// get evaluation_period and first block of current evaluation period
// example:
// block number 1234
// evaluation period 100
// period is the one of block 1200
// return is (100, 1200)
pub
async
fn
current_period
(
client
:
&
Client
,
parent_hash
:
H256
)
->
(
u32
,
u32
)
{
let
height
:
u32
=
client
.storage
()
.at
(
parent_hash
)
.fetch
(
&
runtime
::
storage
()
.system
()
.number
())
.await
.expect
(
"Cannot fetch current pool index"
)
.unwrap_or_default
();
let
evaluation_period
:
u32
=
client
.constants
()
.at
(
&
runtime
::
constants
()
.distance
()
.evaluation_period
())
.expect
(
"Cannot get evaluation period"
);
(
evaluation_period
,
height
-
height
%
evaluation_period
)
}
pub
async
fn
current_pool
(
pub
async
fn
current_pool
(
client
:
&
Client
,
client
:
&
Client
,
parent_hash
:
H256
,
parent_hash
:
H256
,
...
...
This diff is collapsed.
Click to expand it.
distance-oracle/src/lib.rs
+
36
−
8
View file @
effde467
...
@@ -84,9 +84,14 @@ impl Default for Settings {
...
@@ -84,9 +84,14 @@ impl Default for Settings {
}
}
/// Asynchronously runs a computation using the provided client and saves the result to a file.
/// Asynchronously runs a computation using the provided client and saves the result to a file.
/// Also removes files of old evaluation results that are not needed anymore.
pub
async
fn
run_and_save
(
client
:
&
api
::
Client
,
settings
:
&
Settings
)
{
pub
async
fn
run_and_save
(
client
:
&
api
::
Client
,
settings
:
&
Settings
)
{
let
Some
((
evaluation
,
current_pool_index
,
evaluation_result_path
))
=
let
Some
(
RunReturnValue
{
run
(
client
,
settings
,
true
)
.await
evaluation
,
current_period
,
evaluation_period
,
evaluation_result_path
,
})
=
run
(
client
,
settings
,
true
)
.await
else
{
else
{
return
;
return
;
};
};
...
@@ -128,8 +133,8 @@ pub async fn run_and_save(client: &api::Client, settings: &Settings) {
...
@@ -128,8 +133,8 @@ pub async fn run_and_save(client: &api::Client, settings: &Settings) {
.flatten
()
.flatten
()
{
{
if
let
Ok
(
entry_name
)
=
entry
.file_name
()
.into_string
()
{
if
let
Ok
(
entry_name
)
=
entry
.file_name
()
.into_string
()
{
if
let
Ok
(
entry_p
ool
)
=
entry_name
.parse
::
<
isize
>
()
{
if
let
Ok
(
entry_p
eriod
)
=
entry_name
.parse
::
<
u32
>
()
{
if
current_p
ool_index
as
isize
-
entry_pool
>
3
{
if
current_p
eriod
-
entry_period
>
3
*
evaluation_period
{
files_to_remove
.push
(
entry
.path
());
files_to_remove
.push
(
entry
.path
());
}
}
}
}
...
@@ -141,18 +146,32 @@ pub async fn run_and_save(client: &api::Client, settings: &Settings) {
...
@@ -141,18 +146,32 @@ pub async fn run_and_save(client: &api::Client, settings: &Settings) {
});
});
}
}
/// run() function return value
// this struct simply replaced a struct in order to add comments and to avoid confusion
pub
struct
RunReturnValue
{
/// computation result
evaluation
:
Vec
<
sp_runtime
::
Perbill
>
,
/// current period (block number of the period beginning)
current_period
:
u32
,
/// distance evaluation period constant
evaluation_period
:
u32
,
/// file to write result
evaluation_result_path
:
PathBuf
,
}
/// Asynchronously runs a computation based on the provided client and settings.
/// Asynchronously runs a computation based on the provided client and settings.
/// Returns `Option<(evaluation, current_pool_index, evaluation_result_path)>`.
/// Returns `Option<(evaluation, current_pool_index, evaluation_result_path)>`.
pub
async
fn
run
(
pub
async
fn
run
(
client
:
&
api
::
Client
,
client
:
&
api
::
Client
,
settings
:
&
Settings
,
settings
:
&
Settings
,
handle_fs
:
bool
,
handle_fs
:
bool
,
)
->
Option
<
(
Vec
<
sp_runtime
::
Perbill
>
,
u32
,
PathBuf
)
>
{
)
->
Option
<
RunReturnValue
>
{
let
parent_hash
=
api
::
parent_hash
(
client
)
.await
;
let
parent_hash
=
api
::
parent_hash
(
client
)
.await
;
let
max_depth
=
api
::
max_referee_distance
(
client
)
.await
;
let
max_depth
=
api
::
max_referee_distance
(
client
)
.await
;
let
current_pool_index
=
api
::
current_pool_index
(
client
,
parent_hash
)
.await
;
let
current_pool_index
=
api
::
current_pool_index
(
client
,
parent_hash
)
.await
;
let
(
evaluation_period
,
current_period
)
=
api
::
current_period
(
client
,
parent_hash
)
.await
;
// Fetch the pending identities
// Fetch the pending identities
let
Some
(
evaluation_pool
)
=
api
::
current_pool
(
client
,
parent_hash
,
current_pool_index
)
.await
let
Some
(
evaluation_pool
)
=
api
::
current_pool
(
client
,
parent_hash
,
current_pool_index
)
.await
...
@@ -167,9 +186,10 @@ pub async fn run(
...
@@ -167,9 +186,10 @@ pub async fn run(
return
None
;
return
None
;
}
}
// the path is simply the block number of the evaluation
let
evaluation_result_path
=
settings
let
evaluation_result_path
=
settings
.evaluation_result_dir
.evaluation_result_dir
.join
(
(
current_p
ool_index
+
1
)
.to_string
());
.join
(
current_p
eriod
.to_string
());
if
handle_fs
{
if
handle_fs
{
// Stop if already evaluated
// Stop if already evaluated
...
@@ -189,7 +209,10 @@ pub async fn run(
...
@@ -189,7 +209,10 @@ pub async fn run(
});
});
}
}
info!
(
"Evaluating distance for pool {}"
,
current_pool_index
);
info!
(
"Evaluating distance for period starting at block {}"
,
current_period
);
let
evaluation_block
=
api
::
evaluation_block
(
client
,
parent_hash
)
.await
;
let
evaluation_block
=
api
::
evaluation_block
(
client
,
parent_hash
)
.await
;
// member idty -> issued certs
// member idty -> issued certs
...
@@ -245,7 +268,12 @@ pub async fn run(
...
@@ -245,7 +268,12 @@ pub async fn run(
.map
(|(
idty
,
_
)|
distance_rule
(
&
received_certs
,
&
referees
,
max_depth
,
*
idty
))
.map
(|(
idty
,
_
)|
distance_rule
(
&
received_certs
,
&
referees
,
max_depth
,
*
idty
))
.collect
();
.collect
();
Some
((
evaluation
,
current_pool_index
,
evaluation_result_path
))
Some
(
RunReturnValue
{
evaluation
,
current_period
,
evaluation_period
,
evaluation_result_path
,
})
}
}
fn
distance_rule_recursive
(
fn
distance_rule_recursive
(
...
...
This diff is collapsed.
Click to expand it.
pallets/distance/src/lib.rs
+
1
−
1
View file @
effde467
...
@@ -234,7 +234,7 @@ pub mod pallet {
...
@@ -234,7 +234,7 @@ pub mod pallet {
#[pallet::storage]
#[pallet::storage]
pub
(
super
)
type
DidUpdate
<
T
:
Config
>
=
StorageValue
<
_
,
bool
,
ValueQuery
>
;
pub
(
super
)
type
DidUpdate
<
T
:
Config
>
=
StorageValue
<
_
,
bool
,
ValueQuery
>
;
/// The current evaluation pool index.
/// The current evaluation pool index.
Value between 0 and 2.
#[pallet::storage]
#[pallet::storage]
#[pallet::getter(fn
current_pool_index)]
#[pallet::getter(fn
current_pool_index)]
pub
(
super
)
type
CurrentPoolIndex
<
T
:
Config
>
=
StorageValue
<
_
,
u32
,
ValueQuery
>
;
pub
(
super
)
type
CurrentPoolIndex
<
T
:
Config
>
=
StorageValue
<
_
,
u32
,
ValueQuery
>
;
...
...
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