Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into github-ci
Browse files Browse the repository at this point in the history
* upstream/develop:
  `XRPFees`: Fee setting and handling improvements (XRPLF#4247)
  • Loading branch information
ximinez committed Feb 3, 2023
2 parents 897c420 + e4b17d1 commit 6d5dfd7
Show file tree
Hide file tree
Showing 46 changed files with 693 additions and 339 deletions.
3 changes: 2 additions & 1 deletion src/ripple/app/consensus/RCLConsensus.cpp
Expand Up @@ -839,7 +839,8 @@ RCLConsensus::Adaptor::validate(
if (ledger.ledger_->isVotingLedger())
{
// Fees:
feeVote_->doValidation(ledger.ledger_->fees(), v);
feeVote_->doValidation(
ledger.ledger_->fees(), ledger.ledger_->rules(), v);

// Amendments
// FIXME: pass `v` and have the function insert the array
Expand Down
71 changes: 49 additions & 22 deletions src/ripple/app/ledger/Ledger.cpp
Expand Up @@ -591,29 +591,9 @@ Ledger::setup(Config const& config)
{
bool ret = true;

fees_.base = config.FEE_DEFAULT;
fees_.units = config.TRANSACTION_FEE_BASE;
fees_.reserve = config.FEE_ACCOUNT_RESERVE;
fees_.increment = config.FEE_OWNER_RESERVE;

try
{
if (auto const sle = read(keylet::fees()))
{
// VFALCO NOTE Why getFieldIndex and not isFieldPresent?

if (sle->getFieldIndex(sfBaseFee) != -1)
fees_.base = sle->getFieldU64(sfBaseFee);

if (sle->getFieldIndex(sfReferenceFeeUnits) != -1)
fees_.units = sle->getFieldU32(sfReferenceFeeUnits);

if (sle->getFieldIndex(sfReserveBase) != -1)
fees_.reserve = sle->getFieldU32(sfReserveBase);

if (sle->getFieldIndex(sfReserveIncrement) != -1)
fees_.increment = sle->getFieldU32(sfReserveIncrement);
}
rules_ = makeRulesGivenLedger(*this, config.features);
}
catch (SHAMapMissingNode const&)
{
Expand All @@ -624,9 +604,56 @@ Ledger::setup(Config const& config)
Rethrow();
}

fees_.base = config.FEE_DEFAULT;
fees_.reserve = config.FEE_ACCOUNT_RESERVE;
fees_.increment = config.FEE_OWNER_RESERVE;

try
{
rules_ = makeRulesGivenLedger(*this, config.features);
if (auto const sle = read(keylet::fees()))
{
bool oldFees = false;
bool newFees = false;
{
auto const baseFee = sle->at(~sfBaseFee);
auto const reserveBase = sle->at(~sfReserveBase);
auto const reserveIncrement = sle->at(~sfReserveIncrement);
if (baseFee)
fees_.base = *baseFee;
if (reserveBase)
fees_.reserve = *reserveBase;
if (reserveIncrement)
fees_.increment = *reserveIncrement;
oldFees = baseFee || reserveBase || reserveIncrement;
}
{
auto const baseFeeXRP = sle->at(~sfBaseFeeDrops);
auto const reserveBaseXRP = sle->at(~sfReserveBaseDrops);
auto const reserveIncrementXRP =
sle->at(~sfReserveIncrementDrops);
auto assign = [&ret](
XRPAmount& dest,
std::optional<STAmount> const& src) {
if (src)
{
if (src->native())
dest = src->xrp();
else
ret = false;
}
};
assign(fees_.base, baseFeeXRP);
assign(fees_.reserve, reserveBaseXRP);
assign(fees_.increment, reserveIncrementXRP);
newFees = baseFeeXRP || reserveBaseXRP || reserveIncrementXRP;
}
if (oldFees && newFees)
// Should be all of one or the other, but not both
ret = false;
if (!rules_.enabled(featureXRPFees) && newFees)
// Can't populate the new fees before the amendment is enabled
ret = false;
}
}
catch (SHAMapMissingNode const&)
{
Expand Down
8 changes: 4 additions & 4 deletions src/ripple/app/misc/FeeVote.h
Expand Up @@ -42,9 +42,6 @@ class FeeVote
/** The cost of a reference transaction in drops. */
XRPAmount reference_fee{10};

/** The cost of a reference transaction in fee units. */
static constexpr FeeUnit32 reference_fee_units{10};

/** The account reserve requirement in drops. */
XRPAmount account_reserve{10 * DROPS_PER_XRP};

Expand All @@ -60,7 +57,10 @@ class FeeVote
@param baseValidation
*/
virtual void
doValidation(Fees const& lastFees, STValidation& val) = 0;
doValidation(
Fees const& lastFees,
Rules const& rules,
STValidation& val) = 0;

/** Cast our local vote on the fee.
Expand Down

0 comments on commit 6d5dfd7

Please sign in to comment.