1#include <xrpl/tx/invariants/CosignerInvariant.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/protocol/AccountID.h>
8#include <xrpl/protocol/Feature.h>
9#include <xrpl/protocol/Indexes.h>
10#include <xrpl/protocol/Keylet.h>
11#include <xrpl/protocol/LedgerFormats.h>
12#include <xrpl/protocol/Protocol.h>
13#include <xrpl/protocol/SField.h>
14#include <xrpl/protocol/STArray.h>
15#include <xrpl/protocol/STLedgerEntry.h>
16#include <xrpl/protocol/STObject.h>
17#include <xrpl/protocol/STTx.h>
18#include <xrpl/protocol/SeqProxy.h>
19#include <xrpl/protocol/TER.h>
20#include <xrpl/protocol/TxFormats.h>
21#include <xrpl/protocol/XRPAmount.h>
34validSignerArray(
STArray const& signers, std::size_t limit,
SField const& elementName)
39 std::optional<AccountID> previous;
40 for (
auto const& signer : signers)
42 if (signer.getFName() != elementName || !signer.isFieldPresent(sfAccount))
45 auto const account = signer.getAccountID(sfAccount);
46 if (previous && account <= *previous)
54validNestedSigners(
STObject const& signature)
56 return !signature.isFieldPresent(sfSigners) ||
61validSignerArrays(
STObject const& proposedTx)
63 if (!validNestedSigners(proposedTx))
66 for (
auto const* field :
67 std::array<SField const*, 2>{&sfCounterpartySignature, &sfSponsorSignature})
69 if (proposedTx.isFieldPresent(*field) &&
70 !validNestedSigners(proposedTx.getFieldObject(*field)))
74 if (!proposedTx.isFieldPresent(sfBatchSigners))
77 auto const& batchSigners = proposedTx.getFieldArray(sfBatchSigners);
82 batchSigners, [](
auto const& batchSigner) {
return validNestedSigners(batchSigner); });
89 auto const& proposedTx =
proposal.getFieldObject(sfProposedTransaction);
91 proposedTx.getAccountID(sfAccount),
105 if (!
after || (before && before->getType() !=
after->getType()))
108 auto const type =
after->getType();
114 if (type == ltTICKET)
121 after->getAccountID(sfAccount),
after->getFieldU32(sfTicketSequence)));
126 if (type != ltTRANSACTION_PROPOSAL)
145 if (!isDelete && !validSignerArrays(
after->getFieldObject(sfProposedTransaction)))
162 JLOG(j.
fatal()) <<
"Invariant failed: TransactionProposal signer arrays are not canonical.";
179 bool effectsMatch =
false;
180 if (tx.
getTxnType() == ttTRANSACTION_PROPOSAL_CREATE)
184 else if (tx.
getTxnType() == ttTRANSACTION_PROPOSAL_CANCEL)
198 tx.
getTxnType() == ttSPONSORSHIP_TRANSFER && succeeded ? 1 : 0;
205 <<
"Invariant failed: TransactionProposal changes do not match transaction result.";
218 <<
"Invariant failed: TransactionProposal outlived the Ticket it is keyed to.";
A generic endpoint for log messages.
UInt size() const
Number of values in array or object.
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
bool enabled(UInt256 const &feature) const
Returns true if a feature is enabled.
std::shared_ptr< STLedgerEntry const > const & ConstRef
static constexpr std::size_t kMaxMultiSigners
TxType getTxnType() const
static constexpr SeqProxy rawTicket(std::uint32_t v)
Factory function to return a ticket-based SeqProxy.
std::set< uint256 > deletedTickets_
bool invalidSignerArrays_
std::vector< uint256 > ticketsOfDeletedProposals_
bool finalize(STTx const &tx, TER result, XRPAmount, ReadView const &view, beast::Journal const &j) const
void visitEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after)
std::vector< Keylet > proposalsOfDeletedTickets_
Keylet computation functions.
Keylet txProposal(AccountID const &target, std::uint32_t ticketSequence) noexcept
A TransactionProposal.
Keylet ticket(AccountID const &id, SeqProxy const &ticketSeq)
A ticket belonging to an account.
Keylet account(AccountID const &id) noexcept
AccountID root.
json::Value signers(Account const &account, std::uint32_t quorum, std::vector< Signer > const &v)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::size_t kMaxBatchSigners
The maximum number of batch signers.
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
bool isTesSuccess(TER x) noexcept
TERSubset< CanCvtToTER > TER
A pair of SHAMap key and LedgerEntryType.