Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrapper class for Fee Ledger Object #24

Open
wants to merge 4 commits into
base: wrapper
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions src/ripple/app/ledger/Ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
#include <vector>

#include <ripple/nodestore/impl/DatabaseNodeImp.h>
#include <ripple/protocol/Fees.h>

namespace ripple {

Expand Down Expand Up @@ -626,14 +627,14 @@ Ledger::setup()

try
{
if (auto const sle = readSLE(keylet::fees()))
if (auto const feeLedgerObj = 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);
auto const baseFee = feeLedgerObj->baseFee();
auto const reserveBase = feeLedgerObj->reserveBase();
auto const reserveIncrement = feeLedgerObj->reserveIncrement();
if (baseFee)
fees_.base = *baseFee;
if (reserveBase)
Expand All @@ -643,10 +644,10 @@ Ledger::setup()
oldFees = baseFee || reserveBase || reserveIncrement;
}
{
auto const baseFeeXRP = sle->at(~sfBaseFeeDrops);
auto const reserveBaseXRP = sle->at(~sfReserveBaseDrops);
auto const baseFeeXRP = feeLedgerObj->baseFeeDrops();
auto const reserveBaseXRP = feeLedgerObj->reserveBaseDrops();
auto const reserveIncrementXRP =
sle->at(~sfReserveIncrementDrops);
feeLedgerObj->reserveIncrementDrops();
auto assign = [&ret](
XRPAmount& dest,
std::optional<STAmount> const& src) {
Expand Down Expand Up @@ -1101,7 +1102,7 @@ finishLoadByIndexOrHash(

assert(
ledger->info().seq < XRP_LEDGER_EARLIEST_FEES ||
ledger->readSLE(keylet::fees()));
ledger->read(keylet::fees()));
ledger->setImmutable();

JLOG(j.trace()) << "Loaded ledger: " << to_string(ledger->info().hash);
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/ledger/impl/BuildLedger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ buildLedgerImpl(
// Accept ledger
assert(
built->info().seq < XRP_LEDGER_EARLIEST_FEES ||
built->readSLE(keylet::fees()));
built->read(keylet::fees()));
built->setAccepted(closeTime, closeResolution, closeTimeCorrect);

return built;
Expand Down
6 changes: 3 additions & 3 deletions src/ripple/app/ledger/impl/InboundLedger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ InboundLedger::init(ScopedLockType& collectionLock)
<< " local store. " << hash_;
assert(
mLedger->info().seq < XRP_LEDGER_EARLIEST_FEES ||
mLedger->readSLE(keylet::fees()));
mLedger->read(keylet::fees()));
mLedger->setImmutable();

if (mReason == Reason::HISTORY || mReason == Reason::SHARD)
Expand Down Expand Up @@ -421,7 +421,7 @@ InboundLedger::tryDB(NodeStore::Database& srcDB)
complete_ = true;
assert(
mLedger->info().seq < XRP_LEDGER_EARLIEST_FEES ||
mLedger->readSLE(keylet::fees()));
mLedger->read(keylet::fees()));
mLedger->setImmutable();
}
}
Expand Down Expand Up @@ -521,7 +521,7 @@ InboundLedger::done()
{
assert(
mLedger->info().seq < XRP_LEDGER_EARLIEST_FEES ||
mLedger->readSLE(keylet::fees()));
mLedger->read(keylet::fees()));
mLedger->setImmutable();
switch (mReason)
{
Expand Down
6 changes: 3 additions & 3 deletions src/ripple/app/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1712,7 +1712,7 @@ ApplicationImp::startGenesisLedger()
next->updateSkipList();
assert(
next->info().seq < XRP_LEDGER_EARLIEST_FEES ||
next->readSLE(keylet::fees()));
next->read(keylet::fees()));
next->setImmutable();
openLedger_.emplace(next, cachedSLEs_, logs_->journal("OpenLedger"));
m_ledgerMaster->storeLedger(next);
Expand All @@ -1733,7 +1733,7 @@ ApplicationImp::getLastFullLedger()

assert(
ledger->info().seq < XRP_LEDGER_EARLIEST_FEES ||
ledger->readSLE(keylet::fees()));
ledger->read(keylet::fees()));
ledger->setImmutable();

if (getLedgerMaster().haveLedger(seq))
Expand Down Expand Up @@ -1887,7 +1887,7 @@ ApplicationImp::loadLedgerFromFile(std::string const& name)

assert(
loadLedger->info().seq < XRP_LEDGER_EARLIEST_FEES ||
loadLedger->readSLE(keylet::fees()));
loadLedger->read(keylet::fees()));
loadLedger->setAccepted(
closeTime, closeTimeResolution, !closeTimeEstimated);

Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/reporting/ReportingETL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ ReportingETL::flushLedger(std::shared_ptr<Ledger>& ledger)

assert(
ledger->info().seq < XRP_LEDGER_EARLIEST_FEES ||
ledger->readSLE(keylet::fees()));
ledger->read(keylet::fees()));
ledger->setImmutable(false);
auto start = std::chrono::system_clock::now();

