rippled
Loading...
Searching...
No Matches
CanonicalTXSet.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/misc/CanonicalTXSet.h>
21
22namespace ripple {
23
24bool
26{
27 if (lhs.account_ < rhs.account_)
28 return true;
29
30 if (lhs.account_ > rhs.account_)
31 return false;
32
33 if (lhs.seqProxy_ < rhs.seqProxy_)
34 return true;
35
36 if (lhs.seqProxy_ > rhs.seqProxy_)
37 return false;
38
39 return lhs.txId_ < rhs.txId_;
40}
41
44{
45 uint256 ret = beast::zero;
46 memcpy(ret.begin(), account.begin(), account.size());
47 ret ^= salt_;
48 return ret;
49}
50
51void
53{
54 map_.insert(std::make_pair(
55 Key(accountKey(txn->getAccountID(sfAccount)),
56 txn->getSeqProxy(),
57 txn->getTransactionID()),
58 txn));
59}
60
63{
64 // Determining the next viable transaction for an account with Tickets:
65 //
66 // 1. Prioritize transactions with Sequences over transactions with
67 // Tickets.
68 //
69 // 2. For transactions not using Tickets, look for consecutive Sequence
70 // numbers. For transactions using Tickets, don't worry about
71 // consecutive Sequence numbers. Tickets can process out of order.
72 //
73 // 3. After handling all transactions with Sequences, return Tickets
74 // with the lowest Ticket ID first.
76 uint256 const effectiveAccount{accountKey(tx->getAccountID(sfAccount))};
77
78 auto const seqProxy = tx->getSeqProxy();
79 Key const after(effectiveAccount, seqProxy, beast::zero);
80 auto const itrNext{map_.lower_bound(after)};
81 if (itrNext != map_.end() &&
82 itrNext->first.getAccount() == effectiveAccount &&
83 (!itrNext->second->getSeqProxy().isSeq() ||
84 itrNext->second->getSeqProxy().value() == seqProxy.value() + 1))
85 {
86 result = std::move(itrNext->second);
87 map_.erase(itrNext);
88 }
89
90 return result;
91}
92
93} // namespace ripple
void insert(std::shared_ptr< STTx const > const &txn)
std::shared_ptr< STTx const > popAcctTransaction(std::shared_ptr< STTx const > const &tx)
uint256 accountKey(AccountID const &account)
std::map< Key, std::shared_ptr< STTx const > > map_
iterator begin()
Definition base_uint.h:136
T make_pair(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
bool operator<(Slice const &lhs, Slice const &rhs) noexcept
Definition Slice.h:223
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:3266