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
cd9e08f8
Commit
cd9e08f8
authored
5 years ago
by
Joseph Goulden
Browse files
Options
Downloads
Patches
Plain Diff
fix: copy less hashes when removing invalid txs during sync
parent
7c75c535
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
sync/src/synchronization_chain.rs
+18
-29
18 additions, 29 deletions
sync/src/synchronization_chain.rs
with
18 additions
and
29 deletions
sync/src/synchronization_chain.rs
+
18
−
29
View file @
cd9e08f8
...
...
@@ -265,7 +265,7 @@ impl Chain {
/// Get block header by hash
pub
fn
block_header_by_hash
(
&
self
,
hash
:
&
H256
)
->
Option
<
IndexedBlockHeader
>
{
if
let
Some
(
header
)
=
self
.storage
.block_header
(
storage
::
BlockRef
::
Hash
(
hash
.clone
()
))
{
if
let
Some
(
header
)
=
self
.storage
.block_header
(
storage
::
BlockRef
::
Hash
(
*
hash
))
{
return
Some
(
header
);
}
self
.headers_chain
.by_hash
(
hash
)
...
...
@@ -275,7 +275,7 @@ impl Chain {
pub
fn
block_state
(
&
self
,
hash
:
&
H256
)
->
BlockState
{
match
self
.hash_chain
.contains_in
(
hash
)
{
Some
(
queue_index
)
=>
BlockState
::
from_queue_index
(
queue_index
),
None
=>
if
self
.storage
.contains_block
(
storage
::
BlockRef
::
Hash
(
hash
.clone
()
))
{
None
=>
if
self
.storage
.contains_block
(
storage
::
BlockRef
::
Hash
(
*
hash
))
{
BlockState
::
Stored
}
else
if
self
.dead_end_blocks
.contains
(
hash
)
{
BlockState
::
DeadEnd
...
...
@@ -340,7 +340,7 @@ impl Chain {
/// Mark this block as dead end, so these tasks won't be synchronized
pub
fn
mark_dead_end_block
(
&
mut
self
,
hash
:
&
H256
)
{
self
.dead_end_blocks
.insert
(
hash
.clone
()
);
self
.dead_end_blocks
.insert
(
*
hash
);
}
/// Insert new best block to storage
...
...
@@ -382,7 +382,7 @@ impl Chain {
// no transactions to reverify, because we have just appended new transactions to the blockchain
Ok
(
BlockInsertionResult
{
canonized_blocks_hashes
:
vec!
[
block
.hash
()
.clone
()
],
canonized_blocks_hashes
:
vec!
[
*
block
.hash
()],
transactions_to_reverify
:
Vec
::
new
(),
})
},
...
...
@@ -438,7 +438,7 @@ impl Chain {
.collect
();
self
.verifying_transactions
.clear
();
canonized_blocks_hashes
.push
(
block
.hash
()
.clone
()
);
canonized_blocks_hashes
.push
(
*
block
.hash
());
let
result
=
BlockInsertionResult
{
canonized_blocks_hashes
:
canonized_blocks_hashes
,
...
...
@@ -517,7 +517,7 @@ impl Chain {
pub
fn
forget_block_with_children
(
&
mut
self
,
hash
:
&
H256
)
{
let
mut
removal_stack
:
VecDeque
<
H256
>
=
VecDeque
::
new
();
let
mut
removal_queue
:
VecDeque
<
H256
>
=
VecDeque
::
new
();
removal_queue
.push_back
(
hash
.clone
()
);
removal_queue
.push_back
(
*
hash
);
// remove in reverse order to minimize headers operations
while
let
Some
(
hash
)
=
removal_queue
.pop_front
()
{
...
...
@@ -568,34 +568,23 @@ impl Chain {
self
.verifying_transactions
.remove
(
hash
)
.is_some
()
}
/// Remove verifying trasaction + all dependent transactions currently verifying
/// Remove verifying tra
n
saction + all dependent transactions currently verifying
pub
fn
forget_verifying_transaction_with_children
(
&
mut
self
,
hash
:
&
H256
)
{
self
.forget_verifying_transaction
(
hash
);
// TODO: suboptimal
let
mut
queue
:
VecDeque
<
H256
>
=
VecDeque
::
new
();
queue
.push_back
(
hash
.clone
()
);
queue
.push_back
(
*
hash
);
while
let
Some
(
hash
)
=
queue
.pop_front
()
{
let
all_keys
:
Vec
<
_
>
=
self
.verifying_transactions
.keys
()
.cloned
()
.collect
();
for
h
in
all_keys
{
let
remove_verifying_transaction
=
{
if
let
Some
(
entry
)
=
self
.verifying_transactions
.get
(
&
h
)
{
if
entry
.raw.inputs
.iter
()
.any
(|
i
|
i
.previous_output.hash
==
hash
)
{
queue
.push_back
(
h
.clone
());
true
}
else
{
false
}
}
else
{
// iterating by previously read keys
unreachable!
()
}
};
if
remove_verifying_transaction
{
self
.verifying_transactions
.remove
(
&
h
);
}
let
remove
:
Vec
<
H256
>
=
self
.verifying_transactions
.iter
()
.filter
(|(
_
,
e
)|
e
.raw.inputs
.iter
()
.any
(|
i
|
i
.previous_output.hash
==
hash
))
.map
(|(
h
,
_
)|
h
.clone
())
.collect
();
for
h
in
&
remove
{
self
.verifying_transactions
.remove
(
h
);
}
queue
.extend
(
remove
);
}
}
...
...
@@ -604,7 +593,7 @@ impl Chain {
self
.verifying_transactions
.get
(
hash
)
.cloned
()
.or_else
(||
self
.memory_pool
.read
()
.read_by_hash
(
hash
)
.cloned
()
.map
(|
tx
|
IndexedTransaction
::
new
(
hash
.clone
()
,
tx
)))
.map
(|
tx
|
IndexedTransaction
::
new
(
*
hash
,
tx
)))
}
/// Insert transaction to memory pool
...
...
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