Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Dunitrust
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
Operate
Environments
Monitor
Incidents
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
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
nodes
rust
Dunitrust
Commits
19575ea4
Commit
19575ea4
authored
6 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[ref] blockchain: reduce cyclomatic complexity of local_sync()
parent
dc74c280
No related branches found
No related tags found
1 merge request
!127
Elois/fixs
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/modules/blockchain/blockchain/clippy.toml
+1
-1
1 addition, 1 deletion
lib/modules/blockchain/blockchain/clippy.toml
lib/modules/blockchain/blockchain/src/sync/mod.rs
+48
-37
48 additions, 37 deletions
lib/modules/blockchain/blockchain/src/sync/mod.rs
with
49 additions
and
38 deletions
lib/modules/blockchain/blockchain/clippy.toml
+
1
−
1
View file @
19575ea4
cyclomatic-complexity-threshold
=
41
cyclomatic-complexity-threshold
=
39
\ No newline at end of file
\ No newline at end of file
This diff is collapsed.
Click to expand it.
lib/modules/blockchain/blockchain/src/sync/mod.rs
+
48
−
37
View file @
19575ea4
...
@@ -61,19 +61,9 @@ pub enum SyncJobsMess {
...
@@ -61,19 +61,9 @@ pub enum SyncJobsMess {
End
(),
End
(),
}
}
/// Sync from local json files
/// Get json files path
pub
fn
local_sync
<
DC
:
DuniterConf
>
(
profile
:
&
str
,
conf
:
&
DC
,
sync_opts
:
SyncOpt
)
{
fn
get_json_files_path
(
source
:
Option
<
String
>
,
currency
:
Option
<
String
>
)
->
PathBuf
{
let
SyncOpt
{
if
let
Some
(
ref
path
)
=
source
{
source
,
currency
,
end
,
cautious_mode
:
cautious
,
unsafe_mode
:
verif_inner_hash
,
..
}
=
sync_opts
;
// get json_files_path
let
json_files_path
=
if
let
Some
(
ref
path
)
=
source
{
PathBuf
::
from
(
path
)
PathBuf
::
from
(
path
)
}
else
{
}
else
{
let
mut
json_chunks_path
=
match
dirs
::
config_dir
()
{
let
mut
json_chunks_path
=
match
dirs
::
config_dir
()
{
...
@@ -91,9 +81,44 @@ pub fn local_sync<DC: DuniterConf>(profile: &str, conf: &DC, sync_opts: SyncOpt)
...
@@ -91,9 +81,44 @@ pub fn local_sync<DC: DuniterConf>(profile: &str, conf: &DC, sync_opts: SyncOpt)
json_chunks_path
.push
(
currency
);
json_chunks_path
.push
(
currency
);
json_chunks_path
json_chunks_path
};
}
}
/// Get and write currency params
fn
get_and_write_currency_params
(
currency_params_db
:
&
BinDB
<
CurrencyParamsV10Datas
>
,
block_doc
:
&
BlockDocument
,
)
->
CurrencyParameters
{
if
block_doc
.number
.0
!=
0
{
fatal_error!
(
"The first block must have number equal to zero !"
);
}
else
if
block_doc
.parameters
.is_none
()
{
fatal_error!
(
"The genesis block must have parameters !"
);
}
else
{
currency_params_db
.write
(|
db
|
{
db
.0
=
block_doc
.currency
.clone
();
db
.1
=
block_doc
.parameters
.unwrap
();
})
.expect
(
"fail to write in params DB"
);
CurrencyParameters
::
from
((
block_doc
.currency
.clone
(),
block_doc
.parameters
.unwrap
()))
}
}
/// Sync from local json files
pub
fn
local_sync
<
DC
:
DuniterConf
>
(
profile
:
&
str
,
conf
:
&
DC
,
sync_opts
:
SyncOpt
)
{
let
SyncOpt
{
source
,
currency
,
end
,
cautious_mode
:
cautious
,
unsafe_mode
:
verif_inner_hash
,
..
}
=
sync_opts
;
// get json_files_path
let
json_files_path
=
get_json_files_path
(
source
,
currency
);
if
!
json_files_path
.as_path
()
.exists
()
{
if
!
json_files_path
.as_path
()
.exists
()
{
panic!
(
"F
atal
error
:
duniter json chunks folder don't exist !"
);
f
atal
_
error
!
(
"
duniter json chunks folder don't exist !"
);
}
}
// Get verification level
// Get verification level
...
@@ -119,9 +144,6 @@ pub fn local_sync<DC: DuniterConf>(profile: &str, conf: &DC, sync_opts: SyncOpt)
...
@@ -119,9 +144,6 @@ pub fn local_sync<DC: DuniterConf>(profile: &str, conf: &DC, sync_opts: SyncOpt)
};
};
let
pool
=
ThreadPool
::
new
(
nb_workers
);
let
pool
=
ThreadPool
::
new
(
nb_workers
);
//match source {
//SyncSource::LocalJsonFiles(json_files_path) => {
// json_files_path must be a directory
if
!
json_files_path
.is_dir
()
{
if
!
json_files_path
.is_dir
()
{
error!
(
"json_files_path must be a directory"
);
error!
(
"json_files_path must be a directory"
);
panic!
(
"json_files_path must be a directory"
);
panic!
(
"json_files_path must be a directory"
);
...
@@ -244,8 +266,10 @@ pub fn local_sync<DC: DuniterConf>(profile: &str, conf: &DC, sync_opts: SyncOpt)
...
@@ -244,8 +266,10 @@ pub fn local_sync<DC: DuniterConf>(profile: &str, conf: &DC, sync_opts: SyncOpt)
// Open currency_params_db
// Open currency_params_db
let
dbs_path
=
duniter_conf
::
get_blockchain_db_path
(
profile
,
&
conf
.currency
());
let
dbs_path
=
duniter_conf
::
get_blockchain_db_path
(
profile
,
&
conf
.currency
());
let
currency_params_db
=
open_file_db
::
<
CurrencyParamsV10Datas
>
(
&
dbs_path
,
"params.db"
)
let
currency_params_db
=
BinDB
::
File
(
.expect
(
"Fail to open params db"
);
open_file_db
::
<
CurrencyParamsV10Datas
>
(
&
dbs_path
,
"params.db"
)
.expect
(
"Fail to open params db"
),
);
// Apply blocks
// Apply blocks
let
mut
blocks_not_expiring
=
VecDeque
::
with_capacity
(
200_000
);
let
mut
blocks_not_expiring
=
VecDeque
::
with_capacity
(
200_000
);
...
@@ -272,23 +296,10 @@ pub fn local_sync<DC: DuniterConf>(profile: &str, conf: &DC, sync_opts: SyncOpt)
...
@@ -272,23 +296,10 @@ pub fn local_sync<DC: DuniterConf>(profile: &str, conf: &DC, sync_opts: SyncOpt)
all_verif_block_hashs_duration
+=
SystemTime
::
now
()
all_verif_block_hashs_duration
+=
SystemTime
::
now
()
.duration_since
(
verif_block_hashs_begin
)
.duration_since
(
verif_block_hashs_begin
)
.unwrap
();
.unwrap
();
// Get currency params
// Get and write currency params
if
!
get_currency_params
&&
block_doc
.number
.0
==
0
{
if
!
get_currency_params
{
if
block_doc
.parameters
.is_some
()
{
currency_params
=
get_and_write_currency_params
(
&
currency_params_db
,
&
block_doc
);
currency_params_db
.write
(|
db
|
{
db
.0
=
block_doc
.currency
.clone
();
db
.1
=
block_doc
.parameters
.unwrap
();
})
.expect
(
"fail to write in params DB"
);
currency_params
=
CurrencyParameters
::
from
((
block_doc
.currency
.clone
(),
block_doc
.parameters
.unwrap
(),
));
get_currency_params
=
true
;
get_currency_params
=
true
;
}
else
{
panic!
(
"The genesis block are None parameters !"
);
}
}
}
// Push block median_time in blocks_not_expiring
// Push block median_time in blocks_not_expiring
blocks_not_expiring
.push_back
(
block_doc
.median_time
);
blocks_not_expiring
.push_back
(
block_doc
.median_time
);
...
...
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