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
15e365f0
Commit
15e365f0
authored
May 26, 2018
by
Wei Tang
Committed by
Gav Wood
May 26, 2018
Browse files
Update transaction-pool dependency and remove ethereum-types (#174)
parent
f41a4959
Changes
2
Hide whitespace changes
Inline
Side-by-side
transaction-pool/Cargo.toml
View file @
15e365f0
...
...
@@ -5,7 +5,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
[dependencies]
log
=
"0.4.0"
transaction-pool
=
"1.
9
.0"
transaction-pool
=
"1.
12
.0"
error-chain
=
"0.11"
polkadot-api
=
{
path
=
"../api"
}
polkadot-primitives
=
{
path
=
"../primitives"
}
...
...
@@ -16,4 +16,3 @@ substrate-primitives = { path = "../../substrate/primitives" }
substrate-runtime-primitives
=
{
path
=
"../../substrate/runtime/primitives"
}
substrate-codec
=
{
path
=
"../../substrate/codec"
}
ed25519
=
{
path
=
"../../substrate/ed25519"
}
ethereum-types
=
"0.2"
transaction-pool/src/lib.rs
View file @
15e365f0
...
...
@@ -15,7 +15,6 @@
// along with Polkadot. If not, see <http://www.gnu.org/licenses/>.
extern
crate
ed25519
;
extern
crate
ethereum_types
;
extern
crate
substrate_codec
as
codec
;
extern
crate
substrate_primitives
as
substrate_primitives
;
extern
crate
substrate_runtime_primitives
as
substrate_runtime_primitives
;
...
...
@@ -35,22 +34,15 @@ use std::cmp::Ordering;
use
std
::
sync
::
Arc
;
use
polkadot_api
::
PolkadotApi
;
use
primitives
::{
AccountId
,
Timestamp
};
use
primitives
::{
AccountId
,
Timestamp
,
Hash
};
use
primitives
::
parachain
::
CandidateReceipt
;
use
runtime
::{
Block
,
UncheckedExtrinsic
,
TimestampCall
,
ParachainsCall
,
Call
};
use
substrate_runtime_primitives
::
traits
::{
Bounded
,
Checkable
};
use
transaction_pool
::{
Pool
,
Readiness
};
use
transaction_pool
::{
Transaction
,
Pool
,
Readiness
};
use
transaction_pool
::
scoring
::{
Change
,
Choice
};
// TODO: make queue generic over hash and sender so we don't need ethereum-types
pub
use
ethereum_types
::{
Address
as
TruncatedAccountId
,
H256
as
TransactionHash
};
pub
use
transaction_pool
::{
Options
,
Status
,
LightStatus
,
NoopListener
,
VerifiedTransaction
as
VerifiedTransactionOps
};
/// Truncate an account ID to 160 bits.
pub
fn
truncate_id
(
id
:
&
AccountId
)
->
TruncatedAccountId
{
TruncatedAccountId
::
from_slice
(
&
id
[
..
20
])
}
/// Useful functions for working with Polkadot blocks.
pub
struct
PolkadotBlock
{
block
:
Block
,
...
...
@@ -152,7 +144,7 @@ error_chain! {
display
(
"Transaction had bad signature."
),
}
/// Attempted to queue a transaction that is already in the pool.
AlreadyImported
(
hash
:
Transaction
Hash
)
{
AlreadyImported
(
hash
:
Hash
)
{
description
(
"Transaction is already in the pool."
),
display
(
"Transaction {:?} is already in the pool."
,
hash
),
}
...
...
@@ -168,8 +160,8 @@ error_chain! {
#[derive(Debug,
Clone)]
pub
struct
VerifiedTransaction
{
inner
:
<
UncheckedExtrinsic
as
Checkable
>
::
Checked
,
hash
:
Transaction
Hash
,
address
:
Truncated
AccountId
,
hash
:
Hash
,
address
:
AccountId
,
insertion_id
:
u64
,
encoded_size
:
usize
,
}
...
...
@@ -186,7 +178,7 @@ impl VerifiedTransaction {
Ok
(
xt
)
=>
{
// TODO: make transaction-pool use generic types.
let
hash
=
substrate_primitives
::
hashing
::
blake2_256
(
&
message
);
let
address
=
truncate_id
(
&
xt
.signed
)
;
let
address
=
xt
.signed
;
Ok
(
VerifiedTransaction
{
inner
:
xt
,
hash
:
hash
.into
(),
...
...
@@ -210,12 +202,12 @@ impl VerifiedTransaction {
}
/// Get the 256-bit hash of this transaction.
pub
fn
hash
(
&
self
)
->
&
Transaction
Hash
{
pub
fn
hash
(
&
self
)
->
&
Hash
{
&
self
.hash
}
/// Get the
truncated
account ID of the sender of this transaction.
pub
fn
sender
(
&
self
)
->
&
Truncated
AccountId
{
/// Get the account ID of the sender of this transaction.
pub
fn
sender
(
&
self
)
->
&
AccountId
{
&
self
.address
}
...
...
@@ -232,28 +224,29 @@ impl AsRef< <UncheckedExtrinsic as Checkable>::Checked > for VerifiedTransaction
}
impl
transaction_pool
::
VerifiedTransaction
for
VerifiedTransaction
{
fn
hash
(
&
self
)
->
&
TransactionHash
{
type
Hash
=
Hash
;
type
Sender
=
AccountId
;
fn
hash
(
&
self
)
->
&
Hash
{
&
self
.hash
}
fn
sender
(
&
self
)
->
&
Truncated
AccountId
{
fn
sender
(
&
self
)
->
&
AccountId
{
&
self
.address
}
fn
mem_usage
(
&
self
)
->
usize
{
1
// TODO
}
fn
insertion_id
(
&
self
)
->
u64
{
self
.insertion_id
}
}
/// Scoring implementation for polkadot transactions.
#[derive(Debug)]
pub
struct
Scoring
;
impl
transaction_pool
::
Scoring
<
VerifiedTransaction
>
for
Scoring
{
type
Score
=
u64
;
type
Event
=
();
fn
compare
(
&
self
,
old
:
&
VerifiedTransaction
,
other
:
&
VerifiedTransaction
)
->
Ordering
{
old
.inner.index
.cmp
(
&
other
.inner.index
)
...
...
@@ -265,9 +258,9 @@ impl transaction_pool::Scoring<VerifiedTransaction> for Scoring {
fn
update_scores
(
&
self
,
xts
:
&
[
Arc
<
VerifiedTransaction
>
],
xts
:
&
[
Transaction
<
VerifiedTransaction
>
],
scores
:
&
mut
[
Self
::
Score
],
_change
:
Change
_change
:
Change
<
()
>
)
{
for
i
in
0
..
xts
.len
()
{
// all the same score since there are no fees.
...
...
@@ -312,7 +305,7 @@ impl<'a, T: 'a + PolkadotApi> Ready<'a, T> {
impl
<
'a
,
T
:
'a
+
PolkadotApi
>
transaction_pool
::
Ready
<
VerifiedTransaction
>
for
Ready
<
'a
,
T
>
{
fn
is_ready
(
&
mut
self
,
xt
:
&
VerifiedTransaction
)
->
Readiness
{
let
sender
=
xt
.inner.signed
;
trace!
(
target
:
"transaction-pool"
,
"Checking readiness of {} (from {})"
,
xt
.hash
,
Transaction
Hash
::
from
(
sender
));
trace!
(
target
:
"transaction-pool"
,
"Checking readiness of {} (from {})"
,
xt
.hash
,
Hash
::
from
(
sender
));
// TODO: find a way to handle index error properly -- will need changes to
// transaction-pool trait.
...
...
@@ -325,7 +318,7 @@ impl<'a, T: 'a + PolkadotApi> transaction_pool::Ready<VerifiedTransaction> for R
match
xt
.inner.index
.cmp
(
&
next_index
)
{
Ordering
::
Greater
=>
Readiness
::
Future
,
Ordering
::
Equal
=>
Readiness
::
Ready
,
Ordering
::
Less
=>
Readiness
::
Stal
led
,
// TODO: this is not "stalled" but rather stale and can be discarded.
Ordering
::
Less
=>
Readiness
::
Stal
e
,
// TODO: this is not "stalled" but rather stale and can be discarded.
}
}
}
...
...
@@ -375,12 +368,12 @@ impl TransactionPool {
}
/// Remove from the pool.
pub
fn
remove
(
&
mut
self
,
hash
:
&
Transaction
Hash
,
is_valid
:
bool
)
->
Option
<
Arc
<
VerifiedTransaction
>>
{
pub
fn
remove
(
&
mut
self
,
hash
:
&
Hash
,
is_valid
:
bool
)
->
Option
<
Arc
<
VerifiedTransaction
>>
{
self
.inner
.remove
(
hash
,
is_valid
)
}
/// Cull transactions from the queue.
pub
fn
cull
<
T
:
PolkadotApi
>
(
&
mut
self
,
senders
:
Option
<&
[
Truncated
AccountId
]
>
,
ready
:
Ready
<
T
>
)
->
usize
{
pub
fn
cull
<
T
:
PolkadotApi
>
(
&
mut
self
,
senders
:
Option
<&
[
AccountId
]
>
,
ready
:
Ready
<
T
>
)
->
usize
{
self
.inner
.cull
(
senders
,
ready
)
}
...
...
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