Compare commits

..

1 Commits

Author SHA1 Message Date
Mayukha Vadari
0db564d261 WASMI data 2025-11-04 15:57:07 -05:00
20 changed files with 409 additions and 73 deletions

View File

@@ -74,19 +74,12 @@ if grep -q '"xrpld"' cmake/XrplCore.cmake; then
# The script has been rerun, so just restore the name of the binary.
${SED_COMMAND} -i 's/"xrpld"/"rippled"/' cmake/XrplCore.cmake
elif ! grep -q '"rippled"' cmake/XrplCore.cmake; then
${HEAD_COMMAND} -n -1 cmake/XrplCore.cmake > cmake.tmp
ghead -n -1 cmake/XrplCore.cmake > cmake.tmp
echo ' # For the time being, we will keep the name of the binary as it was.' >> cmake.tmp
echo ' set_target_properties(xrpld PROPERTIES OUTPUT_NAME "rippled")' >> cmake.tmp
tail -1 cmake/XrplCore.cmake >> cmake.tmp
mv cmake.tmp cmake/XrplCore.cmake
fi
# Restore the symlink from 'xrpld' to 'rippled'.
${SED_COMMAND} -i -E 's@create_symbolic_link\(xrpld@create_symbolic_link(rippled@' cmake/XrplInstall.cmake
# Remove the symlink that previously pointed from 'ripple' to 'xrpl' but now is
# no longer needed.
${SED_COMMAND} -z -i -E 's@install\(CODE.+CMAKE_INSTALL_INCLUDEDIR}/xrpl\)\n"\)\n+@@' cmake/XrplInstall.cmake
popd
echo "Renaming complete."

3
.gitignore vendored
View File

@@ -111,6 +111,3 @@ bld.rippled/
# Suggested in-tree build directory
/.build*/
# Locally patched Conan recipes
external/conan-center-index/

View File

@@ -135,23 +135,17 @@ locally:
```bash
cd external
mkdir -p conan-center-index
cd conan-center-index
git init
git remote add origin git@github.com:XRPLF/conan-center-index.git
git sparse-checkout init
git sparse-checkout set recipes/grpc
git sparse-checkout add recipes/m4
git sparse-checkout add recipes/snappy
git sparse-checkout set recipes/snappy
git sparse-checkout add recipes/soci
git fetch origin master
git checkout master
conan export --version 1.1.10 recipes/snappy/all
conan export --version 4.0.3 recipes/soci/all
conan export --version 0.42.1 external/wasmi
rm -rf .git
cd ../..
conan export --version 1.72.0 external/conan-center-index/recipes/grpc/all
conan export --version 1.4.19 external/conan-center-index/recipes/m4/all
conan export --version 1.1.10 external/conan-center-index/recipes/snappy/all
conan export --version 4.0.3 external/conan-center-index/recipes/soci/all
```
In the case we switch to a newer version of a dependency that still requires a
@@ -380,6 +374,19 @@ tools.build:cxxflags=['-DBOOST_ASIO_DISABLE_CONCEPTS']
`--settings build_type=$BUILD_TYPE` or in the profile itself,
under the section `[settings]` with the key `build_type`.
If you are using a Microsoft Visual C++ compiler,
then you will need to ensure consistency between the `build_type` setting
and the `compiler.runtime` setting.
When `build_type` is `Release`, `compiler.runtime` should be `MT`.
When `build_type` is `Debug`, `compiler.runtime` should be `MTd`.
```
conan install .. --output-folder . --build missing --settings build_type=Release --settings compiler.runtime=MT
conan install .. --output-folder . --build missing --settings build_type=Debug --settings compiler.runtime=MTd
```
3. Configure CMake and pass the toolchain file generated by Conan, located at
`$OUTPUT_FOLDER/build/generators/conan_toolchain.cmake`.

View File

