36 TransactionQueue::TransactionQueue(
unsigned _limit,
unsigned _futureLimit):
41 unsigned verifierThreads =
std::max(thread::hardware_concurrency(), 3U) - 2U;
42 for (
unsigned i = 0; i < verifierThreads; ++i)
44 setThreadName(
"txcheck" + toString(i));
127 if (!_avoid.count(t->transaction.sha3()))
128 ret.push_back(t->transaction);
148 auto t = cs->second.find(_transaction.
nonce());
149 if (t != cs->second.end())
151 if (_transaction.
gasPrice() < (*t->second).transaction.gasPrice())
155 h256 dropped = (*t->second).transaction.sha3();
164 auto t = fs->second.find(_transaction.
nonce());
165 if (t != fs->second.end())
167 if (_transaction.
gasPrice() < t->second.transaction.gasPrice())
173 if (fs->second.empty())
192 ctxq <<
"Ignoring invalid transaction: " << diagnostic_information(_e);
195 catch (std::exception
const& _e)
197 ctxq <<
"Ignoring invalid transaction: " << _e.what();
215 ret = cs->second.rbegin()->first + 1;
217 if (fs !=
m_future.end() && !fs->second.empty())
218 ret =
std::max(ret, fs->second.rbegin()->first + 1);
226 cwarn <<
"Transaction hash" << _p.first <<
"already in current?!";
234 inserted.first->second = handle;
248 Address from = (*t->second).transaction.from();
251 it->second.erase((*t->second).transaction.nonce());
254 if (it->second.empty())
266 ret = cs->second.size();
269 ret += fs->second.size();
286 for (
auto m = cutoff; m != queue.end(); ++m)
294 queue.erase(cutoff, queue.end());
301 bool newCurrent =
false;
306 auto fb = fs->second.find(nonce);
307 if (
fb != fs->second.end())
310 while (ft != fs->second.end() && ft->second.transaction.nonce() == nonce)
313 PriorityQueue::iterator handle =
m_current.emplace(move(ft->second));
314 inserted.first->second = handle;
321 fs->second.erase(
fb, ft);
322 if (fs->second.empty())
334 if (
m_future.begin()->second.empty())
380 for (
unsigned i = 0; i < itemCount; ++i)
419 cwarn <<
"Bad transaction:" << boost::current_exception_diagnostic_information();
SharedMutex m_lock
General lock.
unsigned m_limit
Max number of pending transactions.
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
h256Hash m_dropped
Transactions that have previously been dropped.
Address from() const
Synonym for safeSender().
std::unordered_map< Address, std::map< u256, VerifiedTransaction > > m_future
std::unordered_map< h256, PriorityQueue::iterator > m_currentByHash
Transaction hash to set ref.
std::atomic< bool > m_aborting
Exit condition for verifier.
void enqueue(RLP const &_data, h512 const &_nodeId)
Add transaction to the queue to be verified and imported.
unsigned m_futureLimit
Max number of future transactions.
std::vector< Transaction > Transactions
Nice name for vector of Transaction.
std::vector< std::thread > m_verifiers
void drop(h256 const &_txHash)
Remove transaction from the queue.
boost::upgrade_to_unique_lock< boost::shared_mutex > UpgradeGuard
std::hash for asio::adress
assert(len-trim+(2 *lenIndices)<=WIDTH)
Signal< ImportResult, h256 const &, h512 const & > m_onImport
Called for each import attempt. Arguments are result, transaction id an node id. Be nice and exit fas...
Mutex x_queue
Verification queue mutex.
Signal< h256 const & > m_onReplaced
Called whan transction is dropped during a call to import() to make room for another transaction...
boost::upgrade_lock< boost::shared_mutex > UpgradableGuard
bytes transaction
RLP encoded transaction data.
ImportResult manageImport_WITH_LOCK(h256 const &_h, Transaction const &_transaction)
u256 maxNonce_WITH_LOCK(Address const &_a) const
void makeCurrent_WITH_LOCK(Transaction const &_t)
Transactions topTransactions(unsigned _limit, h256Hash const &_avoid=h256Hash()) const
Get top transactions from the queue.
#define DEV_GUARDED(MUTEX)
Simple block guard.
Base class for all exceptions.
Verified and imported transaction.
std::deque< UnverifiedTransaction > m_unverified
Pending verification queue.
h256Hash m_known
Headers of transactions in both sets.
IfDropped
Import transaction policy.
std::lock_guard< std::mutex > Guard
unsigned m_futureSize
Current number of future transactions.
void clear()
Clear the queue.
Don't import transaction that was previously dropped.
h256 sha3(IncludeSignature _sig=WithSignature) const
std::unordered_map< Address, std::map< u256, PriorityQueue::iterator > > m_currentByAddressAndNonce
Transactions grouped by account and nonce.
ImportResult check_WITH_LOCK(h256 const &_h, IfDropped _ik)
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
boost::shared_lock< boost::shared_mutex > ReadGuard
ImportResult import(bytes const &_tx, IfDropped _ik=IfDropped::Ignore)
Verify and add transaction to the queue synchronously.
Encodes a transaction, ready to be exported to or freshly imported from RLP.
bool remove_WITH_LOCK(h256 const &_txHash)
boost::unique_lock< boost::shared_mutex > WriteGuard
Address const & safeSender() const noexcept
Like sender() but will never throw.
void setFuture(h256 const &_t)
Mark transaction as future.
void dropGood(Transaction const &_t)
Drop a trasnaction from the list if exists and move following future trasnactions to current (if any)...
u256 maxNonce(Address const &_a) const
Get max nonce for an account.
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
Transaction transaction
Transaction data.
h512 nodeId
Network Id of the peer transaction comes from.
std::unordered_set< h256 > h256Hash
dev::WithExisting max(dev::WithExisting _a, dev::WithExisting _b)
Transaction pending verification.
void insertCurrent_WITH_LOCK(std::pair< h256, Transaction > const &_p)
Signal m_onReady
Future transactions.
std::condition_variable m_queueReady
Signaled when m_unverified has a new entry.
h256Hash knownTransactions() const
Get a hash set of transactions in the queue.
unsigned waiting(Address const &_a) const
Get number of pending transactions for account.
Class for interpreting Recursive Linear-Prefix Data.
const size_t c_maxVerificationQueueSize