1#include <xrpld/app/ledger/Ledger.h>
2#include <xrpld/app/tx/detail/SetSignerList.h>
4#include <xrpl/basics/Log.h>
5#include <xrpl/ledger/ApplyView.h>
6#include <xrpl/protocol/Feature.h>
7#include <xrpl/protocol/Indexes.h>
8#include <xrpl/protocol/STArray.h>
9#include <xrpl/protocol/STObject.h>
10#include <xrpl/protocol/STTx.h>
11#include <xrpl/protocol/TxFlags.h>
35 auto const quorum = tx[sfSignerQuorum];
40 if (quorum && hasSignerEntries)
47 std::sort(signers->begin(), signers->end());
50 sign = std::move(*signers);
53 else if ((quorum == 0) && !hasSignerEntries)
80 <<
"Malformed transaction: Invalid signer set list format.";
119 UNREACHABLE(
"ripple::SetSignerList::doApply : invalid operation");
131 "ripple::SetSignerList::preCompute : result is tesSUCCESS");
134 "ripple::SetSignerList::preCompute : result is known operation");
165 "ripple::signerCountBasedOwnerCountDelta : minimum signers");
168 "ripple::signerCountBasedOwnerCountDelta : maximum signers");
169 return 2 +
static_cast<int>(entryCount);
176 Keylet const& accountKeylet,
177 Keylet const& ownerDirKeylet,
178 Keylet const& signerListKeylet,
192 int removeFromOwnerCount = -1;
195 STArray const& actualList = signers->getFieldArray(sfSignerEntries);
196 removeFromOwnerCount =
202 auto const hint = (*signers)[sfOwnerNode];
204 if (!view.
dirRemove(ownerDirKeylet, hint, signerListKeylet.
key,
false))
207 JLOG(j.
fatal()) <<
"Unable to delete SignerList from owner.";
214 view.
peek(accountKeylet),
215 removeFromOwnerCount,
235 app,
view, accountKeylet, ownerDirKeylet, signerListKeylet, j);
252 JLOG(j.
trace()) <<
"Too many or too few signers in signer list.";
260 "ripple::SetSignerList::validateQuorumAndSignerEntries : sorted "
264 JLOG(j.
trace()) <<
"Duplicate signers in signer list";
271 for (
auto const& signer : signers)
276 JLOG(j.
trace()) <<
"Every signer must have a positive weight.";
280 allSignersWeight += signer.weight;
282 if (signer.account == account)
284 JLOG(j.
trace()) <<
"A signer may not self reference account.";
290 if ((quorum <= 0) || (allSignersWeight < quorum))
292 JLOG(j.
trace()) <<
"Quorum is unreachable";
317 auto const sle =
view().
peek(accountKeylet);
324 constexpr int addedOwnerCount = 1;
347 <<
": " << (page ?
"success" :
"failure");
352 signerList->setFieldU64(sfOwnerNode, *page);
371 (!ledgerEntry->isFieldPresent(sfRegularKey)))
377 ctx_.
app,
view(), accountKeylet, ownerDirKeylet, signerListKeylet,
j_);
388 ledgerEntry->setAccountID(sfOwner,
account_);
390 ledgerEntry->setFieldU32(sfSignerQuorum,
quorum_);
393 ledgerEntry->setFieldU32(sfFlags, flags);
402 obj[sfAccount] = entry.account;
403 obj[sfSignerWeight] = entry.weight;
412 ledgerEntry->setFieldArray(sfSignerEntries, toLedger);
T adjacent_find(T... args)
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
virtual beast::Journal journal(std::string const &name)=0
Writeable view to a ledger, for applying a transaction.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void insert(std::shared_ptr< SLE > const &sle)=0
Insert a new state SLE.
std::optional< std::uint64_t > dirInsert(Keylet const &directory, uint256 const &key, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
Insert an entry to a directory.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual Rules const & rules() const =0
Returns the tx processing rules.
Rules controlling protocol behavior.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
void push_back(STObject const &object)
AccountID getAccountID(SField const &field) const
void setFieldH256(SField const &field, uint256 const &)
bool isFieldPresent(SField const &field) const
static STObject makeInnerObject(SField const &name)
void reserve(std::size_t n)
static constexpr std::size_t minMultiSigners
static constexpr std::size_t maxMultiSigners
void writeSignersToSLE(SLE::pointer const &ledgerEntry, std::uint32_t flags) const
static NotTEC preflight(PreflightContext const &ctx)
static NotTEC validateQuorumAndSignerEntries(std::uint32_t quorum, std::vector< SignerEntries::SignerEntry > const &signers, AccountID const &account, beast::Journal j, Rules const &)
void preCompute() override
static TER removeFromLedger(Application &app, ApplyView &view, AccountID const &account, beast::Journal j)
std::vector< SignerEntries::SignerEntry > signers_
static std::tuple< NotTEC, std::uint32_t, std::vector< SignerEntries::SignerEntry >, Operation > determineOperation(STTx const &tx, ApplyFlags flags, beast::Journal j)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
static Expected< std::vector< SignerEntry >, NotTEC > deserialize(STObject const &obj, beast::Journal journal, std::string_view annotation)
virtual void preCompute()
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet signers(AccountID const &account) noexcept
A SignerList.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
static int signerCountBasedOwnerCountDelta(std::size_t entryCount, Rules const &rules)
static TER removeSignersFromLedger(Application &app, ApplyView &view, Keylet const &accountKeylet, Keylet const &ownerDirKeylet, Keylet const &signerListKeylet, beast::Journal j)
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
static std::uint32_t const DEFAULT_SIGNER_LIST_ID
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &message)
Generate a signature for a message.
@ tecINSUFFICIENT_RESERVE
constexpr std::uint32_t tfUniversalMask
TERSubset< CanCvtToTER > TER
TERSubset< CanCvtToNotTEC > NotTEC
XRPAmount accountReserve(std::size_t ownerCount) const
Returns the account reserve given the owner count, in drops.
A pair of SHAMap key and LedgerEntryType.
State information when preflighting a tx.