-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtransaction_pool.hpp
103 lines (84 loc) · 3.26 KB
/
transaction_pool.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once
#include <outcome/outcome.hpp>
#include "primitives/block_id.hpp"
#include "primitives/transaction.hpp"
#include "primitives/transaction_validity.hpp"
namespace kagome::transaction_pool {
using primitives::Transaction;
class TransactionPool {
public:
struct Status;
struct Limits;
using TxRequestCallback =
std::function<void(const std::shared_ptr<const Transaction> &)>;
virtual ~TransactionPool() = default;
/**
* @return pending transactions
*/
virtual void getPendingTransactions(TxRequestCallback &&callback) const = 0;
/**
* Builds and validates transaction for provided extrinsic, and submit
* result transaction into pool
* @param source how extrinsic was received (for example external or
* submitted through offchain worker)
* @param extrinsic set of bytes representing either transaction or inherent
* @return hash of successfully submitted transaction
* or error if state is invalid or unknown
*/
virtual outcome::result<Transaction::Hash> submitExtrinsic(
primitives::TransactionSource source,
primitives::Extrinsic extrinsic) = 0;
/**
* Import one verified transaction to the pool. If it has unresolved
* dependencies (requires tags of transactions that are not in the pool
* yet), it will wait in the pool until its dependencies are solved, in
* which case it becomes ready and may be pruned, or it is banned from the
* pool for some amount of time as its longevity is reached or the pool is
* overflown
*/
virtual outcome::result<void> submitOne(Transaction &&tx) = 0;
/**
* Remove transaction from the pool
* @param txHash - hash of the removed transaction
* @returns removed transaction or error
*/
virtual outcome::result<Transaction> removeOne(
const Transaction::Hash &txHash) = 0;
/**
* @return transactions ready to included in the next block
*/
virtual void getReadyTransactions(TxRequestCallback &&callback) const = 0;
virtual std::vector<
std::pair<Transaction::Hash, std::shared_ptr<const Transaction>>>
getReadyTransactions() const = 0;
/**
* Remove from the pool and temporarily ban transactions which longevity is
* expired
* @param at a block that is considered current for removal (transaction t
* is banned if
* 'block number when t got to pool' + 't.longevity' <= block number of at)
* @return removed transactions
*/
virtual outcome::result<std::vector<Transaction>> removeStale(
const primitives::BlockId &at) = 0;
virtual Status getStatus() const = 0;
virtual outcome::result<primitives::Transaction> constructTransaction(
primitives::TransactionSource source,
primitives::Extrinsic extrinsic) const = 0;
};
struct TransactionPool::Status {
size_t ready_num;
size_t waiting_num;
};
struct TransactionPool::Limits {
static constexpr size_t kDefaultMaxReadyNum = 128;
static constexpr size_t kDefaultCapacity = 512;
size_t max_ready_num = kDefaultMaxReadyNum;
size_t capacity = kDefaultCapacity;
};
} // namespace kagome::transaction_pool