20#include <xrpld/app/ledger/Ledger.h>
21#include <xrpld/app/main/Application.h>
22#include <xrpld/app/misc/AmendmentTable.h>
23#include <xrpld/app/misc/NetworkOPs.h>
24#include <xrpld/app/tx/detail/Change.h>
26#include <xrpl/basics/Log.h>
27#include <xrpl/ledger/Sandbox.h>
28#include <xrpl/protocol/Feature.h>
29#include <xrpl/protocol/Indexes.h>
30#include <xrpl/protocol/TxFlags.h>
44 if (account != beast::zero)
46 JLOG(ctx.
j.
warn()) <<
"Change: Bad source id";
52 if (!fee.native() || fee != beast::zero)
54 JLOG(ctx.
j.
warn()) <<
"Change: invalid fee";
61 JLOG(ctx.
j.
warn()) <<
"Change: Bad signature";
68 JLOG(ctx.
j.
warn()) <<
"Change: Bad sequence";
75 JLOG(ctx.
j.
warn()) <<
"Change: NegativeUNL not enabled";
89 JLOG(ctx.
j.
warn()) <<
"Change transaction against open ledger";
154 UNREACHABLE(
"ripple::Change::doApply : invalid transaction type");
163 account_ == beast::zero,
"ripple::Change::preCompute : zero account");
169 JLOG(
j_.
warn()) <<
"fixTrustLinesToSelf amendment activation code starting";
176 JLOG(
j_.
warn()) <<
id <<
": Unable to locate trustline";
180 if (tl->getType() != ltRIPPLE_STATE)
182 JLOG(
j_.
warn()) <<
id <<
": Unexpected type "
187 auto const& lo = tl->getFieldAmount(sfLowLimit);
188 auto const& hi = tl->getFieldAmount(sfHighLimit);
192 JLOG(
j_.
warn()) <<
id <<
": Trustline doesn't meet requirements";
196 if (
auto const page = tl->getFieldU64(sfLowNode); !sb.
dirRemove(
199 JLOG(
j_.
error()) <<
id <<
": failed to remove low entry from "
200 <<
toBase58(lo.getIssuer()) <<
":" << page
201 <<
" owner directory";
205 if (
auto const page = tl->getFieldU64(sfHighNode); !sb.
dirRemove(
208 JLOG(
j_.
error()) <<
id <<
": failed to remove high entry from "
209 <<
toBase58(hi.getIssuer()) <<
":" << page
210 <<
" owner directory";
224 JLOG(
j_.
warn()) <<
"Successfully deleted trustline " << id;
233 if (removeTrustLineToSelf(
236 "2F8F21EFCAFD7ACFB07D5BB04F0D2E18587820C7611305BB674A64EAB0FA71E1"sv}) &&
237 removeTrustLineToSelf(
240 "326035D5C0560A9DA8636545DD5A1B0DFCFF63E68D491B5522B767BB00564B1A"sv}))
242 JLOG(
j_.
warn()) <<
"fixTrustLinesToSelf amendment activation code "
243 "executed successfully";
257 if (!amendmentObject)
263 STVector256 amendments = amendmentObject->getFieldV256(sfAmendments);
265 if (
std::find(amendments.begin(), amendments.end(), amendment) !=
274 if (gotMajority && lostMajority)
277 STArray newMajorities(sfMajorities);
280 if (amendmentObject->isFieldPresent(sfMajorities))
283 amendmentObject->getFieldArray(sfMajorities);
284 for (
auto const& majority : oldMajorities)
286 if (majority.getFieldH256(sfAmendment) == amendment)
300 if (!found && lostMajority)
307 auto& entry = newMajorities.
back();
308 entry[sfAmendment] = amendment;
314 JLOG(
j_.
warn()) <<
"Unsupported amendment " << amendment
315 <<
" received a majority.";
318 else if (!lostMajority)
321 amendments.push_back(amendment);
322 amendmentObject->setFieldV256(sfAmendments, amendments);
324 if (amendment == fixTrustLinesToSelf)
331 JLOG(
j_.
error()) <<
"Unsupported amendment " << amendment
332 <<
" activated: server blocked.";
337 if (newMajorities.
empty())
338 amendmentObject->makeFieldAbsent(sfMajorities);
340 amendmentObject->setFieldArray(sfMajorities, newMajorities);
360 feeObject->at(field) = tx[field];
365 set(feeObject,
ctx_.
tx, sfReserveBaseDrops);
366 set(feeObject,
ctx_.
tx, sfReserveIncrementDrops);
368 feeObject->makeFieldAbsent(sfBaseFee);
369 feeObject->makeFieldAbsent(sfReferenceFeeUnits);
370 feeObject->makeFieldAbsent(sfReserveBase);
371 feeObject->makeFieldAbsent(sfReserveIncrement);
376 set(feeObject,
ctx_.
tx, sfReferenceFeeUnits);
378 set(feeObject,
ctx_.
tx, sfReserveIncrement);
383 JLOG(
j_.
warn()) <<
"Fees have been changed";
392 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, not a flag ledger, seq="
402 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, wrong Tx format.";
408 if (seq !=
view().seq())
410 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, wrong ledger seq=" << seq;
417 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, bad validator key";
421 JLOG(
j_.
info()) <<
"N-UNL: applyUNLModify, "
422 << (disabling ?
"ToDisable" :
"ToReEnable")
424 <<
" validator data:" <<
strHex(validator);
434 bool const found = [&] {
435 if (negUnlObject->isFieldPresent(sfDisabledValidators))
438 negUnlObject->getFieldArray(sfDisabledValidators);
439 for (
auto const& v : negUnl)
441 if (v.isFieldPresent(sfPublicKey) &&
442 v.getFieldVL(sfPublicKey) == validator)
452 if (negUnlObject->isFieldPresent(sfValidatorToDisable))
454 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, already has ToDisable";
459 if (negUnlObject->isFieldPresent(sfValidatorToReEnable))
461 if (negUnlObject->getFieldVL(sfValidatorToReEnable) == validator)
464 <<
"N-UNL: applyUNLModify, ToDisable is same as ToReEnable";
473 <<
"N-UNL: applyUNLModify, ToDisable already in negative UNL";
477 negUnlObject->setFieldVL(sfValidatorToDisable, validator);
482 if (negUnlObject->isFieldPresent(sfValidatorToReEnable))
484 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, already has ToReEnable";
489 if (negUnlObject->isFieldPresent(sfValidatorToDisable))
491 if (negUnlObject->getFieldVL(sfValidatorToDisable) == validator)
494 <<
"N-UNL: applyUNLModify, ToReEnable is same as ToDisable";
503 <<
"N-UNL: applyUNLModify, ToReEnable is not in negative UNL";
507 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)
static NotTEC preflight(PreflightContext 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
Blob getSigningPubKey() const
Blob getSignature() 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.
NotTEC preflight0(PreflightContext const &ctx)
Performs early sanity checks on the txid.
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)
bool isTesSuccess(TER x) noexcept
constexpr std::uint32_t tfLostMajority
TERSubset< CanCvtToNotTEC > NotTEC
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)