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
40cd5b16
Commit
40cd5b16
authored
5 years ago
by
Éloïs
Browse files
Options
Downloads
Patches
Plain Diff
[fix] bc-dal: fork tree must be resistant to light data corruption
parent
0130e0cb
No related branches found
No related tags found
1 merge request
!206
[fix] bc-dal: fork tree must be resistant to light data corruption
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs
+25
-20
25 additions, 20 deletions
...dules/blockchain/blockchain-dal/src/entities/fork_tree.rs
lib/modules/blockchain/blockchain/src/dbex.rs
+9
-0
9 additions, 0 deletions
lib/modules/blockchain/blockchain/src/dbex.rs
with
34 additions
and
20 deletions
lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs
+
25
−
20
View file @
40cd5b16
...
...
@@ -265,11 +265,11 @@ impl ForkTree {
/// Get fork branch
pub
fn
get_fork_branch
(
&
self
,
node_id
:
TreeNodeId
)
->
Vec
<
Blockstamp
>
{
let
mut
branch
=
Vec
::
with_capacity
(
self
.max_depth
);
let
node
=
self
.
get_ref_node
(
node_id
);
if
let
Some
(
Some
(
ref
node
))
=
self
.
nodes
.get
(
node_id
.0
)
{
branch
.push
(
node
.data
);
if
let
Some
(
parent_id
)
=
node
.parent
{
let
mut
parent
=
self
.
get_ref_node
(
parent_id
);
if
let
Some
(
Some
(
mut
parent
))
=
self
.
nodes
.get
(
parent_id
.0
)
.cloned
()
{
while
!
self
.main_branch
.contains_key
(
&
parent
.data.id
)
||
self
.get_main_branch_block_hash
(
parent
.data.id
)
...
...
@@ -279,15 +279,19 @@ impl ForkTree {
branch
.push
(
parent
.data
);
if
let
Some
(
parent_id
)
=
parent
.parent
{
parent
=
self
.get_ref_node
(
parent_id
);
parent
=
self
.get_ref_node
(
parent_id
)
.clone
()
;
}
else
{
break
;
}
}
}
}
branch
.reverse
();
branch
}
else
{
vec!
[]
}
}
/// Modify the main branch (function to call after a successful roolback)
pub
fn
change_main_branch
(
...
...
@@ -417,6 +421,7 @@ impl ForkTree {
// Remove root node
self
.nodes
[
root_node_id
.0
]
=
None
;
self
.sheets
.remove
(
&
root_node_id
);
self
.root
=
Some
(
root_node_main_child_id
);
}
...
...
This diff is collapsed.
Click to expand it.
lib/modules/blockchain/blockchain/src/dbex.rs
+
9
−
0
View file @
40cd5b16
...
...
@@ -178,8 +178,17 @@ pub fn dbex_fork_tree(profile_path: PathBuf, _csv: bool) {
.read
(|
fork_tree
|
fork_tree
.clone
())
.expect
(
"Fail to read fork tree DB !"
);
// Print all sheets
println!
(
"-----------------------------------"
);
println!
(
"sheets={:?}"
,
fork_tree
.get_sheets
());
println!
(
"-----------------------------------"
);
// Print all fork branches
for
(
tree_node_id
,
blockstamp
)
in
fork_tree
.get_sheets
()
{
debug!
(
"fork_tree.get_fork_branch({:?}, {})"
,
tree_node_id
,
blockstamp
);
let
branch
=
fork_tree
.get_fork_branch
(
tree_node_id
);
if
!
branch
.is_empty
()
{
println!
(
"Fork branch #{}:"
,
blockstamp
);
...
...
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