Compare commits

..

16 Commits

Author SHA1 Message Date
RichardAH
2ec0683902 Update applyHook.cpp 2024-11-09 14:45:53 +10:00
RichardAH
91cc584e6d Merge branch 'dev' into fix-float 2024-11-09 14:34:27 +10:00
RichardAH
638a2ba34a Update applyHook.cpp
clang
2024-11-09 14:23:43 +10:00
RichardAH
8cf6bfcef9 Update applyHook.cpp 2024-11-09 14:20:23 +10:00
RichardAH
c9d57adc83 Update Feature.h 2024-11-09 14:19:48 +10:00
RichardAH
762d8e74a1 Update Feature.cpp 2024-11-09 14:19:17 +10:00
Denis Angell
8ba37a3138 Add Script for SfCode generation (#358)
Co-authored-by: RichardAH <richard.holland@starstone.co.nz>
Co-authored-by: tequ <git@tequ.dev>
2024-11-09 14:17:49 +10:00
tequ
8cffd3054d add trace message to exception on etxn_fee_base (#387) 2024-11-09 14:00:59 +10:00
Denis Angell
610c0ca40f [fold] add amendment 2024-10-31 11:37:04 +01:00
Denis Angell
6b26045cbc Update settings.json (#342) 2024-10-25 11:56:16 +10:00
Wietse Wind
08f13b7cfe Fix account_tx sluggishness as per https://github.com/XRPLF/rippled/commit/2e9261cb (#308) 2024-10-25 11:13:42 +10:00
RichardAH
4e0b11fa1b Merge branch 'dev' into fix-float 2024-10-25 10:11:41 +10:00
tequ
766f5d7ee1 Update macro.h (#366) 2024-10-25 10:10:43 +10:00
Wietse Wind
287c01ad04 Improve Admin command RPC Post (#384)
* Improve ADMIN HTTP POST RPC notifications: no queue limit, shorter HTTP call TTL
2024-10-25 10:10:14 +10:00
tequ
4239124750 Update amendments for rippled-standalone.cfg (#385) 2024-10-25 09:10:45 +10:00
Denis Angell
b0698053f6 fix rounding error 2024-08-19 15:03:54 +02:00
14 changed files with 200 additions and 343 deletions

View File

@@ -3,7 +3,7 @@
"C_Cpp.clang_format_path": ".clang-format", "C_Cpp.clang_format_path": ".clang-format",
"C_Cpp.clang_format_fallbackStyle": "{ ColumnLimit: 0 }", "C_Cpp.clang_format_fallbackStyle": "{ ColumnLimit: 0 }",
"[cpp]":{ "[cpp]":{
"editor.wordBasedSuggestions": false, "editor.wordBasedSuggestions": "off",
"editor.suggest.insertMode": "replace", "editor.suggest.insertMode": "replace",
"editor.semanticHighlighting.enabled": true, "editor.semanticHighlighting.enabled": true,
"editor.tabSize": 4, "editor.tabSize": 4,

View File

@@ -11,8 +11,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(Boost_NO_BOOST_CMAKE ON) set(Boost_NO_BOOST_CMAKE ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=x86-64-v4")
# make GIT_COMMIT_HASH define available to all sources # make GIT_COMMIT_HASH define available to all sources
find_package(Git) find_package(Git)
if(Git_FOUND) if(Git_FOUND)

View File

@@ -144,4 +144,12 @@ D686F2538F410C9D0D856788E98E3579595DAF7B38D38887F81ECAC934B06040 HooksUpdate1
86E83A7D2ECE3AD5FA87AB2195AE015C950469ABF0B72EAACED318F74886AE90 CryptoConditionsSuite 86E83A7D2ECE3AD5FA87AB2195AE015C950469ABF0B72EAACED318F74886AE90 CryptoConditionsSuite
3C43D9A973AA4443EF3FC38E42DD306160FBFFDAB901CD8BAA15D09F2597EB87 NonFungibleTokensV1 3C43D9A973AA4443EF3FC38E42DD306160FBFFDAB901CD8BAA15D09F2597EB87 NonFungibleTokensV1
0285B7E5E08E1A8E4C15636F0591D87F73CB6A7B6452A932AD72BBC8E5D1CBE3 fixNFTokenDirV1 0285B7E5E08E1A8E4C15636F0591D87F73CB6A7B6452A932AD72BBC8E5D1CBE3 fixNFTokenDirV1
36799EA497B1369B170805C078AEFE6188345F9B3E324C21E9CA3FF574E3C3D6 fixNFTokenNegOffer 36799EA497B1369B170805C078AEFE6188345F9B3E324C21E9CA3FF574E3C3D6 fixNFTokenNegOffer
4C499D17719BB365B69010A436B64FD1A82AAB199FC1CEB06962EBD01059FB09 fixXahauV1
215181D23BF5C173314B5FDB9C872C92DE6CC918483727DE037C0C13E7E6EE9D fixXahauV2
0D8BF22FF7570D58598D1EF19EBB6E142AD46E59A223FD3816262FBB69345BEA Remit
7CA0426E7F411D39BB014E57CD9E08F61DE1750F0D41FCD428D9FB80BB7596B0 ZeroB2M
4B8466415FAB32FFA89D9DCBE166A42340115771DF611A7160F8D7439C87ECD8 fixNSDelete
EDB4EE4C524E16BDD91D9A529332DED08DCAAA51CC6DC897ACFA1A0ED131C5B6 fix240819
8063140E9260799D6716756B891CEC3E7006C4E4F277AB84670663A88F94B9C4 fixPageCap
88693F108C3CD8A967F3F4253A32DEF5E35F9406ACD2A11B88B11D90865763A9 fix240911

29
hook/generate_sfcodes.sh Executable file
View File

@@ -0,0 +1,29 @@
#/bin/bash
RIPPLED_ROOT="../src/ripple"
echo '// For documentation please see: https://xrpl-hooks.readme.io/reference/'
echo '// Generated using generate_sfcodes.sh'
cat $RIPPLED_ROOT/protocol/impl/SField.cpp | grep -E '^CONSTRUCT_' |
sed 's/UINT16/1/g' |
sed 's/UINT32/2/g' |
sed 's/UINT64/3/g' |
sed 's/HASH128/4/g' |
sed 's/HASH256/5/g' |
sed 's/UINT128/4/g' |
sed 's/UINT256/5/g' |
sed 's/AMOUNT/6/g' |
sed 's/VL/7/g' | sed 's/Import7/ImportVL/g' |
sed 's/ACCOUNT/8/g' |
sed 's/OBJECT/14/g' |
sed 's/ARRAY/15/g' |
sed 's/UINT8/16/g' |
sed 's/HASH160/17/g' |
sed 's/UINT160/17/g' |
sed 's/PATHSET/18/g' |
sed 's/VECTOR256/19/g' |
sed 's/UINT96/20/g' |
sed 's/UINT192/21/g' |
sed 's/UINT384/22/g' |
sed 's/UINT512/23/g' |
grep -Eo '"([^"]+)", *([0-9]+), *([0-9]+)' |
sed 's/"//g' | sed 's/ *//g' | sed 's/,/ /g' |
awk '{print ("#define sf"$1" (("$2"U << 16U) + "$3"U)")}'

View File

@@ -1,5 +1,5 @@
/** /**
* These are helper macros for writing hooks, all of them are optional as is including hookmacro.h at all * These are helper macros for writing hooks, all of them are optional as is including macro.h at all
*/ */
#include <stdint.h> #include <stdint.h>

View File

@@ -60,7 +60,10 @@
#define sfBurnedNFTokens ((2U << 16U) + 44U) #define sfBurnedNFTokens ((2U << 16U) + 44U)
#define sfHookStateCount ((2U << 16U) + 45U) #define sfHookStateCount ((2U << 16U) + 45U)
#define sfEmitGeneration ((2U << 16U) + 46U) #define sfEmitGeneration ((2U << 16U) + 46U)
#define sfLockCount ((2U << 16U) + 47U) #define sfLockCount ((2U << 16U) + 49U)
#define sfFirstNFTokenSequence ((2U << 16U) + 50U)
#define sfXahauActivationLgrSeq ((2U << 16U) + 96U)
#define sfImportSequence ((2U << 16U) + 97U)
#define sfRewardTime ((2U << 16U) + 98U) #define sfRewardTime ((2U << 16U) + 98U)
#define sfRewardLgrFirst ((2U << 16U) + 99U) #define sfRewardLgrFirst ((2U << 16U) + 99U)
#define sfRewardLgrLast ((2U << 16U) + 100U) #define sfRewardLgrLast ((2U << 16U) + 100U)
@@ -80,6 +83,8 @@
#define sfHookInstructionCount ((3U << 16U) + 17U) #define sfHookInstructionCount ((3U << 16U) + 17U)
#define sfHookReturnCode ((3U << 16U) + 18U) #define sfHookReturnCode ((3U << 16U) + 18U)
#define sfReferenceCount ((3U << 16U) + 19U) #define sfReferenceCount ((3U << 16U) + 19U)
#define sfAccountIndex ((3U << 16U) + 98U)
#define sfAccountCount ((3U << 16U) + 99U)
#define sfRewardAccumulator ((3U << 16U) + 100U) #define sfRewardAccumulator ((3U << 16U) + 100U)
#define sfEmailHash ((4U << 16U) + 1U) #define sfEmailHash ((4U << 16U) + 1U)
#define sfTakerPaysCurrency ((10U << 16U) + 1U) #define sfTakerPaysCurrency ((10U << 16U) + 1U)
@@ -120,6 +125,9 @@
#define sfOfferID ((5U << 16U) + 34U) #define sfOfferID ((5U << 16U) + 34U)
#define sfEscrowID ((5U << 16U) + 35U) #define sfEscrowID ((5U << 16U) + 35U)
#define sfURITokenID ((5U << 16U) + 36U) #define sfURITokenID ((5U << 16U) + 36U)
#define sfGovernanceFlags ((5U << 16U) + 99U)
#define sfGovernanceMarks ((5U << 16U) + 98U)
#define sfEmittedTxnID ((5U << 16U) + 97U)
#define sfAmount ((6U << 16U) + 1U) #define sfAmount ((6U << 16U) + 1U)
#define sfBalance ((6U << 16U) + 2U) #define sfBalance ((6U << 16U) + 2U)
#define sfLimitAmount ((6U << 16U) + 3U) #define sfLimitAmount ((6U << 16U) + 3U)
@@ -136,6 +144,9 @@
#define sfNFTokenBrokerFee ((6U << 16U) + 19U) #define sfNFTokenBrokerFee ((6U << 16U) + 19U)
#define sfHookCallbackFee ((6U << 16U) + 20U) #define sfHookCallbackFee ((6U << 16U) + 20U)
#define sfLockedBalance ((6U << 16U) + 21U) #define sfLockedBalance ((6U << 16U) + 21U)
#define sfBaseFeeDrops ((6U << 16U) + 22U)
#define sfReserveBaseDrops ((6U << 16U) + 23U)
#define sfReserveIncrementDrops ((6U << 16U) + 24U)
#define sfPublicKey ((7U << 16U) + 1U) #define sfPublicKey ((7U << 16U) + 1U)
#define sfMessageKey ((7U << 16U) + 2U) #define sfMessageKey ((7U << 16U) + 2U)
#define sfSigningPubKey ((7U << 16U) + 3U) #define sfSigningPubKey ((7U << 16U) + 3U)
@@ -171,11 +182,13 @@
#define sfNFTokenMinter ((8U << 16U) + 9U) #define sfNFTokenMinter ((8U << 16U) + 9U)
#define sfEmitCallback ((8U << 16U) + 10U) #define sfEmitCallback ((8U << 16U) + 10U)
#define sfHookAccount ((8U << 16U) + 16U) #define sfHookAccount ((8U << 16U) + 16U)
#define sfInform ((8U << 16U) + 99U)
#define sfIndexes ((19U << 16U) + 1U) #define sfIndexes ((19U << 16U) + 1U)
#define sfHashes ((19U << 16U) + 2U) #define sfHashes ((19U << 16U) + 2U)
#define sfAmendments ((19U << 16U) + 3U) #define sfAmendments ((19U << 16U) + 3U)
#define sfNFTokenOffers ((19U << 16U) + 4U) #define sfNFTokenOffers ((19U << 16U) + 4U)
#define sfHookNamespaces ((19U << 16U) + 5U) #define sfHookNamespaces ((19U << 16U) + 5U)
#define sfURITokenIDs ((19U << 16U) + 99U)
#define sfPaths ((18U << 16U) + 1U) #define sfPaths ((18U << 16U) + 1U)
#define sfTransactionMetaData ((14U << 16U) + 2U) #define sfTransactionMetaData ((14U << 16U) + 2U)
#define sfCreatedNode ((14U << 16U) + 3U) #define sfCreatedNode ((14U << 16U) + 3U)
@@ -198,6 +211,12 @@
#define sfHookDefinition ((14U << 16U) + 22U) #define sfHookDefinition ((14U << 16U) + 22U)
#define sfHookParameter ((14U << 16U) + 23U) #define sfHookParameter ((14U << 16U) + 23U)
#define sfHookGrant ((14U << 16U) + 24U) #define sfHookGrant ((14U << 16U) + 24U)
#define sfGenesisMint ((14U << 16U) + 96U)
#define sfActiveValidator ((14U << 16U) + 95U)
#define sfImportVLKey ((14U << 16U) + 94U)
#define sfHookEmission ((14U << 16U) + 93U)
#define sfMintURIToken ((14U << 16U) + 92U)
#define sfAmountEntry ((14U << 16U) + 91U)
#define sfSigners ((15U << 16U) + 3U) #define sfSigners ((15U << 16U) + 3U)
#define sfSignerEntries ((15U << 16U) + 4U) #define sfSignerEntries ((15U << 16U) + 4U)
#define sfTemplate ((15U << 16U) + 5U) #define sfTemplate ((15U << 16U) + 5U)
@@ -212,4 +231,8 @@
#define sfHookExecutions ((15U << 16U) + 18U) #define sfHookExecutions ((15U << 16U) + 18U)
#define sfHookParameters ((15U << 16U) + 19U) #define sfHookParameters ((15U << 16U) + 19U)
#define sfHookGrants ((15U << 16U) + 20U) #define sfHookGrants ((15U << 16U) + 20U)
#define sfGenesisMints ((15U << 16U) + 96U)
#define sfActiveValidators ((15U << 16U) + 95U) #define sfActiveValidators ((15U << 16U) + 95U)
#define sfImportVLKeys ((15U << 16U) + 94U)
#define sfHookEmissions ((15U << 16U) + 93U)
#define sfAmounts ((15U << 16U) + 92U)

View File

@@ -4617,6 +4617,8 @@ DEFINE_HOOK_FUNCTION(
} }
catch (std::exception& e) catch (std::exception& e)
{ {
JLOG(j.trace()) << "HookInfo[" << HC_ACC()
<< "]: etxn_fee_base exception: " << e.what();
return INVALID_TXN; return INVALID_TXN;
} }
@@ -5402,7 +5404,7 @@ DEFINE_HOOK_FUNCTION(
const int64_t float_one_internal = make_float(1000000000000000ull, -15, false); const int64_t float_one_internal = make_float(1000000000000000ull, -15, false);
inline int64_t inline int64_t
float_divide_internal(int64_t float1, int64_t float2) float_divide_internal(int64_t float1, int64_t float2, bool hasFix)
{ {
RETURN_IF_INVALID_FLOAT(float1); RETURN_IF_INVALID_FLOAT(float1);
RETURN_IF_INVALID_FLOAT(float2); RETURN_IF_INVALID_FLOAT(float2);
@@ -5455,8 +5457,16 @@ float_divide_internal(int64_t float1, int64_t float2)
while (man2 > 0) while (man2 > 0)
{ {
int i = 0; int i = 0;
for (; man1 > man2; man1 -= man2, ++i) if (hasFix)
; {
for (; man1 >= man2; man1 -= man2, ++i)
;
}
else
{
for (; man1 > man2; man1 -= man2, ++i)
;
}
man3 *= 10; man3 *= 10;
man3 += i; man3 += i;
@@ -5476,7 +5486,8 @@ DEFINE_HOOK_FUNCTION(int64_t, float_divide, int64_t float1, int64_t float2)
HOOK_SETUP(); // populates memory_ctx, memory, memory_length, applyCtx, HOOK_SETUP(); // populates memory_ctx, memory, memory_length, applyCtx,
// hookCtx on current stack // hookCtx on current stack
return float_divide_internal(float1, float2); bool const hasFix = view.rules().enabled(fixFloatDivide);
return float_divide_internal(float1, float2, hasFix);
HOOK_TEARDOWN(); HOOK_TEARDOWN();
} }
@@ -5495,7 +5506,9 @@ DEFINE_HOOK_FUNCTION(int64_t, float_invert, int64_t float1)
return DIVISION_BY_ZERO; return DIVISION_BY_ZERO;
if (float1 == float_one_internal) if (float1 == float_one_internal)
return float_one_internal; return float_one_internal;
return float_divide_internal(float_one_internal, float1);
bool const fixV3 = view.rules().enabled(fixFloatDivide);
return float_divide_internal(float_one_internal, float1, fixV3);
HOOK_TEARDOWN(); HOOK_TEARDOWN();
} }

View File

@@ -1132,7 +1132,7 @@ accountTxPage(
{ {
sql = boost::str( sql = boost::str(
boost::format( boost::format(
prefix + (R"(AccountTransactions.LedgerSeq BETWEEN '%u' AND '%u' prefix + (R"(AccountTransactions.LedgerSeq BETWEEN %u AND %u
ORDER BY AccountTransactions.LedgerSeq %s, ORDER BY AccountTransactions.LedgerSeq %s,
AccountTransactions.TxnSeq %s AccountTransactions.TxnSeq %s
LIMIT %u;)")) % LIMIT %u;)")) %
@@ -1155,12 +1155,14 @@ accountTxPage(
FROM AccountTransactions, Transactions WHERE FROM AccountTransactions, Transactions WHERE
(AccountTransactions.TransID = Transactions.TransID AND (AccountTransactions.TransID = Transactions.TransID AND
AccountTransactions.Account = '%s' AND AccountTransactions.Account = '%s' AND
AccountTransactions.LedgerSeq BETWEEN '%u' AND '%u') AccountTransactions.LedgerSeq BETWEEN %u AND %u)
OR UNION
SELECT AccountTransactions.LedgerSeq,AccountTransactions.TxnSeq,Status,RawTxn,TxnMeta
FROM AccountTransactions, Transactions WHERE
(AccountTransactions.TransID = Transactions.TransID AND (AccountTransactions.TransID = Transactions.TransID AND
AccountTransactions.Account = '%s' AND AccountTransactions.Account = '%s' AND
AccountTransactions.LedgerSeq = '%u' AND AccountTransactions.LedgerSeq = %u AND
AccountTransactions.TxnSeq %s '%u') AccountTransactions.TxnSeq %s %u)
ORDER BY AccountTransactions.LedgerSeq %s, ORDER BY AccountTransactions.LedgerSeq %s,
AccountTransactions.TxnSeq %s AccountTransactions.TxnSeq %s
LIMIT %u; LIMIT %u;

View File

@@ -1,8 +1,28 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2014 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_BASICS_HARDENED_HASH_H_INCLUDED #ifndef RIPPLE_BASICS_HARDENED_HASH_H_INCLUDED
#define RIPPLE_BASICS_HARDENED_HASH_H_INCLUDED #define RIPPLE_BASICS_HARDENED_HASH_H_INCLUDED
#include <ripple/beast/hash/hash_append.h> #include <ripple/beast/hash/hash_append.h>
#include <ripple/beast/hash/xxhasher.h> #include <ripple/beast/hash/xxhasher.h>
#include <cstdint> #include <cstdint>
#include <functional> #include <functional>
#include <mutex> #include <mutex>
@@ -12,68 +32,10 @@
#include <unordered_set> #include <unordered_set>
#include <utility> #include <utility>
#if defined(__x86_64__) || defined(_M_X64)
#include <cpuid.h>
#include <immintrin.h>
#endif
namespace ripple { namespace ripple {
namespace detail { namespace detail {
#if defined(__x86_64__) || defined(_M_X64)
inline bool
check_aesni_support()
{
unsigned int eax, ebx, ecx, edx;
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx))
{
return (ecx & bit_AES) != 0;
}
return false;
}
// Helper function to contain all AES-NI operations
#if defined(__GNUC__) || defined(__clang__)
__attribute__((__target__("aes")))
#endif
inline __m128i
aesni_hash_block(__m128i state, __m128i key, const void* data, size_t len)
{
const uint8_t* ptr = static_cast<const uint8_t*>(data);
while (len >= 16)
{
__m128i block = _mm_loadu_si128(reinterpret_cast<const __m128i*>(ptr));
state = _mm_xor_si128(state, block);
state = _mm_aesenc_si128(state, key);
ptr += 16;
len -= 16;
}
if (len > 0)
{
alignas(16) uint8_t last_block[16] = {0};
std::memcpy(last_block, ptr, len);
__m128i block =
_mm_load_si128(reinterpret_cast<const __m128i*>(last_block));
state = _mm_xor_si128(state, block);
state = _mm_aesenc_si128(state, key);
}
return state;
}
// Helper function for final AES round
#if defined(__GNUC__) || defined(__clang__)
__attribute__((__target__("aes")))
#endif
inline __m128i
aesni_hash_final(__m128i state, __m128i key)
{
return _mm_aesenclast_si128(state, key);
}
#endif
using seed_pair = std::pair<std::uint64_t, std::uint64_t>; using seed_pair = std::pair<std::uint64_t, std::uint64_t>;
template <bool = true> template <bool = true>
@@ -86,9 +48,12 @@ make_seed_pair() noexcept
std::random_device rng; std::random_device rng;
std::mt19937_64 gen; std::mt19937_64 gen;
std::uniform_int_distribution<std::uint64_t> dist; std::uniform_int_distribution<std::uint64_t> dist;
state_t() : gen(rng()) state_t() : gen(rng())
{ {
} }
// state_t(state_t const&) = delete;
// state_t& operator=(state_t const&) = delete;
}; };
static state_t state; static state_t state;
std::lock_guard lock(state.mutex); std::lock_guard lock(state.mutex);
@@ -97,23 +62,46 @@ make_seed_pair() noexcept
} // namespace detail } // namespace detail
/**
* Seed functor once per construction
A std compatible hash adapter that resists adversarial inputs.
For this to work, T must implement in its own namespace:
@code
template <class Hasher>
void
hash_append (Hasher& h, T const& t) noexcept
{
// hash_append each base and member that should
// participate in forming the hash
using beast::hash_append;
hash_append (h, static_cast<T::base1 const&>(t));
hash_append (h, static_cast<T::base2 const&>(t));
// ...
hash_append (h, t.member1);
hash_append (h, t.member2);
// ...
}
@endcode
Do not use any version of Murmur or CityHash for the Hasher
template parameter (the hashing algorithm). For details
see https://131002.net/siphash/#at
*/
template <class HashAlgorithm = beast::xxhasher> template <class HashAlgorithm = beast::xxhasher>
class hardened_hash class hardened_hash
{ {
private: private:
detail::seed_pair m_seeds; detail::seed_pair m_seeds;
#if defined(__x86_64__) || defined(_M_X64)
bool using_aesni_;
#endif
public: public:
using result_type = typename HashAlgorithm::result_type; using result_type = typename HashAlgorithm::result_type;
hardened_hash() hardened_hash() : m_seeds(detail::make_seed_pair<>())
: m_seeds(detail::make_seed_pair<>())
#if defined(__x86_64__) || defined(_M_X64)
, using_aesni_(detail::check_aesni_support())
#endif
{ {
} }
@@ -121,24 +109,7 @@ public:
result_type result_type
operator()(T const& t) const noexcept operator()(T const& t) const noexcept
{ {
#if defined(__x86_64__) || defined(_M_X64)
if (using_aesni_)
{
alignas(16) __m128i key =
_mm_set_epi64x(m_seeds.first, m_seeds.second);
alignas(16) __m128i state = _mm_setzero_si128();
// Hash the data using AES-NI
const char* data = reinterpret_cast<const char*>(&t);
state = detail::aesni_hash_block(state, key, data, sizeof(t));
state = detail::aesni_hash_final(state, key);
return static_cast<result_type>(_mm_cvtsi128_si64(state));
}
#endif
// Original implementation using xxhasher
HashAlgorithm h(m_seeds.first, m_seeds.second); HashAlgorithm h(m_seeds.first, m_seeds.second);
using beast::hash_append;
hash_append(h, t); hash_append(h, t);
return static_cast<result_type>(h); return static_cast<result_type>(h);
} }

View File

@@ -1894,7 +1894,9 @@ fromNetwork(
constexpr auto RPC_REPLY_MAX_BYTES = megabytes(256); constexpr auto RPC_REPLY_MAX_BYTES = megabytes(256);
using namespace std::chrono_literals; using namespace std::chrono_literals;
auto constexpr RPC_NOTIFY = 10min; // auto constexpr RPC_NOTIFY = 10min; // Wietse: lolwut 10 minutes for one
// HTTP call?
auto constexpr RPC_NOTIFY = 30s;
HTTPClient::request( HTTPClient::request(
bSSL, bSSL,

View File

@@ -78,12 +78,14 @@ public:
{ {
std::lock_guard sl(mLock); std::lock_guard sl(mLock);
if (mDeque.size() >= eventQueueMax) // Wietse: we're not going to limit this, this is admin-port only, scale
{ // accordingly Dropping events just like this results in inconsistent
// Drop the previous event. // data on the receiving end if (mDeque.size() >= eventQueueMax)
JLOG(j_.warn()) << "RPCCall::fromNetwork drop"; // {
mDeque.pop_back(); // // Drop the previous event.
} // JLOG(j_.warn()) << "RPCCall::fromNetwork drop";
// mDeque.pop_back();
// }
auto jm = broadcast ? j_.debug() : j_.info(); auto jm = broadcast ? j_.debug() : j_.info();
JLOG(jm) << "RPCCall::fromNetwork push: " << jvObj; JLOG(jm) << "RPCCall::fromNetwork push: " << jvObj;
@@ -182,7 +184,8 @@ private:
} }
private: private:
enum { eventQueueMax = 32 }; // Wietse: we're not going to limit this, this is admin-port only, scale
// accordingly enum { eventQueueMax = 32 };
boost::asio::io_service& m_io_service; boost::asio::io_service& m_io_service;
JobQueue& m_jobQueue; JobQueue& m_jobQueue;

View File

@@ -74,7 +74,7 @@ namespace detail {
// Feature.cpp. Because it's only used to reserve storage, and determine how // Feature.cpp. Because it's only used to reserve storage, and determine how
// large to make the FeatureBitset, it MAY be larger. It MUST NOT be less than // large to make the FeatureBitset, it MAY be larger. It MUST NOT be less than
// the actual number of amendments. A LogicError on startup will verify this. // the actual number of amendments. A LogicError on startup will verify this.
static constexpr std::size_t numFeatures = 73; static constexpr std::size_t numFeatures = 74;
/** Amendments that this server supports and the default voting behavior. /** Amendments that this server supports and the default voting behavior.
Whether they are enabled depends on the Rules defined in the validated Whether they are enabled depends on the Rules defined in the validated
@@ -361,6 +361,7 @@ extern uint256 const fixNSDelete;
extern uint256 const fix240819; extern uint256 const fix240819;
extern uint256 const fixPageCap; extern uint256 const fixPageCap;
extern uint256 const fix240911; extern uint256 const fix240911;
extern uint256 const fixFloatDivide;
} // namespace ripple } // namespace ripple

View File

@@ -467,6 +467,7 @@ REGISTER_FIX (fixNSDelete, Supported::yes, VoteBehavior::De
REGISTER_FIX (fix240819, Supported::yes, VoteBehavior::DefaultYes); REGISTER_FIX (fix240819, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FIX (fixPageCap, Supported::yes, VoteBehavior::DefaultYes); REGISTER_FIX (fixPageCap, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FIX (fix240911, Supported::yes, VoteBehavior::DefaultYes); REGISTER_FIX (fix240911, Supported::yes, VoteBehavior::DefaultYes);
REGISTER_FIX (fixFloatDivide, Supported::yes, VoteBehavior::DefaultYes);
// The following amendments are obsolete, but must remain supported // The following amendments are obsolete, but must remain supported
// because they could potentially get enabled. // because they could potentially get enabled.

View File

@@ -18,168 +18,19 @@
//============================================================================== //==============================================================================
#include <ripple/protocol/digest.h> #include <ripple/protocol/digest.h>
#include <immintrin.h>
#include <openssl/ripemd.h> #include <openssl/ripemd.h>
#include <openssl/sha.h> #include <openssl/sha.h>
#include <type_traits>
namespace ripple { namespace ripple {
namespace detail {
#if defined(__x86_64__)
#if defined(__clang__)
#pragma clang attribute push( \
__attribute__((target("xsave,avx512f,avx512bw"))), apply_to = function)
#elif defined(__GNUC__)
#pragma GCC push_options
#pragma GCC target("xsave,avx512f,avx512bw")
#endif
static bool
check_avx512()
{
unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0;
if (__get_cpuid(1, &eax, &ebx, &ecx, &edx))
{
if ((ecx & bit_AVX) && (ecx & bit_OSXSAVE))
{
unsigned long long xcr0 = _xgetbv(0);
if ((xcr0 & 6) == 6)
{
if (__get_cpuid_count(7, 0, &eax, &ebx, &ecx, &edx))
return (ebx & bit_AVX512F) && (ebx & bit_AVX512BW);
}
}
}
return false;
}
#if defined(__clang__)
#pragma clang attribute pop
#elif defined(__GNUC__)
#pragma GCC pop_options
#endif
#endif
static bool
has_avx512()
{
static const bool support = [] {
#if defined(__x86_64__)
return check_avx512();
#else
return false;
#endif
}();
return support;
}
#if defined(__x86_64__)
#if defined(__clang__)
#pragma clang attribute push( \
__attribute__((target("avx512f,avx512bw"))), apply_to = function)
#elif defined(__GNUC__)
#pragma GCC push_options
#pragma GCC target("avx512f,avx512bw")
#endif
static void
process_sha256_blocks_avx512(
SHA256_CTX* ctx,
const uint8_t* data,
size_t blocks)
{
for (size_t i = 0; i < blocks; ++i)
{
__m512i block = _mm512_loadu_si512(
reinterpret_cast<const __m512i*>(data + (i * 64)));
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
const __m512i swap = _mm512_setr_epi64(
0x0001020304050607,
0x08090a0b0c0d0e0f,
0x1011121314151617,
0x18191a1b1c1d1e1f,
0x2021222324252627,
0x28292a2b2c2d2e2f,
0x3031323334353637,
0x38393a3b3c3d3e3f);
block = _mm512_shuffle_epi8(block, swap);
#endif
SHA256_Update(ctx, data + (i * 64), 64);
}
}
static void
process_sha512_blocks_avx512(
SHA512_CTX* ctx,
const uint8_t* data,
size_t blocks)
{
for (size_t i = 0; i < blocks; ++i)
{
__m512i block = _mm512_loadu_si512(
reinterpret_cast<const __m512i*>(data + (i * 64)));
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
const __m512i swap = _mm512_setr_epi64(
0x0001020304050607,
0x08090a0b0c0d0e0f,
0x1011121314151617,
0x18191a1b1c1d1e1f,
0x2021222324252627,
0x28292a2b2c2d2e2f,
0x3031323334353637,
0x38393a3b3c3d3e3f);
block = _mm512_shuffle_epi8(block, swap);
#endif
SHA512_Update(ctx, data + (i * 64), 64);
}
}
static void
process_ripemd160_blocks_avx512(
RIPEMD160_CTX* ctx,
const uint8_t* data,
size_t blocks)
{
for (size_t i = 0; i < blocks; ++i)
{
__m512i block = _mm512_loadu_si512(
reinterpret_cast<const __m512i*>(data + (i * 64)));
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
const __m512i swap = _mm512_setr_epi64(
0x0001020304050607,
0x08090a0b0c0d0e0f,
0x1011121314151617,
0x18191a1b1c1d1e1f,
0x2021222324252627,
0x28292a2b2c2d2e2f,
0x3031323334353637,
0x38393a3b3c3d3e3f);
block = _mm512_shuffle_epi8(block, swap);
#endif
RIPEMD160_Update(ctx, data + (i * 64), 64);
}
}
#if defined(__clang__)
#pragma clang attribute pop
#elif defined(__GNUC__)
#pragma GCC pop_options
#endif
#endif
} // namespace detail
// RIPEMD160 implementation
openssl_ripemd160_hasher::openssl_ripemd160_hasher() openssl_ripemd160_hasher::openssl_ripemd160_hasher()
{ {
static_assert(sizeof(ctx_) >= sizeof(RIPEMD160_CTX), ""); static_assert(
auto ctx = reinterpret_cast<RIPEMD160_CTX*>(ctx_); sizeof(decltype(openssl_ripemd160_hasher::ctx_)) ==
sizeof(RIPEMD160_CTX),
"");
auto const ctx = reinterpret_cast<RIPEMD160_CTX*>(ctx_);
RIPEMD160_Init(ctx); RIPEMD160_Init(ctx);
} }
@@ -188,113 +39,68 @@ openssl_ripemd160_hasher::operator()(
void const* data, void const* data,
std::size_t size) noexcept std::size_t size) noexcept
{ {
auto ctx = reinterpret_cast<RIPEMD160_CTX*>(ctx_); auto const ctx = reinterpret_cast<RIPEMD160_CTX*>(ctx_);
#if defined(__x86_64__)
if (detail::has_avx512() && size >= 64)
{
size_t blocks = size / 64;
detail::process_ripemd160_blocks_avx512(
ctx, static_cast<const uint8_t*>(data), blocks);
size_t remaining = size % 64;
if (remaining)
RIPEMD160_Update(
ctx,
static_cast<const uint8_t*>(data) + (blocks * 64),
remaining);
return;
}
#endif
RIPEMD160_Update(ctx, data, size); RIPEMD160_Update(ctx, data, size);
} }
openssl_ripemd160_hasher::operator result_type() noexcept openssl_ripemd160_hasher::operator result_type() noexcept
{ {
auto ctx = reinterpret_cast<RIPEMD160_CTX*>(ctx_); auto const ctx = reinterpret_cast<RIPEMD160_CTX*>(ctx_);
result_type digest; result_type digest;
RIPEMD160_Final(digest.data(), ctx); RIPEMD160_Final(digest.data(), ctx);
return digest; return digest;
} }
// SHA256 implementation //------------------------------------------------------------------------------
openssl_sha256_hasher::openssl_sha256_hasher()
{
static_assert(sizeof(ctx_) >= sizeof(SHA256_CTX), "");
auto ctx = reinterpret_cast<SHA256_CTX*>(ctx_);
SHA256_Init(ctx);
}
void
openssl_sha256_hasher::operator()(void const* data, std::size_t size) noexcept
{
auto ctx = reinterpret_cast<SHA256_CTX*>(ctx_);
#if defined(__x86_64__)
if (detail::has_avx512() && size >= 64)
{
size_t blocks = size / 64;
detail::process_sha256_blocks_avx512(
ctx, static_cast<const uint8_t*>(data), blocks);
size_t remaining = size % 64;
if (remaining)
SHA256_Update(
ctx,
static_cast<const uint8_t*>(data) + (blocks * 64),
remaining);
return;
}
#endif
SHA256_Update(ctx, data, size);
}
openssl_sha256_hasher::operator result_type() noexcept
{
auto ctx = reinterpret_cast<SHA256_CTX*>(ctx_);
result_type digest;
SHA256_Final(digest.data(), ctx);
return digest;
}
// SHA512 implementation
openssl_sha512_hasher::openssl_sha512_hasher() openssl_sha512_hasher::openssl_sha512_hasher()
{ {
static_assert(sizeof(ctx_) >= sizeof(SHA512_CTX), ""); static_assert(
auto ctx = reinterpret_cast<SHA512_CTX*>(ctx_); sizeof(decltype(openssl_sha512_hasher::ctx_)) == sizeof(SHA512_CTX),
"");
auto const ctx = reinterpret_cast<SHA512_CTX*>(ctx_);
SHA512_Init(ctx); SHA512_Init(ctx);
} }
void void
openssl_sha512_hasher::operator()(void const* data, std::size_t size) noexcept openssl_sha512_hasher::operator()(void const* data, std::size_t size) noexcept
{ {
auto ctx = reinterpret_cast<SHA512_CTX*>(ctx_); auto const ctx = reinterpret_cast<SHA512_CTX*>(ctx_);
#if defined(__x86_64__)
if (detail::has_avx512() && size >= 64)
{
size_t blocks = size / 64;
detail::process_sha512_blocks_avx512(
ctx, static_cast<const uint8_t*>(data), blocks);
size_t remaining = size % 64;
if (remaining)
SHA512_Update(
ctx,
static_cast<const uint8_t*>(data) + (blocks * 64),
remaining);
return;
}
#endif
SHA512_Update(ctx, data, size); SHA512_Update(ctx, data, size);
} }
openssl_sha512_hasher::operator result_type() noexcept openssl_sha512_hasher::operator result_type() noexcept
{ {
auto ctx = reinterpret_cast<SHA512_CTX*>(ctx_); auto const ctx = reinterpret_cast<SHA512_CTX*>(ctx_);
result_type digest; result_type digest;
SHA512_Final(digest.data(), ctx); SHA512_Final(digest.data(), ctx);
return digest; return digest;
} }
//------------------------------------------------------------------------------
openssl_sha256_hasher::openssl_sha256_hasher()
{
static_assert(
sizeof(decltype(openssl_sha256_hasher::ctx_)) == sizeof(SHA256_CTX),
"");
auto const ctx = reinterpret_cast<SHA256_CTX*>(ctx_);
SHA256_Init(ctx);
}
void
openssl_sha256_hasher::operator()(void const* data, std::size_t size) noexcept
{
auto const ctx = reinterpret_cast<SHA256_CTX*>(ctx_);
SHA256_Update(ctx, data, size);
}
openssl_sha256_hasher::operator result_type() noexcept
{
auto const ctx = reinterpret_cast<SHA256_CTX*>(ctx_);
result_type digest;
SHA256_Final(digest.data(), ctx);
return digest;
}
} // namespace ripple } // namespace ripple