1#include <xrpld/app/misc/FeeVote.h>
2#include <xrpld/core/Config.h>
4#include <xrpl/basics/Log.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/beast/utility/Journal.h>
7#include <xrpl/beast/utility/instrumentation.h>
8#include <xrpl/ledger/ReadView.h>
9#include <xrpl/protocol/Feature.h>
10#include <xrpl/protocol/Fees.h>
11#include <xrpl/protocol/Protocol.h>
12#include <xrpl/protocol/SField.h>
13#include <xrpl/protocol/STTx.h>
14#include <xrpl/protocol/STValidation.h>
15#include <xrpl/protocol/Serializer.h>
16#include <xrpl/protocol/SystemParameters.h>
17#include <xrpl/protocol/TxFormats.h>
18#include <xrpl/protocol/XRPAmount.h>
19#include <xrpl/shamap/SHAMap.h>
20#include <xrpl/shamap/SHAMapItem.h>
21#include <xrpl/shamap/SHAMapTreeNode.h>
77 for (
auto const& [key, val] :
voteMap_)
88 return {ourVote, ourVote !=
current_};
127 if (rules.
enabled(featureXRPFees))
130 [&v,
this](
auto const current,
XRPAmount target,
char const* name,
auto const& sfield) {
131 if (current != target)
133 JLOG(
journal_.info()) <<
"Voting for " << name <<
" of " << target;
138 vote(lastFees.
base,
target_.referenceFee,
"base fee", sfBaseFeeDrops);
139 vote(lastFees.
reserve,
target_.accountReserve,
"base reserve", sfReserveBaseDrops);
141 lastFees.
increment,
target_.ownerReserve,
"reserve increment", sfReserveIncrementDrops);
147 auto vote = [&v,
this](
150 auto const& convertCallback,
152 auto const& sfield) {
153 if (current != target)
155 JLOG(
journal_.info()) <<
"Voting for " << name <<
" of " << target;
157 if (
auto const f = convertCallback(target))
162 vote(lastFees.
base,
target_.referenceFee, to64,
"base fee", sfBaseFee);
163 vote(lastFees.
reserve,
target_.accountReserve, to32,
"base reserve", sfReserveBase);
181 lastClosedLedger &&
isFlagLedger(lastClosedLedger->seq()),
182 "xrpl::FeeVoteImpl::doVoting : has a flag ledger");
190 auto const& rules = lastClosedLedger->rules();
191 if (rules.enabled(featureXRPFees))
196 if (
auto const field = ~val->at(~xrpField); field && field->native())
198 auto const vote = field->xrp();
214 for (
auto const& val :
set)
216 if (!val->isTrusted())
218 doVote(val, baseFeeVote, sfBaseFeeDrops);
219 doVote(val, baseReserveVote, sfReserveBaseDrops);
220 doVote(val, incReserveVote, sfReserveIncrementDrops);
227 auto const& valueField) {
228 if (
auto const field = val->at(~valueField))
231 auto const vote = *field;
251 for (
auto const& val :
set)
253 if (!val->isTrusted())
255 doVote(val, baseFeeVote, sfBaseFee);
256 doVote(val, baseReserveVote, sfReserveBase);
257 doVote(val, incReserveVote, sfReserveIncrement);
265 auto const baseFee = baseFeeVote.
getVotes();
266 auto const baseReserve = baseReserveVote.
getVotes();
267 auto const incReserve = incReserveVote.
getVotes();
269 auto const seq = lastClosedLedger->header().seq + 1;
272 if (baseFee.second || baseReserve.second || incReserve.second)
274 JLOG(
journal_.warn()) <<
"We are voting for a fee change: " << baseFee.first <<
"/"
275 << baseReserve.first <<
"/" << incReserve.first;
277 STTx const feeTx(ttFEE, [=, &rules](
auto& obj) {
279 obj[sfLedgerSequence] = seq;
280 if (rules.enabled(featureXRPFees))
282 obj[sfBaseFeeDrops] = baseFee.first;
283 obj[sfReserveBaseDrops] = baseReserve.first;
284 obj[sfReserveIncrementDrops] = incReserve.first;
293 obj[sfReserveIncrement] =
299 uint256 const txID = feeTx.getTransactionID();
301 JLOG(
journal_.warn()) <<
"Vote: " << txID;
306 if (!initialPosition->addGiveItem(
309 JLOG(
journal_.warn()) <<
"Ledger already had fee change";
A generic endpoint for log messages.
void doValidation(Fees const &lastFees, Rules const &rules, STValidation &val) override
Add local fee preference to validation.
FeeVoteImpl(FeeSetup const &setup, beast::Journal journal)
void doVoting(std::shared_ptr< ReadView const > const &lastClosedLedger, std::vector< std::shared_ptr< STValidation > > const &parentValidations, std::shared_ptr< SHAMap > const &initialPosition) override
Cast our local vote on the fee.
beast::Journal const journal_
Manager to process fee votes.
Rules controlling protocol behavior.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Slice slice() const noexcept
value_type const current_
std::map< value_type, int > voteMap_
std::pair< value_type, bool > getVotes() const
value_type current() const
VotableValue(value_type current, value_type target)
void addVote(value_type vote)
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::unique_ptr< FeeVote > makeFeeVote(FeeSetup const &setup, beast::Journal journal)
Create an instance of the FeeVote logic.
constexpr std::enable_if_t< std::is_integral_v< Dest > &&std::is_integral_v< Src >, Dest > unsafeCast(Src s) noexcept
constexpr std::uint32_t kFeeUnitsDeprecated
TypedField< STAmount > SF_AMOUNT
boost::intrusive_ptr< SHAMapItem > makeShamapitem(uint256 const &tag, Slice data)
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
bool isLegalAmountSigned(XRPAmount const &amount)
Returns true if the absolute value of the amount does not exceed the initial XRP in existence.
Fee schedule for startup / standalone, and to vote for.
Reflects the fee settings for a particular ledger.
XRPAmount reserve
Minimum XRP an account must hold to exist on the ledger.
XRPAmount increment
Additional XRP reserve required per owned ledger object.
XRPAmount base
Cost of a reference transaction in drops.