1#include <xrpld/app/ledger/Ledger.h> 
    2#include <xrpld/app/main/Application.h> 
    3#include <xrpld/app/misc/AmendmentTable.h> 
    4#include <xrpld/app/misc/NetworkOPs.h> 
    5#include <xrpld/app/tx/detail/Change.h> 
    7#include <xrpl/basics/Log.h> 
    8#include <xrpl/ledger/Sandbox.h> 
    9#include <xrpl/protocol/Feature.h> 
   10#include <xrpl/protocol/Indexes.h> 
   11#include <xrpl/protocol/TxFlags.h> 
   26    if (account != beast::zero)
 
   28        JLOG(ctx.
j.
warn()) << 
"Change: Bad source id";
 
   34    if (!fee.native() || fee != beast::zero)
 
   36        JLOG(ctx.
j.
warn()) << 
"Change: invalid fee";
 
   43        JLOG(ctx.
j.
warn()) << 
"Change: Bad signature";
 
   50        JLOG(ctx.
j.
warn()) << 
"Change: Bad sequence";
 
   57        JLOG(ctx.
j.
warn()) << 
"Change: NegativeUNL not enabled";
 
 
   71        JLOG(ctx.
j.
warn()) << 
"Change transaction against open ledger";
 
 
  137            UNREACHABLE(
"ripple::Change::doApply : invalid transaction type");
 
 
  147        account_ == beast::zero, 
