Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
parity-bitcoin
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
parity
parity-bitcoin
Commits
dbc707dc
Commit
dbc707dc
authored
5 years ago
by
Joseph Goulden
Browse files
Options
Downloads
Patches
Plain Diff
fix: remove unnecessary copies in OrphanBlocksPool remove_blocks()
parent
7c75c535
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sync/src/synchronization_manager.rs
+1
-3
1 addition, 3 deletions
sync/src/synchronization_manager.rs
sync/src/utils/orphan_blocks_pool.rs
+16
-28
16 additions, 28 deletions
sync/src/utils/orphan_blocks_pool.rs
with
17 additions
and
31 deletions
sync/src/synchronization_manager.rs
+
1
−
3
View file @
dbc707dc
...
...
@@ -267,9 +267,7 @@ pub fn manage_unknown_orphaned_blocks(config: &ManageUnknownBlocksConfig, orphan
};
// remove unknown blocks
let
unknown_to_remove
:
Vec
<
H256
>
=
orphaned_blocks_pool
.remove_blocks
(
&
unknown_to_remove
)
.into_iter
()
.map
(|
b
|
b
.header.hash
)
.collect
();
let
unknown_to_remove
:
Vec
<
H256
>
=
orphaned_blocks_pool
.remove_blocks
(
&
unknown_to_remove
);
if
unknown_to_remove
.is_empty
()
{
None
}
else
{
Some
(
unknown_to_remove
)
}
}
...
...
This diff is collapsed.
Click to expand it.
sync/src/utils/orphan_blocks_pool.rs
+
16
−
28
View file @
dbc707dc
...
...
@@ -85,34 +85,22 @@ impl OrphanBlocksPool {
}
/// Remove blocks with given hashes + all dependent blocks
pub
fn
remove_blocks
(
&
mut
self
,
hashes
:
&
HashSet
<
H256
>
)
->
Vec
<
IndexedBlock
>
{
// TODO: excess clone
let
mut
removed
:
Vec
<
IndexedBlock
>
=
Vec
::
new
();
let
parent_orphan_keys
:
Vec
<
_
>
=
self
.orphaned_blocks
.keys
()
.cloned
()
.collect
();
for
parent_orphan_key
in
parent_orphan_keys
{
if
let
Entry
::
Occupied
(
mut
orphan_entry
)
=
self
.orphaned_blocks
.entry
(
parent_orphan_key
)
{
let
remove_entry
=
{
let
orphans
=
orphan_entry
.get_mut
();
let
orphans_keys
:
HashSet
<
H256
>
=
orphans
.keys
()
.cloned
()
.collect
();
for
orphan_to_remove
in
orphans_keys
.intersection
(
hashes
)
{
self
.unknown_blocks
.remove
(
orphan_to_remove
);
removed
.push
(
orphans
.remove
(
orphan_to_remove
)
.expect
(
"iterating by intersection of orphans keys with hashes; removing from orphans; qed"
)
);
}
orphans
.is_empty
()
};
if
remove_entry
{
orphan_entry
.remove_entry
();
}
pub
fn
remove_blocks
(
&
mut
self
,
hashes
:
&
HashSet
<
H256
>
)
->
Vec
<
H256
>
{
let
mut
removed
:
Vec
<
H256
>
=
Vec
::
new
();
self
.orphaned_blocks
.retain
(|
_
,
orphans
|
{
for
hash
in
hashes
{
orphans
.remove
(
hash
)
.map
(|
_
|
removed
.push
(
*
hash
));
}
}
!
orphans
.is_empty
()
});
for
block
in
&
removed
{
self
.unknown_blocks
.remove
(
block
);
}
// also delete all children
for
hash
in
hashes
.iter
()
{
removed
.extend
(
self
.remove_blocks_for_parent
(
hash
));
removed
.extend
(
self
.remove_blocks_for_parent
(
hash
)
.iter
()
.map
(|
block
|
block
.hash
())
);
}
removed
...
...
@@ -234,10 +222,10 @@ mod tests {
let
removed
=
pool
.remove_blocks
(
&
blocks_to_remove
);
assert_eq!
(
removed
.len
(),
4
);
assert!
(
removed
.iter
()
.any
(|
ref
b
|
b
.hash
()
==
&
b1_hash
));
assert!
(
removed
.iter
()
.any
(|
ref
b
|
b
.hash
()
==
&
b2_hash
));
assert!
(
removed
.iter
()
.any
(|
ref
b
|
b
.hash
()
==
&
b3_hash
));
assert!
(
removed
.iter
()
.any
(|
ref
b
|
b
.hash
()
==
&
b4_hash
));
assert!
(
removed
.iter
()
.any
(|
h
|
h
==
&
b1_hash
));
assert!
(
removed
.iter
()
.any
(|
h
|
h
==
&
b2_hash
));
assert!
(
removed
.iter
()
.any
(|
h
|
h
==
&
b3_hash
));
assert!
(
removed
.iter
()
.any
(|
h
|
h
==
&
b4_hash
));
assert_eq!
(
pool
.len
(),
1
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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