20#include <xrpld/app/ledger/Ledger.h>
21#include <xrpld/app/tx/detail/SetSignerList.h>
23#include <xrpl/basics/Log.h>
24#include <xrpl/ledger/ApplyView.h>
25#include <xrpl/protocol/Feature.h>
26#include <xrpl/protocol/Indexes.h>
27#include <xrpl/protocol/STArray.h>
28#include <xrpl/protocol/STObject.h>
29#include <xrpl/protocol/STTx.h>
30#include <xrpl/protocol/TxFlags.h>
54 auto const quorum = tx[sfSignerQuorum];
59 if (quorum && hasSignerEntries)
66 std::sort(signers->begin(), signers->end());
69 sign = std::move(*signers);
72 else if ((quorum == 0) && !hasSignerEntries)
89 JLOG(ctx.
j.
debug()) <<
"SetSignerList: invalid flags.";
102 <<
"Malformed transaction: Invalid signer set list format.";
140 UNREACHABLE(
"ripple::SetSignerList::doApply : invalid operation");
151 "ripple::SetSignerList::preCompute : result is tesSUCCESS");
154 "ripple::SetSignerList::preCompute : result is known operation");
189 "ripple::signerCountBasedOwnerCountDelta : minimum signers");
192 "ripple::signerCountBasedOwnerCountDelta : maximum signers");
193 return 2 +
static_cast<int>(entryCount);
200 Keylet const& accountKeylet,
201 Keylet const& ownerDirKeylet,
202 Keylet const& signerListKeylet,
216 int removeFromOwnerCount = -1;
219 STArray const& actualList = signers->getFieldArray(sfSignerEntries);
220 removeFromOwnerCount =
226 auto const hint = (*signers)[sfOwnerNode];
228 if (!view.
dirRemove(ownerDirKeylet, hint, signerListKeylet.
key,
false))
230 JLOG(j.
fatal()) <<
"Unable to delete SignerList from owner.";
236 view.
peek(accountKeylet),
237 removeFromOwnerCount,
257 app,
view, accountKeylet, ownerDirKeylet, signerListKeylet, j);
274 JLOG(j.
trace()) <<
"Too many or too few signers in signer list.";
282 "ripple::SetSignerList::validateQuorumAndSignerEntries : sorted "
286 JLOG(j.
trace()) <<
"Duplicate signers in signer list";
291 bool const expandedSignerList = rules.
enabled(featureExpandedSignerList);
296 for (
auto const& signer : signers)
301 JLOG(j.
trace()) <<
"Every signer must have a positive weight.";
305 allSignersWeight += signer.weight;
307 if (signer.account == account)
309 JLOG(j.
trace()) <<
"A signer may not self reference account.";
313 if (signer.tag && !expandedSignerList)
315 JLOG(j.
trace()) <<
"Malformed transaction: sfWalletLocator "
316 "specified in SignerEntry "
317 <<
"but featureExpandedSignerList is not enabled.";
324 if ((quorum <= 0) || (allSignersWeight < quorum))
326 JLOG(j.
trace()) <<
"Quorum is unreachable";
351 auto const sle =
view().
peek(accountKeylet);
359 int addedOwnerCount{1};
388 <<
": " << (page ?
"success" :
"failure");
393 signerList->setFieldU64(sfOwnerNode, *page);
412 (!ledgerEntry->isFieldPresent(sfRegularKey)))
418 ctx_.
app,
view(), accountKeylet, ownerDirKeylet, signerListKeylet,
j_);
429 ledgerEntry->setAccountID(sfOwner,
account_);
431 ledgerEntry->setFieldU32(sfSignerQuorum,
quorum_);
434 ledgerEntry->setFieldU32(sfFlags, flags);
436 bool const expandedSignerList =
446 obj[sfAccount] = entry.account;
447 obj[sfSignerWeight] = entry.weight;
451 if (expandedSignerList && entry.tag)
456 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)
std::uint32_t getFlags() const
static std::size_t const minMultiSigners
static std::size_t maxMultiSigners(Rules const *rules=0)
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 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
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &message)
Generate a signature for a message.
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
@ tecINSUFFICIENT_RESERVE
bool isTesSuccess(TER x) noexcept
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.