1#include <xrpl/tx/transactors/system/Change.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/Slice.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/basics/strHex.h>
7#include <xrpl/beast/utility/Zero.h>
8#include <xrpl/beast/utility/instrumentation.h>
9#include <xrpl/core/ServiceRegistry.h>
10#include <xrpl/ledger/AmendmentTable.h>
11#include <xrpl/ledger/entries/AmendmentsEntry.h>
12#include <xrpl/ledger/entries/FeeSettingsEntry.h>
13#include <xrpl/ledger/entries/NegativeUNLEntry.h>
14#include <xrpl/protocol/Feature.h>
15#include <xrpl/protocol/Protocol.h>
16#include <xrpl/protocol/PublicKey.h>
17#include <xrpl/protocol/SField.h>
18#include <xrpl/protocol/STArray.h>
19#include <xrpl/protocol/STLedgerEntry.h>
20#include <xrpl/protocol/STTx.h>
21#include <xrpl/protocol/STVector256.h>
22#include <xrpl/protocol/TER.h>
23#include <xrpl/protocol/TxFlags.h>
24#include <xrpl/protocol/TxFormats.h>
25#include <xrpl/protocol/XRPAmount.h>
26#include <xrpl/server/NetworkOPs.h>
27#include <xrpl/tx/Transactor.h>
48 JLOG(ctx.
j.
warn()) <<
"Change: Bad source id";
56 JLOG(ctx.
j.
warn()) <<
"Change: invalid fee";
63 JLOG(ctx.
j.
warn()) <<
"Change: Bad signature";
69 JLOG(ctx.
j.
warn()) <<
"Change: Bad sequence";
83 JLOG(ctx.
j.
warn()) <<
"Change transaction against open ledger";
145 switch (
ctx_.tx.getTxnType())
155 UNREACHABLE(
"xrpl::Change::doApply : invalid transaction type");
170 UInt256 const amendment(
ctx_.tx.getFieldH256(sfAmendment));
174 if (!amendmentObject)
185 bool const gotMajority =
ctx_.tx.isFlag(tfGotMajority);
186 bool const lostMajority =
ctx_.tx.isFlag(tfLostMajority);
188 if (gotMajority && lostMajority)
191 STArray newMajorities(sfMajorities);
197 for (
auto const& majority : oldMajorities)
199 if (majority.getFieldH256(sfAmendment) == amendment)
213 if (!found && lostMajority)
220 auto& entry = newMajorities.
back();
221 entry[sfAmendment] = amendment;
224 if (!
ctx_.registry.get().getAmendmentTable().isSupported(amendment))
226 JLOG(
j_.warn()) <<
"Unsupported amendment " << amendment <<
" received a majority.";
229 else if (!lostMajority)
232 amendments.pushBack(amendment);
233 amendmentObject->
setFieldV256(sfAmendments, amendments);
235 ctx_.registry.get().getAmendmentTable().enable(amendment);
237 if (!
ctx_.registry.get().getAmendmentTable().isSupported(amendment))
239 JLOG(
j_.error()) <<
"Unsupported amendment " << amendment
240 <<
" activated: server blocked.";
241 ctx_.registry.get().getOPs().setAmendmentBlocked();
245 if (newMajorities.
empty())
270 feeObject->
at(field) = tx[field];
272 if (
view().rules().enabled(featureXRPFees))
274 set(feeObject,
ctx_.tx, sfBaseFeeDrops);
275 set(feeObject,
ctx_.tx, sfReserveBaseDrops);
276 set(feeObject,
ctx_.tx, sfReserveIncrementDrops);
285 set(feeObject,
ctx_.tx, sfBaseFee);
286 set(feeObject,
ctx_.tx, sfReferenceFeeUnits);
287 set(feeObject,
ctx_.tx, sfReserveBase);
288 set(feeObject,
ctx_.tx, sfReserveIncrement);
293 JLOG(
j_.warn()) <<
"Fees have been changed";
302 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, not a flag ledger, seq=" <<
view().
seq();
306 if (!
ctx_.tx.isFieldPresent(sfUNLModifyDisabling) ||
307 ctx_.tx.getFieldU8(sfUNLModifyDisabling) > 1 || !
ctx_.tx.isFieldPresent(sfLedgerSequence) ||
308 !
ctx_.tx.isFieldPresent(sfUNLModifyValidator))
310 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, wrong Tx format.";
314 bool const disabling =
ctx_.tx.getFieldU8(sfUNLModifyDisabling) != 0u;
315 auto const seq =
ctx_.tx.getFieldU32(sfLedgerSequence);
316 if (seq !=
view().seq())
318 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, wrong ledger seq=" << seq;
322 Blob const validator =
ctx_.tx.getFieldVL(sfUNLModifyValidator);
325 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, bad validator key";
329 JLOG(
j_.info()) <<
"N-UNL: applyUNLModify, " << (disabling ?
"ToDisable" :
"ToReEnable")
330 <<
" seq=" << seq <<
" validator data:" <<
strHex(validator);
339 bool const found = [&] {
342 auto const& negUnl = negUnlObject->
getFieldArray(sfDisabledValidators);
343 for (
auto const& v : negUnl)
345 if (v.isFieldPresent(sfPublicKey) && v.getFieldVL(sfPublicKey) == validator)
357 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, already has ToDisable";
364 if (negUnlObject->
getFieldVL(sfValidatorToReEnable) == validator)
366 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, ToDisable is same as ToReEnable";
374 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, ToDisable already in negative UNL";
378 negUnlObject->
setFieldVL(sfValidatorToDisable, validator);
385 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, already has ToReEnable";
392 if (negUnlObject->
getFieldVL(sfValidatorToDisable) == validator)
394 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, ToReEnable is same as ToDisable";
402 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, ToReEnable is not in negative UNL";
406 negUnlObject->
setFieldVL(sfValidatorToReEnable, validator);
A generic endpoint for log messages.
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
static TER preclaim(PreclaimContext const &ctx)
void visitInvariantEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after) override
Inspect a single ledger entry modified by this transaction.
void preCompute() override
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 pushBack(STObject const &object)
std::shared_ptr< STLedgerEntry const > const & ConstRef
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
Blob getFieldVL(SField const &field) const
void setFieldV256(SField const &field, STVector256 const &v)
std::uint32_t getFieldU32(SField const &field) const
void setFieldVL(SField const &field, Blob const &)
STArray const & getFieldArray(SField const &field) const
void setFieldArray(SField const &field, STArray const &v)
bool isFieldPresent(SField const &field) const
static STObject makeInnerObject(SField const &name)
AccountID getAccountID(SField const &field) const
STVector256 const & getFieldV256(SField const &field) const
void makeFieldAbsent(SField const &field)
STAmount const & getFieldAmount(SField const &field) const
static Blob getSignature(STObject const &sigObject)
TxType getTxnType() const
Blob getSigningPubKey() const
static NotTEC invokePreflight(PreflightContext const &ctx)
AccountID const accountID_
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)
NegativeUNLEntry< ApplyView > NegativeUNLEntryW
std::optional< KeyType > publicKeyType(Slice const &slice)
Returns the type of public key.
Slice makeSlice(std::array< T, N > const &a)
TERSubset< CanCvtToNotTEC > NotTEC
FeeSettingsEntry< ApplyView > FeeSettingsEntryW
TERSubset< CanCvtToTER > TER
NotTEC preflight0(PreflightContext const &ctx, std::uint32_t flagMask)
Performs early sanity checks on the txid and flags.
std::vector< unsigned char > Blob
Storage for linear binary data.
AmendmentsEntry< ApplyView > AmendmentsEntryW
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)