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>
30 if (account != beast::zero)
32 JLOG(ctx.
j.
warn()) <<
"Change: Bad source id";
38 if (!fee.native() || fee != beast::zero)
40 JLOG(ctx.
j.
warn()) <<
"Change: invalid fee";
47 JLOG(ctx.
j.
warn()) <<
"Change: Bad signature";
54 JLOG(ctx.
j.
warn()) <<
"Change: Bad sequence";
68 JLOG(ctx.
j.
warn()) <<
"Change transaction against open ledger";
134 UNREACHABLE(
"xrpl::Change::doApply : invalid transaction type");
144 account_ == beast::zero,
"xrpl::Change::preCompute : zero account");
156 if (!amendmentObject)
162 STVector256 amendments = amendmentObject->getFieldV256(sfAmendments);
164 if (
std::find(amendments.begin(), amendments.end(), amendment) !=
173 if (gotMajority && lostMajority)
176 STArray newMajorities(sfMajorities);
179 if (amendmentObject->isFieldPresent(sfMajorities))
182 amendmentObject->getFieldArray(sfMajorities);
183 for (
auto const& majority : oldMajorities)
185 if (majority.getFieldH256(sfAmendment) == amendment)
199 if (!found && lostMajority)
206 auto& entry = newMajorities.
back();
207 entry[sfAmendment] = amendment;
213 JLOG(
j_.
warn()) <<
"Unsupported amendment " << amendment
214 <<
" received a majority.";
217 else if (!lostMajority)
220 amendments.push_back(amendment);
221 amendmentObject->setFieldV256(sfAmendments, amendments);
227 JLOG(
j_.
error()) <<
"Unsupported amendment " << amendment
228 <<
" activated: server blocked.";
233 if (newMajorities.
empty())
234 amendmentObject->makeFieldAbsent(sfMajorities);
236 amendmentObject->setFieldArray(sfMajorities, newMajorities);
256 feeObject->at(field) = tx[field];
261 set(feeObject,
ctx_.
tx, sfReserveBaseDrops);
262 set(feeObject,
ctx_.
tx, sfReserveIncrementDrops);
264 feeObject->makeFieldAbsent(sfBaseFee);
265 feeObject->makeFieldAbsent(sfReferenceFeeUnits);
266 feeObject->makeFieldAbsent(sfReserveBase);
267 feeObject->makeFieldAbsent(sfReserveIncrement);
272 set(feeObject,
ctx_.
tx, sfReferenceFeeUnits);
274 set(feeObject,
ctx_.
tx, sfReserveIncrement);
279 JLOG(
j_.
warn()) <<
"Fees have been changed";
288 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, not a flag ledger, seq="
298 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, wrong Tx format.";
304 if (seq !=
view().seq())
306 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, wrong ledger seq=" << seq;
313 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, bad validator key";
317 JLOG(
j_.
info()) <<
"N-UNL: applyUNLModify, "
318 << (disabling ?
"ToDisable" :
"ToReEnable")
320 <<
" validator data:" <<
strHex(validator);
330 bool const found = [&] {
331 if (negUnlObject->isFieldPresent(sfDisabledValidators))
334 negUnlObject->getFieldArray(sfDisabledValidators);
335 for (
auto const& v : negUnl)
337 if (v.isFieldPresent(sfPublicKey) &&
338 v.getFieldVL(sfPublicKey) == validator)
348 if (negUnlObject->isFieldPresent(sfValidatorToDisable))
350 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, already has ToDisable";
355 if (negUnlObject->isFieldPresent(sfValidatorToReEnable))
357 if (negUnlObject->getFieldVL(sfValidatorToReEnable) == validator)
360 <<
"N-UNL: applyUNLModify, ToDisable is same as ToReEnable";
369 <<
"N-UNL: applyUNLModify, ToDisable already in negative UNL";
373 negUnlObject->setFieldVL(sfValidatorToDisable, validator);
378 if (negUnlObject->isFieldPresent(sfValidatorToReEnable))
380 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, already has ToReEnable";
385 if (negUnlObject->isFieldPresent(sfValidatorToDisable))
387 if (negUnlObject->getFieldVL(sfValidatorToDisable) == validator)
390 <<
"N-UNL: applyUNLModify, ToReEnable is same as ToDisable";
399 <<
"N-UNL: applyUNLModify, ToReEnable is not in negative UNL";
403 negUnlObject->setFieldVL(sfValidatorToReEnable, validator);
virtual bool isSupported(uint256 const &amendment) const =0
virtual bool enable(uint256 const &amendment)=0
virtual AmendmentTable & getAmendmentTable()=0
virtual NetworkOPs & getOPs()=0
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
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.
static TER preclaim(PreclaimContext const &ctx)
void preCompute() override
virtual void setAmendmentBlocked()=0
virtual Rules const & rules() const =0
Returns the tx processing rules.
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.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
void push_back(STObject const &object)
Blob getFieldVL(SField const &field) const
unsigned char getFieldU8(SField const &field) const
std::uint32_t getFieldU32(SField const &field) const
bool isFieldPresent(SField const &field) const
uint256 getFieldH256(SField const &field) const
static STObject makeInnerObject(SField const &name)
AccountID getAccountID(SField const &field) const
STAmount const & getFieldAmount(SField const &field) const
std::uint32_t getFlags() const
static Blob getSignature(STObject const &sigObject)
TxType getTxnType() const
Blob getSigningPubKey() const
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 const & fees() noexcept
The (fixed) index of the object containing the ledger fees.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
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,...
bool isFlagLedger(LedgerIndex seq)
Returns true if the given ledgerIndex is a flag ledgerIndex.
std::string strHex(FwdIt begin, FwdIt end)
constexpr std::uint32_t tfChangeMask
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
constexpr std::uint32_t tfLostMajority
constexpr std::uint32_t tfGotMajority
NotTEC preflight0(PreflightContext const &ctx, std::uint32_t flagMask)
Performs early sanity checks on the txid.
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)
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)