xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
ledger
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
13
namespace
xrpl
{
14
15
bool
16
operator<
(
CanonicalTXSet::Key
const
& lhs,
CanonicalTXSet::Key
const
& rhs)
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
33
UInt256
34
CanonicalTXSet::accountKey
(
AccountID
const
& account)
35
{
36
UInt256
ret =
beast::kZero
;
37
memcpy(ret.
begin
(), account.begin(), account.size());
38
ret ^=
salt_
;
39
return
ret;
40
}
41
42
void
43
CanonicalTXSet::insert
(
std::shared_ptr<STTx const>
txn)
44
{
45
Key
const
key
(
46
accountKey
(txn->getAccountID(sfAccount)), txn->getSeqProxy(), txn->getTransactionID());
47
map_
.emplace(
key
, std::move(txn));
48
}
49
50
std::shared_ptr<STTx const>
51
CanonicalTXSet::popAcctTransaction
(
std::shared_ptr<STTx const>
const
& tx)
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.
64
std::shared_ptr<STTx const>
result;
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
xrpl::BaseUInt::begin
iterator begin()
Definition
base_uint.h:128
xrpl::CanonicalTXSet::Key
Definition
CanonicalTXSet.h:28
xrpl::CanonicalTXSet::Key::account_
UInt256 account_
Definition
CanonicalTXSet.h:75
xrpl::CanonicalTXSet::Key::txId_
UInt256 txId_
Definition
CanonicalTXSet.h:76
xrpl::CanonicalTXSet::Key::seqProxy_
SeqProxy seqProxy_
Definition
CanonicalTXSet.h:77
xrpl::CanonicalTXSet::salt_
UInt256 salt_
Definition
CanonicalTXSet.h:154
xrpl::CanonicalTXSet::key
UInt256 const & key() const
Definition
CanonicalTXSet.h:145
xrpl::CanonicalTXSet::accountKey
UInt256 accountKey(AccountID const &account)
Definition
CanonicalTXSet.cpp:34
xrpl::CanonicalTXSet::map_
std::map< Key, std::shared_ptr< STTx const > > map_
Definition
CanonicalTXSet.h:151
xrpl::CanonicalTXSet::insert
void insert(std::shared_ptr< STTx const > txn)
Definition
CanonicalTXSet.cpp:43
xrpl::CanonicalTXSet::popAcctTransaction
std::shared_ptr< STTx const > popAcctTransaction(std::shared_ptr< STTx const > const &tx)
Definition
CanonicalTXSet.cpp:51
cstring
memory
beast::kZero
constexpr Zero kZero
Definition
Zero.h:30
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::operator<
bool operator<(Slice const &lhs, Slice const &rhs) noexcept
Definition
Slice.h:212
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
xrpl::after
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition
View.cpp:644
xrpl::AccountID
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition
AccountID.h:34
std::shared_ptr
utility
Generated by
1.17.0