From 29592347c0cec35438b1afb420514098d6345f8c Mon Sep 17 00:00:00 2001 From: John Freeman Date: Tue, 18 Jul 2023 12:09:51 -0500 Subject: [PATCH] Fix the package recipe for consumers of libxrpl (#4631) - "Rename" the type `LedgerInfo` to `LedgerHeader` (but leave an alias for `LedgerInfo` to not yet disturb existing uses). Put it in its own public header, named after itself, so that it is more easily found. - Move the type `Fees` and NFT serialization functions into public (installed) headers. - Compile the XRPL and gRPC protocol buffers directly into `libxrpl` and install their headers. Fix the Conan recipe to correctly export these types. Addresses change (2) in https://github.com/XRPLF/XRPL-Standards/discussions/121. For context: This work supports Clio's dependence on libxrpl. Clio is just an example consumer. These changes should benefit all current and future consumers. --------- Co-authored-by: cyan317 <120398799+cindyyan317@users.noreply.github.com> Signed-off-by: Manoj Doshi --- Builds/CMake/RippledCore.cmake | 24 +++- Builds/CMake/RippledMultiConfig.cmake | 2 +- Builds/CMake/conan/Protobuf.cmake | 23 ++-- Builds/CMake/conan/gRPC.cmake | 38 ++++-- Builds/CMake/deps/Protobuf.cmake | 39 +++--- Builds/CMake/deps/gRPC.cmake | 61 ++++++--- CMakeLists.txt | 17 ++- conanfile.py | 5 +- src/ripple/app/ledger/InboundLedger.h | 8 -- src/ripple/app/ledger/LedgerToJson.h | 17 +-- src/ripple/app/ledger/impl/InboundLedger.cpp | 35 +---- .../ledger/impl/LedgerReplayMsgHandler.cpp | 1 + src/ripple/app/reporting/ETLSource.h | 2 +- src/ripple/app/reporting/P2pProxy.h | 3 +- src/ripple/app/tx/impl/details/NFTokenUtils.h | 90 +------------ src/ripple/ledger/ReadView.h | 87 +----------- src/ripple/ledger/impl/View.cpp | 17 --- .../nodestore/impl/DatabaseShardImp.cpp | 1 + src/ripple/nodestore/impl/Shard.cpp | 1 + src/ripple/overlay/Slot.h | 2 +- src/ripple/overlay/impl/ProtocolMessage.h | 1 - src/ripple/protocol/Fees.h | 57 ++++++++ src/ripple/protocol/LedgerHeader.h | 103 ++++++++++++++ .../NFTSyntheticSerializer.h | 23 +--- src/ripple/{rpc => protocol}/NFTokenID.h | 22 ++- src/ripple/{rpc => protocol}/NFTokenOfferID.h | 21 +-- src/ripple/protocol/Serializer.h | 1 + src/ripple/protocol/impl/LedgerHeader.cpp | 71 ++++++++++ .../impl/NFTSyntheticSerializer.cpp | 21 +-- .../{rpc => protocol}/impl/NFTokenID.cpp | 16 +-- .../{rpc => protocol}/impl/NFTokenOfferID.cpp | 16 +-- src/ripple/protocol/messages.h | 2 +- src/ripple/protocol/nft.h | 127 ++++++++++++++++++ src/ripple/protocol/serialize.h | 48 +++++++ src/ripple/rpc/GRPCHandlers.h | 2 +- src/ripple/rpc/handlers/AccountTx.cpp | 4 +- src/ripple/rpc/handlers/Tx.cpp | 4 +- src/ripple/rpc/impl/RPCHelpers.h | 2 +- src/test/overlay/compression_test.cpp | 2 +- src/test/overlay/reduce_relay_test.cpp | 4 +- 40 files changed, 599 insertions(+), 421 deletions(-) create mode 100644 src/ripple/protocol/Fees.h create mode 100644 src/ripple/protocol/LedgerHeader.h rename src/ripple/{rpc => protocol}/NFTSyntheticSerializer.h (79%) rename src/ripple/{rpc => protocol}/NFTokenID.h (86%) rename src/ripple/{rpc => protocol}/NFTokenOfferID.h (86%) create mode 100644 src/ripple/protocol/impl/LedgerHeader.cpp rename src/ripple/{rpc => protocol}/impl/NFTSyntheticSerializer.cpp (70%) rename src/ripple/{rpc => protocol}/impl/NFTokenID.cpp (94%) rename src/ripple/{rpc => protocol}/impl/NFTokenOfferID.cpp (83%) create mode 100644 src/ripple/protocol/nft.h create mode 100644 src/ripple/protocol/serialize.h diff --git a/Builds/CMake/RippledCore.cmake b/Builds/CMake/RippledCore.cmake index 450a4b2e0..24123418a 100644 --- a/Builds/CMake/RippledCore.cmake +++ b/Builds/CMake/RippledCore.cmake @@ -95,6 +95,7 @@ target_sources (xrpl_core PRIVATE src/ripple/protocol/impl/STIssue.cpp src/ripple/protocol/impl/Keylet.cpp src/ripple/protocol/impl/LedgerFormats.cpp + src/ripple/protocol/impl/LedgerHeader.cpp src/ripple/protocol/impl/PublicKey.cpp src/ripple/protocol/impl/Quality.cpp src/ripple/protocol/impl/QualityFunction.cpp @@ -126,6 +127,9 @@ target_sources (xrpl_core PRIVATE src/ripple/protocol/impl/UintTypes.cpp src/ripple/protocol/impl/digest.cpp src/ripple/protocol/impl/tokens.cpp + src/ripple/protocol/impl/NFTSyntheticSerializer.cpp + src/ripple/protocol/impl/NFTokenID.cpp + src/ripple/protocol/impl/NFTokenOfferID.cpp #[===============================[ main sources: subdir: crypto @@ -243,6 +247,7 @@ install ( src/ripple/protocol/BuildInfo.h src/ripple/protocol/ErrorCodes.h src/ripple/protocol/Feature.h + src/ripple/protocol/Fees.h src/ripple/protocol/HashPrefix.h src/ripple/protocol/Indexes.h src/ripple/protocol/InnerObjectFormats.h @@ -251,6 +256,10 @@ install ( src/ripple/protocol/Keylet.h src/ripple/protocol/KnownFormats.h src/ripple/protocol/LedgerFormats.h + src/ripple/protocol/LedgerHeader.h + src/ripple/protocol/NFTSyntheticSerializer.h + src/ripple/protocol/NFTokenID.h + src/ripple/protocol/NFTokenOfferID.h src/ripple/protocol/Protocol.h src/ripple/protocol/PublicKey.h src/ripple/protocol/Quality.h @@ -288,6 +297,9 @@ install ( src/ripple/protocol/UintTypes.h src/ripple/protocol/digest.h src/ripple/protocol/jss.h + src/ripple/protocol/serialize.h + src/ripple/protocol/nft.h + src/ripple/protocol/nftPageMask.h src/ripple/protocol/tokens.h DESTINATION include/ripple/protocol) install ( @@ -307,6 +319,7 @@ install ( DESTINATION include/ripple/beast/clock) install ( FILES + src/ripple/beast/core/CurrentThreadName.h src/ripple/beast/core/LexicalCast.h src/ripple/beast/core/List.h src/ripple/beast/core/SemanticVersion.h @@ -320,6 +333,14 @@ install ( install ( FILES src/ripple/beast/hash/impl/xxhash.h DESTINATION include/ripple/beast/hash/impl) +install ( + FILES + src/ripple/beast/net/IPAddress.h + src/ripple/beast/net/IPAddressConversion.h + src/ripple/beast/net/IPAddressV4.h + src/ripple/beast/net/IPAddressV6.h + src/ripple/beast/net/IPEndpoint.h + DESTINATION include/ripple/beast/net) install ( FILES src/ripple/beast/rfc2616.h @@ -741,9 +762,6 @@ target_sources (rippled PRIVATE src/ripple/rpc/impl/ShardVerificationScheduler.cpp src/ripple/rpc/impl/Status.cpp src/ripple/rpc/impl/TransactionSign.cpp - src/ripple/rpc/impl/NFTokenID.cpp - src/ripple/rpc/impl/NFTokenOfferID.cpp - src/ripple/rpc/impl/NFTSyntheticSerializer.cpp #[===============================[ main sources: subdir: perflog diff --git a/Builds/CMake/RippledMultiConfig.cmake b/Builds/CMake/RippledMultiConfig.cmake index ae9b182a3..6df48a3d9 100644 --- a/Builds/CMake/RippledMultiConfig.cmake +++ b/Builds/CMake/RippledMultiConfig.cmake @@ -14,7 +14,7 @@ if (is_multiconfig) file(GLOB md_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} CONFIGURE_DEPENDS *.md) LIST(APPEND all_sources ${md_files}) - foreach (_target secp256k1::secp256k1 ed25519::ed25519 pbufs xrpl_core rippled) + foreach (_target secp256k1::secp256k1 ed25519::ed25519 xrpl_core rippled) get_target_property (_type ${_target} TYPE) if(_type STREQUAL "INTERFACE_LIBRARY") continue() diff --git a/Builds/CMake/conan/Protobuf.cmake b/Builds/CMake/conan/Protobuf.cmake index 4d4016e49..e5d866cb0 100644 --- a/Builds/CMake/conan/Protobuf.cmake +++ b/Builds/CMake/conan/Protobuf.cmake @@ -1,22 +1,27 @@ find_package(Protobuf 3.8) -file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/proto_gen) +set(output_dir ${CMAKE_BINARY_DIR}/proto_gen) +file(MAKE_DIRECTORY ${output_dir}) set(ccbd ${CMAKE_CURRENT_BINARY_DIR}) -set(CMAKE_CURRENT_BINARY_DIR ${CMAKE_BINARY_DIR}/proto_gen) +set(CMAKE_CURRENT_BINARY_DIR ${output_dir}) protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS src/ripple/proto/ripple.proto) set(CMAKE_CURRENT_BINARY_DIR ${ccbd}) -add_library(pbufs STATIC ${PROTO_SRCS} ${PROTO_HDRS}) -target_include_directories(pbufs SYSTEM PUBLIC - ${CMAKE_BINARY_DIR}/proto_gen - ${CMAKE_BINARY_DIR}/proto_gen/src/ripple/proto +target_include_directories(xrpl_core SYSTEM PUBLIC + # The generated implementation imports the header relative to the output + # directory. + $ + $ ) -target_link_libraries(pbufs protobuf::libprotobuf) -target_compile_options(pbufs +target_sources(xrpl_core PRIVATE ${output_dir}/src/ripple/proto/ripple.pb.cc) +install( + FILES ${output_dir}/src/ripple/proto/ripple.pb.h + DESTINATION include/ripple/proto) +target_link_libraries(xrpl_core PUBLIC protobuf::libprotobuf) +target_compile_options(xrpl_core PUBLIC $<$: --system-header-prefix="google/protobuf" -Wno-deprecated-dynamic-exception-spec > ) -add_library(Ripple::pbufs ALIAS pbufs) \ No newline at end of file diff --git a/Builds/CMake/conan/gRPC.cmake b/Builds/CMake/conan/gRPC.cmake index 0930ba4dd..de3a88b7b 100644 --- a/Builds/CMake/conan/gRPC.cmake +++ b/Builds/CMake/conan/gRPC.cmake @@ -5,21 +5,30 @@ find_package(gRPC 1.23) grpc defs and bundle into a static lib #]=================================] -set(GRPC_GEN_DIR "${CMAKE_BINARY_DIR}/proto_gen_grpc") +set(output_dir "${CMAKE_BINARY_DIR}/proto_gen_grpc") +set(GRPC_GEN_DIR "${output_dir}/ripple/proto") file(MAKE_DIRECTORY ${GRPC_GEN_DIR}) set(GRPC_PROTO_SRCS) set(GRPC_PROTO_HDRS) set(GRPC_PROTO_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/src/ripple/proto/org") -file(GLOB_RECURSE GRPC_DEFINITION_FILES LIST_DIRECTORIES false "${GRPC_PROTO_ROOT}/*.proto") +file(GLOB_RECURSE GRPC_DEFINITION_FILES "${GRPC_PROTO_ROOT}/*.proto") foreach(file ${GRPC_DEFINITION_FILES}) + # /home/user/rippled/src/ripple/proto/org/.../v1/get_ledger.proto get_filename_component(_abs_file ${file} ABSOLUTE) + # /home/user/rippled/src/ripple/proto/org/.../v1 get_filename_component(_abs_dir ${_abs_file} DIRECTORY) + # get_ledger get_filename_component(_basename ${file} NAME_WE) + # /home/user/rippled/src/ripple/proto get_filename_component(_proto_inc ${GRPC_PROTO_ROOT} DIRECTORY) # updir one level + # org/.../v1/get_ledger.proto file(RELATIVE_PATH _rel_root_file ${_proto_inc} ${_abs_file}) + # org/.../v1 get_filename_component(_rel_root_dir ${_rel_root_file} DIRECTORY) + # src/ripple/proto/org/.../v1 file(RELATIVE_PATH _rel_dir ${CMAKE_CURRENT_SOURCE_DIR} ${_abs_dir}) + # .cmake/proto_gen_grpc/ripple/proto/org/.../v1/get_ledger.grpc.pb.cc set(src_1 "${GRPC_GEN_DIR}/${_rel_root_dir}/${_basename}.grpc.pb.cc") set(src_2 "${GRPC_GEN_DIR}/${_rel_root_dir}/${_basename}.pb.cc") set(hdr_1 "${GRPC_GEN_DIR}/${_rel_root_dir}/${_basename}.grpc.pb.h") @@ -36,20 +45,32 @@ foreach(file ${GRPC_DEFINITION_FILES}) WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Running gRPC C++ protocol buffer compiler on ${file}" VERBATIM) - set_source_files_properties(${src_1} ${src_2} ${hdr_1} ${hdr_2} PROPERTIES GENERATED TRUE) + set_source_files_properties(${src_1} ${src_2} ${hdr_1} ${hdr_2} PROPERTIES + GENERATED TRUE + SKIP_UNITY_BUILD_INCLUSION ON + ) list(APPEND GRPC_PROTO_SRCS ${src_1} ${src_2}) list(APPEND GRPC_PROTO_HDRS ${hdr_1} ${hdr_2}) endforeach() -add_library(grpc_pbufs STATIC ${GRPC_PROTO_SRCS} ${GRPC_PROTO_HDRS}) -#target_include_directories(grpc_pbufs PRIVATE src) -target_include_directories(grpc_pbufs SYSTEM PUBLIC ${GRPC_GEN_DIR}) -target_link_libraries(grpc_pbufs +target_include_directories(xrpl_core SYSTEM PUBLIC + $ + $ + # The generated sources include headers relative to this path. Fix it later. + $ +) +target_sources(xrpl_core PRIVATE ${GRPC_PROTO_SRCS}) +install( + DIRECTORY ${output_dir}/ripple + DESTINATION include/ + FILES_MATCHING PATTERN "*.h" +) +target_link_libraries(xrpl_core PUBLIC "gRPC::grpc++" # libgrpc is missing references. absl::random_random ) -target_compile_options(grpc_pbufs +target_compile_options(xrpl_core PRIVATE $<$:-wd4065> $<$>:-Wno-deprecated-declarations> @@ -59,4 +80,3 @@ target_compile_options(grpc_pbufs --system-header-prefix="google/protobuf" -Wno-deprecated-dynamic-exception-spec >) -add_library(Ripple::grpc_pbufs ALIAS grpc_pbufs) \ No newline at end of file diff --git a/Builds/CMake/deps/Protobuf.cmake b/Builds/CMake/deps/Protobuf.cmake index 35d5b9f0f..b1c4b6c8c 100644 --- a/Builds/CMake/deps/Protobuf.cmake +++ b/Builds/CMake/deps/Protobuf.cmake @@ -129,27 +129,28 @@ else () endif () endif () -file (MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/proto_gen) -set (save_CBD ${CMAKE_CURRENT_BINARY_DIR}) -set (CMAKE_CURRENT_BINARY_DIR ${CMAKE_BINARY_DIR}/proto_gen) -protobuf_generate_cpp ( - PROTO_SRCS - PROTO_HDRS - src/ripple/proto/ripple.proto) -set (CMAKE_CURRENT_BINARY_DIR ${save_CBD}) +set(output_dir ${CMAKE_BINARY_DIR}/proto_gen) +file(MAKE_DIRECTORY ${output_dir}) +set(ccbd ${CMAKE_CURRENT_BINARY_DIR}) +set(CMAKE_CURRENT_BINARY_DIR ${output_dir}) +protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS src/ripple/proto/ripple.proto) +set(CMAKE_CURRENT_BINARY_DIR ${ccbd}) -add_library (pbufs STATIC ${PROTO_SRCS} ${PROTO_HDRS}) - -target_include_directories (pbufs PRIVATE src) -target_include_directories (pbufs - SYSTEM PUBLIC ${CMAKE_BINARY_DIR}/proto_gen) -target_link_libraries (pbufs protobuf::libprotobuf) -target_compile_options (pbufs +target_include_directories(xrpl_core SYSTEM PUBLIC + # The generated implementation imports the header relative to the output + # directory. + $ + $ +) +target_sources(xrpl_core PRIVATE ${output_dir}/src/ripple/proto/ripple.pb.cc) +install( + FILES ${output_dir}/src/ripple/proto/ripple.pb.h + DESTINATION include/ripple/proto) +target_link_libraries(xrpl_core PUBLIC protobuf::libprotobuf) +target_compile_options(xrpl_core PUBLIC $<$: --system-header-prefix="google/protobuf" -Wno-deprecated-dynamic-exception-spec - >) -add_library (Ripple::pbufs ALIAS pbufs) -target_link_libraries (ripple_libs INTERFACE Ripple::pbufs) -exclude_if_included (pbufs) + > +) diff --git a/Builds/CMake/deps/gRPC.cmake b/Builds/CMake/deps/gRPC.cmake index e4beaf89d..794f43a06 100644 --- a/Builds/CMake/deps/gRPC.cmake +++ b/Builds/CMake/deps/gRPC.cmake @@ -314,25 +314,33 @@ endif () grpc defs and bundle into a static lib #]=================================] -set (GRPC_GEN_DIR "${CMAKE_BINARY_DIR}/proto_gen_grpc") -file (MAKE_DIRECTORY ${GRPC_GEN_DIR}) -set (GRPC_PROTO_SRCS) -set (GRPC_PROTO_HDRS) -set (GRPC_PROTO_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/src/ripple/proto/org") -file(GLOB_RECURSE GRPC_DEFINITION_FILES LIST_DIRECTORIES false "${GRPC_PROTO_ROOT}/*.proto") +set(output_dir "${CMAKE_BINARY_DIR}/proto_gen_grpc") +set(GRPC_GEN_DIR "${output_dir}/ripple/proto") +file(MAKE_DIRECTORY ${GRPC_GEN_DIR}) +set(GRPC_PROTO_SRCS) +set(GRPC_PROTO_HDRS) +set(GRPC_PROTO_ROOT "${CMAKE_CURRENT_SOURCE_DIR}/src/ripple/proto/org") +file(GLOB_RECURSE GRPC_DEFINITION_FILES "${GRPC_PROTO_ROOT}/*.proto") foreach(file ${GRPC_DEFINITION_FILES}) + # /home/user/rippled/src/ripple/proto/org/.../v1/get_ledger.proto get_filename_component(_abs_file ${file} ABSOLUTE) + # /home/user/rippled/src/ripple/proto/org/.../v1 get_filename_component(_abs_dir ${_abs_file} DIRECTORY) + # get_ledger get_filename_component(_basename ${file} NAME_WE) + # /home/user/rippled/src/ripple/proto get_filename_component(_proto_inc ${GRPC_PROTO_ROOT} DIRECTORY) # updir one level + # org/.../v1/get_ledger.proto file(RELATIVE_PATH _rel_root_file ${_proto_inc} ${_abs_file}) + # org/.../v1 get_filename_component(_rel_root_dir ${_rel_root_file} DIRECTORY) + # src/ripple/proto/org/.../v1 file(RELATIVE_PATH _rel_dir ${CMAKE_CURRENT_SOURCE_DIR} ${_abs_dir}) - set (src_1 "${GRPC_GEN_DIR}/${_rel_root_dir}/${_basename}.grpc.pb.cc") - set (src_2 "${GRPC_GEN_DIR}/${_rel_root_dir}/${_basename}.pb.cc") - set (hdr_1 "${GRPC_GEN_DIR}/${_rel_root_dir}/${_basename}.grpc.pb.h") - set (hdr_2 "${GRPC_GEN_DIR}/${_rel_root_dir}/${_basename}.pb.h") + set(src_1 "${GRPC_GEN_DIR}/${_rel_root_dir}/${_basename}.grpc.pb.cc") + set(src_2 "${GRPC_GEN_DIR}/${_rel_root_dir}/${_basename}.pb.cc") + set(hdr_1 "${GRPC_GEN_DIR}/${_rel_root_dir}/${_basename}.grpc.pb.h") + set(hdr_2 "${GRPC_GEN_DIR}/${_rel_root_dir}/${_basename}.pb.h") add_custom_command( OUTPUT ${src_1} ${src_2} ${hdr_1} ${hdr_2} COMMAND protobuf::protoc @@ -345,16 +353,32 @@ foreach(file ${GRPC_DEFINITION_FILES}) WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} COMMENT "Running gRPC C++ protocol buffer compiler on ${file}" VERBATIM) - set_source_files_properties(${src_1} ${src_2} ${hdr_1} ${hdr_2} PROPERTIES GENERATED TRUE) + set_source_files_properties(${src_1} ${src_2} ${hdr_1} ${hdr_2} PROPERTIES + GENERATED TRUE + SKIP_UNITY_BUILD_INCLUSION ON + ) list(APPEND GRPC_PROTO_SRCS ${src_1} ${src_2}) list(APPEND GRPC_PROTO_HDRS ${hdr_1} ${hdr_2}) endforeach() -add_library (grpc_pbufs STATIC ${GRPC_PROTO_SRCS} ${GRPC_PROTO_HDRS}) -#target_include_directories (grpc_pbufs PRIVATE src) -target_include_directories (grpc_pbufs SYSTEM PUBLIC ${GRPC_GEN_DIR}) -target_link_libraries (grpc_pbufs protobuf::libprotobuf "gRPC::grpc++${grpc_suffix}") -target_compile_options (grpc_pbufs +target_include_directories(xrpl_core SYSTEM PUBLIC + $ + $ + # The generated sources include headers relative to this path. Fix it later. + $ +) +target_sources(xrpl_core PRIVATE ${GRPC_PROTO_SRCS}) +install( + DIRECTORY ${output_dir}/ripple + DESTINATION include/ + FILES_MATCHING PATTERN "*.h" +) +target_link_libraries(xrpl_core PUBLIC + "gRPC::grpc++" + # libgrpc is missing references. + absl::random_random +) +target_compile_options(xrpl_core PRIVATE $<$:-wd4065> $<$>:-Wno-deprecated-declarations> @@ -364,6 +388,5 @@ target_compile_options (grpc_pbufs --system-header-prefix="google/protobuf" -Wno-deprecated-dynamic-exception-spec >) -add_library (Ripple::grpc_pbufs ALIAS grpc_pbufs) -target_link_libraries (ripple_libs INTERFACE Ripple::grpc_pbufs) -exclude_if_included (grpc_pbufs) +# target_link_libraries (ripple_libs INTERFACE Ripple::grpc_pbufs) +# exclude_if_included (grpc_pbufs) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57fc86e2c..5664593e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -97,8 +97,8 @@ if (NOT USE_CONAN) include(deps/Rocksdb) include(deps/Nudb) include(deps/date) - include(deps/Protobuf) - include(deps/gRPC) + # include(deps/Protobuf) + # include(deps/gRPC) include(deps/cassandra) include(deps/Postgres) include(deps/WasmEdge) @@ -129,8 +129,6 @@ else() endif() find_package(nudb REQUIRED) find_package(date REQUIRED) - include(conan/Protobuf) - include(conan/gRPC) if(TARGET nudb::core) set(nudb nudb::core) elseif(TARGET NuDB::nudb) @@ -154,8 +152,8 @@ else() lz4::lz4 OpenSSL::Crypto OpenSSL::SSL - Ripple::grpc_pbufs - Ripple::pbufs + # Ripple::grpc_pbufs + # Ripple::pbufs secp256k1::secp256k1 soci::soci SQLite::SQLite3 @@ -165,6 +163,13 @@ endif() ### include(RippledCore) +if (NOT USE_CONAN) + include(deps/Protobuf) + include(deps/gRPC) +else() + include(conan/Protobuf) + include(conan/gRPC) +endif() include(RippledInstall) include(RippledCov) include(RippledMultiConfig) diff --git a/conanfile.py b/conanfile.py index 881ffc6a1..016b6bbac 100644 --- a/conanfile.py +++ b/conanfile.py @@ -151,9 +151,12 @@ class Xrpl(ConanFile): 'libed25519.a', 'libsecp256k1.a', ] - libxrpl.includedirs = ['include'] + # TODO: Fix the protobufs to include each other relative to + # `include/`, not `include/ripple/proto/`. + libxrpl.includedirs = ['include', 'include/ripple/proto'] libxrpl.requires = [ 'boost::boost', 'openssl::crypto', 'date::date', + 'grpc::grpc++', ] diff --git a/src/ripple/app/ledger/InboundLedger.h b/src/ripple/app/ledger/InboundLedger.h index 287dbaf7f..357a6fcad 100644 --- a/src/ripple/app/ledger/InboundLedger.h +++ b/src/ripple/app/ledger/InboundLedger.h @@ -197,14 +197,6 @@ private: std::unique_ptr mPeerSet; }; -/** Deserialize a ledger header from a byte array. */ -LedgerInfo -deserializeHeader(Slice data, bool hasHash = false); - -/** Deserialize a ledger header (prefixed with 4 bytes) from a byte array. */ -LedgerInfo -deserializePrefixedHeader(Slice data, bool hasHash = false); - } // namespace ripple #endif diff --git a/src/ripple/app/ledger/LedgerToJson.h b/src/ripple/app/ledger/LedgerToJson.h index 7f3777bc8..f65858388 100644 --- a/src/ripple/app/ledger/LedgerToJson.h +++ b/src/ripple/app/ledger/LedgerToJson.h @@ -26,6 +26,7 @@ #include #include #include +#include #include namespace ripple { @@ -70,22 +71,6 @@ addJson(Json::Value&, LedgerFill const&); Json::Value getJson(LedgerFill const&); -/** Serialize an object to a blob. */ -template -Blob -serializeBlob(Object const& o) -{ - Serializer s; - o.add(s); - return s.peekData(); -} - -/** Serialize an object to a hex string. */ -inline std::string -serializeHex(STObject const& o) -{ - return strHex(serializeBlob(o)); -} } // namespace ripple #endif diff --git a/src/ripple/app/ledger/impl/InboundLedger.cpp b/src/ripple/app/ledger/impl/InboundLedger.cpp index 660c21d53..402362c73 100644 --- a/src/ripple/app/ledger/impl/InboundLedger.cpp +++ b/src/ripple/app/ledger/impl/InboundLedger.cpp @@ -269,36 +269,6 @@ InboundLedger::neededStateHashes(int max, SHAMapSyncFilter* filter) const mLedger->info().accountHash, mLedger->stateMap(), max, filter); } -LedgerInfo -deserializeHeader(Slice data, bool hasHash) -{ - SerialIter sit(data.data(), data.size()); - - LedgerInfo info; - - info.seq = sit.get32(); - info.drops = sit.get64(); - info.parentHash = sit.get256(); - info.txHash = sit.get256(); - info.accountHash = sit.get256(); - info.parentCloseTime = - NetClock::time_point{NetClock::duration{sit.get32()}}; - info.closeTime = NetClock::time_point{NetClock::duration{sit.get32()}}; - info.closeTimeResolution = NetClock::duration{sit.get8()}; - info.closeFlags = sit.get8(); - - if (hasHash) - info.hash = sit.get256(); - - return info; -} - -LedgerInfo -deserializePrefixedHeader(Slice data, bool hasHash) -{ - return deserializeHeader(data + 4, hasHash); -} - // See how much of the ledger data is stored locally // Data found in a fetch pack will be stored void @@ -562,10 +532,9 @@ InboundLedger::trigger(std::shared_ptr const& peer, TriggerReason reason) if (auto stream = journal_.debug()) { + stream << "Trigger acquiring ledger " << hash_; if (peer) - stream << "Trigger acquiring ledger " << hash_ << " from " << peer; - else - stream << "Trigger acquiring ledger " << hash_; + stream << " from " << peer; if (complete_ || failed_) stream << "complete=" << complete_ << " failed=" << failed_; diff --git a/src/ripple/app/ledger/impl/LedgerReplayMsgHandler.cpp b/src/ripple/app/ledger/impl/LedgerReplayMsgHandler.cpp index 57c2fd083..c5301be7e 100644 --- a/src/ripple/app/ledger/impl/LedgerReplayMsgHandler.cpp +++ b/src/ripple/app/ledger/impl/LedgerReplayMsgHandler.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include diff --git a/src/ripple/app/reporting/ETLSource.h b/src/ripple/app/reporting/ETLSource.h index 66cb61bcc..b9f27a1bf 100644 --- a/src/ripple/app/reporting/ETLSource.h +++ b/src/ripple/app/reporting/ETLSource.h @@ -21,6 +21,7 @@ #define RIPPLE_APP_REPORTING_ETLSOURCE_H_INCLUDED #include #include +#include #include #include @@ -29,7 +30,6 @@ #include #include -#include "org/xrpl/rpc/v1/xrp_ledger.grpc.pb.h" #include namespace ripple { diff --git a/src/ripple/app/reporting/P2pProxy.h b/src/ripple/app/reporting/P2pProxy.h index 92cc508a1..55ebc7267 100644 --- a/src/ripple/app/reporting/P2pProxy.h +++ b/src/ripple/app/reporting/P2pProxy.h @@ -21,12 +21,11 @@ #define RIPPLE_APP_REPORTING_P2PPROXY_H_INCLUDED #include +#include #include #include #include - -#include "org/xrpl/rpc/v1/xrp_ledger.grpc.pb.h" #include namespace ripple { diff --git a/src/ripple/app/tx/impl/details/NFTokenUtils.h b/src/ripple/app/tx/impl/details/NFTokenUtils.h index db7cf00be..5242bf38f 100644 --- a/src/ripple/app/tx/impl/details/NFTokenUtils.h +++ b/src/ripple/app/tx/impl/details/NFTokenUtils.h @@ -25,34 +25,12 @@ #include #include #include +#include namespace ripple { namespace nft { -// Separate taxons from regular integers. -struct TaxonTag -{ -}; -using Taxon = tagged_integer; - -inline Taxon -toTaxon(std::uint32_t i) -{ - return static_cast(i); -} - -inline std::uint32_t -toUInt32(Taxon t) -{ - return static_cast(t); -} - -constexpr std::uint16_t const flagBurnable = 0x0001; -constexpr std::uint16_t const flagOnlyXRP = 0x0002; -constexpr std::uint16_t const flagCreateTrustLines = 0x0004; -constexpr std::uint16_t const flagTransferable = 0x0008; - /** Delete up to a specified number of offers from the specified token offer * directory. */ std::size_t @@ -116,72 +94,6 @@ removeToken( bool deleteTokenOffer(ApplyView& view, std::shared_ptr const& offer); -inline std::uint16_t -getFlags(uint256 const& id) -{ - std::uint16_t flags; - memcpy(&flags, id.begin(), 2); - return boost::endian::big_to_native(flags); -} - -inline std::uint16_t -getTransferFee(uint256 const& id) -{ - std::uint16_t fee; - memcpy(&fee, id.begin() + 2, 2); - return boost::endian::big_to_native(fee); -} - -inline std::uint32_t -getSerial(uint256 const& id) -{ - std::uint32_t seq; - memcpy(&seq, id.begin() + 28, 4); - return boost::endian::big_to_native(seq); -} - -inline Taxon -cipheredTaxon(std::uint32_t tokenSeq, Taxon taxon) -{ - // An issuer may issue several NFTs with the same taxon; to ensure that NFTs - // are spread across multiple pages we lightly mix the taxon up by using the - // sequence (which is not under the issuer's direct control) as the seed for - // a simple linear congruential generator. - // - // From the Hull-Dobell theorem we know that f(x)=(m*x+c) mod n will yield a - // permutation of [0, n) when n is a power of 2 if m is congruent to 1 mod 4 - // and c is odd. - // - // Here we use m = 384160001 and c = 2459. The modulo is implicit because we - // use 2^32 for n and the arithmetic gives it to us for "free". - // - // Note that the scramble value we calculate is not cryptographically secure - // but that's fine since all we're looking for is some dispersion. - // - // **IMPORTANT** Changing these numbers would be a breaking change requiring - // an amendment along with a way to distinguish token IDs that - // were generated with the old code. - return taxon ^ toTaxon(((384160001 * tokenSeq) + 2459)); -} - -inline Taxon -getTaxon(uint256 const& id) -{ - std::uint32_t taxon; - memcpy(&taxon, id.begin() + 24, 4); - taxon = boost::endian::big_to_native(taxon); - - // The taxon cipher is just an XOR, so it is reversible by applying the - // XOR a second time. - return cipheredTaxon(getSerial(id), toTaxon(taxon)); -} - -inline AccountID -getIssuer(uint256 const& id) -{ - return AccountID::fromVoid(id.data() + 4); -} - bool compareTokens(uint256 const& a, uint256 const& b); diff --git a/src/ripple/ledger/ReadView.h b/src/ripple/ledger/ReadView.h index e019d602f..2ea3ab492 100644 --- a/src/ripple/ledger/ReadView.h +++ b/src/ripple/ledger/ReadView.h @@ -27,7 +27,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -41,79 +43,6 @@ namespace ripple { -/** Reflects the fee settings for a particular ledger. - - The fees are always the same for any transactions applied - to a ledger. Changes to fees occur in between ledgers. -*/ -struct Fees -{ - XRPAmount base{0}; // Reference tx cost (drops) - XRPAmount reserve{0}; // Reserve base (drops) - XRPAmount increment{0}; // Reserve increment (drops) - - explicit Fees() = default; - Fees(Fees const&) = default; - Fees& - operator=(Fees const&) = default; - - /** Returns the account reserve given the owner count, in drops. - - The reserve is calculated as the reserve base plus - the reserve increment times the number of increments. - */ - XRPAmount - accountReserve(std::size_t ownerCount) const - { - return reserve + ownerCount * increment; - } -}; - -//------------------------------------------------------------------------------ - -/** Information about the notional ledger backing the view. */ -struct LedgerInfo -{ - explicit LedgerInfo() = default; - - // - // For all ledgers - // - - LedgerIndex seq = 0; - NetClock::time_point parentCloseTime = {}; - - // - // For closed ledgers - // - - // Closed means "tx set already determined" - uint256 hash = beast::zero; - uint256 txHash = beast::zero; - uint256 accountHash = beast::zero; - uint256 parentHash = beast::zero; - - XRPAmount drops = beast::zero; - - // If validated is false, it means "not yet validated." - // Once validated is true, it will never be set false at a later time. - // VFALCO TODO Make this not mutable - bool mutable validated = false; - bool accepted = false; - - // flags indicating how this ledger close took place - int closeFlags = 0; - - // the resolution for this ledger close time (2-120 seconds) - NetClock::duration closeTimeResolution = {}; - - // For closed ledgers, the time the ledger - // closed. For open ledgers, the time the ledger - // will close if there's no transactions. - // - NetClock::time_point closeTime = {}; -}; - //------------------------------------------------------------------------------ /** A view into a ledger. @@ -344,18 +273,6 @@ public: //------------------------------------------------------------------------------ -// ledger close flags -static std::uint32_t const sLCF_NoConsensusTime = 0x01; - -inline bool -getCloseAgree(LedgerInfo const& info) -{ - return (info.closeFlags & sLCF_NoConsensusTime) == 0; -} - -void -addRaw(LedgerInfo const&, Serializer&, bool includeHash = false); - Rules makeRulesGivenLedger(DigestAwareReadView const& ledger, Rules const& current); diff --git a/src/ripple/ledger/impl/View.cpp b/src/ripple/ledger/impl/View.cpp index 72d2d9627..e6ec257ff 100644 --- a/src/ripple/ledger/impl/View.cpp +++ b/src/ripple/ledger/impl/View.cpp @@ -158,23 +158,6 @@ cdirNext( // //------------------------------------------------------------------------------ -void -addRaw(LedgerInfo const& info, Serializer& s, bool includeHash) -{ - s.add32(info.seq); - s.add64(info.drops.drops()); - s.addBitString(info.parentHash); - s.addBitString(info.txHash); - s.addBitString(info.accountHash); - s.add32(info.parentCloseTime.time_since_epoch().count()); - s.add32(info.closeTime.time_since_epoch().count()); - s.add8(info.closeTimeResolution.count()); - s.add8(info.closeFlags); - - if (includeHash) - s.addBitString(info.hash); -} - bool hasExpired(ReadView const& view, std::optional const& exp) { diff --git a/src/ripple/nodestore/impl/DatabaseShardImp.cpp b/src/ripple/nodestore/impl/DatabaseShardImp.cpp index 1efcbe2ac..33000b5d2 100644 --- a/src/ripple/nodestore/impl/DatabaseShardImp.cpp +++ b/src/ripple/nodestore/impl/DatabaseShardImp.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include diff --git a/src/ripple/nodestore/impl/Shard.cpp b/src/ripple/nodestore/impl/Shard.cpp index ac4af4782..7876efd6e 100644 --- a/src/ripple/nodestore/impl/Shard.cpp +++ b/src/ripple/nodestore/impl/Shard.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include namespace ripple { diff --git a/src/ripple/overlay/Slot.h b/src/ripple/overlay/Slot.h index 1197eff56..e58619e66 100644 --- a/src/ripple/overlay/Slot.h +++ b/src/ripple/overlay/Slot.h @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/ripple/overlay/impl/ProtocolMessage.h b/src/ripple/overlay/impl/ProtocolMessage.h index 09861353a..d6fb14bc7 100644 --- a/src/ripple/overlay/impl/ProtocolMessage.h +++ b/src/ripple/overlay/impl/ProtocolMessage.h @@ -32,7 +32,6 @@ #include #include #include -#include #include #include diff --git a/src/ripple/protocol/Fees.h b/src/ripple/protocol/Fees.h new file mode 100644 index 000000000..d155b869d --- /dev/null +++ b/src/ripple/protocol/Fees.h @@ -0,0 +1,57 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2023 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_PROTOCOL_FEES_H_INCLUDED +#define RIPPLE_PROTOCOL_FEES_H_INCLUDED + +#include + +namespace ripple { + +/** Reflects the fee settings for a particular ledger. + + The fees are always the same for any transactions applied + to a ledger. Changes to fees occur in between ledgers. +*/ +struct Fees +{ + XRPAmount base{0}; // Reference tx cost (drops) + XRPAmount reserve{0}; // Reserve base (drops) + XRPAmount increment{0}; // Reserve increment (drops) + + explicit Fees() = default; + Fees(Fees const&) = default; + Fees& + operator=(Fees const&) = default; + + /** Returns the account reserve given the owner count, in drops. + + The reserve is calculated as the reserve base plus + the reserve increment times the number of increments. + */ + XRPAmount + accountReserve(std::size_t ownerCount) const + { + return reserve + ownerCount * increment; + } +}; + +} // namespace ripple + +#endif diff --git a/src/ripple/protocol/LedgerHeader.h b/src/ripple/protocol/LedgerHeader.h new file mode 100644 index 000000000..2adcfcfd2 --- /dev/null +++ b/src/ripple/protocol/LedgerHeader.h @@ -0,0 +1,103 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2023 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_PROTOCOL_LEDGERHEADER_H_INCLUDED +#define RIPPLE_PROTOCOL_LEDGERHEADER_H_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace ripple { + +/** Information about the notional ledger backing the view. */ +struct LedgerHeader +{ + explicit LedgerHeader() = default; + + // + // For all ledgers + // + + LedgerIndex seq = 0; + NetClock::time_point parentCloseTime = {}; + + // + // For closed ledgers + // + + // Closed means "tx set already determined" + uint256 hash = beast::zero; + uint256 txHash = beast::zero; + uint256 accountHash = beast::zero; + uint256 parentHash = beast::zero; + + XRPAmount drops = beast::zero; + + // If validated is false, it means "not yet validated." + // Once validated is true, it will never be set false at a later time. + // VFALCO TODO Make this not mutable + bool mutable validated = false; + bool accepted = false; + + // flags indicating how this ledger close took place + int closeFlags = 0; + + // the resolution for this ledger close time (2-120 seconds) + NetClock::duration closeTimeResolution = {}; + + // For closed ledgers, the time the ledger + // closed. For open ledgers, the time the ledger + // will close if there's no transactions. + // + NetClock::time_point closeTime = {}; +}; + +// We call them "headers" in conversation +// but "info" in code. Unintuitive. +// This alias lets us give the "correct" name to the class +// without yet disturbing existing uses. +using LedgerInfo = LedgerHeader; + +// ledger close flags +static std::uint32_t const sLCF_NoConsensusTime = 0x01; + +inline bool +getCloseAgree(LedgerHeader const& info) +{ + return (info.closeFlags & sLCF_NoConsensusTime) == 0; +} + +void +addRaw(LedgerHeader const&, Serializer&, bool includeHash = false); + +/** Deserialize a ledger header from a byte array. */ +LedgerHeader +deserializeHeader(Slice data, bool hasHash = false); + +/** Deserialize a ledger header (prefixed with 4 bytes) from a byte array. */ +LedgerHeader +deserializePrefixedHeader(Slice data, bool hasHash = false); + +} // namespace ripple + +#endif diff --git a/src/ripple/rpc/NFTSyntheticSerializer.h b/src/ripple/protocol/NFTSyntheticSerializer.h similarity index 79% rename from src/ripple/rpc/NFTSyntheticSerializer.h rename to src/ripple/protocol/NFTSyntheticSerializer.h index 090e89378..f9a0cd50a 100644 --- a/src/ripple/rpc/NFTSyntheticSerializer.h +++ b/src/ripple/protocol/NFTSyntheticSerializer.h @@ -17,28 +17,17 @@ */ //============================================================================== -#ifndef RIPPLE_RPC_NFTSYNTHETICSERIALIZER_H_INCLUDED -#define RIPPLE_RPC_NFTSYNTHETICSERIALIZER_H_INCLUDED +#ifndef RIPPLE_PROTOCOL_NFTSYNTHETICSERIALIZER_H_INCLUDED +#define RIPPLE_PROTOCOL_NFTSYNTHETICSERIALIZER_H_INCLUDED -#include -#include +#include +#include +#include -#include #include -namespace Json { -class Value; -} - namespace ripple { -class TxMeta; -class STTx; - -namespace RPC { - -struct JsonContext; - /** Adds common synthetic fields to transaction-related JSON responses @@ -47,12 +36,10 @@ struct JsonContext; void insertNFTSyntheticInJson( Json::Value&, - RPC::JsonContext const&, std::shared_ptr const&, TxMeta const&); /** @} */ -} // namespace RPC } // namespace ripple #endif diff --git a/src/ripple/rpc/NFTokenID.h b/src/ripple/protocol/NFTokenID.h similarity index 86% rename from src/ripple/rpc/NFTokenID.h rename to src/ripple/protocol/NFTokenID.h index cb218966f..f29713aba 100644 --- a/src/ripple/rpc/NFTokenID.h +++ b/src/ripple/protocol/NFTokenID.h @@ -17,25 +17,20 @@ */ //============================================================================== -#ifndef RIPPLE_RPC_NFTOKENID_H_INCLUDED -#define RIPPLE_RPC_NFTOKENID_H_INCLUDED +#ifndef RIPPLE_PROTOCOL_NFTOKENID_H_INCLUDED +#define RIPPLE_PROTOCOL_NFTOKENID_H_INCLUDED -#include +#include +#include +#include +#include -#include #include - -namespace Json { -class Value; -} +#include +#include namespace ripple { -class TxMeta; -class STTx; - -namespace RPC { - /** Add a `nftoken_ids` field to the `meta` output parameter. The field is only added to successful NFTokenMint, NFTokenAcceptOffer, @@ -62,7 +57,6 @@ insertNFTokenID( TxMeta const& transactionMeta); /** @} */ -} // namespace RPC } // namespace ripple #endif diff --git a/src/ripple/rpc/NFTokenOfferID.h b/src/ripple/protocol/NFTokenOfferID.h similarity index 86% rename from src/ripple/rpc/NFTokenOfferID.h rename to src/ripple/protocol/NFTokenOfferID.h index 6c1bef3d1..777324f42 100644 --- a/src/ripple/rpc/NFTokenOfferID.h +++ b/src/ripple/protocol/NFTokenOfferID.h @@ -17,25 +17,19 @@ */ //============================================================================== -#ifndef RIPPLE_RPC_NFTOKENOFFERID_H_INCLUDED -#define RIPPLE_RPC_NFTOKENOFFERID_H_INCLUDED +#ifndef RIPPLE_PROTOCOL_NFTOKENOFFERID_H_INCLUDED +#define RIPPLE_PROTOCOL_NFTOKENOFFERID_H_INCLUDED -#include +#include +#include +#include +#include -#include #include - -namespace Json { -class Value; -} +#include namespace ripple { -class TxMeta; -class STTx; - -namespace RPC { - /** Add an `offer_id` field to the `meta` output parameter. The field is only added to successful NFTokenCreateOffer transactions. @@ -58,7 +52,6 @@ insertNFTokenOfferID( TxMeta const& transactionMeta); /** @} */ -} // namespace RPC } // namespace ripple #endif diff --git a/src/ripple/protocol/Serializer.h b/src/ripple/protocol/Serializer.h index 7c3ccf958..e3ef00eaf 100644 --- a/src/ripple/protocol/Serializer.h +++ b/src/ripple/protocol/Serializer.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include diff --git a/src/ripple/protocol/impl/LedgerHeader.cpp b/src/ripple/protocol/impl/LedgerHeader.cpp new file mode 100644 index 000000000..6d13db224 --- /dev/null +++ b/src/ripple/protocol/impl/LedgerHeader.cpp @@ -0,0 +1,71 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2023 Ripple Labs Inc. + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include + +namespace ripple { + +void +addRaw(LedgerHeader const& info, Serializer& s, bool includeHash) +{ + s.add32(info.seq); + s.add64(info.drops.drops()); + s.addBitString(info.parentHash); + s.addBitString(info.txHash); + s.addBitString(info.accountHash); + s.add32(info.parentCloseTime.time_since_epoch().count()); + s.add32(info.closeTime.time_since_epoch().count()); + s.add8(info.closeTimeResolution.count()); + s.add8(info.closeFlags); + + if (includeHash) + s.addBitString(info.hash); +} + +LedgerHeader +deserializeHeader(Slice data, bool hasHash) +{ + SerialIter sit(data.data(), data.size()); + + LedgerHeader header; + + header.seq = sit.get32(); + header.drops = sit.get64(); + header.parentHash = sit.get256(); + header.txHash = sit.get256(); + header.accountHash = sit.get256(); + header.parentCloseTime = + NetClock::time_point{NetClock::duration{sit.get32()}}; + header.closeTime = NetClock::time_point{NetClock::duration{sit.get32()}}; + header.closeTimeResolution = NetClock::duration{sit.get8()}; + header.closeFlags = sit.get8(); + + if (hasHash) + header.hash = sit.get256(); + + return header; +} + +LedgerHeader +deserializePrefixedHeader(Slice data, bool hasHash) +{ + return deserializeHeader(data + 4, hasHash); +} + +} // namespace ripple diff --git a/src/ripple/rpc/impl/NFTSyntheticSerializer.cpp b/src/ripple/protocol/impl/NFTSyntheticSerializer.cpp similarity index 70% rename from src/ripple/rpc/impl/NFTSyntheticSerializer.cpp rename to src/ripple/protocol/impl/NFTSyntheticSerializer.cpp index f4692cfd4..e34397ada 100644 --- a/src/ripple/rpc/impl/NFTSyntheticSerializer.cpp +++ b/src/ripple/protocol/impl/NFTSyntheticSerializer.cpp @@ -17,28 +17,16 @@ */ //============================================================================== -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include namespace ripple { -namespace RPC { void insertNFTSyntheticInJson( Json::Value& response, - RPC::JsonContext const& context, std::shared_ptr const& transaction, TxMeta const& transactionMeta) { @@ -46,5 +34,4 @@ insertNFTSyntheticInJson( insertNFTokenOfferID(response[jss::meta], transaction, transactionMeta); } -} // namespace RPC } // namespace ripple diff --git a/src/ripple/rpc/impl/NFTokenID.cpp b/src/ripple/protocol/impl/NFTokenID.cpp similarity index 94% rename from src/ripple/rpc/impl/NFTokenID.cpp rename to src/ripple/protocol/impl/NFTokenID.cpp index d0be439ec..ea6ab984c 100644 --- a/src/ripple/rpc/impl/NFTokenID.cpp +++ b/src/ripple/protocol/impl/NFTokenID.cpp @@ -17,21 +17,10 @@ */ //============================================================================== -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include namespace ripple { -namespace RPC { bool canHaveNFTokenID( @@ -198,5 +187,4 @@ insertNFTokenID( } } -} // namespace RPC } // namespace ripple diff --git a/src/ripple/rpc/impl/NFTokenOfferID.cpp b/src/ripple/protocol/impl/NFTokenOfferID.cpp similarity index 83% rename from src/ripple/rpc/impl/NFTokenOfferID.cpp rename to src/ripple/protocol/impl/NFTokenOfferID.cpp index 05d110aac..c9c3118cf 100644 --- a/src/ripple/rpc/impl/NFTokenOfferID.cpp +++ b/src/ripple/protocol/impl/NFTokenOfferID.cpp @@ -17,21 +17,10 @@ */ //============================================================================== -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include namespace ripple { -namespace RPC { bool canHaveNFTokenOfferID( @@ -81,5 +70,4 @@ insertNFTokenOfferID( response[jss::offer_id] = to_string(result.value()); } -} // namespace RPC } // namespace ripple diff --git a/src/ripple/protocol/messages.h b/src/ripple/protocol/messages.h index 81f6dc6c7..e9c9cf60b 100644 --- a/src/ripple/protocol/messages.h +++ b/src/ripple/protocol/messages.h @@ -31,6 +31,6 @@ #undef TYPE_BOOL #endif -#include "ripple.pb.h" +#include #endif diff --git a/src/ripple/protocol/nft.h b/src/ripple/protocol/nft.h new file mode 100644 index 000000000..2df8e0b89 --- /dev/null +++ b/src/ripple/protocol/nft.h @@ -0,0 +1,127 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2023 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_PROTOCOL_NFT_H_INCLUDED +#define RIPPLE_PROTOCOL_NFT_H_INCLUDED + +#include +#include +#include + +#include + +#include +#include + +namespace ripple { +namespace nft { + +// Separate taxons from regular integers. +struct TaxonTag +{ +}; +using Taxon = tagged_integer; + +inline Taxon +toTaxon(std::uint32_t i) +{ + return static_cast(i); +} + +inline std::uint32_t +toUInt32(Taxon t) +{ + return static_cast(t); +} + +constexpr std::uint16_t const flagBurnable = 0x0001; +constexpr std::uint16_t const flagOnlyXRP = 0x0002; +constexpr std::uint16_t const flagCreateTrustLines = 0x0004; +constexpr std::uint16_t const flagTransferable = 0x0008; + +inline std::uint16_t +getFlags(uint256 const& id) +{ + std::uint16_t flags; + memcpy(&flags, id.begin(), 2); + return boost::endian::big_to_native(flags); +} + +inline std::uint16_t +getTransferFee(uint256 const& id) +{ + std::uint16_t fee; + memcpy(&fee, id.begin() + 2, 2); + return boost::endian::big_to_native(fee); +} + +inline std::uint32_t +getSerial(uint256 const& id) +{ + std::uint32_t seq; + memcpy(&seq, id.begin() + 28, 4); + return boost::endian::big_to_native(seq); +} + +inline Taxon +cipheredTaxon(std::uint32_t tokenSeq, Taxon taxon) +{ + // An issuer may issue several NFTs with the same taxon; to ensure that NFTs + // are spread across multiple pages we lightly mix the taxon up by using the + // sequence (which is not under the issuer's direct control) as the seed for + // a simple linear congruential generator. + // + // From the Hull-Dobell theorem we know that f(x)=(m*x+c) mod n will yield a + // permutation of [0, n) when n is a power of 2 if m is congruent to 1 mod 4 + // and c is odd. + // + // Here we use m = 384160001 and c = 2459. The modulo is implicit because we + // use 2^32 for n and the arithmetic gives it to us for "free". + // + // Note that the scramble value we calculate is not cryptographically secure + // but that's fine since all we're looking for is some dispersion. + // + // **IMPORTANT** Changing these numbers would be a breaking change requiring + // an amendment along with a way to distinguish token IDs that + // were generated with the old code. + return taxon ^ toTaxon(((384160001 * tokenSeq) + 2459)); +} + +inline Taxon +getTaxon(uint256 const& id) +{ + std::uint32_t taxon; + memcpy(&taxon, id.begin() + 24, 4); + taxon = boost::endian::big_to_native(taxon); + + // The taxon cipher is just an XOR, so it is reversible by applying the + // XOR a second time. + return cipheredTaxon(getSerial(id), toTaxon(taxon)); +} + +inline AccountID +getIssuer(uint256 const& id) +{ + return AccountID::fromVoid(id.data() + 4); +} + +} // namespace nft +} // namespace ripple + +#endif diff --git a/src/ripple/protocol/serialize.h b/src/ripple/protocol/serialize.h new file mode 100644 index 000000000..93c59acfd --- /dev/null +++ b/src/ripple/protocol/serialize.h @@ -0,0 +1,48 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright (c) 2023 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_PROTOCOL_SERIALIZE_H_INCLUDED +#define RIPPLE_PROTOCOL_SERIALIZE_H_INCLUDED + +#include +#include +#include + +namespace ripple { + +/** Serialize an object to a blob. */ +template +Blob +serializeBlob(Object const& o) +{ + Serializer s; + o.add(s); + return s.peekData(); +} + +/** Serialize an object to a hex string. */ +inline std::string +serializeHex(STObject const& o) +{ + return strHex(serializeBlob(o)); +} + +} // namespace ripple + +#endif diff --git a/src/ripple/rpc/GRPCHandlers.h b/src/ripple/rpc/GRPCHandlers.h index 493de7a5c..9fb8d0909 100644 --- a/src/ripple/rpc/GRPCHandlers.h +++ b/src/ripple/rpc/GRPCHandlers.h @@ -20,9 +20,9 @@ #ifndef RIPPLE_RPC_GRPCHANDLER_H_INCLUDED #define RIPPLE_RPC_GRPCHANDLER_H_INCLUDED +#include #include #include -#include namespace ripple { diff --git a/src/ripple/rpc/handlers/AccountTx.cpp b/src/ripple/rpc/handlers/AccountTx.cpp index bfbc76362..84d087939 100644 --- a/src/ripple/rpc/handlers/AccountTx.cpp +++ b/src/ripple/rpc/handlers/AccountTx.cpp @@ -29,12 +29,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include @@ -334,7 +334,7 @@ populateJsonResponse( insertDeliveredAmount( jvObj[jss::meta], context, txn, *txnMeta); insertNFTSyntheticInJson( - jvObj, context, txn->getSTransaction(), *txnMeta); + jvObj, txn->getSTransaction(), *txnMeta); } } } diff --git a/src/ripple/rpc/handlers/Tx.cpp b/src/ripple/rpc/handlers/Tx.cpp index 02f733d0d..12b0b4f4c 100644 --- a/src/ripple/rpc/handlers/Tx.cpp +++ b/src/ripple/rpc/handlers/Tx.cpp @@ -24,12 +24,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include #include @@ -335,7 +335,7 @@ populateJsonResponse( insertDeliveredAmount( response[jss::meta], context, result.txn, *meta); insertNFTSyntheticInJson( - response, context, result.txn->getSTransaction(), *meta); + response, result.txn->getSTransaction(), *meta); } } response[jss::validated] = result.validated; diff --git a/src/ripple/rpc/impl/RPCHelpers.h b/src/ripple/rpc/impl/RPCHelpers.h index 4c8e80309..3a0c6fa8f 100644 --- a/src/ripple/rpc/impl/RPCHelpers.h +++ b/src/ripple/rpc/impl/RPCHelpers.h @@ -21,6 +21,7 @@ #define RIPPLE_RPC_RPCHELPERS_H_INCLUDED #include +#include #include #include @@ -30,7 +31,6 @@ #include #include #include -#include #include namespace Json { diff --git a/src/test/overlay/compression_test.cpp b/src/test/overlay/compression_test.cpp index e24cb09f9..3b61b2b3a 100644 --- a/src/test/overlay/compression_test.cpp +++ b/src/test/overlay/compression_test.cpp @@ -34,12 +34,12 @@ #include #include #include +#include #include #include #include #include #include -#include #include #include #include diff --git a/src/test/overlay/reduce_relay_test.cpp b/src/test/overlay/reduce_relay_test.cpp index 1839220dc..c722476db 100644 --- a/src/test/overlay/reduce_relay_test.cpp +++ b/src/test/overlay/reduce_relay_test.cpp @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include @@ -1597,4 +1597,4 @@ BEAST_DEFINE_TESTSUITE_MANUAL(reduce_relay_simulate, ripple_data, ripple); } // namespace test -} // namespace ripple \ No newline at end of file +} // namespace ripple