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/STAccount.h>
14#include <xrpl/protocol/STTx.h>
15#include <xrpl/protocol/STValidation.h>
16#include <xrpl/protocol/Serializer.h>
17#include <xrpl/protocol/SystemParameters.h>
18#include <xrpl/protocol/TxFormats.h>
19#include <xrpl/protocol/XRPAmount.h>
20#include <xrpl/shamap/SHAMap.h>
21#include <xrpl/shamap/SHAMapItem.h>
22#include <xrpl/shamap/SHAMapTreeNode.h>
78 for (
auto const& [key, val] :
voteMap_)
89 return {ourVote, ourVote !=
current_};
128 if (rules.
enabled(featureXRPFees))
131 [&v,
this](
auto const current,
XRPAmount target,
char const* name,
auto const& sfield) {
132 if (current != target)
134 JLOG(
journal_.info()) <<
"Voting for " << name <<
" of " << target;
139 vote(lastFees.
base,
target_.referenceFee,
"base fee", sfBaseFeeDrops);
140 vote(lastFees.
reserve,
target_.accountReserve,
"base reserve", sfReserveBaseDrops);
142 lastFees.
increment,
target_.ownerReserve,
"reserve increment", sfReserveIncrementDrops);
148 auto vote = [&v,
this](
151 auto const& convertCallback,
153 auto const& sfield) {
154 if (current != target)
156 JLOG(
journal_.info()) <<
"Voting for " << name <<
" of " << target;
158 if (
auto const f = convertCallback(target))
163 vote(lastFees.
base,
target_.referenceFee, to64,
"base fee", sfBaseFee);
164 vote(lastFees.
reserve,
target_.accountReserve, to32,
"base reserve", sfReserveBase);
182 lastClosedLedger &&
isFlagLedger(lastClosedLedger->seq()),
183 "xrpl::FeeVoteImpl::doVoting : has a flag ledger");
191 auto const& rules = lastClosedLedger->rules();
192 if (rules.enabled(featureXRPFees))
197 if (
auto const field = ~val->at(~xrpField); field && field->native())
199 auto const vote = field->xrp();
215 for (
auto const& val :
set)
217 if (!val->isTrusted())
219 doVote(val, baseFeeVote, sfBaseFeeDrops);
220 doVote(val, baseReserveVote, sfReserveBaseDrops);
221 doVote(val, incReserveVote, sfReserveIncrementDrops);
228 auto const& valueField) {
229 if (
auto const field = val->at(~valueField))
232 auto const vote = *field;
252 for (
auto const& val :
set)
254 if (!val->isTrusted())
256 doVote(val, baseFeeVote, sfBaseFee);
257 doVote(val, baseReserveVote, sfReserveBase);
258 doVote(val, incReserveVote, sfReserveIncrement);
263 auto const [baseFee, baseFeeChanged] = baseFeeVote.
getVotes();
264 auto const [baseReserve, baseReserveChanged] = baseReserveVote.
getVotes();
265 auto const [incReserve, incReserveChanged] = incReserveVote.
getVotes();
267 auto const seq = lastClosedLedger->header().seq + 1;
270 if (baseFeeChanged || baseReserveChanged || incReserveChanged)
272 JLOG(
journal_.warn()) <<
"We are voting for a fee change: " << baseFee <<
"/" << baseReserve
273 <<
"/" << incReserve;
275 STTx const feeTx(ttFEE, [=, &rules](
auto& obj) {
277 obj[sfLedgerSequence] = seq;
278 if (rules.enabled(featureXRPFees))
280 obj[sfBaseFeeDrops] = baseFee;
281 obj[sfReserveBaseDrops] = baseReserve;
282 obj[sfReserveIncrementDrops] = incReserve;
290 obj[sfReserveIncrement] =
296 uint256 const txID = feeTx.getTransactionID();
298 JLOG(
journal_.warn()) <<
"Vote: " << txID;
303 if (!initialPosition->addGiveItem(
306 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::uint32_t kFeeUnitsDeprecated
constexpr Dest unsafeCast(Src s) noexcept
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.