"ripple::Change::preCompute : zero account");
 
 
  153    JLOG(
j_.
warn()) << 
"fixTrustLinesToSelf amendment activation code starting";
 
  160            JLOG(
j_.
warn()) << 
id << 
": Unable to locate trustline";
 
  164        if (tl->getType() != ltRIPPLE_STATE)
 
  166            JLOG(
j_.
warn()) << 
id << 
": Unexpected type " 
  171        auto const& lo = tl->getFieldAmount(sfLowLimit);
 
  172        auto const& hi = tl->getFieldAmount(sfHighLimit);
 
  176            JLOG(
j_.
warn()) << 
id << 
": Trustline doesn't meet requirements";
 
  180        if (
auto const page = tl->getFieldU64(sfLowNode); !sb.
dirRemove(
 
  183            JLOG(
j_.
error()) << 
id << 
": failed to remove low entry from " 
  184                             << 
toBase58(lo.getIssuer()) << 
":" << page
 
  185                             << 
" owner directory";
 
  189        if (
auto const page = tl->getFieldU64(sfHighNode); !sb.
dirRemove(
 
  192            JLOG(
j_.
error()) << 
id << 
": failed to remove high entry from " 
  193                             << 
toBase58(hi.getIssuer()) << 
":" << page
 
  194                             << 
" owner directory";
 
  208        JLOG(
j_.
warn()) << 
"Successfully deleted trustline " << id;
 
  217    if (removeTrustLineToSelf(
 
  220                "2F8F21EFCAFD7ACFB07D5BB04F0D2E18587820C7611305BB674A64EAB0FA71E1"sv}) &&
 
  221        removeTrustLineToSelf(
 
  224                "326035D5C0560A9DA8636545DD5A1B0DFCFF63E68D491B5522B767BB00564B1A"sv}))
 
  226        JLOG(
j_.
warn()) << 
"fixTrustLinesToSelf amendment activation code " 
  227                           "executed successfully";
 
 
  241    if (!amendmentObject)
 
  247    STVector256 amendments = amendmentObject->getFieldV256(sfAmendments);
 
  249    if (
std::find(amendments.begin(), amendments.end(), amendment) !=
 
  258    if (gotMajority && lostMajority)
 
  261    STArray newMajorities(sfMajorities);
 
  264    if (amendmentObject->isFieldPresent(sfMajorities))
 
  267            amendmentObject->getFieldArray(sfMajorities);
 
  268        for (
auto const& majority : oldMajorities)
 
  270            if (majority.getFieldH256(sfAmendment) == amendment)
 
  284    if (!found && lostMajority)
 
  291        auto& entry = newMajorities.
back();
 
  292        entry[sfAmendment] = amendment;
 
  298            JLOG(
j_.
warn()) << 
"Unsupported amendment " << amendment
 
  299                            << 
" received a majority.";
 
  302    else if (!lostMajority)
 
  305        amendments.push_back(amendment);
 
  306        amendmentObject->setFieldV256(sfAmendments, amendments);
 
  308        if (amendment == fixTrustLinesToSelf)
 
  315            JLOG(
j_.
error()) << 
"Unsupported amendment " << amendment
 
  316                             << 
" activated: server blocked.";
 
  321    if (newMajorities.
empty())
 
  322        amendmentObject->makeFieldAbsent(sfMajorities);
 
  324        amendmentObject->setFieldArray(sfMajorities, newMajorities);
 
 
  344        feeObject->at(field) = tx[field];
 
  349        set(feeObject, 
ctx_.
tx, sfReserveBaseDrops);
 
  350        set(feeObject, 
ctx_.
tx, sfReserveIncrementDrops);
 
  352        feeObject->makeFieldAbsent(sfBaseFee);
 
  353        feeObject->makeFieldAbsent(sfReferenceFeeUnits);
 
  354        feeObject->makeFieldAbsent(sfReserveBase);
 
  355        feeObject->makeFieldAbsent(sfReserveIncrement);
 
  360        set(feeObject, 
ctx_.
tx, sfReferenceFeeUnits);
 
  362        set(feeObject, 
ctx_.
tx, sfReserveIncrement);
 
  367    JLOG(
j_.
warn()) << 
"Fees have been changed";
 
 
  376        JLOG(
j_.
warn()) << 
"N-UNL: applyUNLModify, not a flag ledger, seq=" 
  386        JLOG(
j_.
warn()) << 
"N-UNL: applyUNLModify, wrong Tx format.";
 
  392    if (seq != 
view().seq())
 
  394        JLOG(
j_.
warn()) << 
"N-UNL: applyUNLModify, wrong ledger seq=" << seq;
 
  401        JLOG(
j_.
warn()) << 
"N-UNL: applyUNLModify, bad validator key";
 
  405    JLOG(
j_.
info()) << 
"N-UNL: applyUNLModify, " 
  406                    << (disabling ? 
"ToDisable" : 
"ToReEnable")
 
  408                    << 
" validator data:" << 
strHex(validator);
 
  418    bool const found = [&] {
 
  419        if (negUnlObject->isFieldPresent(sfDisabledValidators))
 
  422                negUnlObject->getFieldArray(sfDisabledValidators);
 
  423            for (
auto const& v : negUnl)
 
  425                if (v.isFieldPresent(sfPublicKey) &&
 
  426                    v.getFieldVL(sfPublicKey) == validator)
 
  436        if (negUnlObject->isFieldPresent(sfValidatorToDisable))
 
  438            JLOG(
j_.
warn()) << 
"N-UNL: applyUNLModify, already has ToDisable";
 
  443        if (negUnlObject->isFieldPresent(sfValidatorToReEnable))
 
  445            if (negUnlObject->getFieldVL(sfValidatorToReEnable) == validator)
 
  448                    << 
"N-UNL: applyUNLModify, ToDisable is same as ToReEnable";
 
  457                << 
"N-UNL: applyUNLModify, ToDisable already in negative UNL";
 
  461        negUnlObject->setFieldVL(sfValidatorToDisable, validator);
 
  466        if (negUnlObject->isFieldPresent(sfValidatorToReEnable))
 
  468            JLOG(
j_.
warn()) << 
"N-UNL: applyUNLModify, already has ToReEnable";
 
  473        if (negUnlObject->isFieldPresent(sfValidatorToDisable))
 
  475            if (negUnlObject->getFieldVL(sfValidatorToDisable) == validator)
 
  478                    << 
"N-UNL: applyUNLModify, ToReEnable is same as ToDisable";
 
  487                << 
"N-UNL: applyUNLModify, ToReEnable is not in negative UNL";
 
  491        negUnlObject->setFieldVL(sfValidatorToReEnable, validator);
 
 
virtual bool isSupported(uint256 const &amendment) const =0
 
virtual bool enable(uint256 const &amendment)=0
 
virtual NetworkOPs & getOPs()=0
 
virtual AmendmentTable & getAmendmentTable()=0
 
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
 
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.
 
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
 
void activateTrustLinesToSelfFix()
 
void preCompute() override
 
static TER preclaim(PreclaimContext const &ctx)
 
virtual void setAmendmentBlocked()=0
 
NetClock::time_point parentCloseTime() const
Returns the close time of the previous ledger.
 
virtual bool open() const =0
Returns true if this reflects an open ledger.
 
LedgerIndex seq() const
Returns the sequence number of the base ledger.
 
virtual Rules const & rules() const =0
Returns the tx processing rules.
 
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
 
void push_back(STObject const &object)
 
unsigned char getFieldU8(SField const &field) const
 
Blob getFieldVL(SField const &field) const
 
AccountID getAccountID(SField const &field) const
 
std::uint32_t getFieldU32(SField const &field) const
 
STAmount const & getFieldAmount(SField const &field) const
 
bool isFieldPresent(SField const &field) const
 
static STObject makeInnerObject(SField const &name)
 
std::uint32_t getFlags() const
 
uint256 getFieldH256(SField const &field) const
 
static Blob getSignature(STObject const &sigObject)
 
Blob getSigningPubKey() const
 
TxType getTxnType() const
 
Discardable, editable view to a ledger.
 
void erase(std::shared_ptr< SLE > const &sle) override
Remove a peeked SLE.
 
std::shared_ptr< SLE > peek(Keylet const &k) override
Prepare to modify the SLE associated with key.
 
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
 
Keylet const & negativeUNL() noexcept
The (fixed) index of the object containing the ledger negativeUNL.
 
Keylet const & amendments() noexcept
The index of the amendment table.
 
Keylet account(AccountID const &id) noexcept
AccountID root.
 
Keylet const & fees() noexcept
The (fixed) index of the object containing the ledger fees.
 
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
 
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.
 
constexpr std::uint32_t tfGotMajority
 
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::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
 
bool isFlagLedger(LedgerIndex seq)
Returns true if the given ledgerIndex is a flag ledgerIndex.
 
std::string strHex(FwdIt begin, FwdIt end)
 
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
 
constexpr std::uint32_t tfLostMajority
 
NotTEC preflight0(PreflightContext const &ctx, std::uint32_t flagMask)
Performs early sanity checks on the txid.
 
State information when determining if a tx is likely to claim a fee.
 
State information when preflighting a tx.
 
T time_since_epoch(T... args)