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>
25#include <xrpld/ledger/Sandbox.h>
26#include <xrpl/basics/Log.h>
27#include <xrpl/protocol/Feature.h>
28#include <xrpl/protocol/Indexes.h>
29#include <xrpl/protocol/TxFlags.h>
42 if (account != beast::zero)
44 JLOG(ctx.
j.
warn()) <<
"Change: Bad source id";
50 if (!fee.native() || fee != beast::zero)
52 JLOG(ctx.
j.
warn()) <<
"Change: invalid fee";
59 JLOG(ctx.
j.
warn()) <<
"Change: Bad signature";
66 JLOG(ctx.
j.
warn()) <<
"Change: Bad sequence";
73 JLOG(ctx.
j.
warn()) <<
"Change: NegativeUNL not enabled";
87 JLOG(ctx.
j.
warn()) <<
"Change transaction against open ledger";
152 UNREACHABLE(
"ripple::Change::doApply : invalid transaction type");
161 account_ == beast::zero,
"ripple::Change::preCompute : zero account");
167 JLOG(
j_.
warn()) <<
"fixTrustLinesToSelf amendment activation code starting";
174 JLOG(
j_.
warn()) <<
id <<
": Unable to locate trustline";
178 if (tl->getType() != ltRIPPLE_STATE)
180 JLOG(
j_.
warn()) <<
id <<
": Unexpected type "
185 auto const& lo = tl->getFieldAmount(sfLowLimit);
186 auto const& hi = tl->getFieldAmount(sfHighLimit);
190 JLOG(
j_.
warn()) <<
id <<
": Trustline doesn't meet requirements";
194 if (
auto const page = tl->getFieldU64(sfLowNode); !sb.
dirRemove(
197 JLOG(
j_.
error()) <<
id <<
": failed to remove low entry from "
198 <<
toBase58(lo.getIssuer()) <<
":" << page
199 <<
" owner directory";
203 if (
auto const page = tl->getFieldU64(sfHighNode); !sb.
dirRemove(
206 JLOG(
j_.
error()) <<
id <<
": failed to remove high entry from "
207 <<
toBase58(hi.getIssuer()) <<
":" << page
208 <<
" owner directory";
222 JLOG(
j_.
warn()) <<
"Successfully deleted trustline " << id;
227 using namespace std::literals;
231 if (removeTrustLineToSelf(
234 "2F8F21EFCAFD7ACFB07D5BB04F0D2E18587820C7611305BB674A64EAB0FA71E1"sv}) &&
235 removeTrustLineToSelf(
238 "326035D5C0560A9DA8636545DD5A1B0DFCFF63E68D491B5522B767BB00564B1A"sv}))
240 JLOG(
j_.
warn()) <<
"fixTrustLinesToSelf amendment activation code "
241 "executed successfully";
255 if (!amendmentObject)
257 amendmentObject = std::make_shared<SLE>(k);
261 STVector256 amendments = amendmentObject->getFieldV256(sfAmendments);
263 if (
std::find(amendments.begin(), amendments.end(), amendment) !=
272 if (gotMajority && lostMajority)
275 STArray newMajorities(sfMajorities);
278 if (amendmentObject->isFieldPresent(sfMajorities))
281 amendmentObject->getFieldArray(sfMajorities);
282 for (
auto const& majority : oldMajorities)
284 if (majority.getFieldH256(sfAmendment) == amendment)
298 if (!found && lostMajority)
305 auto& entry = newMajorities.
back();
306 entry[sfAmendment] = amendment;
312 JLOG(
j_.
warn()) <<
"Unsupported amendment " << amendment
313 <<
" received a majority.";
316 else if (!lostMajority)
319 amendments.push_back(amendment);
320 amendmentObject->setFieldV256(sfAmendments, amendments);
322 if (amendment == fixTrustLinesToSelf)
329 JLOG(
j_.
error()) <<
"Unsupported amendment " << amendment
330 <<
" activated: server blocked.";
335 if (newMajorities.
empty())
336 amendmentObject->makeFieldAbsent(sfMajorities);
338 amendmentObject->setFieldArray(sfMajorities, newMajorities);
354 feeObject = std::make_shared<SLE>(k);
358 feeObject->at(field) = tx[field];
363 set(feeObject,
ctx_.
tx, sfReserveBaseDrops);
364 set(feeObject,
ctx_.
tx, sfReserveIncrementDrops);
366 feeObject->makeFieldAbsent(sfBaseFee);
367 feeObject->makeFieldAbsent(sfReferenceFeeUnits);
368 feeObject->makeFieldAbsent(sfReserveBase);
369 feeObject->makeFieldAbsent(sfReserveIncrement);
374 set(feeObject,
ctx_.
tx, sfReferenceFeeUnits);
376 set(feeObject,
ctx_.
tx, sfReserveIncrement);
381 JLOG(
j_.
warn()) <<
"Fees have been changed";
390 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, not a flag ledger, seq="
400 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, wrong Tx format.";
406 if (seq !=
view().seq())
408 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, wrong ledger seq=" << seq;
415 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, bad validator key";
419 JLOG(
j_.
info()) <<
"N-UNL: applyUNLModify, "
420 << (disabling ?
"ToDisable" :
"ToReEnable")
422 <<
" validator data:" <<
strHex(validator);
428 negUnlObject = std::make_shared<SLE>(k);
432 bool const found = [&] {
433 if (negUnlObject->isFieldPresent(sfDisabledValidators))
436 negUnlObject->getFieldArray(sfDisabledValidators);
437 for (
auto const& v : negUnl)
439 if (v.isFieldPresent(sfPublicKey) &&
440 v.getFieldVL(sfPublicKey) == validator)
450 if (negUnlObject->isFieldPresent(sfValidatorToDisable))
452 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, already has ToDisable";
457 if (negUnlObject->isFieldPresent(sfValidatorToReEnable))
459 if (negUnlObject->getFieldVL(sfValidatorToReEnable) == validator)
462 <<
"N-UNL: applyUNLModify, ToDisable is same as ToReEnable";
471 <<
"N-UNL: applyUNLModify, ToDisable already in negative UNL";
475 negUnlObject->setFieldVL(sfValidatorToDisable, validator);
480 if (negUnlObject->isFieldPresent(sfValidatorToReEnable))
482 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, already has ToReEnable";
487 if (negUnlObject->isFieldPresent(sfValidatorToDisable))
489 if (negUnlObject->getFieldVL(sfValidatorToDisable) == validator)
492 <<
"N-UNL: applyUNLModify, ToReEnable is same as ToDisable";
501 <<
"N-UNL: applyUNLModify, ToReEnable is not in negative UNL";
505 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
bool set(T &target, std::string const &name, Section const §ion)
Set a value from a configuration Section If the named value is not found or doesn't parse as a T,...
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.
static bool adjustOwnerCount(ApplyContext &ctx, int count)
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
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)