mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-29 15:35:50 +00:00
Compare commits
9 Commits
vlntb/mem-
...
bthomee/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
690dced2c8 | ||
|
|
13a12c6402 | ||
|
|
362ecbd1cb | ||
|
|
3faff9f7a6 | ||
|
|
7141781db4 | ||
|
|
802ac5629f | ||
|
|
2f15909ffa | ||
|
|
9184b7274c | ||
|
|
54a19a0e8d |
@@ -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
|
||||
|
||||
4
.github/scripts/rename/README.md
vendored
4
.github/scripts/rename/README.md
vendored
@@ -26,6 +26,9 @@ run from the repository root.
|
||||
references to `ripple` and `rippled` (with or without capital letters) to
|
||||
`xrpl` and `xrpld`, respectively. The name of the binary will remain as-is,
|
||||
and will only be renamed to `xrpld` by a later script.
|
||||
4. `.github/scripts/rename/binary.sh`: This script will rename the binary from
|
||||
`rippled` to `xrpld`, and reverses the symlink so that `rippled` points to
|
||||
the `xrpld` binary.
|
||||
|
||||
You can run all these scripts from the repository root as follows:
|
||||
|
||||
@@ -33,4 +36,5 @@ You can run all these scripts from the repository root as follows:
|
||||
./.github/scripts/rename/definitions.sh .
|
||||
./.github/scripts/rename/copyright.sh .
|
||||
./.github/scripts/rename/cmake.sh .
|
||||
./.github/scripts/rename/binary.sh .
|
||||
```
|
||||
|
||||
42
.github/scripts/rename/binary.sh
vendored
Executable file
42
.github/scripts/rename/binary.sh
vendored
Executable file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Exit the script as soon as an error occurs.
|
||||
set -e
|
||||
|
||||
# On MacOS, ensure that GNU sed is installed and available as `gsed`.
|
||||
SED_COMMAND=sed
|
||||
if [[ "${OSTYPE}" == 'darwin'* ]]; then
|
||||
if ! command -v gsed &> /dev/null; then
|
||||
echo "Error: gsed is not installed. Please install it using 'brew install gnu-sed'."
|
||||
exit 1
|
||||
fi
|
||||
SED_COMMAND=gsed
|
||||
fi
|
||||
|
||||
# This script changes the binary name from `rippled` to `xrpld`, and reverses
|
||||
# the symlink that currently points from `xrpld` to `rippled` so that it points
|
||||
# from `rippled` to `xrpld` instead.
|
||||
# Usage: .github/scripts/rename/binary.sh <repository directory>
|
||||
|
||||
if [ "$#" -ne 1 ]; then
|
||||
echo "Usage: $0 <repository directory>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DIRECTORY=$1
|
||||
echo "Processing directory: ${DIRECTORY}"
|
||||
if [ ! -d "${DIRECTORY}" ]; then
|
||||
echo "Error: Directory '${DIRECTORY}' does not exist."
|
||||
exit 1
|
||||
fi
|
||||
pushd ${DIRECTORY}
|
||||
|
||||
# Remove the binary name override added by the cmake.sh script.
|
||||
${SED_COMMAND} -z -i -E 's@\s+# For the time being.+"rippled"\)@@' cmake/XrplCore.cmake
|
||||
|
||||
# Reverse the symlink.
|
||||
${SED_COMMAND} -i -E 's@create_symbolic_link\(rippled@create_symbolic_link(xrpld@' cmake/XrplInstall.cmake
|
||||
${SED_COMMAND} -i -E 's@/xrpld\$\{suffix\}@/rippled${suffix}@' cmake/XrplInstall.cmake
|
||||
|
||||
popd
|
||||
echo "Processing complete."
|
||||
14
.github/workflows/reusable-build-test-config.yml
vendored
14
.github/workflows/reusable-build-test-config.yml
vendored
@@ -129,14 +129,14 @@ jobs:
|
||||
--parallel "${BUILD_NPROC}" \
|
||||
--target "${CMAKE_TARGET}"
|
||||
|
||||
- name: Upload rippled artifact (Linux)
|
||||
- name: Upload the binary (Linux)
|
||||
if: ${{ runner.os == 'Linux' }}
|
||||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
|
||||
env:
|
||||
BUILD_DIR: ${{ inputs.build_dir }}
|
||||
with:
|
||||
name: rippled-${{ inputs.config_name }}
|
||||
path: ${{ env.BUILD_DIR }}/rippled
|
||||
name: xrpld-${{ inputs.config_name }}
|
||||
path: ${{ env.BUILD_DIR }}/xrpld
|
||||
retention-days: 3
|
||||
if-no-files-found: error
|
||||
|
||||
@@ -144,8 +144,8 @@ jobs:
|
||||
if: ${{ runner.os == 'Linux' }}
|
||||
working-directory: ${{ inputs.build_dir }}
|
||||
run: |
|
||||
ldd ./rippled
|
||||
if [ "$(ldd ./rippled | grep -E '(libstdc\+\+|libgcc)' | wc -l)" -eq 0 ]; then
|
||||
ldd ./xrpld
|
||||
if [ "$(ldd ./xrpld | grep -E '(libstdc\+\+|libgcc)' | wc -l)" -eq 0 ]; then
|
||||
echo 'The binary is statically linked.'
|
||||
else
|
||||
echo 'The binary is dynamically linked.'
|
||||
@@ -156,7 +156,7 @@ jobs:
|
||||
if: ${{ runner.os == 'Linux' && env.ENABLED_VOIDSTAR == 'true' }}
|
||||
working-directory: ${{ inputs.build_dir }}
|
||||
run: |
|
||||
./rippled --version | grep libvoidstar
|
||||
./xrpld --version | grep libvoidstar
|
||||
|
||||
- name: Run the separate tests
|
||||
if: ${{ !inputs.build_only }}
|
||||
@@ -177,7 +177,7 @@ jobs:
|
||||
env:
|
||||
BUILD_NPROC: ${{ steps.nproc.outputs.nproc }}
|
||||
run: |
|
||||
./rippled --unittest --unittest-jobs "${BUILD_NPROC}"
|
||||
./xrpld --unittest --unittest-jobs "${BUILD_NPROC}"
|
||||
|
||||
- name: Debug failure (Linux)
|
||||
if: ${{ failure() && runner.os == 'Linux' && !inputs.build_only }}
|
||||
|
||||
@@ -25,7 +25,7 @@ jobs:
|
||||
env:
|
||||
MESSAGE: |
|
||||
|
||||
The dependency relationships between the modules in rippled have
|
||||
The dependency relationships between the modules in xrpld have
|
||||
changed, which may be an improvement or a regression.
|
||||
|
||||
A rule of thumb is that if your changes caused something to be
|
||||
|
||||
2
.github/workflows/reusable-check-rename.yml
vendored
2
.github/workflows/reusable-check-rename.yml
vendored
@@ -25,6 +25,8 @@ jobs:
|
||||
run: .github/scripts/rename/copyright.sh .
|
||||
- name: Check CMake configs
|
||||
run: .github/scripts/rename/cmake.sh .
|
||||
- name: Check binary name
|
||||
run: .github/scripts/rename/binary.sh .
|
||||
- name: Check for differences
|
||||
env:
|
||||
MESSAGE: |
|
||||
|
||||
@@ -223,6 +223,4 @@ if(xrpld)
|
||||
src/test/ledger/Invariants_test.cpp
|
||||
PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE)
|
||||
endif()
|
||||
# For the time being, we will keep the name of the binary as it was.
|
||||
set_target_properties(xrpld PROPERTIES OUTPUT_NAME "rippled")
|
||||
endif()
|
||||
|
||||
@@ -67,8 +67,8 @@ if (is_root_project AND TARGET xrpld)
|
||||
install(CODE "
|
||||
set(CMAKE_MODULE_PATH \"${CMAKE_MODULE_PATH}\")
|
||||
include(create_symbolic_link)
|
||||
create_symbolic_link(rippled${suffix} \
|
||||
\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/xrpld${suffix})
|
||||
create_symbolic_link(xrpld${suffix} \
|
||||
\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/rippled${suffix})
|
||||
")
|
||||
endif ()
|
||||
|
||||
|
||||
@@ -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": []
|
||||
|
||||
@@ -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
|
||||
@@ -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,
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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