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";
64 JLOG(ctx.
j.
warn()) <<
"Change transaction against open ledger";
130 UNREACHABLE(
"ripple::Change::doApply : invalid transaction type");
140 account_ == beast::zero,
"ripple::Change::preCompute : zero account");
152 if (!amendmentObject)
158 STVector256 amendments = amendmentObject->getFieldV256(sfAmendments);
160 if (
std::find(amendments.begin(), amendments.end(), amendment) !=
169 if (gotMajority && lostMajority)
172 STArray newMajorities(sfMajorities);
175 if (amendmentObject->isFieldPresent(sfMajorities))
178 amendmentObject->getFieldArray(sfMajorities);
179 for (
auto const& majority : oldMajorities)
181 if (majority.getFieldH256(sfAmendment) == amendment)
195 if (!found && lostMajority)
202 auto& entry = newMajorities.
back();
203 entry[sfAmendment] = amendment;
209 JLOG(
j_.
warn()) <<
"Unsupported amendment " << amendment
210 <<
" received a majority.";
213 else if (!lostMajority)
216 amendments.push_back(amendment);
217 amendmentObject->setFieldV256(sfAmendments, amendments);
223 JLOG(
j_.
error()) <<
"Unsupported amendment " << amendment
224 <<
" activated: server blocked.";
229 if (newMajorities.
empty())
230 amendmentObject->makeFieldAbsent(sfMajorities);
232 amendmentObject->setFieldArray(sfMajorities, newMajorities);
252 feeObject->at(field) = tx[field];
257 set(feeObject,
ctx_.
tx, sfReserveBaseDrops);
258 set(feeObject,
ctx_.
tx, sfReserveIncrementDrops);
260 feeObject->makeFieldAbsent(sfBaseFee);
261 feeObject->makeFieldAbsent(sfReferenceFeeUnits);
262 feeObject->makeFieldAbsent(sfReserveBase);
263 feeObject->makeFieldAbsent(sfReserveIncrement);
268 set(feeObject,
ctx_.
tx, sfReferenceFeeUnits);
270 set(feeObject,
ctx_.
tx, sfReserveIncrement);
275 JLOG(
j_.
warn()) <<
"Fees have been changed";
284 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, not a flag ledger, seq="
294 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, wrong Tx format.";
300 if (seq !=
view().seq())
302 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, wrong ledger seq=" << seq;
309 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, bad validator key";
313 JLOG(
j_.
info()) <<
"N-UNL: applyUNLModify, "
314 << (disabling ?
"ToDisable" :
"ToReEnable")
316 <<
" validator data:" <<
strHex(validator);
326 bool const found = [&] {
327 if (negUnlObject->isFieldPresent(sfDisabledValidators))
330 negUnlObject->getFieldArray(sfDisabledValidators);
331 for (
auto const& v : negUnl)
333 if (v.isFieldPresent(sfPublicKey) &&
334 v.getFieldVL(sfPublicKey) == validator)
344 if (negUnlObject->isFieldPresent(sfValidatorToDisable))
346 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, already has ToDisable";
351 if (negUnlObject->isFieldPresent(sfValidatorToReEnable))
353 if (negUnlObject->getFieldVL(sfValidatorToReEnable) == validator)
356 <<
"N-UNL: applyUNLModify, ToDisable is same as ToReEnable";
365 <<
"N-UNL: applyUNLModify, ToDisable already in negative UNL";
369 negUnlObject->setFieldVL(sfValidatorToDisable, validator);
374 if (negUnlObject->isFieldPresent(sfValidatorToReEnable))
376 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, already has ToReEnable";
381 if (negUnlObject->isFieldPresent(sfValidatorToDisable))
383 if (negUnlObject->getFieldVL(sfValidatorToDisable) == validator)
386 <<
"N-UNL: applyUNLModify, ToReEnable is same as ToDisable";
395 <<
"N-UNL: applyUNLModify, ToReEnable is not in negative UNL";
399 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.
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 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
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.
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.
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)