You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 30, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: old-docs-migration/docs/02-concepts/d-transaction-pool.md
+5-109
Original file line number
Diff line number
Diff line change
@@ -7,119 +7,15 @@ category: concepts
7
7
keywords: transaction, pool, order, ordering, sorting, validity
8
8
---
9
9
10
-
The transaction pool contains all transactions ([signed](/v3/concepts/extrinsics#signed-transactions)
11
-
and [unsigned](/v3/concepts/extrinsics#unsigned-transactions)) broadcasted to the network that have been
12
-
received and validated by the local node.
13
-
14
-
## Validity
15
-
16
-
The transaction pool checks for transaction validity.
17
-
Note that `validity` of the transaction is not hard-wired to the transaction pool, but is defined by the runtime.
18
-
Example validity checks are:
19
-
20
-
- Checking if the Transaction Index (nonce) is correct.
21
-
- Checking if the account has enough funds to pay for the associated fees.
22
-
- Checking if the signature is valid.
23
-
24
-
The transaction pool also regularly checks validity of existing transactions within the pool.
25
-
A transaction will be dropped from the pool if it is found to be invalid or is an expired mortal transaction.
26
-
27
-
[`validate_transaction`](/rustdocs/latest/sp_transaction_pool/runtime_api/trait.TaggedTransactionQueue.html#method.validate_transaction) is called from the runtime to checks for a valid signature and nonce (or output for a UTXO chain) and returns a `Result`.
10
+
## Validity
11
+
[content not used / to remove]
28
12
It does this check in isolation, so it will not catch errors such as the same output being spent twice.
13
+
`validate_transaction` does not check whether calls to a pallet will succeed.
29
14
30
-
Although it is possible, `validate_transaction` does not check whether calls to pallets will succeed.
31
-
It is a potential DoS vector since all transactions in the network will be passed into `validate_transaction`.
32
-
33
-
The `validate_transaction` function should focus on providing the necessary information for the pool to order and prioritize transactions, and quickly reject all transactions that are invalid or outdated.
34
-
The function will be called frequently, potentially multiple times for the same transaction.
35
-
It is also possible for `validate_transaction` to fail a dependent transaction that would pass `execute_block` if it were executed in the correct order.
36
-
37
-
## Sorting
38
-
39
-
If the transaction is valid, the transaction queue sorts transactions into two groups:
40
-
41
-
- Ready Queue - Contains transactions that can be included in a new pending block.
42
-
For runtimes built with FRAME, the transactions must follow the exact order in the ready queue.
43
-
- Future Queue - Contains transactions that may become valid in the future.
44
-
For example, a transaction may have a `nonce` that is too high for its account.
45
-
This transaction will wait in the future queue until the preceding transactions are included in the chain.
46
-
47
-
Although it's possible to design a custom runtime to remove the queues' strict transaction ordering requirements.
15
+
[ todo : put this in architecture? or design? ]
16
+
It's possible to design a custom runtime to remove the strict ordering requirements of the queue.
48
17
This would allow full nodes to implement different strategies on transaction propagation and block inclusion.
49
18
50
-
## Transaction dependencies
51
-
52
-
The [`ValidTransaction` struct](/rustdocs/latest/sp_runtime/transaction_validity/struct.ValidTransaction.html) defines the `requires` and `provides` parameters to build a dependency graph of transactions.
53
-
Together with `priority` (discussed below), this dependency graph allows the pool to produce a valid linear ordering of transactions.
54
-
55
-
For runtimes built with FRAME, the nodes order transactions with an account-based system.
56
-
Every signed transaction needs to contain a nonce, which is incremented by 1 every time a new transaction is made.
57
-
For example, the first transaction from a new account will have `nonce = 0` and the second transaction will have `nonce = 1`.
58
-
59
-
At minimum, FRAME transactions have a `provides` tag of `encode(sender ++ nonce)` and a `requires` tag of `encode(sender ++ (nonce -1)) if nonce > 1`.
60
-
Transactions do not require anything if `nonce=0`.
61
-
As a result, all transactions coming from a single sender will form a sequence in which they should be included.
62
-
63
-
Substrate supports multiple `provides` and `requires` tags, so custom runtimes can create alternate dependency (ordering) schemes.
64
-
65
-
## Transaction priority
66
-
67
-
Transaction `priority` in the `ValidTransaction` struct determines the ordering of transactions that are in the ready queue.
68
-
If a node is the next block author, it will order transactions from high to low priority in the next block until it reaches the weight or length limit of the block.
69
-
70
-
`priority` defines the linear ordering of a graph in the case of one transaction unlocking multiple dependent transactions.
71
-
For example, if we have two (or more) transactions that have their dependencies satisfied, then we use `priority` to choose the order for them.
72
-
73
-
For runtimes built with [FRAME](/v3/runtime/frame), `priority` is defined as the `fee` that the transaction is going to pay.
74
-
For example:
75
-
76
-
- If we receive 2 transactions from _different_ senders (with `nonce=0`), we use `priority` to
77
-
determine which transaction is more important and included in the block first.
78
-
- If we receive 2 transactions from the _same_ sender with an identical `nonce`, only one
79
-
transaction can be included on-chain. We use `priority` to choose the transaction with a higher
80
-
`fee` to store in the transaction pool.
81
-
82
-
Note that the pool does not know about fees, accounts, or signatures — it only deals with the validity of the transaction and the abstract notion of the `priority`, `requires`, and `provides` parameters.
83
-
All other details are defined by the runtime via the `validate_transaction` function.
84
-
85
-
## Transaction lifecycle
86
-
87
-
A transaction can follow two paths:
88
-
89
-
### Block produced by our node
90
-
91
-
1. Our node listens for transactions on the network.
92
-
1. Each transaction is verified and valid transactions are placed in the transaction pool.
93
-
1. The pool is responsible for ordering the transactions and returning ones that are ready to be included in the block.
94
-
Transactions in the ready queue are used to construct a block.
95
-
1. Transactions are executed and state changes are stored in local memory.
96
-
Transactions from the `ready` queue are also propagated (gossiped) to peers over the network.
97
-
We use the exact ordering as the pending block since transactions in the front of the queue have a higher priority and are more likely to be successfully executed in the next block.
98
-
1. The constructed block is published to the network.
99
-
All other nodes on the network receive and execute the block.
100
-
101
-
Notice that transactions are not removed from the ready queue when blocks are authored, but removed _only_ on block import.
102
-
This is due to the possibility that a recently-authored block may not make it into the canonical chain.
103
-
104
-
### Block received from network
105
-
106
-
The block is executed and the entire block either succeeds or fails.
107
-
108
-
## Signed extensions
109
-
110
-
[`SignedExtension`](/rustdocs/latest/sp_runtime/traits/trait.SignedExtension.html) is a trait by which a transaction can be extended with additional data or logic.
111
-
Signed extensions are used anywhere you want some information about a transaction prior to execution.
112
-
This is heavily used in the transaction pool.
113
-
114
-
The runtime can use some of this data, for example the `Call` that will be dispatched, to calculate transaction fees.
115
-
Signed extensions also include an `AdditionalSigned` type that can hold any encodable data, and therefore allow you to perform any custom logic prior to including or dispatching a transaction.
116
-
The transaction queue regularly calls functions from `SignedExtension` to validate transactions prior to block construction to avoid including transactions that will fail in blocks.
117
-
118
-
Despite the name, `SignedExtension` can also be used to verify [unsigned transactions](/v3/concepts/extrinsics#unsigned-transactions).
119
-
The `*_unsigned` set of methods can be implemented to encapsulate validation, spam, and replay protection logic that is needed by the transaction pool.
0 commit comments