Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
polkadot-sdk
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
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
Show more breadcrumbs
parity
Mirrored projects
polkadot-sdk
Commits
70a30a97
Commit
70a30a97
authored
5 years ago
by
Bastian Köcher
Committed by
GitHub
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Make sure we send collators its role on connect (#991)
parent
9cd8216d
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
polkadot/network/src/protocol/mod.rs
+9
-3
9 additions, 3 deletions
polkadot/network/src/protocol/mod.rs
polkadot/network/src/protocol/tests.rs
+31
-3
31 additions, 3 deletions
polkadot/network/src/protocol/tests.rs
with
40 additions
and
6 deletions
polkadot/network/src/protocol/mod.rs
+
9
−
3
View file @
70a30a97
...
...
@@ -335,9 +335,15 @@ enum CollatorState {
impl
CollatorState
{
fn
send_key
<
F
:
FnMut
(
Message
)
>
(
&
mut
self
,
key
:
ValidatorId
,
mut
f
:
F
)
{
f
(
Message
::
ValidatorId
(
key
));
if
let
CollatorState
::
RolePending
(
role
)
=
*
self
{
f
(
Message
::
CollatorRole
(
role
));
*
self
=
CollatorState
::
Primed
(
Some
(
role
));
match
self
{
CollatorState
::
RolePending
(
role
)
=>
{
f
(
Message
::
CollatorRole
(
*
role
));
*
self
=
CollatorState
::
Primed
(
Some
(
*
role
));
},
CollatorState
::
Fresh
=>
{
*
self
=
CollatorState
::
Primed
(
None
);
},
CollatorState
::
Primed
(
_
)
=>
{},
}
}
...
...
This diff is collapsed.
Click to expand it.
polkadot/network/src/protocol/tests.rs
+
31
−
3
View file @
70a30a97
...
...
@@ -579,7 +579,7 @@ fn fetches_pov_block_from_gossip() {
}
#[test]
fn
validator_sends_key_to_collator_on_status
()
{
fn
validator_sends_key_
and_role_
to_collator_on_status
()
{
let
(
service
,
_gossip
,
mut
pool
,
worker_task
)
=
test_setup
(
Config
{
collating_for
:
None
});
let
peer
=
PeerId
::
random
();
...
...
@@ -602,7 +602,35 @@ fn validator_sends_key_to_collator_on_status() {
});
let
expected_msg
=
Message
::
ValidatorId
(
validator_id
.clone
());
assert!
(
service
.network_service.recorded
.lock
()
.notifications
.iter
()
.
any
(|(
p
,
notification
)|
{
let
validator_id_pos
=
service
.network_service.recorded
.lock
()
.notifications
.iter
()
.
position
(|(
p
,
notification
)|
{
peer
==
*
p
&&
*
notification
==
expected_msg
}));
});
let
expected_msg
=
Message
::
CollatorRole
(
CollatorRole
::
Primary
);
let
collator_role_pos
=
service
.network_service.recorded
.lock
()
.notifications
.iter
()
.position
(|(
p
,
notification
)|
{
peer
==
*
p
&&
*
notification
==
expected_msg
});
assert!
(
validator_id_pos
<
collator_role_pos
);
}
#[test]
fn
collator_state_send_key_updates_state_correctly
()
{
let
mut
state
=
CollatorState
::
Fresh
;
state
.send_key
(
Sr25519Keyring
::
Alice
.public
()
.into
(),
|
_
|
{});
assert!
(
matches!
(
state
,
CollatorState
::
Primed
(
None
)));
let
mut
state
=
CollatorState
::
RolePending
(
CollatorRole
::
Primary
);
let
mut
counter
=
0
;
state
.send_key
(
Sr25519Keyring
::
Alice
.public
()
.into
(),
|
msg
|
{
match
(
counter
,
msg
)
{
(
0
,
Message
::
ValidatorId
(
_
))
=>
{
counter
+=
1
;
},
(
1
,
Message
::
CollatorRole
(
CollatorRole
::
Primary
))
=>
{},
err
@
_
=>
panic!
(
"Unexpected message: {:?}"
,
err
),
}
});
assert!
(
matches!
(
state
,
CollatorState
::
Primed
(
Some
(
CollatorRole
::
Primary
))));
}
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