Expand Down
2 changes: 2 additions & 0 deletions src/ripple/app/tx/impl/Change.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ Change::applyFee()
{
auto const k = keylet::fees();

// It is advantageous to let feeObject be a SLE instead of FeesLgrObject
// SLE is optimised for set operations
SLE::pointer feeObject = view().peekSLE(k);

if (!feeObject)
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/nodestore/impl/Shard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ Shard::finalize(bool writeSQLite, std::optional<uint256> const& referenceHash)
ledger->txMap().setLedgerSeq(ledgerSeq);
assert(
ledger->info().seq < XRP_LEDGER_EARLIEST_FEES ||
ledger->readSLE(keylet::fees()));
ledger->read(keylet::fees()));
ledger->setImmutable();
if (!ledger->stateMap().fetchRoot(
SHAMapHash{ledger->info().accountHash}, nullptr))
Expand Down
100 changes: 100 additions & 0 deletions src/ripple/protocol/Fees.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2021 Ripple Labs Inc.

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================

#ifndef RIPPLE_PROTOCOL_FEES_H_INCLUDED
#define RIPPLE_PROTOCOL_FEES_H_INCLUDED

#include <ripple/protocol/LedgerEntryWrapper.h>

namespace ripple {


template <bool Writable>
class FeesImpl final : public LedgerEntryWrapper<Writable>
{
private:
using Base = LedgerEntryWrapper<Writable>;
using SleT = typename Base::SleT;
using Base::wrapped_;

// This constructor is private so only the factory functions can
// construct an FeesImpl.
FeesImpl(std::shared_ptr<SleT>&& w) : Base(std::move(w))
{
}

// Friend declarations of factory functions.
//
// For classes that contain factories we must declare the entire class
// as a friend unless the class declaration is visible at this point.
friend class ReadView;
friend class ApplyView;

public:
// Conversion operator from FeesImpl<true> to FeesImpl<false>.
operator FeesImpl<true>() const
{
return FeesImpl<false>(
std::const_pointer_cast<std::shared_ptr<STLedgerEntry const>>(
wrapped_));
}

[[nodiscard]] auto
baseFeeDrops() const
{
return wrapped_->at(~sfBaseFeeDrops);
}

[[nodiscard]] auto
baseFee() const
{
return wrapped_->at(~sfBaseFee);
}

[[nodiscard]] auto
reserveBase() const
{
return wrapped_->at(~sfReserveBase);
}

[[nodiscard]] auto
reserveIncrement() const
{
return wrapped_->at(~sfReserveIncrement);
}

[[nodiscard]] auto
reserveBaseDrops() const
{
return wrapped_->at(~sfReserveBaseDrops);
}

[[nodiscard]] auto
reserveIncrementDrops() const
{
return wrapped_->at(~sfReserveIncrementDrops);
}
};

using FeesLgrObjectRd = FeesImpl<false>;
using FeesLgrObject = FeesImpl<true>;

} // namespace ripple

#endif // RIPPLE_PROTOCOL_FEES_H_INCLUDED
4 changes: 2 additions & 2 deletions src/ripple/protocol/Indexes.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ skip() noexcept;
Keylet
skip(LedgerIndex ledger) noexcept;

/** The (fixed) index of the object containing the ledger fees. */
Keylet const&
/** The (permanent) index of the object containing the ledger fees. */
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think that comment change helps clarify the meaning. Thanks.

FeesKeylet const&
fees() noexcept;

/** The (fixed) index of the object containing the ledger negativeUNL. */
Expand Down
16 changes: 16 additions & 0 deletions src/ripple/protocol/Keylet.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ static_assert(std::is_move_assignable_v<Keylet>);
static_assert(std::is_nothrow_destructible_v<Keylet>);
#endif

template <bool>
class FeesImpl;

struct FeesKeylet final : public KeyletBase
{
template <bool Writable>
using TWrapped = FeesImpl<Writable>;

using KeyletBase::check;

explicit FeesKeylet(uint256 const& key)
: KeyletBase(ltFEE_SETTINGS, key)
{
}
};

template <bool>
class AcctRootImpl;

Expand Down
5 changes: 2 additions & 3 deletions src/ripple/protocol/impl/Indexes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,11 +167,10 @@ amendments() noexcept
return ret;
}

Keylet const&
FeesKeylet const&
fees() noexcept
{
static Keylet const ret{
ltFEE_SETTINGS, indexHash(LedgerNameSpace::FEE_SETTINGS)};
static FeesKeylet const ret(indexHash(LedgerNameSpace::FEE_SETTINGS));
return ret;
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/app/RCLValidations_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

#include <ripple/app/consensus/RCLValidations.h>
#include <ripple/app/ledger/Ledger.h>
#include <ripple/basics/Log.h>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing that Log.h is not needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CLion did it for me :)

#include <ripple/basics/StringUtilities.h>
#include <ripple/basics/base_uint.h>
#include <ripple/beast/unit_test.h>
#include <ripple/ledger/View.h>
#include <test/jtx.h>
#include <ripple/protocol/Fees.h>

namespace ripple {
namespace test {
Expand Down Expand Up @@ -106,7 +106,7 @@ class RCLValidations_test : public beast::unit_test::suite
*prev, env.app().timeKeeper().closeTime());
// Force a different hash on the first iteration
next->updateSkipList();
BEAST_EXPECT(next->readSLE(keylet::fees()));
BEAST_EXPECT(next->read(keylet::fees()));
if (forceHash)
{
next->setImmutable();
Expand Down