rippled
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 <ripple/app/misc/CanonicalTXSet.h>
21 
22 namespace ripple {
23 
24 bool
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 
42 uint256
44 {
45  uint256 ret = beast::zero;
46  memcpy(ret.begin(), account.begin(), account.size());
47  ret ^= salt_;
48  return ret;
49 }
50 
51 void
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. Don't worry about consecutive Sequence numbers. Creating Tickets
70  // can introduce a discontinuity in Sequence numbers.
71  //
72  // 3. After handling all transactions with Sequences, return Tickets
73  // with the lowest Ticket ID first.
75  uint256 const effectiveAccount{accountKey(tx->getAccountID(sfAccount))};
76 
77  Key const after(effectiveAccount, tx->getSeqProxy(), beast::zero);
78  auto const itrNext{map_.lower_bound(after)};
79  if (itrNext != map_.end() &&
80  itrNext->first.getAccount() == effectiveAccount)
81  {
82  result = std::move(itrNext->second);
83  map_.erase(itrNext);
84  }
85 
86  return result;
87 }
88 
89 } // namespace ripple
std::shared_ptr
STL class.
ripple::CanonicalTXSet::map_
std::map< Key, std::shared_ptr< STTx const > > map_
Definition: CanonicalTXSet.h:172
ripple::CanonicalTXSet::popAcctTransaction
std::shared_ptr< STTx const > popAcctTransaction(std::shared_ptr< STTx const > const &tx)
Definition: CanonicalTXSet.cpp:62
ripple::CanonicalTXSet::salt_
uint256 salt_
Definition: CanonicalTXSet.h:175
ripple::CanonicalTXSet::Key::seqProxy_
SeqProxy seqProxy_
Definition: CanonicalTXSet.h:97
ripple::uint256
base_uint< 256 > uint256
Definition: base_uint.h:550
ripple::CanonicalTXSet::Key::account_
uint256 account_
Definition: CanonicalTXSet.h:95
ripple::base_uint< 160, detail::AccountIDTag >
ripple::operator<
bool operator<(CanonicalTXSet::Key const &lhs, CanonicalTXSet::Key const &rhs)
Definition: CanonicalTXSet.cpp:25
ripple::CanonicalTXSet::accountKey
uint256 accountKey(AccountID const &account)
Definition: CanonicalTXSet.cpp:43
ripple::CanonicalTXSet::insert
void insert(std::shared_ptr< STTx const > const &txn)
Definition: CanonicalTXSet.cpp:52
ripple::CanonicalTXSet::Key
Definition: CanonicalTXSet.h:41
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::base_uint::begin
iterator begin()
Definition: base_uint.h:133
ripple::CanonicalTXSet::Key::txId_
uint256 txId_
Definition: CanonicalTXSet.h:96
ripple::after
static bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition: Escrow.cpp:88
std::make_pair
T make_pair(T... args)
ripple::sfAccount
const SF_ACCOUNT sfAccount