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");
169 "ripple::signerCountBasedOwnerCountDelta : minimum signers");
172 "ripple::signerCountBasedOwnerCountDelta : maximum signers");
173 return 2 +
static_cast<int>(entryCount);
180 Keylet const& accountKeylet,
181 Keylet const& ownerDirKeylet,
182 Keylet const& signerListKeylet,
196 int removeFromOwnerCount = -1;
199 STArray const& actualList = signers->getFieldArray(sfSignerEntries);
200 removeFromOwnerCount =
206 auto const hint = (*signers)[sfOwnerNode];
208 if (!view.
dirRemove(ownerDirKeylet, hint, signerListKeylet.
key,
false))
211 JLOG(j.
fatal()) <<
"Unable to delete SignerList from owner.";
218 view.
peek(accountKeylet),
219 removeFromOwnerCount,
239 app,
view, accountKeylet, ownerDirKeylet, signerListKeylet, j);
256 JLOG(j.
trace()) <<
"Too many or too few signers in signer list.";
264 "ripple::SetSignerList::validateQuorumAndSignerEntries : sorted "
268 JLOG(j.
trace()) <<
"Duplicate signers in signer list";
273 bool const expandedSignerList = rules.
enabled(featureExpandedSignerList);
278 for (
auto const& signer : signers)
283 JLOG(j.
trace()) <<
"Every signer must have a positive weight.";
287 allSignersWeight += signer.weight;
289 if (signer.account == account)
291 JLOG(j.
trace()) <<
"A signer may not self reference account.";
295 if (signer.tag && !expandedSignerList)
297 JLOG(j.
trace()) <<
"Malformed transaction: sfWalletLocator "
298 "specified in SignerEntry "
299 <<
"but featureExpandedSignerList is not enabled.";
306 if ((quorum <= 0) || (allSignersWeight < quorum))
308 JLOG(j.
trace()) <<
"Quorum is unreachable";
333 auto const sle =
view().
peek(accountKeylet);
341 int addedOwnerCount{1};
370 <<
": " << (page ?
"success" :
"failure");
375 signerList->setFieldU64(sfOwnerNode, *page);
394 (!ledgerEntry->isFieldPresent(sfRegularKey)))
400 ctx_.
app,
view(), accountKeylet, ownerDirKeylet, signerListKeylet,
j_);
411 ledgerEntry->setAccountID(sfOwner,
account_);
413 ledgerEntry->setFieldU32(sfSignerQuorum,
quorum_);
416 ledgerEntry->setFieldU32(sfFlags, flags);
418 bool const expandedSignerList =
428 obj[sfAccount] = entry.account;
429 obj[sfSignerWeight] = entry.weight;
433 if (expandedSignerList && entry.tag)
438 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 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 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.