mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Compare commits
3 Commits
vlntb/mem-
...
ximinez/le
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
518f292c2b | ||
|
|
13a12c6402 | ||
|
|
362ecbd1cb |
@@ -145,7 +145,6 @@ test.toplevel > xrpl.json
|
||||
test.unit_test > xrpl.basics
|
||||
tests.libxrpl > xrpl.basics
|
||||
tests.libxrpl > xrpl.json
|
||||
tests.libxrpl > xrpl.ledger
|
||||
tests.libxrpl > xrpl.net
|
||||
xrpl.json > xrpl.basics
|
||||
xrpl.ledger > xrpl.basics
|
||||
|
||||
@@ -6,18 +6,18 @@
|
||||
"sqlite3/3.49.1#8631739a4c9b93bd3d6b753bac548a63%1756234266.869",
|
||||
"soci/4.0.3#a9f8d773cd33e356b5879a4b0564f287%1756234262.318",
|
||||
"snappy/1.1.10#968fef506ff261592ec30c574d4a7809%1756234314.246",
|
||||
"rocksdb/10.5.1#4a197eca381a3e5ae8adf8cffa5aacd0%1759820024.194",
|
||||
"rocksdb/10.5.1#4a197eca381a3e5ae8adf8cffa5aacd0%1762797952.535",
|
||||
"re2/20230301#dfd6e2bf050eb90ddd8729cfb4c844a4%1756234257.976",
|
||||
"protobuf/3.21.12#d927114e28de9f4691a6bbcdd9a529d1%1756234251.614",
|
||||
"openssl/3.5.4#a1d5835cc6ed5c5b8f3cd5b9b5d24205%1760106486.594",
|
||||
"nudb/2.0.9#c62cfd501e57055a7e0d8ee3d5e5427d%1756234237.107",
|
||||
"nudb/2.0.9#fb8dfd1a5557f5e0528114c2da17721e%1763150366.909",
|
||||
"lz4/1.10.0#59fc63cac7f10fbe8e05c7e62c2f3504%1756234228.999",
|
||||
"libiconv/1.17#1e65319e945f2d31941a9d28cc13c058%1756223727.64",
|
||||
"libbacktrace/cci.20210118#a7691bfccd8caaf66309df196790a5a1%1756230911.03",
|
||||
"libarchive/3.8.1#5cf685686322e906cb42706ab7e099a8%1756234256.696",
|
||||
"jemalloc/5.3.0#e951da9cf599e956cebc117880d2d9f8%1729241615.244",
|
||||
"grpc/1.50.1#02291451d1e17200293a409410d1c4e1%1756234248.958",
|
||||
"doctest/2.4.12#eb9fb352fb2fdfc8abb17ec270945165%1749889324.069",
|
||||
"doctest/2.4.12#eb9fb352fb2fdfc8abb17ec270945165%1762797941.757",
|
||||
"date/3.0.4#f74bbba5a08fa388256688743136cb6f%1756234217.493",
|
||||
"c-ares/1.34.5#b78b91e7cfb1f11ce777a285bbf169c6%1756234217.915",
|
||||
"bzip2/1.0.8#00b4a4658791c1f06914e087f0e792f5%1756234261.716",
|
||||
@@ -53,6 +53,9 @@
|
||||
],
|
||||
"lz4/[>=1.9.4 <2]": [
|
||||
"lz4/1.10.0#59fc63cac7f10fbe8e05c7e62c2f3504"
|
||||
],
|
||||
"sqlite3/3.44.2": [
|
||||
"sqlite3/3.49.1"
|
||||
]
|
||||
},
|
||||
"config_requires": []
|
||||
|
||||
@@ -13,12 +13,28 @@ class Number;
|
||||
std::string
|
||||
to_string(Number const& amount);
|
||||
|
||||
template <class T1, class T2>
|
||||
concept ArithmeticWithNumber =
|
||||
std::is_arithmetic_v<std::remove_reference_t<T1>> &&
|
||||
std::is_convertible_v<T2, Number>;
|
||||
|
||||
template <class T1, class T2>
|
||||
concept OneNumberParam =
|
||||
ArithmeticWithNumber<T1, T2> || ArithmeticWithNumber<T2, T1>;
|
||||
|
||||
class Number
|
||||
{
|
||||
using rep = std::int64_t;
|
||||
rep mantissa_{0};
|
||||
int exponent_{std::numeric_limits<int>::lowest()};
|
||||
|
||||
using urep = std::make_unsigned_t<rep>;
|
||||
|
||||
template <class T>
|
||||
rep
|
||||
utoi(T mantissa)
|
||||
requires std::is_unsigned_v<T>;
|
||||
|
||||
public:
|
||||
// The range for the mantissa when normalized
|
||||
constexpr static std::int64_t minMantissa = 1'000'000'000'000'000LL;
|
||||
@@ -35,7 +51,10 @@ public:
|
||||
|
||||
explicit constexpr Number() = default;
|
||||
|
||||
Number(rep mantissa);
|
||||
template <class T>
|
||||
explicit Number(T mantissa)
|
||||
requires std::is_unsigned_v<T>;
|
||||
explicit Number(rep mantissa);
|
||||
explicit Number(rep mantissa, int exponent);
|
||||
explicit constexpr Number(rep mantissa, int exponent, unchecked) noexcept;
|
||||
|
||||
@@ -59,13 +78,39 @@ public:
|
||||
|
||||
Number&
|
||||
operator+=(Number const& x);
|
||||
template <class T>
|
||||
Number&
|
||||
operator+=(T x)
|
||||
{
|
||||
return operator+=(Number(x));
|
||||
}
|
||||
|
||||
Number&
|
||||
operator-=(Number const& x);
|
||||
template <class T>
|
||||
Number&
|
||||
operator-=(T x)
|
||||
{
|
||||
return operator-=(Number(x));
|
||||
}
|
||||
|
||||
Number&
|
||||
operator*=(Number const& x);
|
||||
template <class T>
|
||||
Number&
|
||||
operator*=(T x)
|
||||
{
|
||||
return operator*=(Number(x));
|
||||
}
|
||||
|
||||
Number&
|
||||
operator/=(Number const& x);
|
||||
template <class T>
|
||||
Number&
|
||||
operator/=(T x)
|
||||
{
|
||||
return operator/=(Number(x));
|
||||
}
|
||||
|
||||
static constexpr Number
|
||||
min() noexcept;
|
||||
@@ -87,12 +132,26 @@ public:
|
||||
{
|
||||
return x.mantissa_ == y.mantissa_ && x.exponent_ == y.exponent_;
|
||||
}
|
||||
template <class T1, class T2>
|
||||
friend constexpr bool
|
||||
operator==(T1&& x, T2&& y) noexcept
|
||||
requires OneNumberParam<T1, T2>
|
||||
{
|
||||
return operator==(Number(x), Number(y));
|
||||
}
|
||||
|
||||
friend constexpr bool
|
||||
operator!=(Number const& x, Number const& y) noexcept
|
||||
{
|
||||
return !(x == y);
|
||||
}
|
||||
template <class T1, class T2>
|
||||
friend constexpr bool
|
||||
operator!=(T1&& x, T2&& y) noexcept
|
||||
requires OneNumberParam<T1, T2>
|
||||
{
|
||||
return operator!=(Number(x), Number(y));
|
||||
}
|
||||
|
||||
friend constexpr bool
|
||||
operator<(Number const& x, Number const& y) noexcept
|
||||
@@ -123,6 +182,13 @@ public:
|
||||
// If equal exponents, compare mantissas
|
||||
return x.mantissa_ < y.mantissa_;
|
||||
}
|
||||
template <class T1, class T2>
|
||||
friend constexpr bool
|
||||
operator<(T1&& x, T2&& y) noexcept
|
||||
requires OneNumberParam<T1, T2>
|
||||
{
|
||||
return operator<(Number(x), Number(y));
|
||||
}
|
||||
|
||||
/** Return the sign of the amount */
|
||||
constexpr int
|
||||
@@ -154,18 +220,39 @@ public:
|
||||
{
|
||||
return y < x;
|
||||
}
|
||||
template <class T1, class T2>
|
||||
friend constexpr bool
|
||||
operator>(T1&& x, T2&& y) noexcept
|
||||
requires OneNumberParam<T1, T2>
|
||||
{
|
||||
return operator>(Number(x), Number(y));
|
||||
}
|
||||
|
||||
friend constexpr bool
|
||||
operator<=(Number const& x, Number const& y) noexcept
|
||||
{
|
||||
return !(y < x);
|
||||
}
|
||||
template <class T1, class T2>
|
||||
friend constexpr bool
|
||||
operator<=(T1&& x, T2&& y) noexcept
|
||||
requires OneNumberParam<T1, T2>
|
||||
{
|
||||
return operator<=(Number(x), Number(y));
|
||||
}
|
||||
|
||||
friend constexpr bool
|
||||
operator>=(Number const& x, Number const& y) noexcept
|
||||
{
|
||||
return !(x < y);
|
||||
}
|
||||
template <class T1, class T2>
|
||||
friend constexpr bool
|
||||
operator>=(T1&& x, T2&& y) noexcept
|
||||
requires OneNumberParam<T1, T2>
|
||||
{
|
||||
return operator>=(Number(x), Number(y));
|
||||
}
|
||||
|
||||
friend std::ostream&
|
||||
operator<<(std::ostream& os, Number const& x)
|
||||
@@ -192,6 +279,16 @@ private:
|
||||
class Guard;
|
||||
};
|
||||
|
||||
template <class T>
|
||||
Number::rep
|
||||
Number::utoi(T mantissa)
|
||||
requires std::is_unsigned_v<T>
|
||||
{
|
||||
if (mantissa > std::numeric_limits<rep>::max())
|
||||
throw std::overflow_error("too high");
|
||||
return static_cast<rep>(mantissa);
|
||||
}
|
||||
|
||||
inline constexpr Number::Number(rep mantissa, int exponent, unchecked) noexcept
|
||||
: mantissa_{mantissa}, exponent_{exponent}
|
||||
{
|
||||
@@ -207,6 +304,13 @@ inline Number::Number(rep mantissa) : Number{mantissa, 0}
|
||||
{
|
||||
}
|
||||
|
||||
template <class T>
|
||||
Number::Number(T mantissa)
|
||||
requires std::is_unsigned_v<T>
|
||||
: Number{utoi(mantissa), 0}
|
||||
{
|
||||
}
|
||||
|
||||
inline constexpr Number::rep
|
||||
Number::mantissa() const noexcept
|
||||
{
|
||||
@@ -277,6 +381,14 @@ operator+(Number const& x, Number const& y)
|
||||
return z;
|
||||
}
|
||||
|
||||
template <class T1, class T2>
|
||||
constexpr Number
|
||||
operator+(T1&& x, T2&& y)
|
||||
requires OneNumberParam<T1, T2>
|
||||
{
|
||||
return operator+(Number(x), Number(y));
|
||||
}
|
||||
|
||||
inline Number
|
||||
operator-(Number const& x, Number const& y)
|
||||
{
|
||||
@@ -285,6 +397,14 @@ operator-(Number const& x, Number const& y)
|
||||
return z;
|
||||
}
|
||||
|
||||
template <class T1, class T2>
|
||||
constexpr Number
|
||||
operator-(T1&& x, T2&& y)
|
||||
requires OneNumberParam<T1, T2>
|
||||
{
|
||||
return operator-(Number(x), Number(y));
|
||||
}
|
||||
|
||||
inline Number
|
||||
operator*(Number const& x, Number const& y)
|
||||
{
|
||||
@@ -293,6 +413,14 @@ operator*(Number const& x, Number const& y)
|
||||
return z;
|
||||
}
|
||||
|
||||
template <class T1, class T2>
|
||||
constexpr Number
|
||||
operator*(T1&& x, T2&& y)
|
||||
requires OneNumberParam<T1, T2>
|
||||
{
|
||||
return operator*(Number(x), Number(y));
|
||||
}
|
||||
|
||||
inline Number
|
||||
operator/(Number const& x, Number const& y)
|
||||
{
|
||||
@@ -301,6 +429,14 @@ operator/(Number const& x, Number const& y)
|
||||
return z;
|
||||
}
|
||||
|
||||
template <class T1, class T2>
|
||||
constexpr Number
|
||||
operator/(T1&& x, T2&& y)
|
||||
requires OneNumberParam<T1, T2>
|
||||
{
|
||||
return operator/(Number(x), Number(y));
|
||||
}
|
||||
|
||||
inline constexpr Number
|
||||
Number::min() noexcept
|
||||
{
|
||||
|
||||
@@ -151,6 +151,9 @@ public:
|
||||
bool
|
||||
retrieve(key_type const& key, T& data);
|
||||
|
||||
mutex_type&
|
||||
peekMutex();
|
||||
|
||||
std::vector<key_type>
|
||||
getKeys() const;
|
||||
|
||||
|
||||
@@ -649,6 +649,29 @@ TaggedCache<
|
||||
return true;
|
||||
}
|
||||
|
||||
template <
|
||||
class Key,
|
||||
class T,
|
||||
bool IsKeyCache,
|
||||
class SharedWeakUnionPointer,
|
||||
class SharedPointerType,
|
||||
class Hash,
|
||||
class KeyEqual,
|
||||
class Mutex>
|
||||
inline auto
|
||||
TaggedCache<
|
||||
Key,
|
||||
T,
|
||||
IsKeyCache,
|
||||
SharedWeakUnionPointer,
|
||||
SharedPointerType,
|
||||
Hash,
|
||||
KeyEqual,
|
||||
Mutex>::peekMutex() -> mutex_type&
|
||||
{
|
||||
return m_mutex;
|
||||
}
|
||||
|
||||
template <
|
||||
class Key,
|
||||
class T,
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
#ifndef XRPL_APP_LEDGER_INDEX_MAP_H_INCLUDED
|
||||
#define XRPL_APP_LEDGER_INDEX_MAP_H_INCLUDED
|
||||
|
||||
#include <algorithm>
|
||||
#include <mutex>
|
||||
#include <unordered_map>
|
||||
|
||||
namespace ripple {
|
||||
|
||||
template <class Key, class Mapped>
|
||||
class LedgerIndexMap
|
||||
{
|
||||
public:
|
||||
LedgerIndexMap() = default;
|
||||
explicit LedgerIndexMap(std::size_t reserve_capacity)
|
||||
{
|
||||
data_.reserve(reserve_capacity);
|
||||
}
|
||||
|
||||
LedgerIndexMap(LedgerIndexMap const&) = delete;
|
||||
LedgerIndexMap&
|
||||
operator=(LedgerIndexMap const&) = delete;
|
||||
LedgerIndexMap(LedgerIndexMap&&) = delete;
|
||||
LedgerIndexMap&
|
||||
operator=(LedgerIndexMap&&) = delete;
|
||||
|
||||
Mapped&
|
||||
operator[](Key const& k)
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
return data_[k];
|
||||
}
|
||||
|
||||
Mapped&
|
||||
operator[](Key&& k)
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
return data_[std::move(k)];
|
||||
}
|
||||
|
||||
[[nodiscard]] Mapped*
|
||||
get(Key const& k)
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
auto it = data_.find(k);
|
||||
return it == data_.end() ? nullptr : &it->second;
|
||||
}
|
||||
|
||||
[[nodiscard]] Mapped const*
|
||||
get(Key const& k) const
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
auto it = data_.find(k);
|
||||
return it == data_.end() ? nullptr : &it->second;
|
||||
}
|
||||
|
||||
template <class... Args>
|
||||
Mapped&
|
||||
put(Key const& k, Args&&... args)
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
auto [it, inserted] = data_.try_emplace(k, std::forward<Args>(args)...);
|
||||
if (!inserted)
|
||||
it->second = Mapped(std::forward<Args>(args)...);
|
||||
return it->second;
|
||||
}
|
||||
|
||||
bool
|
||||
contains(Key const& k) const
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
return data_.find(k) != data_.end();
|
||||
}
|
||||
|
||||
std::size_t
|
||||
size() const noexcept
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
return data_.size();
|
||||
}
|
||||
|
||||
bool
|
||||
empty() const noexcept
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
return data_.empty();
|
||||
}
|
||||
|
||||
void
|
||||
reserve(std::size_t n)
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
data_.reserve(n);
|
||||
}
|
||||
|
||||
void
|
||||
rehash(std::size_t n)
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
data_.rehash(n);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
eraseBefore(Key const& cutoff)
|
||||
{
|
||||
std::lock_guard lock(mutex_);
|
||||
auto const before = data_.size();
|
||||
std::erase_if(data_, [&](auto const& kv) { return kv.first < cutoff; });
|
||||
return before - data_.size();
|
||||
}
|
||||
|
||||
private:
|
||||
std::unordered_map<Key, Mapped> data_;
|
||||
mutable std::mutex mutex_;
|
||||
};
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
#endif // XRPL_APP_LEDGER_INDEX_MAP_H_INCLUDED
|
||||
@@ -29,7 +29,9 @@ struct Fees
|
||||
XRPAmount
|
||||
accountReserve(std::size_t ownerCount) const
|
||||
{
|
||||
return reserve + ownerCount * increment;
|
||||
auto const p = ownerCount * increment;
|
||||
auto const s = reserve + p;
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
IOUAmount() = default;
|
||||
explicit IOUAmount(Number const& other);
|
||||
IOUAmount(beast::Zero);
|
||||
IOUAmount(std::int64_t mantissa, int exponent);
|
||||
IOUAmount(std::int64_t mantissa, int exponent = 0);
|
||||
|
||||
IOUAmount& operator=(beast::Zero);
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public:
|
||||
|
||||
operator Number() const noexcept
|
||||
{
|
||||
return value();
|
||||
return Number{value()};
|
||||
}
|
||||
|
||||
/** Return the sign of the amount */
|
||||
|
||||
@@ -20,7 +20,9 @@ namespace ripple {
|
||||
class XRPAmount : private boost::totally_ordered<XRPAmount>,
|
||||
private boost::additive<XRPAmount>,
|
||||
private boost::equality_comparable<XRPAmount, std::int64_t>,
|
||||
private boost::additive<XRPAmount, std::int64_t>
|
||||
private boost::equality_comparable<XRPAmount, int>,
|
||||
private boost::additive<XRPAmount, std::int64_t>,
|
||||
private boost::additive<XRPAmount, int>
|
||||
{
|
||||
public:
|
||||
using unit_type = unit::dropTag;
|
||||
@@ -68,11 +70,13 @@ public:
|
||||
return XRPAmount{drops_ * rhs};
|
||||
}
|
||||
|
||||
template <class T>
|
||||
friend constexpr XRPAmount
|
||||
operator*(value_type lhs, XRPAmount const& rhs)
|
||||
operator*(T lhs, XRPAmount const& rhs)
|
||||
requires std::is_convertible_v<T, value_type>
|
||||
{
|
||||
// multiplication is commutative
|
||||
return rhs * lhs;
|
||||
return rhs.operator*(lhs);
|
||||
}
|
||||
|
||||
XRPAmount&
|
||||
@@ -127,6 +131,12 @@ public:
|
||||
{
|
||||
return drops_ == other;
|
||||
}
|
||||
friend bool
|
||||
operator==(value_type lhs, XRPAmount const& rhs)
|
||||
{
|
||||
// multiplication is commutative
|
||||
return rhs.operator==(lhs);
|
||||
}
|
||||
|
||||
bool
|
||||
operator<(XRPAmount const& other) const
|
||||
@@ -143,7 +153,7 @@ public:
|
||||
|
||||
operator Number() const noexcept
|
||||
{
|
||||
return drops();
|
||||
return Number{drops()};
|
||||
}
|
||||
|
||||
/** Return the sign of the amount */
|
||||
|
||||
@@ -2884,7 +2884,7 @@ assetsToSharesDeposit(
|
||||
Number(assets.mantissa(), assets.exponent() + vault->at(sfScale))
|
||||
.truncate()};
|
||||
|
||||
Number const shareTotal = issuance->at(sfOutstandingAmount);
|
||||
Number const shareTotal = Number{issuance->at(sfOutstandingAmount)};
|
||||
shares = ((shareTotal * assets) / assetTotal).truncate();
|
||||
return shares;
|
||||
}
|
||||
@@ -2913,7 +2913,7 @@ sharesToAssetsDeposit(
|
||||
shares.exponent() - vault->at(sfScale),
|
||||
false};
|
||||
|
||||
Number const shareTotal = issuance->at(sfOutstandingAmount);
|
||||
Number const shareTotal{issuance->at(sfOutstandingAmount)};
|
||||
assets = (assetTotal * shares) / shareTotal;
|
||||
return assets;
|
||||
}
|
||||
@@ -2939,7 +2939,7 @@ assetsToSharesWithdraw(
|
||||
STAmount shares{vault->at(sfShareMPTID)};
|
||||
if (assetTotal == 0)
|
||||
return shares;
|
||||
Number const shareTotal = issuance->at(sfOutstandingAmount);
|
||||
Number const shareTotal{issuance->at(sfOutstandingAmount)};
|
||||
Number result = (shareTotal * assets) / assetTotal;
|
||||
if (truncate == TruncateShares::yes)
|
||||
result = result.truncate();
|
||||
@@ -2967,7 +2967,7 @@ sharesToAssetsWithdraw(
|
||||
STAmount assets{vault->at(sfAsset)};
|
||||
if (assetTotal == 0)
|
||||
return assets;
|
||||
Number const shareTotal = issuance->at(sfOutstandingAmount);
|
||||
Number const shareTotal{issuance->at(sfOutstandingAmount)};
|
||||
assets = (assetTotal * shares) / shareTotal;
|
||||
return assets;
|
||||
}
|
||||
|
||||
@@ -16,6 +16,12 @@ QualityFunction::QualityFunction(
|
||||
{
|
||||
if (quality.rate() <= beast::zero)
|
||||
Throw<std::runtime_error>("QualityFunction quality rate is 0.");
|
||||
|
||||
static_assert(std::is_arithmetic_v<std::remove_reference_t<int>>);
|
||||
static_assert(std::is_convertible_v<ripple::STAmount, Number>);
|
||||
static_assert(ripple::OneNumberParam<int, ripple::STAmount>);
|
||||
static_assert(!ripple::OneNumberParam<Number, Number>);
|
||||
|
||||
b_ = 1 / quality.rate();
|
||||
}
|
||||
|
||||
|
||||
@@ -1329,7 +1329,7 @@ class Vault_test : public beast::unit_test::suite
|
||||
Vault& vault) {
|
||||
auto [tx, keylet] = vault.create({.owner = owner, .asset = asset});
|
||||
testcase("insufficient fee");
|
||||
env(tx, fee(env.current()->fees().base), ter(telINSUF_FEE_P));
|
||||
env(tx, fee(env.current()->fees().base - 1), ter(telINSUF_FEE_P));
|
||||
});
|
||||
|
||||
testCase([this](
|
||||
@@ -2074,6 +2074,10 @@ class Vault_test : public beast::unit_test::suite
|
||||
auto const sleMPT = env.le(mptoken);
|
||||
BEAST_EXPECT(sleMPT == nullptr);
|
||||
|
||||
// Use one reserve so the next transaction fails
|
||||
env(ticket::create(owner, 1));
|
||||
env.close();
|
||||
|
||||
// No reserve to create MPToken for asset in VaultWithdraw
|
||||
tx = vault.withdraw(
|
||||
{.depositor = owner,
|
||||
@@ -2091,7 +2095,7 @@ class Vault_test : public beast::unit_test::suite
|
||||
}
|
||||
},
|
||||
{.requireAuth = false,
|
||||
.initialXRP = acctReserve + incReserve * 4 - 1});
|
||||
.initialXRP = acctReserve + incReserve * 4 + 1});
|
||||
|
||||
testCase([this](
|
||||
Env& env,
|
||||
@@ -2980,6 +2984,9 @@ class Vault_test : public beast::unit_test::suite
|
||||
env.le(keylet::line(owner, asset.raw().get<Issue>()));
|
||||
BEAST_EXPECT(trustline == nullptr);
|
||||
|
||||
env(ticket::create(owner, 1));
|
||||
env.close();
|
||||
|
||||
// Fail because not enough reserve to create trust line
|
||||
tx = vault.withdraw(
|
||||
{.depositor = owner,
|
||||
@@ -2995,7 +3002,7 @@ class Vault_test : public beast::unit_test::suite
|
||||
env(tx);
|
||||
env.close();
|
||||
},
|
||||
CaseArgs{.initialXRP = acctReserve + incReserve * 4 - 1});
|
||||
CaseArgs{.initialXRP = acctReserve + incReserve * 4 + 1});
|
||||
|
||||
testCase(
|
||||
[&, this](
|
||||
@@ -3016,8 +3023,7 @@ class Vault_test : public beast::unit_test::suite
|
||||
env(pay(owner, charlie, asset(100)));
|
||||
env.close();
|
||||
|
||||
// Use up some reserve on tickets
|
||||
env(ticket::create(charlie, 2));
|
||||
env(ticket::create(charlie, 3));
|
||||
env.close();
|
||||
|
||||
// Fail because not enough reserve to create MPToken for shares
|
||||
@@ -3035,7 +3041,7 @@ class Vault_test : public beast::unit_test::suite
|
||||
env(tx);
|
||||
env.close();
|
||||
},
|
||||
CaseArgs{.initialXRP = acctReserve + incReserve * 4 - 1});
|
||||
CaseArgs{.initialXRP = acctReserve + incReserve * 4 + 1});
|
||||
|
||||
testCase([&, this](
|
||||
Env& env,
|
||||
|
||||
@@ -142,6 +142,34 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
template <class T1, class T2>
|
||||
concept STAmountParams =
|
||||
std::is_convertible_v<T1, STAmount> && std::is_convertible_v<T2, STAmount>;
|
||||
|
||||
template <class T1, class T2>
|
||||
STAmount
|
||||
operator-(T2&& lhs, T1&& rhs)
|
||||
requires STAmountParams<T1, T2>
|
||||
{
|
||||
return STAmount(lhs) - STAmount(rhs);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
STAmount
|
||||
operator-(PrettyAmount&& lhs, STAmount const& rhs)
|
||||
{
|
||||
return STAmount(lhs) - rhs;
|
||||
}
|
||||
|
||||
STAmount
|
||||
operator-(STAmount const& lhs, PrettyAmount&& rhs)
|
||||
{
|
||||
return lhs - STAmount(rhs);
|
||||
}
|
||||
*/
|
||||
|
||||
inline bool
|
||||
operator==(PrettyAmount const& lhs, PrettyAmount const& rhs)
|
||||
{
|
||||
|
||||
@@ -19,7 +19,6 @@ Vault::create(CreateArgs const& args)
|
||||
jv[jss::TransactionType] = jss::VaultCreate;
|
||||
jv[jss::Account] = args.owner.human();
|
||||
jv[jss::Asset] = to_json(args.asset);
|
||||
jv[jss::Fee] = STAmount(env.current()->fees().increment).getJson();
|
||||
if (args.flags)
|
||||
jv[jss::Flags] = *args.flags;
|
||||
return {jv, keylet};
|
||||
|
||||
@@ -370,6 +370,7 @@ public:
|
||||
env(pay(alice, bob, USD(1)), sendmax(USD(10)));
|
||||
env.close();
|
||||
|
||||
auto const ten = USD(10);
|
||||
env.require(balance(alice, USD(10) - amountWithRate));
|
||||
env.require(balance(bob, USD(1)));
|
||||
}
|
||||
|
||||
@@ -731,6 +731,7 @@ class Simulate_test : public beast::unit_test::suite
|
||||
{
|
||||
auto validateOutput = [&](Json::Value const& resp,
|
||||
Json::Value const& tx) {
|
||||
static_assert(ArithmeticWithNumber<XRPAmount, int>);
|
||||
auto result = resp[jss::result];
|
||||
checkBasicReturnValidity(
|
||||
result,
|
||||
|
||||
@@ -29,7 +29,3 @@ if(NOT WIN32)
|
||||
target_link_libraries(xrpl.test.net PRIVATE xrpl.imports.test)
|
||||
add_dependencies(xrpl.tests xrpl.test.net)
|
||||
endif()
|
||||
|
||||
xrpl_add_test(ledger)
|
||||
target_link_libraries(xrpl.test.ledger PRIVATE xrpl.imports.test)
|
||||
add_dependencies(xrpl.tests xrpl.test.ledger)
|
||||
|
||||
@@ -1,191 +0,0 @@
|
||||
#include <xrpl/ledger/LedgerIndexMap.h>
|
||||
|
||||
#include <doctest/doctest.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace ripple;
|
||||
|
||||
TEST_SUITE_BEGIN("LedgerIndexMap");
|
||||
|
||||
using TestMap = LedgerIndexMap<int, std::string>;
|
||||
|
||||
TEST_CASE("Default empty")
|
||||
{
|
||||
TestMap m;
|
||||
CHECK(m.size() == 0);
|
||||
CHECK(m.empty());
|
||||
CHECK(m.get(42) == nullptr);
|
||||
CHECK_FALSE(m.contains(42));
|
||||
}
|
||||
|
||||
TEST_CASE("Operator bracket inserts default")
|
||||
{
|
||||
TestMap m;
|
||||
auto& v = m[10];
|
||||
CHECK(m.size() == 1);
|
||||
CHECK(m.contains(10));
|
||||
CHECK(v.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("Operator bracket, rvalue key")
|
||||
{
|
||||
TestMap m;
|
||||
int k = 7;
|
||||
auto& v1 = m[std::move(k)];
|
||||
v1 = "seven";
|
||||
CHECK(m.size() == 1);
|
||||
auto* got = m.get(7);
|
||||
REQUIRE(got != nullptr);
|
||||
CHECK(*got == "seven");
|
||||
}
|
||||
|
||||
TEST_CASE("Insert through put")
|
||||
{
|
||||
TestMap m;
|
||||
auto& v = m.put(20, "twenty");
|
||||
CHECK(v == "twenty");
|
||||
auto* got = m.get(20);
|
||||
REQUIRE(got != nullptr);
|
||||
CHECK(*got == "twenty");
|
||||
CHECK(m.size() == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("Overwrite existing key with put")
|
||||
{
|
||||
TestMap m;
|
||||
m.put(5, "five");
|
||||
CHECK(m.size() == 1);
|
||||
m.put(5, "FIVE");
|
||||
CHECK(m.size() == 1);
|
||||
auto* got = m.get(5);
|
||||
REQUIRE(got != nullptr);
|
||||
CHECK(*got == "FIVE");
|
||||
}
|
||||
|
||||
TEST_CASE("Once found, one not found")
|
||||
{
|
||||
TestMap m;
|
||||
m.put(1, "one");
|
||||
CHECK(m.get(1) != nullptr);
|
||||
CHECK(m.get(2) == nullptr);
|
||||
}
|
||||
|
||||
TEST_CASE("Try eraseBefore - nothing to do")
|
||||
{
|
||||
TestMap m;
|
||||
m.put(10, "a");
|
||||
m.put(11, "b");
|
||||
m.put(12, "c");
|
||||
CHECK(m.eraseBefore(10) == 0);
|
||||
CHECK(m.size() == 3);
|
||||
CHECK(m.contains(10));
|
||||
CHECK(m.contains(11));
|
||||
CHECK(m.contains(12));
|
||||
}
|
||||
|
||||
TEST_CASE("eraseBefore - removes several entries")
|
||||
{
|
||||
TestMap m;
|
||||
m.put(10, "a");
|
||||
m.put(11, "b");
|
||||
m.put(12, "c");
|
||||
m.put(13, "d");
|
||||
CHECK(m.eraseBefore(12) == 2);
|
||||
CHECK_FALSE(m.contains(10));
|
||||
CHECK_FALSE(m.contains(11));
|
||||
CHECK(m.contains(12));
|
||||
CHECK(m.contains(13));
|
||||
CHECK(m.size() == 2);
|
||||
}
|
||||
|
||||
TEST_CASE("eraseBefore - removes all entries")
|
||||
{
|
||||
TestMap m;
|
||||
m.put(1, "x");
|
||||
m.put(2, "y");
|
||||
CHECK(m.eraseBefore(1000) == 2);
|
||||
CHECK(m.size() == 0);
|
||||
CHECK(m.empty());
|
||||
}
|
||||
|
||||
TEST_CASE("eraseBefore - same call, second time nothing to do")
|
||||
{
|
||||
TestMap m;
|
||||
m.put(10, "a");
|
||||
m.put(11, "b");
|
||||
m.put(12, "c");
|
||||
CHECK(m.eraseBefore(12) == 2);
|
||||
CHECK(m.contains(12));
|
||||
CHECK(m.eraseBefore(12) == 0);
|
||||
CHECK(m.size() == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("eraseBefore - single entry removed")
|
||||
{
|
||||
TestMap m;
|
||||
m.put(10, "v1");
|
||||
m.put(10, "v2");
|
||||
m.put(10, "v3");
|
||||
CHECK(m.size() == 1);
|
||||
CHECK(m.eraseBefore(11) == 1);
|
||||
CHECK(m.size() == 0);
|
||||
}
|
||||
|
||||
TEST_CASE("eraseBefore - outlier still removed in one call")
|
||||
{
|
||||
TestMap m;
|
||||
m.put(10, "a");
|
||||
m.put(12, "c");
|
||||
m.put(11, "b"); // out-of-order insert
|
||||
|
||||
CHECK(m.eraseBefore(12) == 2); // removes 10 and 11
|
||||
CHECK_FALSE(m.contains(10));
|
||||
CHECK_FALSE(m.contains(11));
|
||||
CHECK(m.contains(12));
|
||||
CHECK(m.size() == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("eraseBefore - erase in two steps (one first, then some more)")
|
||||
{
|
||||
TestMap m;
|
||||
for (int k : {10, 11, 12, 13})
|
||||
m.put(k, std::to_string(k));
|
||||
|
||||
CHECK(m.eraseBefore(11) == 1);
|
||||
CHECK_FALSE(m.contains(10));
|
||||
CHECK(m.size() == 3);
|
||||
|
||||
CHECK(m.eraseBefore(13) == 2);
|
||||
CHECK_FALSE(m.contains(11));
|
||||
CHECK_FALSE(m.contains(12));
|
||||
CHECK(m.contains(13));
|
||||
CHECK(m.size() == 1);
|
||||
}
|
||||
|
||||
TEST_CASE("rehash does not lose entries")
|
||||
{
|
||||
TestMap m;
|
||||
for (int k = 0; k < 16; ++k)
|
||||
m.put(k, "v" + std::to_string(k));
|
||||
|
||||
m.reserve(64);
|
||||
m.rehash(32);
|
||||
|
||||
for (int k = 0; k < 16; ++k)
|
||||
{
|
||||
auto* v = m.get(k);
|
||||
REQUIRE(v != nullptr);
|
||||
CHECK(*v == "v" + std::to_string(k));
|
||||
}
|
||||
|
||||
CHECK(m.eraseBefore(8) == 8);
|
||||
for (int k = 0; k < 8; ++k)
|
||||
CHECK_FALSE(m.contains(k));
|
||||
for (int k = 8; k < 16; ++k)
|
||||
CHECK(m.contains(k));
|
||||
}
|
||||
|
||||
TEST_SUITE_END();
|
||||
@@ -1,2 +0,0 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include <doctest/doctest.h>
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
namespace ripple {
|
||||
|
||||
// FIXME: Need to clean up ledgers by index at some point
|
||||
|
||||
LedgerHistory::LedgerHistory(
|
||||
beast::insight::Collector::ptr const& collector,
|
||||
Application& app)
|
||||
@@ -26,7 +28,6 @@ LedgerHistory::LedgerHistory(
|
||||
std::chrono::minutes{5},
|
||||
stopwatch(),
|
||||
app_.journal("TaggedCache"))
|
||||
, mLedgersByIndex(512)
|
||||
, j_(app.journal("LedgerHistory"))
|
||||
{
|
||||
}
|
||||
@@ -43,6 +44,8 @@ LedgerHistory::insert(
|
||||
ledger->stateMap().getHash().isNonZero(),
|
||||
"ripple::LedgerHistory::insert : nonzero hash");
|
||||
|
||||
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
|
||||
|
||||
bool const alreadyHad = m_ledgers_by_hash.canonicalize_replace_cache(
|
||||
ledger->info().hash, ledger);
|
||||
if (validated)
|
||||
@@ -54,18 +57,25 @@ LedgerHistory::insert(
|
||||
LedgerHash
|
||||
LedgerHistory::getLedgerHash(LedgerIndex index)
|
||||
{
|
||||
if (auto p = mLedgersByIndex.get(index))
|
||||
return *p;
|
||||
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
|
||||
if (auto it = mLedgersByIndex.find(index); it != mLedgersByIndex.end())
|
||||
return it->second;
|
||||
return {};
|
||||
}
|
||||
|
||||
std::shared_ptr<Ledger const>
|
||||
LedgerHistory::getLedgerBySeq(LedgerIndex index)
|
||||
{
|
||||
if (auto p = mLedgersByIndex.get(index))
|
||||
{
|
||||
uint256 const hash = *p;
|
||||
return getLedgerByHash(hash);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
std::shared_ptr<Ledger const> ret = loadByIndex(index, app_);
|
||||
@@ -79,6 +89,8 @@ LedgerHistory::getLedgerBySeq(LedgerIndex index)
|
||||
|
||||
{
|
||||
// Add this ledger to the local tracking by index
|
||||
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
|
||||
|
||||
XRPL_ASSERT(
|
||||
ret->isImmutable(),
|
||||
"ripple::LedgerHistory::getLedgerBySeq : immutable result ledger");
|
||||
@@ -427,6 +439,8 @@ LedgerHistory::builtLedger(
|
||||
XRPL_ASSERT(
|
||||
!hash.isZero(), "ripple::LedgerHistory::builtLedger : nonzero hash");
|
||||
|
||||
std::unique_lock sl(m_consensus_validated.peekMutex());
|
||||
|
||||
auto entry = std::make_shared<cv_entry>();
|
||||
m_consensus_validated.canonicalize_replace_client(index, entry);
|
||||
|
||||
@@ -467,6 +481,8 @@ LedgerHistory::validatedLedger(
|
||||
!hash.isZero(),
|
||||
"ripple::LedgerHistory::validatedLedger : nonzero hash");
|
||||
|
||||
std::unique_lock sl(m_consensus_validated.peekMutex());
|
||||
|
||||
auto entry = std::make_shared<cv_entry>();
|
||||
m_consensus_validated.canonicalize_replace_client(index, entry);
|
||||
|
||||
@@ -500,13 +516,13 @@ LedgerHistory::validatedLedger(
|
||||
bool
|
||||
LedgerHistory::fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash)
|
||||
{
|
||||
if (auto cur = mLedgersByIndex.get(ledgerIndex))
|
||||
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
|
||||
auto it = mLedgersByIndex.find(ledgerIndex);
|
||||
|
||||
if ((it != mLedgersByIndex.end()) && (it->second != ledgerHash))
|
||||
{
|
||||
if (*cur != ledgerHash)
|
||||
{
|
||||
mLedgersByIndex.put(ledgerIndex, ledgerHash);
|
||||
return false;
|
||||
}
|
||||
it->second = ledgerHash;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -514,24 +530,12 @@ LedgerHistory::fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash)
|
||||
void
|
||||
LedgerHistory::clearLedgerCachePrior(LedgerIndex seq)
|
||||
{
|
||||
std::size_t hashesCleared = 0;
|
||||
for (LedgerHash it : m_ledgers_by_hash.getKeys())
|
||||
{
|
||||
auto const ledger = getLedgerByHash(it);
|
||||
if (!ledger || ledger->info().seq < seq)
|
||||
{
|
||||
m_ledgers_by_hash.del(it, false);
|
||||
++hashesCleared;
|
||||
}
|
||||
}
|
||||
JLOG(j_.debug()) << "LedgersByHash: cleared " << hashesCleared
|
||||
<< " entries before seq " << seq << " (total now "
|
||||
<< m_ledgers_by_hash.size() << ")";
|
||||
|
||||
std::size_t const indexesCleared = mLedgersByIndex.eraseBefore(seq);
|
||||
JLOG(j_.debug()) << "LedgerIndexMap: cleared " << indexesCleared
|
||||
<< " index entries before seq " << seq << " (total now "
|
||||
<< mLedgersByIndex.size() << ")";
|
||||
}
|
||||
|
||||
} // namespace ripple
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
#include <xrpld/app/main/Application.h>
|
||||
|
||||
#include <xrpl/beast/insight/Collector.h>
|
||||
#include <xrpl/ledger/LedgerIndexMap.h>
|
||||
#include <xrpl/protocol/RippleLedgerHash.h>
|
||||
|
||||
#include <optional>
|
||||
@@ -131,8 +130,7 @@ private:
|
||||
ConsensusValidated m_consensus_validated;
|
||||
|
||||
// Maps ledger indexes to the corresponding hash.
|
||||
ripple::LedgerIndexMap<LedgerIndex, LedgerHash>
|
||||
mLedgersByIndex; // validated ledgers
|
||||
std::map<LedgerIndex, LedgerHash> mLedgersByIndex; // validated ledgers
|
||||
|
||||
beast::Journal j_;
|
||||
};
|
||||
|
||||
@@ -79,13 +79,6 @@ VaultCreate::preflight(PreflightContext const& ctx)
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
XRPAmount
|
||||
VaultCreate::calculateBaseFee(ReadView const& view, STTx const& tx)
|
||||
{
|
||||
// One reserve increment is typically much greater than one base fee.
|
||||
return calculateOwnerReserveFee(view, tx);
|
||||
}
|
||||
|
||||
TER
|
||||
VaultCreate::preclaim(PreclaimContext const& ctx)
|
||||
{
|
||||
@@ -142,8 +135,9 @@ VaultCreate::doApply()
|
||||
|
||||
if (auto ter = dirLink(view(), account_, vault))
|
||||
return ter;
|
||||
adjustOwnerCount(view(), owner, 1, j_);
|
||||
auto ownerCount = owner->at(sfOwnerCount);
|
||||
// We will create Vault and PseudoAccount, hence increase OwnerCount by 2
|
||||
adjustOwnerCount(view(), owner, 2, j_);
|
||||
auto const ownerCount = owner->at(sfOwnerCount);
|
||||
if (mPriorBalance < view().fees().accountReserve(ownerCount))
|
||||
return tecINSUFFICIENT_RESERVE;
|
||||
|
||||
|
||||
@@ -23,9 +23,6 @@ public:
|
||||
static NotTEC
|
||||
preflight(PreflightContext const& ctx);
|
||||
|
||||
static XRPAmount
|
||||
calculateBaseFee(ReadView const& view, STTx const& tx);
|
||||
|
||||
static TER
|
||||
preclaim(PreclaimContext const& ctx);
|
||||
|
||||
|
||||
@@ -146,7 +146,35 @@ VaultDelete::doApply()
|
||||
return tecHAS_OBLIGATIONS; // LCOV_EXCL_LINE
|
||||
|
||||
// Destroy the pseudo-account.
|
||||
view().erase(view().peek(keylet::account(pseudoID)));
|
||||
auto vaultPseudoSLE = view().peek(keylet::account(pseudoID));
|
||||
if (!vaultPseudoSLE || vaultPseudoSLE->at(~sfVaultID) != vault->key())
|
||||
return tefBAD_LEDGER; // LCOV_EXCL_LINE
|
||||
|
||||
// Making the payment and removing the empty holding should have deleted any
|
||||
// obligations associated with the vault or vault pseudo-account.
|
||||
if (*vaultPseudoSLE->at(sfBalance))
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
JLOG(j_.error()) << "VaultDelete: pseudo-account has a balance";
|
||||
return tecHAS_OBLIGATIONS;
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
if (vaultPseudoSLE->at(sfOwnerCount) != 0)
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
JLOG(j_.error()) << "VaultDelete: pseudo-account still owns objects";
|
||||
return tecHAS_OBLIGATIONS;
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
if (view().exists(keylet::ownerDir(pseudoID)))
|
||||
{
|
||||
// LCOV_EXCL_START
|
||||
JLOG(j_.error()) << "VaultDelete: pseudo-account has a directory";
|
||||
return tecHAS_OBLIGATIONS;
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
|
||||
view().erase(vaultPseudoSLE);
|
||||
|
||||
// Remove the vault from its owner's directory.
|
||||
auto const ownerID = vault->at(sfOwner);
|
||||
@@ -170,7 +198,9 @@ VaultDelete::doApply()
|
||||
return tefBAD_LEDGER;
|
||||
// LCOV_EXCL_STOP
|
||||
}
|
||||
adjustOwnerCount(view(), owner, -1, j_);
|
||||
|
||||
// We are destroying Vault and PseudoAccount, hence decrease by 2
|
||||
adjustOwnerCount(view(), owner, -2, j_);
|
||||
|
||||
// Destroy the vault.
|
||||
view().erase(vault);
|
||||
|
||||
Reference in New Issue
Block a user