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
c00a47d5
Commit
c00a47d5
authored
4 years ago
by
Hernando Castano
Committed by
Bastian Köcher
11 months ago
Browse files
Options
Downloads
Patches
Plain Diff
Stop counting invalid requests towards rate limit (#765)
parent
19f021e3
Branches
Branches containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bridges/modules/finality-verifier/src/lib.rs
+37
-2
37 additions, 2 deletions
bridges/modules/finality-verifier/src/lib.rs
with
37 additions
and
2 deletions
bridges/modules/finality-verifier/src/lib.rs
+
37
−
2
View file @
c00a47d5
...
...
@@ -75,6 +75,8 @@ pub mod pallet {
/// The upper bound on the number of requests allowed by the pallet.
///
/// A request refers to an action which writes a header to storage.
///
/// Once this bound is reached the pallet will not allow any dispatchables to be called
/// until the request count has decreased.
#[pallet::constant]
...
...
@@ -117,7 +119,6 @@ pub mod pallet {
Self
::
request_count
()
<
T
::
MaxRequests
::
get
(),
<
Error
<
T
>>
::
TooManyRequests
);
<
RequestCount
<
T
>>
::
mutate
(|
count
|
*
count
+=
1
);
frame_support
::
debug
::
trace!
(
"Going to try and finalize header {:?}"
,
finality_target
);
...
...
@@ -144,11 +145,13 @@ pub mod pallet {
T
::
HeaderChain
::
append_header
(
finality_target
);
frame_support
::
debug
::
info!
(
"Succesfully imported finalized header with hash {:?}!"
,
hash
);
<
RequestCount
<
T
>>
::
mutate
(|
count
|
*
count
+=
1
);
Ok
(()
.into
())
}
}
/// The current number of requests
for calling dispatchables
.
/// The current number of requests
which have written to storage
.
///
/// If the `RequestCount` hits `MaxRequests`, no more calls will be allowed to the pallet until
/// the request capacity is increased.
...
...
@@ -340,6 +343,38 @@ mod tests {
})
}
#[test]
fn
invalid_requests_do_not_count_towards_request_count
()
{
run_test
(||
{
let
submit_invalid_request
=
||
{
let
child
=
test_header
(
1
);
let
header
=
test_header
(
2
);
let
invalid_justification
=
vec!
[
4
,
2
,
4
,
2
]
.encode
();
let
ancestry_proof
=
vec!
[
child
,
header
.clone
()];
Module
::
<
TestRuntime
>
::
submit_finality_proof
(
Origin
::
signed
(
1
),
header
,
invalid_justification
,
ancestry_proof
,
)
};
initialize_substrate_bridge
();
for
_
in
0
..<
TestRuntime
as
Config
>
::
MaxRequests
::
get
()
+
1
{
// Notice that the error here *isn't* `TooManyRequests`
assert_err!
(
submit_invalid_request
(),
<
Error
<
TestRuntime
>>
::
InvalidJustification
);
}
// Can still submit `MaxRequests` requests afterwards
assert_ok!
(
submit_finality_proof
());
assert_ok!
(
submit_finality_proof
());
assert_err!
(
submit_finality_proof
(),
<
Error
<
TestRuntime
>>
::
TooManyRequests
);
})
}
#[test]
fn
allows_request_after_new_block_has_started
()
{
run_test
(||
{
...
...
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