Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
parity-bitcoin
Commits
e4cdea3b
Unverified
Commit
e4cdea3b
authored
Dec 30, 2019
by
Svyatoslav Nikolsky
Committed by
GitHub
Dec 30, 2019
Browse files
Merge pull request #577 from JosephGoulden/optimise_forget_transactions
fix: copy less hashes when removing invalid txs during sync
parents
43935522
cd9e08f8
Pipeline
#72950
failed with stages
in 2 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
sync/src/synchronization_chain.rs
View file @
e4cdea3b
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
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!
Cancel
Please
register
or
sign in
to comment