xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
tx
invariants
PermissionedDomainInvariant.cpp
1
#include <xrpl/tx/invariants/PermissionedDomainInvariant.h>
2
3
#include <xrpl/basics/Log.h>
4
#include <xrpl/beast/utility/Journal.h>
5
#include <xrpl/ledger/ReadView.h>
6
#include <xrpl/ledger/helpers/CredentialHelpers.h>
7
#include <xrpl/protocol/Feature.h>
8
#include <xrpl/protocol/LedgerFormats.h>
9
#include <xrpl/protocol/Protocol.h>
10
#include <xrpl/protocol/SField.h>
11
#include <xrpl/protocol/STAccount.h>
// IWYU pragma: keep
12
#include <xrpl/protocol/STArray.h>
13
#include <xrpl/protocol/STLedgerEntry.h>
14
#include <xrpl/protocol/STTx.h>
15
#include <xrpl/protocol/TER.h>
16
#include <xrpl/protocol/TxFormats.h>
17
#include <xrpl/protocol/XRPAmount.h>
18
19
#include <
vector
>
20
21
namespace
xrpl
{
22
23
void
24
ValidPermissionedDomain::visitEntry
(
bool
isDel,
SLE::ConstRef
before,
SLE::ConstRef
after
)
25
{
26
if
(before && before->getType() != ltPERMISSIONED_DOMAIN)
27
return
;
28
if
(
after
&&
after
->getType() != ltPERMISSIONED_DOMAIN)
29
return
;
30
31
auto
const
check = [isDel](
std::vector<SleStatus>
& sleStatus,
SLE::ConstRef
sle) {
32
auto
const
&
credentials
= sle->getFieldArray(sfAcceptedCredentials);
33
auto
const
sorted =
credentials::makeSorted
(
credentials
);
34
35
SleStatus
ss{
36
.credentialsSize =
credentials
.size(),
37
.isSorted =
false
,
38
.isUnique = !sorted.empty(),
39
.isDelete = isDel,
40
};
41
42
// If array have duplicates then all the other checks are invalid
43
if
(ss.
isUnique
)
44
{
45
unsigned
i = 0;
46
for
(
auto
const
& cred : sorted)
47
{
48
auto
const
& credTx =
credentials
[i++];
49
ss.
isSorted
=
50
(cred.first == credTx[sfIssuer]) && (cred.second == credTx[sfCredentialType]);
51
if
(!ss.
isSorted
)
52
break
;
53
}
54
}
55
sleStatus.
emplace_back
(ss);
56
};
57
58
if
(
after
)
59
check(
sleStatus_
,
after
);
60
}
61
62
bool
63
ValidPermissionedDomain::finalize
(
64
STTx
const
& tx,
65
TER
const
result,
66
XRPAmount
const
,
67
ReadView
const
& view,
68
beast::Journal
const
& j)
69
{
70
auto
const
check = [](
SleStatus
const
& sleStatus,
beast::Journal
const
& j) {
71
if
(!sleStatus.
credentialsSize
)
72
{
73
JLOG(j.
fatal
()) <<
"Invariant failed: permissioned domain with "
74
"no rules."
;
75
return
false
;
76
}
77
78
if
(sleStatus.
credentialsSize
>
kMaxPermissionedDomainCredentialsArraySize
)
79
{
80
JLOG(j.
fatal
()) <<
"Invariant failed: permissioned domain bad "
81
"credentials size "
82
<< sleStatus.
credentialsSize
;
83
return
false
;
84
}
85
86
if
(!sleStatus.
isUnique
)
87
{
88
JLOG(j.
fatal
()) <<
"Invariant failed: permissioned domain credentials "
89
"aren't unique"
;
90
return
false
;
91
}
92
93
if
(!sleStatus.
isSorted
)
94
{
95
JLOG(j.
fatal
()) <<
"Invariant failed: permissioned domain credentials "
96
"aren't sorted"
;
97
return
false
;
98
}
99
100
return
true
;
101
};
102
103
if
(view.
rules
().
enabled
(fixCleanup3_1_3))
104
{
105
// No permissioned domains should be affected if the transaction failed
106
if
(!
isTesSuccess
(result))
107
{
108
// If nothing changed, all is good. If there were changes, that's bad.
109
return
sleStatus_
.empty();
110
}
111
112
if
(
sleStatus_
.size() > 1)
113
{
114
JLOG(j.
fatal
()) <<
"Invariant failed: transaction affected more "
115
"than 1 permissioned domain entry."
;
116
return
false
;
117
}
118
119
switch
(tx.
getTxnType
())
120
{
121
case
ttPERMISSIONED_DOMAIN_SET: {
122
if
(
sleStatus_
.empty())
123
{
124
JLOG(j.
fatal
()) <<
"Invariant failed: no domain objects affected by "
125
"PermissionedDomainSet"
;
126
return
false
;
127
}
128
129
auto
const
& sleStatus =
sleStatus_
[0];
130
if
(sleStatus.
isDelete
)
131
{
132
JLOG(j.
fatal
()) <<
"Invariant failed: domain object "
133
"deleted by PermissionedDomainSet"
;
134
return
false
;
135
}
136
return
check(sleStatus, j);
137
}
138
case
ttPERMISSIONED_DOMAIN_DELETE: {
139
if
(
sleStatus_
.empty())
140
{
141
JLOG(j.
fatal
()) <<
"Invariant failed: no domain objects affected by "
142
"PermissionedDomainDelete"
;
143
return
false
;
144
}
145
146
if
(!
sleStatus_
[0].isDelete)
147
{
148
JLOG(j.
fatal
()) <<
"Invariant failed: domain object "
149
"modified, but not deleted by "
150
"PermissionedDomainDelete"
;
151
return
false
;
152
}
153
return
true
;
154
}
155
default
: {
156
if
(!
sleStatus_
.empty())
157
{
158
JLOG(j.
fatal
()) <<
"Invariant failed: "
<<
sleStatus_
.size()
159
<<
" domain object(s) affected by an "
160
"unauthorized transaction. "
161
<< tx.
getTxnType
();
162
return
false
;
163
}
164
return
true
;
165
}
166
}
167
}
168
else
169
{
170
if
(tx.
getTxnType
() != ttPERMISSIONED_DOMAIN_SET || !
isTesSuccess
(result) ||
171
sleStatus_
.empty())
172
return
true
;
173
return
check(
sleStatus_
[0], j);
174
}
175
}
176
177
}
// namespace xrpl
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
beast::Journal::fatal
Stream fatal() const
Definition
Journal.h:368
xrpl::ReadView
A view into a ledger.
Definition
ReadView.h:41
xrpl::ReadView::rules
virtual Rules const & rules() const =0
Returns the tx processing rules.
xrpl::Rules::enabled
bool enabled(UInt256 const &feature) const
Returns true if a feature is enabled.
Definition
Rules.cpp:182
xrpl::STLedgerEntry::ConstRef
std::shared_ptr< STLedgerEntry const > const & ConstRef
Definition
STLedgerEntry.h:37
xrpl::STTx
Definition
STTx.h:43
xrpl::STTx::getTxnType
TxType getTxnType() const
Definition
STTx.h:250
xrpl::ValidPermissionedDomain::visitEntry
void visitEntry(bool, SLE::ConstRef, SLE::ConstRef)
Definition
PermissionedDomainInvariant.cpp:24
xrpl::ValidPermissionedDomain::sleStatus_
std::vector< SleStatus > sleStatus_
Definition
PermissionedDomainInvariant.h:34
xrpl::ValidPermissionedDomain::finalize
bool finalize(STTx const &, TER const, XRPAmount const, ReadView const &, beast::Journal const &)
Definition
PermissionedDomainInvariant.cpp:63
xrpl::XRPAmount
Definition
XRPAmount.h:29
std::vector::emplace_back
T emplace_back(T... args)
xrpl::credentials
Definition
CredentialHelpers.h:22
xrpl::credentials::makeSorted
std::set< std::pair< AccountID, Slice > > makeSorted(STArray const &credentials)
Definition
CredentialHelpers.cpp:277
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::after
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition
View.cpp:668
xrpl::isTesSuccess
bool isTesSuccess(TER x) noexcept
Definition
TER.h:686
xrpl::TER
TERSubset< CanCvtToTER > TER
Definition
TER.h:657
xrpl::kMaxPermissionedDomainCredentialsArraySize
constexpr std::size_t kMaxPermissionedDomainCredentialsArraySize
The maximum number of credentials can be passed in array for permissioned domain.
Definition
Protocol.h:287
xrpl::ValidPermissionedDomain::SleStatus
Definition
PermissionedDomainInvariant.h:28
xrpl::ValidPermissionedDomain::SleStatus::isSorted
bool isSorted
Definition
PermissionedDomainInvariant.h:30
xrpl::ValidPermissionedDomain::SleStatus::isDelete
bool isDelete
Definition
PermissionedDomainInvariant.h:32
xrpl::ValidPermissionedDomain::SleStatus::isUnique
bool isUnique
Definition
PermissionedDomainInvariant.h:31
xrpl::ValidPermissionedDomain::SleStatus::credentialsSize
std::size_t credentialsSize
Definition
PermissionedDomainInvariant.h:29
vector
Generated by
1.17.0