Compare commits

..

1 Commits

Author SHA1 Message Date
Nik Bougalis
b277c353a8 Eliminate dead bytes from nodestore encoding:
The legacy nodestore encoding for blobs had an 8 byte prefix. Originally
the first 4 bytes stored the sequence number of the ledger to which the
encoded object belogned; the next 4 bytes were never specified rigidly
and some versions stored a redundant copy of the ledger sequence while
others simply set the bytes to 0.

Eventually that scheme was abandoned, and the first 8 bytes were just
set to 0 and ignored when reloading a blob.

This commit removes the unusued 8 byte legacy prefix. The change is
makes it impossible to load old databases with this code and for old
versions to load databases created with this code.
2023-01-07 15:36:34 -08:00
542 changed files with 24867 additions and 68247 deletions

View File

@@ -1,7 +0,0 @@
# Ignore everything
*
# Allow files and directories
!/build-inner.sh
!/release-builder.sh

View File

@@ -1,35 +0,0 @@
name: Build using Docker
on:
push:
branches: [ "dev", "test", "release" ]
pull_request:
branches: [ "dev", "release" ]
jobs:
builder:
runs-on: [self-hosted, vanity]
steps:
- uses: actions/checkout@v3
with:
clean: false
- name: Build using Docker
run: /bin/bash release-builder.sh
unittests:
needs: builder
runs-on: [self-hosted, vanity]
steps:
- name: Unit tests
run: /bin/bash docker-unit-tests.sh
# publisher:
# needs: builder
# runs-on: [self-hosted, vanity]
# steps:
# - uses: actions/upload-artifact@v3
# with:
# name: build-${{ github.run_number }}
# path: |
# release-build/xahaud
# release-build/release.info

View File

@@ -4,17 +4,16 @@ on: [push, pull_request]
jobs:
check:
runs-on: ubuntu-20.04
runs-on: ubuntu-18.04
env:
CLANG_VERSION: 10
steps:
- uses: actions/checkout@v2
- name: Install clang-format
run: |
codename=$( lsb_release --codename --short )
sudo tee /etc/apt/sources.list.d/llvm.list >/dev/null <<EOF
deb http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}-${CLANG_VERSION} main
deb-src http://apt.llvm.org/${codename}/ llvm-toolchain-${codename}-${CLANG_VERSION} main
deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-${CLANG_VERSION} main
deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-${CLANG_VERSION} main
EOF
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add
sudo apt-get update

View File

@@ -6,7 +6,7 @@ on:
jobs:
job:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
container:
image: docker://rippleci/rippled-ci-builder:2944b78d22db
steps:

View File

@@ -4,7 +4,7 @@ on: [push, pull_request]
jobs:
check:
runs-on: ubuntu-latest
runs-on: ubuntu-18.04
env:
CLANG_VERSION: 10
steps:

3
.gitignore vendored
View File

@@ -111,6 +111,3 @@ compile_commands.json
.clangd
packages
pkg_out
pkg
CMakeUserPresets.json
bld.rippled/

13
.vscode/settings.json vendored
View File

@@ -1,13 +0,0 @@
{
"C_Cpp.formatting": "clangFormat",
"C_Cpp.clang_format_path": "/Users/dustedfloor/projects/transia-rnd/rippled-icv2/.clang-format",
"C_Cpp.clang_format_fallbackStyle": "{ ColumnLimit: 0 }",
"[cpp]":{
"editor.wordBasedSuggestions": false,
"editor.suggest.insertMode": "replace",
"editor.semanticHighlighting.enabled": true,
"editor.tabSize": 4,
"editor.defaultFormatter": "xaver.clang-format",
"editor.formatOnSave": false
}
}

View File

@@ -124,10 +124,7 @@ else ()
# * static option set and
# * NOT APPLE (AppleClang does not support static libc/c++) and
# * NOT san (sanitizers typically don't work with static libc/c++)
$<$<AND:$<BOOL:${static}>,$<NOT:$<BOOL:${APPLE}>>,$<NOT:$<BOOL:${san}>>>:
-static-libstdc++
-static-libgcc
>)
$<$<AND:$<BOOL:${static}>,$<NOT:$<BOOL:${APPLE}>>,$<NOT:$<BOOL:${san}>>>:-static-libstdc++>)
endif ()
if (use_gold AND is_gcc)

View File

@@ -13,15 +13,6 @@ if (unity)
set_target_properties(xrpl_core PROPERTIES UNITY_BUILD ON)
endif ()
# Try to find the ACL library
find_library(ACL_LIBRARY NAMES acl)
# Check if ACL was found
if(ACL_LIBRARY)
message(STATUS "Found ACL: ${ACL_LIBRARY}")
else()
message(STATUS "ACL not found, continuing without ACL support")
endif()
#[===============================[
beast/legacy FILES:
@@ -59,7 +50,6 @@ target_sources (xrpl_core PRIVATE
src/ripple/basics/impl/FileUtilities.cpp
src/ripple/basics/impl/IOUAmount.cpp
src/ripple/basics/impl/Log.cpp
src/ripple/basics/impl/Number.cpp
src/ripple/basics/impl/StringUtilities.cpp
#[===============================[
main sources:
@@ -164,7 +154,6 @@ install (
src/ripple/basics/LocalValue.h
src/ripple/basics/Log.h
src/ripple/basics/MathUtilities.h
src/ripple/basics/Number.h
src/ripple/basics/safe_cast.h
src/ripple/basics/Slice.h
src/ripple/basics/spinlock.h
@@ -452,15 +441,12 @@ target_sources (rippled PRIVATE
src/ripple/app/tx/impl/SetRegularKey.cpp
src/ripple/app/tx/impl/SetHook.cpp
src/ripple/app/tx/impl/ClaimReward.cpp
src/ripple/app/tx/impl/GenesisMint.cpp
src/ripple/app/tx/impl/Import.cpp
src/ripple/app/tx/impl/Invoke.cpp
src/ripple/app/tx/impl/SetSignerList.cpp
src/ripple/app/tx/impl/SetTrust.cpp
src/ripple/app/tx/impl/SignerEntries.cpp
src/ripple/app/tx/impl/Taker.cpp
src/ripple/app/tx/impl/Transactor.cpp
src/ripple/app/tx/impl/URIToken.cpp
src/ripple/app/tx/impl/apply.cpp
src/ripple/app/tx/impl/applySteps.cpp
src/ripple/app/hook/impl/applyHook.cpp
@@ -549,6 +535,7 @@ target_sources (rippled PRIVATE
src/ripple/nodestore/impl/DeterministicShard.cpp
src/ripple/nodestore/impl/DecodedBlob.cpp
src/ripple/nodestore/impl/DummyScheduler.cpp
src/ripple/nodestore/impl/EncodedBlob.cpp
src/ripple/nodestore/impl/ManagerImp.cpp
src/ripple/nodestore/impl/NodeObject.cpp
src/ripple/nodestore/impl/Shard.cpp
@@ -658,6 +645,7 @@ target_sources (rippled PRIVATE
src/ripple/rpc/handlers/WalletPropose.cpp
src/ripple/rpc/impl/DeliveredAmount.cpp
src/ripple/rpc/impl/Handler.cpp
src/ripple/rpc/impl/GRPCHelpers.cpp
src/ripple/rpc/impl/LegacyPathFind.cpp
src/ripple/rpc/impl/RPCHandler.cpp
src/ripple/rpc/impl/RPCHelpers.cpp
@@ -703,7 +691,6 @@ if (tests)
src/test/app/AccountTxPaging_test.cpp
src/test/app/AmendmentTable_test.cpp
src/test/app/Check_test.cpp
src/test/app/ClaimReward_test.cpp
src/test/app/CrossingLimits_test.cpp
src/test/app/DeliverMin_test.cpp
src/test/app/DepositAuth_test.cpp
@@ -714,11 +701,8 @@ if (tests)
src/test/app/Flow_test.cpp
src/test/app/Freeze_test.cpp
src/test/app/HashRouter_test.cpp
src/test/app/Import_test.cpp
src/test/app/Invoke_test.cpp
src/test/app/LedgerHistory_test.cpp
src/test/app/LedgerLoad_test.cpp
src/test/app/LedgerMaster_test.cpp
src/test/app/LedgerReplay_test.cpp
src/test/app/LoadFeeTrack_test.cpp
src/test/app/Manifest_test.cpp
@@ -747,13 +731,10 @@ if (tests)
src/test/app/Transaction_ordering_test.cpp
src/test/app/TrustAndBalance_test.cpp
src/test/app/TxQ_test.cpp
src/test/app/UNLReport_test.cpp
src/test/app/URIToken_test.cpp
src/test/app/ValidatorKeys_test.cpp
src/test/app/ValidatorList_test.cpp
src/test/app/ValidatorSite_test.cpp
src/test/app/SetHook_test.cpp
src/test/app/XahauGenesis_test.cpp
src/test/app/tx/apply_test.cpp
#[===============================[
test sources:
@@ -764,7 +745,7 @@ if (tests)
src/test/basics/Expected_test.cpp
src/test/basics/FileUtilities_test.cpp
src/test/basics/IOUAmount_test.cpp
src/test/basics/Number_test.cpp
src/test/basics/KeyCache_test.cpp
src/test/basics/PerfLog_test.cpp
src/test/basics/RangeSet_test.cpp
src/test/basics/scope_test.cpp
@@ -823,6 +804,7 @@ if (tests)
src/test/core/CryptoPRNG_test.cpp
src/test/core/JobQueue_test.cpp
src/test/core/SociDB_test.cpp
src/test/core/Workers_test.cpp
#[===============================[
test sources:
subdir: csf
@@ -936,8 +918,8 @@ if (tests)
src/test/protocol/BuildInfo_test.cpp
src/test/protocol/InnerObjectFormats_test.cpp
src/test/protocol/Issue_test.cpp
src/test/protocol/KnownFormatToGRPC_test.cpp
src/test/protocol/Hooks_test.cpp
src/test/protocol/Memo_test.cpp
src/test/protocol/PublicKey_test.cpp
src/test/protocol/Quality_test.cpp
src/test/protocol/STAccount_test.cpp
@@ -971,6 +953,7 @@ if (tests)
src/test/rpc/DepositAuthorized_test.cpp
src/test/rpc/DeliveredAmount_test.cpp
src/test/rpc/Feature_test.cpp
src/test/rpc/Fee_test.cpp
src/test/rpc/GatewayBalances_test.cpp
src/test/rpc/GetCounts_test.cpp
src/test/rpc/JSONRPC_test.cpp
@@ -993,10 +976,12 @@ if (tests)
src/test/rpc/ServerInfo_test.cpp
src/test/rpc/ShardArchiveHandler_test.cpp
src/test/rpc/Status_test.cpp
src/test/rpc/Submit_test.cpp
src/test/rpc/Subscribe_test.cpp
src/test/rpc/Transaction_test.cpp
src/test/rpc/TransactionEntry_test.cpp
src/test/rpc/TransactionHistory_test.cpp
src/test/rpc/Tx_test.cpp
src/test/rpc/ValidatorInfo_test.cpp
src/test/rpc/ValidatorRPC_test.cpp
src/test/rpc/Version_test.cpp
@@ -1048,7 +1033,3 @@ if (tests)
src/test/rpc/ShardArchiveHandler_test.cpp
PROPERTIES SKIP_UNITY_BUILD_INCLUSION TRUE)
endif () #tests
if(ACL_LIBRARY)
target_link_libraries(rippled ${ACL_LIBRARY})
endif()

View File

@@ -37,7 +37,7 @@ if (is_root_project)
docker build
--pull
--build-arg GIT_COMMIT=${commit_hash}
-t rippleci/rippled-rpm-builder:${container_label}
-t rippled-rpm-builder:${container_label}
$<$<BOOL:${rpm_cache_from}>:--cache-from=${rpm_cache_from}>
-f centos-builder/Dockerfile .
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/Builds/containers
@@ -47,10 +47,12 @@ if (is_root_project)
SOURCES
Builds/containers/centos-builder/Dockerfile
Builds/containers/centos-builder/centos_setup.sh
Builds/containers/centos-builder/extras.sh
Builds/containers/shared/update-rippled.sh
Builds/containers/shared/update_sources.sh
Builds/containers/shared/rippled.service
Builds/containers/shared/rippled-reporting.service
Builds/containers/shared/build_deps.sh
Builds/containers/packaging/rpm/rippled.spec
Builds/containers/packaging/rpm/build_rpm.sh
Builds/containers/packaging/rpm/50-rippled.preset
@@ -64,7 +66,8 @@ if (is_root_project)
-v ${NIH_CACHE_ROOT}/pkgbuild:/opt/rippled_bld/pkg/.nih_c
-v ${CMAKE_CURRENT_SOURCE_DIR}:/opt/rippled_bld/pkg/rippled
-v ${CMAKE_CURRENT_BINARY_DIR}/packages:/opt/rippled_bld/pkg/out
-t rippleci/rippled-rpm-builder:${container_label}
"$<$<BOOL:${map_user}>:--volume=/etc/passwd:/etc/passwd;--volume=/etc/group:/etc/group;--user=${DOCKER_USER_ID}:${DOCKER_GROUP_ID}>"
-t rippled-rpm-builder:${container_label}
/bin/bash -c "cp -fpu rippled/Builds/containers/packaging/rpm/build_rpm.sh . && ./build_rpm.sh"
VERBATIM
USES_TERMINAL
@@ -79,7 +82,7 @@ if (is_root_project)
#[===================================================================[
dpkg
#]===================================================================]
# currently use ubuntu 18.04 as a base b/c it has one of
# currently use ubuntu 16.04 as a base b/c it has one of
# the lower versions of libc among ubuntu and debian releases.
# we could change this in the future and build with some other deb
# based system.
@@ -122,8 +125,10 @@ if (is_root_project)
Builds/containers/ubuntu-builder/ubuntu_setup.sh
bin/getRippledInfo
Builds/containers/shared/install_cmake.sh
Builds/containers/shared/install_boost.sh
Builds/containers/shared/update-rippled.sh
Builds/containers/shared/update_sources.sh
Builds/containers/shared/build_deps.sh
Builds/containers/shared/rippled.service
Builds/containers/shared/rippled-reporting.service
Builds/containers/shared/rippled-logrotate
@@ -136,6 +141,7 @@ if (is_root_project)
-v ${NIH_CACHE_ROOT}/pkgbuild:/opt/rippled_bld/pkg/.nih_c
-v ${CMAKE_CURRENT_SOURCE_DIR}:/opt/rippled_bld/pkg/rippled
-v ${CMAKE_CURRENT_BINARY_DIR}/packages:/opt/rippled_bld/pkg/out
"$<$<BOOL:${map_user}>:--volume=/etc/passwd:/etc/passwd;--volume=/etc/group:/etc/group;--user=${DOCKER_USER_ID}:${DOCKER_GROUP_ID}>"
-t rippled-dpkg-builder:${container_label}
/bin/bash -c "cp -fpu rippled/Builds/containers/packaging/dpkg/build_dpkg.sh . && ./build_dpkg.sh"
VERBATIM
@@ -189,6 +195,7 @@ if (is_root_project)
SOURCES
Builds/containers/ubuntu-builder/Dockerfile
Builds/containers/ubuntu-builder/ubuntu_setup.sh
Builds/containers/shared/build_deps.sh
)
exclude_from_default (ci_container)
else ()

View File

@@ -1,106 +0,0 @@
################################################################################
# SociConfig.cmake - CMake build configuration of SOCI library
################################################################################
# Copyright (C) 2010 Mateusz Loskot <mateusz@loskot.net>
#
# Distributed under the Boost Software License, Version 1.0.
# (See accompanying file LICENSE_1_0.txt or copy at
# http://www.boost.org/LICENSE_1_0.txt)
################################################################################
include(CheckCXXSymbolExists)
if(WIN32)
check_cxx_symbol_exists("_M_AMD64" "" SOCI_TARGET_ARCH_X64)
if(NOT RTC_ARCH_X64)
check_cxx_symbol_exists("_M_IX86" "" SOCI_TARGET_ARCH_X86)
endif(NOT RTC_ARCH_X64)
# add check for arm here
# see http://msdn.microsoft.com/en-us/library/b0084kay.aspx
else(WIN32)
check_cxx_symbol_exists("__i386__" "" SOCI_TARGET_ARCH_X86)
check_cxx_symbol_exists("__x86_64__" "" SOCI_TARGET_ARCH_X64)
check_cxx_symbol_exists("__arm__" "" SOCI_TARGET_ARCH_ARM)
endif(WIN32)
if(NOT DEFINED LIB_SUFFIX)
if(SOCI_TARGET_ARCH_X64)
set(_lib_suffix "64")
else()
set(_lib_suffix "")
endif()
set(LIB_SUFFIX ${_lib_suffix} CACHE STRING "Specifies suffix for the lib directory")
endif()
#
# C++11 Option
#
if(NOT SOCI_CXX_C11)
set (SOCI_CXX_C11 OFF CACHE BOOL "Build to the C++11 standard")
endif()
#
# Force compilation flags and set desired warnings level
#
if (MSVC)
add_definitions(-D_CRT_SECURE_NO_DEPRECATE)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-D_CRT_NONSTDC_NO_WARNING)
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
if(CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
string(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4 /we4266")
endif()
else()
set(SOCI_GCC_CLANG_COMMON_FLAGS "")
# "-pedantic -Werror -Wno-error=parentheses -Wall -Wextra -Wpointer-arith -Wcast-align -Wcast-qual -Wfloat-equal -Woverloaded-virtual -Wredundant-decls -Wno-long-long")
if (SOCI_CXX_C11)
set(SOCI_CXX_VERSION_FLAGS "-std=c++11")
else()
set(SOCI_CXX_VERSION_FLAGS "-std=gnu++98")
endif()
if("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER}" MATCHES "clang")
if(NOT CMAKE_CXX_COMPILER_VERSION LESS 3.1 AND SOCI_ASAN)
set(SOCI_GCC_CLANG_COMMON_FLAGS "${SOCI_GCC_CLANG_COMMON_FLAGS} -fsanitize=address")
endif()
# enforce C++11 for Clang
set(SOCI_CXX_C11 ON)
set(SOCI_CXX_VERSION_FLAGS "-std=c++11")
add_definitions(-DCATCH_CONFIG_CPP11_NO_IS_ENUM)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SOCI_GCC_CLANG_COMMON_FLAGS} ${SOCI_CXX_VERSION_FLAGS}")
elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX)
if(NOT CMAKE_CXX_COMPILER_VERSION LESS 4.8 AND SOCI_ASAN)
set(SOCI_GCC_CLANG_COMMON_FLAGS "${SOCI_GCC_CLANG_COMMON_FLAGS} -fsanitize=address")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${SOCI_GCC_CLANG_COMMON_FLAGS} ${SOCI_CXX_VERSION_FLAGS} ")
if (CMAKE_COMPILER_IS_GNUCXX)
if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-variadic-macros")
endif()
endif()
else()
message(WARNING "Unknown toolset - using default flags to build SOCI")
endif()
endif()
# Set SOCI_HAVE_* variables for soci-config.h generator
set(SOCI_HAVE_CXX_C11 ${SOCI_CXX_C11} CACHE INTERNAL "Enables C++11 support")

View File

@@ -15,5 +15,3 @@ find_library (soci
find_path (SOCI_INCLUDE_DIR
NAMES soci/soci.h)
message("SOCI FOUND AT: ${SOCI_LIB}")

View File

@@ -13,7 +13,7 @@ if(reporting)
ExternalProject_Add(postgres_src
PREFIX ${nih_cache_path}
GIT_REPOSITORY https://github.com/postgres/postgres.git
GIT_TAG REL_14_5
GIT_TAG master
CONFIGURE_COMMAND ./configure --without-readline > /dev/null
BUILD_COMMAND ${CMAKE_COMMAND} -E env --unset=MAKELEVEL make
UPDATE_COMMAND ""

View File

@@ -51,8 +51,7 @@ else()
# This patch process is likely fragile and should be reviewed carefully
# whenever we update the GIT_TAG above.
PATCH_COMMAND
${CMAKE_COMMAND} -D RIPPLED_SOURCE=${CMAKE_CURRENT_SOURCE_DIR}
-P ${CMAKE_CURRENT_SOURCE_DIR}/Builds/CMake/soci_patch.cmake
${CMAKE_COMMAND} -P ${CMAKE_CURRENT_SOURCE_DIR}/Builds/CMake/soci_patch.cmake
CMAKE_ARGS
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_C_COMPILER=${CMAKE_C_COMPILER}

View File

@@ -2,15 +2,6 @@
NIH dep: wasmedge: web assembly runtime for hooks.
#]===================================================================]
find_package(Curses)
if(CURSES_FOUND)
include_directories(${CURSES_INCLUDE_DIR})
target_link_libraries(ripple_libs INTERFACE ${CURSES_LIBRARY})
else()
message(WARNING "CURSES library not found... (only important for mac builds)")
endif()
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
@@ -33,7 +24,6 @@ ExternalProject_Add (wasmedge_src
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
-DLLVM_DIR=${LLVM_DIR}
-DLLVM_LIBRARY_DIR=${LLVM_LIBRARY_DIR}
-DLLVM_ENABLE_TERMINFO=OFF
$<$<NOT:$<BOOL:${is_multiconfig}>>:-DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}>
$<$<BOOL:${MSVC}>:
"-DCMAKE_C_FLAGS=-GR -Gd -fp:precise -FS -MP -march=native"
@@ -73,12 +63,4 @@ set_target_properties (wasmedge PROPERTIES
"${wasmedge_src_BINARY_DIR}/include/api/"
)
target_link_libraries (ripple_libs INTERFACE wasmedge)
#RH NOTE: some compilers / versions of some libraries need these, most don't
find_library(XAR_LIBRARY NAMES xar)
if(XAR_LIBRARY)
target_link_libraries(ripple_libs INTERFACE ${XAR_LIBRARY})
else()
message(WARNING "xar library not found... (only important for mac builds)")
endif()
add_library (NIH::WasmEdge ALIAS wasmedge)

View File

@@ -11,7 +11,7 @@ if(reporting)
ExternalProject_Add(zlib_src
PREFIX ${nih_cache_path}
GIT_REPOSITORY https://github.com/madler/zlib.git
GIT_TAG v1.2.12
GIT_TAG master
INSTALL_COMMAND ""
BUILD_BYPRODUCTS <BINARY_DIR>/${ep_lib_prefix}z.a
LOG_BUILD TRUE
@@ -45,7 +45,7 @@ if(reporting)
ExternalProject_Add(krb5_src
PREFIX ${nih_cache_path}
GIT_REPOSITORY https://github.com/krb5/krb5.git
GIT_TAG krb5-1.20-final
GIT_TAG master
UPDATE_COMMAND ""
CONFIGURE_COMMAND autoreconf src && CFLAGS=-fcommon ./src/configure --enable-static --disable-shared > /dev/null
BUILD_IN_SOURCE 1
@@ -80,7 +80,7 @@ if(reporting)
ExternalProject_Add(libuv_src
PREFIX ${nih_cache_path}
GIT_REPOSITORY https://github.com/libuv/libuv.git
GIT_TAG v1.44.2
GIT_TAG v1.x
INSTALL_COMMAND ""
BUILD_BYPRODUCTS <BINARY_DIR>/${ep_lib_prefix}uv_a.a
LOG_BUILD TRUE
@@ -106,7 +106,7 @@ if(reporting)
ExternalProject_Add(cassandra_src
PREFIX ${nih_cache_path}
GIT_REPOSITORY https://github.com/datastax/cpp-driver.git
GIT_TAG 2.16.2
GIT_TAG master
CMAKE_ARGS
-DLIBUV_ROOT_DIR=${BINARY_DIR}
-DLIBUV_LIBARY=${BINARY_DIR}/libuv_a.a

View File

@@ -2,16 +2,6 @@
# so as to remove type range check exceptions that cause
# us trouble when using boost::optional to select int values
# Soci's CMake setup leaves flags in place that will cause warnings to
# be treated as errors, but some compiler versions throw "new" warnings
# that then cause the build to fail. Simplify that until soci fixes
# those warnings.
if (RIPPLED_SOURCE)
execute_process( COMMAND ${CMAKE_COMMAND} -E copy_if_different
${RIPPLED_SOURCE}/Builds/CMake/SociConfig.cmake.patched
cmake/SociConfig.cmake )
endif ()
# Some versions of CMake erroneously patch external projects on every build.
# If the patch makes no changes, skip it. This workaround can be
# removed once we stop supporting vulnerable versions of CMake.

View File

@@ -1 +0,0 @@
[Please see the BUILD instructions here](../BUILD.md)

View File

@@ -3,7 +3,7 @@
"configurations": [
{
"name": "x64-Debug",
"generator": "Visual Studio 16 2019",
"generator": "Visual Studio 15 2017 Win64",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${thisFileDir}\\build\\${name}",
@@ -23,7 +23,7 @@
},
{
"name": "x64-Release",
"generator": "Visual Studio 16 2019",
"generator": "Visual Studio 15 2017 Win64",
"configurationType": "Release",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${thisFileDir}\\build\\${name}",

View File

@@ -1 +1,263 @@
[Build instructions are currently located in `BUILD.md`](../../BUILD.md)
# Visual Studio 2017 Build Instructions
## Important
We do not recommend Windows for rippled production use at this time. Currently,
the Ubuntu platform has received the highest level of quality assurance,
testing, and support. Additionally, 32-bit Windows versions are not supported.
## Prerequisites
To clone the source code repository, create branches for inspection or
modification, build rippled under Visual Studio, and run the unit tests you will
need these software components
| Component | Minimum Recommended Version |
|-----------|-----------------------|
| [Visual Studio 2017](README.md#install-visual-studio-2017)| 15.5.4 |
| [Git for Windows](README.md#install-git-for-windows)| 2.16.1 |
| [OpenSSL Library](README.md#install-openssl) | 1.1.1L |
| [Boost library](README.md#build-boost) | 1.70.0 |
| [CMake for Windows](README.md#optional-install-cmake-for-windows)* | 3.12 |
\* Only needed if not using the integrated CMake in VS 2017 and prefer generating dedicated project/solution files.
## Install Software
### Install Visual Studio 2017
If not already installed on your system, download your choice of installer from
the [Visual Studio 2017
Download](https://www.visualstudio.com/downloads/download-visual-studio-vs)
page, run the installer, and follow the directions. **You may need to choose the
`Desktop development with C++` workload to install all necessary C++ features.**
Any version of Visual Studio 2017 may be used to build rippled. The **Visual
Studio 2017 Community** edition is available free of charge (see [the product
page](https://www.visualstudio.com/products/visual-studio-community-vs) for
licensing details), while paid editions may be used for an initial free-trial
period.
### Install Git for Windows
Git is a distributed revision control system. The Windows version also provides
the bash shell and many Windows versions of Unix commands. While there are other
varieties of Git (such as TortoiseGit, which has a native Windows interface and
integrates with the Explorer shell), we recommend installing [Git for
Windows](https://git-scm.com/) since it provides a Unix-like command line
environment useful for running shell scripts. Use of the bash shell under
Windows is mandatory for running the unit tests.
### Install OpenSSL
[Download the latest version of
OpenSSL.](http://slproweb.com/products/Win32OpenSSL.html) There will
several `Win64` bit variants available, you want the non-light
`v1.1` line. As of this writing, you **should** select
* Win64 OpenSSL v1.1.1L
and should **not** select
* Anything with "Win32" in the name
* Anything with "light" in the name
* Anything with "EXPERIMENTAL" in the name
* Anything in the 3.0 line - rippled won't currently build with this version.
Run the installer, and choose an appropriate location for your OpenSSL
installation. In this guide we use `C:\lib\OpenSSL-Win64` as the destination
location.
You may be informed on running the installer that "Visual C++ 2008
Redistributables" must first be installed first. If so, download it from the
[same page](http://slproweb.com/products/Win32OpenSSL.html), again making sure
to get the correct 32-/64-bit variant.
* NOTE: Since rippled links statically to OpenSSL, it does not matter where the
OpenSSL .DLL files are placed, or what version they are. rippled does not use
or require any external .DLL files to run other than the standard operating
system ones.
### Build Boost
Boost 1.70 or later is required.
After [downloading boost](http://www.boost.org/users/download/) and unpacking it
to `c:\lib`. As of this writing, the most recent version of boost is 1.70.0,
which will unpack into a directory named `boost_1_70_0`. We recommended either
renaming this directory to `boost`, or creating a junction link `mklink /J boost
boost_1_70_0`, so that you can more easily switch between versions.
Next, open **Developer Command Prompt** and type the following commands
```powershell
cd C:\lib\boost
bootstrap
```
The rippled application is linked statically to the standard runtimes and
external dependencies on Windows, to ensure that the behavior of the executable
is not affected by changes in outside files. Therefore, it is necessary to build
the required boost static libraries using this command:
```powershell
bjam -j<Num Parallel> --toolset=msvc-14.1 address-model=64 architecture=x86 link=static threading=multi runtime-link=shared,static stage
```
where you should replace `<Num Parallel>` with the number of parallel
invocations to use build, e.g. `bjam -j4 ...` would use up to 4 concurrent build
shell commands for the build.
Building the boost libraries may take considerable time. When the build process
is completed, take note of both the reported compiler include paths and linker
library paths as they will be required later.
### (Optional) Install CMake for Windows
[CMake](http://cmake.org) is a cross platform build system generator. Visual
Studio 2017 includes an integrated version of CMake that avoids having to
manually run CMake, but it is undergoing continuous improvement. Users that
prefer to use standard Visual Studio project and solution files need to install
a dedicated version of CMake to generate them. The latest version can be found
at the [CMake download site](https://cmake.org/download/). It is recommended you
select the install option to add CMake to your path.
## Clone the rippled repository
If you are familiar with cloning github repositories, just follow your normal
process and clone `git@github.com:ripple/rippled.git`. Otherwise follow this
section for instructions.
1. If you don't have a github account, sign up for one at
[github.com](https://github.com/).
2. Make sure you have Github ssh keys. For help see
[generating-ssh-keys](https://help.github.com/articles/generating-ssh-keys).
Open the "Git Bash" shell that was installed with "Git for Windows" in the step
above. Navigate to the directory where you want to clone rippled (git bash uses
`/c` for windows's `C:` and forward slash where windows uses backslash, so
`C:\Users\joe\projs` would be `/c/Users/joe/projs` in git bash). Now clone the
repository and optionally switch to the *master* branch. Type the following at
the bash prompt:
```powershell
git clone git@github.com:ripple/rippled.git
cd rippled
```
If you receive an error about not having the "correct access rights" make sure
you have Github ssh keys, as described above.
For a stable release, choose the `master` branch or one of the tagged releases
listed on [rippled's GitHub page](https://github.com/ripple/rippled/releases).
```
git checkout master
```
To test the latest release candidate, choose the `release` branch.
```
git checkout release
```
If you are doing development work and want the latest set of untested features,
you can consider using the `develop` branch instead.
```
git checkout develop
```
# Build using Visual Studio integrated CMake
In Visual Studio 2017, Microsoft added [integrated IDE support for
cmake](https://blogs.msdn.microsoft.com/vcblog/2016/10/05/cmake-support-in-visual-studio/).
To begin, simply:
1. Launch Visual Studio and choose **File | Open | Folder**, navigating to the
cloned rippled folder.
2. Right-click on `CMakeLists.txt` in the **Solution Explorer - Folder View** to
generate a `CMakeSettings.json` file. A sample settings file is provided
[here](/Builds/VisualStudio2017/CMakeSettings-example.json). Customize the
settings for `BOOST_ROOT`, `OPENSSL_ROOT` to match the install paths if they
differ from those in the file.
4. Select either the `x64-Release` or `x64-Debug` configuration from the
**Project Setings** drop-down. This should invoke the built-in CMake project
generator. If not, you can right-click on the `CMakeLists.txt` file and
choose **Cache | Generate Cache**.
5. Select either the `rippled.exe` (unity) or `rippled_classic.exe` (non-unity)
option in the **Select Startup Item** drop-down. This will be the target
built when you press F7. Alternatively, you can choose a target to build from
the top-level **CMake | Build** menu. Note that at this time, there are other
targets listed that come from third party visual studio files embedded in the
rippled repo, e.g. `datagen.vcxproj`. Please ignore them.
For details on configuring debugging sessions or further customization of CMake,
please refer to the [CMake tools for VS
documentation](https://docs.microsoft.com/en-us/cpp/ide/cmake-tools-for-visual-cpp).
If using the provided `CMakeSettings.json` file, the executable will be in
```
.\build\x64-Release\Release\rippled.exe
```
or
```
.\build\x64-Debug\Debug\rippled.exe
```
These paths are relative to your cloned git repository.
# Build using stand-alone CMake
This requires having installed [CMake for
Windows](README.md#optional-install-cmake-for-windows). We do not recommend
mixing this method with the integrated CMake method for the same repository
clone. Assuming you included the cmake executable folder in your path,
execute the following commands within your `rippled` cloned repository:
```
mkdir build\cmake
cd build\cmake
cmake ..\.. -G"Visual Studio 15 2017 Win64" -DBOOST_ROOT="C:\lib\boost_1_70_0" -DOPENSSL_ROOT="C:\lib\OpenSSL-Win64" -DCMAKE_GENERATOR_TOOLSET=host=x64
```
Now launch Visual Studio 2017 and select **File | Open | Project/Solution**.
Navigate to the `build\cmake` folder created above and select the `rippled.sln`
file. You can then choose whether to build the `Debug` or `Release` solution
configuration.
The executable will be in
```
.\build\cmake\Release\rippled.exe
```
or
```
.\build\cmake\Debug\rippled.exe
```
These paths are relative to your cloned git repository.
# Unity/No-Unity Builds
The rippled build system defaults to using
[unity source files](http://onqtam.com/programming/2018-07-07-unity-builds/)
to improve build times. In some cases it might be desirable to disable the
unity build and compile individual translation units. Here is how you can
switch to a "no-unity" build configuration:
## Visual Studio Integrated CMake
Edit your `CmakeSettings.json` (described above) by adding `-Dunity=OFF`
to the `cmakeCommandArgs` entry for each build configuration.
## Standalone CMake Builds
When running cmake to generate the Visual Studio project files, add
`-Dunity=OFF` to the command line options passed to cmake.
**Note:** you will need to re-run the cmake configuration step anytime you
want to switch between unity/no-unity builds.
# Unit Test (Recommended)
`rippled` builds a set of unit tests into the server executable. To run these
unit tests after building, pass the `--unittest` option to the compiled
`rippled` executable. The executable will exit with summary info after running
the unit tests.

View File

@@ -1,263 +0,0 @@
# Visual Studio 2019 Build Instructions
## Important
We do not recommend Windows for rippled production use at this time. Currently,
the Ubuntu platform has received the highest level of quality assurance,
testing, and support. Additionally, 32-bit Windows versions are not supported.
## Prerequisites
To clone the source code repository, create branches for inspection or
modification, build rippled under Visual Studio, and run the unit tests you will
need these software components
| Component | Minimum Recommended Version |
|-----------|-----------------------|
| [Visual Studio 2019](README.md#install-visual-studio-2019)| 15.5.4 |
| [Git for Windows](README.md#install-git-for-windows)| 2.16.1 |
| [OpenSSL Library](README.md#install-openssl) | 1.1.1L |
| [Boost library](README.md#build-boost) | 1.70.0 |
| [CMake for Windows](README.md#optional-install-cmake-for-windows)* | 3.12 |
\* Only needed if not using the integrated CMake in VS 2019 and prefer generating dedicated project/solution files.
## Install Software
### Install Visual Studio 2019
If not already installed on your system, download your choice of installer from
the [Visual Studio 2019
Download](https://www.visualstudio.com/downloads/download-visual-studio-vs)
page, run the installer, and follow the directions. **You may need to choose the
`Desktop development with C++` workload to install all necessary C++ features.**
Any version of Visual Studio 2019 may be used to build rippled. The **Visual
Studio 2019 Community** edition is available free of charge (see [the product
page](https://www.visualstudio.com/products/visual-studio-community-vs) for
licensing details), while paid editions may be used for an initial free-trial
period.
### Install Git for Windows
Git is a distributed revision control system. The Windows version also provides
the bash shell and many Windows versions of Unix commands. While there are other
varieties of Git (such as TortoiseGit, which has a native Windows interface and
integrates with the Explorer shell), we recommend installing [Git for
Windows](https://git-scm.com/) since it provides a Unix-like command line
environment useful for running shell scripts. Use of the bash shell under
Windows is mandatory for running the unit tests.
### Install OpenSSL
[Download the latest version of
OpenSSL.](http://slproweb.com/products/Win32OpenSSL.html) There will
several `Win64` bit variants available, you want the non-light
`v1.1` line. As of this writing, you **should** select
* Win64 OpenSSL v1.1.1q
and should **not** select
* Anything with "Win32" in the name
* Anything with "light" in the name
* Anything with "EXPERIMENTAL" in the name
* Anything in the 3.0 line - rippled won't currently build with this version.
Run the installer, and choose an appropriate location for your OpenSSL
installation. In this guide we use `C:\lib\OpenSSL-Win64` as the destination
location.
You may be informed on running the installer that "Visual C++ 2008
Redistributables" must first be installed first. If so, download it from the
[same page](http://slproweb.com/products/Win32OpenSSL.html), again making sure
to get the correct 32-/64-bit variant.
* NOTE: Since rippled links statically to OpenSSL, it does not matter where the
OpenSSL .DLL files are placed, or what version they are. rippled does not use
or require any external .DLL files to run other than the standard operating
system ones.
### Build Boost
Boost 1.70 or later is required.
[Download boost](http://www.boost.org/users/download/) and unpack it
to `c:\lib`. As of this writing, the most recent version of boost is 1.80.0,
which will unpack into a directory named `boost_1_80_0`. We recommended either
renaming this directory to `boost`, or creating a junction link `mklink /J boost
boost_1_80_0`, so that you can more easily switch between versions.
Next, open **Developer Command Prompt** and type the following commands
```powershell
cd C:\lib\boost
bootstrap
```
The rippled application is linked statically to the standard runtimes and
external dependencies on Windows, to ensure that the behavior of the executable
is not affected by changes in outside files. Therefore, it is necessary to build
the required boost static libraries using this command:
```powershell
b2 -j<Num Parallel> --toolset=msvc-14.2 address-model=64 architecture=x86 link=static threading=multi runtime-link=shared,static stage
```
where you should replace `<Num Parallel>` with the number of parallel
invocations to use build, e.g. `bjam -j8 ...` would use up to 8 concurrent build
shell commands for the build.
Building the boost libraries may take considerable time. When the build process
is completed, take note of both the reported compiler include paths and linker
library paths as they will be required later.
### (Optional) Install CMake for Windows
[CMake](http://cmake.org) is a cross platform build system generator. Visual
Studio 2019 includes an integrated version of CMake that avoids having to
manually run CMake, but it is undergoing continuous improvement. Users that
prefer to use standard Visual Studio project and solution files need to install
a dedicated version of CMake to generate them. The latest version can be found
at the [CMake download site](https://cmake.org/download/). It is recommended you
select the install option to add CMake to your path.
## Clone the rippled repository
If you are familiar with cloning github repositories, just follow your normal
process and clone `git@github.com:ripple/rippled.git`. Otherwise follow this
section for instructions.
1. If you don't have a github account, sign up for one at
[github.com](https://github.com/).
2. Make sure you have Github ssh keys. For help see
[generating-ssh-keys](https://help.github.com/articles/generating-ssh-keys).
Open the "Git Bash" shell that was installed with "Git for Windows" in the step
above. Navigate to the directory where you want to clone rippled (git bash uses
`/c` for windows's `C:` and forward slash where windows uses backslash, so
`C:\Users\joe\projs` would be `/c/Users/joe/projs` in git bash). Now clone the
repository and optionally switch to the *master* branch. Type the following at
the bash prompt:
```powershell
git clone git@github.com:XRPLF/rippled.git
cd rippled
```
If you receive an error about not having the "correct access rights" make sure
you have Github ssh keys, as described above.
For a stable release, choose the `master` branch or one of the tagged releases
listed on [rippled's GitHub page](https://github.com/ripple/rippled/releases).
```
git checkout master
```
To test the latest release candidate, choose the `release` branch.
```
git checkout release
```
If you are doing development work and want the latest set of beta features,
you can consider using the `develop` branch instead.
```
git checkout develop
```
# Build using Visual Studio integrated CMake
In Visual Studio 2017, Microsoft added [integrated IDE support for
cmake](https://blogs.msdn.microsoft.com/vcblog/2016/10/05/cmake-support-in-visual-studio/).
To begin, simply:
1. Launch Visual Studio and choose **File | Open | Folder**, navigating to the
cloned rippled folder.
2. Right-click on `CMakeLists.txt` in the **Solution Explorer - Folder View** to
generate a `CMakeSettings.json` file. A sample settings file is provided
[here](/Builds/VisualStudio2019/CMakeSettings-example.json). Customize the
settings for `BOOST_ROOT`, `OPENSSL_ROOT` to match the install paths if they
differ from those in the file.
4. Select either the `x64-Release` or `x64-Debug` configuration from the
**Project Settings** drop-down. This should invoke the built-in CMake project
generator. If not, you can right-click on the `CMakeLists.txt` file and
choose **Configure rippled**.
5. Select the `rippled.exe`
option in the **Select Startup Item** drop-down. This will be the target
built when you press F7. Alternatively, you can choose a target to build from
the top-level **CMake | Build** menu. Note that at this time, there are other
targets listed that come from third party visual studio files embedded in the
rippled repo, e.g. `datagen.vcxproj`. Please ignore them.
For details on configuring debugging sessions or further customization of CMake,
please refer to the [CMake tools for VS
documentation](https://docs.microsoft.com/en-us/cpp/ide/cmake-tools-for-visual-cpp).
If using the provided `CMakeSettings.json` file, the executable will be in
```
.\build\x64-Release\Release\rippled.exe
```
or
```
.\build\x64-Debug\Debug\rippled.exe
```
These paths are relative to your cloned git repository.
# Build using stand-alone CMake
This requires having installed [CMake for
Windows](README.md#optional-install-cmake-for-windows). We do not recommend
mixing this method with the integrated CMake method for the same repository
clone. Assuming you included the cmake executable folder in your path,
execute the following commands within your `rippled` cloned repository:
```
mkdir build\cmake
cd build\cmake
cmake ..\.. -G"Visual Studio 16 2019" -Ax64 -DBOOST_ROOT="C:\lib\boost" -DOPENSSL_ROOT="C:\lib\OpenSSL-Win64" -DCMAKE_GENERATOR_TOOLSET=host=x64
```
Now launch Visual Studio 2019 and select **File | Open | Project/Solution**.
Navigate to the `build\cmake` folder created above and select the `rippled.sln`
file. You can then choose whether to build the `Debug` or `Release` solution
configuration.
The executable will be in
```
.\build\cmake\Release\rippled.exe
```
or
```
.\build\cmake\Debug\rippled.exe
```
These paths are relative to your cloned git repository.
# Unity/No-Unity Builds
The rippled build system defaults to using
[unity source files](http://onqtam.com/programming/2018-07-07-unity-builds/)
to improve build times. In some cases it might be desirable to disable the
unity build and compile individual translation units. Here is how you can
switch to a "no-unity" build configuration:
## Visual Studio Integrated CMake
Edit your `CmakeSettings.json` (described above) by adding `-Dunity=OFF`
to the `cmakeCommandArgs` entry for each build configuration.
## Standalone CMake Builds
When running cmake to generate the Visual Studio project files, add
`-Dunity=OFF` to the command line options passed to cmake.
**Note:** you will need to re-run the cmake configuration step anytime you
want to switch between unity/no-unity builds.
# Unit Test (Recommended)
`rippled` builds a set of unit tests into the server executable. To run these
unit tests after building, pass the `--unittest` option to the compiled
`rippled` executable. The executable will exit with summary info after running
the unit tests.

View File

@@ -1,26 +1,43 @@
FROM rippleci/centos:7
FROM centos:7
ARG GIT_COMMIT=unknown
ARG CI_USE=false
LABEL git-commit=$GIT_COMMIT
COPY centos-builder/centos_setup.sh /tmp/
COPY shared/build_deps.sh /tmp/
COPY shared/install_cmake.sh /tmp/
COPY centos-builder/extras.sh /tmp/
COPY shared/install_boost.sh /tmp/
RUN chmod +x /tmp/centos_setup.sh && \
chmod +x /tmp/install_cmake.sh
chmod +x /tmp/build_deps.sh && \
chmod +x /tmp/install_boost.sh && \
chmod +x /tmp/install_cmake.sh && \
chmod +x /tmp/extras.sh
RUN /tmp/centos_setup.sh
RUN /tmp/install_cmake.sh 3.16.3 /opt/local/cmake-3.16
RUN /tmp/install_cmake.sh 3.16.1 /opt/local/cmake-3.16
RUN ln -s /opt/local/cmake-3.16 /opt/local/cmake
ENV PATH="/opt/local/cmake/bin:$PATH"
# TODO: Install latest CMake for testing
RUN if [ "${CI_USE}" = true ] ; then /tmp/install_cmake.sh 3.16.3 /opt/local/cmake-3.16; fi
# also install min supported cmake for testing
RUN if [ "${CI_USE}" = true ] ; then /tmp/install_cmake.sh 3.9.0 /opt/local/cmake-3.9; fi
RUN source scl_source enable devtoolset-7 python27 && \
/tmp/build_deps.sh
ENV BOOST_ROOT="/opt/local/boost/_INSTALLED_"
ENV PLANTUML_JAR="/opt/plantuml/plantuml.jar"
ENV OPENSSL_ROOT="/opt/local/openssl"
ENV GDB_ROOT="/opt/local/gdb"
RUN source scl_source enable devtoolset-7 python27 && \
/tmp/extras.sh
# prep files for package building
RUN mkdir -m 777 -p /opt/rippled_bld/pkg
WORKDIR /opt/rippled_bld/pkg
RUN mkdir -m 777 ./rpmbuild
RUN mkdir -m 777 ./rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
COPY packaging/rpm/build_rpm.sh ./
CMD ./build_rpm.sh

View File

@@ -7,16 +7,31 @@ yum -y upgrade
yum -y update
yum -y install epel-release centos-release-scl
yum -y install \
wget curl time gcc-c++ yum-utils autoconf automake pkgconfig libtool \
wget curl time gcc-c++ time yum-utils autoconf automake pkgconfig libtool \
libstdc++-static rpm-build gnupg which make cmake \
devtoolset-11 devtoolset-11-gdb devtoolset-11-binutils devtoolset-11-libstdc++-devel \
devtoolset-11-libasan-devel devtoolset-11-libtsan-devel devtoolset-11-libubsan-devel devtoolset-11-liblsan-devel \
devtoolset-7 devtoolset-7-gdb devtoolset-7-libasan-devel devtoolset-7-libtsan-devel devtoolset-7-libubsan-devel \
devtoolset-8 devtoolset-8-gdb devtoolset-8-binutils devtoolset-8-libstdc++-devel \
devtoolset-8-libasan-devel devtoolset-8-libtsan-devel devtoolset-8-libubsan-devel devtoolset-8-liblsan-devel \
flex flex-devel bison bison-devel parallel \
ncurses ncurses-devel ncurses-libs graphviz graphviz-devel \
lzip p7zip bzip2 bzip2-devel lzma-sdk lzma-sdk-devel xz-devel \
zlib zlib-devel zlib-static texinfo openssl openssl-static \
jemalloc jemalloc-devel \
libicu-devel htop \
rh-python38 \
python27-python rh-python35-python \
python-devel python27-python-devel rh-python35-python-devel \
python27 rh-python35 \
ninja-build git svn \
swig perl-Digest-MD5
swig perl-Digest-MD5 python2-pip
if [ "${CI_USE}" = true ] ; then
# TODO need permanent link
yum -y install ftp://ftp.pbone.net/mirror/archive.fedoraproject.org/fedora-secondary/updates/26/i386/Packages/p/python2-six-1.10.0-9.fc26.noarch.rpm
yum -y install \
llvm-toolset-7 llvm-toolset-7-runtime llvm-toolset-7-build llvm-toolset-7-clang \
llvm-toolset-7-clang-analyzer llvm-toolset-7-clang-devel llvm-toolset-7-clang-libs \
llvm-toolset-7-clang-tools-extra llvm-toolset-7-compiler-rt llvm-toolset-7-lldb \
llvm-toolset-7-lldb-devel llvm-toolset-7-python-lldb
fi

View File

@@ -0,0 +1,33 @@
#!/usr/bin/env bash
set -ex
if [ "${CI_USE}" = true ] ; then
cd /tmp
wget https://ftp.gnu.org/gnu/gdb/gdb-8.3.1.tar.xz
tar xf gdb-8.3.1.tar.xz
cd gdb-8.3
./configure CFLAGS="-w -O2" CXXFLAGS="-std=gnu++11 -g -O2 -w" --prefix=/opt/local/gdb-8.3
make -j$(nproc)
make install
ln -s /opt/local/gdb-8.3 /opt/local/gdb
cd ..
rm -f gdb-8.3.tar.xz
rm -rf gdb-8.3
# clang from source
cd /tmp
git clone https://github.com/llvm/llvm-project.git
cd llvm-project
git checkout llvmorg-9.0.0
INSTALL=/opt/llvm-9/
mkdir mybuilddir && cd mybuilddir
# TODO figure out necessary options
cmake ../llvm -G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DLLVM_ENABLE_PROJECTS='clang;clang-tools-extra;libcxx;libcxxabi;lldb;compiler-rt;lld;polly' \
-DCMAKE_INSTALL_PREFIX=${INSTALL} \
-DLLVM_LIBDIR_SUFFIX=64
cmake --build . --parallel --target install
cd /tmp
rm -rf llvm-project
fi

View File

@@ -11,10 +11,10 @@ variables:
# these containers are built manually using the rippled
# cmake build (container targets) and tagged/pushed so they
# can be used here
RPM_CONTAINER_TAG: "2023-02-13"
RPM_CONTAINER_TAG: "2020-02-10"
RPM_CONTAINER_NAME: "rippled-rpm-builder"
RPM_CONTAINER_FULLNAME: "${RPM_CONTAINER_NAME}:${RPM_CONTAINER_TAG}"
DPKG_CONTAINER_TAG: "2023-03-20"
DPKG_CONTAINER_TAG: "2020-02-10"
DPKG_CONTAINER_NAME: "rippled-dpkg-builder"
DPKG_CONTAINER_FULLNAME: "${DPKG_CONTAINER_NAME}:${DPKG_CONTAINER_TAG}"
ARTIFACTORY_HOST: "artifactory.ops.ripple.com"
@@ -83,7 +83,6 @@ stages:
#########################################################################
rpm_build:
timeout: "1h 30m"
stage: build_packages
<<: *dind_param
artifacts:
@@ -93,7 +92,6 @@ rpm_build:
- . ./Builds/containers/gitlab-ci/build_package.sh rpm
dpkg_build:
timeout: "1h 30m"
stage: build_packages
<<: *dind_param
artifacts:
@@ -181,38 +179,47 @@ centos_7_smoketest:
stage: smoketest
dependencies:
- rpm_build
- rpm_sign
image:
name: artifactory.ops.ripple.com/centos:7
<<: *run_local_smoketest
# TODO: Remove "allow_failure" when tests fixed
rocky_8_smoketest:
stage: smoketest
dependencies:
- rpm_build
- rpm_sign
image:
name: artifactory.ops.ripple.com/rockylinux/rockylinux:8
name: rockylinux/rockylinux:8
<<: *run_local_smoketest
allow_failure: true
fedora_37_smoketest:
fedora_34_smoketest:
stage: smoketest
dependencies:
- rpm_build
- rpm_sign
image:
name: artifactory.ops.ripple.com/fedora:37
name: artifactory.ops.ripple.com/fedora:34
<<: *run_local_smoketest
allow_failure: true
fedora_38_smoketest:
fedora_35_smoketest:
stage: smoketest
dependencies:
- rpm_build
- rpm_sign
image:
name: artifactory.ops.ripple.com/fedora:38
name: artifactory.ops.ripple.com/fedora:35
<<: *run_local_smoketest
allow_failure: true
ubuntu_18_smoketest:
stage: smoketest
dependencies:
- dpkg_build
- dpkg_sign
image:
name: artifactory.ops.ripple.com/ubuntu:18.04
<<: *run_local_smoketest
@@ -221,22 +228,36 @@ ubuntu_20_smoketest:
stage: smoketest
dependencies:
- dpkg_build
- dpkg_sign
image:
name: artifactory.ops.ripple.com/ubuntu:20.04
<<: *run_local_smoketest
# TODO: remove "allow_failure" when 22.04 released in 4/2022...
ubuntu_22_smoketest:
stage: smoketest
dependencies:
- dpkg_build
- dpkg_sign
image:
name: artifactory.ops.ripple.com/ubuntu:22.04
<<: *run_local_smoketest
allow_failure: true
debian_9_smoketest:
stage: smoketest
dependencies:
- dpkg_build
- dpkg_sign
image:
name: artifactory.ops.ripple.com/debian:9
<<: *run_local_smoketest
debian_10_smoketest:
stage: smoketest
dependencies:
- dpkg_build
- dpkg_sign
image:
name: artifactory.ops.ripple.com/debian:10
<<: *run_local_smoketest
@@ -245,6 +266,7 @@ debian_11_smoketest:
stage: smoketest
dependencies:
- dpkg_build
- dpkg_sign
image:
name: artifactory.ops.ripple.com/debian:11
<<: *run_local_smoketest
@@ -345,39 +367,41 @@ centos_7_verify_repo_test:
<<: *only_primary
<<: *run_repo_smoketest
rocky_8_verify_repo_test:
stage: verify_from_test
variables:
RPM_REPO: "rippled-rpm-test-mirror"
image:
name: artifactory.ops.ripple.com/rockylinux/rockylinux:8
name: rockylinux/rockylinux:8
dependencies:
- rpm_sign
<<: *only_primary
<<: *run_repo_smoketest
allow_failure: true
fedora_37_verify_repo_test:
fedora_34_verify_repo_test:
stage: verify_from_test
variables:
RPM_REPO: "rippled-rpm-test-mirror"
image:
name: artifactory.ops.ripple.com/fedora:37
name: artifactory.ops.ripple.com/fedora:34
dependencies:
- rpm_sign
<<: *only_primary
<<: *run_repo_smoketest
allow_failure: true
fedora_38_verify_repo_test:
fedora_35_verify_repo_test:
stage: verify_from_test
variables:
RPM_REPO: "rippled-rpm-test-mirror"
image:
name: artifactory.ops.ripple.com/fedora:38
name: artifactory.ops.ripple.com/fedora:35
dependencies:
- rpm_sign
<<: *only_primary
<<: *run_repo_smoketest
allow_failure: true
ubuntu_18_verify_repo_test:
stage: verify_from_test
@@ -403,6 +427,7 @@ ubuntu_20_verify_repo_test:
<<: *only_primary
<<: *run_repo_smoketest
# TODO: remove "allow_failure" when 22.04 released in 4/2022...
ubuntu_22_verify_repo_test:
stage: verify_from_test
variables:
@@ -414,6 +439,19 @@ ubuntu_22_verify_repo_test:
- dpkg_sign
<<: *only_primary
<<: *run_repo_smoketest
allow_failure: true
debian_9_verify_repo_test:
stage: verify_from_test
variables:
DISTRO: "stretch"
DEB_REPO: "rippled-deb-test-mirror"
image:
name: artifactory.ops.ripple.com/debian:9
dependencies:
- dpkg_sign
<<: *only_primary
<<: *run_repo_smoketest
debian_10_verify_repo_test:
stage: verify_from_test
@@ -504,38 +542,41 @@ centos_7_verify_repo_prod:
<<: *only_primary
<<: *run_repo_smoketest
rocky_8_verify_repo_prod:
stage: verify_from_prod
rocky_8_verify_repo_test:
stage: verify_from_test
variables:
RPM_REPO: "rippled-rpm"
RPM_REPO: "rippled-rpm-test-mirror"
image:
name: artifactory.ops.ripple.com/rockylinux/rockylinux:8
name: rockylinux/rockylinux:8
dependencies:
- rpm_sign
<<: *only_primary
<<: *run_repo_smoketest
allow_failure: true
fedora_37_verify_repo_prod:
fedora_34_verify_repo_prod:
stage: verify_from_prod
variables:
RPM_REPO: "rippled-rpm"
image:
name: artifactory.ops.ripple.com/fedora:37
name: artifactory.ops.ripple.com/fedora:34
dependencies:
- rpm_sign
<<: *only_primary
<<: *run_repo_smoketest
allow_failure: true
fedora_38_verify_repo_prod:
fedora_35_verify_repo_prod:
stage: verify_from_prod
variables:
RPM_REPO: "rippled-rpm"
image:
name: artifactory.ops.ripple.com/fedora:38
name: artifactory.ops.ripple.com/fedora:35
dependencies:
- rpm_sign
<<: *only_primary
<<: *run_repo_smoketest
allow_failure: true
ubuntu_18_verify_repo_prod:
stage: verify_from_prod
@@ -561,6 +602,7 @@ ubuntu_20_verify_repo_prod:
<<: *only_primary
<<: *run_repo_smoketest
# TODO: remove "allow_failure" when 22.04 released in 4/2022...
ubuntu_22_verify_repo_prod:
stage: verify_from_prod
variables:
@@ -572,6 +614,19 @@ ubuntu_22_verify_repo_prod:
- dpkg_sign
<<: *only_primary
<<: *run_repo_smoketest
allow_failure: true
debian_9_verify_repo_prod:
stage: verify_from_prod
variables:
DISTRO: "stretch"
DEB_REPO: "rippled-deb"
image:
name: artifactory.ops.ripple.com/debian:9
dependencies:
- dpkg_sign
<<: *only_primary
<<: *run_repo_smoketest
debian_10_verify_repo_prod:
stage: verify_from_prod
@@ -638,9 +693,11 @@ build_centos_container:
<<: *dind_param
script:
- . ./Builds/containers/gitlab-ci/build_container.sh rpm
allow_failure: true
build_ubuntu_container:
stage: build_containers
<<: *dind_param
script:
- . ./Builds/containers/gitlab-ci/build_container.sh dpkg
allow_failure: true

View File

@@ -14,17 +14,18 @@ cd $TOPDIR
cd build/dpkg/packages
CURLARGS="-sk -X${action} -urippled:${ARTIFACTORY_DEPLOY_KEY_RIPPLED}"
RIPPLED_PKG=$(ls rippled_*.deb)
RIPPLED_DEV_PKG=$(ls rippled-dev_*.deb)
RIPPLED_REPORTING_PKG=$(ls rippled-reporting_*.deb)
RIPPLED_DBG_PKG=$(ls rippled-dbgsym_*.*deb)
RIPPLED_REPORTING_DBG_PKG=$(ls rippled-reporting-dbgsym_*.*deb)
RIPPLED_DBG_PKG=$(ls rippled-dbgsym_*.deb)
RIPPLED_REPORTING_DBG_PKG=$(ls rippled-reporting-dbgsym_*.deb)
# TODO - where to upload src tgz?
RIPPLED_SRC=$(ls rippled_*.orig.tar.gz)
DEB_MATRIX=";deb.component=${COMPONENT};deb.architecture=amd64"
for dist in buster bullseye bionic focal jammy; do
for dist in stretch buster bullseye bionic focal jammy; do
DEB_MATRIX="${DEB_MATRIX};deb.distribution=${dist}"
done
echo "{ \"debs\": {" > "${TOPDIR}/files.info"
for deb in ${RIPPLED_PKG} ${RIPPLED_DBG_PKG} ${RIPPLED_REPORTING_PKG} ${RIPPLED_REPORTING_DBG_PKG}; do
for deb in ${RIPPLED_PKG} ${RIPPLED_DEV_PKG} ${RIPPLED_DBG_PKG} ${RIPPLED_REPORTING_PKG} ${RIPPLED_REPORTING_DBG_PKG}; do
# first item doesn't get a comma separator
if [ $deb != $RIPPLED_PKG ] ; then
echo "," >> "${TOPDIR}/files.info"

View File

@@ -81,10 +81,8 @@ else
elif [ "${install_from}" = "local" ] ; then
# cached pkg install
pkgs=("yum-utils openssl-static zlib-static")
if [[ "$ID" =~ rocky|fedora ]]; then
if [[ "$ID" =~ "rocky" ]]; then
sed -i 's/enabled=0/enabled=1/g' /etc/yum.repos.d/Rocky-PowerTools.repo
fi
if [ "$ID" = "rocky" ]; then
sed -i 's/enabled=0/enabled=1/g' /etc/yum.repos.d/Rocky-PowerTools.repo
pkgs="${pkgs[@]/openssl-static}"
fi
yum install -y $pkgs

View File

@@ -15,7 +15,7 @@ RIPPLED_DPKG_VERSION=$(echo "${RIPPLED_VERSION}" | sed 's!-!~!g')
# TODO - decide how to handle the trailing/release
# version here (hardcoded to 1). Does it ever need to change?
RIPPLED_DPKG_FULL_VERSION="${RIPPLED_DPKG_VERSION}-1"
git config --global --add safe.directory /opt/rippled_bld/pkg/rippled
cd /opt/rippled_bld/pkg/rippled
if [[ -n $(git status --porcelain) ]]; then
git status
@@ -45,6 +45,8 @@ CHANGELOG
# PATH must be preserved for our more modern cmake in /opt/local
# TODO : consider allowing lintian to run in future ?
export DH_BUILD_DDEBS=1
export CC=gcc-8
export CXX=g++-8
debuild --no-lintian --preserve-envvar PATH --preserve-env -us -uc
rc=$?; if [[ $rc != 0 ]]; then
error "error building dpkg"
@@ -52,6 +54,7 @@ fi
cd ..
# copy artifacts
cp rippled-dev_${RIPPLED_DPKG_FULL_VERSION}_amd64.deb ${PKG_OUTDIR}
cp rippled-reporting_${RIPPLED_DPKG_FULL_VERSION}_amd64.deb ${PKG_OUTDIR}
cp rippled_${RIPPLED_DPKG_FULL_VERSION}_amd64.deb ${PKG_OUTDIR}
cp rippled_${RIPPLED_DPKG_FULL_VERSION}.dsc ${PKG_OUTDIR}
@@ -81,12 +84,15 @@ DBG_SHA256=$(cat shasums | \
grep "rippled-dbgsym_${RIPPLED_DPKG_VERSION}-1_amd64.*" | cut -d " " -f 1)
REPORTING_DBG_SHA256=$(cat shasums | \
grep "rippled-reporting-dbgsym_${RIPPLED_DPKG_VERSION}-1_amd64.*" | cut -d " " -f 1)
DEV_SHA256=$(cat shasums | \
grep "rippled-dev_${RIPPLED_DPKG_VERSION}-1_amd64.deb" | cut -d " " -f 1)
REPORTING_SHA256=$(cat shasums | \
grep "rippled-reporting_${RIPPLED_DPKG_VERSION}-1_amd64.deb" | cut -d " " -f 1)
SRC_SHA256=$(cat shasums | \
grep "rippled_${RIPPLED_DPKG_VERSION}.orig.tar.gz" | cut -d " " -f 1)
echo "deb_sha256=${DEB_SHA256}" >> ${PKG_OUTDIR}/build_vars
echo "dbg_sha256=${DBG_SHA256}" >> ${PKG_OUTDIR}/build_vars
echo "dev_sha256=${DEV_SHA256}" >> ${PKG_OUTDIR}/build_vars
echo "reporting_sha256=${REPORTING_SHA256}" >> ${PKG_OUTDIR}/build_vars
echo "reporting_dbg_sha256=${REPORTING_DBG_SHA256}" >> ${PKG_OUTDIR}/build_vars
echo "src_sha256=${SRC_SHA256}" >> ${PKG_OUTDIR}/build_vars

View File

@@ -17,3 +17,11 @@ Architecture: any
Multi-Arch: foreign
Depends: ${misc:Depends}, ${shlibs:Depends}
Description: rippled reporting daemon
Package: rippled-dev
Section: devel
Recommends: rippled (= ${binary:Version})
Architecture: any
Multi-Arch: same
Depends: ${misc:Depends}, ${shlibs:Depends}, libprotobuf-dev, libprotoc-dev, protobuf-compiler
Description: development files for applications using xrpl core library (serialize + sign)

View File

@@ -5,4 +5,4 @@ opt/ripple/bin/getRippledInfo
opt/ripple/etc/rippled.cfg
opt/ripple/etc/validators.txt
opt/ripple/etc/update-rippled-cron
etc/logrotate.d/rippled
etc/logrotate.d/rippled

View File

@@ -16,50 +16,31 @@ override_dh_systemd_start:
override_dh_auto_configure:
env
rm -rf bld
conan export external/snappy snappy/1.1.9@
conan install . \
--install-folder bld/rippled \
--build missing \
--build boost \
--build sqlite3 \
--settings build_type=Release
cmake -DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
rm -rf bld && mkdir -p bld/rippled
cd bld/rippled && \
cmake ../.. -G Ninja \
-DCMAKE_INSTALL_PREFIX=/opt/ripple \
-Dstatic=ON \
-Dunity=OFF \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-Dvalidator_keys=ON \
-B bld/rippled
conan install . \
--install-folder bld/rippled-reporting \
--build missing \
--build boost \
--build sqlite3 \
--build libuv \
--settings build_type=Release \
--options reporting=True
cmake -DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/opt/rippled-reporting \
-Dstatic=ON \
-Dunity=OFF \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-Dreporting=ON \
-B bld/rippled-reporting
-Dvalidator_keys=ON \
-Dunity=OFF \
-DCMAKE_VERBOSE_MAKEFILE=OFF
cmake -S . \
-B bld/rippled-reporting \
-G Ninja \
-DCMAKE_INSTALL_PREFIX=/opt/rippled-reporting \
-DCMAKE_BUILD_TYPE=Release \
-Dstatic=ON \
-Dunity=OFF \
-DCMAKE_VERBOSE_MAKEFILE=OFF \
-Dreporting=ON
override_dh_auto_build:
cmake --build bld/rippled --target rippled --target validator-keys -j${nproc}
cmake --build bld/rippled-reporting --target rippled -j${nproc}
cmake --build bld/rippled --target rippled --target validator-keys --parallel
cmake --build bld/rippled-reporting --target rippled --parallel
override_dh_auto_install:
cmake --install bld/rippled --prefix debian/tmp/opt/ripple
@@ -71,10 +52,10 @@ override_dh_auto_install:
rm -rf debian/tmp/opt/ripple/lib64/cmake/date
mkdir -p debian/tmp/opt/rippled-reporting/etc
mkdir -p debian/tmp/opt/rippled-reporting/bin
cp cfg/validators-example.txt debian/tmp/opt/rippled-reporting/etc/validators.txt
install -D bld/rippled/validator-keys/validator-keys debian/tmp/opt/rippled-reporting/bin/validator-keys
sed -E 's/rippled?/rippled-reporting/g' Builds/containers/shared/update-rippled.sh > debian/tmp/opt/rippled-reporting/bin/update-rippled-reporting.sh
sed -E 's/rippled?/rippled-reporting/g' bin/getRippledInfo > debian/tmp/opt/rippled-reporting/bin/getRippledReportingInfo
sed -E 's/rippled?/rippled-reporting/g' Builds/containers/shared/update-rippled-cron > debian/tmp/opt/rippled-reporting/etc/update-rippled-reporting-cron
sed -E 's/rippled?/rippled-reporting/g' Builds/containers/shared/rippled-logrotate > debian/tmp/etc/logrotate.d/rippled-reporting
sed -E 's/rippled?/rippled-reporting/g' Builds/containers/shared/rippled-logrotate > debian/tmp/etc/logrotate.d/rippled-reporting

View File

@@ -29,20 +29,17 @@ if [[ $RPM_PATCH ]]; then
fi
cd /opt/rippled_bld/pkg/rippled
if [[ -n $(git status --porcelain) ]]; then
git status
error "Unstaged changes in this repo - please commit first"
fi
git archive --format tar.gz --prefix rippled/ -o ../rpmbuild/SOURCES/rippled.tar.gz HEAD
# TODO include validator-keys sources
cd ..
source /opt/rh/devtoolset-11/enable
source /opt/rh/devtoolset-8/enable
rpmbuild --define "_topdir ${PWD}/rpmbuild" -ba rippled.spec
rc=$?; if [[ $rc != 0 ]]; then
error "error building rpm"
fi

View File

@@ -36,64 +36,16 @@ History server for XRP Ledger
%setup -c -n rippled
%build
rm -rf ~/.conan/profiles/default
cp /opt/libcstd/libstdc++.so.6.0.22 /usr/lib64
cp /opt/libcstd/libstdc++.so.6.0.22 /lib64
ln -sf /usr/lib64/libstdc++.so.6.0.22 /usr/lib64/libstdc++.so.6
ln -sf /lib64/libstdc++.so.6.0.22 /usr/lib64/libstdc++.so.6
source /opt/rh/rh-python38/enable
pip install "conan<2"
conan profile new default --detect
conan profile update settings.compiler.libcxx=libstdc++11 default
conan profile update settings.compiler.cppstd=20 default
cd rippled
mkdir -p bld.rippled
conan export external/snappy snappy/1.1.9@
pushd bld.rippled
conan install .. \
--settings build_type=Release \
--output-folder . \
--build missing
cmake -G Ninja \
-DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake \
-DCMAKE_INSTALL_PREFIX=%{_prefix} \
-DCMAKE_BUILD_TYPE=Release \
-Dunity=OFF \
-Dstatic=ON \
-Dvalidator_keys=ON \
-DCMAKE_VERBOSE_MAKEFILE=ON \
..
cmake .. -G Ninja -DCMAKE_INSTALL_PREFIX=%{_prefix} -DCMAKE_BUILD_TYPE=Release -Dunity=OFF -Dstatic=true -DCMAKE_VERBOSE_MAKEFILE=OFF -Dvalidator_keys=ON
cmake --build . --parallel $(nproc) --target rippled --target validator-keys
popd
mkdir -p bld.rippled-reporting
pushd bld.rippled-reporting
conan install .. \
--settings build_type=Release \
--output-folder . \
--build missing \
--settings compiler.cppstd=17 \
--options reporting=True
cmake -G Ninja \
-DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake \
-DCMAKE_INSTALL_PREFIX=%{_prefix} \
-DCMAKE_BUILD_TYPE=Release \
-Dunity=OFF \
-Dstatic=ON \
-Dvalidator_keys=ON \
-Dreporting=ON \
-DCMAKE_VERBOSE_MAKEFILE=ON \
..
cd bld.rippled-reporting
cmake .. -G Ninja -DCMAKE_INSTALL_PREFIX=%{_prefix}-reporting -DCMAKE_BUILD_TYPE=Release -Dunity=OFF -Dstatic=true -DCMAKE_VERBOSE_MAKEFILE=OFF -Dreporting=ON
cmake --build . --parallel $(nproc) --target rippled
%pre
@@ -101,18 +53,13 @@ test -e /etc/pki/tls || { mkdir -p /etc/pki; ln -s /usr/lib/ssl /etc/pki/tls; }
%install
rm -rf $RPM_BUILD_ROOT
DESTDIR=$RPM_BUILD_ROOT cmake --build rippled/bld.rippled --target install #-- -v
mkdir -p $RPM_BUILD_ROOT
rm -rf ${RPM_BUILD_ROOT}/%{_prefix}/lib64/
DESTDIR=$RPM_BUILD_ROOT cmake --build rippled/bld.rippled --target install -- -v
rm -rf ${RPM_BUILD_ROOT}/%{_prefix}/lib64/cmake/date
install -d ${RPM_BUILD_ROOT}/etc/opt/ripple
install -d ${RPM_BUILD_ROOT}/usr/local/bin
install -D ./rippled/cfg/rippled-example.cfg ${RPM_BUILD_ROOT}/%{_prefix}/etc/rippled.cfg
install -D ./rippled/cfg/validators-example.txt ${RPM_BUILD_ROOT}/%{_prefix}/etc/validators.txt
ln -sf %{_prefix}/etc/rippled.cfg ${RPM_BUILD_ROOT}/etc/opt/ripple/rippled.cfg
ln -sf %{_prefix}/etc/validators.txt ${RPM_BUILD_ROOT}/etc/opt/ripple/validators.txt
ln -sf %{_prefix}/bin/rippled ${RPM_BUILD_ROOT}/usr/local/bin/rippled
ln -s %{_prefix}/etc/rippled.cfg ${RPM_BUILD_ROOT}/etc/opt/ripple/rippled.cfg
ln -s %{_prefix}/etc/validators.txt ${RPM_BUILD_ROOT}/etc/opt/ripple/validators.txt
ln -s %{_prefix}/bin/rippled ${RPM_BUILD_ROOT}/usr/local/bin/rippled
install -D rippled/bld.rippled/validator-keys/validator-keys ${RPM_BUILD_ROOT}%{_bindir}/validator-keys
install -D ./rippled/Builds/containers/shared/rippled.service ${RPM_BUILD_ROOT}/usr/lib/systemd/system/rippled.service
install -D ./rippled/Builds/containers/packaging/rpm/50-rippled.preset ${RPM_BUILD_ROOT}/usr/lib/systemd/system-preset/50-rippled.preset
@@ -194,7 +141,6 @@ chmod -x /usr/lib/systemd/system/rippled-reporting.service
%config(noreplace) /etc/logrotate.d/rippled
%config(noreplace) /usr/lib/systemd/system/rippled.service
%config(noreplace) /usr/lib/systemd/system-preset/50-rippled.preset
%dir /var/log/rippled/
%dir /var/lib/rippled/

View File

@@ -0,0 +1,147 @@
#!/usr/bin/env bash
set -ex
function build_boost()
{
local boost_ver=$1
local do_link=$2
local boost_path=$(echo "${boost_ver}" | sed -e 's!\.!_!g')
mkdir -p /opt/local
cd /opt/local
BOOST_ROOT=/opt/local/boost_${boost_path}
BOOST_URL="https://boostorg.jfrog.io/artifactory/main/release/${boost_ver}/source/boost_${boost_path}.tar.gz"
BOOST_BUILD_ALL=true
. /tmp/install_boost.sh
if [ "$do_link" = true ] ; then
ln -s ./boost_${boost_path} boost
fi
}
build_boost "1.70.0" true
# installed in opt, so won't be used
# unless specified by OPENSSL_ROOT_DIR
cd /tmp
OPENSSL_VER=1.1.1d
wget https://www.openssl.org/source/openssl-${OPENSSL_VER}.tar.gz
tar xf openssl-${OPENSSL_VER}.tar.gz
cd openssl-${OPENSSL_VER}
# NOTE: add -g to the end of the following line if we want debug symbols for openssl
SSLDIR=$(openssl version -d | cut -d: -f2 | tr -d [:space:]\")
./config -fPIC --prefix=/opt/local/openssl --openssldir=${SSLDIR} zlib shared
make -j$(nproc) >> make_output.txt 2>&1
make install >> make_output.txt 2>&1
cd ..
rm -f openssl-${OPENSSL_VER}.tar.gz
rm -rf openssl-${OPENSSL_VER}
LD_LIBRARY_PATH=${LD_LIBRARY_PATH:-}:/opt/local/openssl/lib /opt/local/openssl/bin/openssl version -a
cd /tmp
wget https://libarchive.org/downloads/libarchive-3.4.1.tar.gz
tar xzf libarchive-3.4.1.tar.gz
cd libarchive-3.4.1
mkdir _bld && cd _bld
cmake -DCMAKE_BUILD_TYPE=Release ..
make -j$(nproc) >> make_output.txt 2>&1
make install >> make_output.txt 2>&1
cd ../..
rm -f libarchive-3.4.1.tar.gz
rm -rf libarchive-3.4.1
cd /tmp
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.10.1/protobuf-all-3.10.1.tar.gz
tar xf protobuf-all-3.10.1.tar.gz
cd protobuf-3.10.1
./autogen.sh
./configure
make -j$(nproc) >> make_output.txt 2>&1
make install >> make_output.txt 2>&1
ldconfig
cd ..
rm -f protobuf-all-3.10.1.tar.gz
rm -rf protobuf-3.10.1
cd /tmp
wget https://c-ares.haxx.se/download/c-ares-1.15.0.tar.gz
tar xf c-ares-1.15.0.tar.gz
cd c-ares-1.15.0
mkdir _bld && cd _bld
cmake \
-DHAVE_LIBNSL=OFF \
-DCMAKE_BUILD_TYPE=Release \
-DCARES_STATIC=ON \
-DCARES_SHARED=OFF \
-DCARES_INSTALL=ON \
-DCARES_STATIC_PIC=ON \
-DCARES_BUILD_TOOLS=OFF \
-DCARES_BUILD_TESTS=OFF \
-DCARES_BUILD_CONTAINER_TESTS=OFF \
..
make -j$(nproc) >> make_output.txt 2>&1
make install >> make_output.txt 2>&1
cd ../..
rm -f c-ares-1.15.0.tar.gz
rm -rf c-ares-1.15.0
cd /tmp
wget https://github.com/grpc/grpc/archive/v1.25.0.tar.gz
tar xf v1.25.0.tar.gz
cd grpc-1.25.0
mkdir _bld && cd _bld
cmake \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_SHARED_LIBS=OFF \
-DgRPC_ZLIB_PROVIDER=package \
-DgRPC_CARES_PROVIDER=package \
-DgRPC_SSL_PROVIDER=package \
-DgRPC_PROTOBUF_PROVIDER=package \
-DProtobuf_USE_STATIC_LIBS=ON \
..
make -j$(nproc) >> make_output.txt 2>&1
make install >> make_output.txt 2>&1
cd ../..
rm -f xf v1.25.0.tar.gz
rm -rf grpc-1.25.0
if [ "${CI_USE}" = true ] ; then
build_boost "1.71.0" false
cd /tmp
wget https://github.com/doxygen/doxygen/archive/Release_1_8_16.tar.gz
tar xf Release_1_8_16.tar.gz
cd doxygen-Release_1_8_16
mkdir build
cd build
cmake -G "Unix Makefiles" ..
make -j$(nproc) >> make_output.txt 2>&1
make install >> make_output.txt 2>&1
cd ../..
rm -f Release_1_8_16.tar.gz
rm -rf doxygen-Release_1_8_16
mkdir -p /opt/plantuml
wget -O /opt/plantuml/plantuml.jar https://downloads.sourceforge.net/project/plantuml/plantuml.jar
cd /tmp
wget https://github.com/linux-test-project/lcov/releases/download/v1.14/lcov-1.14.tar.gz
tar xfz lcov-1.14.tar.gz
cd lcov-1.14
make install PREFIX=/usr/local
cd ..
rm -r lcov-1.14 lcov-1.14.tar.gz
cd /tmp
wget https://github.com/ccache/ccache/releases/download/v3.7.6/ccache-3.7.6.tar.gz
tar xf ccache-3.7.6.tar.gz
cd ccache-3.7.6
./configure --prefix=/usr/local
make >> make_output.txt 2>&1
make install >> make_output.txt 2>&1
cd ..
rm -f ccache-3.7.6.tar.gz
rm -rf ccache-3.7.6
pip install requests
pip install https://github.com/codecov/codecov-python/archive/master.zip
fi

View File

@@ -0,0 +1,93 @@
#!/usr/bin/env bash
# Assumptions:
# 1) BOOST_ROOT and BOOST_URL are already defined,
# and contain valid values. BOOST_URL2 may be defined
# as a fallback. BOOST_WGET_OPTIONS may be defined with
# retry options if the download(s) fail on the first try.
# 2) The last namepart of BOOST_ROOT matches the
# folder name internal to boost's .tar.gz
# When testing you can force a boost build by clearing travis caches:
# https://travis-ci.org/ripple/rippled/caches
set -exu
odir=$(pwd)
: ${BOOST_TOOLSET:=msvc-14.1}
if [[ -d "$BOOST_ROOT/lib" || -d "${BOOST_ROOT}/stage/lib" ]] ; then
echo "Using cached boost at $BOOST_ROOT"
exit
fi
#fetch/unpack:
fn=$(basename -- "$BOOST_URL")
ext="${fn##*.}"
wopt="--quiet"
wget ${wopt} $BOOST_URL -O /tmp/boost.tar.${ext} || \
( [ -n "${BOOST_URL2}" ] && \
wget ${wopt} $BOOST_URL2 -O /tmp/boost.tar.${ext} ) || \
( [ -n "${BOOST_WGET_OPTIONS}" ] &&
( wget ${wopt} ${BOOST_WGET_OPTIONS} $BOOST_URL -O /tmp/boost.tar.${ext} || \
( [ -n "${BOOST_URL2}" ] && \
wget ${wopt} ${BOOST_WGET_OPTIONS} $BOOST_URL2 -O /tmp/boost.tar.${ext} )
)
)
cd $(dirname $BOOST_ROOT)
rm -fr ${BOOST_ROOT}
mkdir ${BOOST_ROOT}
tar xf /tmp/boost.tar.${ext} -C ${BOOST_ROOT} --strip-components 1
cd $BOOST_ROOT
BLDARGS=()
if [[ ${BOOST_BUILD_ALL:-false} == "true" ]]; then
# we never need boost-python...so even for ALL
# option we can skip it
BLDARGS+=(--without-python)
else
BLDARGS+=(--with-chrono)
BLDARGS+=(--with-container)
BLDARGS+=(--with-context)
BLDARGS+=(--with-coroutine)
BLDARGS+=(--with-date_time)
BLDARGS+=(--with-filesystem)
BLDARGS+=(--with-program_options)
BLDARGS+=(--with-regex)
BLDARGS+=(--with-system)
BLDARGS+=(--with-atomic)
BLDARGS+=(--with-thread)
fi
BLDARGS+=(-j$((2*${NUM_PROCESSORS:-2})))
BLDARGS+=(--prefix=${BOOST_ROOT}/_INSTALLED_)
BLDARGS+=(-d0) # suppress messages/output
if [[ -z ${COMSPEC:-} ]]; then
if [[ "$(uname)" == "Darwin" ]] ; then
BLDARGS+=(cxxflags="-std=c++14 -fvisibility=default")
else
BLDARGS+=(cxxflags="-std=c++14")
BLDARGS+=(runtime-link="static,shared")
fi
BLDARGS+=(--layout=tagged)
./bootstrap.sh
./b2 "${BLDARGS[@]}" stage
./b2 "${BLDARGS[@]}" install
else
BLDARGS+=(runtime-link="static,shared")
BLDARGS+=(--layout=versioned)
BLDARGS+=(--toolset="${BOOST_TOOLSET}")
BLDARGS+=(address-model=64)
BLDARGS+=(architecture=x86)
BLDARGS+=(link=static)
BLDARGS+=(threading=multi)
cmd /E:ON /D /S /C"bootstrap.bat"
./b2.exe "${BLDARGS[@]}" stage
./b2.exe "${BLDARGS[@]}" install
fi
if [[ ${CI:-false} == "true" ]]; then
# save some disk space...these are mostly
# obj files and don't need to be kept in CI contexts
rm -rf bin.v2
fi
cd $odir

View File

@@ -21,13 +21,8 @@ if [[ "${installed}" != "" && ${installed} =~ ${cm_maj}.${cm_min}.${cm_rel} ]] ;
echo "cmake already installed: ${installed}"
exit
fi
# From CMake 20+ "Linux" is lowercase so using `uname` won't create be the correct path
if [ ${cm_min} -gt 19 ]; then
linux="linux"
else
linux=$(uname)
fi
pkgname="cmake-${cm_maj}.${cm_min}.${cm_rel}-${linux}-x86_64.tar.gz"
pkgname="cmake-${cm_maj}.${cm_min}.${cm_rel}-$(uname)-x86_64.tar.gz"
tmppkg="/tmp/cmake.tar.gz"
wget --quiet https://cmake.org/files/v${cm_maj}.${cm_min}/${pkgname} -O ${tmppkg}
mkdir -p ${CMAKE_ROOT}
@@ -35,3 +30,5 @@ cd ${CMAKE_ROOT}
tar --strip-components 1 -xf ${tmppkg}
rm -f ${tmppkg}
echo "installed: $(cmake_version)"

View File

@@ -4,12 +4,33 @@ ARG GIT_COMMIT=unknown
ARG CI_USE=false
LABEL git-commit=$GIT_COMMIT
WORKDIR /root
COPY ubuntu-builder/ubuntu_setup.sh .
RUN ./ubuntu_setup.sh && rm ubuntu_setup.sh
# install/setup prerequisites:
COPY ubuntu-builder/ubuntu_setup.sh /tmp/
COPY shared/build_deps.sh /tmp/
COPY shared/install_cmake.sh /tmp/
COPY shared/install_boost.sh /tmp/
RUN chmod +x /tmp/ubuntu_setup.sh && \
chmod +x /tmp/build_deps.sh && \
chmod +x /tmp/install_boost.sh && \
chmod +x /tmp/install_cmake.sh
RUN /tmp/ubuntu_setup.sh
RUN mkdir -m 777 -p /opt/rippled_bld/pkg/
RUN /tmp/install_cmake.sh 3.16.1 /opt/local/cmake-3.16
RUN ln -s /opt/local/cmake-3.16 /opt/local/cmake
ENV PATH="/opt/local/cmake/bin:$PATH"
# also install min supported cmake for testing
RUN if [ "${CI_USE}" = true ] ; then /tmp/install_cmake.sh 3.9.0 /opt/local/cmake-3.9; fi
RUN /tmp/build_deps.sh
ENV PLANTUML_JAR="/opt/plantuml/plantuml.jar"
ENV BOOST_ROOT="/opt/local/boost/_INSTALLED_"
ENV OPENSSL_ROOT="/opt/local/openssl"
# prep files for package building
RUN mkdir -m 777 -p /opt/rippled_bld/pkg/debian
RUN update-alternatives --set gcc /usr/bin/gcc-8
WORKDIR /opt/rippled_bld/pkg
COPY packaging/dpkg/build_dpkg.sh ./
CMD ./build_dpkg.sh

View File

@@ -1,76 +1,189 @@
#!/usr/bin/env bash
set -ex
set -o errexit
set -o nounset
set -o xtrace
source /etc/os-release
# Parameters
if [[ ${VERSION_ID} =~ ^18\. || ${VERSION_ID} =~ ^16\. ]] ; then
echo "setup for ${PRETTY_NAME}"
else
echo "${VERSION} not supported"
exit 1
fi
gcc_version=${GCC_VERSION:-10}
cmake_version=${CMAKE_VERSION:-3.25.1}
conan_version=${CONAN_VERSION:-1.59}
export DEBIAN_FRONTEND="noninteractive"
echo "Acquire::Retries 3;" > /etc/apt/apt.conf.d/80-retries
echo "Acquire::http::Pipeline-Depth 0;" >> /etc/apt/apt.conf.d/80-retries
echo "Acquire::http::No-Cache true;" >> /etc/apt/apt.conf.d/80-retries
echo "Acquire::BrokenProxy true;" >> /etc/apt/apt.conf.d/80-retries
apt-get update -o Acquire::CompressionTypes::Order::=gz
apt update
# Iteratively build the list of packages to install so that we can interleave
# the lines with comments explaining their inclusion.
dependencies=''
# - to identify the Ubuntu version
dependencies+=' lsb-release'
# - for add-apt-repository
dependencies+=' software-properties-common'
# - to download CMake
dependencies+=' curl'
# - to build CMake
dependencies+=' libssl-dev'
# - Python headers for Boost.Python
dependencies+=' python3-dev'
# - to install Conan
dependencies+=' python3-pip'
# - to download rippled
dependencies+=' git'
# - CMake generators (but not CMake itself)
dependencies+=' make ninja-build'
apt install --yes ${dependencies}
apt-get -y update
apt-get -y install apt-utils
apt-get -y install software-properties-common wget
apt-get -y upgrade
if [[ ${VERSION_ID} =~ ^18\. ]] ; then
apt-add-repository -y multiverse
apt-add-repository -y universe
fi
add-apt-repository -y ppa:ubuntu-toolchain-r/test
apt-get -y clean
apt-get -y update
add-apt-repository --yes ppa:ubuntu-toolchain-r/test
apt install --yes gcc-${gcc_version} g++-${gcc_version} \
debhelper debmake debsums gnupg dh-buildinfo dh-make dh-systemd cmake \
ninja-build zlib1g-dev make cmake ninja-build autoconf automake \
pkg-config apt-transport-https
apt-get -y --fix-missing install \
make cmake ninja-build autoconf automake libtool pkg-config libtool \
openssl libssl-dev \
liblzma-dev libbz2-dev zlib1g-dev \
libjemalloc-dev \
python-pip \
gdb gdbserver \
libstdc++6 \
flex bison parallel \
libicu-dev texinfo \
java-common javacc \
dpkg-dev debhelper devscripts fakeroot \
debmake git-buildpackage dh-make gitpkg debsums gnupg \
dh-buildinfo dh-make dh-systemd \
apt-transport-https
# Give us nice unversioned aliases for gcc and company.
apt-get -y install gcc-7 g++-7
update-alternatives --install \
/usr/bin/gcc gcc /usr/bin/gcc-${gcc_version} 100 \
--slave /usr/bin/g++ g++ /usr/bin/g++-${gcc_version} \
--slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-${gcc_version} \
--slave /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-${gcc_version} \
--slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-${gcc_version} \
--slave /usr/bin/gcov gcov /usr/bin/gcov-${gcc_version} \
--slave /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-dump-${gcc_version} \
--slave /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-tool-${gcc_version}
/usr/bin/gcc gcc /usr/bin/gcc-7 40 \
--slave /usr/bin/g++ g++ /usr/bin/g++-7 \
--slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-7 \
--slave /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-7 \
--slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-7 \
--slave /usr/bin/gcov gcov /usr/bin/gcov-7 \
--slave /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-dump-7 \
--slave /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-tool-7
apt-get -y install gcc-8 g++-8
update-alternatives --install \
/usr/bin/gcc gcc /usr/bin/gcc-8 20 \
--slave /usr/bin/g++ g++ /usr/bin/g++-8 \
--slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-8 \
--slave /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-8 \
--slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-8 \
--slave /usr/bin/gcov gcov /usr/bin/gcov-8 \
--slave /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-dump-8 \
--slave /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-tool-8
update-alternatives --auto gcc
# Download and unpack CMake.
cmake_slug="cmake-${cmake_version}"
curl --location --remote-name \
"https://github.com/Kitware/CMake/releases/download/v${cmake_version}/${cmake_slug}.tar.gz"
tar xzf ${cmake_slug}.tar.gz
rm ${cmake_slug}.tar.gz
update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-7 40
update-alternatives --install /usr/bin/cpp cpp /usr/bin/cpp-8 20
update-alternatives --auto cpp
# Build and install CMake.
cd ${cmake_slug}
./bootstrap --parallel=$(nproc)
make --jobs $(nproc)
make install
cd ..
rm --recursive --force ${cmake_slug}
if [ "${CI_USE}" = true ] ; then
apt-get -y install gcc-6 g++-6
update-alternatives --install \
/usr/bin/gcc gcc /usr/bin/gcc-6 10 \
--slave /usr/bin/g++ g++ /usr/bin/g++-6 \
--slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-6 \
--slave /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-6 \
--slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-6 \
--slave /usr/bin/gcov gcov /usr/bin/gcov-6 \
--slave /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-dump-6 \
--slave /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-tool-6
# Install Conan.
pip3 install conan==${conan_version}
apt-get -y install gcc-9 g++-9
update-alternatives --install \
/usr/bin/gcc gcc /usr/bin/gcc-9 15 \
--slave /usr/bin/g++ g++ /usr/bin/g++-9 \
--slave /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-9 \
--slave /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-9 \
--slave /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-9 \
--slave /usr/bin/gcov gcov /usr/bin/gcov-9 \
--slave /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-dump-9 \
--slave /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-tool-9
fi
if [[ ${VERSION_ID} =~ ^18\. ]] ; then
apt-get -y install binutils
elif [[ ${VERSION_ID} =~ ^16\. ]] ; then
apt-get -y install python-software-properties binutils-gold
fi
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
if [[ ${VERSION_ID} =~ ^18\. ]] ; then
cat << EOF > /etc/apt/sources.list.d/llvm.list
deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main
deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic main
deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-7 main
deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-7 main
deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main
deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-8 main
deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main
deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main
EOF
elif [[ ${VERSION_ID} =~ ^16\. ]] ; then
cat << EOF > /etc/apt/sources.list.d/llvm.list
deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial main
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial main
deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-7 main
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-7 main
deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-8 main
deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main
deb-src http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main
EOF
fi
apt-get -y update
apt-get -y install \
clang-7 libclang-common-7-dev libclang-7-dev libllvm7 llvm-7 \
llvm-7-dev llvm-7-runtime clang-format-7 python-clang-7 \
lld-7 libfuzzer-7-dev libc++-7-dev
update-alternatives --install \
/usr/bin/clang clang /usr/bin/clang-7 40 \
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-7 \
--slave /usr/bin/llvm-profdata llvm-profdata /usr/bin/llvm-profdata-7 \
--slave /usr/bin/asan-symbolize asan-symbolize /usr/bin/asan_symbolize-7 \
--slave /usr/bin/llvm-symbolizer llvm-symbolizer /usr/bin/llvm-symbolizer-7 \
--slave /usr/bin/clang-format clang-format /usr/bin/clang-format-7 \
--slave /usr/bin/llvm-ar llvm-ar /usr/bin/llvm-ar-7 \
--slave /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-7 \
--slave /usr/bin/llvm-nm llvm-nm /usr/bin/llvm-nm-7
apt-get -y install \
clang-8 libclang-common-8-dev libclang-8-dev libllvm8 llvm-8 \
llvm-8-dev llvm-8-runtime clang-format-8 python-clang-8 \
lld-8 libfuzzer-8-dev libc++-8-dev
update-alternatives --install \
/usr/bin/clang clang /usr/bin/clang-8 20 \
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-8 \
--slave /usr/bin/llvm-profdata llvm-profdata /usr/bin/llvm-profdata-8 \
--slave /usr/bin/asan-symbolize asan-symbolize /usr/bin/asan_symbolize-8 \
--slave /usr/bin/llvm-symbolizer llvm-symbolizer /usr/bin/llvm-symbolizer-8 \
--slave /usr/bin/clang-format clang-format /usr/bin/clang-format-8 \
--slave /usr/bin/llvm-ar llvm-ar /usr/bin/llvm-ar-8 \
--slave /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-8 \
--slave /usr/bin/llvm-nm llvm-nm /usr/bin/llvm-nm-8
update-alternatives --auto clang
if [ "${CI_USE}" = true ] ; then
apt-get -y install \
clang-9 libclang-common-9-dev libclang-9-dev libllvm9 llvm-9 \
llvm-9-dev llvm-9-runtime clang-format-9 python-clang-9 \
lld-9 libfuzzer-9-dev libc++-9-dev
update-alternatives --install \
/usr/bin/clang clang /usr/bin/clang-9 20 \
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-9 \
--slave /usr/bin/llvm-profdata llvm-profdata /usr/bin/llvm-profdata-9 \
--slave /usr/bin/asan-symbolize asan-symbolize /usr/bin/asan_symbolize-9 \
--slave /usr/bin/llvm-symbolizer llvm-symbolizer /usr/bin/llvm-symbolizer-9 \
--slave /usr/bin/clang-format clang-format /usr/bin/clang-format-9 \
--slave /usr/bin/llvm-ar llvm-ar /usr/bin/llvm-ar-9 \
--slave /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-9 \
--slave /usr/bin/llvm-nm llvm-nm /usr/bin/llvm-nm-9
# only install latest lldb
apt-get -y install lldb-9 python-lldb-9 liblldb-9-dev
update-alternatives --install \
/usr/bin/lldb lldb /usr/bin/lldb-9 50 \
--slave /usr/bin/lldb-server lldb-server /usr/bin/lldb-server-9 \
--slave /usr/bin/lldb-argdumper lldb-argdumper /usr/bin/lldb-argdumper-9 \
--slave /usr/bin/lldb-instr lldb-instr /usr/bin/lldb-instr-9 \
--slave /usr/bin/lldb-mi lldb-mi /usr/bin/lldb-mi-9
update-alternatives --auto clang
fi
apt-get -y autoremove
conan profile new --detect gcc
conan profile update settings.compiler=gcc gcc
conan profile update settings.compiler.version=${gcc_version} gcc
conan profile update settings.compiler.libcxx=libstdc++11 gcc
conan profile update env.CC=/usr/bin/gcc gcc
conan profile update env.CXX=/usr/bin/g++ gcc

View File

@@ -79,7 +79,6 @@ ripple.server > ripple.protocol
ripple.shamap > ripple.basics
ripple.shamap > ripple.beast
ripple.shamap > ripple.crypto
ripple.shamap > ripple.json
ripple.shamap > ripple.nodestore
ripple.shamap > ripple.protocol
test.app > ripple.app
@@ -113,6 +112,7 @@ test.consensus > ripple.basics
test.consensus > ripple.beast
test.consensus > ripple.consensus
test.consensus > ripple.ledger
test.consensus > ripple.rpc
test.consensus > test.csf
test.consensus > test.toplevel
test.consensus > test.unit_test
@@ -120,6 +120,7 @@ test.core > ripple.basics
test.core > ripple.beast
test.core > ripple.core
test.core > ripple.crypto
test.core > ripple.json
test.core > ripple.server
test.core > test.jtx
test.core > test.toplevel

View File

@@ -1 +1,270 @@
[Build instructions are currently located in `BUILD.md`](../../BUILD.md)
# Linux Build Instructions
This document focuses on building rippled for development purposes under recent
Ubuntu linux distributions. To build rippled for Redhat, Fedora or Centos
builds, including docker based builds for those distributions, please consult
the [rippled-package-builder](https://github.com/ripple/rippled-package-builder)
repository.
Note: Ubuntu 16.04 users may need to update their compiler (see the dependencies
section). For non Ubuntu distributions, the steps below should work be
installing the appropriate dependencies using that distribution's package
management tools.
## Dependencies
gcc-8 or later is required.
Use `apt-get` to install the dependencies provided by the distribution
```
$ apt-get update
$ apt-get install -y gcc g++ wget git cmake pkg-config libprotoc-dev protobuf-compiler libprotobuf-dev libssl-dev
```
To build the software in reporting mode, install these additional dependencies:
```
$ apt-get install -y autoconf flex bison
```
Advanced users can choose to install newer versions of gcc, or the clang compiler.
At this time, rippled only supports protobuf version 2. Using version 3 of
protobuf will give errors.
### Build Boost
Boost 1.70 or later is required. We recommend downloading and compiling boost
with the following process: After changing to the directory where
you wish to download and compile boost, run
```
$ wget https://boostorg.jfrog.io/artifactory/main/release/1.70.0/source/boost_1_70_0.tar.gz
$ tar -xzf boost_1_70_0.tar.gz
$ cd boost_1_70_0
$ ./bootstrap.sh
$ ./b2 headers
$ ./b2 -j<Num Parallel>
```
### (Optional) Dependencies for Building Source Documentation
Source code documentation is not required for running/debugging rippled. That
said, the documentation contains some helpful information about specific
components of the application. For more information on how to install and run
the necessary components, see [this document](../../docs/README.md)
## Build
### Clone the rippled repository
From a shell:
```
git clone git@github.com:ripple/rippled.git
cd rippled
```
For a stable release, choose the `master` branch or one of the tagged releases
listed on [GitHub](https://github.com/ripple/rippled/releases).
```
git checkout master
```
or to test the latest release candidate, choose the `release` branch.
```
git checkout release
```
If you are doing development work and want the latest set of untested
features, you can consider using the `develop` branch instead.
```
git checkout develop
```
### Configure Library Paths
If you didn't persistently set the `BOOST_ROOT` environment variable to the
directory in which you compiled boost, then you should set it temporarily.
For example, you built Boost in your home directory `~/boost_1_70_0`, you
would do for any shell in which you want to build:
```
export BOOST_ROOT=~/boost_1_70_0
```
Alternatively, you can add `DBOOST_ROOT=~/boost_1_70_0` to the command line when
invoking `cmake`.
### Generate Configuration
All builds should be done in a separate directory from the source tree root
(a subdirectory is fine). For example, from the root of the ripple source tree:
```
mkdir my_build
cd my_build
```
followed by:
```
cmake -DCMAKE_BUILD_TYPE=Debug ..
```
If your operating system does not provide static libraries (Arch Linux, and
Manjaro Linux, for example), you must configure a non-static build by adding
`-Dstatic=OFF` to the above cmake line.
`CMAKE_BUILD_TYPE` can be changed as desired for `Debug` vs.
`Release` builds (all four standard cmake build types are supported).
To select a different compiler (most likely gcc will be found by default), pass
`-DCMAKE_C_COMPILER=<path/to/c-compiler>` and
`-DCMAKE_CXX_COMPILER=</path/to/cxx-compiler>` when configuring. If you prefer,
you can instead set `CC` and `CXX` environment variables which cmake will honor.
#### Options During Configuration:
The CMake file defines a number of configure-time options which can be
examined by running `cmake-gui` or `ccmake` to generated the build. In
particular, the `unity` option allows you to select between the unity and
non-unity builds. `unity` builds are faster to compile since they combine
multiple sources into a single compiliation unit - this is the default if you
don't specify. `nounity` builds can be helpful for detecting include omissions
or for finding other build-related issues, but aren't generally needed for
testing and running.
* `-Dunity=ON` to enable/disable unity builds (defaults to ON)
* `-Dassert=ON` to enable asserts
* `-Djemalloc=ON` to enable jemalloc support for heap checking
* `-Dsan=thread` to enable the thread sanitizer with clang
* `-Dsan=address` to enable the address sanitizer with clang
* `-Dstatic=ON` to enable static linking library dependencies
* `-Dreporting=ON` to build code necessary for reporting mode (defaults to OFF)
Several other infrequently used options are available - run `ccmake` or
`cmake-gui` for a list of all options.
### Build
Once you have generated the build system, you can run the build via cmake:
```
cmake --build . -- -j <parallel jobs>
```
the `-j` parameter in this example tells the build tool to compile several
files in parallel. This value should be chosen roughly based on the number of
cores you have available and/or want to use for building.
When the build completes successfully, you will have a `rippled` executable in
the current directory, which can be used to connect to the network (when
properly configured) or to run unit tests.
#### Optional Installation
The rippled cmake build supports an installation target that will install
rippled as well as a support library that can be used to sign transactions. In
order to build and install the files, specify the `install` target when
building, e.g.:
```
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/opt/local ..
cmake --build . --target install -- -j <parallel jobs>
```
We recommend specifying `CMAKE_INSTALL_PREFIX` when configuring in order to
explicitly control the install location for your files. Without this setting,
cmake will typically install in `/usr/local`. It is also possible to "rehome"
the installation by specifying the `DESTDIR` env variable during the install phase,
e.g.:
```
DESTDIR=~/mylibs cmake --build . --target install -- -j <parallel jobs>
```
in which case, the files would be installed in the `CMAKE_INSTALL_PREFIX` within
the specified `DESTDIR` path.
#### Signing Library
If you want to use the signing support library to create an application, there
are two simple mechanisms with cmake + git that facilitate this.
With either option below, you will have access to a library from the
rippled project that you can link to in your own project's CMakeLists.txt, e.g.:
```
target_link_libraries (my-signing-app Ripple::xrpl_core)
```
##### Option 1: git submodules + add_subdirectory
First, add the rippled repo as a submodule to your project repo:
```
git submodule add -b master https://github.com/ripple/rippled.git vendor/rippled
```
change the `vendor/rippled` path as desired for your repo layout. Furthermore,
change the branch name if you want to track a different rippled branch, such
as `develop`.
Second, to bring this submodule into your project, just add the rippled subdirectory:
```
add_subdirectory (vendor/rippled)
```
##### Option 2: installed rippled + find_package
First, follow the "Optional Installation" instructions above to
build and install the desired version of rippled.
To make use of the installed files, add the following to your CMakeLists.txt file:
```
set (CMAKE_MODULE_PATH /opt/local/lib/cmake/ripple ${CMAKE_MODULE_PATH})
find_package(Ripple REQUIRED)
```
change the `/opt/local` module path above to match your chosen installation prefix.
## Unit Tests (Recommended)
`rippled` builds a set of unit tests into the server executable. To run these unit
tests after building, pass the `--unittest` option to the compiled `rippled`
executable. The executable will exit with summary info after running the unit tests.
## Workaround for a compile error in soci
Compilation errors have been observed with Apple Clang 13.1.6+ and soci v4.x. soci compiles with the `-Werror` flag which causes warnings to be treated as errors. These warnings pertain to style (not correctness). However, they cause the cmake process to fail.
Here's an example of how this looks:
```
.../rippled/.nih_c/unix_makefiles/AppleClang_13.1.6.13160021/Debug/src/soci/src/core/session.cpp:450:66: note: in instantiation of function template specialization 'soci::use<std::string>' requested here
return prepare << backEnd_->get_column_descriptions_query(), use(table_name, "t");
^
1 error generated.
```
Please apply the below patch (courtesy of Scott Determan) to remove these errors. `.nih_c/unix_makefiles/AppleClang_13.1.6.13160021/Debug/src/soci/cmake/SociConfig.cmake` file needs to be edited. This file is an example for Mac OS and it might be slightly different for other OS/Architectures.
```
diff --git a/cmake/SociConfig.cmake b/cmake/SociConfig.cmake
index 97d907e4..11bcd1f3 100644
--- a/cmake/SociConfig.cmake
+++ b/cmake/SociConfig.cmake
@@ -58,8 +58,8 @@ if (MSVC)
else()
- set(SOCI_GCC_CLANG_COMMON_FLAGS
- "-pedantic -Werror -Wno-error=parentheses -Wall -Wextra -Wpointer-arith -Wcast-align -Wcast-qual -Wfloat-equal -Woverloaded-virtual -Wredundant-decls -Wno-long-long")
+ set(SOCI_GCC_CLANG_COMMON_FLAGS "")
+ # "-pedantic -Werror -Wno-error=parentheses -Wall -Wextra -Wpointer-arith -Wcast-align -Wcast-qual -Wfloat-equal -Woverloaded-virtual -Wredundant-decls -Wno-long-long")
```

View File

@@ -1 +1,3 @@
[Build instructions are currently located in `BUILD.md`](../../BUILD.md)
# macOS Build Instructions
[Build and Run rippled on macOS](https://xrpl.org/build-run-rippled-macos.html)

View File

@@ -83,5 +83,4 @@ include(RippledCore)
include(RippledInstall)
include(RippledCov)
include(RippledMultiConfig)
include(RippledDocs)
include(RippledValidatorKeys)

View File

@@ -58,7 +58,7 @@ Existing maintainers can resign, or be subject to a vote for removal at the behe
* [JoelKatz](https://github.com/JoelKatz) (Ripple)
* [Manojsdoshi](https://github.com/manojsdoshi) (Ripple)
* [N3tc4t](https://github.com/n3tc4t) (XRPL Labs)
* [Nikolaos D Bougalis](https://github.com/nbougalis)
* [Nikolaos D Bougalis](https://github.com/nbougalis) (Ripple)
* [Nixer89](https://github.com/nixer89) (XRP Ledger Foundation)
* [RichardAH](https://github.com/RichardAH) (XRPL Labs + XRP Ledger Foundation)
* [Seelabs](https://github.com/seelabs) (Ripple)

View File

@@ -1,3 +1,63 @@
# The Xahau Ledger
# Hooks Public Testnet + Documentation
TODO: Doco
Please see [Hooks Testnet V2](https://hooks-testnet-v2.xrpl-labs.com/) for faucet + documentation + explorer + builder.
# The XRP Ledger
The [XRP Ledger](https://xrpl.org/) is a decentralized cryptographic ledger powered by a network of peer-to-peer nodes. The XRP Ledger uses a novel Byzantine Fault Tolerant consensus algorithm to settle and record transactions in a secure distributed database without a central operator.
## XRP
[XRP](https://xrpl.org/xrp.html) is a public, counterparty-free asset native to the XRP Ledger, and is designed to bridge the many different currencies in use worldwide. XRP is traded on the open-market and is available for anyone to access. The XRP Ledger was created in 2012 with a finite supply of 100 billion units of XRP. Its creators gifted 80 billion XRP to a company, now called [Ripple](https://ripple.com/), to develop the XRP Ledger and its ecosystem. Ripple uses XRP to help build the Internet of Value, ushering in a world in which money moves as fast and efficiently as information does today.
## rippled
The server software that powers the XRP Ledger is called `rippled` and is available in this repository under the permissive [ISC open-source license](LICENSE.md). The `rippled` server software is written primarily in C++ and runs on a variety of platforms. The `rippled` server software can run in several modes depending on its [configuration](https://xrpl.org/rippled-server-modes.html).
### Build from Source
* [Linux](Builds/linux/README.md)
* [Mac](Builds/macos/README.md) (Not recommended for production)
* [Windows](Builds/VisualStudio2017/README.md) (Not recommended for production)
## Key Features of the XRP Ledger
- **[Censorship-Resistant Transaction Processing][]:** No single party decides which transactions succeed or fail, and no one can "roll back" a transaction after it completes. As long as those who choose to participate in the network keep it healthy, they can settle transactions in seconds.
- **[Fast, Efficient Consensus Algorithm][]:** The XRP Ledger's consensus algorithm settles transactions in 4 to 5 seconds, processing at a throughput of up to 1500 transactions per second. These properties put XRP at least an order of magnitude ahead of other top digital assets.
- **[Finite XRP Supply][]:** When the XRP Ledger began, 100 billion XRP were created, and no more XRP will ever be created. The available supply of XRP decreases slowly over time as small amounts are destroyed to pay transaction costs.
- **[Responsible Software Governance][]:** A team of full-time, world-class developers at Ripple maintain and continually improve the XRP Ledger's underlying software with contributions from the open-source community. Ripple acts as a steward for the technology and an advocate for its interests, and builds constructive relationships with governments and financial institutions worldwide.
- **[Secure, Adaptable Cryptography][]:** The XRP Ledger relies on industry standard digital signature systems like ECDSA (the same scheme used by Bitcoin) but also supports modern, efficient algorithms like Ed25519. The extensible nature of the XRP Ledger's software makes it possible to add and disable algorithms as the state of the art in cryptography advances.
- **[Modern Features for Smart Contracts][]:** Features like Escrow, Checks, and Payment Channels support cutting-edge financial applications including the [Interledger Protocol](https://interledger.org/). This toolbox of advanced features comes with safety features like a process for amending the network and separate checks against invariant constraints.
- **[On-Ledger Decentralized Exchange][]:** In addition to all the features that make XRP useful on its own, the XRP Ledger also has a fully-functional accounting system for tracking and trading obligations denominated in any way users want, and an exchange built into the protocol. The XRP Ledger can settle long, cross-currency payment paths and exchanges of multiple currencies in atomic transactions, bridging gaps of trust with XRP.
[Censorship-Resistant Transaction Processing]: https://xrpl.org/xrp-ledger-overview.html#censorship-resistant-transaction-processing
[Fast, Efficient Consensus Algorithm]: https://xrpl.org/xrp-ledger-overview.html#fast-efficient-consensus-algorithm
[Finite XRP Supply]: https://xrpl.org/xrp-ledger-overview.html#finite-xrp-supply
[Responsible Software Governance]: https://xrpl.org/xrp-ledger-overview.html#responsible-software-governance
[Secure, Adaptable Cryptography]: https://xrpl.org/xrp-ledger-overview.html#secure-adaptable-cryptography
[Modern Features for Smart Contracts]: https://xrpl.org/xrp-ledger-overview.html#modern-features-for-smart-contracts
[On-Ledger Decentralized Exchange]: https://xrpl.org/xrp-ledger-overview.html#on-ledger-decentralized-exchange
## Source Code
[![travis-ci.com: Build Status](https://travis-ci.com/ripple/rippled.svg?branch=develop)](https://travis-ci.com/ripple/rippled)
[![codecov.io: Code Coverage](https://codecov.io/gh/ripple/rippled/branch/develop/graph/badge.svg)](https://codecov.io/gh/ripple/rippled)
### Repository Contents
| Folder | Contents |
|:-----------|:-------------------------------------------------|
| `./bin` | Scripts and data files for Ripple integrators. |
| `./Builds` | Platform-specific guides for building `rippled`. |
| `./docs` | Source documentation files and doxygen config. |
| `./cfg` | Example configuration files. |
| `./src` | Source code. |
Some of the directories under `src` are external repositories included using
git-subtree. See those directories' README files for more details.
## See Also
* [XRP Ledger Dev Portal](https://xrpl.org/)
* [Setup and Installation](https://xrpl.org/install-rippled.html)
* [Source Documentation (Doxygen)](https://xrplf.github.io/rippled/)
* [Learn more about the XRP Ledger (YouTube)](https://www.youtube.com/playlist?list=PLJQ55Tj1hIVZtJ_JdTvSum2qMTsedWkNi)

View File

@@ -5,255 +5,7 @@
This document contains the release notes for `rippled`, the reference server implementation of the XRP Ledger protocol. To learn more about how to build, run or update a `rippled` server, visit https://xrpl.org/install-rippled.html
Have new ideas? Need help with setting up your node? [Please open an issue here](https://github.com/xrplf/rippled/issues/new/choose).
# Introducing XRP Ledger version 1.10.1
Version 1.10.1 of `rippled`, the reference server implementation of the XRP Ledger protocol, is now available. This release restores packages for Ubuntu 18.04.
Compared to version 1.10.0, the only C++ code change fixes an edge case in Reporting Mode.
If you are already running version 1.10.0, then upgrading to version 1.10.1 is generally not required.
[Sign Up for Future Release Announcements](https://groups.google.com/g/ripple-server)
<!-- BREAK -->
## Install / Upgrade
On supported platforms, see the [instructions on installing or updating `rippled`](https://xrpl.org/install-rippled.html).
## Changelog
- [`da18c86cbf`](https://github.com/ripple/rippled/commit/da18c86cbfea1d8fe6940035f9103e15890d47ce) Build packages with Ubuntu 18.04
- [`f7b3ddd87b`](https://github.com/ripple/rippled/commit/f7b3ddd87b8ef093a06ab1420bea57ed1e77643a) Reporting Mode: Do not attempt to acquire missing data from peer network (#4458)
### GitHub
The public source code repository for `rippled` is hosted on GitHub at <https://github.com/XRPLF/rippled>.
We welcome all contributions and invite everyone to join the community of XRP Ledger developers to help build the Internet of Value.
### Credits
The following people contributed directly to this release:
- John Freeman <jfreeman08@gmail.com>
- Mark Travis <mtrippled@users.noreply.github.com>
- Michael Legleux <mlegleux@ripple.com>
Bug Bounties and Responsible Disclosures:
We welcome reviews of the rippled code and urge researchers to
responsibly disclose any issues they may find.
To report a bug, please send a detailed report to:
bugs@xrpl.org
# Introducing XRP Ledger version 1.10.0
Version 1.10.0 of `rippled`, the reference server implementation of the XRP Ledger protocol, is now available. This release introduces six new amendments, detailed below, and cleans up code to improve performance.
[Sign Up for Future Release Announcements](https://groups.google.com/g/ripple-server)
<!-- BREAK -->
## Action Required
Six new amendments are now open for voting according to the XRP Ledger's [amendment process](https://xrpl.org/amendments.html), which enables protocol changes following two weeks of >80% support from trusted validators.
If you operate an XRP Ledger server, upgrade to version 1.10.0 by March 21 to ensure service continuity. The exact time that protocol changes take effect depends on the voting decisions of the decentralized network.
## Install / Upgrade
On supported platforms, see the [instructions on installing or updating `rippled`](https://xrpl.org/install-rippled.html).
## New Amendments
- **`featureImmediateOfferKilled`**: Changes the response code of an `OfferCreate` transaction with the `tfImmediateOrCancel` flag to return `tecKILLED` when no funds are moved. The previous return code of `tecSUCCESS` was unintuitive. [#4157](https://github.com/XRPLF/rippled/pull/4157)
- **`featureDisallowIncoming`**: Enables an account to block incoming checks, payment channels, NFToken offers, and trust lines. [#4336](https://github.com/XRPLF/rippled/pull/4336)
- **`featureXRPFees`**: Simplifies transaction cost calculations to use XRP directly, rather than calculating indirectly in "fee units" and translating the results to XRP. Updates all instances of "fee units" in the protocol and ledger data to be drops of XRP instead. [#4247](https://github.com/XRPLF/rippled/pull/4247)
- **`fixUniversalNumber`**: Simplifies and unifies the code for decimal floating point math. In some cases, this provides slightly better accuracy than the previous code, resulting in calculations whose least significant digits are different than when calculated with the previous code. The different results may cause other edge case differences where precise calculations are used, such as ranking of offers or processing of payments that use several different paths. [#4192](https://github.com/XRPLF/rippled/pull/4192)
- **`fixNonFungibleTokensV1_2`**: This amendment is a combination of NFToken fixes. [#4417](https://github.com/XRPLF/rippled/pull/4417)
- Fixes unburnable NFTokens when it has over 500 offers. [#4346](https://github.com/XRPLF/rippled/pull/4346)
- Fixes 3 NFToken offer acceptance issues. [#4380](https://github.com/XRPLF/rippled/pull/4380)
- Prevents brokered sales of NFTokens to owners. [#4403](https://github.com/XRPLF/rippled/pull/4403)
- Only allows the destination to settle NFToken offers through brokerage. [#4399](https://github.com/XRPLF/rippled/pull/4399)
- **`fixTrustLinesToSelf`**: Trust lines must be between two different accounts, but two exceptions exist because of a bug that briefly existed. This amendment removes those trust lines. [69bb2be](https://github.com/XRPLF/rippled/pull/4270/commits/69bb2be446e3cc24c694c0835b48bd2ecd3d119e)
## Changelog
### New Features and Improvements
- **Improve Handshake in the peer protocol**: Switched to using a cryptographically secure PRNG for the Instance Cookie. `rippled` now uses hex encoding for the `Closed-Ledger` and `Previous-Ledger` fields in the Handshake. Also added `--newnodeid` and `--nodeid` command line options. [5a15229](https://github.com/XRPLF/rippled/pull/4270/commits/5a15229eeb13b69c8adf1f653b88a8f8b9480546)
- **RPC tooBusy response now has 503 HTTP status code**: Added ripplerpc 3.0, enabling RPC tooBusy responses to return relevant HTTP status codes. This is a non-breaking change that only applies to JSON-RPC when you include `"ripplerpc": "3.0"` in the request. [#4143](https://github.com/XRPLF/rippled/pull/4143)
- **Use the Conan package manager**: Added a `conanfile.py` and Conan recipe for Snappy. Removed the RocksDB recipe from the repo; you can now get it from Conan Center. [#4367](https://github.com/XRPLF/rippled/pull/4367), [c2b03fe](https://github.com/XRPLF/rippled/commit/c2b03fecca19a304b37467b01fa78593d3dce3fb)
- **Update Build Instructions**: Updated the build instructions to build with the Conan package manager and restructured info for easier comprehension. [#4376](https://github.com/XRPLF/rippled/pull/4376), [#4383](https://github.com/XRPLF/rippled/pull/4383)
- **Revise CONTRIBUTING**: Updated code contribution guidelines. `rippled` is an open source project and contributions are very welcome. [#4382](https://github.com/XRPLF/rippled/pull/4382)
- **Update documented pathfinding configuration defaults**: `417cfc2` changed the default Path Finding configuration values, but missed updating the values documented in rippled-example.cfg. Updated those defaults and added recommended values for nodes that want to support advanced pathfinding. [#4409](https://github.com/XRPLF/rippled/pull/4409)
- **Remove gRPC code previously used for the Xpring SDK**: Removed gRPC code used for the Xpring SDK. The gRPC API is also enabled locally by default in `rippled-example.cfg`. This API is used for [Reporting Mode](https://xrpl.org/build-run-rippled-in-reporting-mode.html) and [Clio](https://github.com/XRPLF/clio). [28f4cc7](https://github.com/XRPLF/rippled/pull/4321/commits/28f4cc7817c2e477f0d7e9ade8f07a45ff2b81f1)
- **Switch from C++17 to C++20**: Updated `rippled` to use C++20. [92d35e5](https://github.com/XRPLF/rippled/pull/4270/commits/92d35e54c7de6bbe44ff6c7c52cc0765b3f78258)
- **Support for Boost 1.80.0:**: [04ef885](https://github.com/XRPLF/rippled/pull/4321/commits/04ef8851081f6ee9176783ad3725960b8a931ebb)
- **Reduce default reserves to 10/2**: Updated the hard-coded default reserves to match the current settings on Mainnet. [#4329](https://github.com/XRPLF/rippled/pull/4329)
- **Improve self-signed certificate generation**: Improved speed and security of TLS certificate generation on fresh startup. [0ecfc7c](https://github.com/XRPLF/rippled/pull/4270/commits/0ecfc7cb1a958b731e5f184876ea89ae2d4214ee)
### Bug Fixes
- **Update command-line usage help message**: Added `manifest` and `validator_info` to the `rippled` CLI usage statement. [b88ed5a](https://github.com/XRPLF/rippled/pull/4270/commits/b88ed5a8ec2a0735031ca23dc6569d54787dc2f2)
- **Work around gdb bug by changing a template parameter**: Added a workaround for a bug in gdb, where unsigned template parameters caused issues with RTTI. [#4332](https://github.com/XRPLF/rippled/pull/4332)
- **Fix clang 15 warnings**: [#4325](https://github.com/XRPLF/rippled/pull/4325)
- **Catch transaction deserialization error in doLedgerGrpc**: Fixed an issue in the gRPC API, so `Clio` can extract ledger headers and state objects from specific transactions that can't be deserialized by `rippled` code. [#4323](https://github.com/XRPLF/rippled/pull/4323)
- **Update dependency: gRPC**: New Conan recipes broke the old version of gRPC, so the dependency was updated. [#4407](https://github.com/XRPLF/rippled/pull/4407)
- **Fix Doxygen workflow**: Added options to build documentation that don't depend on the library dependencies of `rippled`. [#4372](https://github.com/XRPLF/rippled/pull/4372)
- **Don't try to read SLE with key 0 from the ledger**: Fixed the `preclaim` function to check for 0 in `NFTokenSellOffer` and `NFTokenBuyOffer` before calling `Ledger::read`. This issue only affected debug builds. [#4351](https://github.com/XRPLF/rippled/pull/4351)
- **Update broken link to hosted Doxygen content**: [5e1cb09](https://github.com/XRPLF/rippled/pull/4270/commits/5e1cb09b8892e650f6c34a66521b6b1673bd6b65)
### Code Cleanup
- **Prevent unnecessary `shared_ptr` copies by accepting a value in `SHAMapInnerNode::setChild`**: [#4266](https://github.com/XRPLF/rippled/pull/4266)
- **Release TaggedCache object memory outside the lock**: [3726f8b](https://github.com/XRPLF/rippled/pull/4321/commits/3726f8bf31b3eab8bab39dce139656fd705ae9a0)
- **Rename SHAMapStoreImp::stopping() to healthWait()**: [7e9e910](https://github.com/XRPLF/rippled/pull/4321/commits/7e9e9104eabbf0391a0837de5630af17a788e233)
- **Improve wrapper around OpenSSL RAND**: [7b3507b](https://github.com/XRPLF/rippled/pull/4270/commits/7b3507bb873495a974db33c57a888221ddabcacc)
- **Improve AccountID string conversion caching**: Improved memory cache usage. [e2eed96](https://github.com/XRPLF/rippled/pull/4270/commits/e2eed966b0ecb6445027e6a023b48d702c5f4832)
- **Build the command map at compile time**: [9aaa0df](https://github.com/XRPLF/rippled/pull/4270/commits/9aaa0dff5fd422e5f6880df8e20a1fd5ad3b4424)
- **Avoid unnecessary copying and dynamic memory allocations**: [d318ab6](https://github.com/XRPLF/rippled/pull/4270/commits/d318ab612adc86f1fd8527a50af232f377ca89ef)
- **Use constexpr to check memo validity**: [e67f905](https://github.com/XRPLF/rippled/pull/4270/commits/e67f90588a9050162881389d7e7d1d0fb31066b0)
- **Remove charUnHex**: [83ac141](https://github.com/XRPLF/rippled/pull/4270/commits/83ac141f656b1a95b5661853951ebd95b3ffba99)
- **Remove deprecated AccountTxOld.cpp**: [ce64f7a](https://github.com/XRPLF/rippled/pull/4270/commits/ce64f7a90f99c6b5e68d3c3d913443023de061a6)
- **Remove const_cast usage**: [23ce431](https://github.com/XRPLF/rippled/pull/4321/commits/23ce4318768b718c82e01004d23f1abc9a9549ff)
- **Remove inaccessible code paths and outdated data format wchar_t**: [95fabd5](https://github.com/XRPLF/rippled/pull/4321/commits/95fabd5762a4917753c06268192e4d4e4baef8e4)
- **Improve move semantics in Expected**: [#4326](https://github.com/XRPLF/rippled/pull/4326)
### GitHub
The public source code repository for `rippled` is hosted on GitHub at <https://github.com/XRPLF/rippled>.
We welcome all contributions and invite everyone to join the community of XRP Ledger developers to help build the Internet of Value.
### Credits
The following people contributed directly to this release:
- Alexander Kremer <akremer@ripple.com>
- Alloy Networks <45832257+alloynetworks@users.noreply.github.com>
- CJ Cobb <46455409+cjcobb23@users.noreply.github.com>
- Chenna Keshava B S <ckbs.keshava56@gmail.com>
- Crypto Brad Garlinghouse <cryptobradgarlinghouse@protonmail.com>
- Denis Angell <dangell@transia.co>
- Ed Hennis <ed@ripple.com>
- Elliot Lee <github.public@intelliot.com>
- Gregory Popovitch <greg7mdp@gmail.com>
- Howard Hinnant <howard.hinnant@gmail.com>
- J. Scott Branson <18340247+crypticrabbit@users.noreply.github.com>
- John Freeman <jfreeman08@gmail.com>
- ledhed2222 <ledhed2222@users.noreply.github.com>
- Levin Winter <33220502+levinwinter@users.noreply.github.com>
- manojsdoshi <mdoshi@ripple.com>
- Nik Bougalis <nikb@bougalis.net>
- RichardAH <richard.holland@starstone.co.nz>
- Scott Determan <scott.determan@yahoo.com>
- Scott Schurr <scott@ripple.com>
- Shawn Xie <35279399+shawnxie999@users.noreply.github.com>
Security Bug Bounty Acknowledgements:
- Aaron Hook
- Levin Winter
Bug Bounties and Responsible Disclosures:
We welcome reviews of the rippled code and urge researchers to
responsibly disclose any issues they may find.
To report a bug, please send a detailed report to:
bugs@xrpl.org
# Introducing XRP Ledger version 1.9.4
Version 1.9.4 of `rippled`, the reference implementation of the XRP Ledger protocol is now available. This release introduces an amendment that removes the ability for an NFT issuer to indicate that trust lines should be automatically created for royalty payments from secondary sales of NFTs, in response to a bug report that indicated how this functionality could be abused to mount a denial of service attack against the issuer.
## Action Required
This release introduces a new amendment to the XRP Ledger protocol, **`fixRemoveNFTokenAutoTrustLine`** to mitigate a potential denial-of-service attack against NFT issuers that minted NFTs and allowed secondary trading of those NFTs to create trust lines for any asset.
This amendment is open for voting according to the XRP Ledger's [amendment process](https://xrpl.org/amendments.html), which enables protocol changes following two weeks of >80% support from trusted validators.
If you operate an XRP Ledger server, then you should upgrade to version 1.9.4 within two weeks, to ensure service continuity. The exact time that protocol changes take effect depends on the voting decisions of the decentralized network.
For more information about NFTs on the XRP Ledger, see [NFT Conceptual Overview](https://xrpl.org/nft-conceptual-overview.html).
## Install / Upgrade
On supported platforms, see the [instructions on installing or updating `rippled`](https://xrpl.org/install-rippled.html).
## Changelog
## Contributions
The primary change in this release is the following bug fix:
- **Introduce fixRemoveNFTokenAutoTrustLine amendment**: Introduces the `fixRemoveNFTokenAutoTrustLine` amendment, which disables the `tfTrustLine` flag, which a malicious attacker could exploit to mount denial-of-service attacks against NFT issuers that specified the flag on their NFTs. ([#4301](https://github.com/XRPLF/rippled/4301))
### GitHub
The public source code repository for `rippled` is hosted on GitHub at <https://github.com/XRPLF/rippled>.
We welcome all contributions and invite everyone to join the community of XRP Ledger developers and help us build the Internet of Value.
### Credits
The following people contributed directly to this release:
- Scott Schurr <scott@ripple.com>
- Howard Hinnant <howard@ripple.com>
- Scott Determan <scott.determan@yahoo.com>
- Ikko Ashimine <eltociear@gmail.com>
Have new ideas? Need help with setting up your node? Come visit us [here](https://github.com/xrplf/rippled/issues/new/choose)
# Introducing XRP Ledger version 1.9.3
@@ -267,7 +19,7 @@ On supported platforms, see the [instructions on installing or updating `rippled
## Contributions
This release contains the following bug fixes:
This releases contains the following bug fixes:
- **Change by-value to by-reference to persist vote**: A minor technical flaw, caused by use of a copy instead of a reference, resulted in operator-configured "yes" votes to not be properly loaded after a restart. ([#4256](https://github.com/XRPLF/rippled/pull/4256))
- **Properly handle self-assignment of PublicKey**: The `PublicKey` copy assignment operator mishandled the case where a `PublicKey` would be assigned to itself, and could result in undefined behavior.

View File

@@ -1,61 +0,0 @@
#!/bin/bash
echo "START INSIDE CONTAINER - CORE"
echo "-- BUILD CORES: $3"
echo "-- GITHUB_REPOSITORY: $1"
echo "-- GITHUB_SHA: $2"
echo "-- GITHUB_RUN_NUMBER: $4"
umask 0000;
cd /io/ &&
echo "Importing env... Lines:" &&
cat .env|wc -l &&
source .env &&
perl -i -pe "s/^(\\s*)-DBUILD_SHARED_LIBS=OFF/\\1-DBUILD_SHARED_LIBS=OFF\\n\\1-DROCKSDB_BUILD_SHARED=OFF/g" Builds/CMake/deps/Rocksdb.cmake &&
mv Builds/CMake/deps/WasmEdge.cmake Builds/CMake/deps/WasmEdge.old &&
echo "find_package(LLVM REQUIRED CONFIG)
message(STATUS \"Found LLVM ${LLVM_PACKAGE_VERSION}\")
message(STATUS \"Using LLVMConfig.cmake in: \${LLVM_DIR}\")
add_library (wasmedge STATIC IMPORTED GLOBAL)
set_target_properties(wasmedge PROPERTIES IMPORTED_LOCATION \${WasmEdge_LIB})
target_link_libraries (ripple_libs INTERFACE wasmedge)
add_library (NIH::WasmEdge ALIAS wasmedge)
message(\"WasmEdge DONE\")
" > Builds/CMake/deps/WasmEdge.cmake &&
git checkout src/ripple/protocol/impl/BuildInfo.cpp &&
sed -i s/\"0.0.0\"/\"$(date +%Y).$(date +%-m).$(date +%-d)-$(git rev-parse --abbrev-ref HEAD)+$4\"/g src/ripple/protocol/impl/BuildInfo.cpp &&
cd release-build &&
cmake .. -DCMAKE_BUILD_TYPE=Release -DBoost_NO_BOOST_CMAKE=ON -DLLVM_DIR=/usr/lib64/llvm13/lib/cmake/llvm/ -DLLVM_LIBRARY_DIR=/usr/lib64/llvm13/lib/ -DWasmEdge_LIB=/usr/local/lib64/libwasmedge.a &&
make -j$3 VERBOSE=1 &&
strip -s rippled &&
mv rippled xahaud &&
echo "Build host: `hostname`" > release.info &&
echo "Build date: `date`" >> release.info &&
echo "Build md5: `md5sum xahaud`" >> release.info &&
echo "Git remotes:" >> release.info &&
git remote -v >> release.info
echo "Git status:" >> release.info &&
git status -v >> release.info &&
echo "Git log [last 20]:" >> release.info &&
git log -n 20 >> release.info;
if [[ "$4" == "" ]]; then
# Non GH, local building
echo "Non GH, local building, no Action runner magic"
else
# GH Action, runner
cp /io/release-build/xahaud /data/builds/$(date +%Y).$(date +%-m).$(date +%-d)-$(git rev-parse --abbrev-ref HEAD)+$4
cp /io/release-build/release.info /data/builds/$(date +%Y).$(date +%-m).$(date +%-d)-$(git rev-parse --abbrev-ref HEAD)+$4.releaseinfo
echo "Published build to: http://build.xahau.tech/"
echo $(date +%Y).$(date +%-m).$(date +%-d)-$(git rev-parse --abbrev-ref HEAD)+$4
fi
cd ..;
mv src/ripple/net/impl/RegisterSSLCerts.cpp.old src/ripple/net/impl/RegisterSSLCerts.cpp;
mv Builds/CMake/deps/Rocksdb.cmake.old Builds/CMake/deps/Rocksdb.cmake;
mv Builds/CMake/deps/WasmEdge.old Builds/CMake/deps/WasmEdge.cmake;
echo "END INSIDE CONTAINER - CORE"

View File

@@ -1,159 +0,0 @@
#!/bin/bash
echo "START INSIDE CONTAINER - FULL"
echo "-- BUILD CORES: $3"
echo "-- GITHUB_REPOSITORY: $1"
echo "-- GITHUB_SHA: $2"
echo "-- GITHUB_RUN_NUMBER: $4"
umask 0000;
cd /io;
mkdir 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
cp src/ripple/net/impl/RegisterSSLCerts.cpp src/ripple/net/impl/RegisterSSLCerts.cpp.old
perl -i -pe "s/^{/{
#ifdef EMBEDDED_CA_BUNDLE
BIO *cbio = BIO_new_mem_buf(ca_bundle.data(), ca_bundle.size());
X509_STORE *cts = SSL_CTX_get_cert_store(ctx.native_handle());
if(!cts || !cbio)
JLOG(j.warn())
<< \"Failed to create cts\/cbio when loading embedded certs.\";
else
{
X509_INFO *itmp;
int i, count = 0, type = X509_FILETYPE_PEM;
STACK_OF(X509_INFO) *inf = PEM_X509_INFO_read_bio(cbio, NULL, NULL, NULL);
if (!inf)
{
BIO_free(cbio);
JLOG(j.warn())
<< \"Failed to read cbio when loading embedded certs.\";
}
else
{
for (i = 0; i < sk_X509_INFO_num(inf); i++)
{
itmp = sk_X509_INFO_value(inf, i);
if (itmp->x509)
{
X509_STORE_add_cert(cts, itmp->x509);
count++;
}
if (itmp->crl)
{
X509_STORE_add_crl(cts, itmp->crl);
count++;
}
}
sk_X509_INFO_pop_free(inf, X509_INFO_free);
BIO_free(cbio);
}
}
#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;
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++ \
devtoolset-9-gcc-c++ \
devtoolset-10-gcc-c++ \
snappy snappy-devel \
zlib zlib-devel \
lz4-devel \
libasan &&
export PATH=`echo $PATH | sed -E "s/devtoolset-9/devtoolset-7/g"` &&
echo "-- Install ZStd 1.1.3 --" &&
yum install epel-release -y &&
ZSTD_VERSION="1.1.3" &&
( wget -nc -q -O zstd-${ZSTD_VERSION}.tar.gz https://github.com/facebook/zstd/archive/v${ZSTD_VERSION}.tar.gz; echo "" ) &&
tar xzvf zstd-${ZSTD_VERSION}.tar.gz &&
cd zstd-${ZSTD_VERSION} &&
make -j$3 install &&
cd .. &&
echo "-- Install Cmake 3.23.1 --" &&
pwd &&
( wget -nc -q https://github.com/Kitware/CMake/releases/download/v3.23.1/cmake-3.23.1-linux-x86_64.tar.gz; echo "" ) &&
tar -xzf cmake-3.23.1-linux-x86_64.tar.gz -C /hbb/ &&
echo "-- Install Boost 1.75.0 --" &&
pwd &&
( wget -nc -q https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz; echo "" ) &&
tar -xzf boost_1_75_0.tar.gz &&
cd boost_1_75_0 && ./bootstrap.sh && ./b2 link=static -j$3 && ./b2 install &&
cd ../ &&
echo "-- Install Protobuf 3.20.0 --" &&
pwd &&
( wget -nc -q https://github.com/protocolbuffers/protobuf/releases/download/v3.20.0/protobuf-all-3.20.0.tar.gz; echo "" ) &&
tar -xzf protobuf-all-3.20.0.tar.gz &&
cd protobuf-3.20.0/ &&
./autogen.sh && ./configure --prefix=/usr --disable-shared link=static && make -j$3 && make install &&
cd .. &&
echo "-- Build LLD --" &&
pwd &&
ln /usr/bin/llvm-config-13 /usr/bin/llvm-config &&
mv /opt/rh/devtoolset-9/root/usr/bin/ar /opt/rh/devtoolset-9/root/usr/bin/ar-9 &&
ln /opt/rh/devtoolset-10/root/usr/bin/ar /opt/rh/devtoolset-9/root/usr/bin/ar &&
( wget -nc -q https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/lld-13.0.1.src.tar.xz; echo "" ) &&
( wget -nc -q https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/libunwind-13.0.1.src.tar.xz; echo "" ) &&
tar -xf lld-13.0.1.src.tar.xz &&
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 &&
cd build &&
cmake .. -DLLVM_LIBRARY_DIR=/usr/lib64/llvm13/lib/ -DCMAKE_INSTALL_PREFIX=/usr/lib64/llvm13/ -DCMAKE_BUILD_TYPE=Release &&
make -j$3 install &&
ln -s /usr/lib64/llvm13/lib/include/lld /usr/include/lld &&
cp /usr/lib64/llvm13/lib/liblld*.a /usr/local/lib/ &&
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 "" ) &&
cd build &&
export BOOST_ROOT="/usr/local/src/boost_1_75_0" &&
export Boost_LIBRARY_DIRS="/usr/local/lib" &&
export BOOST_INCLUDEDIR="/usr/local/src/boost_1_75_0" &&
export PATH=`echo $PATH | sed -E "s/devtoolset-7/devtoolset-9/g"` &&
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DWASMEDGE_BUILD_SHARED_LIB=OFF \
-DWASMEDGE_BUILD_STATIC_LIB=ON \
-DWASMEDGE_BUILD_AOT_RUNTIME=ON \
-DWASMEDGE_FORCE_DISABLE_LTO=ON \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DWASMEDGE_LINK_LLVM_STATIC=ON \
-DWASMEDGE_BUILD_PLUGINS=OFF \
-DWASMEDGE_LINK_TOOLS_STATIC=ON \
-DBoost_NO_BOOST_CMAKE=ON -DLLVM_DIR=/usr/lib64/llvm13/lib/cmake/llvm/ -DLLVM_LIBRARY_DIR=/usr/lib64/llvm13/lib/ &&
make -j$3 install &&
export PATH=`echo $PATH | sed -E "s/devtoolset-9/devtoolset-10/g"` &&
cp -r include/api/wasmedge /usr/include/ &&
cd /io/ &&
echo "-- Build Rippled --" &&
pwd &&
cp Builds/CMake/deps/Rocksdb.cmake Builds/CMake/deps/Rocksdb.cmake.old &&
echo "MOVING TO [ build-core.sh ]"
cd /io;
printenv > .env.temp;
cat .env.temp | grep '=' | sed s/\\\(^[^=]\\+=\\\)/\\1\\\"/g|sed s/\$/\\\"/g > .env;
rm .env.temp;
echo "Persisting ENV:"
cat .env
./build-core.sh "$1" "$2" "$3" "$4"
echo "END [ build-core.sh ]"
echo "END INSIDE CONTAINER - FULL"
echo "-- Built with env vars:"

View File

@@ -1,88 +0,0 @@
{
"ledger": {
"accepted": true,
"accountState": [
{
"Account": "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh",
"Balance": "100000000000000000",
"Flags": 0,
"LedgerEntryType": "AccountRoot",
"OwnerCount": 0,
"PreviousTxnID": "A92EF82C3C68F771927E3892A2F708F12CBD492EF68A860F042E4053C8EC6C8D",
"PreviousTxnLgrSeq": 3,
"Sequence": 4,
"index": "2B6AC232AA4C4BE41BF49D2459FA4A0347E1B543A4C92FCEE0821C0201E2E9A8"
},
{
"Amendments": [
"740352F2412A9909880C23A559FCECEDA3BE2126FED62FC7660D628A06927F11",
"3012E8230864E95A58C60FD61430D7E1B4D3353195F2981DC12B0C7C0950FFAC",
"67A34F2CF55BFC0F93AACD5B281413176FEE195269FA6D95219A2DF738671172",
"F64E1EABBE79D55B3BB82020516CEC2C582A98A6BFE20FBE9BB6A0D233418064",
"157D2D480E006395B76F948E3E07A45A05FE10230D88A7993C71F97AE4B1F2D1",
"7117E2EC2DBF119CA55181D69819F1999ECEE1A0225A7FD2B9ED47940968479C",
"CA7C02118BA27599528543DFE77BA6838D1B0F43B447D4D7F53523CE6A0E9AC2",
"58BE9B5968C4DA7C59BA900961828B113E5490699B21877DEF9A31E9D0FE5D5F",
"3CBC5C4E630A1B82380295CDA84B32B49DD066602E74E39B85EF64137FA65194",
"5D08145F0A4983F23AFFFF514E83FAD355C5ABFBB6CAB76FB5BC8519FF5F33BE",
"FBD513F1B893AC765B78F250E6FFA6A11B573209D1842ADC787C850696741288",
"586480873651E106F1D6339B0C4A8945BA705A777F3F4524626FF1FC07EFE41D",
"2CD5286D8D687E98B41102BDD797198E81EA41DF7BD104E6561FEB104EFF2561",
"C4483A1896170C66C098DEA5B0E024309C60DC960DE5F01CD7AF986AA3D9AD37",
"8F81B066ED20DAECA20DF57187767685EEF3980B228E0667A650BAF24426D3B4",
"621A0B264970359869E3C0363A899909AAB7A887C8B73519E4ECF952D33258A8",
"89308AF3B8B10B7192C4E613E1D2E4D9BA64B2EE2D5232402AE82A6A7220D953",
"00C1FC4A53E60AB02C864641002B3172F38677E29C26C5406685179B37E1EDAC",
"25BA44241B3BD880770BFA4DA21C7180576831855368CBEC6A3154FDE4A7676E",
"1F4AFA8FA1BC8827AD4C0F682C03A8B671DCDF6B5C4DE36D44243A684103EF88",
"4F46DF03559967AC60F2EB272FEFE3928A7594A45FF774B87A7E540DB0F8F068",
"B4E4F5D2D6FB84DF7399960A732309C9FD530EAE5941838160042833625A6076",
"955DF3FA5891195A9DAEFA1DDC6BB244B545DDE1BAA84CBB25D5F12A8DA68A0C",
"AF8DF7465C338AE64B1E937D6C8DA138C0D63AD5134A68792BBBE1F63356C422",
"452F5906C46D46F407883344BFDD90E672B672C5E9943DB4891E3A34FEEEB9DB",
"B6B3EEDC0267AB50491FDC450A398AF30DBCD977CECED8BEF2499CAB5DAC19E2",
"98DECF327BF79997AEC178323AD51A830E457BFC6D454DAF3E46E5EC42DC619F",
"B2A4DB846F0891BF2C76AB2F2ACC8F5B4EC64437135C6E56F3F859DE5FFD5856",
"32A122F1352A4C7B3A6D790362CC34749C5E57FCE896377BFDC6CCD14F6CD627",
"F1ED6B4A411D8B872E65B9DCB4C8B100375B0DD3D62D07192E011D6D7F339013",
"75A7E01C505DD5A179DFE3E000A9B6F1EDDEB55A12F95579A23E15B15DC8BE5A",
"47C3002ABA31628447E8E9A8B315FAA935CE30183F9A9B86845E469CA2CDC3DF",
"93E516234E35E08CA689FA33A6D38E103881F8DCB53023F728C307AA89D515A7",
"2E2FB9CF8A44EB80F4694D38AADAE9B8B7ADAFD2F092E10068E61C98C4F092B0",
"73761231F7F3D94EC3D8C63D91BDD0D89045C6F71B917D1925C01253515A6669",
"AE35ABDEFBDE520372B31C957020B34A7A4A9DC3115A69803A44016477C84D6E",
"ECE6819DBA5DB528F1A241695F5A9811EF99467CDE22510954FD357780BBD078",
"42F8B586B357ABBAAAA1C733C3E7D3B75761395340D0CDF600179E8737E22478",
"919857E4B902A20216E4819B9BD9FD1FD19A66ECF63151C18A4C48C873DB9578",
"ECF412BE0964EC2E71DCF807EEEA6EA8470D3DB15173D46F28AB6E234860AC32",
"86E83A7D2ECE3AD5FA87AB2195AE015C950469ABF0B72EAACED318F74886AE90",
"3C43D9A973AA4443EF3FC38E42DD306160FBFFDAB901CD8BAA15D09F2597EB87",
"0285B7E5E08E1A8E4C15636F0591D87F73CB6A7B6452A932AD72BBC8E5D1CBE3",
"36799EA497B1369B170805C078AEFE6188345F9B3E324C21E9CA3FF574E3C3D6"
],
"Flags": 0,
"LedgerEntryType": "Amendments",
"index": "7DB0788C020F02780A673DC74757F23823FA3014C1866E72CC4CD8B226CD6EF4"
}
],
"account_hash": "5DF3A98772FB73E782B8740E87885C6BAD9BA486422E3626DEF968AD2CB2C514",
"close_flags": 0,
"close_time": 733708800,
"close_time_human": "2023-Apr-02 00:00:00.000000",
"close_time_resolution": 10,
"closed": true,
"hash": "56DA0940767AC2F17F0E384F04816002403D0756432B9D503DDA20128A2AAF11",
"ledger_hash": "56DA0940767AC2F17F0E384F04816002403D0756432B9D503DDA20128A2AAF11",
"ledger_index": "5",
"parent_close_time": 733708800,
"parent_hash": "56DA0940767AC2F17F0E384F04816002403D0756432B9D503DDA20128A2AAF11",
"seqNum": "5",
"totalCoins": "100000000000000000",
"total_coins": "100000000000000000",
"transaction_hash": "9A77D1D1A4B36DA77B9C4DC63FDEB8F821741D157802F9C42A6ED86003D8B4A0",
"transactions": []
},
"ledger_current_index": 5,
"status": "success",
"validated": true
}

View File

@@ -758,9 +758,7 @@
# When searching for paths, the default search aggressiveness. This can take
# exponentially more resources as the size is increased.
#
# The recommended value to support advanced pathfinding is: 7
#
# The default is: 2
# The default is: 7
#
# [path_search_fast]
# [path_search_max]
@@ -769,19 +767,12 @@
# If you do not need pathfinding, you can set path_search_max to zero to
# disable it and avoid some expensive bookkeeping.
#
# To support advanced pathfinding the recommended value for
# 'path_search_fast' is 2, and for 'path_search_max' is 10.
#
# The default for 'path_search_fast' is 2. The default for 'path_search_max' is 3.
# The default for 'path_search_fast' is 2. The default for 'path_search_max' is 10.
#
# [path_search_old]
#
# For clients that use the legacy path finding interfaces, the search
# aggressiveness to use.
#
# The recommended value to support advanced pathfinding is: 7.
#
# The default is: 2
# aggressiveness to use. The default is 7.
#
#
#
@@ -1441,7 +1432,7 @@
# default. Don't change this without understanding the consequences.
#
# Example:
# account_reserve = 10000000 # 10 XRP
# account_reserve = 20000000 # 20 XRP
#
# owner_reserve = <drops>
#
@@ -1453,7 +1444,7 @@
# default. Don't change this without understanding the consequences.
#
# Example:
# owner_reserve = 2000000 # 2 XRP
# owner_reserve = 5000000 # 5 XRP
#
#-------------------------------------------------------------------------------
#
@@ -1638,10 +1629,10 @@ ip = 127.0.0.1
admin = 127.0.0.1
protocol = ws
[port_grpc]
port = 50051
ip = 127.0.0.1
secure_gateway = 127.0.0.1
#[port_grpc]
#port = 50051
#ip = 0.0.0.0
#secure_gateway = 127.0.0.1
#[port_ws_public]
#port = 6005

View File

@@ -1401,7 +1401,7 @@
# default. Don't change this without understanding the consequences.
#
# Example:
# account_reserve = 10000000 # 10 XRP
# account_reserve = 20000000 # 20 XRP
#
# owner_reserve = <drops>
#
@@ -1413,7 +1413,7 @@
# default. Don't change this without understanding the consequences.
#
# Example:
# owner_reserve = 2000000 # 2 XRP
# owner_reserve = 5000000 # 5 XRP
#
#-------------------------------------------------------------------------------
#

View File

@@ -1,140 +0,0 @@
# standalone: ./rippled -a --ledgerfile config/genesis.json --conf config/rippled-standalone.cfg
[server]
port_rpc_admin_local
port_ws_public
port_ws_admin_local
# port_peer
# port_ws_admin_local
# ssl_key = /etc/ssl/private/server.key
# ssl_cert = /etc/ssl/certs/server.crt
[port_rpc_admin_local]
port = 5005
ip = 0.0.0.0
admin = 0.0.0.0
protocol = http
[port_ws_public]
port = 80
ip = 0.0.0.0
protocol = ws
# [port_peer]
# port = 51235
# ip = 0.0.0.0
# protocol = peer
[port_ws_admin_local]
port = 6006
ip = 0.0.0.0
admin = 0.0.0.0
protocol = ws
[node_size]
small
# tiny
# small
# medium
# large
# huge
[node_db]
type=NuDB
path=db/nudb
advisory_delete=0
# How many ledgers do we want to keep (history)?
# Integer value that defines the number of ledgers
# between online deletion events
online_delete=256
[ledger_history]
# How many ledgers do we want to keep (history)?
# Integer value (ledger count)
# or (if you have lots of TB SSD storage): 'full'
256
[database_path]
db
[debug_logfile]
debug.log
[sntp_servers]
time.windows.com
time.apple.com
time.nist.gov
pool.ntp.org
[ips]
r.ripple.com 51235
[validators_file]
validators-example.txt
[rpc_startup]
{ "command": "log_level", "severity": "trace" }
# severity (order: lots of information .. only errors)
# debug
# info
# warning
# error
# fatal
[ssl_verify]
1
[fee_account_reserve]
5000000
[fee_owner_reserve]
1000000
[network_id]
21338
[amendments]
740352F2412A9909880C23A559FCECEDA3BE2126FED62FC7660D628A06927F11 Flow
3012E8230864E95A58C60FD61430D7E1B4D3353195F2981DC12B0C7C0950FFAC FlowCross
67A34F2CF55BFC0F93AACD5B281413176FEE195269FA6D95219A2DF738671172 fix1513
F64E1EABBE79D55B3BB82020516CEC2C582A98A6BFE20FBE9BB6A0D233418064 DepositAuth
157D2D480E006395B76F948E3E07A45A05FE10230D88A7993C71F97AE4B1F2D1 Checks
7117E2EC2DBF119CA55181D69819F1999ECEE1A0225A7FD2B9ED47940968479C fix1571
CA7C02118BA27599528543DFE77BA6838D1B0F43B447D4D7F53523CE6A0E9AC2 fix1543
58BE9B5968C4DA7C59BA900961828B113E5490699B21877DEF9A31E9D0FE5D5F fix1623
3CBC5C4E630A1B82380295CDA84B32B49DD066602E74E39B85EF64137FA65194 DepositPreauth
5D08145F0A4983F23AFFFF514E83FAD355C5ABFBB6CAB76FB5BC8519FF5F33BE fix1515
FBD513F1B893AC765B78F250E6FFA6A11B573209D1842ADC787C850696741288 fix1578
586480873651E106F1D6339B0C4A8945BA705A777F3F4524626FF1FC07EFE41D MultiSignReserve
2CD5286D8D687E98B41102BDD797198E81EA41DF7BD104E6561FEB104EFF2561 fixTakerDryOfferRemoval
C4483A1896170C66C098DEA5B0E024309C60DC960DE5F01CD7AF986AA3D9AD37 fixMasterKeyAsRegularKey
8F81B066ED20DAECA20DF57187767685EEF3980B228E0667A650BAF24426D3B4 fixCheckThreading
621A0B264970359869E3C0363A899909AAB7A887C8B73519E4ECF952D33258A8 fixPayChanRecipientOwnerDir
30CD365592B8EE40489BA01AE2F7555CAC9C983145871DC82A42A31CF5BAE7D9 DeletableAccounts
89308AF3B8B10B7192C4E613E1D2E4D9BA64B2EE2D5232402AE82A6A7220D953 fixQualityUpperBound
00C1FC4A53E60AB02C864641002B3172F38677E29C26C5406685179B37E1EDAC RequireFullyCanonicalSig
25BA44241B3BD880770BFA4DA21C7180576831855368CBEC6A3154FDE4A7676E fix1781
1F4AFA8FA1BC8827AD4C0F682C03A8B671DCDF6B5C4DE36D44243A684103EF88 HardenedValidations
4F46DF03559967AC60F2EB272FEFE3928A7594A45FF774B87A7E540DB0F8F068 fixAmendmentMajorityCalc
B4E4F5D2D6FB84DF7399960A732309C9FD530EAE5941838160042833625A6076 NegativeUNL
955DF3FA5891195A9DAEFA1DDC6BB244B545DDE1BAA84CBB25D5F12A8DA68A0C TicketBatch
AF8DF7465C338AE64B1E937D6C8DA138C0D63AD5134A68792BBBE1F63356C422 FlowSortStrands
452F5906C46D46F407883344BFDD90E672B672C5E9943DB4891E3A34FEEEB9DB fixSTAmountCanonicalize
B6B3EEDC0267AB50491FDC450A398AF30DBCD977CECED8BEF2499CAB5DAC19E2 fixRmSmallIncreasedQOffers
98DECF327BF79997AEC178323AD51A830E457BFC6D454DAF3E46E5EC42DC619F CheckCashMakesTrustLine
B2A4DB846F0891BF2C76AB2F2ACC8F5B4EC64437135C6E56F3F859DE5FFD5856 ExpandedSignerList
32A122F1352A4C7B3A6D790362CC34749C5E57FCE896377BFDC6CCD14F6CD627 NonFungibleTokensV1_1
2E2FB9CF8A44EB80F4694D38AADAE9B8B7ADAFD2F092E10068E61C98C4F092B0 fixUniversalNumber
73761231F7F3D94EC3D8C63D91BDD0D89045C6F71B917D1925C01253515A6669 fixNonFungibleTokensV1_2
AE35ABDEFBDE520372B31C957020B34A7A4A9DC3115A69803A44016477C84D6E fixNFTokenRemint
ECF412BE0964EC2E71DCF807EEEA6EA8470D3DB15173D46F28AB6E234860AC32 Hooks
42F8B586B357ABBAAAA1C733C3E7D3B75761395340D0CDF600179E8737E22478 BalanceRewards
919857E4B902A20216E4819B9BD9FD1FD19A66ECF63151C18A4C48C873DB9578 PaychanAndEscrowForTokens
ECF412BE0964EC2E71DCF807EEEA6EA8470D3DB15173D46F28AB6E234860AC32 URIToken
86E83A7D2ECE3AD5FA87AB2195AE015C950469ABF0B72EAACED318F74886AE90 CryptoConditionsSuite
3C43D9A973AA4443EF3FC38E42DD306160FBFFDAB901CD8BAA15D09F2597EB87 NonFungibleTokensV1
0285B7E5E08E1A8E4C15636F0591D87F73CB6A7B6452A932AD72BBC8E5D1CBE3 fixNFTokenDirV1
36799EA497B1369B170805C078AEFE6188345F9B3E324C21E9CA3FF574E3C3D6 fixNFTokenNegOffer

View File

@@ -26,6 +26,7 @@
#
# Examples:
# https://vl.ripple.com
# https://vl.coil.com
# https://vl.xrplf.org
# http://127.0.0.1:8000
# file:///etc/opt/ripple/vl.txt

View File

@@ -1,4 +0,0 @@
#!/bin/bash
docker run --rm -i -v $(pwd):/io ubuntu sh -c '/io/release-build/xahaud -u'

View File

@@ -1,5 +1,16 @@
# `rippled` Docker Image
# Rippled Docker Image
- Some info relating to Docker containers can be found here: [../Builds/containers](../Builds/containers)
- Images for building and testing rippled can be found here: [thejohnfreeman/rippled-docker](https://github.com/thejohnfreeman/rippled-docker/)
- These images do not have rippled. They have all the tools necessary to build rippled.
Rippled has a continuous deployment pipeline that turns every git commit into a
docker image for quick testing and deployment.
To run the tip of the latest release via docker:
```$ docker run -P -v /srv/rippled/ ripple/rippled:latest```
To run the tip of active development:
```$ docker run -P -v /srv/rippled/ ripple/rippled:develop```
Where ```/srv/rippled``` points to a directory containing a rippled.cfg and
database files. By default, port 5005/tcp maps to the RPC port and 51235/udp to
the peer port.

View File

@@ -1,16 +0,0 @@
sources:
"1.1.9":
url: "https://github.com/google/snappy/archive/1.1.9.tar.gz"
sha256: "75c1fbb3d618dd3a0483bff0e26d0a92b495bbe5059c8b4f1c962b478b6e06e7"
"1.1.8":
url: "https://github.com/google/snappy/archive/1.1.8.tar.gz"
sha256: "16b677f07832a612b0836178db7f374e414f94657c138e6993cbfc5dcc58651f"
"1.1.7":
url: "https://github.com/google/snappy/archive/1.1.7.tar.gz"
sha256: "3dfa02e873ff51a11ee02b9ca391807f0c8ea0529a4924afa645fbf97163f9d4"
patches:
"1.1.9":
- patch_file: "patches/1.1.9-0001-fix-inlining-failure.patch"
- patch_file: "patches/1.1.9-0002-no-Werror.patch"
- patch_file: "patches/1.1.9-0003-fix-clobber-list-older-llvm.patch"
- patch_file: "patches/1.1.9-0004-rtti-by-default.patch"

View File

@@ -1,89 +0,0 @@
from conan import ConanFile
from conan.tools.build import check_min_cppstd
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, rmdir
from conan.tools.scm import Version
import os
required_conan_version = ">=1.54.0"
class SnappyConan(ConanFile):
name = "snappy"
description = "A fast compressor/decompressor"
topics = ("google", "compressor", "decompressor")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/google/snappy"
license = "BSD-3-Clause"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}
def export_sources(self):
export_conandata_patches(self)
def config_options(self):
if self.settings.os == 'Windows':
del self.options.fPIC
def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")
def layout(self):
cmake_layout(self, src_folder="src")
def validate(self):
if self.settings.compiler.get_safe("cppstd"):
check_min_cppstd(self, 11)
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["SNAPPY_BUILD_TESTS"] = False
if Version(self.version) >= "1.1.8":
tc.variables["SNAPPY_FUZZING_BUILD"] = False
tc.variables["SNAPPY_REQUIRE_AVX"] = False
tc.variables["SNAPPY_REQUIRE_AVX2"] = False
tc.variables["SNAPPY_INSTALL"] = True
if Version(self.version) >= "1.1.9":
tc.variables["SNAPPY_BUILD_BENCHMARKS"] = False
tc.generate()
def build(self):
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()
def package(self):
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
def package_info(self):
self.cpp_info.set_property("cmake_file_name", "Snappy")
self.cpp_info.set_property("cmake_target_name", "Snappy::snappy")
# TODO: back to global scope in conan v2 once cmake_find_package* generators removed
self.cpp_info.components["snappylib"].libs = ["snappy"]
if not self.options.shared:
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["snappylib"].system_libs.append("m")
# TODO: to remove in conan v2 once cmake_find_package* generators removed
self.cpp_info.names["cmake_find_package"] = "Snappy"
self.cpp_info.names["cmake_find_package_multi"] = "Snappy"
self.cpp_info.components["snappylib"].names["cmake_find_package"] = "snappy"
self.cpp_info.components["snappylib"].names["cmake_find_package_multi"] = "snappy"
self.cpp_info.components["snappylib"].set_property("cmake_target_name", "Snappy::snappy")

View File

@@ -1,14 +0,0 @@
Fixes the following error:
error: inlining failed in call to always_inline size_t snappy::AdvanceToNextTag(const uint8_t**, size_t*): function body can be overwritten at link time
--- snappy-stubs-internal.h
+++ snappy-stubs-internal.h
@@ -100,7 +100,7 @@
// Inlining hints.
#ifdef HAVE_ATTRIBUTE_ALWAYS_INLINE
-#define SNAPPY_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline))
+#define SNAPPY_ATTRIBUTE_ALWAYS_INLINE
#else
#define SNAPPY_ATTRIBUTE_ALWAYS_INLINE
#endif

View File

@@ -1,12 +0,0 @@
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -69,7 +69,7 @@
- # Use -Werror for clang only.
+if(0)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
if(NOT CMAKE_CXX_FLAGS MATCHES "-Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror")
endif(NOT CMAKE_CXX_FLAGS MATCHES "-Werror")
endif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
-
+endif()

View File

@@ -1,12 +0,0 @@
asm clobbers do not work for clang < 9 and apple-clang < 11 (found by SpaceIm)
--- snappy.cc
+++ snappy.cc
@@ -1026,7 +1026,7 @@
size_t literal_len = *tag >> 2;
size_t tag_type = *tag;
bool is_literal;
-#if defined(__GNUC__) && defined(__x86_64__)
+#if defined(__GNUC__) && defined(__x86_64__) && ( (!defined(__clang__) && !defined(__APPLE__)) || (!defined(__APPLE__) && defined(__clang__) && (__clang_major__ >= 9)) || (defined(__APPLE__) && defined(__clang__) && (__clang_major__ > 11)) )
// TODO clang misses the fact that the (c & 3) already correctly
// sets the zero flag.
asm("and $3, %k[tag_type]\n\t"

View File

@@ -1,20 +0,0 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -53,8 +53,6 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
add_definitions(-D_HAS_EXCEPTIONS=0)
# Disable RTTI.
- string(REGEX REPLACE "/GR" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-")
else(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# Use -Wall for clang and gcc.
if(NOT CMAKE_CXX_FLAGS MATCHES "-Wall")
@@ -78,8 +76,6 @@ endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-exceptions")
# Disable RTTI.
- string(REGEX REPLACE "-frtti" "" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti")
endif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
# BUILD_SHARED_LIBS is a standard CMake variable, but we declare it here to make

View File

@@ -1,68 +0,0 @@
# Xahau Launch Hooks
## Savings Hook
When it comes to managing money, it is a common practice to maintain separate spending and savings accounts.
Suppose you receive an income or salary to your on-ledger account several times a month. Each time you receive funds above a certain threshold you may wish to move a predefined percentage to a savings account where you will not accidentally spend them. The savings hook does exactly this.
### Hook Parameters
1. Account to install on
2. Account to send savings to
3. The percentage to send
4. The threshold at which it is activated
5. Whether it applies to incoming payments only, outgoing payments only or both.
### xApp Features
1. Display the send-to account
2. Display the percentage
3. Display the total amount sent
4. Display the conditions of sending (threshold + incoming/outgoing payments)
5. Allow the hook to be uninstalled
## Firewall Hook
The ledger is a messy place full of unwanted transactions and spam. To avoid being spammed with low value transactions containing unsolicitied memos you may install a Firewall hook on your account.
### Hook Parameters
1. Types of transactions to allow into and out of your account (Payment, Escrow, PayChannel) etc.
2. Allow a minimum number of drops for an incoming txn to be allowed.
3. Allow a minimum amount to be specified for each of the trustline assets on the account as well.
4. Allow any txn with a memo larger than X bytes to be blocked regardless of other rules.
### xApp Features
1. Display the current settings of the hook. Allow the settings to be changed.
2. Allow the hook to be uninstalled.
## Blocklist Hook
Filter outgoing and incoming payments against a known list of scam accounts maintained by a third party. This acts as a guard against accidentally sending to a scam, or being sent tainted funds by a scammer.
### Hook Parameters
1. The blocklist (account) to listen to.
### xApp Features
1. Number of times a transaction was blocked.
2. The current blocklist (account) being listened to.
3. Allow the hook to be uninstalled.
## Direct Debit Hook
Allow trusted third parties to pull funds from your account up to a limit you set. For example your power company can bill you and your account can automatically pay that bill.
### Hook Parameters
1. One or more accounts to provide direct deposit authorization to.
2. A currency and a limit for each of these.
## xApp Features
1. See who you've authorized.
2. See how much they're authorized for.
3. See how much they've drawn down this month.
4. Allow authorization to be removed.
5. Allow authorization limit to be changed.
6. Allow additional authorizations to be created.
7. Allow the hook to be uninstalled.
8. Show a list of recent direct debit transactions.
## High-Value Payment Hook
When sending high value transactions out of your account, require first a notification that a high valued payment will be made, followed by a time delay, followed by the high value transaction itself. This prevents accidental high value sends, adding an additional layer of security to your account.
### Hook Parameters
1. Select currencies for which the hook will act.
2. Select the thresholds for which the hook will be triggered.
### xApp Features
1. See current pending outgoing high value transactions.
2. State that the hook is active and for which currencies and thresholds.
3. Allow the hook to be uninstalled.
4. If installed, and a high value transaction is made from Xumm, it is redirected into the xApp.
5. The xApp then generates a notification transaction (ttInvoke) which is sent to the hook.
6. The xApp will then remind the user with an event at a later time that the transaction proper still needs to be sent.
7. Sending the transaction proper again will result in successful send.

View File

@@ -41,18 +41,12 @@
"PayChannel": 120,
"Check": 67,
"DepositPreauth": 112,
"NegativeUNL": 78,
"NFTokenPage": 80,
"NFTokenOffer": 55,
"Any": -3,
"Child": -2,
"NegativeUnl": 78,
"Any": 0,
"Child": 7378,
"Nickname": 110,
"Contract": 99,
"GeneratorMap": 103,
"Hook": 72,
"HookState": 118,
"HookDefinition": 68,
"EmittedTxn": 69
"GeneratorMap": 103
},
"FIELDS": [
[
@@ -138,7 +132,7 @@
[
"LedgerEntry",
{
"nth": 1,
"nth": 257,
"isVLEncoded": false,
"isSerialized": false,
"isSigningField": true,
@@ -148,7 +142,7 @@
[
"Transaction",
{
"nth": 1,
"nth": 257,
"isVLEncoded": false,
"isSerialized": false,
"isSigningField": true,
@@ -158,7 +152,7 @@
[
"Validation",
{
"nth": 1,
"nth": 257,
"isVLEncoded": false,
"isSerialized": false,
"isSigningField": true,
@@ -168,7 +162,7 @@
[
"Metadata",
{
"nth": 1,
"nth": 257,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
@@ -325,16 +319,6 @@
"type": "UInt16"
}
],
[
"NetworkID",
{
"nth": 1,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "UInt32"
}
],
[
"Flags",
{
@@ -726,7 +710,7 @@
}
],
[
"NFTokenTaxon",
"TokenTaxon",
{
"nth": 42,
"isVLEncoded": false,
@@ -736,7 +720,7 @@
}
],
[
"MintedNFTokens",
"MintedTokens",
{
"nth": 43,
"isVLEncoded": false,
@@ -746,7 +730,7 @@
}
],
[
"BurnedNFTokens",
"BurnedTokens",
{
"nth": 44,
"isVLEncoded": false,
@@ -775,16 +759,6 @@
"type": "UInt32"
}
],
[
"LockCount",
{
"nth": 47,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "UInt32"
}
],
[
"RewardTime",
{
@@ -926,7 +900,7 @@
}
],
[
"NFTokenOfferNode",
"OfferNode",
{
"nth": 12,
"isVLEncoded": false,
@@ -945,6 +919,16 @@
"type": "UInt64"
}
],
[
"HookOn",
{
"nth": 16,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "UInt64"
}
],
[
"HookInstructionCount",
{
@@ -1205,16 +1189,6 @@
"type": "Hash256"
}
],
[
"HookOn",
{
"nth": 20,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "Hash256"
}
],
[
"Digest",
{
@@ -1286,7 +1260,7 @@
}
],
[
"NFTokenBuyOffer",
"BuyOffer",
{
"nth": 28,
"isVLEncoded": false,
@@ -1296,7 +1270,7 @@
}
],
[
"NFTokenSellOffer",
"SellOffer",
{
"nth": 29,
"isVLEncoded": false,
@@ -1345,26 +1319,6 @@
"type": "Hash256"
}
],
[
"OfferID",
{
"nth": 34,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "Hash256"
}
],
[
"EscrowID",
{
"nth": 35,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "Hash256"
}
],
[
"Amount",
{
@@ -1505,26 +1459,6 @@
"type": "Amount"
}
],
[
"HookCallbackFee",
{
"nth": 20,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "Amount"
}
],
[
"LockedBalance",
{
"nth": 21,
"isVLEncoded": false,
"isSerialized": true,
"isSigningField": true,
"type": "Amount"
}
],
[
"PublicKey",
{
@@ -1772,7 +1706,7 @@
"isVLEncoded": true,
"isSerialized": true,
"isSigningField": true,
"type": "Blob"
"type":"Blob"
}
],
[
@@ -1906,7 +1840,7 @@
}
],
[
"NFTokenOffers",
"TokenOffers",
{
"nth": 4,
"isVLEncoded": true,
@@ -1915,16 +1849,6 @@
"type": "Vector256"
}
],
[
"HookNamespaces",
{
"nth": 5,
"isVLEncoded": true,
"isSerialized": true,
"isSigningField": true,
"type": "Vector256"
}
],
[
"Paths",
{
@@ -2300,9 +2224,6 @@
"telCAN_NOT_QUEUE_BLOCKED": -389,
"telCAN_NOT_QUEUE_FEE": -388,
"telCAN_NOT_QUEUE_FULL": -387,
"telWRONG_NETWORK": -386,
"telREQUIRES_NETWORK_ID": -385,
"telNETWORK_ID_MAKES_TX_NON_CANONICAL": -384,
"temMALFORMED": -299,
"temBAD_AMOUNT": -298,
@@ -2337,13 +2258,10 @@
"temBAD_TICK_SIZE": -269,
"temINVALID_ACCOUNT_ID": -268,
"temCANNOT_PREAUTH_SELF": -267,
"temINVALID_COUNT": -266,
"temHOOK_DATA_TOO_LARGE": -265,
"temHOOK_REJECTED": -264,
"temUNCERTAIN": -263,
"temUNKNOWN": -262,
"temSEQ_AND_TICKET": -261,
"temBAD_NFTOKEN_TRANSFER_FEE": -260,
"temUNCERTAIN": -266,
"temUNKNOWN": -265,
"temSEQ_AND_TICKET": -264,
"temBAD_NFTOKEN_TRANSFER_FEE": -263,
"tefFAILURE": -199,
"tefALREADY": -198,
@@ -2379,7 +2297,6 @@
"terNO_RIPPLE": -90,
"terQUEUED": -89,
"terPRE_TICKET": -88,
"terNO_HOOK": -87,
"tesSUCCESS": 0,
@@ -2422,6 +2339,7 @@
"tecHAS_OBLIGATIONS": 151,
"tecTOO_SOON": 152,
"tecHOOK_REJECTED": 153,
"tecMAX_SEQUENCE_REACHED": 154,
"tecNO_SUITABLE_NFTOKEN_PAGE": 155,
"tecNFTOKEN_BUY_SELL_MISMATCH": 156,
@@ -2430,8 +2348,8 @@
"tecINSUFFICIENT_FUNDS": 159,
"tecOBJECT_NOT_FOUND": 160,
"tecINSUFFICIENT_PAYMENT": 161,
"tecREQUIRES_FLAG": 162,
"tecPRECISION_LOSS": 163
"tecINCORRECT_ASSET": 162,
"tecTOO_MANY": 163
},
"TRANSACTION_TYPES": {
"Invalid": -1,
@@ -2467,7 +2385,8 @@
"Invoke": 99,
"EnableAmendment": 100,
"SetFee": 101,
"UNLModify": 102,
"EmitFailure": 103
"UNLModify": 102
}
}

View File

@@ -31,7 +31,7 @@
#define MANTISSA_UNDERSIZED -27
#define EXPONENT_OVERSIZED -28
#define EXPONENT_UNDERSIZED -29
#define XFL_OVERFLOW -30
#define OVERFLOW -30
#define NOT_IOU_AMOUNT -31
#define NOT_AN_AMOUNT -32
#define CANT_RETURN_NEGATIVE -33
@@ -42,8 +42,5 @@
#define RESERVE_INSUFFICIENT -38
#define COMPLEX_NOT_SUPPORTED -39
#define DOES_NOT_MATCH -40
#define INVALID_KEY -41
#define NOT_A_STRING -42
#define MEM_OVERLAP -43
#define HOOK_ERROR_CODES
#endif //HOOK_ERROR_CODES
#endif //HOOK_ERROR_CODES

View File

@@ -10,83 +10,12 @@ extern int64_t
accept(uint32_t read_ptr, uint32_t read_len, int64_t error_code);
extern int64_t
rollback(uint32_t read_ptr, uint32_t read_len, int64_t error_code);
// UTIL
extern int64_t
util_raddr(
emit(
uint32_t write_ptr,
uint32_t write_len,
uint32_t read_ptr,
uint32_t read_len);
extern int64_t
util_accid(
uint32_t write_ptr,
uint32_t write_len,
uint32_t read_ptr,
uint32_t read_len);
extern int64_t
util_verify(
uint32_t dread_ptr,
uint32_t dread_len,
uint32_t sread_ptr,
uint32_t sread_len,
uint32_t kread_ptr,
uint32_t kread_len);
extern int64_t
util_sha512h(
uint32_t write_ptr,
uint32_t write_len,
uint32_t read_ptr,
uint32_t read_len);
extern int64_t
util_keylet(
uint32_t write_ptr,
uint32_t write_len,
uint32_t keylet_type,
uint32_t a,
uint32_t b,
uint32_t c,
uint32_t d,
uint32_t e,
uint32_t f);
// STO
extern int64_t
sto_validate(uint32_t tread_ptr, uint32_t tread_len);
extern int64_t
sto_subfield(uint32_t read_ptr, uint32_t read_len, uint32_t field_id);
extern int64_t
sto_subarray(uint32_t read_ptr, uint32_t read_len, uint32_t array_id);
extern int64_t
sto_emplace(
uint32_t write_ptr,
uint32_t write_len,
uint32_t sread_ptr,
uint32_t sread_len,
uint32_t fread_ptr,
uint32_t fread_len,
uint32_t field_id);
extern int64_t
sto_erase(
uint32_t write_ptr,
uint32_t write_len,
uint32_t read_ptr,
uint32_t read_len,
uint32_t field_id);
// EMITTED TXN
extern int64_t
etxn_burden(void);
@@ -96,9 +25,6 @@ etxn_details(uint32_t write_ptr, uint32_t write_len);
extern int64_t
etxn_fee_base(uint32_t read_ptr, uint32_t read_len);
extern int64_t
etxn_reserve(uint32_t count);
extern int64_t
etxn_generation(void);
@@ -106,19 +32,37 @@ extern int64_t
etxn_nonce(uint32_t write_ptr, uint32_t write_len);
extern int64_t
emit(
uint32_t write_ptr,
uint32_t write_len,
uint32_t read_ptr,
uint32_t read_len);
// FLOAT
etxn_reserve(uint32_t count);
extern int64_t
float_set(int32_t exponent, int64_t mantissa);
fee_base(void);
extern int64_t
float_multiply(int64_t float1, int64_t float2);
float_compare(int64_t float1, int64_t float2, uint32_t mode);
extern int64_t
float_divide(int64_t float1, int64_t float2);
extern int64_t
float_exponent(int64_t float1);
extern int64_t
float_exponent_set(int64_t float1, int32_t exponent);
extern int64_t
float_int(int64_t float1, uint32_t decimal_places, uint32_t abs);
extern int64_t
float_invert(int64_t float1);
extern int64_t
float_log(int64_t float1);
extern int64_t
float_mantissa(int64_t float1);
extern int64_t
float_mantissa_set(int64_t float1, int64_t mantissa);
extern int64_t
float_mulratio(
@@ -127,14 +71,26 @@ float_mulratio(
uint32_t numerator,
uint32_t denominator);
extern int64_t
float_multiply(int64_t float1, int64_t float2);
extern int64_t
float_negate(int64_t float1);
extern int64_t
float_compare(int64_t float1, int64_t float2, uint32_t mode);
float_one(void);
extern int64_t
float_sum(int64_t float1, int64_t float2);
float_root(int64_t float1, uint32_t n);
extern int64_t
float_set(int32_t exponent, int64_t mantissa);
extern int64_t
float_sign(int64_t float1);
extern int64_t
float_sign_set(int64_t float1, uint32_t negative);
extern int64_t
float_sto(
@@ -151,63 +107,24 @@ extern int64_t
float_sto_set(uint32_t read_ptr, uint32_t read_len);
extern int64_t
float_invert(int64_t float1);
extern int64_t
float_divide(int64_t float1, int64_t float2);
extern int64_t
float_one(void);
extern int64_t
float_mantissa(int64_t float1);
extern int64_t
float_sign(int64_t float1);
extern int64_t
float_int(int64_t float1, uint32_t decimal_places, uint32_t abs);
extern int64_t
float_log(int64_t float1);
extern int64_t
float_root(int64_t float1, uint32_t n);
// LEDGER
extern int64_t
fee_base(void);
extern int64_t
ledger_seq(void);
extern int64_t
ledger_last_time(void);
extern int64_t
ledger_last_hash(uint32_t write_ptr, uint32_t write_len);
extern int64_t
ledger_nonce(uint32_t write_ptr, uint32_t write_len);
extern int64_t
ledger_keylet(
uint32_t write_ptr,
uint32_t write_len,
uint32_t lread_ptr,
uint32_t lread_len,
uint32_t hread_ptr,
uint32_t hread_len);
// HOOK
float_sum(int64_t float1, int64_t float2);
extern int64_t
hook_account(uint32_t write_ptr, uint32_t write_len);
extern int64_t
hook_again(void);
extern int64_t
hook_hash(uint32_t write_ptr, uint32_t write_len, int32_t hook_no);
extern int64_t
hook_param(
uint32_t write_ptr,
uint32_t write_len,
uint32_t read_ptr,
uint32_t read_len);
extern int64_t
hook_param_set(
uint32_t read_ptr,
@@ -218,22 +135,58 @@ hook_param_set(
uint32_t hread_len);
extern int64_t
hook_param(
uint32_t write_ptr,
uint32_t write_len,
uint32_t read_ptr,
uint32_t read_len);
extern int64_t
hook_again(void);
hook_pos(void);
extern int64_t
hook_skip(uint32_t read_ptr, uint32_t read_len, uint32_t flags);
extern int64_t
hook_pos(void);
ledger_keylet(
uint32_t write_ptr,
uint32_t write_len,
uint32_t lread_ptr,
uint32_t lread_len,
uint32_t hread_ptr,
uint32_t hread_len);
// SLOT
extern int64_t
ledger_last_hash(uint32_t write_ptr, uint32_t write_len);
extern int64_t
ledger_last_time(void);
extern int64_t
ledger_nonce(uint32_t write_ptr, uint32_t write_len);
extern int64_t
ledger_seq(void);
extern int64_t
meta_slot(uint32_t slot_no);
extern int64_t
otxn_burden(void);
extern int64_t
otxn_field(uint32_t write_ptr, uint32_t write_len, uint32_t field_id);
extern int64_t
otxn_field_txt(uint32_t write_ptr, uint32_t write_len, uint32_t field_id);
extern int64_t
otxn_generation(void);
extern int64_t
otxn_id(uint32_t write_ptr, uint32_t write_len, uint32_t flags);
extern int64_t
otxn_slot(uint32_t slot_no);
extern int64_t
otxn_type(void);
extern int64_t
rollback(uint32_t read_ptr, uint32_t read_len, int64_t error_code);
extern int64_t
slot(uint32_t write_ptr, uint32_t write_len, uint32_t slot);
@@ -244,6 +197,12 @@ slot_clear(uint32_t slot);
extern int64_t
slot_count(uint32_t slot);
extern int64_t
slot_float(uint32_t slot_no);
extern int64_t
slot_id(uint32_t write_ptr, uint32_t write_len, uint32_t slot);
extern int64_t
slot_set(uint32_t read_ptr, uint32_t read_len, uint32_t slot);
@@ -259,29 +218,6 @@ slot_subfield(uint32_t parent_slot, uint32_t field_id, uint32_t new_slot);
extern int64_t
slot_type(uint32_t slot_no, uint32_t flags);
extern int64_t
slot_float(uint32_t slot_no);
// STATE
extern int64_t
state_set(
uint32_t read_ptr,
uint32_t read_len,
uint32_t kread_ptr,
uint32_t kread_len);
extern int64_t
state_foreign_set(
uint32_t read_ptr,
uint32_t read_len,
uint32_t kread_ptr,
uint32_t kread_len,
uint32_t nread_ptr,
uint32_t nread_len,
uint32_t aread_ptr,
uint32_t aread_len);
extern int64_t
state(
uint32_t write_ptr,
@@ -300,7 +236,50 @@ state_foreign(
uint32_t aread_ptr,
uint32_t aread_len);
// TRACE
extern int64_t
state_foreign_set(
uint32_t read_ptr,
uint32_t read_len,
uint32_t kread_ptr,
uint32_t kread_len,
uint32_t nread_ptr,
uint32_t nread_len,
uint32_t aread_ptr,
uint32_t aread_len);
extern int64_t
state_set(
uint32_t read_ptr,
uint32_t read_len,
uint32_t kread_ptr,
uint32_t kread_len);
extern int64_t
sto_emplace(
uint32_t write_ptr,
uint32_t write_len,
uint32_t sread_ptr,
uint32_t sread_len,
uint32_t fread_ptr,
uint32_t fread_len,
uint32_t field_id);
extern int64_t
sto_erase(
uint32_t write_ptr,
uint32_t write_len,
uint32_t read_ptr,
uint32_t read_len,
uint32_t field_id);
extern int64_t
sto_subarray(uint32_t read_ptr, uint32_t read_len, uint32_t array_id);
extern int64_t
sto_subfield(uint32_t read_ptr, uint32_t read_len, uint32_t field_id);
extern int64_t
sto_validate(uint32_t tread_ptr, uint32_t tread_len);
extern int64_t
trace(
@@ -310,45 +289,55 @@ trace(
uint32_t dread_len,
uint32_t as_hex);
extern int64_t
trace_float(uint32_t read_ptr, uint32_t read_len, int64_t float1);
extern int64_t
trace_num(uint32_t read_ptr, uint32_t read_len, int64_t number);
extern int64_t
trace_float(uint32_t read_ptr, uint32_t read_len, int64_t float1);
// OTXN
trace_slot(uint32_t read_ptr, uint32_t read_len, uint32_t slot);
extern int64_t
otxn_burden(void);
extern int64_t
otxn_field(uint32_t write_ptr, uint32_t write_len, uint32_t field_id);
extern int64_t
otxn_generation(void);
extern int64_t
otxn_id(uint32_t write_ptr, uint32_t write_len, uint32_t flags);
extern int64_t
otxn_type(void);
extern int64_t
otxn_slot(uint32_t slot_no);
extern int64_t
otxn_param(
util_accid(
uint32_t write_ptr,
uint32_t write_len,
uint32_t read_ptr,
uint32_t read_len);
extern int64_t
meta_slot(uint32_t slot_no);
util_keylet(
uint32_t write_ptr,
uint32_t write_len,
uint32_t keylet_type,
uint32_t a,
uint32_t b,
uint32_t c,
uint32_t d,
uint32_t e,
uint32_t f);
// featureHooks1
extern int64_t
util_raddr(
uint32_t write_ptr,
uint32_t write_len,
uint32_t read_ptr,
uint32_t read_len);
extern int64_t xpop_slot(uint32_t, uint32_t);
extern int64_t
util_sha512h(
uint32_t write_ptr,
uint32_t write_len,
uint32_t read_ptr,
uint32_t read_len);
extern int64_t
util_verify(
uint32_t dread_ptr,
uint32_t dread_len,
uint32_t sread_ptr,
uint32_t sread_len,
uint32_t kread_ptr,
uint32_t kread_len);
#define HOOK_EXTERN
#endif // HOOK_EXTERN

377
hook/gov_hook.c Normal file
View File

@@ -0,0 +1,377 @@
#include "hookapi.h"
#define ASSERT(x)\
if (!(x))\
rollback(0,0,__LINE__);
#define INIT_MEMBER_COUNT 5
#define MAX_MEMBER_COUNT 20
#define INIT_AMOUNT 50000000000000ULL // 50MM
// test accounts only, must be replaced with real accounts prior to launch
uint8_t initial_members[] =
{
// the first 12 bytes of each is padding to allow a reverse key
// to be easily set for the account id
// acc 0 - rJmkqLL4mqrc9kbP5Ztkq4TvVamYNetedp
0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U, 0x00U, 0x00U,
0xC2U,0xF1U,0x07U,0xE6U,0xE8U,0x64U,0xD3U,0x90U,0x6DU,0x0AU,
0x08U,0x84U,0x46U,0xFDU,0xDFU,0x8AU,0x7BU,0x2FU,0x56U,0x9CU,
// acc 1 - rEVGdPT6ACPPcXGNwNeeYYtoRTKFaqhEi4
0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U, 0x00U, 0x00U,
0x9EU,0xEAU,0x73U,0xF5U,0xF0U,0x62U,0x7EU,0x69U,0x39U,0x7EU,
0xC7U,0x2EU,0x9AU,0x3CU,0x78U,0x04U,0xC0U,0xF2U,0xBFU,0x69U,
// acc 2 - rJi1kZsQthVqVPLmQdTmG8AtiAKk26J9ST
0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U, 0x00U, 0x00U,
0xC3U,0xE8U,0xE2U,0x9AU,0xB6U,0x28U,0x47U,0x27U,0x5CU,0xEDU,
0x36U,0xEBU,0xF4U,0xE9U,0x28U,0xDCU,0x25U,0xA0U,0x7FU,0x24U,
// acc 3 - rHm34nx2QSJKXhe32NiNbsnrUSeZqDZMkg
0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U, 0x00U, 0x00U,
0xB7U,0xDAU,0x76U,0x2DU,0xB9U,0x90U,0x2EU,0x85U,0x19U,0x96U,
0x66U,0xB2U,0xE6U,0xC3U,0x00U,0x9CU,0x5EU,0x27U,0x57U,0x69U,
// acc 4 - rLc3URyuFpTqBAcPFK5J7c73h488ew79dH
0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U,0x00U, 0x00U, 0x00U,
0xD7U,0x0EU,0xF4U,0xD5U,0x02U,0x1CU,0x7CU,0x64U,0x6AU,0x98U,
0xE8U,0x4FU,0x60U,0xFEU,0xD3U,0x64U,0xA0U,0x04U,0x45U,0x32U,
};
// this is the xfl for 0.00333333333
uint8_t initial_reward[] = // on key FF, 0..0
{
0x53U,0xCBU,0xD7U,0xA6U,0x25U,0x0DU,0x78U,0x80U
};
uint8_t key[32];
uint8_t account_field[32];
uint8_t zero[32];
#define DONE()\
{\
accept(0,0,(uint32_t)__LINE__);\
}
#define TRACELINE()\
{\
uint8_t out[4];\
out[0] = (__LINE__ >> 24U) & 0xFFU;\
out[1] = (__LINE__ >> 16U) & 0xFFU;\
out[2] = (__LINE__ >> 8U) & 0xFFU;\
out[3] = (__LINE__ >> 0U) & 0xFFU;\
trace(SBUF("Line upto:"), out, 4, 1);\
}
int64_t hook(uint32_t r)
{
_g(1,1);
uint8_t ttbuf[2];
int64_t br = otxn_field(SBUF(ttbuf), sfTransactionType);
uint32_t txntype = ((uint32_t)(ttbuf[0]) << 16U) + ((uint32_t)(ttbuf[1]));
if (txntype != 99) // ttINVOKE
DONE();
// get the account id
ASSERT(otxn_field(account_field + 12, 20, sfAccount) == 20);
uint8_t hook_accid[20];
hook_account(SBUF(hook_accid));
// start of hook proper
int64_t member_count = state(0,0, SBUF(key));
TRACEVAR(member_count);
// initial execution, setup hook
if (member_count == DOESNT_EXIST)
{
etxn_reserve(INIT_MEMBER_COUNT);
// set member count
int8_t imc = INIT_MEMBER_COUNT;
ASSERT(state_set(&imc, 1, SBUF(key))); // member count is on the zero key
// set reward rate
key[0] = 0xFFU;
ASSERT(state_set(SBUF(initial_reward), SBUF(key))); // interest rate is on the the FF, 0...0 key
key[0] = 0;
for (uint32_t i = 0; GUARD(INIT_MEMBER_COUNT), i < INIT_MEMBER_COUNT; ++i)
{
key[31] = i+1;
// 0... X where X is member id started from 1
// maps to the member's account ID
// reverse key
ASSERT(state_set(initial_members + (i * 32) + 12, 20, SBUF(key)) == 20);
// 0, 0... ACCOUNT ID maps to member_id (as above)
// forward key
ASSERT(state_set(key + 31, 1, initial_members + (i * 32), 32) == 1);
// emit initial
uint8_t tx[PREPARE_PAYMENT_SIMPLE_SIZE];
PREPARE_PAYMENT_SIMPLE(tx, INIT_AMOUNT, (initial_members + (i * 32) + 12), 0, 0);
// emit the transaction
uint8_t emithash[32];
int64_t emit_result = emit(SBUF(emithash), SBUF(tx));
ASSERT(emit_result > 0);
TRACEVAR(emit_result);
}
DONE();
}
// outgoing txns allowed
if (BUFFER_EQUAL_20(hook_accid, account_field + 12))
DONE();
// otherwise a normal execution (not initial)
// first let's check if the invoking party is a member
int64_t member_id = state(0,0,SBUF(account_field));
ASSERT(member_id >= 0);
// the only thing you can do is vote for a topic
// so lets process their vote
ASSERT(otxn_slot(1) == 1);
ASSERT(slot_subfield(1, sfHookParameters, 2) == 2);
// first parameter must contain the topic as key and the topic data as value
ASSERT(slot_subarray(2, 0, 2) == 2);
ASSERT(slot_subfield(2, sfHookParameterName, 3) == 3);
ASSERT(slot_subfield(2, sfHookParameterValue, 4) == 4);
uint8_t dump[1024];
uint64_t dumpsize = slot(SBUF(dump), 4);
trace(SBUF("dump"), dump, dumpsize, 1);
int64_t topic = slot(0,0, 3) & 0xFFU; // there's a high "size" byte because it's a VL
TRACEVAR(topic);
ASSERT(topic >= 1 && topic <= 25);
uint8_t topic_data_buffer[44]; // this gives us some bytes on the front to play with to avoid buffer copies
uint8_t* topic_data = topic_data_buffer + 12;;
uint8_t topic_size =
topic == 1 ? 8 :
topic >= 2 && topic <= 5 ? 32 : 20;
// reuse account_field to record vote
account_field[0] = topic;
// read canidate from ttINVOKE parameter
ASSERT(slot(topic_data - 1, topic_size + 1, 4) == topic_size + 1);
*(topic_data - 1) = 0; // this is the size byte for the VL
// get previous vote if any on this topic (1-25)
uint8_t previous_topic_data[32];
int64_t previous_topic_size = state(previous_topic_data, topic_size, SBUF(account_field));
// write vote to voting key
ASSERT(state_set(topic_data, topic_size, SBUF(account_field)) == topic_size);
// check if the vote they're making has already been cast before,
// if it is identical to their existing vote for this topic then just end with tesSUCCESS
if (previous_topic_size == topic_size && BUFFER_EQUAL_32(previous_topic_data, topic_data))
DONE();
// execution to here means the vote is different
// we might have to decrement the old voting if they voted previously
// and we will have to increment the new voting
// decrement old counter
if (previous_topic_size > 0)
{
uint8_t votes = 0;
previous_topic_data[31] = topic;
if (state(&votes, 1, SBUF(previous_topic_data)) && votes > 0)
{
votes--;
ASSERT(state_set(&votes, 1, SBUF(previous_topic_data)));
}
}
// increment new counter
uint8_t votes = 0;
uint8_t last_byte = *(topic_data + 31);
*(topic_data + 31) = topic;
state(&votes, 1, topic_data, 32);
votes++;
ASSERT(state_set(&votes, 1, topic_data, 32));
*(topic_data + 31) = last_byte;
// set this flag if the topic data is all zeros, it's important in some cases
int topic_data_zero = BUFFER_EQUAL_32(topic_data, zero);
TRACEVAR(topic_data_zero);
TRACEVAR(votes);
TRACEVAR(member_count);
TRACEVAR(topic);
// now check if we hit threshold
if (votes == member_count || // 100% required for topics 1 - 5 (interest rate, hooks0-3)
(topic > 5 && votes >= (member_count * 0.8))) // 80% required for membership voting
{
// 100%/80% threshold as needed is reached
// action vote
TRACESTR("Actioning votes");
if (topic == 1)
{
// change reward %
key[0] = 0xFFU;
ASSERT(state_set(topic_data, 8, SBUF(key))); // interest rate is on the the FF, 0...0 key
}
else if (topic <= 5)
{
// set hook hash
uint8_t pos = topic - 2;
// first get the hook ledget object
uint8_t keylet[34];
ASSERT(util_keylet(SBUF(keylet), KEYLET_HOOK, SBUF(hook_accid), 0,0,0,0) == 34);
ASSERT(slot_set(SBUF(keylet), 5) == 5);
// now get the hooks array
ASSERT(slot_subfield(5, sfHooks, 6) == 6);
// now check the entry
if (slot_subarray(6, pos, 7) == 7)
{
// it exists
// check if its identical
uint8_t existing_hook[32];
ASSERT(slot_subfield(7, sfHookHash, 8) == 8);
ASSERT(slot(SBUF(existing_hook), 8) == 32);
// if it is then do nothing
if (BUFFER_EQUAL_32(existing_hook, topic_data))
DONE();
}
// generate the hook definition keylet
ASSERT(util_keylet(SBUF(keylet), KEYLET_HOOK_DEFINITION, topic_data, 32, 0,0,0,0) == 34);
// check if the ledger contains such a hook definition
ASSERT(slot_set(SBUF(keylet), 9) == 9);
// it does so now we can do the emit
etxn_reserve(1);
// RH UPTO: do hookset emit
uint8_t* hookhash =
topic_data_zero
? ((uint8_t*)0xFFFFFFFFU) // if the topic data is all zero then it's a delete operation
: topic_data; // otherwise it's an install operation
uint8_t* h[4] =
{
pos == 0 ? hookhash : 0,
pos == 1 ? hookhash : 0,
pos == 2 ? hookhash : 0,
pos == 3 ? hookhash : 0
};
uint8_t emit_buf[1024];
uint32_t emit_size = 0;
PREPARE_HOOKSET(emit_buf, sizeof(emit_buf), h[0], h[1], h[2], h[3], emit_size);
uint8_t emithash[32];
int64_t emit_result = emit(SBUF(emithash), emit_buf, emit_size);
TRACEVAR(emit_result);
}
else
{
// add / change member
key[31] = topic - 6;
uint8_t previous_member[32];
int previous_present = (state(previous_member + 12, 20, SBUF(key)) == 20);
if (previous_present && !topic_data_zero)
{
// we will not change member count, we're adding a member and removing a member
}
else
{
// decrement member count
ASSERT(member_count > 0); // just bail out if the last member is trying to self remove
if (previous_present)
member_count--;
else
member_count++;
ASSERT(state_set(&member_count, 1, SBUF(zero)) == 1);
}
// we need to garbage collect all their votes
if (previous_present)
{
for (int i = 1; GUARD(25), i <= 25; ++i)
{
previous_member[0] = i;
uint8_t vote_key[32];
if (state(SBUF(vote_key), SBUF(previous_member)) == 32)
{
uint8_t vote_count = 0;
if (state(&vote_count, 1, SBUF(vote_key)) == 1)
{
if (vote_count <= 1)
{
ASSERT(state_set(0,0, SBUF(vote_key)) == 0);
}
else
{
vote_count--;
ASSERT(state_set(&vote_count, 1, SBUF(vote_key)) == 1);
}
}
// delete the entry
ASSERT(state_set(0,0, SBUF(previous_member)) == 0);
}
}
}
if (!topic_data_zero)
{
// add the new member
// reverse key
key[31] = topic - 6;
ASSERT(state_set(topic_data, 20, SBUF(key)) == 20);
// forward key
ASSERT(state_set(key + 31, 1, topic_data_buffer, 32) == 20);
}
// done!
}
}
DONE();
}

View File

@@ -1,717 +0,0 @@
#include "hookapi.h"
#define ASSERT(x)\
if (!(x))\
rollback(SBUF("Govern: Assertion failed."),__LINE__);
#define SEAT_COUNT 20
#define HOOK_MAX 10 // maximum number of hooks on an account
/**
* Xahau Governance Hook
*
* The governance model is a 20 seat round table.
* Each seat may be filled or empty (provided there is at least one filled seat.)
* The primary governance table sits on the genesis account. This is also called the L1 table.
* Seats at this table are called L1s or L1 members.
* At L1, for votes relating to table membership 80% of the filled seats must vote in favour.
* At L1, for votes relating to everything else 100% of the filled seats must vote in favour.
* One or more L1 seats may contain an account that has an L2 governance hook installed on it and is blackholed.
* This is referred to as an L2 table. The seats at the table are called L2s or L2 members.
* There may be multiple L2 tables.
*
* Hook Parameters:
*
* // both table types uses these parameters V
*
* Parameter Name: {'I', 'M', 'C'}
* Parameter Value: Initial Member Count <1 byte>
*
* Parameter Name: {'I', 'S', '\0'}
* Parameter Value: Initial seat #0's member's 20 byte Account ID.
*
* // only L1 table uses these parameters V
*
* Parameter Name: {'I', 'R', 'R'}
* Parameter Value: Initial Reward Rate <8 byte XFL fraction between 0 and 1, LE>
*
* Parameter Name: {'I', 'R', 'D'}
* Parameter Value: Initial Reward Delay <8 byte LE int seconds between rewards>
* ...
*
* Topics:
* 'H[0-9]' - Hook Hash in positions 0-9 <32 byte hash> on genesis
* 'RR' - reward rate <le xfl 8 bytes>
* 'RD' - reward delay <le xfl 8 bytes>
* 'S[0-19]' - who is a governance member occupying that seat <20 byte accid>
*
* Hook State:
* State Key: {0..0, 'M', 'C'}
* State Data: Current member count <1 byte>
*
* State Key: {0..0, 'R', 'R'}
* State Data: Current reward rate <8 byte LE XFL> (L1 table only)
*
* State Key: {0..0, 'R', 'D'}
* State Data: Current reward delay <8 byte LE int> (L1 table only)
*
* State Key: {0..0, '\0 + seat id'}
* State Data: 20 byte account ID for the member who occupies this seat. If absent unoccupied.
*
* State Key: {0..0, <20 byte account id>}
* State Data: Seat number this member occupies <1 byte>
*
* State Key: {'V', 'H|R|S' <topic type>, '\0 + topic id', <layer>, 0..0, <member accid>}
* State Data: A vote by a member for a topic and topic data
*
* State Key: {'C', 'H|R|S' <topic type>, '\0 + topic id', <layer>, 0*, <front truncated topic data>}
* State Data: The number of members who have voted for that topic data and topic combination <1 byte>
*
* Hook Invocation:
* ttINVOKE:
* First time:
* Behaviour: Setup hook, setup initial accounts, end (accept).
*
* Subsequent:
* Behaviour: Vote on a topic, if the votes meet the topic vote threshold, action the topic.
*
* Parameter Name: {'L'}
* Parameter Value: Which layer the vote is inteded for (ONLY L2 TABLES USE THIS PARAMETER)
* { 1 a vote cast by an L2 member about an L1 topic }, or
* { 2 a vote cast by an L2 member about an L2 topic }
*
*
* Parameter Name: {'T'}
* Parameter Value: The topic to vote on <2 bytes>
* { 'S|H' (seat, hook), '\0 + topic id' }, or
* { 'R' (reward), 'R|D' (rate, delay) }
*
* Parameter Name: {'V'}
* Parameter Value: The data to vote for this topic (accid, hook hash, reward rate/delay)
**/
#define SVAR(x) &x, sizeof(x)
#define DONE(x)\
accept(SBUF(x),__LINE__);
#define NOPE(x)\
rollback(SBUF(x), __LINE__);
#define DEBUG 1
// genesis account id
uint8_t genesis[20] =
{0xB5U,0xF7U,0x62U,0x79U,0x8AU,0x53U,0xD5U,0x43U,0xA0U,0x14U,
0xCAU,0xF8U,0xB2U,0x97U,0xCFU,0xF8U,0xF2U,0xF9U,0x37U,0xE8U};
uint8_t zero32[32];
int64_t hook(uint32_t r)
{
_g(1,1);
etxn_reserve(1);
// in debug mode the test case can supply a line number that the hook will then print here.
{
uint8_t ln[2];
if (otxn_param(SBUF(ln), "D", 1) == 2)
{
uint16_t lineno = (((uint16_t)ln[0]) << 8U) + ln[1];
trace_num(SBUF("DBGLN"), lineno);
}
}
int64_t tt = otxn_type();
if (tt != 99) // ttINVOKE only
DONE("Governance: Passing non-Invoke txn. HookOn should be changed to avoid this.");
// get the account id
uint8_t account_field[32];
otxn_field(account_field + 12, 20, sfAccount);
uint8_t hook_accid[32];
hook_account(hook_accid + 12, 20);
// outgoing txns to other hooks allowed
if (BUFFER_EQUAL_20(hook_accid + 12, account_field + 12))
{
uint8_t dest_acc[20];
if (otxn_field(SBUF(dest_acc), sfDestination) == 20 && !BUFFER_EQUAL_20(hook_accid + 12, dest_acc))
DONE("Goverance: Passing outgoing txn.");
}
int64_t is_L1_table = BUFFER_EQUAL_20(hook_accid + 12, genesis);
if (is_L1_table)
trace(SBUF("Governance: Starting governance logic on L1 table."), 0,0,0);
else
trace(SBUF("Governance: Starting governance logic on L2 table."), 0,0,0);
int64_t member_count = state(0,0, "MC", 2);
// initial execution, setup hook
if (member_count == DOESNT_EXIST)
{
// gather hook parameters
uint8_t imc;
uint64_t irr, ird;
if (hook_param(SVAR(imc), "IMC", 3) < 0)
NOPE("Governance: Initial Member Count Parameter missing (IMC).");
TRACEVAR(imc);
// set member count
ASSERT(0 < state_set(SVAR(imc), "MC", 2));
member_count = imc;
TRACEVAR(member_count);
if (imc == 0)
NOPE("Governance: Initial Member Count must be > 0.");
if (imc > SEAT_COUNT)
NOPE("Governance: Initial Member Count must be <= Seat Count (20).");
if (is_L1_table)
{
if (hook_param(SVAR(irr), "IRR", 3) < 0)
NOPE("Governance: Initial Reward Rate Parameter missing (IRR).");
if (hook_param(SVAR(ird), "IRD", 3) < 0)
NOPE("Governance: Initial Reward Delay Parameter miss (IRD).");
if (ird == 0)
NOPE("Governance: Initial Reward Delay must be > 0.");
// set reward rate
ASSERT(0 < state_set(SVAR(irr), "RR", 2));
// set reward delay
ASSERT(0 < state_set(SVAR(ird), "RD", 2));
}
for (uint8_t i = 0; GUARD(SEAT_COUNT), i < member_count; ++i)
{
uint8_t member_acc[20];
uint8_t member_pkey[3] = {'I', 'S', i};
if (hook_param(SBUF(member_acc), member_pkey, 3) != 20)
NOPE("Governance: One or more initial member account ID's is missing");
// 0... X where X is member id started from 1
// maps to the member's account ID
trace(SBUF("Member:"), SBUF(member_acc), 1);
// reverse key
ASSERT(state_set(SBUF(member_acc), SVAR(i)) == 20);
// 0, 0... ACCOUNT ID maps to member_id (as above)
// forward key
ASSERT(state_set(SVAR(i), SBUF(member_acc)) == 1);
}
DONE("Governance: Setup completed successfully.");
}
if (DEBUG)
TRACEVAR(member_count);
// otherwise a normal execution (not initial)
// first let's check if the invoking party is a member
int64_t member_id = state(0,0,account_field + 12, 20);
if (member_id < 0)
NOPE("Governance: You are not currently a governance member at this table.");
// the only thing a member can do is vote for a topic
// so lets process their vote
// { 'S|H|R', '\0 + topicid' }
uint8_t topic[2];
int64_t result = otxn_param(SBUF(topic), "T", 1);
uint8_t t = topic[0]; // topic type
uint8_t n = topic[1]; // number (seats) (or R/D for reward rate/delay)
if (result != 2 || (
t != 'S' && // topic type: seat
t != 'H' && // topic type: hook
t != 'R')) // topic type: reward
NOPE("Governance: Valid TOPIC must be specified as otxn parameter.");
if (t == 'S' && n > (SEAT_COUNT - 1))
NOPE("Governance: Valid seat topics are 0 through 19.");
if (t == 'H' && n > HOOK_MAX)
NOPE("Governance: Valid hook topics are 0 through 9.");
if (t == 'R' && n != 'R' && n != 'D')
NOPE("Governance: Valid reward topics are R (rate) and D (delay).");
// is their vote for the L2 table or the L1 table?
uint8_t l = 1;
if (!is_L1_table)
{
result = otxn_param(&l, 1, "L", 1);
if (result != 1)
NOPE("Governance: Missing L parameter. Which layer are you voting for?");
TRACEVAR(l);
if (l != 1 && l != 2)
NOPE("Governance: Layer parameter must be '1' or '2'.");
}
if (l == 2 && t == 'R')
NOPE("Governance: L2s cannot vote on RR/RD at L2, did you mean to set L=1?");
// RH TODO: validate RR/RD xfl > 0
uint8_t topic_data[56 /* there's a 24 byte pad on the back for later logic */];
uint8_t topic_size =
t == 'H' ? 32 : // hook topics are a 32 byte hook hash
t == 'S' ? 20 : // account topics are a 20 byte account ID
8; // reward topics are an 8 byte le xfl
uint8_t padding = 32 - topic_size;
result = otxn_param(topic_data + padding, topic_size, "V", 1);
if (result != topic_size)
NOPE("Governance: Missing or incorrect size of VOTE data for TOPIC type.");
// set this flag if the topic data is all zeros
int topic_data_zero =
(*((uint64_t*)(topic_data + 0)) == 0) &&
(*((uint64_t*)(topic_data + 8)) == 0) &&
(*((uint64_t*)(topic_data + 16)) == 0) &&
(*((uint64_t*)(topic_data + 24)) == 0);
trace(SBUF("topic_data_raw:"), topic_data, 56, 1);
trace_num(SBUF("topic_padding:"), padding);
trace_num(SBUF("topic_size:"), topic_size);
trace(SBUF("topic_data:"), topic_data + padding, topic_size, 1);
// reuse account_field to create vote key
account_field[0] = 'V';
account_field[1] = t;
account_field[2] = n;
account_field[3] = l;
// get their previous vote if any on this topic
uint8_t previous_topic_data[32];
int64_t previous_topic_size =
state(previous_topic_data + padding, topic_size, SBUF(account_field));
// check if the vote they're making has already been cast before,
// if it is identical to their existing vote for this topic then just end with tesSUCCESS
trace(SBUF("previous_topic_data"), previous_topic_data, 32, 1);
trace(SBUF("topic_data"), topic_data, 32, 1);
trace_num(SBUF("previous_topic_size"), previous_topic_size);
trace_num(SBUF("topic_size"), topic_size);
if (previous_topic_size == topic_size && BUFFER_EQUAL_32(previous_topic_data, topic_data))
DONE("Governance: Your vote is already cast this way for this topic.");
// execution to here means the vote is different
// we might have to decrement the old voting if they voted previously
// and we will have to increment the new voting
// write vote to their voting key
ASSERT(state_set(topic_data + padding, topic_size, SBUF(account_field)) == topic_size);
uint8_t previous_votes = 0;
// decrement old vote counter for this option
if (previous_topic_size > 0)
{
uint8_t votes = 0;
// override the first two bytes to turn it into a vote count key
previous_topic_data[0] = 'C';
previous_topic_data[1] = t;
previous_topic_data[2] = n;
previous_topic_data[3] = l;
ASSERT(state(&votes, 1, SBUF(previous_topic_data)) == 1);
ASSERT(votes > 0);
previous_votes = votes;
votes--;
// delete the state entry if votes hit zero
ASSERT(state_set(votes == 0 ? 0 : &votes, votes == 0 ? 0 : 1, SBUF(previous_topic_data)) >= 0);
}
// increment new counter
uint8_t votes = 0;
{
// we're going to clobber the topic data to turn it into a vote count key
// so store the first bytes
uint64_t saved_data = *((uint64_t*)topic_data);
topic_data[0] = 'C';
topic_data[1] = t;
topic_data[2] = n;
topic_data[3] = l;
state(&votes, 1, topic_data, 32);
votes++;
ASSERT(0 < state_set(&votes, 1, topic_data, 32));
// restore the saved bytes
*((uint64_t*)topic_data) = saved_data;
}
if (DEBUG)
{
TRACEVAR(topic_data_zero);
TRACEVAR(votes);
TRACEVAR(member_count);
trace(SBUF("topic"), topic, 2, 1);
}
// this flag is used to determine if a L2 table should send a "nulling" vote to remove its existing vote
// from the L1 table it sits at.
int64_t lost_majority = 0;
int64_t q80 = member_count * 0.8;
int64_t q51 = member_count * 0.51;
if (q80 < 2)
q80 = 2;
if (q51 < 2)
q51 = 2;
if (is_L1_table || l == 2)
{
if (votes <
(t == 'S'
? q80 // L1s have 80% threshold for membership/seat voting
: member_count)) // L1s have 100% threshold for all other voting
DONE("Governance: Vote record. Not yet enough votes to action.");
}
else // layer 2 table voting on a l1 topic
{
lost_majority = previous_votes >= q51 && votes < q51;
if (lost_majority)
trace(SBUF("Governance: Majority lost, undoing L1 vote..."),0,0,0);
else if (votes < q51)
DONE("Governance: Not yet enough votes to action L1 vote..");
}
// action vote
if (DEBUG)
TRACESTR("Actioning votes");
if (l == 1 && !is_L1_table)
{
uint8_t txn_out[1024];
uint8_t* buf_out = txn_out;
uint32_t cls = (uint32_t)ledger_seq();
_01_02_ENCODE_TT (buf_out, ttINVOKE);
_02_02_ENCODE_FLAGS (buf_out, tfCANONICAL);
_02_04_ENCODE_SEQUENCE (buf_out, 0);
_02_26_ENCODE_FLS (buf_out, cls + 1);
_02_27_ENCODE_LLS (buf_out, cls + 5);
uint8_t* fee_ptr = buf_out;
_06_08_ENCODE_DROPS_FEE (buf_out, 0);
_07_03_ENCODE_SIGNING_PUBKEY_NULL (buf_out);
_08_01_ENCODE_ACCOUNT_SRC (buf_out, hook_accid + 12);
_08_03_ENCODE_ACCOUNT_DST (buf_out, genesis);
int64_t edlen = etxn_details((uint32_t)buf_out, 512);
buf_out += edlen;
/** Parameters:
* F013E017 70180154
* 701902
* <00> <two byte topic code>
* E1E0177018015670
* 19
* <topic len>
* <topic data>
* E1F1
*/
// note wasm is LE and Txns are BE so these large constants are endian flipped
// to undo the flipping on insertion into memory
*((uint64_t*)buf_out) = 0x5401187017E013F0ULL; // parameters array, first parameter preamble
buf_out += 8;
*((uint32_t*)buf_out) = 0x021970UL;
buf_out += 3;
*buf_out++ = t; // topic
*buf_out++ = n;
*((uint64_t*)buf_out) = 0x705601187017E0E1ULL;
buf_out += 8;
*buf_out++ = 0x19U;
// topic data len
*buf_out++ = topic_size;
if (lost_majority)
{
// do nothing, the array already has zeros here
}
else
{
uint64_t* d = (uint64_t*)buf_out;
uint64_t* s = (uint64_t*)(topic_data + padding);
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
*d++ = *s++;
}
buf_out += topic_size;
// topicdata
*((uint16_t*)buf_out) = 0xF1E1U;
int64_t txn_len = buf_out - txn_out;
// populate fee
int64_t fee = etxn_fee_base(txn_out, txn_len);
_06_08_ENCODE_DROPS_FEE (fee_ptr, fee );
trace(SBUF("Governance: Emitting invoke to L1"), txn_out, txn_len, 1);
uint8_t emit_hash[32];
int64_t emit_result = emit(SBUF(emit_hash), txn_out, txn_len);
trace_num(SBUF("Governance: Emit result"), emit_result);
if (emit_result == 32)
accept(SBUF("Governance: Successfully emitted L1 vote."), __LINE__);
NOPE("Governance: L1 vote emission failed.");
}
switch(t)
{
case 'R':
{
// reward topics
int64_t result = state_set(topic_data + padding, topic_size, SBUF(topic));
TRACEVAR(result);
ASSERT(0 < result);
if (n == 'R')
DONE("Governance: Reward rate change actioned!");
DONE("Governance: Reward delay change actioned!");
}
case 'H':
{
// hook topics
// first get the hook ledget object
uint8_t keylet[34];
util_keylet(SBUF(keylet), KEYLET_HOOK, hook_accid + 12, 20, 0,0,0,0);
slot_set(SBUF(keylet), 5);
// now get the hooks array
slot_subfield(5, sfHooks, 6);
// now check the entry
if (slot_subarray(6, n, 7) == 7)
{
// it exists
// check if its identical
uint8_t existing_hook[32];
if (slot_subfield(7, sfHookHash, 8) == 8)
{
ASSERT(slot(SBUF(existing_hook), 8) == 32);
// if it is then do nothing
if (BUFFER_EQUAL_32(existing_hook, topic_data))
DONE("Goverance: Target hook is already the same as actioned hook.");
}
}
// generate the hook definition keylet
if (!topic_data_zero)
{
util_keylet(SBUF(keylet), KEYLET_HOOK_DEFINITION, topic_data, 32, 0,0,0,0);
// check if the ledger contains such a hook definition
if (slot_set(SBUF(keylet), 9) != 9)
NOPE("Goverance: Hook Hash doesn't exist on ledger while actioning hook.");
}
// it does so now we can do the emit
uint8_t* hookhash =
topic_data_zero
? ((uint8_t*)0xFFFFFFFFU) // if the topic data is all zero then it's a delete operation
: topic_data; // otherwise it's an install operation
uint8_t* h[10];
h[n] = hookhash;
uint8_t emit_buf[1024];
uint32_t emit_size = 0;
PREPARE_HOOKSET(emit_buf, sizeof(emit_buf), h, emit_size);
trace(SBUF("EmittedTxn"), emit_buf, emit_size, 1);
uint8_t emithash[32];
int64_t emit_result = emit(SBUF(emithash), emit_buf, emit_size);
if (DEBUG)
TRACEVAR(emit_result);
if (emit_result != 32)
NOPE("Governance: Emit failed during hook actioning.");
trace(SBUF("EmittedTxnHash"), emithash, 32, 1);
DONE("Governance: Hook actioned.");
}
case 'S':
{
// add / change member
uint8_t previous_member[32];
int previous_present = (state(previous_member + 12, 20, &n, 1) == 20);
if (previous_present)
{
trace(SBUF("Previous present==:"), previous_member, 32, 1);
}
if (BUFFER_EQUAL_20((previous_member + 12), (topic_data + 12)))
DONE("Governance: Actioning seat change, but seat already contains the new member.");
int64_t existing_member = state(0,0, topic_data + 12, 20);
int existing_member_moving = existing_member >= 0;
if (existing_member_moving)
trace(SBUF("Governance: Moving existing member to new seat."), 0,0,0);
uint8_t op = ((!previous_present) << 2U) +
(topic_data_zero << 1U) + existing_member_moving;
ASSERT(op != 0b011U && op != 0b111U && op < 8);
// logic table:
// E/!E - seat is empty/filled
// Z/!Z - topic data is zero non zero (zero = member deletion)
// M/!M - topic is an existing member who is moving
//
// E|Z|M
// -+-+-
// 0 0 0 - seat is full, vote is for a member, an existing member is not moving MC
// 0 0 1 - seat is full, vote is for a member, an existing member is moving MC--
// 0 1 0 - seat is full, vote is for deletion, an existing member is not moving MC--
// 0 1 1 - seat is full, vote is for deletion, an existing member is moving (impossible)
// 1 0 0 - seat is empty, vote is for a member, member is not an existing member MC++
// 1 0 1 - seat is empty, vote is for a member, member is an existing member MC
// 1 1 0 - seat is empty, vote is for deletion, not an existing member moving MC
// 1 1 1 - seat is empty, vote is for deletion, an existing member moving (impossible)
TRACEVAR(op);
trace_num(SBUF("E"), !previous_present);
trace_num(SBUF("Z"), topic_data_zero);
trace_num(SBUF("M"), existing_member_moving);
// adjust member count
{
if (op == 0b001U || op == 0b010U)
member_count--;
else if (op == 0b100U)
member_count++;
TRACEVAR(previous_present);
TRACEVAR(topic_data_zero);
TRACEVAR(member_count);
ASSERT(member_count > 1); // just bail out if the second last member is being removed
uint8_t mc = member_count;
ASSERT(state_set(&mc, 1, "MC", 2) == 1);
}
// if an existing member is moving we need to delete them before re-adding them
if (existing_member_moving)
{
// delete the old member
// reverse key
uint8_t m = (uint8_t)existing_member;
ASSERT(state_set(0,0, &m, 1) == 0);
// forward key
ASSERT(state_set(0, 0, topic_data + 12, 20) == 0);
}
// we need to garbage collect all their votes
if (previous_present)
{
previous_member[0] = 'V';
for (int i = 1; GUARD(32), i < 32; ++i)
{
previous_member[1] = i < 2 ? 'R' : i < 12 ? 'H' : 'S';
previous_member[2] =
i == 0 ? 'R' :
i == 1 ? 'D' :
i < 12 ? i - 2 :
i - 12;
uint8_t vote_key[32];
if (state(SBUF(vote_key), SBUF(previous_member)) == 32)
{
uint8_t vote_count = 0;
// find and decrement the vote counter
vote_key[0] = 'C';
vote_key[1] = previous_member[1];
vote_key[2] = previous_member[2];
if (state(&vote_count, 1, SBUF(vote_key)) == 1)
{
// if we're down to 1 vote then delete state
if (vote_count <= 1)
{
ASSERT(state_set(0,0, SBUF(vote_key)) == 0);
trace_num(SBUF("Decrement vote count deleted"), vote_count);
}
else // otherwise decrement
{
vote_count--;
ASSERT(state_set(&vote_count, 1, SBUF(vote_key)) == 1);
trace_num(SBUF("Decrement vote count to"), vote_count);
}
}
// delete the vote entry
ASSERT(state_set(0,0, SBUF(previous_member)) == 0);
trace(SBUF("Vote entry deleted"), vote_key, 32, 1);
}
}
// delete the old member
// reverse key
ASSERT(state_set(0,0, &n, 1) == 0);
// forward key
ASSERT(state_set(0, 0, previous_member + 12, 20) == 0);
}
if (!topic_data_zero)
{
// add the new member
// reverse key
ASSERT(state_set(topic_data + 12, 20, &n, 1) == 20);
// forward key
ASSERT(state_set(&n, 1, topic_data + 12, 20) == 1);
}
DONE("Governance: Action member change.");
}
}
rollback(SBUF("Governance: Internal logic error."), __LINE__);
}

View File

@@ -36,7 +36,6 @@
#define KEYLET_EMITTED 22
#define KEYLET_NFT_OFFER 23
#define KEYLET_HOOK_DEFINITION 24
#define KEYLET_HOOK_STATE_DIR 25
#define COMPARE_EQUAL 1U
#define COMPARE_LESS 2U
@@ -46,6 +45,5 @@
#include "extern.h"
#include "sfcodes.h"
#include "macro.h"
#include "tts.h"
#endif

View File

@@ -136,7 +136,11 @@ int out_len = 0;\
*(((uint64_t*)(buf1)) + 0) == *(((uint64_t*)(buf2)) + 0) &&\
*(((uint64_t*)(buf1)) + 1) == *(((uint64_t*)(buf2)) + 1) &&\
*(((uint64_t*)(buf1)) + 2) == *(((uint64_t*)(buf2)) + 2) &&\
*(((uint64_t*)(buf1)) + 3) == *(((uint64_t*)(buf2)) + 3))
*(((uint64_t*)(buf1)) + 3) == *(((uint64_t*)(buf2)) + 3) &&\
*(((uint64_t*)(buf1)) + 4) == *(((uint64_t*)(buf2)) + 4) &&\
*(((uint64_t*)(buf1)) + 5) == *(((uint64_t*)(buf2)) + 5) &&\
*(((uint64_t*)(buf1)) + 6) == *(((uint64_t*)(buf2)) + 6) &&\
*(((uint64_t*)(buf1)) + 7) == *(((uint64_t*)(buf2)) + 7))
// when using this macro buf1len may be dynamic but buf2len must be static
@@ -261,6 +265,10 @@ int out_len = 0;\
if (i < 0) buf[0] |= 0x80U;\
}
#define ttPAYMENT 0
#define ttCHECK_CREATE 16
#define ttNFT_ACCEPT_OFFER 29
#define ttHOOK_SET 22
#define tfCANONICAL 0x80000000UL
#define atACCOUNT 1U
@@ -483,11 +491,16 @@ int out_len = 0;\
#define _07_03_ENCODE_SIGNING_PUBKEY(buf_out, pkey )\
ENCODE_SIGNING_PUBKEY(buf_out, pkey );
#define ENCODE_SIGNING_PUBKEY_NULL_SIZE 2
#define ENCODE_SIGNING_PUBKEY_NULL_SIZE 35
#define ENCODE_SIGNING_PUBKEY_NULL(buf_out )\
{\
*buf_out++ = 0x73U;\
*buf_out++ = 0x00U;\
buf_out[0] = 0x73U;\
buf_out[1] = 0x21U;\
*(uint64_t*)(buf_out+2) = 0;\
*(uint64_t*)(buf_out+10) = 0;\
*(uint64_t*)(buf_out+18) = 0;\
*(uint64_t*)(buf_out+25) = 0;\
buf_out += ENCODE_SIGNING_PUBKEY_NULL_SIZE;\
}
#define _07_03_ENCODE_SIGNING_PUBKEY_NULL(buf_out )\
@@ -516,21 +529,17 @@ int out_len = 0;\
}\
else\
{\
*buf_out++ = 0x50U; /* HookHash */\
*buf_out++ = 0x1FU;\
uint64_t* d = (uint64_t*)buf_out;\
uint64_t* s = (uint64_t*)hook0;\
*d++ = *s++;\
*d++ = *s++;\
*d++ = *s++;\
*d++ = *s++;\
buf_out+=32;\
*buf_out++ = 0x1FU; /* HookHash */\
*buf_out++ = *hook0++; *buf_out++ = *hook0++; *buf_out++ = *hook0++; *buf_out++ = *hook0++; \
*buf_out++ = *hook0++; *buf_out++ = *hook0++; *buf_out++ = *hook0++; *buf_out++ = *hook0++; \
*buf_out++ = *hook0++; *buf_out++ = *hook0++; *buf_out++ = *hook0++; *buf_out++ = *hook0++; \
*buf_out++ = *hook0++; *buf_out++ = *hook0++; *buf_out++ = *hook0++; *buf_out++ = *hook0++; \
}\
}\
*buf_out++ = 0xE1U;\
}
#define PREPARE_HOOKSET(buf_out_master, maxlen, h, sizeout)\
#define PREPARE_HOOKSET(buf_out_master, maxlen, hash0, hash1, hash2, hash3, sizeout)\
{\
uint8_t* buf_out = (buf_out_master); \
uint8_t acc[20]; \
@@ -549,16 +558,10 @@ int out_len = 0;\
int64_t edlen = etxn_details((uint32_t)buf_out, remaining_size); \
buf_out += edlen; \
*buf_out++ = 0xFBU; /* hook array start */ \
_0E_0E_ENCODE_HOOKOBJ (buf_out, h[0]); \
_0E_0E_ENCODE_HOOKOBJ (buf_out, h[1]); \
_0E_0E_ENCODE_HOOKOBJ (buf_out, h[2]); \
_0E_0E_ENCODE_HOOKOBJ (buf_out, h[3]); \
_0E_0E_ENCODE_HOOKOBJ (buf_out, h[4]); \
_0E_0E_ENCODE_HOOKOBJ (buf_out, h[5]); \
_0E_0E_ENCODE_HOOKOBJ (buf_out, h[6]); \
_0E_0E_ENCODE_HOOKOBJ (buf_out, h[7]); \
_0E_0E_ENCODE_HOOKOBJ (buf_out, h[8]); \
_0E_0E_ENCODE_HOOKOBJ (buf_out, h[9]); \
_0E_0E_ENCODE_HOOKOBJ (buf_out, hash0); \
_0E_0E_ENCODE_HOOKOBJ (buf_out, hash1); \
_0E_0E_ENCODE_HOOKOBJ (buf_out, hash2); \
_0E_0E_ENCODE_HOOKOBJ (buf_out, hash3); \
*buf_out++ = 0xF1U; /* hook array end */ \
sizeout = (buf_out - (buf_out_master)); \
int64_t fee = etxn_fee_base(buf_out_master, sizeout); \

View File

@@ -1,172 +0,0 @@
all: reward govern mint
accept:
wasmcc accept.c -o accept.wasm -Oz -Wl,--allow-undefined -I../
hook-cleaner accept.wasm
reward:
wasmcc reward.c -o reward.wasm -Oz -Wl,--allow-undefined -I../
wasm-opt reward.wasm -o reward.wasm \
--shrink-level=100000000 \
--coalesce-locals-learning \
--vacuum \
--merge-blocks \
--merge-locals \
--flatten \
--ignore-implicit-traps \
-ffm \
--const-hoisting \
--code-folding \
--code-pushing \
--dae-optimizing \
--dce \
--simplify-globals-optimizing \
--simplify-locals-nonesting \
--reorder-locals \
--rereloop \
--precompute-propagate \
--local-cse \
--remove-unused-brs \
--memory-packing \
-c \
--avoid-reinterprets \
-Oz
hook-cleaner reward.wasm
wasm-opt reward.wasm -o reward.wasm \
--shrink-level=100000000 \
--coalesce-locals-learning \
--vacuum \
--merge-blocks \
--merge-locals \
--flatten \
--ignore-implicit-traps \
-ffm \
--const-hoisting \
--code-folding \
--code-pushing \
--dae-optimizing \
--dce \
--simplify-globals-optimizing \
--simplify-locals-nonesting \
--reorder-locals \
--rereloop \
--precompute-propagate \
--local-cse \
--remove-unused-brs \
--memory-packing \
-c \
--avoid-reinterprets \
-Oz
hook-cleaner reward.wasm
guard_checker reward.wasm
govern:
wasmcc govern.c -o govern.wasm -Oz -Wl,--allow-undefined -I../
wasm-opt govern.wasm -o govern.wasm \
--shrink-level=100000000 \
--coalesce-locals-learning \
--vacuum \
--merge-blocks \
--merge-locals \
--flatten \
--ignore-implicit-traps \
-ffm \
--const-hoisting \
--code-folding \
--code-pushing \
--dae-optimizing \
--dce \
--simplify-globals-optimizing \
--simplify-locals-nonesting \
--reorder-locals \
--rereloop \
--precompute-propagate \
--local-cse \
--remove-unused-brs \
--memory-packing \
-c \
--avoid-reinterprets \
-Oz
hook-cleaner govern.wasm
wasm-opt govern.wasm -o govern.wasm \
--shrink-level=100000000 \
--coalesce-locals-learning \
--vacuum \
--merge-blocks \
--merge-locals \
--flatten \
--ignore-implicit-traps \
-ffm \
--const-hoisting \
--code-folding \
--code-pushing \
--dae-optimizing \
--dce \
--simplify-globals-optimizing \
--simplify-locals-nonesting \
--reorder-locals \
--rereloop \
--precompute-propagate \
--local-cse \
--remove-unused-brs \
--memory-packing \
-c \
--avoid-reinterprets \
-Oz
hook-cleaner govern.wasm
guard_checker govern.wasm
mint:
wasmcc mint.c -o mint.wasm -Oz -Wl,--allow-undefined -I../
wasm-opt mint.wasm -o mint.wasm \
--shrink-level=100000000 \
--coalesce-locals-learning \
--vacuum \
--merge-blocks \
--merge-locals \
--flatten \
--ignore-implicit-traps \
-ffm \
--const-hoisting \
--code-folding \
--code-pushing \
--dae-optimizing \
--dce \
--simplify-globals-optimizing \
--simplify-locals-nonesting \
--reorder-locals \
--rereloop \
--precompute-propagate \
--local-cse \
--remove-unused-brs \
--memory-packing \
-c \
--avoid-reinterprets \
-Oz
hook-cleaner mint.wasm
wasm-opt mint.wasm -o mint.wasm \
--shrink-level=100000000 \
--coalesce-locals-learning \
--vacuum \
--merge-blocks \
--merge-locals \
--flatten \
--ignore-implicit-traps \
-ffm \
--const-hoisting \
--code-folding \
--code-pushing \
--dae-optimizing \
--dce \
--simplify-globals-optimizing \
--simplify-locals-nonesting \
--reorder-locals \
--rereloop \
--precompute-propagate \
--local-cse \
--remove-unused-brs \
--memory-packing \
-c \
--avoid-reinterprets \
-Oz
hook-cleaner mint.wasm
guard_checker mint.wasm
nftoken:
wasmcc nftoken.c -o nftoken.wasm -Oz -Wl,--allow-undefined -I../
hook-cleaner nftoken.wasm

View File

@@ -1,164 +0,0 @@
// This hook just tests GenesisMint transactor, it is not for production use
#include "hookapi.h"
#define ASSERT(x)\
if (!(x))\
rollback(SBUF("Reward: Assertion failure."),__LINE__);
#define DEBUG 1
uint8_t txn_mint[13850] =
{
/* size,upto */
/* 3, 0 */ 0x12U, 0x00U, 0x60U, /* tt = GenesisMint */
/* 5, 3 */ 0x22U, 0x80U, 0x00U, 0x00U, 0x00U, /* flags = tfCanonical */
/* 5, 8 */ 0x24U, 0x00U, 0x00U, 0x00U, 0x00U, /* sequence = 0 */
/* 6, 13 */ 0x20U, 0x1AU, 0x00U, 0x00U, 0x00U, 0x00U, /* first ledger seq */
/* 6, 19 */ 0x20U, 0x1BU, 0x00U, 0x00U, 0x00U, 0x00U, /* last ledger seq */
/* 9, 25 */ 0x68U, 0x40U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, /* fee */
/* 35, 34 */ 0x73U, 0x21U, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* pubkey */
/* 22, 69 */ 0x81U, 0x14U, 0xB5U,0xF7U,0x62U,0x79U,0x8AU,0x53U,0xD5U,0x43U,0xA0U,0x14U,
0xCAU,0xF8U,0xB2U,0x97U,0xCFU,0xF8U,0xF2U,0xF9U,0x37U,0xE8U, /* src acc */
/* 116, 91 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* emit detail */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 207, ... */ 0xF0U, 0x60U, /* gen mints arr */
/* 34 bytes per entries + 1 tail byte
E060
61
4111111111111111 // amount
8114
1234567891234567891234567891234567891234 // account
E1
... repeat
F1 // tail byte
*
* */
// 210 bytes + 34 bytes per entry * number of entries + any alignment padding desired
};
uint8_t entry[40] = {
/* 0, 2 */ 0xE0U, 0x60U, // obj start
/* 2, 1 */ 0x61U, // amount header
/* 3, 8 */ 0,0,0,0,0,0,0,0, // amount payload
/* 11, 2 */ 0x83U, 0x14U, // account header
/* 13, 20 */ 0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0, // account payload
/* 33, 1 */ 0xE1U // obj end
};
#define ENTRY_DROPS(drops_tmp)\
{\
uint8_t* b = entry + 3U;\
*b++ = 0b01000000 + (( drops_tmp >> 56 ) & 0b00111111 );\
*b++ = (drops_tmp >> 48) & 0xFFU;\
*b++ = (drops_tmp >> 40) & 0xFFU;\
*b++ = (drops_tmp >> 32) & 0xFFU;\
*b++ = (drops_tmp >> 24) & 0xFFU;\
*b++ = (drops_tmp >> 16) & 0xFFU;\
*b++ = (drops_tmp >> 8) & 0xFFU;\
*b++ = (drops_tmp >> 0) & 0xFFU;\
}
#define BE_DROPS(drops)\
{\
uint64_t drops_tmp = drops;\
uint8_t* b = (uint8_t*)&drops;\
*b++ = 0b01000000 + (( drops_tmp >> 56 ) & 0b00111111 );\
*b++ = (drops_tmp >> 48) & 0xFFU;\
*b++ = (drops_tmp >> 40) & 0xFFU;\
*b++ = (drops_tmp >> 32) & 0xFFU;\
*b++ = (drops_tmp >> 24) & 0xFFU;\
*b++ = (drops_tmp >> 16) & 0xFFU;\
*b++ = (drops_tmp >> 8) & 0xFFU;\
*b++ = (drops_tmp >> 0) & 0xFFU;\
}
//uint8_t preamble[4] = {0xE0U, 0x60U, 0x61U, 0x00};
int64_t hook(uint32_t r)
{
etxn_reserve(1);
_g(1,1);
// emit the txn
uint64_t drops = 12345;
ENTRY_DROPS(drops);
#define COUNT 400
uint8_t* upto = txn_mint + 209U;
uint8_t* end = upto + (34U * COUNT);
for (; GUARD(COUNT), upto < end; upto += 34)
{
uint64_t* d = (uint64_t*)upto;
uint64_t* s = (uint64_t*)entry;
*d++ = *s++;
*d++ = *s++;
//*d++ = *s++;
//*d++ = *s++;
*(d+2) = *(s+2);
otxn_field(upto + 13, 20, sfDestination);
*((uint32_t*)(upto + 13)) = upto;
/*
*
*upto++ = 0xE0U; // obj start
*upto++ = 0x60U;
*upto++ = 0x61U; // amt
*((uint32_t*)upto) = preamble;
upto += 3;
*((uint64_t*)upto) = drops;
upto += 8;
*upto++ = 0x83U; // acc
*upto++ = 0x14U;
*((uint16_t*)upto) = preamble2;
upto += 2;
*/
}
*upto++ = 0xF1U; // array end
etxn_details(txn_mint + 91, 116);
int64_t fee = etxn_fee_base(txn_mint, upto - txn_mint);
BE_DROPS(fee);
*((uint64_t*)(txn_mint + 26)) = fee;
int64_t seq = ledger_seq() + 1;
txn_mint[15] = (seq >> 24U) & 0xFFU;
txn_mint[16] = (seq >> 16U) & 0xFFU;
txn_mint[17] = (seq >> 8U) & 0xFFU;
txn_mint[18] = seq & 0xFFU;
seq += 4;
txn_mint[21] = (seq >> 24U) & 0xFFU;
txn_mint[22] = (seq >> 16U) & 0xFFU;
txn_mint[23] = (seq >> 8U) & 0xFFU;
txn_mint[24] = seq & 0xFFU;
trace(SBUF("emit:"), txn_mint, upto-txn_mint, 1);
uint8_t emithash[32];
int64_t emit_result = emit(SBUF(emithash), txn_mint, upto - txn_mint);
if (DEBUG)
TRACEVAR(emit_result);
if (emit_result < 0)
rollback(SBUF("MintTest: Emit failed."), __LINE__);
accept(SBUF("MintTest: Emitted txn successfully."), __LINE__);
}

View File

@@ -1,213 +0,0 @@
#include <stdint.h>
#include "hookapi.h"
#define SVAR(x) &x, sizeof(x)
#define SBUF(x) (x), sizeof(x)
#define NOPE(x)\
{\
return rollback((x), sizeof(x), __LINE__);\
}
#define ttNFTOKEN_BURN 26
#define ttIMPORT 97
#define ttURITOKEN_MINT 45
int64_t hook(uint32_t r)
{
_g(1,1);
uint8_t hook_acc[20];
hook_account(SBUF(hook_acc));
uint8_t otxn_acc[20];
otxn_field(SBUF(otxn_acc), sfAccount);
// outgoing
if (BUFFER_EQUAL_20(hook_acc, otxn_acc))
accept(SBUF("NFTImport: Passing outgoing txn."), __LINE__);
if (otxn_type() != ttIMPORT)
accept(SBUF("NFTImport: Passing non ttIMPORT txn."), otxn_type());
int64_t retval = xpop_slot(1,2);
if (retval <= 0)
NOPE("Failed to slot xpop");
#define tx_slot 1
#define meta_slot 2
trace_num("Slotted xpop", 12, retval);
uint8_t dump1[2048];
uint8_t dump2[2048];
int64_t len1 = slot(dump1, sizeof(dump1), tx_slot);
int64_t len2 = slot(dump2, sizeof(dump2), meta_slot);
trace("tx", 2, dump1, len1, 1);
trace("meta", 4, dump2, len2, 1);
if (slot_subfield(meta_slot, sfTransactionResult, 3) != 3)
NOPE("Failed to slot transaction result");
uint8_t tr;
if (slot(SVAR(tr), 3) != 1)
NOPE("Failed to dump transaction result");
trace_num(SBUF("Inner Transaction Result:"), tr);
if (tr != 0)
NOPE("Inner Transaction Result not tesSUCCESS (0).");
// execution to here means tesSUCCESS on inner
if (slot_subfield(tx_slot, sfTransactionType, 4) != 4)
NOPE("Could not slot transaction type");
uint8_t tt_buf[2];
if (slot(SBUF(tt_buf), 4) != 2)
NOPE("Could not dump transaction type");
uint16_t tt = UINT16_FROM_BUF(tt_buf);
if (tt != ttNFTOKEN_BURN)
NOPE("Only NFTokenBurn is accepted");
// go track down the URI of the token (this is a huge pain, has to be done through metadata)
//
#define nodes 5
if (slot_subfield(meta_slot, sfAffectedNodes, nodes) != nodes)
NOPE("Could not slot sfAffectedNodes");
uint8_t dump4[1024];
trace(SBUF("slot nodes"), dump4, slot(SBUF(dump4), nodes), 1);
int64_t count = slot_count(nodes);
if (count > 5) count = 5;
int64_t found;
for (int i = 0; GUARD(5), i < count; ++i)
{
if (slot_subarray(nodes, i, 6) != 6)
break;
if (slot_subfield(6, sfLedgerEntryType, 7) != 7)
NOPE("Could not slot LedgerEntryType");
uint8_t buf[2];
slot(SVAR(buf), 7);
if (UINT16_FROM_BUF(buf) == 0x0050U)
{
found = 1;
break;
}
}
if (!found)
NOPE("Could not find NFTokenPage in xpop metadata");
if (slot_subfield(6, sfPreviousFields, 6) != 6 && slot_subfield(6, sfFinalFields, 6) != 6)
NOPE("Could not slot sfPreviousFields");
if (slot_subfield(6, sfNFTokens, 6) != 6)
NOPE("Could not slot sfNFTokens");
count = slot_count(6);
if (count > 32) count = 32;
trace_num(SBUF("Modified node count:"), count);
uint8_t burned_tid[32];
if (slot_subfield(tx_slot, sfNFTokenID, 7) != 7 || slot(SBUF(burned_tid), 7) != 32)
NOPE("Xpop txn did not contain valid nftokenid");
uint8_t uri[256];
int64_t urilen;
found = 0;
for (int i = 0; GUARD(32), i < count; ++i)
{
if (slot_subarray(6, i, 7) != 7)
break;
{
uint8_t dump4[1024];
int64_t len = slot(SBUF(dump4), 7);
trace(SBUF("dump4"), dump4, len, 1);
}
uint8_t tid[32];
int64_t r;
if ((r=slot_subfield(7, sfNFTokenID, 8)) != 8)
{
trace_num(SBUF("r"), r);
break;
}
slot(SBUF(tid), 8);
if (slot_subfield(7, sfURI, 8) != 8)
continue;
urilen = slot(SBUF(uri), 8);
trace(SBUF("uri: "), uri, urilen, 1);
trace(SBUF("tid1"), tid, 32, 1);
trace(SBUF("tid2"), burned_tid, 32, 1);
found = BUFFER_EQUAL_32(tid, burned_tid);
if (found)
{
trace(SBUF("found"), 0,0,0);
found = 1;
break;
}
}
if (!found)
NOPE("Could not find the NFTokenID in the metadata");
trace(SBUF("URI from xpop: "), uri, urilen, 1);
etxn_reserve(1);
uint8_t txn_buf[1024];
int64_t txn_len;
{
uint8_t* buf_out = txn_buf;
uint32_t cls = (uint32_t)ledger_seq();
_01_02_ENCODE_TT (buf_out, ttURITOKEN_MINT );
_02_02_ENCODE_FLAGS (buf_out, tfCANONICAL );
_02_04_ENCODE_SEQUENCE (buf_out, 0 );
_02_26_ENCODE_FLS (buf_out, cls + 1 );
_02_27_ENCODE_LLS (buf_out, cls + 5 );
_06_01_ENCODE_DROPS_AMOUNT (buf_out, 0 );
uint8_t* fee_ptr = buf_out;
_06_08_ENCODE_DROPS_FEE (buf_out, 0 );
_07_03_ENCODE_SIGNING_PUBKEY_NULL (buf_out );
// URI
*buf_out++ = 0x75U;
for (int i = 0; GUARD(32), i < 32; ++i)
*(((uint64_t*)buf_out) + i) = *(((uint64_t*)uri) + i);
buf_out += urilen;
_08_01_ENCODE_ACCOUNT_SRC (buf_out, hook_acc );
_08_03_ENCODE_ACCOUNT_DST (buf_out, otxn_acc );
int64_t edlen = etxn_details((uint32_t)buf_out, 512);
trace_num(SBUF("edlen"), edlen);
buf_out += edlen;
txn_len = buf_out - txn_buf;
int64_t fee = etxn_fee_base(txn_buf, txn_len);
_06_08_ENCODE_DROPS_FEE (fee_ptr, fee );
}
trace(SBUF("emit txn"), txn_buf, txn_len, 1);
uint8_t etxid[32];
if (emit(SBUF(etxid), txn_buf, txn_len) < 0)
NOPE("Emission failed");
trace(SBUF("Emission success"), etxid, 32, 1);
return accept(0UL, 0UL, __LINE__);
}

View File

@@ -1,69 +0,0 @@
//reworked version of https://github.com/RichardAH/xrpl-tools/blob/master/validator-address-tool/vatool.js
const rac = require('ripple-address-codec');
const { XrplClient } = require('xrpl-client');
const { sign, derive, XrplDefinitions } = require('xrpl-accountlib');
const ed = require('elliptic').eddsa;
const ec = new ed('ed25519');
if (process.argv.length < 6)
{
console.log("Rekey validator address tool");
console.log("Usage: node " + process.argv[1] + " validator_secret_key raddr_to_rekey_to fee_drops network_id [ws://localhost:6005]");
process.exit(1);
}
const sk = (()=>
{
return 'ED' +
Buffer.from(ec.keyFromSecret(rac.codec._codec.decode(process.argv[2]).slice(1,33)).secret()).
toString('hex').toUpperCase();
})();
console.log(sk)
const account = derive.privatekey(sk);
console.log(account);
const endpoint = process.argv.length >= 7 ? process.argv[6] : 'ws://localhost:6005';
console.log("endpoint:", endpoint);
const client = new XrplClient(endpoint);
(async () => {
const liveDefinitions = await client.send({ "command": "server_definitions" })
const definitions = new XrplDefinitions(liveDefinitions)
const ledgerInfo = await client.send({
command: 'ledger'
})
// console.log(ledgerInfo)
const accountInfo = await client.send({
command: 'account_info',
account: account.address,
})
const txJsonPreSigning = {
TransactionType: 'SetRegularKey',
Account: account.address,
RegularKey: process.argv[3],
Fee: process.argv[4] + '',
LastLedgerSequence: Number(ledgerInfo.closed.ledger.seqNum) + 5,
Sequence: accountInfo.account_data.Sequence,
NetworkID: process.argv[5]
};
const signed = sign(txJsonPreSigning, account, definitions);
console.log('Tx', signed.id);
console.log(signed.signedTransaction);
const submit = await client.send({
command: 'submit',
tx_blob: signed.signedTransaction
});
console.log(submit);
})();

View File

@@ -1,345 +0,0 @@
#include "hookapi.h"
#define DEFAULT_REWARD_DELAY 6199553087261802496ULL
#define DEFAULT_REWARD_RATE 6038156834009797973ULL
//0.00333333333f
#define L1SEATS 20U
#define MAXUNL 128U
#define SVAR(x) &(x), sizeof(x)
#define ASSERT(x)\
if (!(x))\
rollback(SBUF("Reward: Assertion failure."),__LINE__);
#define DEBUG 1
uint8_t txn_mint[928] =
{
/* size,upto */
/* 3, 0 */ 0x12U, 0x00U, 0x60U, /* tt = GenesisMint */
/* 5, 3 */ 0x22U, 0x80U, 0x00U, 0x00U, 0x00U, /* flags = tfCanonical */
/* 5, 8 */ 0x24U, 0x00U, 0x00U, 0x00U, 0x00U, /* sequence = 0 */
/* 6, 13 */ 0x20U, 0x1AU, 0x00U, 0x00U, 0x00U, 0x00U, /* first ledger seq */
/* 6, 19 */ 0x20U, 0x1BU, 0x00U, 0x00U, 0x00U, 0x00U, /* last ledger seq */
/* 9, 25 */ 0x68U, 0x40U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, /* fee */
/* 35, 34 */ 0x73U, 0x21U, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* pubkey */
/* 22, 69 */ 0x81U, 0x14U, 0xB5U,0xF7U,0x62U,0x79U,0x8AU,0x53U,0xD5U,0x43U,0xA0U,0x14U,
0xCAU,0xF8U,0xB2U,0x97U,0xCFU,0xF8U,0xF2U,0xF9U,0x37U,0xE8U, /* src acc */
/* 116, 91 */ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* emit detail */
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
/* 207, ... */ 0xF0U, 0x60U, /* gen mints arr */
/* 34 bytes per entries + 1 tail byte
E060
61
4111111111111111 // amount
8114
1234567891234567891234567891234567891234 // account
E1
... repeat
F1 // tail byte
*
* */
// 210 bytes + 34 bytes per entry * number of entries + any alignment padding desired
};
uint8_t template[40] = {
/* 0, 2 */ 0xE0U, 0x60U, // obj start
/* 2, 1 */ 0x61U, // amount header
/* 3, 8 */ 0,0,0,0,0,0,0,0, // amount payload
/* 11, 2 */ 0x83U, 0x14U, // account header
/* 13, 20 */ 0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0, // account payload
/* 33, 1 */ 0xE1U // obj end
};
#define TEMPLATE_DROPS(drops_tmp)\
{\
uint8_t* b = template + 3U;\
*b++ = 0b01000000 + (( drops_tmp >> 56 ) & 0b00111111 );\
*b++ = (drops_tmp >> 48) & 0xFFU;\
*b++ = (drops_tmp >> 40) & 0xFFU;\
*b++ = (drops_tmp >> 32) & 0xFFU;\
*b++ = (drops_tmp >> 24) & 0xFFU;\
*b++ = (drops_tmp >> 16) & 0xFFU;\
*b++ = (drops_tmp >> 8) & 0xFFU;\
*b++ = (drops_tmp >> 0) & 0xFFU;\
}
#define BE_DROPS(drops)\
{\
uint64_t drops_tmp = drops;\
uint8_t* b = (uint8_t*)&drops;\
*b++ = 0b01000000 + (( drops_tmp >> 56 ) & 0b00111111 );\
*b++ = (drops_tmp >> 48) & 0xFFU;\
*b++ = (drops_tmp >> 40) & 0xFFU;\
*b++ = (drops_tmp >> 32) & 0xFFU;\
*b++ = (drops_tmp >> 24) & 0xFFU;\
*b++ = (drops_tmp >> 16) & 0xFFU;\
*b++ = (drops_tmp >> 8) & 0xFFU;\
*b++ = (drops_tmp >> 0) & 0xFFU;\
}
uint8_t member_count_key[2] = {'M', 'C'};
uint8_t unlreport_keylet[34] =
{
0,0,0x61U,0xE3U,0x2EU,0x7AU,0x24U,0xA2U,0x38U,0xF1U,0xC6U,0x19U,
0xD5U,0xF9U,0xDDU,0xCCU,0x41U,0xA9U,0x4BU,0x33U,0xB6U,0x6CU,
0x01U,0x63U,0xF7U,0xEFU,0xCCU,0x8AU,0x19U,0xC9U,0xFDU,0x6FU,
0x28U,0xDCU
};
uint8_t msg_buf[] = "You must wait 0000000 seconds";
int64_t hook(uint32_t r)
{
etxn_reserve(1);
_g(1,1);
// only process ttCLAIM_REWARD
if (otxn_type() != 98)
accept(SBUF("Reward: Passing non-claim txn"), __LINE__);
uint8_t otxn_acc[20];
uint8_t hook_acc[20];
// get the account id
otxn_field(SBUF(otxn_acc), sfAccount);
// write the hook account into the txn template
hook_account(SBUF(hook_acc));
if (BUFFER_EQUAL_20(hook_acc, otxn_acc))
accept(SBUF("Reward: Passing outgoing txn"), __LINE__);
// the default rate and delay are used if somehow the keys are missing from hook state (graceful failure)
int64_t xfl_rr = DEFAULT_REWARD_RATE;
int64_t xfl_rd = DEFAULT_REWARD_DELAY;
// load state if it exists (which it should)
state(&xfl_rr, 8, "RR", 2);
state(&xfl_rd, 8, "RD", 2);
// if either of these is 0 that's disabled
if (xfl_rr <= 0 || xfl_rd <= 0 )
rollback(SBUF("Reward: Rewards are disabled by governance."), __LINE__);
int64_t required_delay = float_int(xfl_rd, 0, 0);
if (required_delay < 0 || float_sign(xfl_rr) != 0 ||
float_compare(xfl_rr, float_one(), COMPARE_GREATER) ||
float_compare(xfl_rd, float_one(), COMPARE_GREATER))
rollback(SBUF("Reward: Rewards incorrectly configured by governance or unrecoverable error."), __LINE__);
// get the account root keylet
uint8_t kl[34];
util_keylet(SBUF(kl), KEYLET_ACCOUNT, SBUF(otxn_acc), 0,0,0,0);
// slot the account root, this can't fail
slot_set(SBUF(kl), 1);
// this is a first time claim reward has run and will setup these fields
if (slot_subfield(1, sfRewardAccumulator, 2) != 2)
accept(SBUF("Reward: Passing reward setup txn"), __LINE__);
// this is an actual claim reward
slot_subfield(1, sfRewardLgrFirst, 3);
slot_subfield(1, sfRewardLgrLast, 4);
slot_subfield(1, sfBalance, 5);
slot_subfield(1, sfRewardTime, 6);
int64_t time = slot(0,0,6);
int64_t time_elapsed = ledger_last_time() - time;
if (time_elapsed < required_delay)
{
//2 600 000
time_elapsed = required_delay - time_elapsed;
msg_buf[14] += (time_elapsed / 1000000) % 10;
msg_buf[15] += (time_elapsed / 100000) % 10;
msg_buf[16] += (time_elapsed / 10000) % 10;
msg_buf[17] += (time_elapsed / 1000) % 10;
msg_buf[18] += (time_elapsed / 100) % 10;
msg_buf[19] += (time_elapsed / 10) % 10;
msg_buf[20] += (time_elapsed ) % 10;
rollback(SBUF(msg_buf), __LINE__);
}
int64_t accumulator = slot(0,0,2);
int64_t first = slot(0,0,3);
int64_t last = slot(0,0,4);
int64_t bal = slot(0,0,5);
if (DEBUG)
{
TRACEVAR(accumulator);
TRACEVAR(first);
TRACEVAR(last);
}
ASSERT(/*accumulator > 0 &&*/ first > 0 && last > 0);
// we need to add the final block ourselves
int64_t cur = ledger_seq();
int64_t elapsed = cur - first;
ASSERT(elapsed > 0);
int64_t elapsed_since_last = ledger_seq() - last;
bal &= ~0xE000000000000000ULL;
bal /= 1000000LL;
if (DEBUG)
{
TRACEVAR(bal);
TRACEVAR(accumulator);
}
if (bal > 0 && elapsed_since_last > 0)
accumulator += bal * elapsed_since_last;
if (DEBUG)
TRACEVAR(accumulator);
int64_t xfl_accum = float_set(0, accumulator);
ASSERT(xfl_accum > 0);
int64_t xfl_elapsed = float_set(0, elapsed);
ASSERT(xfl_elapsed > 0);
int64_t xfl_reward = float_divide(xfl_accum, xfl_elapsed);
xfl_reward = float_multiply(xfl_rr, xfl_reward);
if (DEBUG)
TRACEVAR(xfl_reward);
uint64_t reward_drops = float_int(xfl_reward, 6, 1);
uint64_t l1_drops = reward_drops / L1SEATS;
otxn_slot(1);
slot_subfield(1, sfFee, 2);
int64_t xfl_fee = slot_float(2);
// user gets back the fee they spent running the hook
if (xfl_fee > 0)
reward_drops += float_int(xfl_fee, 6, 1);
TEMPLATE_DROPS(reward_drops);
uint8_t* upto = txn_mint + 209U;
uint8_t* end = upto + (34U * (L1SEATS + 1));
// first account is always the rewardee
{
uint64_t* d = (uint64_t*)upto;
uint64_t* s = (uint64_t*)template;
*d++ = *s++;
*d++ = *s++;
*(d+2) = *(s+2);
otxn_field(upto + 13, 20, sfAccount);
}
upto += 34U;
// now iterate all possible seats in all possible tables
TEMPLATE_DROPS(l1_drops);
// there are two conditions for L1 governance members to receive rewards:
// 1. they must be an L1 member
// 2. they must be an active validator
// load the UNLReport, this will let us know who has been validating and who hasn't
uint64_t can_reward[L1SEATS];
uint8_t av_array[(60 * MAXUNL) + 4];
if (slot_set(SBUF(unlreport_keylet), 1) == 1 &&
slot_subfield(1, sfActiveValidators, 1) == 1 &&
slot(SBUF(av_array), 1) > 0)
{
// at least some validators have been validating so those get a reward if they are on the governance table
// we are going to assume the UNL never exceeds 64
uint8_t seat = 0;
uint8_t* av_upto = av_array + 39 /* offset to the first key */;
uint64_t av_size = slot_count(1);
if (av_size > MAXUNL) av_size = MAXUNL;
for (uint64_t i = 0; GUARD(MAXUNL), i < av_size; ++i, av_upto += 60U)
{
trace(SBUF("av:"), av_upto, 20, 1);
if (state(SVAR(seat), av_upto, 20) != 1 || seat > L1SEATS)
continue;
can_reward[seat] = 1;
}
// iterate the seats at the table and add reward entries for the active validators
for (uint8_t l1_seat = 0; upto < end && l1_seat < L1SEATS; l1_seat++)
{
GUARD(L1SEATS);
if (!can_reward[l1_seat])
continue;
// copy template 1 into next GenesisMints array position
uint64_t* d = (uint64_t*)upto;
uint64_t* s = (uint64_t*)template;
*d++ = *s++;
*d++ = *s++;
*(d+2) = *(s+2);
if (state(upto + 13, 20, &l1_seat, 1) == 20)
upto += 34;
}
}
*upto++ = 0xF1U;
// populate other txn fields
etxn_details(txn_mint + 91, 116);
int64_t fee = etxn_fee_base(txn_mint, upto - txn_mint);
BE_DROPS(fee);
*((uint64_t*)(txn_mint + 26)) = fee;
int64_t seq = ledger_seq() + 1;
txn_mint[15] = (seq >> 24U) & 0xFFU;
txn_mint[16] = (seq >> 16U) & 0xFFU;
txn_mint[17] = (seq >> 8U) & 0xFFU;
txn_mint[18] = seq & 0xFFU;
seq += 4;
txn_mint[21] = (seq >> 24U) & 0xFFU;
txn_mint[22] = (seq >> 16U) & 0xFFU;
txn_mint[23] = (seq >> 8U) & 0xFFU;
txn_mint[24] = seq & 0xFFU;
trace(SBUF("emit:"), txn_mint, upto-txn_mint, 1);
uint8_t emithash[32];
int64_t emit_result = emit(SBUF(emithash), txn_mint, upto - txn_mint);
if (DEBUG)
TRACEVAR(emit_result);
if (emit_result < 0)
rollback(SBUF("Reward: Emit loopback failed."), __LINE__);
accept(SBUF("Reward: Emitted reward txn successfully."), __LINE__);
}

133
hook/reward_hook.c Normal file
View File

@@ -0,0 +1,133 @@
#include "hookapi.h"
//#define REWARD_DELAY 2600000LL
#define REWARD_DELAY 60LL
#define REWARD_MULTIPLIER 0.00333333333f
#define ASSERT(x)\
if (!(x))\
rollback(0,0,__LINE__);
int64_t hook(uint32_t r)
{
etxn_reserve(1);
_g(1,1);
uint8_t ttbuf[16];
int64_t br = otxn_field(SBUF(ttbuf), sfTransactionType);
uint32_t txntype = ((uint32_t)(ttbuf[0]) << 16U) + ((uint32_t)(ttbuf[1]));
if (txntype != 98)
accept(0,0,0);
// get the account id
uint8_t account_field[20];
ASSERT(otxn_field(SBUF(account_field), sfAccount) == 20);
uint8_t hook_accid[20];
hook_account(SBUF(hook_accid));
int equal = 0; BUFFER_EQUAL(equal, hook_accid, account_field, 20);
if (equal)
accept(0,0,0);
// get the account root keylet
uint8_t kl[34];
ASSERT(util_keylet(SBUF(kl), KEYLET_ACCOUNT, SBUF(account_field), 0,0,0,0) == 34);
// slot the account root
ASSERT(slot_set(SBUF(kl), 1) == 1);
int64_t accum_slot = slot_subfield(1, sfRewardAccumulator, 2);
// this is a first time claim reward has run and will setup these fields
if (accum_slot == DOESNT_EXIST)
accept(0,0,0);
// this is an actual claim reward
ASSERT(accum_slot == 2);
ASSERT(slot_subfield(1, sfRewardLgrFirst, 3) == 3);
ASSERT(slot_subfield(1, sfRewardLgrLast, 4) == 4);
ASSERT(slot_subfield(1, sfBalance, 5) == 5);
ASSERT(slot_subfield(1, sfRewardTime, 6) == 6);
int64_t time = slot(0,0,6);
int64_t time_elapsed = ledger_last_time() - time;
if (time_elapsed < REWARD_DELAY)
{
uint8_t msg_buf[] =
{
'Y','o','u',' ','m','u','s','t', // 8
' ','w','a','i','t',' ', //+6 = 14
'0','0','0','0','0','0','0',
' ','s','e','c','o','n','d','s' };
//2 600 000
time_elapsed = REWARD_DELAY - time_elapsed;
msg_buf[14] += (time_elapsed / 1000000) % 10;
msg_buf[15] += (time_elapsed / 100000) % 10;
msg_buf[16] += (time_elapsed / 10000) % 10;
msg_buf[17] += (time_elapsed / 1000) % 10;
msg_buf[18] += (time_elapsed / 100) % 10;
msg_buf[19] += (time_elapsed / 10) % 10;
msg_buf[20] += (time_elapsed ) % 10;
rollback(SBUF(msg_buf), time_elapsed);
}
int64_t accumulator = slot(0,0,2);
int64_t first = slot(0,0,3);
int64_t last = slot(0,0,4);
int64_t bal = slot(0,0,5);
TRACEVAR(accumulator);
TRACEVAR(first);
TRACEVAR(last);
ASSERT(accumulator > 0 && first > 0 && last > 0);
// we need to add the final block ourselves
int64_t cur = ledger_seq();
int64_t elapsed = cur - first;
ASSERT(elapsed > 0);
int64_t elapsed_since_last = ledger_seq() - last;
bal &= ~0xE000000000000000ULL;
bal /= 1000000LL;
TRACEVAR(bal);
TRACEVAR(accumulator);
if (bal > 0 && elapsed_since_last > 0)
accumulator += bal * elapsed_since_last;
TRACEVAR(accumulator);
int64_t reward = (int64_t)(((REWARD_MULTIPLIER * (double)accumulator)) / ((double)elapsed));
TRACEVAR(reward);
int64_t reward_drops = reward * 1000000ULL;
ASSERT(reward_drops > reward);
TRACEVAR(reward_drops);
uint8_t tx[PREPARE_PAYMENT_SIMPLE_SIZE];
PREPARE_PAYMENT_SIMPLE(tx, reward_drops, account_field, 0, 0);
// emit the transaction
uint8_t emithash[32];
int64_t emit_result = emit(SBUF(emithash), SBUF(tx));
TRACEVAR(emit_result);
accept(0,0,0);
}

View File

@@ -1,215 +0,0 @@
// For documentation please see: https://xrpl-hooks.readme.io/reference/
// Generated using generate_sfcodes.sh
#define sfCloseResolution ((16U << 16U) + 1U)
#define sfMethod ((16U << 16U) + 2U)
#define sfTransactionResult ((16U << 16U) + 3U)
#define sfTickSize ((16U << 16U) + 16U)
#define sfUNLModifyDisabling ((16U << 16U) + 17U)
#define sfHookResult ((16U << 16U) + 18U)
#define sfLedgerEntryType ((1U << 16U) + 1U)
#define sfTransactionType ((1U << 16U) + 2U)
#define sfSignerWeight ((1U << 16U) + 3U)
#define sfTransferFee ((1U << 16U) + 4U)
#define sfVersion ((1U << 16U) + 16U)
#define sfHookStateChangeCount ((1U << 16U) + 17U)
#define sfHookEmitCount ((1U << 16U) + 18U)
#define sfHookExecutionIndex ((1U << 16U) + 19U)
#define sfHookApiVersion ((1U << 16U) + 20U)
#define sfNetworkID ((2U << 16U) + 1U)
#define sfFlags ((2U << 16U) + 2U)
#define sfSourceTag ((2U << 16U) + 3U)
#define sfSequence ((2U << 16U) + 4U)
#define sfPreviousTxnLgrSeq ((2U << 16U) + 5U)
#define sfLedgerSequence ((2U << 16U) + 6U)
#define sfCloseTime ((2U << 16U) + 7U)
#define sfParentCloseTime ((2U << 16U) + 8U)
#define sfSigningTime ((2U << 16U) + 9U)
#define sfExpiration ((2U << 16U) + 10U)
#define sfTransferRate ((2U << 16U) + 11U)
#define sfWalletSize ((2U << 16U) + 12U)
#define sfOwnerCount ((2U << 16U) + 13U)
#define sfDestinationTag ((2U << 16U) + 14U)
#define sfHighQualityIn ((2U << 16U) + 16U)
#define sfHighQualityOut ((2U << 16U) + 17U)
#define sfLowQualityIn ((2U << 16U) + 18U)
#define sfLowQualityOut ((2U << 16U) + 19U)
#define sfQualityIn ((2U << 16U) + 20U)
#define sfQualityOut ((2U << 16U) + 21U)
#define sfStampEscrow ((2U << 16U) + 22U)
#define sfBondAmount ((2U << 16U) + 23U)
#define sfLoadFee ((2U << 16U) + 24U)
#define sfOfferSequence ((2U << 16U) + 25U)
#define sfFirstLedgerSequence ((2U << 16U) + 26U)
#define sfLastLedgerSequence ((2U << 16U) + 27U)
#define sfTransactionIndex ((2U << 16U) + 28U)
#define sfOperationLimit ((2U << 16U) + 29U)
#define sfReferenceFeeUnits ((2U << 16U) + 30U)
#define sfReserveBase ((2U << 16U) + 31U)
#define sfReserveIncrement ((2U << 16U) + 32U)
#define sfSetFlag ((2U << 16U) + 33U)
#define sfClearFlag ((2U << 16U) + 34U)
#define sfSignerQuorum ((2U << 16U) + 35U)
#define sfCancelAfter ((2U << 16U) + 36U)
#define sfFinishAfter ((2U << 16U) + 37U)
#define sfSignerListID ((2U << 16U) + 38U)
#define sfSettleDelay ((2U << 16U) + 39U)
#define sfTicketCount ((2U << 16U) + 40U)
#define sfTicketSequence ((2U << 16U) + 41U)
#define sfNFTokenTaxon ((2U << 16U) + 42U)
#define sfMintedNFTokens ((2U << 16U) + 43U)
#define sfBurnedNFTokens ((2U << 16U) + 44U)
#define sfHookStateCount ((2U << 16U) + 45U)
#define sfEmitGeneration ((2U << 16U) + 46U)
#define sfLockCount ((2U << 16U) + 47U)
#define sfRewardTime ((2U << 16U) + 98U)
#define sfRewardLgrFirst ((2U << 16U) + 99U)
#define sfRewardLgrLast ((2U << 16U) + 100U)
#define sfIndexNext ((3U << 16U) + 1U)
#define sfIndexPrevious ((3U << 16U) + 2U)
#define sfBookNode ((3U << 16U) + 3U)
#define sfOwnerNode ((3U << 16U) + 4U)
#define sfBaseFee ((3U << 16U) + 5U)
#define sfExchangeRate ((3U << 16U) + 6U)
#define sfLowNode ((3U << 16U) + 7U)
#define sfHighNode ((3U << 16U) + 8U)
#define sfDestinationNode ((3U << 16U) + 9U)
#define sfCookie ((3U << 16U) + 10U)
#define sfServerVersion ((3U << 16U) + 11U)
#define sfNFTokenOfferNode ((3U << 16U) + 12U)
#define sfEmitBurden ((3U << 16U) + 13U)
#define sfHookInstructionCount ((3U << 16U) + 17U)
#define sfHookReturnCode ((3U << 16U) + 18U)
#define sfReferenceCount ((3U << 16U) + 19U)
#define sfRewardAccumulator ((3U << 16U) + 100U)
#define sfEmailHash ((4U << 16U) + 1U)
#define sfTakerPaysCurrency ((10U << 16U) + 1U)
#define sfTakerPaysIssuer ((10U << 16U) + 2U)
#define sfTakerGetsCurrency ((10U << 16U) + 3U)
#define sfTakerGetsIssuer ((10U << 16U) + 4U)
#define sfLedgerHash ((5U << 16U) + 1U)
#define sfParentHash ((5U << 16U) + 2U)
#define sfTransactionHash ((5U << 16U) + 3U)
#define sfAccountHash ((5U << 16U) + 4U)
#define sfPreviousTxnID ((5U << 16U) + 5U)
#define sfLedgerIndex ((5U << 16U) + 6U)
#define sfWalletLocator ((5U << 16U) + 7U)
#define sfRootIndex ((5U << 16U) + 8U)
#define sfAccountTxnID ((5U << 16U) + 9U)
#define sfNFTokenID ((5U << 16U) + 10U)
#define sfEmitParentTxnID ((5U << 16U) + 11U)
#define sfEmitNonce ((5U << 16U) + 12U)
#define sfEmitHookHash ((5U << 16U) + 13U)
#define sfBookDirectory ((5U << 16U) + 16U)
#define sfInvoiceID ((5U << 16U) + 17U)
#define sfNickname ((5U << 16U) + 18U)
#define sfAmendment ((5U << 16U) + 19U)
#define sfHookOn ((5U << 16U) + 20U)
#define sfDigest ((5U << 16U) + 21U)
#define sfChannel ((5U << 16U) + 22U)
#define sfConsensusHash ((5U << 16U) + 23U)
#define sfCheckID ((5U << 16U) + 24U)
#define sfValidatedHash ((5U << 16U) + 25U)
#define sfPreviousPageMin ((5U << 16U) + 26U)
#define sfNextPageMin ((5U << 16U) + 27U)
#define sfNFTokenBuyOffer ((5U << 16U) + 28U)
#define sfNFTokenSellOffer ((5U << 16U) + 29U)
#define sfHookStateKey ((5U << 16U) + 30U)
#define sfHookHash ((5U << 16U) + 31U)
#define sfHookNamespace ((5U << 16U) + 32U)
#define sfHookSetTxnID ((5U << 16U) + 33U)
#define sfOfferID ((5U << 16U) + 34U)
#define sfEscrowID ((5U << 16U) + 35U)
#define sfURITokenID ((5U << 16U) + 36U)
#define sfAmount ((6U << 16U) + 1U)
#define sfBalance ((6U << 16U) + 2U)
#define sfLimitAmount ((6U << 16U) + 3U)
#define sfTakerPays ((6U << 16U) + 4U)
#define sfTakerGets ((6U << 16U) + 5U)
#define sfLowLimit ((6U << 16U) + 6U)
#define sfHighLimit ((6U << 16U) + 7U)
#define sfFee ((6U << 16U) + 8U)
#define sfSendMax ((6U << 16U) + 9U)
#define sfDeliverMin ((6U << 16U) + 10U)
#define sfMinimumOffer ((6U << 16U) + 16U)
#define sfRippleEscrow ((6U << 16U) + 17U)
#define sfDeliveredAmount ((6U << 16U) + 18U)
#define sfNFTokenBrokerFee ((6U << 16U) + 19U)
#define sfHookCallbackFee ((6U << 16U) + 20U)
#define sfLockedBalance ((6U << 16U) + 21U)
#define sfPublicKey ((7U << 16U) + 1U)
#define sfMessageKey ((7U << 16U) + 2U)
#define sfSigningPubKey ((7U << 16U) + 3U)
#define sfTxnSignature ((7U << 16U) + 4U)
#define sfURI ((7U << 16U) + 5U)
#define sfSignature ((7U << 16U) + 6U)
#define sfDomain ((7U << 16U) + 7U)
#define sfFundCode ((7U << 16U) + 8U)
#define sfRemoveCode ((7U << 16U) + 9U)
#define sfExpireCode ((7U << 16U) + 10U)
#define sfCreateCode ((7U << 16U) + 11U)
#define sfMemoType ((7U << 16U) + 12U)
#define sfMemoData ((7U << 16U) + 13U)
#define sfMemoFormat ((7U << 16U) + 14U)
#define sfFulfillment ((7U << 16U) + 16U)
#define sfCondition ((7U << 16U) + 17U)
#define sfMasterSignature ((7U << 16U) + 18U)
#define sfUNLModifyValidator ((7U << 16U) + 19U)
#define sfValidatorToDisable ((7U << 16U) + 20U)
#define sfValidatorToReEnable ((7U << 16U) + 21U)
#define sfHookStateData ((7U << 16U) + 22U)
#define sfHookReturnString ((7U << 16U) + 23U)
#define sfHookParameterName ((7U << 16U) + 24U)
#define sfHookParameterValue ((7U << 16U) + 25U)
#define sfBlob ((7U << 16U) + 26U)
#define sfAccount ((8U << 16U) + 1U)
#define sfOwner ((8U << 16U) + 2U)
#define sfDestination ((8U << 16U) + 3U)
#define sfIssuer ((8U << 16U) + 4U)
#define sfAuthorize ((8U << 16U) + 5U)
#define sfUnauthorize ((8U << 16U) + 6U)
#define sfRegularKey ((8U << 16U) + 8U)
#define sfNFTokenMinter ((8U << 16U) + 9U)
#define sfEmitCallback ((8U << 16U) + 10U)
#define sfHookAccount ((8U << 16U) + 16U)
#define sfIndexes ((19U << 16U) + 1U)
#define sfHashes ((19U << 16U) + 2U)
#define sfAmendments ((19U << 16U) + 3U)
#define sfNFTokenOffers ((19U << 16U) + 4U)
#define sfHookNamespaces ((19U << 16U) + 5U)
#define sfPaths ((18U << 16U) + 1U)
#define sfTransactionMetaData ((14U << 16U) + 2U)
#define sfCreatedNode ((14U << 16U) + 3U)
#define sfDeletedNode ((14U << 16U) + 4U)
#define sfModifiedNode ((14U << 16U) + 5U)
#define sfPreviousFields ((14U << 16U) + 6U)
#define sfFinalFields ((14U << 16U) + 7U)
#define sfNewFields ((14U << 16U) + 8U)
#define sfTemplateEntry ((14U << 16U) + 9U)
#define sfMemo ((14U << 16U) + 10U)
#define sfSignerEntry ((14U << 16U) + 11U)
#define sfNFToken ((14U << 16U) + 12U)
#define sfEmitDetails ((14U << 16U) + 13U)
#define sfHook ((14U << 16U) + 14U)
#define sfSigner ((14U << 16U) + 16U)
#define sfMajority ((14U << 16U) + 18U)
#define sfDisabledValidator ((14U << 16U) + 19U)
#define sfEmittedTxn ((14U << 16U) + 20U)
#define sfHookExecution ((14U << 16U) + 21U)
#define sfHookDefinition ((14U << 16U) + 22U)
#define sfHookParameter ((14U << 16U) + 23U)
#define sfHookGrant ((14U << 16U) + 24U)
#define sfSigners ((15U << 16U) + 3U)
#define sfSignerEntries ((15U << 16U) + 4U)
#define sfTemplate ((15U << 16U) + 5U)
#define sfNecessary ((15U << 16U) + 6U)
#define sfSufficient ((15U << 16U) + 7U)
#define sfAffectedNodes ((15U << 16U) + 8U)
#define sfMemos ((15U << 16U) + 9U)
#define sfNFTokens ((15U << 16U) + 10U)
#define sfHooks ((15U << 16U) + 11U)
#define sfMajorities ((15U << 16U) + 16U)
#define sfDisabledValidators ((15U << 16U) + 17U)
#define sfHookExecutions ((15U << 16U) + 18U)
#define sfHookParameters ((15U << 16U) + 19U)
#define sfHookGrants ((15U << 16U) + 20U)
#define sfActiveValidators ((15U << 16U) + 95U)

View File

@@ -1,42 +0,0 @@
// For documentation please see: https://xrpl-hooks.readme.io/reference/
#define ttPAYMENT 0
#define ttESCROW_CREATE 1
#define ttESCROW_FINISH 2
#define ttACCOUNT_SET 3
#define ttESCROW_CANCEL 4
#define ttREGULAR_KEY_SET 5
// #define ttNICKNAME_SET 6 // deprecated
#define ttOFFER_CREATE 7
#define ttOFFER_CANCEL 8
#define ttTICKET_CREATE 10
// #define ttSPINAL_TAP 11 // deprecated
#define ttSIGNER_LIST_SET 12
#define ttPAYCHAN_CREATE 13
#define ttPAYCHAN_FUND 14
#define ttPAYCHAN_CLAIM 15
#define ttCHECK_CREATE 16
#define ttCHECK_CASH 17
#define ttCHECK_CANCEL 18
#define ttDEPOSIT_PREAUTH 19
#define ttTRUST_SET 20
#define ttACCOUNT_DELETE 21
#define ttHOOK_SET 22
#define ttNFTOKEN_MINT 25
#define ttNFTOKEN_BURN 26
#define ttNFTOKEN_CREATE_OFFER 27
#define ttNFTOKEN_CANCEL_OFFER 28
#define ttNFTOKEN_ACCEPT_OFFER 29
#define ttURITOKEN_MINT 45
#define ttURITOKEN_BURN 46
#define ttURITOKEN_BUY 47
#define ttURITOKEN_CREATE_SELL_OFFER 48
#define ttURITOKEN_CANCEL_SELL_OFFER 49
#define ttGENESIS_MINT 96
#define ttIMPORT 97
#define ttCLAIM_REWARD 98
#define ttINVOKE 99
#define ttAMENDMENT 100
#define ttFEE 101
#define ttUNL_MODIFY 102
#define ttEMIT_FAILURE 103
#define ttUNL_REPORT 104

View File

@@ -233,8 +233,7 @@ module.exports = {
let base_drops = fees.base_fee
delete txn_to_send['SigningPubKey']
if (txn_to_send['Fee'] === undefined)
txn_to_send['Fee'] = base_drops + '';
txn_to_send['Fee'] = base_drops + '';
api.request(
{
@@ -274,17 +273,6 @@ module.exports = {
});
}
const submit = (seed, txn) =>
{
return new Promise((resolve, reject) =>
{
api.submit(txn,
{wallet: xrpljs.Wallet.fromSeed(seed)}).then(s=>
{
resolve(s);
}).catch(e=>{reject(e);});
});
}
const feeSubmit = (seed, txn) =>
{
@@ -589,7 +577,6 @@ module.exports = {
resolve({
hex_memos: hex_memos,
rbc: rbc,
rac: rac,
api: api,
xrpljs: xrpljs,
assertTxnSuccess: assertTxnSuccess,
@@ -622,7 +609,6 @@ module.exports = {
trustSet: trustSet,
issueTokens: issueTokens,
log: log,
submit: submit,
setTshCollect: setTshCollect,
feeSubmitAcceptMultiple: feeSubmitAcceptMultiple,
nftid: nftid

File diff suppressed because it is too large Load Diff

View File

@@ -1,22 +1,4 @@
#!/bin/bash
echo "START BUILDING (HOST)"
echo "Cleaning previously built binary"
rm -f release-build/xahaud
BUILD_CORES=$(echo "scale=0 ; `nproc` / 3" | bc)
if [[ "$GITHUB_REPOSITORY" == "" ]]; then
#Default
BUILD_CORES=8
fi
echo "-- BUILD CORES: $BUILD_CORES"
echo "-- GITHUB_REPOSITORY: $GITHUB_REPOSITORY"
echo "-- GITHUB_SHA: $GITHUB_SHA"
echo "-- GITHUB_RUN_NUMBER: $GITHUB_RUN_NUMBER"
which docker 2> /dev/null 2> /dev/null
if [ "$?" -eq "1" ]
then
@@ -27,34 +9,153 @@ fi
stat .git 2> /dev/null 2> /dev/null
if [ "$?" -eq "1" ]
then
echo 'Run this inside the source directory. (.git dir not found).'
echo 'Run this inside the rippled directory. (.git dir not found).'
exit 1
fi
docker run -t -i --rm -v `pwd`:/io --network host ghcr.io/foobarwidget/holy-build-box-x64 /hbb_exe/activate-exec bash -x -c '
cd /io;
mkdir src/certs;
curl -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
cp src/ripple/net/impl/RegisterSSLCerts.cpp src/ripple/net/impl/RegisterSSLCerts.cpp.old
perl -i -pe "s/^{/{
#ifdef EMBEDDED_CA_BUNDLE
BIO *cbio = BIO_new_mem_buf(ca_bundle.data(), ca_bundle.size());
X509_STORE *cts = SSL_CTX_get_cert_store(ctx.native_handle());
if(!cts || !cbio)
JLOG(j.warn())
<< \"Failed to create cts\/cbio when loading embedded certs.\";
else
{
X509_INFO *itmp;
int i, count = 0, type = X509_FILETYPE_PEM;
STACK_OF(X509_INFO) *inf = PEM_X509_INFO_read_bio(cbio, NULL, NULL, NULL);
STATIC_CONTAINER=$(docker ps -a | grep xahaud_cached_builder |wc -l)
if [[ "$STATIC_CONTAINER" -gt "0" && "$GITHUB_REPOSITORY" != "" ]]; then
echo "Static container, execute in static container to have max. cache"
docker start xahaud_cached_builder
docker exec -i xahaud_cached_builder /hbb_exe/activate-exec bash -x /io/build-core.sh "$GITHUB_REPOSITORY" "$GITHUB_SHA" "$BUILD_CORES" "$GITHUB_RUN_NUMBER"
docker stop xahaud_cached_builder
else
echo "No static container, build on temp container"
rm -rf release-build;
mkdir -p release-build;
if [[ "$GITHUB_REPOSITORY" == "" ]]; then
# Non GH, local building
echo "Non-GH runner, local building, temp container"
docker run -i --user 0:$(id -g) --rm -v /data/builds:/data/builds -v `pwd`:/io --network host ghcr.io/foobarwidget/holy-build-box-x64 /hbb_exe/activate-exec bash -x /io/build-full.sh "$GITHUB_REPOSITORY" "$GITHUB_SHA" "$BUILD_CORES" "$GITHUB_RUN_NUMBER"
else
# GH Action, runner
echo "GH Action, runner, clean & re-create create persistent container"
docker rm -f xahaud_cached_builder
docker run -di --user 0:$(id -g) --name xahaud_cached_builder -v /data/builds:/data/builds -v `pwd`:/io --network host ghcr.io/foobarwidget/holy-build-box-x64 /hbb_exe/activate-exec bash
docker exec -i xahaud_cached_builder /hbb_exe/activate-exec bash -x /io/build-full.sh "$GITHUB_REPOSITORY" "$GITHUB_SHA" "$BUILD_CORES" "$GITHUB_RUN_NUMBER"
docker stop xahaud_cached_builder
fi
if (!inf)
{
BIO_free(cbio);
JLOG(j.warn())
<< \"Failed to read cbio when loading embedded certs.\";
}
else
{
for (i = 0; i < sk_X509_INFO_num(inf); i++)
{
itmp = sk_X509_INFO_value(inf, i);
if (itmp->x509)
{
X509_STORE_add_cert(cts, itmp->x509);
count++;
}
if (itmp->crl)
{
X509_STORE_add_crl(cts, itmp->crl);
count++;
}
}
sk_X509_INFO_pop_free(inf, X509_INFO_free);
BIO_free(cbio);
}
}
#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
echo "DONE BUILDING (HOST)"
rm -rf release-build;
mkdir release-build;
mkdir .nih_c;
mkdir .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 \
gcc-c++ \
snappy snappy-devel \
zlib zlib-devel \
lz4-devel \
libasan &&
echo "-- Install ZStd 1.1.3 --" &&
yum install epel-release -y &&
ZSTD_VERSION="1.1.3" &&
( wget -nc -O zstd-${ZSTD_VERSION}.tar.gz https://github.com/facebook/zstd/archive/v${ZSTD_VERSION}.tar.gz; echo "" ) &&
tar xzvf zstd-${ZSTD_VERSION}.tar.gz &&
cd zstd-${ZSTD_VERSION} &&
make -j8 && make install &&
cd .. &&
echo "-- Install Cmake 3.23.1 --" &&
pwd &&
( wget -nc https://github.com/Kitware/CMake/releases/download/v3.23.1/cmake-3.23.1-linux-x86_64.tar.gz; echo "" ) &&
tar -xzf cmake-3.23.1-linux-x86_64.tar.gz -C /hbb/ &&
echo "-- Install Boost 1.75.0 --" &&
pwd &&
( wget -nc https://boostorg.jfrog.io/artifactory/main/release/1.75.0/source/boost_1_75_0.tar.gz; echo "" ) &&
tar -xzf boost_1_75_0.tar.gz &&
cd boost_1_75_0 && ./bootstrap.sh && ./b2 link=static -j8 && ./b2 install &&
cd ../ &&
echo "-- Install Protobuf 3.20.0 --" &&
pwd &&
( wget -nc https://github.com/protocolbuffers/protobuf/releases/download/v3.20.0/protobuf-all-3.20.0.tar.gz; echo "" ) &&
tar -xzf protobuf-all-3.20.0.tar.gz &&
cd protobuf-3.20.0/ &&
./autogen.sh && ./configure --prefix=/usr --disable-shared link=static && make -j8 && make install &&
cd .. &&
echo "-- Build LLD --" &&
pwd &&
ln /usr/bin/llvm-config-13 /usr/bin/llvm-config &&
mv /opt/rh/devtoolset-9/root/usr/bin/ar /opt/rh/devtoolset-9/root/usr/bin/ar-9 &&
ln /opt/rh/devtoolset-10/root/usr/bin/ar /opt/rh/devtoolset-9/root/usr/bin/ar &&
( wget -nc https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/lld-13.0.1.src.tar.xz; echo "" ) &&
( wget -nc https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/libunwind-13.0.1.src.tar.xz; echo "" ) &&
tar -xf lld-13.0.1.src.tar.xz &&
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 &&
cd build &&
cmake .. -DLLVM_LIBRARY_DIR=/usr/lib64/llvm13/lib/ -DCMAKE_INSTALL_PREFIX=/usr/lib64/llvm13/ -DCMAKE_BUILD_TYPE=Release &&
make -j8 &&
make install &&
ln -s /usr/lib64/llvm13/lib/include/lld /usr/include/lld &&
cp /usr/lib64/llvm13/lib/liblld*.a /usr/local/lib/ &&
cd ../../../ &&
echo "-- Build WasmEdge --" &&
( git clone https://github.com/WasmEdge/WasmEdge.git; echo "" ) &&
cd WasmEdge &&
( mkdir build; echo "" ) &&
cd build &&
export BOOST_ROOT="/usr/local/src/boost_1_75_0" &&
export Boost_LIBRARY_DIRS="/usr/local/lib" &&
export BOOST_INCLUDEDIR="/usr/local/src/boost_1_75_0" &&
cmake .. \
-DWASMEDGE_BUILD_SHARED_LIB=OFF \
-DWASMEDGE_BUILD_STATIC_LIB=ON \
-DWASMEDGE_BUILD_AOT_RUNTIME=ON \
-DWASMEDGE_FORCE_DISABLE_LTO=ON \
-DCMAKE_POSITION_INDEPENDENT_CODE=ON \
-DWASMEDGE_LINK_LLVM_STATIC=ON \
-DWASMEDGE_BUILD_PLUGINS=OFF \
-DWASMEDGE_LINK_TOOLS_STATIC=ON \
-DBoost_NO_BOOST_CMAKE=ON -DLLVM_DIR=/usr/lib64/llvm13/lib/cmake/llvm/ -DLLVM_LIBRARY_DIR=/usr/lib64/llvm13/lib/ &&
make -j8 &&
make install &&
cd ../../ &&
echo "-- Build Rippled --" &&
pwd &&
cp Builds/CMake/deps/Rocksdb.cmake Builds/CMake/deps/Rocksdb.cmake.old &&
perl -i -pe "s/^(\\s*)-DBUILD_SHARED_LIBS=OFF/\\1-DBUILD_SHARED_LIBS=OFF\\n\\1-DROCKSDB_BUILD_SHARED=OFF/g" Builds/CMake/deps/Rocksdb.cmake &&
cd release-build &&
cmake .. -DBoost_NO_BOOST_CMAKE=ON -DLLVM_DIR=/usr/lib64/llvm13/lib/cmake/llvm/ -DLLVM_LIBRARY_DIR=/usr/lib64/llvm13/lib/ &&
make -j8 VERBOSE=1 &&
strip -s rippled &&
mv rippled xahaud &&
echo "Build host: `hostname`" > release.info &&
echo "Build date: `date`" >> release.info &&
echo "Build md5: `md5sum xahaud`" >> release.info &&
echo "Git remotes:" >> release.info &&
git remote -v >> release.info
echo "Git status:" >> release.info &&
git status -v >> release.info &&
echo "Git log [last 20]:" >> release.info &&
git log -n 20 >> release.info;
cd ..;
mv src/ripple/net/impl/RegisterSSLCerts.cpp.old src/ripple/net/impl/RegisterSSLCerts.cpp;
mv Builds/CMake/deps/Rocksdb.cmake.old Builds/CMake/deps/Rocksdb.cmake'

File diff suppressed because it is too large Load Diff

View File

@@ -92,7 +92,7 @@ RCLConsensus::Adaptor::Adaptor(
rand_int(
crypto_prng(),
std::numeric_limits<std::uint64_t>::max() - 1))
, nUnlVote_(validatorKeys_.nodeID, j_, app)
, nUnlVote_(validatorKeys_.nodeID, j_)
{
assert(valCookie_ != 0);
@@ -178,11 +178,16 @@ RCLConsensus::Adaptor::share(RCLCxPeerPos const& peerPos)
void
RCLConsensus::Adaptor::share(RCLCxTx const& tx)
{
//RH TODO: never broadcast emitted transactions
//fix below:
//if (tx.isFieldPresent(sfEmitDetails))
// return;
// If we didn't relay this transaction recently, relay it to all peers
if (app_.getHashRouter().shouldRelay(tx.id()))
{
JLOG(j_.debug()) << "Relaying disputed tx " << tx.id();
auto const slice = tx.tx_->slice();
auto const slice = tx.tx_.slice();
protocol::TMTransaction msg;
msg.set_rawtransaction(slice.data(), slice.size());
msg.set_status(protocol::tsNEW);
@@ -318,18 +323,15 @@ RCLConsensus::Adaptor::onClose(
initialSet->setUnbacked();
// Build SHAMap containing all transactions in our open ledger
Serializer s;
for (auto const& tx : initialLedger->txs)
{
JLOG(j_.trace()) << "Adding open ledger TX "
<< tx.first->getTransactionID();
s.clear();
Serializer s(2048);
tx.first->add(s);
initialSet->addItem(
SHAMapNodeType::tnTRANSACTION_NM,
make_shamapitem(tx.first->getTransactionID(), s.slice()));
SHAMapItem(tx.first->getTransactionID(), s.slice()));
}
// Add pseudo-transactions to the set
@@ -341,7 +343,7 @@ RCLConsensus::Adaptor::onClose(
// pseudo-transactions
auto validations = app_.validators().negativeUNLFilter(
app_.getValidations().getTrustedForLedger(
prevLedger->info().parentHash, prevLedger->seq() - 1));
prevLedger->info().parentHash));
if (validations.size() >= app_.validators().quorum())
{
feeVote_->doVoting(prevLedger, validations, initialSet);
@@ -373,8 +375,7 @@ RCLConsensus::Adaptor::onClose(
RCLCensorshipDetector<TxID, LedgerIndex>::TxIDSeqVec proposed;
initialSet->visitLeaves(
[&proposed,
seq](boost::intrusive_ptr<SHAMapItem const> const& item) {
[&proposed, seq](std::shared_ptr<SHAMapItem const> const& item) {
proposed.emplace_back(item->key(), seq);
});
@@ -497,21 +498,17 @@ RCLConsensus::Adaptor::doAccept(
for (auto const& item : *result.txns.map_)
{
#ifndef DEBUG
try
{
retriableTxs.insert(std::make_shared<STTx const>(item.slice()));
retriableTxs.insert(
std::make_shared<STTx const>(SerialIter{item.slice()}));
JLOG(j_.debug()) << " Tx: " << item.key();
#ifndef DEBUG
}
catch (std::exception const& ex)
catch (std::exception const&)
{
failed.insert(item.key());
JLOG(j_.warn())
<< " Tx: " << item.key() << " throws: " << ex.what();
JLOG(j_.warn()) << " Tx: " << item.key() << " throws!";
}
#endif
}
auto built = buildLCL(
@@ -537,7 +534,7 @@ RCLConsensus::Adaptor::doAccept(
std::vector<TxID> accepted;
result.txns.map_->visitLeaves(
[&accepted](boost::intrusive_ptr<SHAMapItem const> const& item) {
[&accepted](std::shared_ptr<SHAMapItem const> const& item) {
accepted.push_back(item->key());
});
@@ -612,8 +609,8 @@ RCLConsensus::Adaptor::doAccept(
<< "Test applying disputed transaction that did"
<< " not get in " << dispute.tx().id();
auto txn =
std::make_shared<STTx const>(dispute.tx().tx_->slice());
SerialIter sit(dispute.tx().tx_.slice());
auto txn = std::make_shared<STTx const>(sit);
// Disputed pseudo-transactions that were not accepted
// can't be successfully applied in the next ledger
@@ -624,11 +621,10 @@ RCLConsensus::Adaptor::doAccept(
anyDisputes = true;
}
catch (std::exception const& ex)
catch (std::exception const&)
{
JLOG(j_.debug()) << "Failed to apply transaction we voted "
"NO on. Exception: "
<< ex.what();
JLOG(j_.debug())
<< "Failed to apply transaction we voted NO on";
}
}
}
@@ -648,7 +644,7 @@ RCLConsensus::Adaptor::doAccept(
app_,
*rules,
built.ledger_,
localTxs_.getTransactions(),
localTxs_.getTxSet(),
anyDisputes,
retriableTxs,
tapNONE,
@@ -778,6 +774,7 @@ RCLConsensus::Adaptor::buildLCL(
j_);
}();
// Update fee computations based on accepted txs
using namespace std::chrono_literals;
app_.getTxQ().processClosedLedger(app_, *built, roundTime > 5s);
@@ -848,8 +845,7 @@ RCLConsensus::Adaptor::validate(
if (ledger.ledger_->isVotingLedger())
{
// Fees:
feeVote_->doValidation(
ledger.ledger_->fees(), ledger.ledger_->rules(), v);
feeVote_->doValidation(ledger.ledger_->fees(), v);
// Amendments
// FIXME: pass `v` and have the function insert the array
@@ -863,17 +859,16 @@ RCLConsensus::Adaptor::validate(
}
});
Serializer ser;
v->add(ser);
auto const serialized = v->getSerialized();
// suppress it if we receive it
app_.getHashRouter().addSuppression(sha512Half(ser.slice()));
app_.getHashRouter().addSuppression(sha512Half(makeSlice(serialized)));
handleNewValidation(app_, v, "local");
// Broadcast to all our peers:
protocol::TMValidation val;
val.set_validation(ser.slice().data(), ser.slice().size());
val.set_validation(serialized.data(), serialized.size());
app_.overlay().broadcast(val);
// Publish to all our subscribers:

View File

@@ -71,7 +71,7 @@ proposalUniqueId(
Slice const& publicKey,
Slice const& signature)
{
Serializer s;
Serializer s(512);
s.addBitString(proposeHash);
s.addBitString(previousLedger);
s.add32(proposeSeq);
@@ -79,7 +79,7 @@ proposalUniqueId(
s.addVL(publicKey);
s.addVL(signature);
return sha512Half(s.slice());
return s.getSHA512Half();
}
} // namespace ripple

View File

@@ -42,7 +42,7 @@ public:
@param txn The transaction to wrap
*/
RCLCxTx(boost::intrusive_ptr<SHAMapItem const> txn) : tx_(std::move(txn))
RCLCxTx(SHAMapItem const& txn) : tx_{txn}
{
}
@@ -50,11 +50,11 @@ public:
ID const&
id() const
{
return tx_->key();
return tx_.key();
}
//! The SHAMapItem that represents the transaction.
boost::intrusive_ptr<SHAMapItem const> tx_;
SHAMapItem const tx_;
};
/** Represents a set of transactions in RCLConsensus.
@@ -90,7 +90,8 @@ public:
bool
insert(Tx const& t)
{
return map_->addItem(SHAMapNodeType::tnTRANSACTION_NM, t.tx_);
return map_->addItem(
SHAMapNodeType::tnTRANSACTION_NM, SHAMapItem{t.tx_});
}
/** Remove a transaction from the set.
@@ -144,7 +145,7 @@ public:
code uses the shared_ptr semantics to know whether the find
was successful and properly creates a Tx as needed.
*/
boost::intrusive_ptr<SHAMapItem const> const&
std::shared_ptr<const SHAMapItem> const&
find(Tx::ID const& entry) const
{
return map_->peekItem(entry);

View File

@@ -206,12 +206,14 @@ handleNewValidation(
if (outcome == ValStatus::conflicting)
ls << "Byzantine Behavior Detector: "
<< (val->isTrusted() ? "trusted " : "untrusted ") << id
<< ": Conflicting validation for " << seq << "!";
<< ": Conflicting validation for " << seq << "!\n["
<< val->getSerializer().slice() << "]";
if (outcome == ValStatus::multiple)
ls << "Byzantine Behavior Detector: "
<< (val->isTrusted() ? "trusted " : "untrusted ") << id
<< ": Multiple validations for " << seq << "/" << hash << "!";
<< ": Multiple validations for " << seq << "/" << hash << "!\n["
<< val->getSerializer().slice() << "]";
}
}

View File

@@ -25,36 +25,6 @@ namespace ripple
namespace hook
{
// RH TODO: put these somewhere better, and allow rules to be fed in
inline
uint32_t maxHookParameterKeySize(void)
{
return 32;
}
inline
uint32_t maxHookParameterValueSize(void)
{
return 256;
}
inline
uint32_t maxHookStateDataSize(void) {
return 256U;
}
inline
uint32_t maxHookWasmSize(void)
{
return 0xFFFFU;
}
inline
uint32_t maxHookChainLength(void)
{
return 10;
}
enum TSHFlags : uint8_t
{
tshNONE = 0b000,
@@ -159,10 +129,6 @@ namespace hook
WASM_VALIDATION = 81, // a generic error while parsing wasm, usually leb128 overflow
HOOK_CBAK_DIFF_TYPES = 82, // hook and cbak function definitions were different
PARAMETERS_NAME_REPEATED = 83,
NESTING_LIMIT = 84, // the hook nested blocks/loops/ifs beyond 16 levels
SECTIONS_OUT_OF_SEQUENCE = 85, // the wasm contained sections out of sequence
CUSTOM_SECTION_DISALLOWED = 86, // the wasm contained a custom section (id=0)
INTERNAL_ERROR = 87, // an internal error described by the log text
// RH NOTE: only HookSet msgs got log codes, possibly all Hook log lines should get a code?
};
};
@@ -199,9 +165,7 @@ namespace hook_api
EMITTED_TXN = 22,
NFT_OFFER = 23,
HOOK_DEFINITION = 24,
HOOK_STATE_DIR = 25,
LAST_KLTYPE_V0 = HOOK_DEFINITION,
LAST_KLTYPE_V1 = HOOK_STATE_DIR,
LAST_KLTYPE = HOOK_DEFINITION
};
}
@@ -260,7 +224,6 @@ namespace hook_api
INVALID_KEY = -41, // user supplied key was not valid
NOT_A_STRING = -42, // nul terminator missing from a string argument
MEM_OVERLAP = -43, // one or more specified buffers are the same memory
TOO_MANY_STATE_MODIFICATIONS = -44, // more than 5000 modified state entires in the combined hook chains
};
enum ExitType : uint8_t
@@ -271,96 +234,354 @@ namespace hook_api
ACCEPT = 3,
};
const uint16_t max_state_modifications = 256;
const uint8_t max_slots = 255;
const uint8_t max_nonce = 255;
const uint8_t max_emit = 255;
const uint8_t max_params = 16;
const double fee_base_multiplier = 1.1f;
// RH NOTE: Find descriptions of api functions in ./impl/applyHook.cpp and hookapi.h (include for hooks)
// this is a map of the api name to its return code (vec[0] and its parameters vec[>0]) as wasm type codes
static const std::map<std::string, std::vector<uint8_t>> import_whitelist
// RH TODO: there's definitely a mucher nicer way to do this, but it involves modifying the base_uint
// class and we don't want to do that yet.
static const std::array<ripple::uint256, 256> UINT256_BIT =
{
{"_g",{0x7FU,0x7FU,0x7FU}},
{"accept",{0x7EU,0x7FU,0x7FU,0x7EU}},
{"rollback",{0x7EU,0x7FU,0x7FU,0x7EU}},
{"util_raddr",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"util_accid",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"util_verify",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"util_sha512h",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"util_keylet",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"sto_validate",{0x7EU,0x7FU,0x7FU}},
{"sto_subfield",{0x7EU,0x7FU,0x7FU,0x7FU}},
{"sto_subarray",{0x7EU,0x7FU,0x7FU,0x7FU}},
{"sto_emplace",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"sto_erase",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"etxn_burden",{0x7EU}},
{"etxn_details",{0x7EU,0x7FU,0x7FU}},
{"etxn_fee_base",{0x7EU,0x7FU,0x7FU}},
{"etxn_reserve",{0x7EU,0x7FU}},
{"etxn_generation",{0x7EU}},
{"etxn_nonce",{0x7EU,0x7FU,0x7FU}},
{"emit",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"float_set",{0x7EU,0x7FU,0x7EU}},
{"float_multiply",{0x7EU,0x7EU,0x7EU}},
{"float_mulratio",{0x7EU,0x7EU,0x7FU,0x7FU,0x7FU}},
{"float_negate",{0x7EU,0x7EU}},
{"float_compare",{0x7EU,0x7EU,0x7EU,0x7FU}},
{"float_sum",{0x7EU,0x7EU,0x7EU}},
{"float_sto",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7EU,0x7FU}},
{"float_sto_set",{0x7EU,0x7FU,0x7FU}},
{"float_invert",{0x7EU,0x7EU}},
{"float_divide",{0x7EU,0x7EU,0x7EU}},
{"float_one",{0x7EU}},
{"float_mantissa",{0x7EU,0x7EU}},
{"float_sign",{0x7EU,0x7EU}},
{"float_int",{0x7EU,0x7EU,0x7FU,0x7FU}},
{"float_log",{0x7EU,0x7EU}},
{"float_root",{0x7EU,0x7EU,0x7FU}},
{"fee_base",{0x7EU}},
{"ledger_seq",{0x7EU}},
{"ledger_last_time",{0x7EU}},
{"ledger_last_hash",{0x7EU,0x7FU,0x7FU}},
{"ledger_nonce",{0x7EU,0x7FU,0x7FU}},
{"ledger_keylet",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"hook_account",{0x7EU,0x7FU,0x7FU}},
{"hook_hash",{0x7EU,0x7FU,0x7FU,0x7FU}},
{"hook_param_set",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"hook_param",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"hook_again",{0x7EU}},
{"hook_skip",{0x7EU,0x7FU,0x7FU,0x7FU}},
{"hook_pos",{0x7EU}},
{"slot",{0x7EU,0x7FU,0x7FU,0x7FU}},
{"slot_clear",{0x7EU,0x7FU}},
{"slot_count",{0x7EU,0x7FU}},
{"slot_set",{0x7EU,0x7FU,0x7FU,0x7FU}},
{"slot_size",{0x7EU,0x7FU}},
{"slot_subarray",{0x7EU,0x7FU,0x7FU,0x7FU}},
{"slot_subfield",{0x7EU,0x7FU,0x7FU,0x7FU}},
{"slot_type",{0x7EU,0x7FU,0x7FU}},
{"slot_float",{0x7EU,0x7FU}},
{"state_set",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"state_foreign_set",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"state",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"state_foreign",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"trace",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"trace_num",{0x7EU,0x7FU,0x7FU,0x7EU}},
{"trace_float",{0x7EU,0x7FU,0x7FU,0x7EU}},
{"otxn_burden",{0x7EU}},
{"otxn_field",{0x7EU,0x7FU,0x7FU,0x7FU}},
{"otxn_generation",{0x7EU}},
{"otxn_id",{0x7EU,0x7FU,0x7FU,0x7FU}},
{"otxn_type",{0x7EU}},
{"otxn_slot",{0x7EU,0x7FU}},
{"otxn_param",{0x7EU,0x7FU,0x7FU,0x7FU,0x7FU}},
{"meta_slot",{0x7EU,0x7FU}}
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000001"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000002"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000004"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000008"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000010"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000020"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000040"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000080"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000100"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000200"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000400"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000800"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000001000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000002000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000004000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000008000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000010000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000020000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000040000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000080000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000100000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000200000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000400000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000800000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000001000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000002000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000004000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000008000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000010000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000020000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000040000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000080000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000100000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000200000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000400000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000800000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000001000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000002000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000004000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000008000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000010000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000020000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000040000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000080000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000100000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000200000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000400000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000800000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000001000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000002000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000004000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000008000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000010000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000020000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000040000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000080000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000100000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000200000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000400000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000800000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000001000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000002000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000004000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000008000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000010000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000020000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000040000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000080000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000100000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000200000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000400000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000800000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000001000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000002000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000004000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000008000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000010000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000020000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000040000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000080000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000100000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000200000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000400000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000800000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000001000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000002000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000004000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000008000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000010000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000020000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000040000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000080000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000100000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000200000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000400000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000800000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000001000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000002000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000004000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000008000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000010000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000020000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000040000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000080000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000100000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000200000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000400000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000800000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000001000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000002000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000004000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000008000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000010000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000020000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000040000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000080000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000100000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000200000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000400000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000800000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000001000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000002000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000004000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000008000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000010000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000020000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000040000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000080000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000100000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000200000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000400000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000800000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000001000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000002000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000004000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000008000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000010000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000020000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000040000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000080000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000100000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000200000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000400000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000800000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000001000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000002000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000004000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000008000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000010000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000020000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000040000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000080000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000100000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000200000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000400000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000800000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000001000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000002000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000004000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000008000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000010000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000020000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000040000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000080000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000100000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000200000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000400000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000800000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000001000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000002000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000004000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000008000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000010000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000020000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000040000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000080000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000100000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000200000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000400000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000800000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000001000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000002000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000004000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000008000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000010000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000020000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000040000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000080000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000100000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000200000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000400000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000800000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000001000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000002000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000004000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000008000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000010000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000020000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000040000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000080000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000100000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000200000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000400000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000800000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000001000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000002000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000004000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000008000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000010000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000020000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000040000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000080000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000100000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000200000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000400000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000800000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000001000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000002000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000004000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000008000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000010000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000020000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000040000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000080000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000100000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000200000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000400000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000800000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000001000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000002000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000004000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000008000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000010000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000020000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000040000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000080000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000100000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000200000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000400000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000800000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0001000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0002000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0004000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0008000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0010000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0020000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0040000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0080000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0100000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0200000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0400000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0800000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("1000000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("2000000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("4000000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("8000000000000000000000000000000000000000000000000000000000000000")
};
// featureHooks1
static const std::map<std::string, std::vector<uint8_t>> import_whitelist_1
// RH NOTE: Find descriptions of api functions in ./impl/applyHook.cpp and hookapi.h (include for hooks)
static const std::set<std::string> import_whitelist
{
{"xpop_slot",{0x7EU,0x7FU,0x7FU}}
"accept",
"emit",
"etxn_burden",
"etxn_details",
"etxn_fee_base",
"etxn_generation",
"etxn_reserve",
"etxn_nonce",
"float_compare",
"float_divide",
"float_invert",
"float_mantissa",
"float_mulratio",
"float_multiply",
"float_int",
"float_negate",
"float_one",
"float_set",
"float_sign",
"float_sto",
"float_sto_set",
"float_sum",
"float_log",
"float_root",
"fee_base",
"_g",
"hook_account",
"hook_hash",
"ledger_seq",
"ledger_last_hash",
"ledger_last_time",
"ledger_nonce",
"ledger_keylet",
"otxn_burden",
"otxn_field",
"otxn_slot",
"otxn_generation",
"otxn_id",
"otxn_type",
"rollback",
"slot",
"slot_clear",
"slot_count",
"slot_set",
"slot_size",
"slot_subarray",
"slot_subfield",
"slot_type",
"slot_float",
"state",
"state_foreign",
"state_set",
"state_foreign_set",
"trace",
"trace_num",
"trace_float",
"util_accid",
"util_raddr",
"util_sha512h",
"util_verify",
"sto_subarray",
"sto_subfield",
"sto_validate",
"sto_emplace",
"sto_erase",
"util_keylet",
"hook_pos",
"hook_param",
"hook_param_set",
"hook_skip",
"hook_again",
"meta_slot",
"str_find",
"str_replace",
"str_concat",
"str_compare"
};
};
#endif

View File

@@ -7,7 +7,6 @@
#include <stack>
#include <string>
#include <functional>
#include <memory>
#include "Enum.h"
using GuardLog = std::optional<std::reference_wrapper<std::basic_ostream<char>>>;
@@ -95,7 +94,7 @@ parseSignedLeb128(
// this macro will return temMALFORMED if i ever exceeds the end of the hook
#define CHECK_SHORT_HOOK()\
{\
if (i >= wasm.size())\
if (i >= hook.size())\
{\
\
GUARDLOG(hook::log::SHORT_HOOK) \
@@ -108,7 +107,7 @@ parseSignedLeb128(
#define REQUIRE(x)\
{\
if (i + (x) > wasm.size())\
if (i + (x) > hook.size())\
{\
\
GUARDLOG(hook::log::SHORT_HOOK) \
@@ -124,10 +123,10 @@ parseSignedLeb128(
}
#define LEB()\
parseLeb128(wasm, i, &i)
parseLeb128(hook, i, &i)
#define SIGNED_LEB()\
parseSignedLeb128(wasm, i, &i)
parseSignedLeb128(hook, i, &i)
#define GUARD_ERROR(msg)\
{\
@@ -144,97 +143,36 @@ parseSignedLeb128(
struct WasmBlkInf
{
uint32_t sanity_check;
uint32_t iteration_bound;
uint32_t instruction_count;
WasmBlkInf* parent;
std::vector<WasmBlkInf*> children;
uint32_t start_byte;
bool is_root;
WasmBlkInf(
uint32_t iteration_bound_,
uint32_t instruction_count_,
WasmBlkInf* parent_,
uint32_t start_byte_,
bool is_root_ = false)
:
sanity_check(0x1234ABCDU),
iteration_bound(iteration_bound_),
instruction_count(instruction_count_),
parent(parent_),
children({}),
start_byte(start_byte_),
is_root(is_root_)
{
// all done by the above
}
WasmBlkInf* add_child(uint32_t iteration_bound, uint32_t start_byte)
{
WasmBlkInf* child = new WasmBlkInf(iteration_bound, 0, this, start_byte, false);
children.push_back(child);
return child;
}
~WasmBlkInf()
{
for (WasmBlkInf* child : children)
delete child;
}
std::vector<WasmBlkInf> children;
};
#define PRINT_WCE(x)\
{\
if (DEBUG_GUARD)\
printf("%llx:: [%u]%.*swce=%ld | start=%x instcount=%u guard=%u, "\
"parent_guard=%d, multiplier=%g parentptr=%llx\n",\
&blk,\
x,\
level, " ",\
worst_case_execution,\
blk->start_byte,\
blk->instruction_count,\
blk->iteration_bound,\
(blk->parent != 0 ? blk->parent->iteration_bound : -1),\
multiplier, &(blk->parent));\
printf("[%u]%.*swce=%ld | g=%u, pg=%u, m=%g\n",\
x,\
level, " ",\
worst_case_execution,\
blk->iteration_bound,\
(blk->parent ? blk->parent->iteration_bound : -1),\
multiplier);\
}
// compute worst case execution time
// compute worst case execution time
inline
uint64_t compute_wce (const WasmBlkInf* blk, int level, bool* recursion_limit_reached)
uint64_t compute_wce (const WasmBlkInf* blk, int level = 0)
{
if (level > 16)
{
*recursion_limit_reached = true;
return 0;
}
if (blk->sanity_check != 0x1234ABCDU)
{
printf("!!! sanity check failed\n");
*recursion_limit_reached = true;
return (uint64_t)-1;
}
WasmBlkInf const* parent = blk->parent;
if (parent && parent->sanity_check != 0x1234ABCDU)
{
printf("!!! parent sanity check failed\n");
*recursion_limit_reached = true;
return (uint64_t)-1;
}
uint64_t worst_case_execution = blk->instruction_count;
double multiplier = 1.0;
if (blk->children.size() > 0)
for (auto const& child : blk->children)
worst_case_execution += compute_wce(child, level + 1, recursion_limit_reached);
worst_case_execution += compute_wce(&child, level + 1);
if (parent == 0 ||
parent->iteration_bound == 0) // this condtion should never occur [defensively programmed]
if (blk->parent == 0 ||
blk->parent->iteration_bound == 0) // this condtion should never occur [defensively programmed]
{
PRINT_WCE(1);
return worst_case_execution;
@@ -242,9 +180,9 @@ uint64_t compute_wce (const WasmBlkInf* blk, int level, bool* recursion_limit_re
// if the block has a parent then the quotient of its guard and its parent's guard
// gives us the loop iterations and thus the multiplier for the instruction count
multiplier =
multiplier =
((double)(blk->iteration_bound)) /
((double)(parent->iteration_bound));
((double)(blk->parent->iteration_bound));
worst_case_execution *= multiplier;
if (worst_case_execution < 1.0)
@@ -262,7 +200,7 @@ uint64_t compute_wce (const WasmBlkInf* blk, int level, bool* recursion_limit_re
inline
std::optional<uint64_t>
check_guard(
std::vector<uint8_t> const& wasm,
std::vector<uint8_t> const& hook,
int codesec,
int start_offset,
int end_offset,
@@ -272,24 +210,17 @@ check_guard(
std::string guardLogAccStr)
{
#define MAX_GUARD_CALLS 1024
uint32_t guard_count = 0;
if (DEBUG_GUARD)
printf("\ncheck_guard called with "
"codesec=%d start_offset=%d end_offset=%d guard_func_idx=%d last_import_idx=%d\n",
codesec, start_offset, end_offset, guard_func_idx, last_import_idx);
if (end_offset <= 0) end_offset = wasm.size();
if (end_offset <= 0) end_offset = hook.size();
int block_depth = 0;
// the root node is constructed in a unique ptr, which will cause its destructor to be called
// when the function exits. The destructor of the root node will recursively free all heap allocated children.
//WasmBlkInf(uint32_t iteration_bound_, uint32_t instruction_count_,
// WasmBlkInf* parent_, uint32_t start_byte_, bool is_root_ = false) :
std::unique_ptr<WasmBlkInf> root = std::make_unique<WasmBlkInf>(1, 0, (WasmBlkInf*)0, start_offset, true);
WasmBlkInf* current = &(*root);
WasmBlkInf root { .iteration_bound = 1, .instruction_count = 0, .parent = 0, .children = {} };
WasmBlkInf* current = &root;
if (DEBUG_GUARD)
printf("\n\n\nstart of guard analysis for codesec %d\n", codesec);
@@ -301,12 +232,12 @@ check_guard(
{
printf("->");
for (int z = i; z < 16 + i && z < end_offset; ++z)
printf("%02X", wasm[z]);
printf("%02X", hook[z]);
printf("\n");
}
REQUIRE(1);
uint8_t instr = wasm[i];
uint8_t instr = hook[i];
ADVANCE(1);
current->instruction_count++;
@@ -329,11 +260,10 @@ check_guard(
REQUIRE(1);
// discard the block return type
uint8_t block_type = wasm[i];
uint8_t block_type = hook[i];
if ((block_type >= 0x7CU && block_type <= 0x7FU) ||
block_type == 0x7BU || block_type == 0x70U ||
block_type == 0x7BU || block_type == 0x40U ||
block_type == 0x6FU)
block_type == 0x7BU || block_type == 0x40U)
{
ADVANCE(1);
}
@@ -342,7 +272,7 @@ check_guard(
SIGNED_LEB();
}
uint32_t iteration_bound = (current->parent == 0 ? 1 : current->iteration_bound);
uint32_t iteration_bound = (current->parent == 0 ? 1 : current->parent->iteration_bound);
if (instr == 0x03U)
{
// now look for the guard call
@@ -353,37 +283,45 @@ check_guard(
// first i32
REQUIRE(1);
if (wasm[i] != 0x41U)
if (hook[i] != 0x41U)
GUARD_ERROR("Missing first i32.const after loop instruction");
ADVANCE(1);
SIGNED_LEB(); // this is the ID, we don't need it here
// second i32
REQUIRE(1);
if (wasm[i] != 0x41U)
if (hook[i] != 0x41U)
GUARD_ERROR("Missing second i32.const after loop instruction");
ADVANCE(1);
iteration_bound = LEB(); // second param is the iteration bound, which is important here
// guard call
REQUIRE(1);
if (wasm[i] != 0x10U)
if (hook[i] != 0x10U)
GUARD_ERROR("Missing call to _g after first and second i32.const at loop start");
ADVANCE(1);
uint64_t call_func_idx = LEB(); // the function being called *must* be the _g function
//printf("iteration_bound: %d, call_func_idx: %ld, guard_func_idx: %d\n",
// iteration_bound, call_func_idx, guard_func_idx);
if (iteration_bound == 0)
GUARD_ERROR("Guard call cannot specify 0 maxiter.");
if (call_func_idx != guard_func_idx)
GUARD_ERROR("Call after first and second i32.const at loop start was not _g");
if (guard_count++ > MAX_GUARD_CALLS)
GUARD_ERROR("Too many guard calls! Limit is 1024");
}
current = current->add_child(iteration_bound, i);
current->children.push_back(
{
.iteration_bound = iteration_bound,
.instruction_count = 0,
.parent = current,
.children = {}
});
block_depth++;
current = &(current->children[current->children.size()-1]);
continue;
}
@@ -396,20 +334,8 @@ check_guard(
current = current->parent;
if (current == 0 && block_depth == -1 && (i >= end_offset))
break; // codesec end
else if (current == 0)
{
GUARD_ERROR("Illegal block end (current==0)");
}
else if (block_depth < 0)
{
GUARD_ERROR("Illegal block end (block_depth<0)");
}
if (current->sanity_check != 0x1234ABCDU)
{
GUARD_ERROR("Sanity check failed (bad pointer)");
}
else if (current == 0 || block_depth < 0)
GUARD_ERROR("Illegal block end");
continue;
}
@@ -440,8 +366,8 @@ check_guard(
LEB();
continue;
}
if (instr == 0x0FU) // return
if (instr == 0x0FU) // return
{
if (DEBUG_GUARD_VERBOSE)
printf("Guard checker - return instruction at %d [%x]\n", i, i);
@@ -462,14 +388,6 @@ check_guard(
return {};
}
// enforce guard call limit
if (callee_idx == guard_func_idx)
{
if (guard_count++ > MAX_GUARD_CALLS)
GUARD_ERROR("Too many guard calls! Limit is 1024");
}
continue;
}
@@ -480,10 +398,10 @@ check_guard(
<< "codesec: " << codesec << " hook byte offset: " << i << "\n";
return {};
}
// reference instructions
if (instr >= 0xD0U && instr <= 0xD2)
if (instr >= 0xD0U && instr <= 0xD2)
{
if (DEBUG_GUARD_VERBOSE)
printf("Guard checker - reference instruction at %d [%x]\n", i, i);
@@ -492,7 +410,7 @@ check_guard(
{
REQUIRE(1);
// if it's a ref type it's a single byte
if (!(wasm[i] == 0x70U || wasm[i] == 0x6FU))
if (!(hook[i] == 0x70U || hook[i] == 0x6FU))
GUARD_ERROR("Invalid reftype in 0xD0 instruction");
ADVANCE(1);
}
@@ -502,7 +420,7 @@ check_guard(
REQUIRE(1);
LEB();
}
continue;
}
@@ -513,7 +431,7 @@ check_guard(
{
if (DEBUG_GUARD_VERBOSE)
printf("Guard checker - parametric instruction at %d [%x]\n", i, i);
if (instr == 0x1CU) // select t*
{
REQUIRE(1);
@@ -521,7 +439,7 @@ check_guard(
for (uint64_t n = 0; n < vec_count; ++n)
{
REQUIRE(1);
uint8_t v = wasm[i];
uint8_t v = hook[i];
if ((v >= 0x7BU && v <= 0x7FU) || v == 0x70U || v == 0x6FU)
{
// fine
@@ -559,13 +477,13 @@ check_guard(
LEB();
continue;
}
if (DEBUG_GUARD_VERBOSE)
printf("Guard checker - 0xFC instruction at %d [%x]\n", i, i);
uint64_t fc_type = LEB();
REQUIRE(1);
if (fc_type >= 12 && fc_type <= 17) // table instructions
{
LEB();
@@ -658,8 +576,8 @@ check_guard(
REQUIRE(4);
ADVANCE(4);
continue;
}
}
if (instr == 0x44U) // f64.const
{
if (DEBUG_GUARD_VERBOSE)
@@ -668,15 +586,15 @@ check_guard(
REQUIRE(8);
ADVANCE(8);
continue;
}
}
// even more numeric instructions
if (instr >= 0x45U && instr <= 0xC4U)
{
if (DEBUG_GUARD_VERBOSE)
printf("Guard checker - numeric instruction at %d [%x]\n", i, i);
// these have no arguments
// these have no arguments
continue;
}
@@ -716,7 +634,7 @@ check_guard(
}
continue;
}
// execution to here is an error, unknown instruction
{
char ihex[64];
@@ -726,14 +644,7 @@ check_guard(
}
}
bool recursion_limit_reached = false;
uint64_t wce = compute_wce(&(*root), 0, &recursion_limit_reached);
if (recursion_limit_reached)
{
GUARDLOG(hook::log::NESTING_LIMIT) << "GuardCheck "
<< "Maximum allowable depth of blocks reached (16 levels). Flatten your loops and conditions!.\n";
return {};
}
uint64_t wce = compute_wce(&root);
GUARDLOG(hook::log::INSTRUCTION_COUNT) << "GuardCheck "
<< "Total worse-case execution count: " << wce << "\n";
@@ -757,15 +668,15 @@ std::pair<
uint64_t // max instruction count for cbak()
>>
validateGuards(
std::vector<uint8_t> const& wasm,
std::vector<uint8_t> const& hook,
bool strict,
GuardLog guardLog,
std::string guardLogAccStr,
uint64_t rulesVersion = 0)
std::string guardLogAccStr)
{
uint64_t byteCount = wasm.size();
uint64_t byteCount = hook.size();
// 63 bytes is the smallest possible valid hook wasm
if (byteCount < 63U)
// RH TODO compute actual smallest possible hook and update this value
if (byteCount < 10)
{
GUARDLOG(hook::log::WASM_TOO_SMALL)
<< "Malformed transaction: Hook was not valid webassembly binary. Too small." << "\n";
@@ -776,7 +687,7 @@ validateGuards(
unsigned char header[8] = { 0x00U, 0x61U, 0x73U, 0x6DU, 0x01U, 0x00U, 0x00U, 0x00U };
for (int i = 0; i < 8; ++i)
{
if (wasm[i] != header[i])
if (hook[i] != header[i])
{
GUARDLOG(hook::log::WASM_BAD_MAGIC)
<< "Malformed transaction: Hook was not valid webassembly binary. "
@@ -793,14 +704,13 @@ validateGuards(
// this maps function ids to type ids, used for looking up the type of cbak and hook
// as established inside the wasm binary.
std::map<int, int> func_type_map;
std::map<int /* type idx */, std::map<int /* import index */, std::string /* api name */>> import_type_map;
// now we check for guards... first check if _g is imported
int guard_import_number = -1;
int last_import_number = -1;
int import_count = 0;
int last_section_type = 0;
for (int i = 8, j = 0; i < wasm.size();)
for (int i = 8, j = 0; i < hook.size();)
{
if (j == i)
@@ -815,27 +725,8 @@ validateGuards(
j = i;
// each web assembly section begins with a single byte section type 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 <= 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 {};
}
int section_length = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
int section_type = hook[i++];
int section_length = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
//int section_start = i;
if (DEBUG_GUARD_VERBOSE)
@@ -844,10 +735,10 @@ validateGuards(
int next_section = i + section_length;
// we are interested in the import section... we need to know if _g is imported and which import# it is
if (section_type == 2) // import section
{
// we are interested in the import section... we need to know if _g is imported and which import# it is
import_count = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
import_count = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
if (import_count <= 0)
{
GUARDLOG(hook::log::IMPORTS_MISSING)
@@ -862,8 +753,8 @@ validateGuards(
for (int j = 0; j < import_count; ++j)
{
// first check module name
int mod_length = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
if (mod_length < 1 || mod_length > (wasm.size() - i))
int mod_length = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
if (mod_length < 1 || mod_length > (hook.size() - i))
{
GUARDLOG(hook::log::IMPORT_MODULE_BAD)
<< "Malformed transaction. "
@@ -871,7 +762,7 @@ validateGuards(
return {};
}
if (std::string_view( (const char*)(wasm.data() + i), (size_t)mod_length ) != "env")
if (std::string_view( (const char*)(hook.data() + i), (size_t)mod_length ) != "env")
{
GUARDLOG(hook::log::IMPORT_MODULE_ENV)
<< "Malformed transaction. "
@@ -882,8 +773,8 @@ validateGuards(
i += mod_length; CHECK_SHORT_HOOK();
// next get import name
int name_length = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
if (name_length < 1 || name_length > (wasm.size() - i))
int name_length = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
if (name_length < 1 || name_length > (hook.size() - i))
{
GUARDLOG(hook::log::IMPORT_NAME_BAD)
<< "Malformed transaction. "
@@ -891,52 +782,37 @@ validateGuards(
return {};
}
std::string import_name { (const char*)(wasm.data() + i), (size_t)name_length };
std::string import_name { (const char*)(hook.data() + i), (size_t)name_length };
i += name_length; CHECK_SHORT_HOOK();
// next get import type
if (wasm[i] > 0x00)
if (hook[i] > 0x00)
{
// not a function import
GUARDLOG(hook::log::IMPORT_ILLEGAL)
<< "Malformed transaction. "
<< "Hook attempted to import an import type other than a function.\n";
return {};
// RH TODO check these other imports for weird stuff
i++; CHECK_SHORT_HOOK();
parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
continue;
}
// execution to here means it's a function import
i++; CHECK_SHORT_HOOK();
int type_idx =
parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
/*int type_idx = */
parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
// RH TODO: validate that the parameters of the imported functions are correct
if (import_name == "_g")
{
guard_import_number = func_upto;
}
else if (hook_api::import_whitelist.find(import_name) == hook_api::import_whitelist.end())
} else if (hook_api::import_whitelist.find(import_name) == hook_api::import_whitelist.end())
{
if (rulesVersion > 0 &&
hook_api::import_whitelist_1.find(import_name) != hook_api::import_whitelist_1.end())
{
// PASS, this is a version 1 api
}
else
{
GUARDLOG(hook::log::IMPORT_ILLEGAL)
<< "Malformed transaction. "
<< "Hook attempted to import a function that does not "
<< "appear in the hook_api function set: `" << import_name << "`" << "\n";
return {};
}
GUARDLOG(hook::log::IMPORT_ILLEGAL)
<< "Malformed transaction. "
<< "Hook attempted to import a function that does not "
<< "appear in the hook_api function set: `" << import_name << "`" << "\n";
return {};
}
// add to import map
if (import_type_map.find(type_idx) == import_type_map.end())
import_type_map[type_idx] = {{ func_upto, std::move(import_name) }};
else
import_type_map[type_idx].emplace(func_upto, std::move(import_name));
func_upto++;
}
@@ -958,7 +834,7 @@ validateGuards(
} else
if (section_type == 7) // export section
{
int export_count = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
int export_count = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
if (export_count <= 0)
{
GUARDLOG(hook::log::EXPORTS_MISSING)
@@ -970,14 +846,14 @@ validateGuards(
for (int j = 0; j < export_count; ++j)
{
int name_len = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
int name_len = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
if (name_len == 4)
{
if (wasm[i] == 'h' && wasm[i+1] == 'o' && wasm[i+2] == 'o' && wasm[i+3] == 'k')
if (hook[i] == 'h' && hook[i+1] == 'o' && hook[i+2] == 'o' && hook[i+3] == 'k')
{
i += name_len; CHECK_SHORT_HOOK();
if (wasm[i] != 0)
if (hook[i] != 0)
{
GUARDLOG(hook::log::EXPORT_HOOK_FUNC)
<< "Malformed transaction. "
@@ -986,14 +862,14 @@ validateGuards(
}
i++; CHECK_SHORT_HOOK();
hook_func_idx = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
hook_func_idx = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
continue;
}
if (wasm[i] == 'c' && wasm[i+1] == 'b' && wasm[i+2] == 'a' && wasm[i+3] == 'k')
if (hook[i] == 'c' && hook[i+1] == 'b' && hook[i+2] == 'a' && hook[i+3] == 'k')
{
i += name_len; CHECK_SHORT_HOOK();
if (wasm[i] != 0)
if (hook[i] != 0)
{
GUARDLOG(hook::log::EXPORT_CBAK_FUNC)
<< "Malformed transaction. "
@@ -1001,13 +877,13 @@ validateGuards(
return {};
}
i++; CHECK_SHORT_HOOK();
cbak_func_idx = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
cbak_func_idx = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
continue;
}
}
i += name_len + 1;
parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
}
// execution to here means export section was parsed
@@ -1022,7 +898,7 @@ validateGuards(
}
else if (section_type == 3) // function section
{
int function_count = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
int function_count = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
if (function_count <= 0)
{
GUARDLOG(hook::log::FUNCS_MISSING)
@@ -1034,7 +910,7 @@ validateGuards(
for (int j = 0; j < function_count; ++j)
{
int type_idx = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
int type_idx = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
if (DEBUG_GUARD)
printf("Function map: func %d -> type %d\n", j, type_idx);
func_type_map[j] = type_idx;
@@ -1076,22 +952,29 @@ validateGuards(
int64_t maxInstrCountHook = 0;
int64_t maxInstrCountCbak = 0;
/* printf( "hook_func_idx: %d\ncbak_func_idx: %d\n"
"hook_type_idx: %d\ncbak_type_idx: %d\n",
*hook_func_idx,
*cbak_func_idx,
hook_type_idx, *cbak_type_idx);
*/
// second pass... where we check all the guard function calls follow the guard rules
// minimal other validation in this pass because first pass caught most of it
for (int i = 8; i < wasm.size();)
for (int i = 8; i < hook.size();)
{
int section_type = wasm[i++];
int section_length = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
int section_type = hook[i++];
int section_length = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
//int section_start = i;
int next_section = i + section_length;
if (section_type == 1) // type section
{
int type_count = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
int type_count = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
for (int j = 0; j < type_count; ++j)
{
if (wasm[i++] != 0x60)
if (hook[i++] != 0x60)
{
GUARDLOG(hook::log::FUNC_TYPE_INVALID)
<< "Invalid function type. "
@@ -1102,77 +985,18 @@ validateGuards(
}
CHECK_SHORT_HOOK();
// check the consistency of the type
std::optional<std::string> first_name;
std::optional<std::reference_wrapper<std::vector<uint8_t> const>> first_signature;
if (auto const& usage = import_type_map.find(j); usage != import_type_map.end())
int param_count = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
if (j == hook_type_idx && param_count != 1)
{
for (auto const& [import_idx, api_name] : usage->second)
{
auto const& api_signature =
hook_api::import_whitelist.find(api_name) != hook_api::import_whitelist.end()
? hook_api::import_whitelist.find(api_name)->second
: hook_api::import_whitelist_1.find(api_name)->second;
if (!first_signature)
{
first_name = api_name;
first_signature = api_signature;
continue;
}
if (api_signature != (*first_signature).get())
{
GUARDLOG(hook::log::FUNC_TYPE_INVALID)
<< "Function type is inconsitent across referenced apis. "
<< "This probably means one of your apis has the wrong signature. "
<< "(Either: " << *first_name << ", or: " << api_name << ".) "
<< "Codesec: " << section_type << " "
<< "Local: " << j << " "
<< "Offset: " << i << "\n";
return {};
}
}
}
else if (j == hook_type_idx)
{
// pass
}
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 {};
}
int param_count = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
if (j == hook_type_idx)
{
if (param_count != 1)
{
GUARDLOG(hook::log::PARAM_HOOK_CBAK)
<< "Malformed transaction. "
<< "hook and cbak function definition must have exactly one parameter (uint32_t)." << "\n";
return {};
}
}
else
if (param_count != (*first_signature).get().size() - 1)
{
GUARDLOG(hook::log::FUNC_TYPE_INVALID)
GUARDLOG(hook::log::PARAM_HOOK_CBAK)
<< "Malformed transaction. "
<< "Hook API: " << *first_name << " has the wrong number of parameters.\n";
<< "hook and cbak function definition must have exactly one parameter (uint32_t)." << "\n";
return {};
}
for (int k = 0; k < param_count; ++k)
{
int param_type = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
int param_type = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
if (param_type == 0x7FU || param_type == 0x7EU ||
param_type == 0x7DU || param_type == 0x7CU)
{
@@ -1194,30 +1018,20 @@ validateGuards(
j, *hook_func_idx, *cbak_func_idx, param_count, param_type);
// hook and cbak parameter check here
if (j == hook_type_idx)
if (j == hook_type_idx && param_type != 0x7FU /* i32 */)
{
if (param_type != 0x7FU /* i32 */)
{
GUARDLOG(hook::log::PARAM_HOOK_CBAK)
<< "Malformed transaction. "
<< "hook and cbak function definition must have exactly one uint32_t parameter." << "\n";
return {};
}
}
else
if ((*first_signature).get()[k + 1] != param_type)
{
GUARDLOG(hook::log::FUNC_PARAM_INVALID)
GUARDLOG(hook::log::PARAM_HOOK_CBAK)
<< "Malformed transaction. "
<< "Hook API: " << *first_name << " definition parameters incorrect." << "\n";
<< "hook and cbak function definition must have exactly one uint32_t parameter." << "\n";
return {};
}
}
int result_count = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
int result_count = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
// RH TODO: enable this for production
// this needs a reliable hook cleaner otherwise it will catch most compilers out
if (result_count != 1)
if (strict && result_count != 1)
{
GUARDLOG(hook::log::FUNC_RETURN_COUNT)
<< "Malformed transaction. "
@@ -1229,7 +1043,7 @@ validateGuards(
// so for completeness this loop is here but can be taken out in prod
for (int k = 0; k < result_count; ++k)
{
int result_type = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
int result_type = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
if (result_type == 0x7F || result_type == 0x7E ||
result_type == 0x7D || result_type == 0x7C)
{
@@ -1251,29 +1065,17 @@ validateGuards(
j, *hook_func_idx, *cbak_func_idx, result_count, result_type);
// hook and cbak return type check here
if (j == hook_type_idx)
if (j == hook_type_idx && (result_count != 1 || result_type != 0x7E /* i64 */))
{
if (result_count != 1 || result_type != 0x7E /* i64 */)
{
GUARDLOG(hook::log::RETURN_HOOK_CBAK)
<< "Malformed transaction. "
<< (j == hook_type_idx ? "hook" : "cbak") << " j=" << j << " "
<< " function definition must have exactly one int64_t return type. "
<< "resultcount=" << result_count << ", resulttype=" << result_type << ", "
<< "paramcount=" << param_count << "\n";
return {};
}
}
else
if ((*first_signature).get()[0] != result_type)
{
GUARDLOG(hook::log::FUNC_RETURN_INVALID)
GUARDLOG(hook::log::RETURN_HOOK_CBAK)
<< "Malformed transaction. "
<< "Hook API: " << *first_name << " definition return type incorrect." << "\n";
<< (j == hook_type_idx ? "hook" : "cbak") << " j=" << j << " "
<< " function definition must have exactly one int64_t return type. "
<< "resultcount=" << result_count << ", resulttype=" << result_type << ", "
<< "paramcount=" << param_count << "\n";
return {};
}
}
}
}
else
@@ -1281,19 +1083,19 @@ validateGuards(
{
// RH TODO: parse anywhere else an expr is allowed in wasm and enforce rules there too
// these are the functions
int func_count = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
int func_count = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
for (int j = 0; j < func_count; ++j)
{
// parse locals
int code_size = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
int code_size = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
int code_end = i + code_size;
int local_count = parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
int local_count = parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
for (int k = 0; k < local_count; ++k)
{
/*int array_size = */
parseLeb128(wasm, i, &i); CHECK_SHORT_HOOK();
if (!(wasm[i] >= 0x7C && wasm[i] <= 0x7F))
parseLeb128(hook, i, &i); CHECK_SHORT_HOOK();
if (!(hook[i] >= 0x7C && hook[i] <= 0x7F))
{
GUARDLOG(hook::log::TYPE_INVALID)
<< "Invalid local type. "
@@ -1312,7 +1114,7 @@ validateGuards(
auto valid =
check_guard(
wasm,
hook,
j,
i,
code_end,
@@ -1345,4 +1147,22 @@ validateGuards(
return std::pair<uint64_t, uint64_t>{maxInstrCountHook, maxInstrCountCbak};
/*
GUARDLOG(hook::log::WASM_SMOKE_TEST)
<< "Trying to wasm instantiate proposed hook "
<< "size = " << hook.size() << "\n";
std::optional<std::string> result =
hook::HookExecutor::validateWasm(hook.data(), (size_t)hook.size());
if (result)
{
GUARDLOG(hook::log::WASM_TEST_FAILURE)
<< "Tried to set a hook with invalid code. VM error: "
<< *result << "\n";
return {};
}
*/
return std::pair<uint64_t, uint64_t>{maxInstrCountHook, maxInstrCountCbak};
}

View File

@@ -142,7 +142,6 @@
R hook_api::F(hook::HookContext& hookCtx, WasmEdge_CallingFrameContext const& frameCtx)
#define HOOK_SETUP()\
try {\
[[maybe_unused]] ApplyContext& applyCtx = hookCtx.applyCtx;\
[[maybe_unused]] auto& view = applyCtx.view();\
[[maybe_unused]] auto j = applyCtx.app.journal("View");\
@@ -150,18 +149,7 @@
WasmEdge_CallingFrameGetMemoryInstance(&frameCtx, 0);\
[[maybe_unused]] unsigned char* memory = WasmEdge_MemoryInstanceGetPointer(memoryCtx, 0, 0);\
[[maybe_unused]] const uint64_t memory_length = WasmEdge_MemoryInstanceGetPageSize(memoryCtx) * \
WasmEdge_kPageSize;\
if (!memoryCtx || !memory || !memory_length)\
return INTERNAL_ERROR;\
#define HOOK_TEARDOWN()\
} catch (const std::exception& e) {\
JLOG(hookCtx.applyCtx.app.journal("View").error())\
<< "HookError[" << HC_ACC() << "]: "\
<< __func__ << " threw uncaught exception, what="\
<< e.what();\
return INTERNAL_ERROR;\
}
WasmEdge_kPageSize;
#define WRITE_WASM_MEMORY(bytes_written, guest_dst_ptr, guest_dst_len,\
host_src_ptr, host_src_len, host_memory_ptr, guest_memory_length)\
@@ -175,10 +163,8 @@
<< " bytes past end of wasm memory";\
return OUT_OF_BOUNDS;\
}\
if (!WasmEdge_ResultOK(\
WasmEdge_MemoryInstanceSetData(memoryCtx, \
reinterpret_cast<const uint8_t*>(host_src_ptr), guest_dst_ptr, bytes_to_write)))\
return INTERNAL_ERROR;\
WasmEdge_MemoryInstanceSetData(memoryCtx, \
reinterpret_cast<const uint8_t*>(host_src_ptr), guest_dst_ptr, bytes_to_write);\
bytes_written += bytes_to_write;\
}
@@ -191,9 +177,34 @@
return bytes_written;\
}
#define RETURN_HOOK_TRACE(read_ptr, read_len, t)\
{\
if (j.trace())\
{\
int rl = read_len;\
if (rl > 1024)\
rl = 1024;\
if (NOT_IN_BOUNDS(read_ptr, read_len, memory_length))\
return OUT_OF_BOUNDS;\
std::string out;\
out.reserve(rl);\
if (!(read_ptr == 0 && read_len == 0))\
{\
out = std::string((const char*)(memory + read_ptr), (size_t)rl);\
/* replace all nul chars with spaces */\
for (char* ptr = out.data(); ptr < out.data() + out.size(); ++ptr)\
if (*ptr == '\0') *ptr = ' ';\
}\
j.trace()\
<< "HookTrace[" << HC_ACC() << "]: "\
<< out << (out.empty() ? "" : " ")\
<< t;\
}\
return 0;\
}
// ptr = pointer inside the wasm memory space
#define NOT_IN_BOUNDS(ptr, len, memory_length)\
((static_cast<uint64_t>(ptr) >= static_cast<uint64_t>(memory_length)) || \
((static_cast<uint64_t>(ptr) > static_cast<uint64_t>(memory_length)) || \
((static_cast<uint64_t>(ptr) + static_cast<uint64_t>(len)) > static_cast<uint64_t>(memory_length)))
#define HOOK_EXIT(read_ptr, read_len, error_code, exit_type)\
@@ -222,28 +233,3 @@
hookCtx.result.exitCode = error_code;\
return (exit_type == hook_api::ExitType::ACCEPT ? RC_ACCEPT : RC_ROLLBACK);\
}
#define WRITE_WASM_MEMORY_OR_RETURN_AS_INT64(write_ptr_in, write_len_in, data_ptr_in, data_len_in, is_account_in)\
{\
uint8_t* data_ptr = (uint8_t*)(data_ptr_in);\
int data_len = (data_len_in);\
if (is_account_in)\
{\
data_len--;\
data_ptr++;\
}\
if (data_len < 0 ||\
data_len > (data_len_in) ||\
data_ptr < (data_ptr_in))\
return INTERNAL_ERROR;\
if (data_len == 0)\
return 0;\
if ((write_ptr_in) == 0)\
return data_as_int64(data_ptr, data_len);\
if (data_len > (write_len_in))\
return TOO_SMALL;\
WRITE_WASM_MEMORY_AND_RETURN(\
(write_ptr_in), (write_len_in),\
data_ptr, data_len,\
memory, memory_length);\
}

View File

@@ -1,269 +0,0 @@
#ifndef HOOKMISC_INCLUDED
#define HOOKMISC_INCLUDED 1
namespace ripple
{
// RH TODO: there's definitely a mucher nicer way to do this, but it involves modifying the base_uint
// class and we don't want to do that yet.
static const std::array<ripple::uint256, 256> UINT256_BIT =
{
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000001"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000002"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000004"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000008"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000010"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000020"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000040"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000080"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000100"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000200"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000400"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000000800"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000001000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000002000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000004000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000008000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000010000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000020000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000040000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000080000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000100000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000200000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000400000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000000800000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000001000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000002000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000004000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000008000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000010000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000020000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000040000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000080000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000100000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000200000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000400000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000000800000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000001000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000002000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000004000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000008000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000010000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000020000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000040000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000080000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000100000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000200000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000400000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000000800000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000001000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000002000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000004000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000008000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000010000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000020000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000040000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000080000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000100000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000200000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000400000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000000800000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000001000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000002000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000004000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000008000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000010000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000020000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000040000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000080000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000100000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000200000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000400000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000000800000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000001000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000002000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000004000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000008000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000010000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000020000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000040000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000080000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000100000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000200000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000400000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000000800000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000001000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000002000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000004000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000008000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000010000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000020000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000040000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000080000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000100000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000200000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000400000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000000800000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000001000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000002000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000004000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000008000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000010000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000020000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000040000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000080000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000100000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000200000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000400000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000000800000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000001000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000002000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000004000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000008000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000010000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000020000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000040000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000080000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000100000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000200000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000400000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000000800000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000001000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000002000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000004000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000008000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000010000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000020000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000040000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000080000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000100000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000200000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000400000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000000800000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000001000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000002000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000004000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000008000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000010000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000020000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000040000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000080000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000100000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000200000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000400000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000000800000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000001000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000002000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000004000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000008000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000010000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000020000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000040000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000080000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000100000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000200000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000400000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000000800000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000001000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000002000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000004000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000008000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000010000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000020000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000040000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000080000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000100000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000200000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000400000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000000800000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000001000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000002000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000004000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000008000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000010000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000020000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000040000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000080000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000100000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000200000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000400000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000000800000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000001000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000002000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000004000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000008000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000010000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000020000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000040000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000080000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000100000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000200000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000400000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000000800000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000001000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000002000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000004000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000008000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000010000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000020000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000040000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000080000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000100000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000200000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000400000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000000800000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000001000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000002000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000004000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000008000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000010000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000020000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000040000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000080000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000100000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000200000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000400000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000000800000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000001000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000002000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000004000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000008000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000010000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000020000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000040000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000080000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000100000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000200000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000400000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000000800000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000001000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000002000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000004000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000008000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000010000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000020000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000040000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000080000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000100000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000200000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000400000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0000800000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0001000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0002000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0004000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0008000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0010000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0020000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0040000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0080000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0100000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0200000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0400000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("0800000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("1000000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("2000000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("4000000000000000000000000000000000000000000000000000000000000000"),
ripple::uint256("8000000000000000000000000000000000000000000000000000000000000000")
};
}
#endif

View File

@@ -14,7 +14,6 @@
#include <ripple/protocol/digest.h>
#include <wasmedge/wasmedge.h>
#include <ripple/app/hook/Macro.h>
#include <ripple/app/hook/Misc.h>
#include <ripple/app/hook/Enum.h>
namespace hook
@@ -27,59 +26,48 @@ namespace hook
// and is preserved across the execution of the set of hook chains
// being executed in the current transaction. It is committed to lgr
// only upon tesSuccess for the otxn.
class HookStateMap :
public std::map<
ripple::AccountID, // account that owns the state
using HookStateMap =
std::map<
ripple::AccountID, // account that owns the state
std::pair<
int64_t, // remaining available ownercount
std::map<ripple::uint256, // namespace
std::map<ripple::uint256, // key
std::pair<
int64_t, // remaining available ownercount
std::map<ripple::uint256, // namespace
std::map<ripple::uint256, // key
std::pair<
bool, // is modified from ledger value
ripple::Blob>>>>> // the value
{
public:
uint32_t modified_entry_count = 0; // track the number of total modified
};
bool, // is modified from ledger value
ripple::Blob>>>>>; // the value
using namespace ripple;
static const std::map<uint16_t, uint8_t> TSHAllowances =
{
{ttPAYMENT, tshROLLBACK },
{ttESCROW_CREATE, tshROLLBACK },
{ttESCROW_FINISH, tshROLLBACK },
{ttACCOUNT_SET, tshNONE },
{ttESCROW_CANCEL, tshCOLLECT },
{ttREGULAR_KEY_SET, tshROLLBACK },
{ttOFFER_CREATE, tshCOLLECT },
{ttOFFER_CANCEL, tshNONE },
{ttTICKET_CREATE, tshNONE },
{ttSIGNER_LIST_SET, tshROLLBACK },
{ttPAYCHAN_CREATE, tshROLLBACK },
{ttPAYCHAN_FUND, tshCOLLECT },
{ttPAYCHAN_CLAIM, tshCOLLECT },
{ttCHECK_CREATE, tshROLLBACK },
{ttCHECK_CASH, tshROLLBACK },
{ttCHECK_CANCEL, tshCOLLECT },
{ttDEPOSIT_PREAUTH, tshROLLBACK },
{ttTRUST_SET, tshCOLLECT },
{ttACCOUNT_DELETE, tshROLLBACK },
{ttHOOK_SET, tshNONE },
{ttNFTOKEN_MINT, tshROLLBACK },
{ttNFTOKEN_BURN, tshCOLLECT },
{ttNFTOKEN_CREATE_OFFER, tshROLLBACK },
{ttNFTOKEN_CANCEL_OFFER, tshCOLLECT },
{ttNFTOKEN_ACCEPT_OFFER, tshROLLBACK },
{ttCLAIM_REWARD, tshROLLBACK },
{ttINVOKE, tshROLLBACK },
{ttURITOKEN_MINT, tshNONE },
{ttURITOKEN_BURN, tshROLLBACK },
{ttURITOKEN_BUY, tshROLLBACK },
{ttURITOKEN_CREATE_SELL_OFFER, tshROLLBACK },
{ttURITOKEN_CANCEL_SELL_OFFER, tshNONE },
{ttIMPORT, tshROLLBACK },
{ttPAYMENT, tshROLLBACK },
{ttESCROW_CREATE, tshROLLBACK },
{ttESCROW_FINISH, tshROLLBACK },
{ttACCOUNT_SET, tshNONE },
{ttESCROW_CANCEL, tshCOLLECT },
{ttREGULAR_KEY_SET, tshROLLBACK },
{ttOFFER_CREATE, tshCOLLECT },
{ttOFFER_CANCEL, tshNONE },
{ttTICKET_CREATE, tshNONE },
{ttSIGNER_LIST_SET, tshROLLBACK },
{ttPAYCHAN_CREATE, tshROLLBACK },
{ttPAYCHAN_FUND, tshCOLLECT },
{ttPAYCHAN_CLAIM, tshCOLLECT },
{ttCHECK_CREATE, tshROLLBACK },
{ttCHECK_CASH, tshROLLBACK },
{ttCHECK_CANCEL, tshCOLLECT },
{ttDEPOSIT_PREAUTH, tshROLLBACK },
{ttTRUST_SET, tshCOLLECT },
{ttACCOUNT_DELETE, tshROLLBACK },
{ttHOOK_SET, tshNONE },
{ttNFTOKEN_MINT, tshROLLBACK },
{ttNFTOKEN_BURN, tshCOLLECT },
{ttNFTOKEN_CREATE_OFFER, tshROLLBACK },
{ttNFTOKEN_CANCEL_OFFER, tshCOLLECT },
{ttNFTOKEN_ACCEPT_OFFER, tshROLLBACK },
{ttCLAIM_REWARD, tshROLLBACK },
{ttINVOKE, tshROLLBACK }
};
@@ -90,6 +78,9 @@ namespace hook
namespace hook_api
{
#define TER_TO_HOOK_RETURN_CODE(x)\
(((TERtoInt(x)) << 16)*-1)
// for debugging if you want a lot of output change to 1
#define HOOK_DBG 0
#define DBG_PRINTF if (HOOK_DBG) printf
@@ -208,13 +199,10 @@ namespace hook_api
DECLARE_HOOK_FUNCTION(int64_t, otxn_id, uint32_t write_ptr, uint32_t write_len, uint32_t flags );
DECLARE_HOOK_FUNCNARG(int64_t, otxn_type );
DECLARE_HOOK_FUNCTION(int64_t, otxn_slot, uint32_t slot_no );
DECLARE_HOOK_FUNCTION(int64_t, otxn_param, uint32_t write_ptr, uint32_t write_len,
uint32_t read_ptr, uint32_t read_len);
DECLARE_HOOK_FUNCTION(int64_t, meta_slot, uint32_t slot_no );
DECLARE_HOOK_FUNCTION(int64_t, xpop_slot, uint32_t slot_no_tx, uint32_t slot_no_meta );
/*
DECLARE_HOOK_FUNCTION(int64_t, str_find, uint32_t hread_ptr, uint32_t hread_len,
uint32_t nread_ptr, uint32_t nread_len,
uint32_t mode, uint32_t n);
@@ -229,7 +217,7 @@ namespace hook_api
DECLARE_HOOK_FUNCTION(int64_t, str_concat, uint32_t write_ptr, uint32_t write_len,
uint32_t read_ptr, uint32_t read_len,
uint64_t operand, uint32_t operand_type);
*/
} /* end namespace hook_api */
namespace hook
@@ -269,6 +257,13 @@ namespace hook
struct HookContext;
uint32_t maxHookStateDataSize(void);
uint32_t maxHookWasmSize(void);
uint32_t maxHookParameterKeySize(void);
uint32_t maxHookParameterValueSize(void);
uint32_t maxHookChainLength(void);
uint32_t computeHookStateOwnerCount(uint32_t hookStateCount);
@@ -390,7 +385,7 @@ namespace hook
bool /* retval of true means an error */
gatherHookParameters(
std::shared_ptr<ripple::STLedgerEntry> const& hookDef,
ripple::STObject const& hookObj,
ripple::STObject const* hookObj,
std::map<std::vector<uint8_t>, std::vector<uint8_t>>& parameters,
beast::Journal const& j_);
@@ -436,75 +431,31 @@ namespace hook
public:
HookContext& hookCtx;
HookContext hookCtx;
WasmEdge_ModuleInstanceContext* importObj;
class WasmEdgeVM
{
public:
WasmEdge_ConfigureContext* conf = NULL;
WasmEdge_VMContext* ctx = NULL;
WasmEdgeVM()
{
conf = WasmEdge_ConfigureCreate();
if (!conf)
return;
WasmEdge_ConfigureStatisticsSetInstructionCounting(conf, true);
ctx = WasmEdge_VMCreate(conf, NULL);
}
bool
sane()
{
return ctx && conf;
}
~WasmEdgeVM()
{
if (conf)
WasmEdge_ConfigureDelete(conf);
if (ctx)
WasmEdge_VMDelete(ctx);
}
};
// if an error occured return a string prefixed with `prefix` followed by the error description
static std::optional<std::string> getWasmError(std::string prefix, WasmEdge_Result& res)
{
if (WasmEdge_ResultOK(res))
return {};
const char* msg = WasmEdge_ResultGetMessage(res);
return prefix + ": " + (msg ? msg : "unknown error");
}
/**
* Validate that a web assembly blob can be loaded by wasmedge
*/
static std::optional<std::string> validateWasm(const void* wasm, size_t len)
{
WasmEdgeVM vm;
if (!vm.sane())
return "Could not create WASMEDGE instance";
WasmEdge_Result res =
WasmEdge_VMLoadWasmFromBuffer(vm.ctx, reinterpret_cast<const uint8_t*>(wasm), len);
if (auto err = getWasmError("VMLoadWasmFromBuffer failed", res); err)
return *err;
res = WasmEdge_VMValidate(vm.ctx);
if (auto err = getWasmError("VMValidate failed", res); err)
return *err;
return {};
std::optional<std::string> ret;
WasmEdge_ConfigureContext* confCtx = WasmEdge_ConfigureCreate();
WasmEdge_VMContext* vmCtx = WasmEdge_VMCreate(confCtx, NULL);
WasmEdge_Result res = WasmEdge_VMLoadWasmFromBuffer(vmCtx, reinterpret_cast<const uint8_t*>(wasm), len);
if (!WasmEdge_ResultOK(res))
ret = "VMLoadWasmFromBuffer failed";
else
{
res = WasmEdge_VMValidate(vmCtx);
if (!WasmEdge_ResultOK(res))
ret = "VMValidate failed";
}
WasmEdge_VMDelete(vmCtx);
WasmEdge_ConfigureDelete(confCtx);
return ret;
}
/**
* Execute web assembly byte code against the constructed Hook Context
* Once execution has occured the exector is spent and cannot be used again and should be destructed
@@ -521,47 +472,61 @@ namespace hook
JLOG(j.trace())
<< "HookInfo[" << HC_ACC() << "]: creating wasm instance";
WasmEdge_LogOff();
WasmEdge_ConfigureContext* confCtx = WasmEdge_ConfigureCreate();
WasmEdge_ConfigureStatisticsSetInstructionCounting(confCtx, true);
WasmEdge_VMContext* vmCtx = WasmEdge_VMCreate(confCtx, NULL);
WasmEdgeVM vm;
if (!vm.sane())
{
JLOG(j.warn())
<< "HookError[" << HC_ACC() << "]: Could not create WASMEDGE instance.";
hookCtx.result.exitType = hook_api::ExitType::WASM_ERROR;
return;
}
WasmEdge_Result res = WasmEdge_VMRegisterModuleFromImport(vm.ctx, this->importObj);
if (auto err = getWasmError("Import phase failed", res); err)
WasmEdge_Result res = WasmEdge_VMRegisterModuleFromImport(vmCtx, this->importObj);
if (!WasmEdge_ResultOK(res))
{
hookCtx.result.exitType = hook_api::ExitType::WASM_ERROR;
JLOG(j.trace()) << "HookError[" << HC_ACC() << "]: " << *err;
return;
JLOG(j.trace())
<< "HookError[" << HC_ACC() << "]: Import phase failed "
<< WasmEdge_ResultGetMessage(res);
}
WasmEdge_Value params[1] = { WasmEdge_ValueGenI32((int64_t)wasmParam) };
WasmEdge_Value returns[1];
res =
WasmEdge_VMRunWasmFromBuffer(vm.ctx, reinterpret_cast<const uint8_t*>(wasm), len,
callback ? cbakFunctionName : hookFunctionName,
params, 1, returns, 1);
if (auto err = getWasmError("WASM VM error", res); err)
else
{
JLOG(j.warn()) << "HookError[" << HC_ACC() << "]: " << *err;
hookCtx.result.exitType = hook_api::ExitType::WASM_ERROR;
return;
WasmEdge_Value params[1] = { WasmEdge_ValueGenI32((int64_t)wasmParam) };
WasmEdge_Value returns[1];
/*
printf("executing hook wasm:\n");
for (int j = 0; j < len; j++)
{
if (j % 16 == 0)
printf("0x%08X:\t", j);
printf("%02X%s", (reinterpret_cast<const uint8_t*>(wasm))[j],
(j % 16 == 15 ? "\n" :
(j % 4 == 3 ? " " :
(j % 2 == 1 ? " " : ""))));
}
printf("\n----\n");
*/
res =
WasmEdge_VMRunWasmFromBuffer(vmCtx, reinterpret_cast<const uint8_t*>(wasm), len,
callback ? cbakFunctionName : hookFunctionName,
params, 1, returns, 1);
if (!WasmEdge_ResultOK(res))
{
JLOG(j.warn())
<< "HookError[" << HC_ACC() << "]: WASM VM error "
<< WasmEdge_ResultGetMessage(res);
hookCtx.result.exitType = hook_api::ExitType::WASM_ERROR;
}
else
{
auto* statsCtx= WasmEdge_VMGetStatisticsContext(vmCtx);
hookCtx.result.instructionCount = WasmEdge_StatisticsGetInstrCount(statsCtx);
}
}
auto* statsCtx= WasmEdge_VMGetStatisticsContext(vm.ctx);
hookCtx.result.instructionCount = WasmEdge_StatisticsGetInstrCount(statsCtx);
// RH NOTE: stack unwind will clean up WasmEdgeVM
WasmEdge_ConfigureDelete(confCtx);
WasmEdge_VMDelete(vmCtx);
}
HookExecutor(HookContext& ctx)
@@ -618,8 +583,6 @@ namespace hook
ADD_HOOK_FUNCTION(otxn_id, ctx);
ADD_HOOK_FUNCTION(otxn_type, ctx);
ADD_HOOK_FUNCTION(otxn_slot, ctx);
ADD_HOOK_FUNCTION(otxn_param, ctx);
ADD_HOOK_FUNCTION(hook_account, ctx);
ADD_HOOK_FUNCTION(hook_hash, ctx);
ADD_HOOK_FUNCTION(hook_again, ctx);
@@ -655,14 +618,12 @@ namespace hook
ADD_HOOK_FUNCTION(trace_float, ctx);
ADD_HOOK_FUNCTION(meta_slot, ctx);
ADD_HOOK_FUNCTION(xpop_slot, ctx);
/*
ADD_HOOK_FUNCTION(str_find, ctx);
ADD_HOOK_FUNCTION(str_replace, ctx);
ADD_HOOK_FUNCTION(str_compare, ctx);
ADD_HOOK_FUNCTION(str_concat, ctx);
*/
WasmEdge_TableInstanceContext* hostTable = WasmEdge_TableInstanceCreate(tableType);
WasmEdge_ModuleInstanceAddTable(importObj, tableName, hostTable);

View File

@@ -76,7 +76,7 @@ int main(int argc, char** argv)
close(fd);
auto result =
validateGuards(hook, std::cout, "", 1);
validateGuards(hook, true, std::cout, "");
if (!result)
{

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -35,8 +35,9 @@ AcceptedLedgerTx::AcceptedLedgerTx(
{
assert(!ledger->open());
SerializerInto s(mRawMeta);
Serializer s;
met->add(s);
mRawMeta = std::move(s.modData());
mJson = Json::objectValue;
mJson[jss::transaction] = mTxn->getJson(JsonOptions::none);
@@ -76,7 +77,7 @@ std::string
AcceptedLedgerTx::getEscMeta() const
{
assert(!mRawMeta.empty());
return sqlBlobLiteral(makeSlice(mRawMeta));
return sqlBlobLiteral(mRawMeta);
}
} // namespace ripple

View File

@@ -46,6 +46,8 @@ ConsensusTransSetSF::gotNode(
if (fromFilter)
return;
m_nodeCache.insert(nodeHash, nodeData);
if ((type == SHAMapNodeType::tnTRANSACTION_NM) && (nodeData.size() > 16))
{
// this is a transaction, and we didn't have it
@@ -54,56 +56,46 @@ ConsensusTransSetSF::gotNode(
try
{
// We use substr to skip the 4 byte prefix
auto stx =
std::make_shared<STTx const>(makeSlice(nodeData).substr(4));
// skip prefix
Serializer s(nodeData.data() + 4, nodeData.size() - 4);
SerialIter sit(s.slice());
auto stx = std::make_shared<STTx const>(std::ref(sit));
assert(stx->getTransactionID() == nodeHash.as_uint256());
app_.getJobQueue().addJob(
jtTRANSACTION, "TXS->TXN", [app = &app_, stx]() {
app->getOPs().submitTransaction(stx);
});
auto const pap = &app_;
app_.getJobQueue().addJob(jtTRANSACTION, "TXS->TXN", [pap, stx]() {
pap->getOPs().submitTransaction(stx);
});
}
catch (std::exception const& ex)
catch (std::exception const&)
{
JLOG(j_.warn())
<< "Fetched invalid tx in proposed set: " << ex.what();
return;
JLOG(j_.warn()) << "Fetched invalid transaction in proposed set";
}
}
m_nodeCache.insert(nodeHash.as_uint256(), nodeData);
}
std::optional<Blob>
ConsensusTransSetSF::getNode(SHAMapHash const& nodeHash) const
{
auto const nh = nodeHash.as_uint256();
Blob nodeData;
// if (m_nodeCache.retrieve(nodeHash, nodeData))
// return nodeData;
//
//
if (auto e = m_nodeCache.fetch(nh))
return *e; // This requires copying the blob.
if (m_nodeCache.retrieve(nodeHash, nodeData))
return nodeData;
auto txn =
app_.getMasterTransaction().fetch_from_cache(nodeHash.as_uint256());
if (!txn)
return std::nullopt;
if (txn)
{
// this is a transaction, and we have it
JLOG(j_.trace()) << "Node in our acquiring TX set is TXN we have";
Serializer s;
s.add32(HashPrefix::transactionID);
txn->getSTransaction()->add(s);
assert(sha512Half(s.slice()) == nodeHash.as_uint256());
nodeData = s.peekData();
return nodeData;
}
nodeData.clear();
nodeData.reserve(768);
// this is a transaction, and we have it
JLOG(j_.trace()) << "Node in our acquiring TX set is TXN we have";
SerializerInto s(nodeData);
s.add32(HashPrefix::transactionID);
txn->getSTransaction()->add(s);
assert(sha512Half(makeSlice(nodeData)) == nodeHash.as_uint256());
return nodeData;
return std::nullopt;
}
} // namespace ripple

View File

@@ -34,7 +34,7 @@ namespace ripple {
class ConsensusTransSetSF : public SHAMapSyncFilter
{
public:
using NodeCache = TaggedCache<uint256, Blob>;
using NodeCache = TaggedCache<SHAMapHash, Blob>;
ConsensusTransSetSF(Application& app, NodeCache& nodeCache);

View File

@@ -61,10 +61,24 @@ public:
void
update(std::uint32_t seq);
/** Returns true if we got all the data. */
bool
isComplete() const
{
return complete_;
}
/** Returns false if we failed to get the data. */
bool
isFailed() const
{
return failed_;
}
std::shared_ptr<Ledger const>
getLedger() const
{
return ledger_;
return mLedger;
}
std::uint32_t
@@ -161,9 +175,14 @@ private:
clock_type& m_clock;
clock_type::time_point mLastAction;
std::shared_ptr<Ledger> ledger_;
std::shared_ptr<Ledger> mLedger;
bool mHaveHeader;
bool mHaveState;
bool mHaveTransactions;
bool mSignaled;
bool mByHash;
std::uint32_t mSeq;
Reason const reason_;
Reason const mReason;
std::set<uint256> mRecentNodes;
@@ -174,6 +193,7 @@ private:
std::vector<
std::pair<std::weak_ptr<Peer>, std::shared_ptr<protocol::TMLedgerData>>>
mReceivedData;
bool mReceiveDispatched;
std::unique_ptr<PeerSet> mPeerSet;
};

View File

@@ -42,7 +42,7 @@ public:
InboundTransactions&
operator=(InboundTransactions const&) = delete;
virtual ~InboundTransactions() = default;
virtual ~InboundTransactions() = 0;
/** Find and return a transaction set, or nullptr if it is missing.
*
@@ -59,13 +59,13 @@ public:
*
* @param setHash The transaction set ID (digest of the SHAMap root node).
* @param peer The peer that sent the message.
* @param data The data we received.
* @param message The LedgerData message.
*/
virtual void
gotData(
uint256 const& setHash,
std::shared_ptr<Peer> peer,
std::vector<std::pair<SHAMapNodeID, Slice>> const& data) = 0;
std::shared_ptr<protocol::TMLedgerData> message) = 0;
/** Add a transaction set.
*

View File

@@ -42,13 +42,11 @@
#include <ripple/core/SociDB.h>
#include <ripple/json/to_string.h>
#include <ripple/nodestore/Database.h>
#include <ripple/protocol/Deserializer.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/HashPrefix.h>
#include <ripple/protocol/Indexes.h>
#include <ripple/protocol/PublicKey.h>
#include <ripple/protocol/SecretKey.h>
#include <ripple/protocol/Serializer.h>
#include <ripple/protocol/UintTypes.h>
#include <ripple/protocol/digest.h>
#include <ripple/protocol/jss.h>
@@ -121,7 +119,9 @@ public:
sles_type::value_type
dereference() const override
{
return std::make_shared<SLE const>(iter_->slice(), iter_->key());
auto const item = *iter_;
SerialIter sit(item.slice());
return std::make_shared<SLE const>(sit, item.key());
}
};
@@ -168,7 +168,7 @@ public:
txs_type::value_type
dereference() const override
{
auto const& item = *iter_;
auto const item = *iter_;
if (metadata_)
return deserializeTxPlusMeta(item);
return {deserializeTx(item), nullptr};
@@ -183,10 +183,9 @@ Ledger::Ledger(
std::vector<uint256> const& amendments,
Family& family)
: mImmutable(false)
, txMap_(SHAMapType::TRANSACTION, family)
, stateMap_(SHAMapType::STATE, family)
, txMap_(std::make_shared<SHAMap>(SHAMapType::TRANSACTION, family))
, stateMap_(std::make_shared<SHAMap>(SHAMapType::STATE, family))
, rules_{config.features}
, j_(beast::Journal(beast::Journal::getNullSink()))
{
info_.seq = 1;
info_.drops = INITIAL_XRP;
@@ -210,34 +209,8 @@ Ledger::Ledger(
rawInsert(sle);
}
{
auto sle = std::make_shared<SLE>(keylet::fees());
// Whether featureXRPFees is supported will depend on startup options.
if (std::find(amendments.begin(), amendments.end(), featureXRPFees) !=
amendments.end())
{
sle->at(sfBaseFeeDrops) = config.FEES.reference_fee;
sle->at(sfReserveBaseDrops) = config.FEES.account_reserve;
sle->at(sfReserveIncrementDrops) = config.FEES.owner_reserve;
}
else
{
if (auto const f =
config.FEES.reference_fee.dropsAs<std::uint64_t>())
sle->at(sfBaseFee) = *f;
if (auto const f =
config.FEES.account_reserve.dropsAs<std::uint32_t>())
sle->at(sfReserveBase) = *f;
if (auto const f =
config.FEES.owner_reserve.dropsAs<std::uint32_t>())
sle->at(sfReserveIncrement) = *f;
sle->at(sfReferenceFeeUnits) = Config::FEE_UNITS_DEPRECATED;
}
rawInsert(sle);
}
stateMap_.flushDirty(hotACCOUNT_NODE);
setImmutable();
stateMap_->flushDirty(hotACCOUNT_NODE);
setImmutable(config);
}
Ledger::Ledger(
@@ -248,16 +221,19 @@ Ledger::Ledger(
Family& family,
beast::Journal j)
: mImmutable(true)
, txMap_(SHAMapType::TRANSACTION, info.txHash, family)
, stateMap_(SHAMapType::STATE, info.accountHash, family)
, txMap_(std::make_shared<SHAMap>(
SHAMapType::TRANSACTION,
info.txHash,
family))
, stateMap_(
std::make_shared<SHAMap>(SHAMapType::STATE, info.accountHash, family))
, rules_(config.features)
, info_(info)
, j_(j)
{
loaded = true;
if (info_.txHash.isNonZero() &&
!txMap_.fetchRoot(SHAMapHash{info_.txHash}, nullptr))
!txMap_->fetchRoot(SHAMapHash{info_.txHash}, nullptr))
{
if (config.reporting())
{
@@ -269,7 +245,7 @@ Ledger::Ledger(
}
if (info_.accountHash.isNonZero() &&
!stateMap_.fetchRoot(SHAMapHash{info_.accountHash}, nullptr))
!stateMap_->fetchRoot(SHAMapHash{info_.accountHash}, nullptr))
{
if (config.reporting())
{
@@ -280,29 +256,29 @@ Ledger::Ledger(
JLOG(j.warn()) << "Don't have state data root for ledger" << info_.seq;
}
txMap_.setImmutable();
stateMap_.setImmutable();
txMap_->setImmutable();
stateMap_->setImmutable();
defaultFees(config);
if (!setup())
if (!setup(config))
loaded = false;
if (!loaded)
{
info_.hash = calculateLedgerHash(info_);
if (acquire && !config.reporting())
family.missingNodeAcquireByHash(info_.hash, info_.seq);
family.missingNode(info_.hash, info_.seq);
}
}
// Create a new ledger that follows this one
Ledger::Ledger(Ledger const& prevLedger, NetClock::time_point closeTime)
: mImmutable(false)
, txMap_(SHAMapType::TRANSACTION, prevLedger.txMap_.family())
, stateMap_(prevLedger.stateMap_, true)
, txMap_(std::make_shared<SHAMap>(
SHAMapType::TRANSACTION,
prevLedger.stateMap_->family()))
, stateMap_(prevLedger.stateMap_->snapShot(true))
, fees_(prevLedger.fees_)
, rules_(prevLedger.rules_)
, j_(beast::Journal(beast::Journal::getNullSink()))
{
info_.seq = prevLedger.info_.seq + 1;
info_.parentCloseTime = prevLedger.info_.closeTime;
@@ -328,11 +304,14 @@ Ledger::Ledger(Ledger const& prevLedger, NetClock::time_point closeTime)
Ledger::Ledger(LedgerInfo const& info, Config const& config, Family& family)
: mImmutable(true)
, txMap_(SHAMapType::TRANSACTION, info.txHash, family)
, stateMap_(SHAMapType::STATE, info.accountHash, family)
, txMap_(std::make_shared<SHAMap>(
SHAMapType::TRANSACTION,
info.txHash,
family))
, stateMap_(
std::make_shared<SHAMap>(SHAMapType::STATE, info.accountHash, family))
, rules_{config.features}
, info_(info)
, j_(beast::Journal(beast::Journal::getNullSink()))
{
info_.hash = calculateLedgerHash(info_);
}
@@ -343,43 +322,42 @@ Ledger::Ledger(
Config const& config,
Family& family)
: mImmutable(false)
, txMap_(SHAMapType::TRANSACTION, family)
, stateMap_(SHAMapType::STATE, family)
, txMap_(std::make_shared<SHAMap>(SHAMapType::TRANSACTION, family))
, stateMap_(std::make_shared<SHAMap>(SHAMapType::STATE, family))
, rules_{config.features}
, j_(beast::Journal(beast::Journal::getNullSink()))
{
info_.seq = ledgerSeq;
info_.closeTime = closeTime;
info_.closeTimeResolution = ledgerDefaultTimeResolution;
defaultFees(config);
setup();
setup(config);
}
void
Ledger::setImmutable(bool rehash)
Ledger::setImmutable(Config const& config, bool rehash)
{
// Force update, since this is the only
// place the hash transitions to valid
if (!mImmutable && rehash)
{
info_.txHash = txMap_.getHash().as_uint256();
info_.accountHash = stateMap_.getHash().as_uint256();
info_.txHash = txMap_->getHash().as_uint256();
info_.accountHash = stateMap_->getHash().as_uint256();
}
if (rehash)
info_.hash = calculateLedgerHash(info_);
mImmutable = true;
txMap_.setImmutable();
stateMap_.setImmutable();
setup();
txMap_->setImmutable();
stateMap_->setImmutable();
setup(config);
}
void
Ledger::setAccepted(
NetClock::time_point closeTime,
NetClock::duration closeResolution,
bool correctCloseTime)
bool correctCloseTime,
Config const& config)
{
// Used when we witnessed the consensus.
assert(!open());
@@ -387,16 +365,15 @@ Ledger::setAccepted(
info_.closeTime = closeTime;
info_.closeTimeResolution = closeResolution;
info_.closeFlags = correctCloseTime ? 0 : sLCF_NoConsensusTime;
setImmutable();
setImmutable(config);
}
bool
Ledger::addSLE(SLE const& sle)
{
Serializer s;
sle.add(s);
return stateMap_.addItem(
SHAMapNodeType::tnACCOUNT_STATE, make_shamapitem(sle.key(), s.slice()));
auto const s = sle.getSerializer();
SHAMapItem item(sle.key(), s.slice());
return stateMap_->addItem(SHAMapNodeType::tnACCOUNT_STATE, std::move(item));
}
//------------------------------------------------------------------------------
@@ -404,7 +381,8 @@ Ledger::addSLE(SLE const& sle)
std::shared_ptr<STTx const>
deserializeTx(SHAMapItem const& item)
{
return std::make_shared<STTx const>(item.slice());
SerialIter sit(item.slice());
return std::make_shared<STTx const>(sit);
}
std::pair<std::shared_ptr<STTx const>, std::shared_ptr<STObject const>>
@@ -413,8 +391,14 @@ deserializeTxPlusMeta(SHAMapItem const& item)
std::pair<std::shared_ptr<STTx const>, std::shared_ptr<STObject const>>
result;
SerialIter sit(item.slice());
result.first = std::make_shared<STTx const>(sit.getVL());
result.second = std::make_shared<STObject const>(sit.getVL(), sfMetadata);
{
SerialIter s(sit.getSlice(sit.getVLDataLength()));
result.first = std::make_shared<STTx const>(s);
}
{
SerialIter s(sit.getSlice(sit.getVLDataLength()));
result.second = std::make_shared<STObject const>(s, sfMetadata);
}
return result;
}
@@ -424,20 +408,20 @@ bool
Ledger::exists(Keylet const& k) const
{
// VFALCO NOTE Perhaps check the type for debug builds?
return stateMap_.hasItem(k.key);
return stateMap_->hasItem(k.key);
}
bool
Ledger::exists(uint256 const& key) const
{
return stateMap_.hasItem(key);
return stateMap_->hasItem(key);
}
std::optional<uint256>
Ledger::succ(uint256 const& key, std::optional<uint256> const& last) const
{
auto item = stateMap_.upper_bound(key);
if (item == stateMap_.end())
auto item = stateMap_->upper_bound(key);
if (item == stateMap_->end())
return std::nullopt;
if (last && item->key() >= last)
return std::nullopt;
@@ -452,10 +436,10 @@ Ledger::read(Keylet const& k) const
assert(false);
return nullptr;
}
auto const& item = stateMap_.peekItem(k.key);
auto const& item = stateMap_->peekItem(k.key);
if (!item)
return nullptr;
auto sle = std::make_shared<SLE>(item->slice(), item->key());
auto sle = std::make_shared<SLE>(SerialIter{item->slice()}, item->key());
if (!k.check(*sle))
return nullptr;
return sle;
@@ -466,44 +450,45 @@ Ledger::read(Keylet const& k) const
auto
Ledger::slesBegin() const -> std::unique_ptr<sles_type::iter_base>
{
return std::make_unique<sles_iter_impl>(stateMap_.begin());
return std::make_unique<sles_iter_impl>(stateMap_->begin());
}
auto
Ledger::slesEnd() const -> std::unique_ptr<sles_type::iter_base>
{
return std::make_unique<sles_iter_impl>(stateMap_.end());
return std::make_unique<sles_iter_impl>(stateMap_->end());
}
auto
Ledger::slesUpperBound(uint256 const& key) const
-> std::unique_ptr<sles_type::iter_base>
{
return std::make_unique<sles_iter_impl>(stateMap_.upper_bound(key));
return std::make_unique<sles_iter_impl>(stateMap_->upper_bound(key));
}
auto
Ledger::txsBegin() const -> std::unique_ptr<txs_type::iter_base>
{
return std::make_unique<txs_iter_impl>(!open(), txMap_.begin());
return std::make_unique<txs_iter_impl>(!open(), txMap_->begin());
}
auto
Ledger::txsEnd() const -> std::unique_ptr<txs_type::iter_base>
{
return std::make_unique<txs_iter_impl>(!open(), txMap_.end());
return std::make_unique<txs_iter_impl>(!open(), txMap_->end());
}
bool
Ledger::txExists(uint256 const& key) const
{
return txMap_.hasItem(key);
return txMap_->hasItem(key);
}
auto
Ledger::txRead(key_type const& key) const -> tx_type
{
auto const& item = txMap_.peekItem(key);
assert(txMap_);
auto const& item = txMap_->peekItem(key);
if (!item)
return {};
if (!open())
@@ -520,7 +505,7 @@ Ledger::digest(key_type const& key) const -> std::optional<digest_type>
SHAMapHash digest;
// VFALCO Unfortunately this loads the item
// from the NodeStore needlessly.
if (!stateMap_.peekItem(key, digest))
if (!stateMap_->peekItem(key, digest))
return std::nullopt;
return digest.as_uint256();
}
@@ -530,14 +515,14 @@ Ledger::digest(key_type const& key) const -> std::optional<digest_type>
void
Ledger::rawErase(std::shared_ptr<SLE> const& sle)
{
if (!stateMap_.delItem(sle->key()))
if (!stateMap_->delItem(sle->key()))
LogicError("Ledger::rawErase: key not found");
}
void
Ledger::rawErase(uint256 const& key)
{
if (!stateMap_.delItem(key))
if (!stateMap_->delItem(key))
LogicError("Ledger::rawErase: key not found");
}
@@ -546,9 +531,9 @@ Ledger::rawInsert(std::shared_ptr<SLE> const& sle)
{
Serializer ss;
sle->add(ss);
if (!stateMap_.addGiveItem(
if (!stateMap_->addGiveItem(
SHAMapNodeType::tnACCOUNT_STATE,
make_shamapitem(sle->key(), ss.slice())))
std::make_shared<SHAMapItem const>(sle->key(), ss.slice())))
LogicError("Ledger::rawInsert: key already exists");
}
@@ -557,139 +542,111 @@ Ledger::rawReplace(std::shared_ptr<SLE> const& sle)
{
Serializer ss;
sle->add(ss);
if (!stateMap_.updateGiveItem(
if (!stateMap_->updateGiveItem(
SHAMapNodeType::tnACCOUNT_STATE,
make_shamapitem(sle->key(), ss.slice())))
std::make_shared<SHAMapItem const>(sle->key(), ss.slice())))
LogicError("Ledger::rawReplace: key not found");
}
void
Ledger::rawTxInsert(uint256 const& key, Slice txn, Slice metaData)
Ledger::rawTxInsert(
uint256 const& key,
std::shared_ptr<Serializer const> const& txn,
std::shared_ptr<Serializer const> const& metaData)
{
assert(!metaData.empty());
assert(metaData);
// low-level - just add to table
Serializer s;
s.addVL(txn);
s.addVL(metaData);
if (!txMap_.addGiveItem(
SHAMapNodeType::tnTRANSACTION_MD, make_shamapitem(key, s.slice())))
Serializer s(txn->getDataLength() + metaData->getDataLength() + 16);
s.addVL(txn->peekData());
s.addVL(metaData->peekData());
if (!txMap().addGiveItem(
SHAMapNodeType::tnTRANSACTION_MD,
std::make_shared<SHAMapItem const>(key, s.slice())))
LogicError("duplicate_tx: " + to_string(key));
}
uint256
Ledger::rawTxInsertWithHash(uint256 const& key, Slice txn, Slice metaData)
Ledger::rawTxInsertWithHash(
uint256 const& key,
std::shared_ptr<Serializer const> const& txn,
std::shared_ptr<Serializer const> const& metaData)
{
assert(!metaData.empty());
assert(metaData);
// low-level - just add to table
Serializer s; // FIXME(txn.size() + metaData.size() + 16);
s.addVL(txn);
s.addVL(metaData);
if (!txMap_.addGiveItem(
SHAMapNodeType::tnTRANSACTION_MD, make_shamapitem(key, s.slice())))
Serializer s(txn->getDataLength() + metaData->getDataLength() + 16);
s.addVL(txn->peekData());
s.addVL(metaData->peekData());
auto item = std::make_shared<SHAMapItem const>(key, s.slice());
auto hash = sha512Half(HashPrefix::txNode, item->slice(), item->key());
if (!txMap().addGiveItem(SHAMapNodeType::tnTRANSACTION_MD, std::move(item)))
LogicError("duplicate_tx: " + to_string(key));
return sha512Half(HashPrefix::txNode, s.slice(), key);
return hash;
}
bool
Ledger::setup()
Ledger::setup(Config const& config)
{
bool ret = true;
try
{
rules_ = makeRulesGivenLedger(*this, rules_);
}
catch (SHAMapMissingNode const&)
{
ret = false;
}
catch (std::exception const& ex)
{
JLOG(j_.error()) << "Exception in " << __func__ << ": " << ex.what();
Rethrow();
}
fees_.base = config.FEE_DEFAULT;
fees_.units = config.TRANSACTION_FEE_BASE;
fees_.reserve = config.FEE_ACCOUNT_RESERVE;
fees_.increment = config.FEE_OWNER_RESERVE;
try
{
if (auto const sle = read(keylet::fees()))
{
bool oldFees = false;
bool newFees = false;
{
auto const baseFee = sle->at(~sfBaseFee);
auto const reserveBase = sle->at(~sfReserveBase);
auto const reserveIncrement = sle->at(~sfReserveIncrement);
if (baseFee)
fees_.base = *baseFee;
if (reserveBase)
fees_.reserve = *reserveBase;
if (reserveIncrement)
fees_.increment = *reserveIncrement;
oldFees = baseFee || reserveBase || reserveIncrement;
}
{
auto const baseFeeXRP = sle->at(~sfBaseFeeDrops);
auto const reserveBaseXRP = sle->at(~sfReserveBaseDrops);
auto const reserveIncrementXRP =
sle->at(~sfReserveIncrementDrops);
auto assign = [&ret](
XRPAmount& dest,
std::optional<STAmount> const& src) {
if (src)
{
if (src->native())
dest = src->xrp();
else
ret = false;
}
};
assign(fees_.base, baseFeeXRP);
assign(fees_.reserve, reserveBaseXRP);
assign(fees_.increment, reserveIncrementXRP);
newFees = baseFeeXRP || reserveBaseXRP || reserveIncrementXRP;
}
if (oldFees && newFees)
// Should be all of one or the other, but not both
ret = false;
if (!rules_.enabled(featureXRPFees) && newFees)
// Can't populate the new fees before the amendment is enabled
ret = false;
// VFALCO NOTE Why getFieldIndex and not isFieldPresent?
if (sle->getFieldIndex(sfBaseFee) != -1)
fees_.base = sle->getFieldU64(sfBaseFee);
if (sle->getFieldIndex(sfReferenceFeeUnits) != -1)
fees_.units = sle->getFieldU32(sfReferenceFeeUnits);
if (sle->getFieldIndex(sfReserveBase) != -1)
fees_.reserve = sle->getFieldU32(sfReserveBase);
if (sle->getFieldIndex(sfReserveIncrement) != -1)
fees_.increment = sle->getFieldU32(sfReserveIncrement);
}
}
catch (SHAMapMissingNode const&)
{
ret = false;
}
catch (std::exception const& ex)
catch (std::exception const&)
{
Rethrow();
}
try
{
rules_ = makeRulesGivenLedger(*this, config.features);
}
catch (SHAMapMissingNode const&)
{
ret = false;
}
catch (std::exception const&)
{
JLOG(j_.error()) << "Exception in " << __func__ << ": " << ex.what();
Rethrow();
}
return ret;
}
void
Ledger::defaultFees(Config const& config)
{
assert(fees_.base == 0 && fees_.reserve == 0 && fees_.increment == 0);
if (fees_.base == 0)
fees_.base = config.FEES.reference_fee;
if (fees_.reserve == 0)
fees_.reserve = config.FEES.account_reserve;
if (fees_.increment == 0)
fees_.increment = config.FEES.owner_reserve;
}
std::shared_ptr<SLE>
Ledger::peek(Keylet const& k) const
{
auto const& value = stateMap_.peekItem(k.key);
auto const& value = stateMap_->peekItem(k.key);
if (!value)
return nullptr;
auto sle = std::make_shared<SLE>(value->slice(), value->key());
auto sle = std::make_shared<SLE>(SerialIter{value->slice()}, value->key());
if (!k.check(*sle))
return nullptr;
return sle;
@@ -808,8 +765,8 @@ Ledger::walkLedger(beast::Journal j, bool parallel) const
std::vector<SHAMapMissingNode> missingNodes1;
std::vector<SHAMapMissingNode> missingNodes2;
if (stateMap_.getHash().isZero() && !info_.accountHash.isZero() &&
!stateMap_.fetchRoot(SHAMapHash{info_.accountHash}, nullptr))
if (stateMap_->getHash().isZero() && !info_.accountHash.isZero() &&
!stateMap_->fetchRoot(SHAMapHash{info_.accountHash}, nullptr))
{
missingNodes1.emplace_back(
SHAMapType::STATE, SHAMapHash{info_.accountHash});
@@ -817,9 +774,9 @@ Ledger::walkLedger(beast::Journal j, bool parallel) const
else
{
if (parallel)
return stateMap_.walkMapParallel(missingNodes1, 32);
return stateMap_->walkMapParallel(missingNodes1, 32);
else
stateMap_.walkMap(missingNodes1, 32);
stateMap_->walkMap(missingNodes1, 32);
}
if (!missingNodes1.empty())
@@ -831,15 +788,15 @@ Ledger::walkLedger(beast::Journal j, bool parallel) const
}
}
if (txMap_.getHash().isZero() && info_.txHash.isNonZero() &&
!txMap_.fetchRoot(SHAMapHash{info_.txHash}, nullptr))
if (txMap_->getHash().isZero() && info_.txHash.isNonZero() &&
!txMap_->fetchRoot(SHAMapHash{info_.txHash}, nullptr))
{
missingNodes2.emplace_back(
SHAMapType::TRANSACTION, SHAMapHash{info_.txHash});
}
else
{
txMap_.walkMap(missingNodes2, 32);
txMap_->walkMap(missingNodes2, 32);
}
if (!missingNodes2.empty())
@@ -856,9 +813,9 @@ Ledger::walkLedger(beast::Journal j, bool parallel) const
bool
Ledger::assertSensible(beast::Journal ledgerJ) const
{
if (info_.hash.isNonZero() && info_.accountHash.isNonZero() &&
(info_.accountHash == stateMap_.getHash().as_uint256()) &&
(info_.txHash == txMap_.getHash().as_uint256()))
if (info_.hash.isNonZero() && info_.accountHash.isNonZero() && stateMap_ &&
txMap_ && (info_.accountHash == stateMap_->getHash().as_uint256()) &&
(info_.txHash == txMap_->getHash().as_uint256()))
{
return true;
}
@@ -1020,14 +977,15 @@ pendSaveValidated(
return true;
}
JobType const jobType{isCurrent ? jtPUBLEDGER : jtPUBOLDLEDGER};
char const* const jobName{
isCurrent ? "Ledger::pendSave" : "Ledger::pendOldSave"};
// See if we can use the JobQueue.
if (!isSynchronous &&
app.getJobQueue().addJob(
isCurrent ? jtPUBLEDGER : jtPUBOLDLEDGER,
std::to_string(ledger->seq()),
[&app, ledger, isCurrent]() {
saveValidatedLedger(app, ledger, isCurrent);
}))
app.getJobQueue().addJob(jobType, jobName, [&app, ledger, isCurrent]() {
saveValidatedLedger(app, ledger, isCurrent);
}))
{
return true;
}
@@ -1039,15 +997,15 @@ pendSaveValidated(
void
Ledger::unshare() const
{
stateMap_.unshare();
txMap_.unshare();
stateMap_->unshare();
txMap_->unshare();
}
void
Ledger::invariants() const
{
stateMap_.invariants();
txMap_.invariants();
stateMap_->invariants();
txMap_->invariants();
}
//------------------------------------------------------------------------------
@@ -1086,8 +1044,7 @@ finishLoadByIndexOrHash(
if (!ledger)
return;
assert(ledger->read(keylet::fees()));
ledger->setImmutable();
ledger->setImmutable(config);
JLOG(j.trace()) << "Loaded ledger: " << to_string(ledger->info().hash);

View File

@@ -28,6 +28,7 @@
#include <ripple/protocol/Book.h>
#include <ripple/protocol/Indexes.h>
#include <ripple/protocol/STLedgerEntry.h>
#include <ripple/protocol/Serializer.h>
#include <ripple/protocol/TxMeta.h>
#include <ripple/shamap/SHAMap.h>
#include <mutex>
@@ -82,10 +83,6 @@ public:
Ledger&
operator=(Ledger const&) = delete;
Ledger(Ledger&&) = delete;
Ledger&
operator=(Ledger&&) = delete;
/** Create the Genesis ledger.
The Genesis ledger contains a single account whose
@@ -239,7 +236,10 @@ public:
//
void
rawTxInsert(uint256 const& key, Slice txn, Slice metaData) override;
rawTxInsert(
uint256 const& key,
std::shared_ptr<Serializer const> const& txn,
std::shared_ptr<Serializer const> const& metaData) override;
// Insert the transaction, and return the hash of the SHAMap leaf node
// holding the transaction. The hash can be used to fetch the transaction
@@ -249,7 +249,10 @@ public:
// @param metaData transaction metadata
// @return hash of SHAMap leaf node that holds the transaction
uint256
rawTxInsertWithHash(uint256 const& key, Slice txn, Slice metaData);
rawTxInsertWithHash(
uint256 const& key,
std::shared_ptr<Serializer const> const& txn,
std::shared_ptr<Serializer const> const& metaData);
//--------------------------------------------------------------------------
@@ -263,10 +266,11 @@ public:
setAccepted(
NetClock::time_point closeTime,
NetClock::duration closeResolution,
bool correctCloseTime);
bool correctCloseTime,
Config const& config);
void
setImmutable(bool rehash = true);
setImmutable(Config const& config, bool rehash = true);
bool
isImmutable() const
@@ -287,10 +291,10 @@ public:
void
setFull() const
{
txMap_.setFull();
txMap_.setLedgerSeq(info_.seq);
stateMap_.setFull();
stateMap_.setLedgerSeq(info_.seq);
txMap_->setFull();
stateMap_->setFull();
txMap_->setLedgerSeq(info_.seq);
stateMap_->setLedgerSeq(info_.seq);
}
void
@@ -302,25 +306,25 @@ public:
SHAMap const&
stateMap() const
{
return stateMap_;
return *stateMap_;
}
SHAMap&
stateMap()
{
return stateMap_;
return *stateMap_;
}
SHAMap const&
txMap() const
{
return txMap_;
return *txMap_;
}
SHAMap&
txMap()
{
return txMap_;
return *txMap_;
}
// returns false on error
@@ -391,18 +395,12 @@ private:
class txs_iter_impl;
bool
setup();
void
defaultFees(Config const& config);
setup(Config const& config);
bool mImmutable;
// A SHAMap containing the transactions associated with this ledger.
SHAMap mutable txMap_;
// A SHAMap containing the state objects for this ledger.
SHAMap mutable stateMap_;
std::shared_ptr<SHAMap> txMap_;
std::shared_ptr<SHAMap> stateMap_;
// Protects fee variables
std::mutex mutable mutex_;
@@ -410,7 +408,6 @@ private:
Fees fees_;
Rules rules_;
LedgerInfo info_;
beast::Journal j_;
};
/** A ledger wrapped in a CachedView. */

View File

@@ -34,13 +34,13 @@ LedgerHistory::LedgerHistory(
: app_(app)
, collector_(collector)
, mismatch_counter_(collector->make_counter("ledger.history", "mismatch"))
, ledgerCache_(
, m_ledgers_by_hash(
"LedgerCache",
app_.config().getValueFor(SizedItem::ledgerSize),
std::chrono::seconds{app_.config().getValueFor(SizedItem::ledgerAge)},
stopwatch(),
app_.journal("TaggedCache"))
, consensusValidated_(
, m_consensus_validated(
"ConsensusValidated",
64,
std::chrono::minutes{5},
@@ -51,20 +51,17 @@ LedgerHistory::LedgerHistory(
}
bool
LedgerHistory::insert(
std::shared_ptr<Ledger const> const& ledger,
bool validated)
LedgerHistory::insert(std::shared_ptr<Ledger const> ledger, bool validated)
{
if (!ledger->isImmutable())
LogicError("mutable Ledger in insert");
assert(ledger->stateMap().getHash().isNonZero());
const bool alreadyHad =
ledgerCache_.insert_or_assign(ledger->info().hash, ledger);
std::unique_lock sl(mutex_);
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
const bool alreadyHad = m_ledgers_by_hash.canonicalize_replace_cache(
ledger->info().hash, ledger);
if (validated)
mLedgersByIndex[ledger->info().seq] = ledger->info().hash;
@@ -74,21 +71,23 @@ LedgerHistory::insert(
LedgerHash
LedgerHistory::getLedgerHash(LedgerIndex index)
{
std::unique_lock sl(mutex_);
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
auto it = mLedgersByIndex.find(index);
if (auto it = mLedgersByIndex.find(index); it != mLedgersByIndex.end())
if (it != mLedgersByIndex.end())
return it->second;
return {};
return uint256();
}
std::shared_ptr<Ledger const>
LedgerHistory::getLedgerBySeq(LedgerIndex index)
{
{
std::unique_lock sl(mutex_);
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
auto it = mLedgersByIndex.find(index);
if (auto it = mLedgersByIndex.find(index); it != mLedgersByIndex.end())
if (it != mLedgersByIndex.end())
{
uint256 hash = it->second;
sl.unlock();
@@ -102,19 +101,22 @@ LedgerHistory::getLedgerBySeq(LedgerIndex index)
return ret;
assert(ret->info().seq == index);
assert(ret->isImmutable());
ledgerCache_.retrieve_or_insert(ret->info().hash, ret);
// Add this ledger to the local tracking by index
std::lock_guard sl(mutex_);
mLedgersByIndex[ret->info().seq] = ret->info().hash;
return (ret->info().seq == index) ? ret : nullptr;
{
// Add this ledger to the local tracking by index
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
assert(ret->isImmutable());
m_ledgers_by_hash.canonicalize_replace_client(ret->info().hash, ret);
mLedgersByIndex[ret->info().seq] = ret->info().hash;
return (ret->info().seq == index) ? ret : nullptr;
}
}
std::shared_ptr<Ledger const>
LedgerHistory::getLedgerByHash(LedgerHash const& hash)
{
auto ret = ledgerCache_.fetch(hash);
auto ret = m_ledgers_by_hash.fetch(hash);
if (ret)
{
@@ -130,7 +132,7 @@ LedgerHistory::getLedgerByHash(LedgerHash const& hash)
assert(ret->isImmutable());
assert(ret->info().hash == hash);
ledgerCache_.retrieve_or_insert(ret->info().hash, ret);
m_ledgers_by_hash.canonicalize_replace_client(ret->info().hash, ret);
assert(ret->info().hash == hash);
return ret;
@@ -165,19 +167,19 @@ log_metadata_difference(
uint256 const& tx,
beast::Journal j)
{
auto getMeta = [](ReadView const& ledger, uint256 const& txID) {
std::optional<TxMeta> ret;
if (auto meta = ledger.txRead(txID).second)
ret.emplace(txID, ledger.seq(), *meta);
return ret;
auto getMeta = [](ReadView const& ledger,
uint256 const& txID) -> std::shared_ptr<TxMeta> {
auto meta = ledger.txRead(txID).second;
if (!meta)
return {};
return std::make_shared<TxMeta>(txID, ledger.seq(), *meta);
};
auto validMetaData = getMeta(validLedger, tx);
auto builtMetaData = getMeta(builtLedger, tx);
assert(validMetaData != nullptr || builtMetaData != nullptr);
assert(validMetaData || builtMetaData);
if (validMetaData && builtMetaData)
if (validMetaData != nullptr && builtMetaData != nullptr)
{
auto const& validNodes = validMetaData->getNodes();
auto const& builtNodes = builtMetaData->getNodes();
@@ -278,26 +280,37 @@ log_metadata_difference(
<< validNodes.getJson(JsonOptions::none);
}
}
return;
}
if (validMetaData)
else if (validMetaData != nullptr)
{
JLOG(j.error()) << "MISMATCH on TX " << tx
<< ": Metadata Difference. Valid=\n"
<< ": Metadata Difference (built has none)\n"
<< validMetaData->getJson(JsonOptions::none);
}
if (builtMetaData)
else // builtMetaData != nullptr
{
JLOG(j.error()) << "MISMATCH on TX " << tx
<< ": Metadata Difference. Built=\n"
<< ": Metadata Difference (valid has none)\n"
<< builtMetaData->getJson(JsonOptions::none);
}
}
//------------------------------------------------------------------------------
// Return list of leaves sorted by key
static std::vector<SHAMapItem const*>
leaves(SHAMap const& sm)
{
std::vector<SHAMapItem const*> v;
for (auto const& item : sm)
v.push_back(&item);
std::sort(
v.begin(), v.end(), [](SHAMapItem const* lhs, SHAMapItem const* rhs) {
return lhs->key() < rhs->key();
});
return v;
}
void
LedgerHistory::handleMismatch(
LedgerHash const& built,
@@ -325,10 +338,9 @@ LedgerHistory::handleMismatch(
if (auto stream = j_.debug())
{
stream << "Mismatch on " << builtLedger->info().seq << ":\n"
<< " Built: " << getJson({*builtLedger, {}}) << "\n"
<< " Valid: " << getJson({*validLedger, {}}) << "\n"
<< " Consensus: " << consensus;
stream << "Built: " << getJson({*builtLedger, {}});
stream << "Valid: " << getJson({*validLedger, {}});
stream << "Consensus: " << consensus;
}
// Determine the mismatch reason, distinguishing Byzantine
@@ -360,23 +372,6 @@ LedgerHistory::handleMismatch(
<< to_string(*builtConsensusHash);
}
// Grab the leaves from the specified SHAMap and sort them by key:
auto leaves = [](SHAMap const& sm) {
std::vector<SHAMapItem const*> v;
for (auto const& item : sm)
v.push_back(&item);
std::sort(
v.begin(),
v.end(),
[](SHAMapItem const* lhs, SHAMapItem const* rhs) {
return lhs->key() < rhs->key();
});
return v;
};
// Find differences between built and valid ledgers
auto const builtTx = leaves(builtLedger->txMap());
auto const validTx = leaves(validLedger->txMap());
@@ -434,8 +429,10 @@ LedgerHistory::builtLedger(
LedgerHash hash = ledger->info().hash;
assert(!hash.isZero());
std::unique_lock sl(m_consensus_validated.peekMutex());
auto entry = std::make_shared<cv_entry>();
consensusValidated_.retrieve_or_insert(index, entry);
m_consensus_validated.canonicalize_replace_client(index, entry);
if (entry->validated && !entry->built)
{
@@ -472,65 +469,61 @@ LedgerHistory::validatedLedger(
LedgerHash hash = ledger->info().hash;
assert(!hash.isZero());
std::unique_lock sl(m_consensus_validated.peekMutex());
auto entry = std::make_shared<cv_entry>();
consensusValidated_.retrieve_or_insert(index, entry);
m_consensus_validated.canonicalize_replace_client(index, entry);
if (entry->built && !entry->validated && entry->built.value() != hash)
if (entry->built && !entry->validated)
{
JLOG(j_.error()) << "Mismatch on validated ledger (seq " << index
<< "): built is" << entry->built.value()
<< ", validated is:" << hash;
handleMismatch(
entry->built.value(),
hash,
entry->builtConsensusHash,
consensusHash,
entry->consensus.value());
if (entry->built.value() != hash)
{
JLOG(j_.error())
<< "MISMATCH: seq=" << index
<< " built:" << entry->built.value() << " then:" << hash;
handleMismatch(
entry->built.value(),
hash,
entry->builtConsensusHash,
consensusHash,
entry->consensus.value());
}
else
{
// We built a ledger locally and then validated it
JLOG(j_.debug()) << "MATCH: seq=" << index;
}
}
entry->validated.emplace(hash);
entry->validatedConsensusHash = consensusHash;
}
/** Ensure ledgerCache_ doesn't have the wrong hash for a particular index
/** Ensure m_ledgers_by_hash doesn't have the wrong hash for a particular index
*/
bool
LedgerHistory::fixIndex(LedgerIndex ledgerIndex, LedgerHash const& ledgerHash)
{
std::lock_guard sl(mutex_);
std::unique_lock sl(m_ledgers_by_hash.peekMutex());
auto it = mLedgersByIndex.find(ledgerIndex);
if (auto it = mLedgersByIndex.find(ledgerIndex);
(it != mLedgersByIndex.end()) && (it->second != ledgerHash))
if ((it != mLedgersByIndex.end()) && (it->second != ledgerHash))
{
it->second = ledgerHash;
return false;
}
return true;
}
void
LedgerHistory::clearLedgerCachePrior(LedgerIndex seq)
{
ledgerCache_.erase_if(
[seq](Ledger const& ledger) { return ledger.info().seq < seq; });
}
Json::Value
LedgerHistory::info() const
{
Json::Value ret(Json::objectValue);
ret["lc"] = ledgerCache_.info();
ret["cv"] = consensusValidated_.info();
for (LedgerHash it : m_ledgers_by_hash.getKeys())
{
std::lock_guard sl(mutex_);
ret["lbi"] = std::to_string(mLedgersByIndex.size());
auto const ledger = getLedgerByHash(it);
if (!ledger || ledger->info().seq < seq)
m_ledgers_by_hash.del(it, false);
}
return ret;
}
} // namespace ripple

Some files were not shown because too many files have changed in this diff Show More