Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
parity
Mirrored projects
polkadot
Commits
3a95aca1
Unverified
Commit
3a95aca1
authored
Aug 31, 2020
by
Bernhard Schuster
Committed by
GitHub
Aug 31, 2020
Browse files
chore: nits that were left in bitfield dist (#1665)
parent
0c47cbba
Pipeline
#105165
passed with stages
in 19 minutes and 14 seconds
Changes
1
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
node/network/bitfield-distribution/src/lib.rs
View file @
3a95aca1
...
@@ -127,6 +127,8 @@ impl PerRelayParentData {
...
@@ -127,6 +127,8 @@ impl PerRelayParentData {
}
}
}
}
const
TARGET
:
&
'static
str
=
"bitd"
;
/// The bitfield distribution subsystem.
/// The bitfield distribution subsystem.
pub
struct
BitfieldDistribution
;
pub
struct
BitfieldDistribution
;
...
@@ -144,22 +146,22 @@ impl BitfieldDistribution {
...
@@ -144,22 +146,22 @@ impl BitfieldDistribution {
FromOverseer
::
Communication
{
FromOverseer
::
Communication
{
msg
:
BitfieldDistributionMessage
::
DistributeBitfield
(
hash
,
signed_availability
),
msg
:
BitfieldDistributionMessage
::
DistributeBitfield
(
hash
,
signed_availability
),
}
=>
{
}
=>
{
trace!
(
target
:
"bitd"
,
"Processing DistributeBitfield"
);
trace!
(
target
:
TARGET
,
"Processing DistributeBitfield"
);
handle_bitfield_distribution
(
&
mut
ctx
,
&
mut
state
,
hash
,
signed_availability
)
handle_bitfield_distribution
(
&
mut
ctx
,
&
mut
state
,
hash
,
signed_availability
)
.await
?
;
.await
?
;
}
}
FromOverseer
::
Communication
{
FromOverseer
::
Communication
{
msg
:
BitfieldDistributionMessage
::
NetworkBridgeUpdateV1
(
event
),
msg
:
BitfieldDistributionMessage
::
NetworkBridgeUpdateV1
(
event
),
}
=>
{
}
=>
{
trace!
(
target
:
"bitd"
,
"Processing NetworkMessage"
);
trace!
(
target
:
TARGET
,
"Processing NetworkMessage"
);
// a network message was received
// a network message was received
if
let
Err
(
e
)
=
handle_network_msg
(
&
mut
ctx
,
&
mut
state
,
event
)
.await
{
if
let
Err
(
e
)
=
handle_network_msg
(
&
mut
ctx
,
&
mut
state
,
event
)
.await
{
warn!
(
target
:
"bitd"
,
"Failed to handle incomming network messages: {:?}"
,
e
);
warn!
(
target
:
TARGET
,
"Failed to handle incomming network messages: {:?}"
,
e
);
}
}
}
}
FromOverseer
::
Signal
(
OverseerSignal
::
ActiveLeaves
(
ActiveLeavesUpdate
{
activated
,
deactivated
}))
=>
{
FromOverseer
::
Signal
(
OverseerSignal
::
ActiveLeaves
(
ActiveLeavesUpdate
{
activated
,
deactivated
}))
=>
{
for
relay_parent
in
activated
{
for
relay_parent
in
activated
{
trace!
(
target
:
"bitd"
,
"Start {:?}"
,
relay_parent
);
trace!
(
target
:
TARGET
,
"Start {:?}"
,
relay_parent
);
// query basic system parameters once
// query basic system parameters once
if
let
Some
((
validator_set
,
signing_context
))
=
if
let
Some
((
validator_set
,
signing_context
))
=
query_basics
(
&
mut
ctx
,
relay_parent
)
.await
?
query_basics
(
&
mut
ctx
,
relay_parent
)
.await
?
...
@@ -181,15 +183,15 @@ impl BitfieldDistribution {
...
@@ -181,15 +183,15 @@ impl BitfieldDistribution {
}
}
for
relay_parent
in
deactivated
{
for
relay_parent
in
deactivated
{
trace!
(
target
:
"bitd"
,
"Stop {:?}"
,
relay_parent
);
trace!
(
target
:
TARGET
,
"Stop {:?}"
,
relay_parent
);
// defer the cleanup to the view change
// defer the cleanup to the view change
}
}
}
}
FromOverseer
::
Signal
(
OverseerSignal
::
BlockFinalized
(
hash
))
=>
{
FromOverseer
::
Signal
(
OverseerSignal
::
BlockFinalized
(
hash
))
=>
{
trace!
(
target
:
"bitd"
,
"Block finalized {:?}"
,
hash
);
trace!
(
target
:
TARGET
,
"Block finalized {:?}"
,
hash
);
}
}
FromOverseer
::
Signal
(
OverseerSignal
::
Conclude
)
=>
{
FromOverseer
::
Signal
(
OverseerSignal
::
Conclude
)
=>
{
trace!
(
target
:
"bitd"
,
"Conclude"
);
trace!
(
target
:
TARGET
,
"Conclude"
);
return
Ok
(());
return
Ok
(());
}
}
}
}
...
@@ -206,7 +208,7 @@ async fn modify_reputation<Context>(
...
@@ -206,7 +208,7 @@ async fn modify_reputation<Context>(
where
where
Context
:
SubsystemContext
<
Message
=
BitfieldDistributionMessage
>
,
Context
:
SubsystemContext
<
Message
=
BitfieldDistributionMessage
>
,
{
{
trace!
(
target
:
"bitd"
,
"Reputation change of {:?} for peer {:?}"
,
rep
,
peer
);
trace!
(
target
:
TARGET
,
"Reputation change of {:?} for peer {:?}"
,
rep
,
peer
);
ctx
.send_message
(
AllMessages
::
NetworkBridge
(
ctx
.send_message
(
AllMessages
::
NetworkBridge
(
NetworkBridgeMessage
::
ReportPeer
(
peer
,
rep
),
NetworkBridgeMessage
::
ReportPeer
(
peer
,
rep
),
))
))
...
@@ -231,7 +233,7 @@ where
...
@@ -231,7 +233,7 @@ where
job_data
job_data
}
else
{
}
else
{
trace!
(
trace!
(
target
:
"bitd"
,
target
:
TARGET
,
"Not supposed to work on relay parent {} related data"
,
"Not supposed to work on relay parent {} related data"
,
relay_parent
relay_parent
);
);
...
@@ -240,7 +242,7 @@ where
...
@@ -240,7 +242,7 @@ where
};
};
let
validator_set
=
&
job_data
.validator_set
;
let
validator_set
=
&
job_data
.validator_set
;
if
validator_set
.is_empty
()
{
if
validator_set
.is_empty
()
{
trace!
(
target
:
"bitd"
,
"Validator set for {:?} is empty"
,
relay_parent
);
trace!
(
target
:
TARGET
,
"Validator set for {:?} is empty"
,
relay_parent
);
return
Ok
(());
return
Ok
(());
}
}
...
@@ -248,7 +250,7 @@ where
...
@@ -248,7 +250,7 @@ where
let
validator
=
if
let
Some
(
validator
)
=
validator_set
.get
(
validator_index
)
{
let
validator
=
if
let
Some
(
validator
)
=
validator_set
.get
(
validator_index
)
{
validator
.clone
()
validator
.clone
()
}
else
{
}
else
{
trace!
(
target
:
"bitd"
,
"Could not find a validator for index {}"
,
validator_index
);
trace!
(
target
:
TARGET
,
"Could not find a validator for index {}"
,
validator_index
);
return
Ok
(());
return
Ok
(());
};
};
...
@@ -308,7 +310,7 @@ where
...
@@ -308,7 +310,7 @@ where
if
interested_peers
.is_empty
()
{
if
interested_peers
.is_empty
()
{
trace!
(
trace!
(
target
:
"bitd"
,
target
:
TARGET
,
"No peers are interested in gossip for relay parent {:?}"
,
"No peers are interested in gossip for relay parent {:?}"
,
message
.relay_parent
message
.relay_parent
);
);
...
@@ -334,12 +336,12 @@ async fn process_incoming_peer_message<Context>(
...
@@ -334,12 +336,12 @@ async fn process_incoming_peer_message<Context>(
where
where
Context
:
SubsystemContext
<
Message
=
BitfieldDistributionMessage
>
,
Context
:
SubsystemContext
<
Message
=
BitfieldDistributionMessage
>
,
{
{
// we don't care about this, not part of our view
// we don't care about this, not part of our view
.
if
!
state
.view
.contains
(
&
message
.relay_parent
)
{
if
!
state
.view
.contains
(
&
message
.relay_parent
)
{
return
modify_reputation
(
ctx
,
origin
,
COST_NOT_IN_VIEW
)
.await
;
return
modify_reputation
(
ctx
,
origin
,
COST_NOT_IN_VIEW
)
.await
;
}
}
// Ignore anything the overseer did not tell this subsystem to work on
// Ignore anything the overseer did not tell this subsystem to work on
.
let
mut
job_data
=
state
.per_relay_parent
.get_mut
(
&
message
.relay_parent
);
let
mut
job_data
=
state
.per_relay_parent
.get_mut
(
&
message
.relay_parent
);
let
job_data
:
&
mut
_
=
if
let
Some
(
ref
mut
job_data
)
=
job_data
{
let
job_data
:
&
mut
_
=
if
let
Some
(
ref
mut
job_data
)
=
job_data
{
job_data
job_data
...
@@ -350,7 +352,7 @@ where
...
@@ -350,7 +352,7 @@ where
let
validator_set
=
&
job_data
.validator_set
;
let
validator_set
=
&
job_data
.validator_set
;
if
validator_set
.is_empty
()
{
if
validator_set
.is_empty
()
{
trace!
(
trace!
(
target
:
"bitd"
,
target
:
TARGET
,
"Validator set for relay parent {:?} is empty"
,
"Validator set for relay parent {:?} is empty"
,
&
message
.relay_parent
&
message
.relay_parent
);
);
...
@@ -391,7 +393,7 @@ where
...
@@ -391,7 +393,7 @@ where
// only relay_message a message of a validator once
// only relay_message a message of a validator once
if
one_per_validator
.get
(
&
validator
)
.is_some
()
{
if
one_per_validator
.get
(
&
validator
)
.is_some
()
{
trace!
(
trace!
(
target
:
"bitd"
,
target
:
TARGET
,
"Already received a message for validator at index {}"
,
"Already received a message for validator at index {}"
,
validator_index
validator_index
);
);
...
@@ -407,6 +409,7 @@ where
...
@@ -407,6 +409,7 @@ where
modify_reputation
(
ctx
,
origin
,
COST_SIGNATURE_INVALID
)
.await
modify_reputation
(
ctx
,
origin
,
COST_SIGNATURE_INVALID
)
.await
}
}
}
}
/// Deal with network bridge updates and track what needs to be tracked
/// Deal with network bridge updates and track what needs to be tracked
/// which depends on the message type received.
/// which depends on the message type received.
async
fn
handle_network_msg
<
Context
>
(
async
fn
handle_network_msg
<
Context
>
(
...
@@ -435,7 +438,7 @@ where
...
@@ -435,7 +438,7 @@ where
NetworkBridgeEvent
::
PeerMessage
(
remote
,
message
)
=>
{
NetworkBridgeEvent
::
PeerMessage
(
remote
,
message
)
=>
{
match
message
{
match
message
{
protocol_v1
::
BitfieldDistributionMessage
::
Bitfield
(
relay_parent
,
bitfield
)
=>
{
protocol_v1
::
BitfieldDistributionMessage
::
Bitfield
(
relay_parent
,
bitfield
)
=>
{
trace!
(
target
:
"bitd"
,
"Received bitfield gossip from peer {:?}"
,
&
remote
);
trace!
(
target
:
TARGET
,
"Received bitfield gossip from peer {:?}"
,
&
remote
);
let
gossiped_bitfield
=
BitfieldGossipMessage
{
let
gossiped_bitfield
=
BitfieldGossipMessage
{
relay_parent
,
relay_parent
,
signed_availability
:
bitfield
,
signed_availability
:
bitfield
,
...
@@ -455,7 +458,7 @@ fn handle_our_view_change(state: &mut ProtocolState, view: View) -> SubsystemRes
...
@@ -455,7 +458,7 @@ fn handle_our_view_change(state: &mut ProtocolState, view: View) -> SubsystemRes
for
added
in
state
.view
.difference
(
&
old_view
)
{
for
added
in
state
.view
.difference
(
&
old_view
)
{
if
!
state
.per_relay_parent
.contains_key
(
&
added
)
{
if
!
state
.per_relay_parent
.contains_key
(
&
added
)
{
warn!
(
warn!
(
target
:
"bitd"
,
target
:
TARGET
,
"Our view contains {} but the overseer never told use we should work on this"
,
"Our view contains {} but the overseer never told use we should work on this"
,
&
added
&
added
);
);
...
@@ -501,7 +504,7 @@ where
...
@@ -501,7 +504,7 @@ where
one_per_validator
one_per_validator
.into_iter
()
.into_iter
()
.filter
(
move
|(
validator
,
_message
)|
{
.filter
(
move
|(
validator
,
_message
)|
{
// ..except for the ones the peer already has
// ..except for the ones the peer already has
.
job_data
.message_from_validator_needed_by_peer
(
&
origin
,
validator
)
job_data
.message_from_validator_needed_by_peer
(
&
origin
,
validator
)
}),
}),
)
)
...
@@ -598,7 +601,7 @@ where
...
@@ -598,7 +601,7 @@ where
SigningContext
{
parent_hash
:
relay_parent
,
session_index
:
s
},
SigningContext
{
parent_hash
:
relay_parent
,
session_index
:
s
},
))),
))),
(
Err
(
e
),
_
)
|
(
_
,
Err
(
e
))
=>
{
(
Err
(
e
),
_
)
|
(
_
,
Err
(
e
))
=>
{
warn!
(
target
:
"bitd"
,
"Failed to fetch basics from runtime API: {:?}"
,
e
);
warn!
(
target
:
TARGET
,
"Failed to fetch basics from runtime API: {:?}"
,
e
);
Ok
(
None
)
Ok
(
None
)
}
}
}
}
...
...
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