mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-30 23:45:48 +00:00
Compare commits
3 Commits
multiple_t
...
fixPageCap
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff82ea1305 | ||
|
|
f2f9983590 | ||
|
|
faebfce3ed |
2
.github/workflows/clang-format.yml
vendored
2
.github/workflows/clang-format.yml
vendored
@@ -30,7 +30,7 @@ jobs:
|
||||
git diff --exit-code | tee "clang-format.patch"
|
||||
- name: Upload patch
|
||||
if: failure() && steps.assert.outcome == 'failure'
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v2
|
||||
continue-on-error: true
|
||||
with:
|
||||
name: clang-format.patch
|
||||
|
||||
2
.github/workflows/levelization.yml
vendored
2
.github/workflows/levelization.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
git diff --exit-code | tee "levelization.patch"
|
||||
- name: Upload patch
|
||||
if: failure() && steps.assert.outcome == 'failure'
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v2
|
||||
continue-on-error: true
|
||||
with:
|
||||
name: levelization.patch
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# Xahau
|
||||
# Xahau
|
||||
|
||||
**Note:** Throughout this README, references to "we" or "our" pertain to the community and contributors involved in the Xahau network. It does not imply a legal entity or a specific collection of individuals.
|
||||
|
||||
@@ -68,4 +68,4 @@ git-subtree. See those directories' README files for more details.
|
||||
- **Testnet & Faucet**: Test applications and obtain test XAH at [xahau-test.net](https://xahau-test.net) and use the testnet explorer at [explorer.xahau.network](https://explorer.xahau.network).
|
||||
- **Supporting Wallets**: A list of wallets that support XAH and Xahau-based assets.
|
||||
- [Xumm](https://xumm.app)
|
||||
- [Crossmark](https://crossmark.io)
|
||||
- [Crossmark](https://crossmark.io)
|
||||
@@ -134,12 +134,8 @@ RCLConsensus::Adaptor::acquireLedger(LedgerHash const& hash)
|
||||
acquiringLedger_ = hash;
|
||||
|
||||
app_.getJobQueue().addJob(
|
||||
jtADVANCE,
|
||||
"getConsensusLedger1",
|
||||
[id = hash, &app = app_, this]() {
|
||||
JLOG(j_.debug())
|
||||
<< "JOB advanceLedger getConsensusLedger1 started";
|
||||
app.getInboundLedgers().acquireAsync(
|
||||
jtADVANCE, "getConsensusLedger", [id = hash, &app = app_]() {
|
||||
app.getInboundLedgers().acquire(
|
||||
id, 0, InboundLedger::Reason::CONSENSUS);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -135,10 +135,8 @@ RCLValidationsAdaptor::acquire(LedgerHash const& hash)
|
||||
Application* pApp = &app_;
|
||||
|
||||
app_.getJobQueue().addJob(
|
||||
jtADVANCE, "getConsensusLedger2", [pApp, hash, this]() {
|
||||
JLOG(j_.debug())
|
||||
<< "JOB advanceLedger getConsensusLedger2 started";
|
||||
pApp->getInboundLedgers().acquireAsync(
|
||||
jtADVANCE, "getConsensusLedger", [pApp, hash]() {
|
||||
pApp->getInboundLedgers().acquire(
|
||||
hash, 0, InboundLedger::Reason::CONSENSUS);
|
||||
});
|
||||
return std::nullopt;
|
||||
@@ -154,9 +152,7 @@ void
|
||||
handleNewValidation(
|
||||
Application& app,
|
||||
std::shared_ptr<STValidation> const& val,
|
||||
std::string const& source,
|
||||
BypassAccept const bypassAccept,
|
||||
std::optional<beast::Journal> j)
|
||||
std::string const& source)
|
||||
{
|
||||
auto const& signingKey = val->getSignerPublic();
|
||||
auto const& hash = val->getLedgerHash();
|
||||
@@ -181,23 +177,7 @@ handleNewValidation(
|
||||
if (outcome == ValStatus::current)
|
||||
{
|
||||
if (val->isTrusted())
|
||||
{
|
||||
// Was: app.getLedgerMaster().checkAccept(hash, seq);
|
||||
// https://github.com/XRPLF/rippled/commit/fbbea9e6e25795a8a6bd1bf64b780771933a9579
|
||||
if (bypassAccept == BypassAccept::yes)
|
||||
{
|
||||
assert(j.has_value());
|
||||
if (j.has_value())
|
||||
{
|
||||
JLOG(j->trace()) << "Bypassing checkAccept for validation "
|
||||
<< val->getLedgerHash();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
app.getLedgerMaster().checkAccept(hash, seq);
|
||||
}
|
||||
}
|
||||
app.getLedgerMaster().checkAccept(hash, seq);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,16 +25,12 @@
|
||||
#include <ripple/protocol/Protocol.h>
|
||||
#include <ripple/protocol/RippleLedgerHash.h>
|
||||
#include <ripple/protocol/STValidation.h>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
class Application;
|
||||
|
||||
enum class BypassAccept : bool { no = false, yes };
|
||||
|
||||
/** Wrapper over STValidation for generic Validation code
|
||||
|
||||
Wraps an STValidation for compatibility with the generic validation code.
|
||||
@@ -252,9 +248,7 @@ void
|
||||
handleNewValidation(
|
||||
Application& app,
|
||||
std::shared_ptr<STValidation> const& val,
|
||||
std::string const& source,
|
||||
BypassAccept const bypassAccept = BypassAccept::no,
|
||||
std::optional<beast::Journal> j = std::nullopt);
|
||||
std::string const& source);
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
|
||||
@@ -38,21 +38,10 @@ public:
|
||||
virtual ~InboundLedgers() = default;
|
||||
|
||||
// VFALCO TODO Should this be called findOrAdd ?
|
||||
// Callers should use this if they possibly need an authoritative
|
||||
// response immediately.
|
||||
//
|
||||
virtual std::shared_ptr<Ledger const>
|
||||
acquire(uint256 const& hash, std::uint32_t seq, InboundLedger::Reason) = 0;
|
||||
|
||||
// Callers should use this if they are known to be executing on the Job
|
||||
// Queue. TODO review whether all callers of acquire() can use this
|
||||
// instead. Inbound ledger acquisition is asynchronous anyway.
|
||||
virtual void
|
||||
acquireAsync(
|
||||
uint256 const& hash,
|
||||
std::uint32_t seq,
|
||||
InboundLedger::Reason reason) = 0;
|
||||
|
||||
virtual std::shared_ptr<InboundLedger>
|
||||
find(LedgerHash const& hash) = 0;
|
||||
|
||||
|
||||
@@ -58,15 +58,12 @@ LedgerHistory::insert(std::shared_ptr<Ledger const> ledger, bool validated)
|
||||
|
||||
assert(ledger->stateMap().getHash().isNonZero());
|
||||
|
||||
std::unique_lock sl(m_ledgers_by_hash.peekMutex(ledger->info().hash));
|
||||
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
|
||||
|
||||
const bool alreadyHad = m_ledgers_by_hash.canonicalize_replace_cache(
|
||||
ledger->info().hash, ledger);
|
||||
if (validated)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(mLedgersByIndexMutex);
|
||||
mLedgersByIndex[ledger->info().seq] = ledger->info().hash;
|
||||
}
|
||||
|
||||
return alreadyHad;
|
||||
}
|
||||
@@ -74,7 +71,7 @@ LedgerHistory::insert(std::shared_ptr<Ledger const> ledger, bool validated)
|
||||
LedgerHash
|
||||
LedgerHistory::getLedgerHash(LedgerIndex index)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(mLedgersByIndexMutex);
|
||||
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
|
||||
auto it = mLedgersByIndex.find(index);
|
||||
|
||||
if (it != mLedgersByIndex.end())
|
||||
@@ -87,13 +84,13 @@ std::shared_ptr<Ledger const>
|
||||
LedgerHistory::getLedgerBySeq(LedgerIndex index)
|
||||
{
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(mLedgersByIndexMutex);
|
||||
|
||||
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
|
||||
auto it = mLedgersByIndex.find(index);
|
||||
|
||||
if (it != mLedgersByIndex.end())
|
||||
{
|
||||
uint256 hash = it->second;
|
||||
sl.unlock();
|
||||
return getLedgerByHash(hash);
|
||||
}
|
||||
}
|
||||
@@ -107,17 +104,11 @@ LedgerHistory::getLedgerBySeq(LedgerIndex index)
|
||||
|
||||
{
|
||||
// Add this ledger to the local tracking by index
|
||||
{
|
||||
std::unique_lock sl(m_ledgers_by_hash.peekMutex(ret->info().hash));
|
||||
assert(ret->isImmutable());
|
||||
m_ledgers_by_hash.canonicalize_replace_client(
|
||||
ret->info().hash, ret);
|
||||
}
|
||||
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
|
||||
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(mLedgersByIndexMutex);
|
||||
mLedgersByIndex[ret->info().seq] = ret->info().hash;
|
||||
}
|
||||
assert(ret->isImmutable());
|
||||
m_ledgers_by_hash.canonicalize_replace_client(ret->info().hash, ret);
|
||||
mLedgersByIndex[ret->info().seq] = ret->info().hash;
|
||||
return (ret->info().seq == index) ? ret : nullptr;
|
||||
}
|
||||
}
|
||||
@@ -449,7 +440,7 @@ LedgerHistory::builtLedger(
|
||||
LedgerHash hash = ledger->info().hash;
|
||||
assert(!hash.isZero());
|
||||
|
||||
std::unique_lock sl(m_consensus_validated.peekMutex(index));
|
||||
std::unique_lock sl(m_consensus_validated.peekMutex());
|
||||
|
||||
auto entry = std::make_shared<cv_entry>();
|
||||
m_consensus_validated.canonicalize_replace_client(index, entry);
|
||||
@@ -489,7 +480,7 @@ LedgerHistory::validatedLedger(
|
||||
LedgerHash hash = ledger->info().hash;
|
||||
assert(!hash.isZero());
|
||||
|
||||
std::unique_lock sl(m_consensus_validated.peekMutex(index));
|
||||
std::unique_lock sl(m_consensus_validated.peekMutex());
|
||||
|
||||
auto entry = std::make_shared<cv_entry>();
|
||||
m_consensus_validated.canonicalize_replace_client(index, entry);
|
||||
@@ -524,7 +515,7 @@ LedgerHistory::validatedLedger(
|
||||
bool
|
||||
LedgerHistory::fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(mLedgersByIndexMutex);
|
||||
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
|
||||
auto it = mLedgersByIndex.find(ledgerIndex);
|
||||
|
||||
if ((it != mLedgersByIndex.end()) && (it->second != ledgerHash))
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
#include <ripple/protocol/RippleLedgerHash.h>
|
||||
|
||||
#include <optional>
|
||||
#include <shared_mutex>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
@@ -151,7 +150,6 @@ private:
|
||||
|
||||
// Maps ledger indexes to the corresponding hash.
|
||||
std::map<LedgerIndex, LedgerHash> mLedgersByIndex; // validated ledgers
|
||||
std::shared_mutex mLedgersByIndexMutex;
|
||||
|
||||
beast::Journal j_;
|
||||
};
|
||||
|
||||
@@ -560,7 +560,7 @@ InboundLedger::trigger(std::shared_ptr<Peer> const& peer, TriggerReason reason)
|
||||
return;
|
||||
}
|
||||
|
||||
if (auto stream = journal_.debug())
|
||||
if (auto stream = journal_.trace())
|
||||
{
|
||||
if (peer)
|
||||
stream << "Trigger acquiring ledger " << hash_ << " from " << peer;
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
#include <ripple/core/JobQueue.h>
|
||||
#include <ripple/nodestore/DatabaseShard.h>
|
||||
#include <ripple/protocol/jss.h>
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
@@ -142,37 +141,6 @@ public:
|
||||
return inbound->getLedger();
|
||||
}
|
||||
|
||||
void
|
||||
acquireAsync(
|
||||
uint256 const& hash,
|
||||
std::uint32_t seq,
|
||||
InboundLedger::Reason reason) override
|
||||
{
|
||||
std::unique_lock lock(acquiresMutex_);
|
||||
try
|
||||
{
|
||||
if (pendingAcquires_.contains(hash))
|
||||
return;
|
||||
pendingAcquires_.insert(hash);
|
||||
lock.unlock();
|
||||
acquire(hash, seq, reason);
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
JLOG(j_.warn())
|
||||
<< "Exception thrown for acquiring new inbound ledger " << hash
|
||||
<< ": " << e.what();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
JLOG(j_.warn())
|
||||
<< "Unknown exception thrown for acquiring new inbound ledger "
|
||||
<< hash;
|
||||
}
|
||||
lock.lock();
|
||||
pendingAcquires_.erase(hash);
|
||||
}
|
||||
|
||||
std::shared_ptr<InboundLedger>
|
||||
find(uint256 const& hash) override
|
||||
{
|
||||
@@ -458,9 +426,6 @@ private:
|
||||
beast::insight::Counter mCounter;
|
||||
|
||||
std::unique_ptr<PeerSetBuilder> mPeerSetBuilder;
|
||||
|
||||
std::set<uint256> pendingAcquires_;
|
||||
std::mutex acquiresMutex_;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -70,9 +70,7 @@
|
||||
#include <boost/asio/ip/host_name.hpp>
|
||||
#include <boost/asio/steady_timer.hpp>
|
||||
|
||||
#include <exception>
|
||||
#include <mutex>
|
||||
#include <set>
|
||||
#include <string>
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
@@ -778,9 +776,6 @@ private:
|
||||
|
||||
StateAccounting accounting_{};
|
||||
|
||||
std::set<uint256> pendingValidations_;
|
||||
std::mutex validationsMutex_;
|
||||
|
||||
private:
|
||||
struct Stats
|
||||
{
|
||||
@@ -1796,8 +1791,7 @@ NetworkOPsImp::checkLastClosedLedger(
|
||||
}
|
||||
|
||||
JLOG(m_journal.warn()) << "We are not running on the consensus ledger";
|
||||
JLOG(m_journal.info()) << "Our LCL: " << ourClosed->info().hash
|
||||
<< getJson({*ourClosed, {}});
|
||||
JLOG(m_journal.info()) << "Our LCL: " << getJson({*ourClosed, {}});
|
||||
JLOG(m_journal.info()) << "Net LCL " << closedLedger;
|
||||
|
||||
if ((mMode == OperatingMode::TRACKING) || (mMode == OperatingMode::FULL))
|
||||
@@ -2351,37 +2345,7 @@ NetworkOPsImp::recvValidation(
|
||||
JLOG(m_journal.trace())
|
||||
<< "recvValidation " << val->getLedgerHash() << " from " << source;
|
||||
|
||||
// handleNewValidation(app_, val, source);
|
||||
// https://github.com/XRPLF/rippled/commit/fbbea9e6e25795a8a6bd1bf64b780771933a9579
|
||||
std::unique_lock lock(validationsMutex_);
|
||||
BypassAccept bypassAccept = BypassAccept::no;
|
||||
try
|
||||
{
|
||||
if (pendingValidations_.contains(val->getLedgerHash()))
|
||||
bypassAccept = BypassAccept::yes;
|
||||
else
|
||||
pendingValidations_.insert(val->getLedgerHash());
|
||||
lock.unlock();
|
||||
handleNewValidation(app_, val, source, bypassAccept, m_journal);
|
||||
}
|
||||
catch (std::exception const& e)
|
||||
{
|
||||
JLOG(m_journal.warn())
|
||||
<< "Exception thrown for handling new validation "
|
||||
<< val->getLedgerHash() << ": " << e.what();
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
JLOG(m_journal.warn())
|
||||
<< "Unknown exception thrown for handling new validation "
|
||||
<< val->getLedgerHash();
|
||||
}
|
||||
if (bypassAccept == BypassAccept::no)
|
||||
{
|
||||
lock.lock();
|
||||
pendingValidations_.erase(val->getLedgerHash());
|
||||
lock.unlock();
|
||||
}
|
||||
handleNewValidation(app_, val, source);
|
||||
|
||||
pubValidation(val);
|
||||
|
||||
|
||||
@@ -111,7 +111,7 @@ public:
|
||||
std::uint32_t minimumTxnInLedgerSA = 1000;
|
||||
/// Number of transactions per ledger that fee escalation "works
|
||||
/// towards".
|
||||
std::uint32_t targetTxnInLedger = 1000;
|
||||
std::uint32_t targetTxnInLedger = 256;
|
||||
/** Optional maximum allowed value of transactions per ledger before
|
||||
fee escalation kicks in. By default, the maximum is an emergent
|
||||
property of network, validator, and consensus performance. This
|
||||
|
||||
@@ -1923,7 +1923,6 @@ Transactor::operator()()
|
||||
uint32_t lgrCur = view().seq();
|
||||
|
||||
bool const has240819 = view().rules().enabled(fix240819);
|
||||
bool const has240911 = view().rules().enabled(fix240911);
|
||||
|
||||
auto const& sfRewardFields =
|
||||
*(ripple::SField::knownCodeToField.at(917511 - has240819));
|
||||
@@ -1972,11 +1971,7 @@ Transactor::operator()()
|
||||
uint32_t lgrElapsed = lgrCur - lgrLast;
|
||||
|
||||
// overflow safety
|
||||
if (!has240911 &&
|
||||
(lgrElapsed > lgrCur || lgrElapsed > lgrLast ||
|
||||
lgrElapsed == 0))
|
||||
continue;
|
||||
if (has240911 && (lgrElapsed > lgrCur || lgrElapsed == 0))
|
||||
if (lgrElapsed > lgrCur || lgrElapsed > lgrLast || lgrElapsed == 0)
|
||||
continue;
|
||||
|
||||
uint64_t accum = sle->getFieldU64(sfRewardAccumulator);
|
||||
|
||||
@@ -53,7 +53,7 @@ template <
|
||||
class Hash = hardened_hash<>,
|
||||
class KeyEqual = std::equal_to<Key>,
|
||||
class Mutex = std::recursive_mutex>
|
||||
class TaggedCacheSingle
|
||||
class TaggedCache
|
||||
{
|
||||
public:
|
||||
using mutex_type = Mutex;
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
using clock_type = beast::abstract_clock<std::chrono::steady_clock>;
|
||||
|
||||
public:
|
||||
TaggedCacheSingle(
|
||||
TaggedCache(
|
||||
std::string const& name,
|
||||
int size,
|
||||
clock_type::duration expiration,
|
||||
@@ -74,7 +74,7 @@ public:
|
||||
, m_clock(clock)
|
||||
, m_stats(
|
||||
name,
|
||||
std::bind(&TaggedCacheSingle::collect_metrics, this),
|
||||
std::bind(&TaggedCache::collect_metrics, this),
|
||||
collector)
|
||||
, m_name(name)
|
||||
, m_target_size(size)
|
||||
@@ -258,7 +258,7 @@ public:
|
||||
// At this point allStuffToSweep will go out of scope outside the lock
|
||||
// and decrement the reference count on each strong pointer.
|
||||
JLOG(m_journal.debug())
|
||||
<< m_name << " TaggedCacheSingle sweep lock duration "
|
||||
<< m_name << " TaggedCache sweep lock duration "
|
||||
<< std::chrono::duration_cast<std::chrono::milliseconds>(
|
||||
std::chrono::steady_clock::now() - start)
|
||||
.count()
|
||||
@@ -715,7 +715,7 @@ private:
|
||||
if (mapRemovals || cacheRemovals)
|
||||
{
|
||||
JLOG(m_journal.debug())
|
||||
<< "TaggedCacheSingle partition sweep " << m_name
|
||||
<< "TaggedCache partition sweep " << m_name
|
||||
<< ": cache = " << partition.size() << "-" << cacheRemovals
|
||||
<< ", map-=" << mapRemovals;
|
||||
}
|
||||
@@ -762,7 +762,7 @@ private:
|
||||
if (mapRemovals || cacheRemovals)
|
||||
{
|
||||
JLOG(m_journal.debug())
|
||||
<< "TaggedCacheSingle partition sweep " << m_name
|
||||
<< "TaggedCache partition sweep " << m_name
|
||||
<< ": cache = " << partition.size() << "-" << cacheRemovals
|
||||
<< ", map-=" << mapRemovals;
|
||||
}
|
||||
@@ -793,253 +793,6 @@ private:
|
||||
std::uint64_t m_misses;
|
||||
};
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
template <
|
||||
class Key,
|
||||
class T,
|
||||
bool IsKeyCache = false,
|
||||
class Hash = hardened_hash<>,
|
||||
class KeyEqual = std::equal_to<Key>,
|
||||
class Mutex = std::recursive_mutex>
|
||||
class TaggedCache
|
||||
{
|
||||
private:
|
||||
static constexpr size_t NUM_CACHES = 16;
|
||||
|
||||
using CacheType =
|
||||
TaggedCacheSingle<Key, T, IsKeyCache, Hash, KeyEqual, Mutex>;
|
||||
std::array<std::unique_ptr<CacheType>, NUM_CACHES> caches;
|
||||
|
||||
// Helper function to get the index of the cache based on the key
|
||||
size_t
|
||||
getCacheIndex(const Key& key) const
|
||||
{
|
||||
// Assuming Key can be hashed
|
||||
size_t hash = Hash{}(key);
|
||||
return hash & 0xF; // Use the least significant nibble
|
||||
}
|
||||
|
||||
public:
|
||||
using mutex_type = Mutex;
|
||||
using key_type = Key;
|
||||
using mapped_type = T;
|
||||
using clock_type = beast::abstract_clock<std::chrono::steady_clock>;
|
||||
|
||||
TaggedCache(
|
||||
std::string const& name,
|
||||
int size,
|
||||
clock_type::duration expiration,
|
||||
clock_type& clock,
|
||||
beast::Journal journal,
|
||||
beast::insight::Collector::ptr const& collector =
|
||||
beast::insight::NullCollector::New())
|
||||
{
|
||||
for (size_t i = 0; i < NUM_CACHES; ++i)
|
||||
{
|
||||
caches[i] = std::make_unique<CacheType>(
|
||||
name + "_" + std::to_string(i),
|
||||
size / NUM_CACHES, // Distribute size across caches
|
||||
expiration,
|
||||
clock,
|
||||
journal,
|
||||
collector);
|
||||
}
|
||||
}
|
||||
|
||||
// Implement all public methods of TaggedCache, delegating to the
|
||||
// appropriate cache instance
|
||||
|
||||
clock_type&
|
||||
clock()
|
||||
{
|
||||
return caches[0]->clock(); // All caches share the same clock
|
||||
}
|
||||
|
||||
std::size_t
|
||||
size() const
|
||||
{
|
||||
std::size_t total = 0;
|
||||
for (const auto& cache : caches)
|
||||
total += cache->size();
|
||||
return total;
|
||||
}
|
||||
|
||||
void
|
||||
setTargetSize(int s)
|
||||
{
|
||||
int sizePerCache = s / NUM_CACHES;
|
||||
for (auto& cache : caches)
|
||||
cache->setTargetSize(sizePerCache);
|
||||
}
|
||||
|
||||
clock_type::duration
|
||||
getTargetAge() const
|
||||
{
|
||||
return caches[0]
|
||||
->getTargetAge(); // All caches share the same target age
|
||||
}
|
||||
|
||||
void
|
||||
setTargetAge(clock_type::duration s)
|
||||
{
|
||||
for (auto& cache : caches)
|
||||
cache->setTargetAge(s);
|
||||
}
|
||||
|
||||
int
|
||||
getCacheSize() const
|
||||
{
|
||||
int total = 0;
|
||||
for (const auto& cache : caches)
|
||||
total += cache->getCacheSize();
|
||||
return total;
|
||||
}
|
||||
|
||||
int
|
||||
getTrackSize() const
|
||||
{
|
||||
int total = 0;
|
||||
for (const auto& cache : caches)
|
||||
total += cache->getTrackSize();
|
||||
return total;
|
||||
}
|
||||
|
||||
float
|
||||
getHitRate()
|
||||
{
|
||||
float totalHitRate = 0;
|
||||
for (const auto& cache : caches)
|
||||
totalHitRate += cache->getHitRate();
|
||||
return totalHitRate / NUM_CACHES;
|
||||
}
|
||||
|
||||
void
|
||||
clear()
|
||||
{
|
||||
for (auto& cache : caches)
|
||||
cache->clear();
|
||||
}
|
||||
|
||||
void
|
||||
reset()
|
||||
{
|
||||
for (auto& cache : caches)
|
||||
cache->reset();
|
||||
}
|
||||
|
||||
template <class KeyComparable>
|
||||
bool
|
||||
touch_if_exists(KeyComparable const& key)
|
||||
{
|
||||
return caches[getCacheIndex(key)]->touch_if_exists(key);
|
||||
}
|
||||
|
||||
void
|
||||
sweep()
|
||||
{
|
||||
for (auto& cache : caches)
|
||||
cache->sweep();
|
||||
}
|
||||
|
||||
bool
|
||||
del(const key_type& key, bool valid)
|
||||
{
|
||||
return caches[getCacheIndex(key)]->del(key, valid);
|
||||
}
|
||||
|
||||
bool
|
||||
canonicalize(
|
||||
const key_type& key,
|
||||
std::shared_ptr<T>& data,
|
||||
std::function<bool(std::shared_ptr<T> const&)>&& replace)
|
||||
{
|
||||
return caches[getCacheIndex(key)]->canonicalize(
|
||||
key, data, std::move(replace));
|
||||
}
|
||||
|
||||
bool
|
||||
canonicalize_replace_cache(
|
||||
const key_type& key,
|
||||
std::shared_ptr<T> const& data)
|
||||
{
|
||||
return caches[getCacheIndex(key)]->canonicalize_replace_cache(
|
||||
key, data);
|
||||
}
|
||||
|
||||
bool
|
||||
canonicalize_replace_client(const key_type& key, std::shared_ptr<T>& data)
|
||||
{
|
||||
return caches[getCacheIndex(key)]->canonicalize_replace_client(
|
||||
key, data);
|
||||
}
|
||||
|
||||
std::shared_ptr<T>
|
||||
fetch(const key_type& key)
|
||||
{
|
||||
return caches[getCacheIndex(key)]->fetch(key);
|
||||
}
|
||||
|
||||
template <class ReturnType = bool>
|
||||
auto
|
||||
insert(key_type const& key, T const& value)
|
||||
-> std::enable_if_t<!IsKeyCache, ReturnType>
|
||||
{
|
||||
return caches[getCacheIndex(key)]->insert(key, value);
|
||||
}
|
||||
|
||||
template <class ReturnType = bool>
|
||||
auto
|
||||
insert(key_type const& key) -> std::enable_if_t<IsKeyCache, ReturnType>
|
||||
{
|
||||
return caches[getCacheIndex(key)]->insert(key);
|
||||
}
|
||||
|
||||
bool
|
||||
retrieve(const key_type& key, T& data)
|
||||
{
|
||||
return caches[getCacheIndex(key)]->retrieve(key, data);
|
||||
}
|
||||
|
||||
mutex_type&
|
||||
peekMutex(key_type const& key)
|
||||
{
|
||||
return caches[getCacheIndex(key)]->peekMutex();
|
||||
}
|
||||
|
||||
std::vector<key_type>
|
||||
getKeys() const
|
||||
{
|
||||
std::vector<key_type> allKeys;
|
||||
for (const auto& cache : caches)
|
||||
{
|
||||
auto keys = cache->getKeys();
|
||||
allKeys.insert(allKeys.end(), keys.begin(), keys.end());
|
||||
}
|
||||
return allKeys;
|
||||
}
|
||||
|
||||
double
|
||||
rate() const
|
||||
{
|
||||
double totalRate = 0;
|
||||
for (const auto& cache : caches)
|
||||
totalRate += cache->rate();
|
||||
return totalRate / NUM_CACHES;
|
||||
}
|
||||
|
||||
template <class Handler>
|
||||
std::shared_ptr<T>
|
||||
fetch(key_type const& digest, Handler const& h)
|
||||
{
|
||||
return caches[getCacheIndex(digest)]->fetch(digest, h);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
#endif
|
||||
|
||||
@@ -240,7 +240,7 @@ public:
|
||||
bool LEDGER_REPLAY = false;
|
||||
|
||||
// Work queue limits
|
||||
int MAX_TRANSACTIONS = 1000;
|
||||
int MAX_TRANSACTIONS = 250;
|
||||
static constexpr int MAX_JOB_QUEUE_TX = 1000;
|
||||
static constexpr int MIN_JOB_QUEUE_TX = 100;
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ namespace detail {
|
||||
// Feature.cpp. Because it's only used to reserve storage, and determine how
|
||||
// large to make the FeatureBitset, it MAY be larger. It MUST NOT be less than
|
||||
// the actual number of amendments. A LogicError on startup will verify this.
|
||||
static constexpr std::size_t numFeatures = 73;
|
||||
static constexpr std::size_t numFeatures = 72;
|
||||
|
||||
/** Amendments that this server supports and the default voting behavior.
|
||||
Whether they are enabled depends on the Rules defined in the validated
|
||||
@@ -360,7 +360,6 @@ extern uint256 const featureZeroB2M;
|
||||
extern uint256 const fixNSDelete;
|
||||
extern uint256 const fix240819;
|
||||
extern uint256 const fixPageCap;
|
||||
extern uint256 const fix240911;
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
|
||||
@@ -466,7 +466,6 @@ REGISTER_FEATURE(ZeroB2M, Supported::yes, VoteBehavior::De
|
||||
REGISTER_FIX (fixNSDelete, Supported::yes, VoteBehavior::DefaultNo);
|
||||
REGISTER_FIX (fix240819, Supported::yes, VoteBehavior::DefaultYes);
|
||||
REGISTER_FIX (fixPageCap, Supported::yes, VoteBehavior::DefaultYes);
|
||||
REGISTER_FIX (fix240911, Supported::yes, VoteBehavior::DefaultYes);
|
||||
|
||||
// The following amendments are obsolete, but must remain supported
|
||||
// because they could potentially get enabled.
|
||||
|
||||
@@ -106,14 +106,6 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
virtual void
|
||||
acquireAsync(
|
||||
uint256 const& hash,
|
||||
std::uint32_t seq,
|
||||
InboundLedger::Reason reason) override
|
||||
{
|
||||
}
|
||||
|
||||
virtual std::shared_ptr<InboundLedger>
|
||||
find(LedgerHash const& hash) override
|
||||
{
|
||||
|
||||
@@ -5020,550 +5020,6 @@ struct XahauGenesis_test : public beast::unit_test::suite
|
||||
BEAST_EXPECT(asPercent == 4);
|
||||
}
|
||||
|
||||
void
|
||||
testDeposit(FeatureBitset features)
|
||||
{
|
||||
using namespace jtx;
|
||||
using namespace std::chrono_literals;
|
||||
testcase("test deposit");
|
||||
|
||||
Env env{*this, envconfig(), features - featureXahauGenesis};
|
||||
|
||||
double const rateDrops = 0.00333333333 * 1'000'000;
|
||||
STAmount const feesXRP = XRP(1);
|
||||
|
||||
auto const user = Account("user");
|
||||
env.fund(XRP(1000), user);
|
||||
env.close();
|
||||
|
||||
// setup governance
|
||||
auto const alice = Account("alice");
|
||||
auto const bob = Account("bob");
|
||||
auto const carol = Account("carol");
|
||||
auto const david = Account("david");
|
||||
auto const edward = Account("edward");
|
||||
|
||||
env.fund(XRP(10000), alice, bob, carol, david, edward);
|
||||
env.close();
|
||||
|
||||
std::vector<AccountID> initial_members_ids{
|
||||
alice.id(), bob.id(), carol.id(), david.id(), edward.id()};
|
||||
|
||||
setupGov(env, initial_members_ids);
|
||||
|
||||
// update reward delay
|
||||
{
|
||||
// this will be the new reward delay
|
||||
// 100
|
||||
std::vector<uint8_t> vote_data{
|
||||
0x00U, 0x80U, 0xC6U, 0xA4U, 0x7EU, 0x8DU, 0x03U, 0x55U};
|
||||
|
||||
updateTopic(
|
||||
env, alice, bob, carol, david, edward, 'R', 'D', vote_data);
|
||||
}
|
||||
|
||||
// verify unl report does not exist
|
||||
BEAST_EXPECT(hasUNLReport(env) == false);
|
||||
|
||||
// opt in claim reward
|
||||
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
|
||||
env.close();
|
||||
|
||||
env(pay(alice, user, XRP(1000)));
|
||||
env.close();
|
||||
|
||||
// close ledgers
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
env.close(10s);
|
||||
}
|
||||
|
||||
// close claim ledger & time
|
||||
STAmount const preUser = env.balance(user);
|
||||
NetClock::time_point const preTime = lastClose(env);
|
||||
std::uint32_t const preLedger = env.current()->seq();
|
||||
auto const [acct, acctSle] = accountKeyAndSle(*env.current(), user);
|
||||
|
||||
// claim reward
|
||||
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
|
||||
env.close();
|
||||
|
||||
// trigger emitted txn
|
||||
env.close();
|
||||
|
||||
// calculate rewards
|
||||
bool const has240819 = env.current()->rules().enabled(fix240819);
|
||||
STAmount const netReward =
|
||||
rewardUserAmount(*acctSle, preLedger, rateDrops);
|
||||
BEAST_EXPECT(netReward == (has240819 ? XRP(6.383333) : XRP(6.663333)));
|
||||
|
||||
// validate account fields
|
||||
STAmount const postUser = preUser + netReward;
|
||||
BEAST_EXPECT(expectAccountFields(
|
||||
env,
|
||||
user,
|
||||
preLedger,
|
||||
preLedger + 1,
|
||||
has240819 ? (preUser - feesXRP) : postUser,
|
||||
preTime));
|
||||
BEAST_EXPECT(
|
||||
postUser == (has240819 ? XRP(2005.383333) : XRP(2005.663333)));
|
||||
}
|
||||
|
||||
void
|
||||
testDepositWithdraw(FeatureBitset features)
|
||||
{
|
||||
using namespace jtx;
|
||||
using namespace std::chrono_literals;
|
||||
testcase("test deposit withdraw");
|
||||
|
||||
Env env{*this, envconfig(), features - featureXahauGenesis};
|
||||
|
||||
double const rateDrops = 0.00333333333 * 1'000'000;
|
||||
STAmount const feesXRP = XRP(1);
|
||||
|
||||
auto const user = Account("user");
|
||||
env.fund(XRP(1000), user);
|
||||
env.close();
|
||||
|
||||
// setup governance
|
||||
auto const alice = Account("alice");
|
||||
auto const bob = Account("bob");
|
||||
auto const carol = Account("carol");
|
||||
auto const david = Account("david");
|
||||
auto const edward = Account("edward");
|
||||
|
||||
env.fund(XRP(10000), alice, bob, carol, david, edward);
|
||||
env.close();
|
||||
|
||||
std::vector<AccountID> initial_members_ids{
|
||||
alice.id(), bob.id(), carol.id(), david.id(), edward.id()};
|
||||
|
||||
setupGov(env, initial_members_ids);
|
||||
|
||||
// update reward delay
|
||||
{
|
||||
// this will be the new reward delay
|
||||
// 100
|
||||
std::vector<uint8_t> vote_data{
|
||||
0x00U, 0x80U, 0xC6U, 0xA4U, 0x7EU, 0x8DU, 0x03U, 0x55U};
|
||||
|
||||
updateTopic(
|
||||
env, alice, bob, carol, david, edward, 'R', 'D', vote_data);
|
||||
}
|
||||
|
||||
// verify unl report does not exist
|
||||
BEAST_EXPECT(hasUNLReport(env) == false);
|
||||
|
||||
// opt in claim reward
|
||||
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
|
||||
env.close();
|
||||
|
||||
env(pay(alice, user, XRP(1000)));
|
||||
env.close();
|
||||
|
||||
env(pay(user, alice, XRP(1000)));
|
||||
env.close();
|
||||
|
||||
// close ledgers
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
env.close(10s);
|
||||
}
|
||||
|
||||
// close claim ledger & time
|
||||
STAmount const preUser = env.balance(user);
|
||||
NetClock::time_point const preTime = lastClose(env);
|
||||
std::uint32_t const preLedger = env.current()->seq();
|
||||
auto const [acct, acctSle] = accountKeyAndSle(*env.current(), user);
|
||||
|
||||
// claim reward
|
||||
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
|
||||
env.close();
|
||||
|
||||
// trigger emitted txn
|
||||
env.close();
|
||||
|
||||
// calculate rewards
|
||||
bool const has240819 = env.current()->rules().enabled(fix240819);
|
||||
STAmount const netReward =
|
||||
rewardUserAmount(*acctSle, preLedger, rateDrops);
|
||||
BEAST_EXPECT(netReward == XRP(3.583333));
|
||||
|
||||
// validate account fields
|
||||
STAmount const postUser = preUser + netReward;
|
||||
BEAST_EXPECT(expectAccountFields(
|
||||
env,
|
||||
user,
|
||||
preLedger,
|
||||
preLedger + 1,
|
||||
has240819 ? (preUser - feesXRP) : postUser,
|
||||
preTime));
|
||||
BEAST_EXPECT(postUser == XRP(1002.583323));
|
||||
}
|
||||
|
||||
void
|
||||
testDepositLate(FeatureBitset features)
|
||||
{
|
||||
using namespace jtx;
|
||||
using namespace std::chrono_literals;
|
||||
testcase("test deposit late");
|
||||
|
||||
Env env{*this, envconfig(), features - featureXahauGenesis};
|
||||
|
||||
double const rateDrops = 0.00333333333 * 1'000'000;
|
||||
STAmount const feesXRP = XRP(1);
|
||||
|
||||
auto const user = Account("user");
|
||||
env.fund(XRP(1000), user);
|
||||
env.close();
|
||||
|
||||
// setup governance
|
||||
auto const alice = Account("alice");
|
||||
auto const bob = Account("bob");
|
||||
auto const carol = Account("carol");
|
||||
auto const david = Account("david");
|
||||
auto const edward = Account("edward");
|
||||
|
||||
env.fund(XRP(10000), alice, bob, carol, david, edward);
|
||||
env.close();
|
||||
|
||||
std::vector<AccountID> initial_members_ids{
|
||||
alice.id(), bob.id(), carol.id(), david.id(), edward.id()};
|
||||
|
||||
setupGov(env, initial_members_ids);
|
||||
|
||||
// update reward delay
|
||||
{
|
||||
// this will be the new reward delay
|
||||
// 100
|
||||
std::vector<uint8_t> vote_data{
|
||||
0x00U, 0x80U, 0xC6U, 0xA4U, 0x7EU, 0x8DU, 0x03U, 0x55U};
|
||||
|
||||
updateTopic(
|
||||
env, alice, bob, carol, david, edward, 'R', 'D', vote_data);
|
||||
}
|
||||
|
||||
// verify unl report does not exist
|
||||
BEAST_EXPECT(hasUNLReport(env) == false);
|
||||
|
||||
// opt in claim reward
|
||||
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
|
||||
env.close();
|
||||
|
||||
// close ledgers
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
env.close(10s);
|
||||
}
|
||||
|
||||
env(pay(alice, user, XRP(1000)));
|
||||
env.close();
|
||||
|
||||
// close claim ledger & time
|
||||
STAmount const preUser = env.balance(user);
|
||||
NetClock::time_point const preTime = lastClose(env);
|
||||
std::uint32_t const preLedger = env.current()->seq();
|
||||
auto const [acct, acctSle] = accountKeyAndSle(*env.current(), user);
|
||||
|
||||
// claim reward
|
||||
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
|
||||
env.close();
|
||||
|
||||
// trigger emitted txn
|
||||
env.close();
|
||||
|
||||
// calculate rewards
|
||||
bool const has240819 = env.current()->rules().enabled(fix240819);
|
||||
STAmount const netReward =
|
||||
rewardUserAmount(*acctSle, preLedger, rateDrops);
|
||||
BEAST_EXPECT(netReward == (has240819 ? XRP(3.606666) : XRP(6.663333)));
|
||||
|
||||
// validate account fields
|
||||
STAmount const postUser = preUser + netReward;
|
||||
BEAST_EXPECT(expectAccountFields(
|
||||
env,
|
||||
user,
|
||||
preLedger,
|
||||
preLedger + 1,
|
||||
has240819 ? (preUser - feesXRP) : postUser,
|
||||
preTime));
|
||||
BEAST_EXPECT(
|
||||
postUser == (has240819 ? XRP(2002.606666) : XRP(2005.663333)));
|
||||
}
|
||||
|
||||
void
|
||||
testDepositWithdrawLate(FeatureBitset features)
|
||||
{
|
||||
using namespace jtx;
|
||||
using namespace std::chrono_literals;
|
||||
testcase("test deposit late withdraw");
|
||||
|
||||
Env env{*this, envconfig(), features - featureXahauGenesis};
|
||||
|
||||
double const rateDrops = 0.00333333333 * 1'000'000;
|
||||
STAmount const feesXRP = XRP(1);
|
||||
|
||||
auto const user = Account("user");
|
||||
env.fund(XRP(1000), user);
|
||||
env.close();
|
||||
|
||||
// setup governance
|
||||
auto const alice = Account("alice");
|
||||
auto const bob = Account("bob");
|
||||
auto const carol = Account("carol");
|
||||
auto const david = Account("david");
|
||||
auto const edward = Account("edward");
|
||||
|
||||
env.fund(XRP(10000), alice, bob, carol, david, edward);
|
||||
env.close();
|
||||
|
||||
std::vector<AccountID> initial_members_ids{
|
||||
alice.id(), bob.id(), carol.id(), david.id(), edward.id()};
|
||||
|
||||
setupGov(env, initial_members_ids);
|
||||
|
||||
// update reward delay
|
||||
{
|
||||
// this will be the new reward delay
|
||||
// 100
|
||||
std::vector<uint8_t> vote_data{
|
||||
0x00U, 0x80U, 0xC6U, 0xA4U, 0x7EU, 0x8DU, 0x03U, 0x55U};
|
||||
|
||||
updateTopic(
|
||||
env, alice, bob, carol, david, edward, 'R', 'D', vote_data);
|
||||
}
|
||||
|
||||
// verify unl report does not exist
|
||||
BEAST_EXPECT(hasUNLReport(env) == false);
|
||||
|
||||
// opt in claim reward
|
||||
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
|
||||
env.close();
|
||||
|
||||
// close ledgers
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
env.close(10s);
|
||||
}
|
||||
|
||||
env(pay(alice, user, XRP(1000)));
|
||||
env.close();
|
||||
|
||||
env(pay(user, alice, XRP(1000)));
|
||||
env.close();
|
||||
|
||||
// close claim ledger & time
|
||||
STAmount const preUser = env.balance(user);
|
||||
NetClock::time_point const preTime = lastClose(env);
|
||||
std::uint32_t const preLedger = env.current()->seq();
|
||||
auto const [acct, acctSle] = accountKeyAndSle(*env.current(), user);
|
||||
|
||||
// claim reward
|
||||
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
|
||||
env.close();
|
||||
|
||||
// trigger emitted txn
|
||||
env.close();
|
||||
|
||||
// calculate rewards
|
||||
bool const has240819 = env.current()->rules().enabled(fix240819);
|
||||
STAmount const netReward =
|
||||
rewardUserAmount(*acctSle, preLedger, rateDrops);
|
||||
BEAST_EXPECT(netReward == (has240819 ? XRP(3.583333) : XRP(6.149999)));
|
||||
|
||||
// validate account fields
|
||||
STAmount const postUser = preUser + netReward;
|
||||
BEAST_EXPECT(expectAccountFields(
|
||||
env,
|
||||
user,
|
||||
preLedger,
|
||||
preLedger + 1,
|
||||
has240819 ? (preUser - feesXRP) : postUser,
|
||||
preTime));
|
||||
BEAST_EXPECT(
|
||||
postUser == (has240819 ? XRP(1002.583323) : XRP(1005.149989)));
|
||||
}
|
||||
|
||||
void
|
||||
testNoClaim(FeatureBitset features)
|
||||
{
|
||||
using namespace jtx;
|
||||
using namespace std::chrono_literals;
|
||||
testcase("test no claim");
|
||||
|
||||
Env env{*this, envconfig(), features - featureXahauGenesis};
|
||||
|
||||
double const rateDrops = 0.00333333333 * 1'000'000;
|
||||
STAmount const feesXRP = XRP(1);
|
||||
|
||||
auto const user = Account("user");
|
||||
env.fund(XRP(1000), user);
|
||||
env.close();
|
||||
|
||||
// setup governance
|
||||
auto const alice = Account("alice");
|
||||
auto const bob = Account("bob");
|
||||
auto const carol = Account("carol");
|
||||
auto const david = Account("david");
|
||||
auto const edward = Account("edward");
|
||||
|
||||
env.fund(XRP(10000), alice, bob, carol, david, edward);
|
||||
env.close();
|
||||
|
||||
std::vector<AccountID> initial_members_ids{
|
||||
alice.id(), bob.id(), carol.id(), david.id(), edward.id()};
|
||||
|
||||
setupGov(env, initial_members_ids);
|
||||
|
||||
// update reward delay
|
||||
{
|
||||
// this will be the new reward delay
|
||||
// 100
|
||||
std::vector<uint8_t> vote_data{
|
||||
0x00U, 0x80U, 0xC6U, 0xA4U, 0x7EU, 0x8DU, 0x03U, 0x55U};
|
||||
|
||||
updateTopic(
|
||||
env, alice, bob, carol, david, edward, 'R', 'D', vote_data);
|
||||
}
|
||||
|
||||
// verify unl report does not exist
|
||||
BEAST_EXPECT(hasUNLReport(env) == false);
|
||||
|
||||
// opt in claim reward
|
||||
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
|
||||
env.close();
|
||||
|
||||
// close ledgers (2 cycles)
|
||||
for (int i = 0; i < 20; ++i)
|
||||
{
|
||||
env.close(10s);
|
||||
}
|
||||
|
||||
// close claim ledger & time
|
||||
STAmount const preUser = env.balance(user);
|
||||
NetClock::time_point const preTime = lastClose(env);
|
||||
std::uint32_t const preLedger = env.current()->seq();
|
||||
auto const [acct, acctSle] = accountKeyAndSle(*env.current(), user);
|
||||
|
||||
// claim reward
|
||||
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
|
||||
env.close();
|
||||
|
||||
// trigger emitted txn
|
||||
env.close();
|
||||
|
||||
// calculate rewards
|
||||
bool const hasFix = env.current()->rules().enabled(fix240819) &&
|
||||
env.current()->rules().enabled(fix240911);
|
||||
STAmount const netReward =
|
||||
rewardUserAmount(*acctSle, preLedger, rateDrops);
|
||||
BEAST_EXPECT(netReward == (hasFix ? XRP(3.329999) : XRP(3.329999)));
|
||||
|
||||
// validate account fields
|
||||
STAmount const postUser = preUser + netReward;
|
||||
BEAST_EXPECT(expectAccountFields(
|
||||
env,
|
||||
user,
|
||||
preLedger,
|
||||
preLedger + 1,
|
||||
hasFix ? (preUser - feesXRP) : postUser,
|
||||
preTime));
|
||||
BEAST_EXPECT(
|
||||
postUser == (hasFix ? XRP(1002.329999) : XRP(1002.329999)));
|
||||
}
|
||||
|
||||
void
|
||||
testNoClaimLate(FeatureBitset features)
|
||||
{
|
||||
using namespace jtx;
|
||||
using namespace std::chrono_literals;
|
||||
testcase("test no claim late");
|
||||
|
||||
Env env{*this, envconfig(), features - featureXahauGenesis};
|
||||
|
||||
double const rateDrops = 0.00333333333 * 1'000'000;
|
||||
STAmount const feesXRP = XRP(1);
|
||||
|
||||
auto const user = Account("user");
|
||||
env.fund(XRP(1000), user);
|
||||
env.close();
|
||||
|
||||
// setup governance
|
||||
auto const alice = Account("alice");
|
||||
auto const bob = Account("bob");
|
||||
auto const carol = Account("carol");
|
||||
auto const david = Account("david");
|
||||
auto const edward = Account("edward");
|
||||
|
||||
env.fund(XRP(10000), alice, bob, carol, david, edward);
|
||||
env.close();
|
||||
|
||||
std::vector<AccountID> initial_members_ids{
|
||||
alice.id(), bob.id(), carol.id(), david.id(), edward.id()};
|
||||
|
||||
setupGov(env, initial_members_ids);
|
||||
|
||||
// update reward delay
|
||||
{
|
||||
// this will be the new reward delay
|
||||
// 100
|
||||
std::vector<uint8_t> vote_data{
|
||||
0x00U, 0x80U, 0xC6U, 0xA4U, 0x7EU, 0x8DU, 0x03U, 0x55U};
|
||||
|
||||
updateTopic(
|
||||
env, alice, bob, carol, david, edward, 'R', 'D', vote_data);
|
||||
}
|
||||
|
||||
// verify unl report does not exist
|
||||
BEAST_EXPECT(hasUNLReport(env) == false);
|
||||
|
||||
// opt in claim reward
|
||||
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
|
||||
env.close();
|
||||
|
||||
// close ledgers (2 cycles)
|
||||
for (int i = 0; i < 20; ++i)
|
||||
{
|
||||
env.close(10s);
|
||||
}
|
||||
|
||||
env(pay(alice, user, XRP(1000)));
|
||||
env.close();
|
||||
|
||||
// close claim ledger & time
|
||||
STAmount const preUser = env.balance(user);
|
||||
NetClock::time_point const preTime = lastClose(env);
|
||||
std::uint32_t const preLedger = env.current()->seq();
|
||||
auto const [acct, acctSle] = accountKeyAndSle(*env.current(), user);
|
||||
|
||||
// claim reward
|
||||
env(claimReward(user, env.master), fee(feesXRP), ter(tesSUCCESS));
|
||||
env.close();
|
||||
|
||||
// trigger emitted txn
|
||||
env.close();
|
||||
|
||||
// calculate rewards
|
||||
bool const hasFix = env.current()->rules().enabled(fix240819) &&
|
||||
env.current()->rules().enabled(fix240911);
|
||||
STAmount const netReward =
|
||||
rewardUserAmount(*acctSle, preLedger, rateDrops);
|
||||
BEAST_EXPECT(netReward == (hasFix ? XRP(3.479999) : XRP(6.663333)));
|
||||
|
||||
// validate account fields
|
||||
STAmount const postUser = preUser + netReward;
|
||||
BEAST_EXPECT(expectAccountFields(
|
||||
env,
|
||||
user,
|
||||
preLedger,
|
||||
preLedger + 1,
|
||||
hasFix ? (preUser - feesXRP) : postUser,
|
||||
preTime));
|
||||
BEAST_EXPECT(
|
||||
postUser == (hasFix ? XRP(2002.479999) : XRP(2005.663333)));
|
||||
}
|
||||
|
||||
void
|
||||
testRewardHookWithFeats(FeatureBitset features)
|
||||
{
|
||||
@@ -5582,12 +5038,6 @@ struct XahauGenesis_test : public beast::unit_test::suite
|
||||
testInvalidElapsed0(features);
|
||||
testInvalidElapsedNegative(features);
|
||||
testCompoundInterest(features);
|
||||
testDeposit(features);
|
||||
testDepositWithdraw(features);
|
||||
testDepositLate(features);
|
||||
testDepositWithdrawLate(features);
|
||||
testNoClaim(features);
|
||||
testNoClaimLate(features);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -5606,9 +5056,8 @@ struct XahauGenesis_test : public beast::unit_test::suite
|
||||
using namespace test::jtx;
|
||||
auto const sa = supported_amendments();
|
||||
testGovernHookWithFeats(sa);
|
||||
testRewardHookWithFeats(sa);
|
||||
testRewardHookWithFeats(sa - fix240819);
|
||||
testRewardHookWithFeats(sa - fix240819 - fix240911);
|
||||
testRewardHookWithFeats(sa);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user