xrpld
Loading...
Searching...
No Matches
CanonicalTXSet.cpp
1#include <xrpl/ledger/CanonicalTXSet.h>
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/beast/utility/Zero.h>
5#include <xrpl/protocol/AccountID.h>
6#include <xrpl/protocol/SField.h>
7#include <xrpl/protocol/STTx.h>
8
9#include <cstring>
10#include <memory>
11#include <utility>
12
13namespace xrpl {
14
15bool
17{
18 if (lhs.account_ < rhs.account_)
19 return true;
20
21 if (lhs.account_ > rhs.account_)
22 return false;
23
24 if (lhs.seqProxy_ < rhs.seqProxy_)
25 return true;
26
27 if (lhs.seqProxy_ > rhs.seqProxy_)
28 return false;
29
30 return lhs.txId_ < rhs.txId_;
31}
32
35{
36 uint256 ret = beast::kZero;
37 memcpy(ret.begin(), account.begin(), account.size());
38 ret ^= salt_;
39 return ret;
40}
41
42void
44{
45 Key const key(
46 accountKey(txn->getAccountID(sfAccount)), txn->getSeqProxy(), txn->getTransactionID());
47 map_.emplace(key, std::move(txn));
48}
49
52{
53 // Determining the next viable transaction for an account with Tickets:
54 //
55 // 1. Prioritize transactions with Sequences over transactions with
56 // Tickets.
57 //
58 // 2. For transactions not using Tickets, look for consecutive Sequence
59 // numbers. For transactions using Tickets, don't worry about
60 // consecutive Sequence numbers. Tickets can process out of order.
61 //
62 // 3. After handling all transactions with Sequences, return Tickets
63 // with the lowest Ticket ID first.
65 uint256 const effectiveAccount{accountKey(tx->getAccountID(sfAccount))};
66
67 auto const seqProxy = tx->getSeqProxy();
68 Key const after(effectiveAccount, seqProxy, beast::kZero);
69 auto const itrNext{map_.lower_bound(after)};
70 if (itrNext != map_.end() && itrNext->first.getAccount() == effectiveAccount &&
71 (!itrNext->second->getSeqProxy().isSeq() ||
72 itrNext->second->getSeqProxy().value() == seqProxy.value() + 1))
73 {
74 result = std::move(itrNext->second);
75 map_.erase(itrNext);
76 }
77
78 return result;
79}
80
81} // namespace xrpl
iterator begin()
Definition base_uint.h:117
std::map< Key, std::shared_ptr< STTx const > > map_
void insert(std::shared_ptr< STTx const > txn)
uint256 const & key() const
std::shared_ptr< STTx const > popAcctTransaction(std::shared_ptr< STTx const > const &tx)
uint256 accountKey(AccountID const &account)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
bool operator<(Slice const &lhs, Slice const &rhs) noexcept
Definition Slice.h:199
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:554
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
BaseUInt< 256 > uint256
Definition base_uint.h:562