@@ -119,6 +119,7 @@ endif()
find_package(nudb REQUIRED)
find_package(date REQUIRED)
find_package(wasmi REQUIRED)
find_package(xxHash REQUIRED)
target_link_libraries(xrpl_libs INTERFACE

View File

@@ -72,9 +72,9 @@ if (MSVC)
-GS
-Zc:forScope
>
# dynamic runtime
$<$<CONFIG:Debug>:-MDd>
$<$<NOT:$<CONFIG:Debug>>:-MD>
# static runtime
$<$<CONFIG:Debug>:-MTd>
$<$<NOT:$<CONFIG:Debug>>:-MT>
$<$<BOOL:${werr}>:-WX>
)
target_compile_definitions (common

View File

@@ -63,11 +63,17 @@ target_link_libraries(xrpl.imports.main
Xrpl::opts
Xrpl::syslibs
secp256k1::secp256k1
wasmi::wasmi
xrpl.libpb
xxHash::xxhash
$<$<BOOL:${voidstar}>:antithesis-sdk-cpp>
)
if (WIN32)
target_link_libraries(xrpl.imports.main INTERFACE ntdll)
endif()
include(add_module)
include(target_link_modules)

View File

@@ -37,6 +37,13 @@ install(
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
install(CODE "
set(CMAKE_MODULE_PATH \"${CMAKE_MODULE_PATH}\")
include(create_symbolic_link)
create_symbolic_link(xrpl \
\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_INCLUDEDIR}/xrpl)
")
install (EXPORT XrplExports
FILE XrplTargets.cmake
NAMESPACE Xrpl::
@@ -67,7 +74,7 @@ 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} \
create_symbolic_link(xrpld${suffix} \
\$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/xrpld${suffix})
")
endif ()

View File

@@ -1,63 +1,46 @@
{
"version": "0.5",
"requires": [
"zstd/1.5.5#8400bcba21d1b495dca55edf3f065246%1744114239.76",
"zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1756234269.497",
"xz_utils/5.4.5#b885d1d79c9d30cff3803f7f551dbe66%1724318972.064",
"xxhash/0.8.3#681d36a0a6111fc56e5e45ea182c19cc%1756234289.683",
"sqlite3/3.49.1#8631739a4c9b93bd3d6b753bac548a63%1756234266.869",
"soci/4.0.3#a9f8d773cd33e356b5879a4b0564f287%1756234262.318",
"snappy/1.1.10#968fef506ff261592ec30c574d4a7809%1756234314.246",
"rocksdb/10.0.1#85537f46e538974d67da0c3977de48ac%1756234304.347",
"re2/20230301#dfd6e2bf050eb90ddd8729cfb4c844a4%1756234257.976",
"protobuf/6.32.1#f481fd276fc23a33b85a3ed1e898b693%1759134873.45",
"pcre2/10.42#9a35f5089feb875ec61a38eca364ce77%1743524593.693",
"openssl/3.5.4#a1d5835cc6ed5c5b8f3cd5b9b5d24205%1760106486.594",
"protobuf/3.21.12#d927114e28de9f4691a6bbcdd9a529d1%1756234251.614",
"openssl/3.5.4#a1d5835cc6ed5c5b8f3cd5b9b5d24205%1759746684.671",
"nudb/2.0.9#c62cfd501e57055a7e0d8ee3d5e5427d%1756234237.107",
"lz4/1.10.0#59fc63cac7f10fbe8e05c7e62c2f3504%1756234228.999",
"libxcrypt/4.4.36#4b4e8f20794f1997dd59eeed0b7cdcfb%1696519152.422",
"libsystemd/255.10#0552f8de4d3eeaaefd87f6677dfbce1f%1723640836.911",
"libselinux/3.6#5a78ff6ae5034eeaac8da723361a8ce4%1717655459.344",
"libmount/2.39.2#64850679fa9d5ead878e5076b0cab2a8%1705591482.625",
"libiconv/1.17#1e65319e945f2d31941a9d28cc13c058%1756223727.64",
"libcap/2.69#7ef2d60864c2e58e89db957be936dc49%1693427138.461",
"libbacktrace/cci.20210118#a7691bfccd8caaf66309df196790a5a1%1756230911.03",
"libarchive/3.8.1#5cf685686322e906cb42706ab7e099a8%1756234256.696",
"jemalloc/5.3.0#e951da9cf599e956cebc117880d2d9f8%1729241615.244",
"grpc/1.72.0#7a2ffa9b7f9a097f732ec47bc9aff0d0%1754440207.194",
"grpc/1.50.1#02291451d1e17200293a409410d1c4e1%1756234248.958",
"doctest/2.4.11#a4211dfc329a16ba9f280f9574025659%1756234220.819",
"date/3.0.4#f74bbba5a08fa388256688743136cb6f%1756234217.493",
"c-ares/1.34.5#b78b91e7cfb1f11ce777a285bbf169c6%1756234217.915",
"bzip2/1.0.8#00b4a4658791c1f06914e087f0e792f5%1756234261.716",
"boost/1.88.0#8852c0b72ce8271fb8ff7c53456d4983%1756223752.326",
"abseil/20250127.0#9e8e8cfc89a1324139fc0ee3bd4d8c8c%1753819045.301"
"abseil/20230802.1#f0f91485b111dc9837a68972cb19ca7b%1756234220.907"
],
"build_requires": [
"zlib/1.3.1#b8bc2603263cf7eccbd6e17e66b0ed76%1756234269.497",
"strawberryperl/5.32.1.1#707032463aa0620fa17ec0d887f5fe41%1756234281.733",
"protobuf/6.32.1#f481fd276fc23a33b85a3ed1e898b693%1759134873.45",
"pkgconf/2.2.0#4ac315b50ef734072b00ff3aacbf52bf%1755505628.021",
"pkgconf/2.1.0#21f96520faf7660b99f872e956d2ac13%1755505630.82",
"ninja/1.13.1#294f8721dbcde145674f7ba44994700e%1753400352.374",
"protobuf/3.21.12#d927114e28de9f4691a6bbcdd9a529d1%1756234251.614",
"nasm/2.16.01#31e26f2ee3c4346ecd347911bd126904%1756234232.901",
"msys2/cci.latest#5b73b10144f73cc5bfe0572ed9be39e1%1751977009.857",
"meson/1.9.1#abbc783cd297bedce14581b4aec060b8%1758626166.349",
"meson/1.4.0#2262941cc8fbb0099dd0c196ca2a6c01%1726730116.631",
"m4/1.4.19#f119296e5c4772b3bb7ab060ae8f417b%1760707875.678",
"libtool/2.4.7#14e7739cc128bc1623d2ed318008e47e%1755679003.847",
"gperf/3.1#a7afdf8f7cccdc2dcd4d962370c33d4f%1755780571.156",
"gnu-config/cci.20210814#69fde734e1a46fd1655b4af46ab40945%1746203214.947",
"flex/2.6.4#e35bc44b3fcbcd661e0af0dc5b5b1ad4%1674818991.113",
"m4/1.4.19#b38ced39a01e31fef5435bc634461fd2%1700758725.451",
"cmake/3.31.8#dde3bde00bb843687e55aea5afa0e220%1756234232.89",
"b2/5.3.3#107c15377719889654eb9a162a673975%1756234226.28",
"automake/1.16.5#b91b7c384c3deaa9d535be02da14d04f%1755524470.56",
"autoconf/2.71#51077f068e61700d65bb05541ea1e4b0%1731054366.86",
"abseil/20250127.0#9e8e8cfc89a1324139fc0ee3bd4d8c8c%1753819045.301"
"autoconf/2.71#51077f068e61700d65bb05541ea1e4b0%1731054366.86"
],
"python_requires": [],
"overrides": {
"protobuf/5.27.0": [
"protobuf/6.32.1"
"protobuf/3.21.12": [
null,
"protobuf/3.21.12"
],
"lz4/1.9.4": [
"lz4/1.10.0"
@@ -70,4 +53,4 @@
]
},
"config_requires": []
}
}

View File

@@ -14,12 +14,18 @@ compiler={{compiler}}
compiler.version={{ compiler_version }}
compiler.cppstd=20
{% if os == "Windows" %}
compiler.runtime=dynamic
compiler.runtime=static
{% else %}
compiler.libcxx={{detect_api.detect_libcxx(compiler, version, compiler_exe)}}
{% endif %}
[conf]
{% if compiler == "clang" and compiler_version >= 19 %}
grpc/1.50.1:tools.build:cxxflags+=['-Wno-missing-template-arg-list-after-template-kw']
{% endif %}
{% if compiler == "apple-clang" and compiler_version >= 17 %}
grpc/1.50.1:tools.build:cxxflags+=['-Wno-missing-template-arg-list-after-template-kw']
{% endif %}
{% if compiler == "gcc" and compiler_version < 13 %}
tools.build:cxxflags+=['-Wno-restrict']
{% endif %}

View File

@@ -2,6 +2,7 @@ from conan import ConanFile, __version__ as conan_version
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
import re
class Xrpl(ConanFile):
name = 'xrpl'
@@ -24,11 +25,12 @@ class Xrpl(ConanFile):
}
requires = [
'grpc/1.72.0',
'grpc/1.50.1',
'libarchive/3.8.1',
'nudb/2.0.9',
'openssl/3.5.4',
'soci/4.0.3',
'wasmi/0.42.1',
'zlib/1.3.1',
]
@@ -37,7 +39,7 @@ class Xrpl(ConanFile):
]
tool_requires = [
'protobuf/6.32.1',
'protobuf/3.21.12',
]
default_options = {
@@ -55,16 +57,6 @@ class Xrpl(ConanFile):
'date/*:header_only': True,
'grpc/*:shared': False,
'grpc/*:secure': True,
'grpc/*:codegen': True,
'grpc/*:cpp_plugin': True,
'grpc/*:csharp_ext': False,
'grpc/*:csharp_plugin': False,
'grpc/*:node_plugin': False,
'grpc/*:objective_c_plugin': False,
'grpc/*:php_plugin': False,
'grpc/*:python_plugin': False,
'grpc/*:ruby_plugin': False,
'grpc/*:otel_plugin': False,
'libarchive/*:shared': False,
'libarchive/*:with_acl': False,
'libarchive/*:with_bzip2': False,
@@ -119,7 +111,7 @@ class Xrpl(ConanFile):
self.requires('boost/1.88.0', force=True, **transitive_headers_opt)
self.requires('date/3.0.4', **transitive_headers_opt)
self.requires('lz4/1.10.0', force=True)
self.requires('protobuf/6.32.1', force=True)
self.requires('protobuf/3.21.12', force=True)
self.requires('sqlite3/3.49.1', force=True)
if self.options.jemalloc:
self.requires('jemalloc/5.3.0')
@@ -143,6 +135,7 @@ class Xrpl(ConanFile):
self.folders.generators = 'build/generators'
generators = 'CMakeDeps'
def generate(self):
tc = CMakeToolchain(self)
tc.variables['tests'] = self.options.tests
@@ -200,6 +193,7 @@ class Xrpl(ConanFile):
'protobuf::libprotobuf',
'soci::soci',
'sqlite3::sqlite',
'wasmi::wasmi',
'xxhash::xxhash',
'zlib::zlib',
]

5
external/wasmi/conandata.yml vendored Normal file
View File

@@ -0,0 +1,5 @@
patches:
0.42.1:
- patch_description: install only static lib (to prevent conflict with shared)
patch_file: patches/wasmi.patch
patch_type: conan

90
external/wasmi/conanfile.py vendored Normal file
View File

@@ -0,0 +1,90 @@
from conan import ConanFile, tools
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps, cmake_layout
from conan.tools.files import (
apply_conandata_patches,
export_conandata_patches,
# get,
)
from conan.tools.scm import Git
import os
# import json
required_conan_version = ">=1.55.0"
class WasmiConan(ConanFile):
name = "wasmi"
license = "Apache License v2.0"
url = "https://github.com/wasmi-labs/wasmi.git"
description = "WebAssembly (Wasm) interpreter"
package_type = "library"
settings = "os", "compiler", "build_type", "arch"
options = {"shared": [True, False]}
default_options = {"shared": False}
# generators = "CMakeToolchain", "CMakeDeps"
#requires = [("llvm/20.1.1@")]
def export_sources(self):
export_conandata_patches(self)
pass
# def build_requirements(self):
# self.tool_requires("llvm/20.1.1")
def config_options(self):
#if self.settings.os == "Windows":
# del self.options.fPIC
pass
def layout(self):
cmake_layout(self, src_folder="src")
def source(self):
git = Git(self)
git.fetch_commit(
url="https://github.com/wasmi-labs/wasmi.git",
commit="f628a7a86c9715f2c306f6ef9aea1cc2bdca5fa7",
)
#get(self, **self.conan_data["sources"][self.version], strip_root=True)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["CMAKE_CXX_STANDARD"] = 20
tc.variables["BUILD_SHARED_LIBS"] = 0
tc.generate()
# This generates "foo-config.cmake" and "bar-config.cmake" in self.generators_folder
deps = CMakeDeps(self)
deps.generate()
def build(self):
apply_conandata_patches(self)
cmake = CMake(self)
cmake.verbose = True
cmake.configure(build_script_folder=os.path.join(self.source_folder, "crates", "c_api"))
cmake.build()
#self.run(f'echo {self.source_folder}')
# Explicit way:
# self.run('cmake %s/hello %s' % (self.source_folder, cmake.command_line))
# self.run("cmake --build . %s" % cmake.build_config)
def package(self):
cmake = CMake(self)
cmake.verbose = True
cmake.install()
def package_info(self):
self.cpp_info.libs = ["wasmi"]
self.cpp_info.names["cmake_find_package"] = "wasmi"
self.cpp_info.names["cmake_find_package_multi"] = "wasmi"

View File

@@ -0,0 +1,15 @@
diff --git a/crates/c_api/CMakeLists.txt b/crates/c_api/CMakeLists.txt
index b15c787..97dd294 100644
--- a/crates/c_api/CMakeLists.txt
+++ b/crates/c_api/CMakeLists.txt
@@ -43,6 +43,10 @@ endif()
list(TRANSFORM WASMI_SHARED_FILES PREPEND ${WASMI_TARGET_DIR}/)
list(TRANSFORM WASMI_STATIC_FILES PREPEND ${WASMI_TARGET_DIR}/)
+if(NOT BUILD_SHARED_LIBS)
+ set(WASMI_SHARED_FILES )
+endif()
+
# Instructions on how to build and install the Wasmi Rust crate.
find_program(WASMI_CARGO_BINARY cargo REQUIRED)
include(ExternalProject)

109
external/wasmi/patches/wasmi.patch vendored Normal file
View File

@@ -0,0 +1,109 @@
diff --git a/crates/c_api/CMakeLists.txt b/crates/c_api/CMakeLists.txt
index b15c787a..0d0a04b7 100644
--- a/crates/c_api/CMakeLists.txt
+++ b/crates/c_api/CMakeLists.txt
@@ -43,6 +43,11 @@ endif()
list(TRANSFORM WASMI_SHARED_FILES PREPEND ${WASMI_TARGET_DIR}/)
list(TRANSFORM WASMI_STATIC_FILES PREPEND ${WASMI_TARGET_DIR}/)
+if(NOT BUILD_SHARED_LIBS)
+ set(WASMI_SHARED_FILES )
+endif()
+
+
# Instructions on how to build and install the Wasmi Rust crate.
find_program(WASMI_CARGO_BINARY cargo REQUIRED)
include(ExternalProject)
diff --git a/crates/c_api/include/wasm.h b/crates/c_api/include/wasm.h
index 5ee617ff..0199192d 100644
--- a/crates/c_api/include/wasm.h
+++ b/crates/c_api/include/wasm.h
@@ -146,6 +146,13 @@ WASM_DECLARE_OWN(store)
WASM_API_EXTERN own wasm_store_t* wasm_store_new(wasm_engine_t*);
+// Store fuel functions (forward declarations)
+struct wasmi_error;
+
+WASM_API_EXTERN struct wasmi_error* wasm_store_get_fuel(const wasm_store_t*, uint64_t* fuel);
+WASM_API_EXTERN struct wasmi_error* wasm_store_set_fuel(wasm_store_t*, uint64_t fuel);
+//WASM_API_EXTERN void *wasm_store_get_data(const wasm_store_t*);
+//WASM_API_EXTERN void wasm_store_set_data(wasm_store_t*, void *data);
///////////////////////////////////////////////////////////////////////////////
// Type Representations
diff --git a/crates/c_api/include/wasmi.h b/crates/c_api/include/wasmi.h
index 2caffa37..0c0584ec 100644
--- a/crates/c_api/include/wasmi.h
+++ b/crates/c_api/include/wasmi.h
@@ -10,7 +10,7 @@
/**
* \brief Wasmi version string.
*/
-#define WASMI_VERSION "0.35.0"
+#define WASMI_VERSION "0.42.1"
/**
* \brief Wasmi major version number.
*/
@@ -18,10 +18,10 @@
/**
* \brief Wasmi minor version number.
*/
-#define WASMI_VERSION_MINOR 35
+#define WASMI_VERSION_MINOR 42
/**
* \brief Wasmi patch version number.
*/
-#define WASMI_VERSION_PATCH 0
+#define WASMI_VERSION_PATCH 1
#endif // WASMI_H
diff --git a/crates/c_api/src/store.rs b/crates/c_api/src/store.rs
index 56d4898f..543dbff8 100644
--- a/crates/c_api/src/store.rs
+++ b/crates/c_api/src/store.rs
@@ -175,3 +175,44 @@ pub extern "C" fn wasmi_context_set_fuel(
) -> Option<Box<wasmi_error_t>> {
crate::handle_result(store.set_fuel(fuel), |()| {})
}
+
+////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////////////
+
+/// Returns the current fuel of the wasm store context in `fuel`.
+///
+/// Wraps [`Store::get_fuel`].
+///
+/// # Errors
+///
+/// If [`Store::get_fuel`] errors.
+#[no_mangle]
+pub extern "C" fn wasm_store_get_fuel(
+ store: &wasm_store_t,
+ fuel: &mut u64,
+) -> Option<Box<wasmi_error_t>> {
+ let context = unsafe { store.inner.context() };
+ crate::handle_result(context.get_fuel(), |amt| {
+ *fuel = amt;
+ })
+}
+
+/// Sets the current fuel of the wasm store context to `fuel`.
+///
+/// Wraps [`Store::set_fuel`].
+///
+/// # Errors
+///
+/// If [`Store::set_fuel`] errors.
+#[no_mangle]
+pub extern "C" fn wasm_store_set_fuel(
+ store: &mut wasm_store_t,
+ fuel: u64,
+) -> Option<Box<wasmi_error_t>> {
+
+ let mut context = unsafe { store.inner.context_mut() };
+ crate::handle_result(context.set_fuel(fuel), |()| {})
+}
+

View File

@@ -62,6 +62,7 @@ XRPL_FIX (UniversalNumber, Supported::yes, VoteBehavior::DefaultNo
XRPL_FEATURE(XRPFees, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(DisallowIncoming, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FIX (RemoveNFTokenAutoTrustLine, Supported::yes, VoteBehavior::DefaultYes)
XRPL_FIX (TrustLinesToSelf, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(ExpandedSignerList, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(CheckCashMakesTrustLine, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FEATURE(FlowSortStrands, Supported::yes, VoteBehavior::DefaultYes)
@@ -118,7 +119,6 @@ XRPL_RETIRE(fixReducedOffersV1)
XRPL_RETIRE(fixRmSmallIncreasedQOffers)
XRPL_RETIRE(fixSTAmountCanonicalize)
XRPL_RETIRE(fixTakerDryOfferRemoval)
XRPL_RETIRE(fixTrustLinesToSelf)
XRPL_RETIRE(CryptoConditions)
XRPL_RETIRE(Escrow)
XRPL_RETIRE(EnforceInvariants)

View File

@@ -121,8 +121,7 @@ class Feature_test : public beast::unit_test::suite
// Test a random sampling of the variables. If any of these get retired
// or removed, swap out for any other feature.
BEAST_EXPECT(
featureToName(fixRemoveNFTokenAutoTrustLine) ==
"fixRemoveNFTokenAutoTrustLine");
featureToName(fixTrustLinesToSelf) == "fixTrustLinesToSelf");
BEAST_EXPECT(featureToName(featureFlow) == "Flow");
BEAST_EXPECT(featureToName(featureNegativeUNL) == "NegativeUNL");
BEAST_EXPECT(

View File

@@ -106,7 +106,7 @@ OrderBookDB::update(std::shared_ptr<ReadView const> const& ledger)
book.domain = (*sle)[~sfDomainID];
if (book.domain)
domainBooks[{book.in, *book.domain}].insert(book.out);
domainBooks_[{book.in, *book.domain}].insert(book.out);
else
allBooks[book.in].insert(book.out);

View File

@@ -147,6 +147,88 @@ Change::preCompute()
account_ == beast::zero, "ripple::Change::preCompute : zero account");
}
void
Change::activateTrustLinesToSelfFix()
{
JLOG(j_.warn()) << "fixTrustLinesToSelf amendment activation code starting";
auto removeTrustLineToSelf = [this](Sandbox& sb, uint256 id) {
auto tl = sb.peek(keylet::child(id));
if (tl == nullptr)
{
JLOG(j_.warn()) << id << ": Unable to locate trustline";
return true;
}
if (tl->getType() != ltRIPPLE_STATE)
{
JLOG(j_.warn()) << id << ": Unexpected type "
<< static_cast<std::uint16_t>(tl->getType());
return true;
}
auto const& lo = tl->getFieldAmount(sfLowLimit);
auto const& hi = tl->getFieldAmount(sfHighLimit);
if (lo != hi)
{
JLOG(j_.warn()) << id << ": Trustline doesn't meet requirements";
return true;
}
if (auto const page = tl->getFieldU64(sfLowNode); !sb.dirRemove(
keylet::ownerDir(lo.getIssuer()), page, tl->key(), false))
{
JLOG(j_.error()) << id << ": failed to remove low entry from "
<< toBase58(lo.getIssuer()) << ":" << page
<< " owner directory";
return false;
}
if (auto const page = tl->getFieldU64(sfHighNode); !sb.dirRemove(
keylet::ownerDir(hi.getIssuer()), page, tl->key(), false))
{
JLOG(j_.error()) << id << ": failed to remove high entry from "
<< toBase58(hi.getIssuer()) << ":" << page
<< " owner directory";
return false;
}
if (tl->getFlags() & lsfLowReserve)
adjustOwnerCount(
sb, sb.peek(keylet::account(lo.getIssuer())), -1, j_);
if (tl->getFlags() & lsfHighReserve)
adjustOwnerCount(
sb, sb.peek(keylet::account(hi.getIssuer())), -1, j_);
sb.erase(tl);
JLOG(j_.warn()) << "Successfully deleted trustline " << id;
return true;
};
using namespace std::literals;
Sandbox sb(&view());
if (removeTrustLineToSelf(
sb,
uint256{
"2F8F21EFCAFD7ACFB07D5BB04F0D2E18587820C7611305BB674A64EAB0FA71E1"sv}) &&
removeTrustLineToSelf(
sb,
uint256{
"326035D5C0560A9DA8636545DD5A1B0DFCFF63E68D491B5522B767BB00564B1A"sv}))
{
JLOG(j_.warn()) << "fixTrustLinesToSelf amendment activation code "
"executed successfully";
sb.apply(ctx_.rawView());
}
}
TER
Change::applyAmendment()
{
@@ -223,6 +305,9 @@ Change::applyAmendment()
amendments.push_back(amendment);
amendmentObject->setFieldV256(sfAmendments, amendments);
if (amendment == fixTrustLinesToSelf)
activateTrustLinesToSelfFix();
ctx_.app.getAmendmentTable().enable(amendment);
if (!ctx_.app.getAmendmentTable().isSupported(amendment))

View File

@@ -29,6 +29,9 @@ public:
preclaim(PreclaimContext const& ctx);
private:
void
activateTrustLinesToSelfFix();
TER
applyAmendment();

View File

@@ -195,8 +195,29 @@ SetTrust::preclaim(PreclaimContext const& ctx)
auto const currency = saLimitAmount.getCurrency();
auto const uDstAccountID = saLimitAmount.getIssuer();
if (id == uDstAccountID)
return temDST_IS_SRC;
if (ctx.view.rules().enabled(fixTrustLinesToSelf))
{
if (id == uDstAccountID)
return temDST_IS_SRC;
}
else
{
if (id == uDstAccountID)
{
// Prevent trustline to self from being created,
// unless one has somehow already been created
// (in which case doApply will clean it up).
auto const sleDelete =
ctx.view.read(keylet::line(id, uDstAccountID, currency));
if (!sleDelete)
{
JLOG(ctx.j.trace())
<< "Malformed transaction: Can not extend credit to self.";
return temDST_IS_SRC;
}
}
}
// This might be nullptr
auto const sleDst = ctx.view.read(keylet::account(uDstAccountID));
@@ -382,6 +403,21 @@ SetTrust::doApply()
auto viewJ = ctx_.app.journal("View");
// Trust lines to self are impossible but because of the old bug there
// are two on 19-02-2022. This code was here to allow those trust lines
// to be deleted. The fixTrustLinesToSelf fix amendment will remove them
// when it enables so this code will no longer be needed.
if (!view().rules().enabled(fixTrustLinesToSelf) &&
account_ == uDstAccountID)
{
return trustDelete(
view(),
view().peek(keylet::line(account_, uDstAccountID, currency)),
account_,
uDstAccountID,
viewJ);
}
SLE::pointer sleDst = view().peek(keylet::account(uDstAccountID));
if (!sleDst)