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/Fees.h>
16#include <xrpl/protocol/Protocol.h>
17#include <xrpl/protocol/PublicKey.h>
18#include <xrpl/protocol/SField.h>
19#include <xrpl/protocol/STArray.h>
20#include <xrpl/protocol/STLedgerEntry.h>
21#include <xrpl/protocol/STTx.h>
22#include <xrpl/protocol/STVector256.h>
23#include <xrpl/protocol/TER.h>
24#include <xrpl/protocol/TxFlags.h>
25#include <xrpl/protocol/TxFormats.h>
26#include <xrpl/protocol/XRPAmount.h>
27#include <xrpl/server/NetworkOPs.h>
28#include <xrpl/tx/Transactor.h>
49 JLOG(ctx.
j.
warn()) <<
"Change: Bad source id";
57 JLOG(ctx.
j.
warn()) <<
"Change: invalid fee";
64 JLOG(ctx.
j.
warn()) <<
"Change: Bad signature";
70 JLOG(ctx.
j.
warn()) <<
"Change: Bad sequence";
84 JLOG(ctx.
j.
warn()) <<
"Change transaction against open ledger";
129 switch (
ctx_.tx.getTxnType())
139 UNREACHABLE(
"xrpl::Change::doApply : invalid transaction type");
170 JLOG(
j_.info()) <<
"Feature Extension fees initialized on SmartEscrow activation";
176 UInt256 const amendment(
ctx_.tx.getFieldH256(sfAmendment));
180 if (!amendmentObject)
191 bool const gotMajority =
ctx_.tx.isFlag(tfGotMajority);
192 bool const lostMajority =
ctx_.tx.isFlag(tfLostMajority);
194 if (gotMajority && lostMajority)
197 STArray newMajorities(sfMajorities);
203 for (
auto const& majority : oldMajorities)
205 if (majority.getFieldH256(sfAmendment) == amendment)
219 if (!found && lostMajority)
226 auto& entry = newMajorities.
back();
227 entry[sfAmendment] = amendment;
230 if (!
ctx_.registry.get().getAmendmentTable().isSupported(amendment))
232 JLOG(
j_.warn()) <<
"Unsupported amendment " << amendment <<
" received a majority.";
235 else if (!lostMajority)
238 amendments.pushBack(amendment);
239 amendmentObject->
setFieldV256(sfAmendments, amendments);
241 ctx_.registry.get().getAmendmentTable().enable(amendment);
243 if (!
ctx_.registry.get().getAmendmentTable().isSupported(amendment))
245 JLOG(
j_.error()) <<
"Unsupported amendment " << amendment
246 <<
" activated: server blocked.";
247 ctx_.registry.get().getOPs().setAmendmentBlocked();
250 if (amendment == featureSmartEscrow)
254 if (newMajorities.
empty())
279 ((feeObject->
at(fields) = tx[fields]), ...);
281 set(feeObject,
ctx_.tx, sfBaseFeeDrops, sfReserveBaseDrops, sfReserveIncrementDrops);
287 if (
view().rules().enabled(featureSmartEscrow))
289 set(feeObject,
ctx_.tx, sfGasLimit, sfBytecodeSizeLimit, sfGasPrice);
294 JLOG(
j_.warn()) <<
"Fees have been changed";
303 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, not a flag ledger, seq=" <<
view().
seq();
307 if (!
ctx_.tx.isFieldPresent(sfUNLModifyDisabling) ||
308 ctx_.tx.getFieldU8(sfUNLModifyDisabling) > 1 || !
ctx_.tx.isFieldPresent(sfLedgerSequence) ||
309 !
ctx_.tx.isFieldPresent(sfUNLModifyValidator))
311 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, wrong Tx format.";
315 bool const disabling =
ctx_.tx.getFieldU8(sfUNLModifyDisabling) != 0u;
316 auto const seq =
ctx_.tx.getFieldU32(sfLedgerSequence);
317 if (seq !=
view().seq())
319 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, wrong ledger seq=" << seq;
323 Blob const validator =
ctx_.tx.getFieldVL(sfUNLModifyValidator);
326 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, bad validator key";
330 JLOG(
j_.info()) <<
"N-UNL: applyUNLModify, " << (disabling ?
"ToDisable" :
"ToReEnable")
331 <<
" seq=" << seq <<
" validator data:" <<
strHex(validator);
340 bool const found = [&] {
343 auto const& negUnl = negUnlObject->
getFieldArray(sfDisabledValidators);
344 for (
auto const& v : negUnl)
346 if (v.isFieldPresent(sfPublicKey) && v.getFieldVL(sfPublicKey) == validator)
358 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, already has ToDisable";
365 if (negUnlObject->
getFieldVL(sfValidatorToReEnable) == validator)
367 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, ToDisable is same as ToReEnable";
375 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, ToDisable already in negative UNL";
379 negUnlObject->
setFieldVL(sfValidatorToDisable, validator);
386 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, already has ToReEnable";
393 if (negUnlObject->
getFieldVL(sfValidatorToDisable) == validator)
395 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, ToReEnable is same as ToDisable";
403 JLOG(
j_.warn()) <<
"N-UNL: applyUNLModify, ToReEnable is not in negative UNL";
407 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 initializeVMFees()
Write the default Feature Extension fee settings into FeeSettings on featureSmartEscrow activation.
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,...
constexpr std::uint32_t kDefaultGasLimit
bool isFlagLedger(LedgerIndex seq)
Returns true if the given ledgerIndex is a flag ledgerIndex.
constexpr std::uint32_t kMinGasPrice
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
constexpr std::uint32_t kDefaultGasPrice
constexpr std::uint32_t kDefaultBytecodeSizeLimit
FeeSettingsEntry< ApplyView > FeeSettingsEntryW
TERSubset< CanCvtToTER > TER
NotTEC preflight0(PreflightContext const &ctx, std::uint32_t flagMask)
Performs early sanity checks on the txid and flags.
constexpr std::uint32_t kMaxGasLimit
Hard protocol bounds on the Feature Extension fee settings.
constexpr std::uint32_t kMaxBytecodeSizeLimit
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)