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
587ea254
Commit
587ea254
authored
3 years ago
by
Roman Proskuryakov
Committed by
GitHub
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Refactor code a little bit (#8932)
parent
6d13520d
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
substrate/client/network/src/block_request_handler.rs
+7
-11
7 additions, 11 deletions
substrate/client/network/src/block_request_handler.rs
with
7 additions
and
11 deletions
substrate/client/network/src/block_request_handler.rs
+
7
−
11
View file @
587ea254
...
...
@@ -46,7 +46,7 @@ mod rep {
use
super
::
ReputationChange
as
Rep
;
/// Reputation change when a peer sent us the same request multiple times.
pub
const
SAME_REQUEST
:
Rep
=
Rep
::
new
(
i32
::
min_value
(),
"Same block request multiple times"
);
pub
const
SAME_REQUEST
:
Rep
=
Rep
::
new
_fatal
(
"Same block request multiple times"
);
}
/// Generates a [`ProtocolConfig`] for the block request protocol, refusing incoming requests.
...
...
@@ -65,11 +65,7 @@ pub fn generate_protocol_config(protocol_id: &ProtocolId) -> ProtocolConfig {
// Visibility `pub(crate)` to allow `crate::light_client_requests::sender` to generate block request
// protocol name and send block requests.
pub
(
crate
)
fn
generate_protocol_name
(
protocol_id
:
&
ProtocolId
)
->
String
{
let
mut
s
=
String
::
new
();
s
.push_str
(
"/"
);
s
.push_str
(
protocol_id
.as_ref
());
s
.push_str
(
"/sync/2"
);
s
format!
(
"/{}/sync/2"
,
protocol_id
.as_ref
())
}
/// The key of [`BlockRequestHandler::seen_requests`].
...
...
@@ -192,7 +188,7 @@ impl<B: BlockT> BlockRequestHandler<B> {
support_multiple_justifications
,
};
let
mut
reputation_change
s
=
Vec
::
new
()
;
let
mut
reputation_change
=
None
;
match
self
.seen_requests
.get_mut
(
&
key
)
{
Some
(
SeenRequestsValue
::
First
)
=>
{},
...
...
@@ -200,7 +196,7 @@ impl<B: BlockT> BlockRequestHandler<B> {
*
requests
=
requests
.saturating_add
(
1
);
if
*
requests
>
MAX_NUMBER_OF_SAME_REQUESTS_PER_PEER
{
reputation_change
s
.push
(
rep
::
SAME_REQUEST
);
reputation_change
=
Some
(
rep
::
SAME_REQUEST
);
}
},
None
=>
{
...
...
@@ -219,7 +215,7 @@ impl<B: BlockT> BlockRequestHandler<B> {
attributes
,
);
let
result
=
if
reputation_change
s
.is_
empty
()
{
let
result
=
if
reputation_change
.is_
none
()
{
let
block_response
=
self
.get_block_response
(
attributes
,
from_block_id
,
...
...
@@ -228,7 +224,7 @@ impl<B: BlockT> BlockRequestHandler<B> {
support_multiple_justifications
,
)
?
;
// If any of the blocks contains
n
ay data, we can consider it as successful request.
// If any of the blocks contains a
n
y data, we can consider it as successful request.
if
block_response
.blocks
.iter
()
...
...
@@ -253,7 +249,7 @@ impl<B: BlockT> BlockRequestHandler<B> {
pending_response
.send
(
OutgoingResponse
{
result
,
reputation_changes
,
reputation_changes
:
reputation_change
.into_iter
()
.collect
()
,
sent_feedback
:
None
,
})
.map_err
(|
_
|
HandleRequestError
::
SendResponse
)
}
...
...
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