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
3e63009a
Commit
3e63009a
authored
6 years ago
by
Tomasz Drwięga
Committed by
Gav Wood
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Make sure to ban invalid transactions. (#615) (#620)
parent
a0069f5f
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
substrate/substrate/extrinsic-pool/src/pool.rs
+25
-0
25 additions, 0 deletions
substrate/substrate/extrinsic-pool/src/pool.rs
substrate/substrate/extrinsic-pool/src/rotator.rs
+18
-11
18 additions, 11 deletions
substrate/substrate/extrinsic-pool/src/rotator.rs
with
43 additions
and
11 deletions
substrate/substrate/extrinsic-pool/src/pool.rs
+
25
−
0
View file @
3e63009a
...
...
@@ -262,9 +262,17 @@ impl<B: ChainApi> Pool<B> {
pub
fn
remove
(
&
self
,
hashes
:
&
[
B
::
Hash
],
is_valid
:
bool
)
->
Vec
<
Option
<
Arc
<
VerifiedFor
<
B
>>>>
{
let
mut
pool
=
self
.pool
.write
();
let
mut
results
=
Vec
::
with_capacity
(
hashes
.len
());
// temporarily ban invalid transactions
if
!
is_valid
{
debug!
(
target
:
"transaction-pool"
,
"Banning invalid transactions: {:?}"
,
hashes
);
self
.rotator
.ban
(
&
time
::
Instant
::
now
(),
hashes
);
}
for
hash
in
hashes
{
results
.push
(
pool
.remove
(
hash
,
is_valid
));
}
results
}
...
...
@@ -578,4 +586,21 @@ pub mod tests {
let
pending
:
Vec
<
_
>
=
pool
.cull_and_get_pending
(
&
BlockId
::
number
(
0
),
|
p
|
p
.map
(|
a
|
(
*
a
.sender
(),
a
.original.transfer.nonce
))
.collect
())
.unwrap
();
assert_eq!
(
pending
,
vec!
[(
Alice
.to_raw_public
()
.into
(),
209
),
(
Alice
.to_raw_public
()
.into
(),
210
)]);
}
#[test]
fn
should_ban_invalid_transactions
()
{
let
pool
=
pool
();
let
uxt
=
uxt
(
Alice
,
209
);
let
hash
=
*
pool
.submit_one
(
&
BlockId
::
number
(
0
),
uxt
.clone
())
.unwrap
()
.hash
();
pool
.remove
(
&
[
hash
],
true
);
pool
.submit_one
(
&
BlockId
::
number
(
0
),
uxt
.clone
())
.unwrap
();
// when
pool
.remove
(
&
[
hash
],
false
);
let
pending
:
Vec
<
AccountId
>
=
pool
.cull_and_get_pending
(
&
BlockId
::
number
(
0
),
|
p
|
p
.map
(|
a
|
*
a
.sender
())
.collect
())
.unwrap
();
assert_eq!
(
pending
,
vec!
[]);
// then
pool
.submit_one
(
&
BlockId
::
number
(
0
),
uxt
.clone
())
.unwrap_err
();
}
}
This diff is collapsed.
Click to expand it.
substrate/substrate/extrinsic-pool/src/rotator.rs
+
18
−
11
View file @
3e63009a
...
...
@@ -58,6 +58,23 @@ impl<Hash: hash::Hash + Eq + Clone> PoolRotator<Hash> {
self
.banned_until
.read
()
.contains_key
(
hash
)
}
/// Bans given set of hashes.
pub
fn
ban
(
&
self
,
now
:
&
Instant
,
hashes
:
&
[
Hash
])
{
let
mut
banned
=
self
.banned_until
.write
();
for
hash
in
hashes
{
banned
.insert
(
hash
.clone
(),
*
now
+
self
.ban_time
);
}
if
banned
.len
()
>
2
*
EXPECTED_SIZE
{
while
banned
.len
()
>
EXPECTED_SIZE
{
if
let
Some
(
key
)
=
banned
.keys
()
.next
()
.cloned
()
{
banned
.remove
(
&
key
);
}
}
}
}
/// Bans extrinsic if it's stale.
///
/// Returns `true` if extrinsic is stale and got banned.
...
...
@@ -69,17 +86,7 @@ impl<Hash: hash::Hash + Eq + Clone> PoolRotator<Hash> {
return
false
;
}
let
mut
banned
=
self
.banned_until
.write
();
banned
.insert
(
xt
.verified
.hash
()
.clone
(),
*
now
+
self
.ban_time
);
if
banned
.len
()
>
2
*
EXPECTED_SIZE
{
while
banned
.len
()
>
EXPECTED_SIZE
{
if
let
Some
(
key
)
=
banned
.keys
()
.next
()
.cloned
()
{
banned
.remove
(
&
key
);
}
}
}
self
.ban
(
now
,
&
[
xt
.verified
.hash
()
.clone
()]);
true
}
...
...
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