Compare commits

...

11 Commits

Author SHA1 Message Date
Denis Angell
c6a27e895e compile 2025-02-26 13:10:03 +01:00
Denis Angell
b56dc38c22 Merge branch 'dev' into func-hooks 2025-02-26 12:39:50 +01:00
Denis Angell
e654219ba5 dump 2025-02-26 12:39:47 +01:00
tequ
89cacb1258 Enhance shell script error handling and debugging on GHA (#447) 2025-02-24 10:33:21 +01:00
tequ
8ccff44e8c Fix Error handling on build action (#412) 2025-02-24 18:16:21 +10:00
tequ
420240a2ab Fixed not to use a large fixed range in the magic_enum. (#436) 2025-02-24 17:46:42 +10:00
Richard Holland
230873f196 debug gh builds 2025-02-06 15:21:37 +11:00
Wietse Wind
1fb1a99ea2 Update build-in-docker.yml 2025-02-05 08:23:49 +01:00
Richard Holland
e0b63ac70e Revert "debug account tx tests under release builder"
This reverts commit da8df63be3.

Revert "add strict filtering to account_tx api (#429)"

This reverts commit 317bd4bc6e.
2025-02-05 14:59:33 +11:00
Richard Holland
da8df63be3 debug account tx tests under release builder 2025-02-04 17:02:17 +11:00
RichardAH
317bd4bc6e add strict filtering to account_tx api (#429) 2025-02-03 17:56:08 +10:00
13 changed files with 279 additions and 70 deletions

View File

@@ -14,7 +14,7 @@ jobs:
checkout:
runs-on: [self-hosted, vanity]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
clean: false
checkpatterns:

View File

@@ -764,6 +764,7 @@ if (tests)
src/test/app/ValidatorSite_test.cpp
src/test/app/SetHook_test.cpp
src/test/app/SetHookTSH_test.cpp
src/test/app/SetHookV3_test.cpp
src/test/app/Wildcard_test.cpp
src/test/app/XahauGenesis_test.cpp
src/test/app/tx/apply_test.cpp

View File

@@ -1,4 +1,11 @@
#!/bin/bash
#!/bin/bash -u
# We use set -e and bash with -u to bail on first non zero exit code of any
# processes launched or upon any unbound variable.
# We use set -x to print commands before running them to help with
# debugging.
set -ex
set -e
echo "START INSIDE CONTAINER - CORE"

View File

@@ -1,4 +1,11 @@
#!/bin/bash
#!/bin/bash -u
# We use set -e and bash with -u to bail on first non zero exit code of any
# processes launched or upon any unbound variable.
# We use set -x to print commands before running them to help with
# debugging.
set -ex
set -e
echo "START INSIDE CONTAINER - FULL"
@@ -19,7 +26,7 @@ yum-config-manager --disable centos-sclo-sclo
####
cd /io;
mkdir src/certs;
mkdir -p src/certs;
curl --silent -k https://raw.githubusercontent.com/RichardAH/rippled-release-builder/main/ca-bundle/certbundle.h -o src/certs/certbundle.h;
if [ "`grep certbundle.h src/ripple/net/impl/RegisterSSLCerts.cpp | wc -l`" -eq "0" ]
then
@@ -66,8 +73,8 @@ then
#endif/g" src/ripple/net/impl/RegisterSSLCerts.cpp &&
sed -i "s/#include <ripple\/net\/RegisterSSLCerts.h>/\0\n#include <certs\/certbundle.h>/g" src/ripple/net/impl/RegisterSSLCerts.cpp
fi
mkdir .nih_c;
mkdir .nih_toolchain;
mkdir -p .nih_c;
mkdir -p .nih_toolchain;
cd .nih_toolchain &&
yum install -y wget lz4 lz4-devel git llvm13-static.x86_64 llvm13-devel.x86_64 devtoolset-10-binutils zlib-static ncurses-static -y \
devtoolset-7-gcc-c++ \
@@ -115,7 +122,7 @@ tar -xf libunwind-13.0.1.src.tar.xz &&
cp -r libunwind-13.0.1.src/include libunwind-13.0.1.src/src lld-13.0.1.src/ &&
cd lld-13.0.1.src &&
rm -rf build CMakeCache.txt &&
mkdir build &&
mkdir -p build &&
cd build &&
cmake .. -DLLVM_LIBRARY_DIR=/usr/lib64/llvm13/lib/ -DCMAKE_INSTALL_PREFIX=/usr/lib64/llvm13/ -DCMAKE_BUILD_TYPE=Release &&
make -j$3 install &&
@@ -125,7 +132,7 @@ cd ../../ &&
echo "-- Build WasmEdge --" &&
( wget -nc -q https://github.com/WasmEdge/WasmEdge/archive/refs/tags/0.11.2.zip; unzip -o 0.11.2.zip; ) &&
cd WasmEdge-0.11.2 &&
( mkdir build; echo "" ) &&
( mkdir -p build; echo "" ) &&
cd build &&
export BOOST_ROOT="/usr/local/src/boost_1_86_0" &&
export Boost_LIBRARY_DIRS="/usr/local/lib" &&

View File

@@ -1,4 +1,11 @@
#!/bin/bash
#!/bin/bash -u
# We use set -e and bash with -u to bail on first non zero exit code of any
# processes launched or upon any unbound variable.
# We use set -x to print commands before running them to help with
# debugging.
set -ex
set -e
echo "START BUILDING (HOST)"
@@ -36,7 +43,8 @@ fi
STATIC_CONTAINER=$(docker ps -a | grep $CONTAINER_NAME |wc -l)
if [[ "$STATIC_CONTAINER" -gt "0" && "$GITHUB_REPOSITORY" != "" ]]; then
#if [[ "$STATIC_CONTAINER" -gt "0" && "$GITHUB_REPOSITORY" != "" ]]; then
if false; then
echo "Static container, execute in static container to have max. cache"
docker start $CONTAINER_NAME
docker exec -i $CONTAINER_NAME /hbb_exe/activate-exec bash -x /io/build-core.sh "$GITHUB_REPOSITORY" "$GITHUB_SHA" "$BUILD_CORES" "$GITHUB_RUN_NUMBER"

View File

@@ -14,9 +14,9 @@
using GuardLog =
std::optional<std::reference_wrapper<std::basic_ostream<char>>>;
#define DEBUG_GUARD 0
#define DEBUG_GUARD_VERBOSE 0
#define DEBUG_GUARD_VERY_VERBOSE 0
#define DEBUG_GUARD 1
#define DEBUG_GUARD_VERBOSE 1
#define DEBUG_GUARD_VERY_VERBOSE 1
#define GUARDLOG(logCode) \
if (!guardLog) \
@@ -901,23 +901,23 @@ validateGuards(
// followed by an leb128 length
int section_type = wasm[i++];
if (section_type == 0)
{
GUARDLOG(hook::log::CUSTOM_SECTION_DISALLOWED)
<< "Malformed transaction. "
<< "Hook contained a custom section, which is not allowed. Use "
"cleaner.\n";
return {};
}
// if (section_type == 0)
// {
// GUARDLOG(hook::log::CUSTOM_SECTION_DISALLOWED)
// << "Malformed transaction. "
// << "Hook contained a custom section, which is not allowed. Use "
// "cleaner.\n";
// return {};
// }
if (section_type <= last_section_type)
{
GUARDLOG(hook::log::SECTIONS_OUT_OF_SEQUENCE)
<< "Malformed transcation. "
<< "Hook contained wasm sections that were either repeated or "
"were out of sequence.\n";
return {};
}
// if (section_type <= last_section_type)
// {
// GUARDLOG(hook::log::SECTIONS_OUT_OF_SEQUENCE)
// << "Malformed transcation. "
// << "Hook contained wasm sections that were either repeated or "
// "were out of sequence.\n";
// return {};
// }
last_section_type = section_type;
@@ -1139,21 +1139,32 @@ validateGuards(
}
}
if (wasm[i] == 'm' && wasm[i + 1] == 'e' && wasm[i + 2] == 't' && wasm[i + 3] == 'h' && wasm[i + 4] == 'o' && wasm[i + 5] == 'd')
{
i += name_len;
CHECK_SHORT_HOOK();
i++;
CHECK_SHORT_HOOK();
hook_func_idx = parseLeb128(wasm, i, &i);
CHECK_SHORT_HOOK();
continue;
}
i += name_len + 1;
parseLeb128(wasm, i, &i);
CHECK_SHORT_HOOK();
}
// execution to here means export section was parsed
if (!hook_func_idx)
{
GUARDLOG(hook::log::EXPORT_MISSING)
<< "Malformed transaction. "
<< "Hook did not export: "
<< (!hook_func_idx ? "int64_t hook(uint32_t); " : "")
<< "\n";
return {};
}
// if (!hook_func_idx)
// {
// GUARDLOG(hook::log::EXPORT_MISSING)
// << "Malformed transaction. "
// << "Hook did not export: "
// << (!hook_func_idx ? "int64_t hook(uint32_t); " : "")
// << "\n";
// return {};
// }
}
else if (section_type == 3) // function section
{
@@ -1295,13 +1306,13 @@ validateGuards(
else
{
// fail
GUARDLOG(hook::log::FUNC_TYPE_INVALID)
<< "Invalid function type. Not used by any import or "
"hook/cbak func. "
<< "Codesec: " << section_type << " "
<< "Local: " << j << " "
<< "Offset: " << i << "\n";
return {};
// GUARDLOG(hook::log::FUNC_TYPE_INVALID)
// << "Invalid function type. Not used by any import or "
// "hook/cbak func. "
// << "Codesec: " << section_type << " "
// << "Local: " << j << " "
// << "Offset: " << i << "\n";
// return {};
}
int param_count = parseLeb128(wasm, i, &i);
@@ -1320,11 +1331,11 @@ validateGuards(
}
else if (param_count != (*first_signature).get().size() - 1)
{
GUARDLOG(hook::log::FUNC_TYPE_INVALID)
<< "Malformed transaction. "
<< "Hook API: " << *first_name
<< " has the wrong number of parameters.\n";
return {};
// GUARDLOG(hook::log::FUNC_TYPE_INVALID)
// << "Malformed transaction. "
// << "Hook API: " << *first_name
// << " has the wrong number of parameters.\n";
// return {};
}
for (int k = 0; k < param_count; ++k)
@@ -1388,12 +1399,12 @@ validateGuards(
// most compilers out
if (result_count != 1)
{
GUARDLOG(hook::log::FUNC_RETURN_COUNT)
<< "Malformed transaction. "
<< "Hook declares a function type that returns fewer "
"or more than one value. "
<< "\n";
return {};
// GUARDLOG(hook::log::FUNC_RETURN_COUNT)
// << "Malformed transaction. "
// << "Hook declares a function type that returns fewer "
// "or more than one value. "
// << "\n";
// return {};
}
// this can only ever be 1 in production, but in testing it may

View File

@@ -723,6 +723,9 @@ public:
uint32_t wasmParam,
beast::Journal const& j)
{
static WasmEdge_String _hookFunctionName = WasmEdge_StringCreateByCString("methodCreate");
// HookExecutor can only execute once
assert(!spent);
@@ -761,7 +764,7 @@ public:
vm.ctx,
reinterpret_cast<const uint8_t*>(wasm),
len,
callback ? cbakFunctionName : hookFunctionName,
_hookFunctionName,
params,
1,
returns,

View File

@@ -1776,7 +1776,7 @@ Transactor::operator()()
// write state if all chains executed successfully
if (isTesSuccess(result))
hook::finalizeHookState(stateMap, ctx_, ctx_.tx.getTransactionID());
result = hook::finalizeHookState(stateMap, ctx_, ctx_.tx.getTransactionID());
// write hook results
// this happens irrespective of whether final result was a tesSUCCESS
@@ -2031,8 +2031,9 @@ Transactor::operator()()
for (auto const& [accID, hookHashes] : aawMap)
doAgainAsWeak(accID, hookHashes, stateMap, weakResults, proMeta);
result = hook::finalizeHookState(stateMap, ctx_, ctx_.tx.getTransactionID());
// write hook results
hook::finalizeHookState(stateMap, ctx_, ctx_.tx.getTransactionID());
for (auto& weakResult : weakResults)
hook::finalizeHookResult(weakResult, ctx_, isTesSuccess(result));

View File

@@ -36,12 +36,12 @@
#include <magic/magic_enum.h>
#include <sstream>
#define MAGIC_ENUM(x) \
#define MAGIC_ENUM(x, _min, _max) \
template <> \
struct magic_enum::customize::enum_range<x> \
{ \
static constexpr int min = -20000; \
static constexpr int max = 20000; \
static constexpr int min = _min; \
static constexpr int max = _max; \
};
#define MAGIC_ENUM_16(x) \
@@ -59,14 +59,14 @@
static constexpr bool is_flags = true; \
};
MAGIC_ENUM(ripple::SerializedTypeID);
MAGIC_ENUM(ripple::LedgerEntryType);
MAGIC_ENUM(ripple::TELcodes);
MAGIC_ENUM(ripple::TEMcodes);
MAGIC_ENUM(ripple::TEFcodes);
MAGIC_ENUM(ripple::TERcodes);
MAGIC_ENUM(ripple::TEScodes);
MAGIC_ENUM(ripple::TECcodes);
MAGIC_ENUM(ripple::SerializedTypeID, -2, 10004);
MAGIC_ENUM(ripple::LedgerEntryType, 0, 255);
MAGIC_ENUM(ripple::TELcodes, -399, 300);
MAGIC_ENUM(ripple::TEMcodes, -299, -200);
MAGIC_ENUM(ripple::TEFcodes, -199, -100);
MAGIC_ENUM(ripple::TERcodes, -99, -1);
MAGIC_ENUM(ripple::TEScodes, 0, 1);
MAGIC_ENUM(ripple::TECcodes, 100, 255);
MAGIC_ENUM_16(ripple::TxType);
MAGIC_ENUM_FLAG(ripple::UniversalFlags);
MAGIC_ENUM_FLAG(ripple::AccountSetFlags);

1
src/test/app/.env Normal file
View File

@@ -0,0 +1 @@
HOOKS_COMPILE_HOST=http://localhost:9000

View File

@@ -0,0 +1,140 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012-2016 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <ripple/app/hook/Enum.h>
#include <ripple/app/ledger/LedgerMaster.h>
#include <ripple/app/tx/impl/SetHook.h>
#include <ripple/protocol/TxFlags.h>
#include <ripple/protocol/jss.h>
#include <test/app/SetHook_wasm.h>
#include <test/jtx.h>
#include <test/jtx/hook.h>
#include <unordered_map>
#include <iostream>
#include <ripple/json/json_reader.h>
namespace ripple {
namespace test {
class SetHookV3_test : public beast::unit_test::suite
{
private:
// helper
void static overrideFlag(Json::Value& jv)
{
jv[jss::Flags] = hsfOVERRIDE;
}
public:
// This is a large fee, large enough that we can set most small test hooks
// without running into fee issues we only want to test fee code specifically in
// fee unit tests, the rest of the time we want to ignore it.
#define HSFEE fee(100'000'000)
#define M(m) memo(m, "", "")
std::string
loadHook()
{
std::string name = "/Users/darkmatter/projects/ledger-works/xahaud/src/test/app/wasm/custom.wasm";
if (!std::filesystem::exists(name)) {
std::cout << "File does not exist: " << name << "\n";
return "";
}
std::ifstream hookFile(name, std::ios::binary);
if (!hookFile)
{
std::cout << "Failed to open file: " << name << "\n";
return "";
}
// Read the file into a vector
std::vector<char> buffer((std::istreambuf_iterator<char>(hookFile)), std::istreambuf_iterator<char>());
// Check if the buffer is empty
if (buffer.empty()) {
std::cout << "File is empty or could not be read properly.\n";
return "";
}
return strHex(buffer);
}
void
testSimple(FeatureBitset features)
{
testcase("Test simple");
using namespace jtx;
// Env env{*this, features};
Env env{*this, envconfig(), features, nullptr,
beast::severities::kTrace
};
auto const alice = Account{"alice"};
auto const gw = Account{"gateway"};
auto const USD = gw["USD"];
env.fund(XRP(10000), alice, gw);
env.close();
env.trust(USD(100000), alice);
env.close();
env(pay(gw, alice, USD(10000)));
env.close();
std::string hook = loadHook();
std::cout << "Hook: " << hook << "\n";
// install the hook on alice
env(ripple::test::jtx::hook(alice, {{hso(hook, overrideFlag)}}, 0),
M("set simple"),
HSFEE);
env.close();
// // invoke the hook
// Json::Value jv = invoke::invoke(alice);
// Json::Value params{Json::arrayValue};
// Json::Value pv;
// Json::Value piv;
// piv[jss::HookParameterName] = "736F6D6566756E63";
// piv[jss::HookParameterValue] = "736F6D6566756E63";
// pv[jss::HookParameter] = piv;
// params[0u] = pv;
// jv[jss::HookParameters] = params;
env(invoke::invoke(alice), M("test simple"), fee(XRP(1)));
}
void
testWithFeatures(FeatureBitset features)
{
testSimple(features);
}
void
run() override
{
using namespace test::jtx;
auto const sa = supported_amendments();
testWithFeatures(sa);
}
};
BEAST_DEFINE_TESTSUITE(SetHookV3, app, ripple);
} // namespace test
} // namespace ripple
#undef M

View File

@@ -0,0 +1,10 @@
/**
*
*/
#include "hookapi.h"
int64_t hook(uint32_t reserved) {
TRACESTR("Base.c: Called.");
_g(1,1);
return accept(SBUF("base: Finished."), __LINE__);;
}

View File

@@ -0,0 +1,20 @@
/**
*
*/
#include "hookapi.h"
// #define DEBUG 1
// #define SBUF(str) (uint32_t)(str), sizeof(str)
// #define TRACESTR(v) if (DEBUG) trace((uint32_t)(#v), (uint32_t)(sizeof(#v) - 1), (uint32_t)(v), sizeof(v), 0);
// // hook developers should use this guard macro, simply GUARD(<maximum iterations>)
// #define GUARD(maxiter) _g((1ULL << 31U) + __LINE__, (maxiter)+1)
// #define GUARDM(maxiter, n) _g(( (1ULL << 31U) + (__LINE__ << 16) + n), (maxiter)+1)
// hooks-cli compile-c contracts/custom.c build
int64_t methodCreate(uint32_t reserved) {
TRACESTR("somefunc.c: Called.");
for (int i = 0; GUARD(10), i < 10; i++) {
TRACESTR("somefunc.c: Iterating.");
}
return accept(SBUF("somefunc.c: Finished."), __LINE__);
}