25 #include <condition_variable> 130 struct VerifiedTransaction
132 VerifiedTransaction(
Transaction const& _t): transaction(_t) {}
133 VerifiedTransaction(VerifiedTransaction&& _t): transaction(
std::move(_t.transaction)) {}
135 VerifiedTransaction(VerifiedTransaction
const&) =
delete;
136 VerifiedTransaction& operator=(VerifiedTransaction
const&) =
delete;
138 Transaction transaction;
142 struct UnverifiedTransaction
144 UnverifiedTransaction() {}
145 UnverifiedTransaction(
bytesConstRef const& _t,
h512 const& _nodeId): transaction(_t.toBytes()), nodeId(_nodeId) {}
146 UnverifiedTransaction(UnverifiedTransaction&& _t): transaction(
std::move(_t.transaction)), nodeId(
std::move(_t.nodeId)) {}
147 UnverifiedTransaction& operator=(UnverifiedTransaction&& _other)
149 assert(&_other !=
this);
151 transaction = std::move(_other.transaction);
152 nodeId = std::move(_other.nodeId);
156 UnverifiedTransaction(UnverifiedTransaction
const&) =
delete;
157 UnverifiedTransaction& operator=(UnverifiedTransaction
const&) =
delete;
163 struct PriorityCompare
167 bool operator()(VerifiedTransaction
const& _first, VerifiedTransaction
const& _second)
const 169 u256 const& height1 = _first.transaction.nonce() - queue.m_currentByAddressAndNonce[_first.transaction.sender()].begin()->first;
170 u256 const& height2 = _second.transaction.nonce() - queue.m_currentByAddressAndNonce[_second.transaction.sender()].begin()->first;
171 return height1 < height2 || (height1 == height2 && _first.transaction.gasPrice() > _second.transaction.gasPrice());
176 using PriorityQueue = std::multiset<VerifiedTransaction, PriorityCompare>;
180 ImportResult manageImport_WITH_LOCK(
h256 const& _h, Transaction
const& _transaction);
182 void insertCurrent_WITH_LOCK(std::pair<h256, Transaction>
const& _p);
183 void makeCurrent_WITH_LOCK(Transaction
const& _t);
184 bool remove_WITH_LOCK(
h256 const& _txHash);
191 std::unordered_map<h256, std::function<void(ImportResult)>> m_callbacks;
194 PriorityQueue m_current;
195 std::unordered_map<h256, PriorityQueue::iterator> m_currentByHash;
196 std::unordered_map<Address, std::map<u256, PriorityQueue::iterator>> m_currentByAddressAndNonce;
197 std::unordered_map<Address, std::map<u256, VerifiedTransaction>> m_future;
200 Signal<ImportResult, h256 const&, h512 const&> m_onImport;
201 Signal<h256 const&> m_onReplaced;
203 unsigned m_futureLimit;
204 unsigned m_futureSize = 0;
206 std::condition_variable m_queueReady;
207 std::vector<std::thread> m_verifiers;
208 std::deque<UnverifiedTransaction> m_unverified;
209 mutable Mutex x_queue;
210 std::atomic<bool> m_aborting = {
false};
u256 maxNonce(Address const &_a) const
A queue of Transactions, each stored as RLP. Maintains a transaction queue sorted by nonce diff and g...
Handler< ImportResult, h256 const &, h512 const & > onImport(T const &_t)
Register a handler that will be called once asynchronous verification is comeplte an transaction has ...
void enqueue(RLP const &_data, h512 const &_nodeId)
TransactionQueue(Limits const &_l)
Handler onReady(T const &_t)
Register a handler that will be called once there is a new transaction imported.
void drop(h256 const &_txHash)
std::vector< Transaction > Transactions
Nice name for vector of Transaction.
#define DEV_GUARDED(MUTEX)
Simple block guard. The expression/block following is guarded though the given mutex. Usage:
IfDropped
Import transaction policy.
std::shared_ptr< typename Signal< Args... >::HandlerAux > Handler
unsigned waiting(Address const &_a) const
Logger createLogger(int _severity, std::string const &_channel)
std::vector< byte > bytes
vector_ref< byte const > bytesConstRef
void clear()
Clear the queue.
Don't import transaction that was previously dropped.
std::shared_ptr< HandlerAux > add(Callback const &_h)
h256Hash knownTransactions() const
boost::shared_lock< boost::shared_mutex > ReadGuard
Encodes a transaction, ready to be exported to or freshly imported from RLP.
void setFuture(h256 const &_t)
void dropGood(Transaction const &_t)
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void > > u256
boost::shared_mutex SharedMutex
Transactions topTransactions(unsigned _limit, h256Hash const &_avoid=h256Hash()) const
std::unordered_set< h256 > h256Hash
Handler< h256 const & > onReplaced(T const &_t)
Register a handler that will be called once asynchronous verification is comeplte an transaction has ...
boost::log::sources::severity_channel_logger<> Logger
TransactionQueue(unsigned _limit=1024, unsigned _futureLimit=1024)
TransactionQueue.