1#include <xrpl/tx/transactors/account/SignerListSet.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/beast/utility/instrumentation.h>
6#include <xrpl/core/ServiceRegistry.h>
7#include <xrpl/ledger/ApplyView.h>
8#include <xrpl/ledger/ReadView.h>
9#include <xrpl/ledger/helpers/AccountRootHelpers.h>
10#include <xrpl/ledger/helpers/DirectoryHelpers.h>
11#include <xrpl/protocol/AccountID.h>
12#include <xrpl/protocol/Feature.h>
13#include <xrpl/protocol/Indexes.h>
14#include <xrpl/protocol/Keylet.h>
15#include <xrpl/protocol/LedgerFormats.h>
16#include <xrpl/protocol/SField.h>
17#include <xrpl/protocol/STArray.h>
18#include <xrpl/protocol/STLedgerEntry.h>
19#include <xrpl/protocol/STObject.h>
20#include <xrpl/protocol/STTx.h>
21#include <xrpl/protocol/TER.h>
22#include <xrpl/protocol/TxFlags.h>
23#include <xrpl/protocol/XRPAmount.h>
24#include <xrpl/tx/SignerEntries.h>
25#include <xrpl/tx/Transactor.h>
47 auto const quorum = tx[sfSignerQuorum];
52 if ((quorum != 0u) && hasSignerEntries)
62 sign = std::move(*signers);
65 else if ((quorum == 0) && !hasSignerEntries)
86 return std::get<0>(result);
91 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: Invalid signer set list format.";
100 std::get<1>(result), std::get<2>(result), account, ctx.
j, ctx.
rules);
126 UNREACHABLE(
"xrpl::SignerListSet::doApply : invalid operation");
138 "xrpl::SignerListSet::preCompute : result is tesSUCCESS");
141 "xrpl::SignerListSet::preCompute : result is known operation");
145 do_ = std::get<3>(result);
172 "xrpl::signerCountBasedOwnerCountDelta : minimum signers");
175 "xrpl::signerCountBasedOwnerCountDelta : maximum signers");
176 return 2 +
static_cast<int>(entryCount);
183 Keylet const& accountKeylet,
184 Keylet const& ownerDirKeylet,
185 Keylet const& signerListKeylet,
199 int removeFromOwnerCount = -1;
200 if (!signers->isFlag(lsfOneOwnerCount))
202 STArray const& actualList = signers->getFieldArray(sfSignerEntries);
203 removeFromOwnerCount =
208 auto const hint = (*signers)[sfOwnerNode];
210 if (!view.
dirRemove(ownerDirKeylet, hint, signerListKeylet.
key,
false))
213 JLOG(j.
fatal()) <<
"Unable to delete SignerList from owner.";
219 view, view.
peek(accountKeylet), removeFromOwnerCount, registry.
getJournal(
"View"));
238 registry,
view, accountKeylet, ownerDirKeylet, signerListKeylet, j);
254 JLOG(j.
trace()) <<
"Too many or too few signers in signer list.";
262 "xrpl::SignerListSet::validateQuorumAndSignerEntries : sorted "
266 JLOG(j.
trace()) <<
"Duplicate signers in signer list";
273 for (
auto const& signer : signers)
278 JLOG(j.
trace()) <<
"Every signer must have a positive weight.";
282 allSignersWeight += signer.weight;
284 if (signer.account == account)
286 JLOG(j.
trace()) <<
"A signer may not self reference account.";
292 if ((quorum <= 0) || (allSignersWeight < quorum))
294 JLOG(j.
trace()) <<
"Quorum is unreachable";
311 ctx_.registry,
view(), accountKeylet, ownerDirKeylet, signerListKeylet,
j_))
314 auto const sle =
view().
peek(accountKeylet);
321 static constexpr int kAddedOwnerCount = 1;
337 auto viewJ =
ctx_.registry.get().getJournal(
"View");
343 << (page ?
"success" :
"failure");
348 signerList->setFieldU64(sfOwnerNode, *page);
366 if ((ledgerEntry->isFlag(lsfDisableMaster)) && (!ledgerEntry->isFieldPresent(sfRegularKey)))
372 ctx_.registry,
view(), accountKeylet, ownerDirKeylet, signerListKeylet,
j_);
379 if (
ctx_.view().rules().enabled(fixIncludeKeyletFields))
381 ledgerEntry->setAccountID(sfOwner,
accountID_);
383 ledgerEntry->setFieldU32(sfSignerQuorum,
quorum_);
386 ledgerEntry->setFieldU32(sfFlags, flags);
395 obj[sfAccount] = entry.account;
396 obj[sfSignerWeight] = entry.weight;
405 ledgerEntry->setFieldArray(sfSignerEntries, toLedger);
T adjacent_find(T... args)
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
const_iterator begin() const
UInt size() const
Number of values in array or object.
const_iterator end() const
Writeable view to a ledger, for applying a transaction.
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void insert(SLE::ref sle)=0
Insert a new state SLE.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void erase(SLE::ref sle)=0
Remove a peeked SLE.
virtual Rules const & rules() const =0
Returns the tx processing rules.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
Rules controlling protocol behavior.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
void pushBack(STObject const &object)
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const & const_ref
void reserve(std::size_t n)
bool isFieldPresent(SField const &field) const
static STObject makeInnerObject(SField const &name)
AccountID getAccountID(SField const &field) const
void setFieldH256(SField const &field, uint256 const &)
static constexpr std::size_t kMinMultiSigners
static constexpr std::size_t kMaxMultiSigners
Service registry for dependency injection.
virtual beast::Journal getJournal(std::string const &name)=0
static std::expected< std::vector< SignerEntry >, NotTEC > deserialize(STObject const &obj, beast::Journal journal, std::string_view annotation)
static NotTEC preflight(PreflightContext const &ctx)
void preCompute() override
static std::tuple< NotTEC, std::uint32_t, std::vector< SignerEntries::SignerEntry >, Operation > determineOperation(STTx const &tx, ApplyFlags flags, beast::Journal j)
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
static NotTEC validateQuorumAndSignerEntries(std::uint32_t quorum, std::vector< SignerEntries::SignerEntry > const &signers, AccountID const &account, beast::Journal j, Rules const &)
std::vector< SignerEntries::SignerEntry > signers_
static TER removeFromLedger(ServiceRegistry ®istry, ApplyView &view, AccountID const &account, beast::Journal j)
void writeSignersToSLE(SLE::pointer const &ledgerEntry, std::uint32_t flags) const
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
AccountID const accountID_
virtual void preCompute()
Keylet signerList(AccountID const &account) noexcept
A SignerList.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
static std::uint32_t const kDefaultSignerListId
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
TERSubset< CanCvtToNotTEC > NotTEC
void adjustOwnerCount(ApplyView &view, SLE::ref sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
Returns a function that sets the owner on a directory SLE.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
static int signerCountBasedOwnerCountDelta(std::size_t entryCount, Rules const &rules)
bool isTesSuccess(TER x) noexcept
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &message)
Generate a signature for a message.
TERSubset< CanCvtToTER > TER
@ tecINSUFFICIENT_RESERVE
constexpr FlagValue tfUniversalMask
static TER removeSignersFromLedger(ServiceRegistry ®istry, ApplyView &view, Keylet const &accountKeylet, Keylet const &ownerDirKeylet, Keylet const &signerListKeylet, beast::Journal j)
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.