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>
29 if (account != beast::zero)
31 JLOG(ctx.
j.
warn()) <<
"Change: Bad source id";
37 if (!fee.native() || fee != beast::zero)
39 JLOG(ctx.
j.
warn()) <<
"Change: invalid fee";
45 JLOG(ctx.
j.
warn()) <<
"Change: Bad signature";
51 JLOG(ctx.
j.
warn()) <<
"Change: Bad sequence";
65 JLOG(ctx.
j.
warn()) <<
"Change transaction against open ledger";
125 UNREACHABLE(
"xrpl::Change::doApply : invalid transaction type");
134 XRPL_ASSERT(
account_ == beast::zero,
"xrpl::Change::preCompute : zero account");
146 if (!amendmentObject)
152 STVector256 amendments = amendmentObject->getFieldV256(sfAmendments);
154 if (
std::find(amendments.begin(), amendments.end(), amendment) != amendments.end())
162 if (gotMajority && lostMajority)
165 STArray newMajorities(sfMajorities);
168 if (amendmentObject->isFieldPresent(sfMajorities))
170 STArray const& oldMajorities = amendmentObject->getFieldArray(sfMajorities);
171 for (
auto const& majority : oldMajorities)
173 if (majority.getFieldH256(sfAmendment) == amendment)
187 if (!found && lostMajority)
194 auto& entry = newMajorities.
back();
195 entry[sfAmendment] = amendment;
200 JLOG(
j_.
warn()) <<
"Unsupported amendment " << amendment <<
" received a majority.";
203 else if (!lostMajority)
206 amendments.push_back(amendment);
207 amendmentObject->setFieldV256(sfAmendments, amendments);
213 JLOG(
j_.
error()) <<
"Unsupported amendment " << amendment <<
" activated: server blocked.";
218 if (newMajorities.
empty())
219 amendmentObject->makeFieldAbsent(sfMajorities);
221 amendmentObject->setFieldArray(sfMajorities, newMajorities);
240 auto set = [](
SLE::pointer& feeObject,
STTx const& tx,
auto const& field) { feeObject->at(field) = tx[field]; };
244 set(feeObject,
ctx_.
tx, sfReserveBaseDrops);
245 set(feeObject,
ctx_.
tx, sfReserveIncrementDrops);
247 feeObject->makeFieldAbsent(sfBaseFee);
248 feeObject->makeFieldAbsent(sfReferenceFeeUnits);
249 feeObject->makeFieldAbsent(sfReserveBase);
250 feeObject->makeFieldAbsent(sfReserveIncrement);
255 set(feeObject,
ctx_.
tx, sfReferenceFeeUnits);
257 set(feeObject,
ctx_.
tx, sfReserveIncrement);
262 JLOG(
j_.
warn()) <<
"Fees have been changed";
271 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, not a flag ledger, seq=" <<
view().
seq();
278 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, wrong Tx format.";
284 if (seq !=
view().seq())
286 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, wrong ledger seq=" << seq;
293 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, bad validator key";
297 JLOG(
j_.
info()) <<
"N-UNL: applyUNLModify, " << (disabling ?
"ToDisable" :
"ToReEnable") <<
" seq=" << seq
298 <<
" validator data:" <<
strHex(validator);
308 bool const found = [&] {
309 if (negUnlObject->isFieldPresent(sfDisabledValidators))
311 auto const& negUnl = negUnlObject->getFieldArray(sfDisabledValidators);
312 for (
auto const& v : negUnl)
314 if (v.isFieldPresent(sfPublicKey) && v.getFieldVL(sfPublicKey) == validator)
324 if (negUnlObject->isFieldPresent(sfValidatorToDisable))
326 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, already has ToDisable";
331 if (negUnlObject->isFieldPresent(sfValidatorToReEnable))
333 if (negUnlObject->getFieldVL(sfValidatorToReEnable) == validator)
335 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, ToDisable is same as ToReEnable";
343 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, ToDisable already in negative UNL";
347 negUnlObject->setFieldVL(sfValidatorToDisable, validator);
352 if (negUnlObject->isFieldPresent(sfValidatorToReEnable))
354 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, already has ToReEnable";
359 if (negUnlObject->isFieldPresent(sfValidatorToDisable))
361 if (negUnlObject->getFieldVL(sfValidatorToDisable) == validator)
363 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, ToReEnable is same as ToDisable";
371 JLOG(
j_.
warn()) <<
"N-UNL: applyUNLModify, ToReEnable is not in negative UNL";
375 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)