Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
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
GitLab is going to be shut down, which is unfortunate for all those who use it. More information can be found here https://github.com/paritytech/ci_cd/issues/1041
You are on a read-only GitLab instance.
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
0c4ae551
Commit
0c4ae551
authored
6 years ago
by
Arkadiy Paronyan
Committed by
Gav Wood
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Fixed common block tracking on new block announcement (#1305)
parent
71343248
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/core/network/src/sync.rs
+25
-7
25 additions, 7 deletions
substrate/core/network/src/sync.rs
with
25 additions
and
7 deletions
substrate/core/network/src/sync.rs
+
25
−
7
View file @
0c4ae551
...
...
@@ -282,8 +282,11 @@ impl<B: BlockT> ChainSync<B> {
self
.best_queued_hash
=
*
hash
;
}
// Update common blocks
for
(
_
,
peer
)
in
self
.peers
.iter_mut
()
{
trace!
(
target
:
"sync"
,
"Updating peer info ours={}, theirs={}"
,
number
,
peer
.best_number
);
for
(
n
,
peer
)
in
self
.peers
.iter_mut
()
{
if
let
PeerSyncState
::
AncestorSearch
(
_
)
=
peer
.state
{
continue
;
}
trace!
(
target
:
"sync"
,
"Updating peer {} info, ours={}, common={}, their best={}"
,
n
,
number
,
peer
.common_number
,
peer
.best_number
);
if
peer
.best_number
>=
number
{
peer
.common_number
=
number
;
peer
.common_hash
=
*
hash
;
...
...
@@ -301,22 +304,34 @@ impl<B: BlockT> ChainSync<B> {
pub
(
crate
)
fn
on_block_announce
(
&
mut
self
,
protocol
:
&
mut
Context
<
B
>
,
who
:
NodeIndex
,
hash
:
B
::
Hash
,
header
:
&
B
::
Header
)
{
let
number
=
*
header
.number
();
if
number
<=
As
::
sa
(
0
)
{
trace!
(
target
:
"sync"
,
"Ignored invalid block announcement from {}: {}"
,
who
,
hash
);
return
;
}
let
known_parent
=
self
.is_known
(
protocol
,
&
header
.parent_hash
());
let
known
=
self
.is_known
(
protocol
,
&
hash
);
if
let
Some
(
ref
mut
peer
)
=
self
.peers
.get_mut
(
&
who
)
{
if
number
>
peer
.best_number
{
// update their best block
peer
.best_number
=
number
;
peer
.best_hash
=
hash
;
}
if
number
<=
self
.best_queued_number
&&
number
>
peer
.common_number
{
if
let
PeerSyncState
::
AncestorSearch
(
_
)
=
peer
.state
{
return
;
}
if
header
.parent_hash
()
==
&
self
.best_queued_hash
||
known_parent
{
peer
.common_number
=
number
-
As
::
sa
(
1
);
}
else
if
known
{
peer
.common_number
=
number
}
}
else
{
return
;
}
if
!
self
.is_known_or
_already_downloading
(
protocol
,
&
hash
)
{
if
!
(
known
||
self
.is
_already_downloading
(
&
hash
)
)
{
let
stale
=
number
<=
self
.best_queued_number
;
if
stale
{
if
!
self
.is_known_or
_already_downloading
(
protocol
,
header
.parent_hash
())
{
if
!
(
known_parent
||
self
.is
_already_downloading
(
header
.parent_hash
())
)
{
trace!
(
target
:
"sync"
,
"Ignoring unknown stale block announce from {}: {} {:?}"
,
who
,
hash
,
header
);
}
else
{
trace!
(
target
:
"sync"
,
"Considering new stale block announced from {}: {} {:?}"
,
who
,
hash
,
header
);
...
...
@@ -331,9 +346,12 @@ impl<B: BlockT> ChainSync<B> {
}
}
fn
is_
known_or_
already_downloading
(
&
self
,
protocol
:
&
mut
Context
<
B
>
,
hash
:
&
B
::
Hash
)
->
bool
{
fn
is_already_downloading
(
&
self
,
hash
:
&
B
::
Hash
)
->
bool
{
self
.peers
.iter
()
.any
(|(
_
,
p
)|
p
.state
==
PeerSyncState
::
DownloadingStale
(
*
hash
))
||
block_status
(
&*
protocol
.client
(),
&*
self
.import_queue
,
*
hash
)
.ok
()
.map_or
(
false
,
|
s
|
s
!=
BlockStatus
::
Unknown
)
}
fn
is_known
(
&
self
,
protocol
:
&
mut
Context
<
B
>
,
hash
:
&
B
::
Hash
)
->
bool
{
block_status
(
&*
protocol
.client
(),
&*
self
.import_queue
,
*
hash
)
.ok
()
.map_or
(
false
,
|
s
|
s
!=
BlockStatus
::
Unknown
)
}
pub
(
crate
)
fn
peer_disconnected
(
&
mut
self
,
protocol
:
&
mut
Context
<
B
>
,
who
:
NodeIndex
)
{
...
...
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