Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RPC for server_definitions to rippled #4703

Merged
merged 37 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
439179d
Add rpc call `server_definitions` to rippled.
RichardAH Jan 30, 2023
c8f73bd
capitalization fix for server_definitions with URIToken
RichardAH Feb 9, 2023
ede9634
remove magic_enum
mvadari Sep 12, 2023
e8ba1ef
get STypes, TxTypes, LedgerEntryTypes, Fields working
mvadari Sep 13, 2023
38db68b
get TER codes working
mvadari Sep 13, 2023
18cecad
clean up
mvadari Sep 13, 2023
2ac883e
run clang-format
mvadari Sep 13, 2023
d36cb79
fix bugs + clean up
mvadari Sep 13, 2023
54f19e3
add to CLI help list
mvadari Sep 13, 2023
1607c55
fix header issue
mvadari Sep 13, 2023
2ca2bb7
Merge branch 'develop' into server-definitions
mvadari Sep 14, 2023
ff4f55d
use KnownFormats iterator instead of custom map
mvadari Sep 18, 2023
166ab29
add comments back into macro
mvadari Sep 18, 2023
fd2da62
merge develop
mvadari Sep 18, 2023
e22e3b3
Merge branch 'develop' into server-definitions
mvadari Sep 19, 2023
423bf60
Merge branch 'develop' into server-definitions
mvadari Oct 3, 2023
5fc2ee5
make defsHash not optional
mvadari Oct 3, 2023
5d36478
add hash support to rippled CLI
mvadari Oct 3, 2023
f430626
fix XChainBridge capitalization
mvadari Oct 3, 2023
c46a5f7
remove unneeded forward declaration
mvadari Oct 3, 2023
e67f72c
remove unneeded void
mvadari Oct 3, 2023
18edf9e
remove str
mvadari Oct 3, 2023
89f336a
add underscore to private internal variables
mvadari Oct 3, 2023
7f53fcf
Merge branch 'develop' into server-definitions
mvadari Oct 4, 2023
d558b66
respond to comments
mvadari Oct 11, 2023
c34bcd0
separate declarations from implementations
mvadari Oct 11, 2023
ed92a27
Merge branch 'develop' into server-definitions
mvadari Oct 11, 2023
ebe4258
respond to more comments
mvadari Oct 11, 2023
b628b42
clean up + edit changelog
mvadari Oct 16, 2023
c64bd2f
Merge branch 'develop' into server-definitions
mvadari Oct 16, 2023
162ba8b
Merge branch 'develop' into server-definitions
mvadari Oct 17, 2023
d8503ae
add tests
mvadari Oct 17, 2023
7f17a78
switch out operator
mvadari Oct 17, 2023
205c0f5
update comments + remove generate function
mvadari Oct 18, 2023
3e4b7a5
Merge branch 'develop' into server-definitions
mvadari Oct 18, 2023
cd69226
fix build issue
mvadari Oct 18, 2023
008f092
Merge branch 'develop' into server-definitions
mvadari Oct 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/ripple/app/main/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ printHelp(const po::options_description& desc)
" peer_reservations_list\n"
" ripple ...\n"
" ripple_path_find <json> [<ledger>]\n"
" server_definitions\n"
" server_info [counters]\n"
mvadari marked this conversation as resolved.
Show resolved Hide resolved
" server_state [counters]\n"
" sign <private_key> <tx_json> [offline]\n"
Expand Down
10 changes: 10 additions & 0 deletions src/ripple/protocol/KnownFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ class KnownFormats
return formats_.end();
}

std::map<char const*, KeyType> const
mvadari marked this conversation as resolved.
Show resolved Hide resolved
getNamesAndTypes() const
{
return namesAndTypes_;
}

protected:
/** Retrieve a format based on its name.
*/
Expand Down Expand Up @@ -185,6 +191,8 @@ class KnownFormats
names_[name] = &item;
types_[type] = &item;

namesAndTypes_.insert({name, type});
mvadari marked this conversation as resolved.
Show resolved Hide resolved

return item;
}

Expand All @@ -198,6 +206,8 @@ class KnownFormats

boost::container::flat_map<std::string, Item const*> names_;
boost::container::flat_map<KeyType, Item const*> types_;

std::map<char const*, KeyType> namesAndTypes_;
mvadari marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace ripple
Expand Down
90 changes: 52 additions & 38 deletions src/ripple/protocol/SField.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,43 +50,56 @@ class STBitString;
template <class>
class STInteger;
class STVector256;

enum SerializedTypeID {
// special types
STI_UNKNOWN = -2,
STI_NOTPRESENT = 0,

// // types (common)
STI_UINT16 = 1,
STI_UINT32 = 2,
STI_UINT64 = 3,
STI_UINT128 = 4,
STI_UINT256 = 5,
STI_AMOUNT = 6,
STI_VL = 7,
STI_ACCOUNT = 8,
// 9-13 are reserved
STI_OBJECT = 14,
STI_ARRAY = 15,

// types (uncommon)
STI_UINT8 = 16,
STI_UINT160 = 17,
STI_PATHSET = 18,
STI_VECTOR256 = 19,
STI_UINT96 = 20,
STI_UINT192 = 21,
STI_UINT384 = 22,
STI_UINT512 = 23,
STI_ISSUE = 24,

// high level types
// cannot be serialized inside other types
STI_TRANSACTION = 10001,
STI_LEDGERENTRY = 10002,
STI_VALIDATION = 10003,
STI_METADATA = 10004,
};
class Definitions;

#pragma push_macro("XMACRO")
#undef XMACRO

#define XMACRO(STYPE) \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yuck. Consider using Boost.Describe at least.

Copy link
Collaborator Author

@mvadari mvadari Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't figure out how to properly use Boost.Describe - I keep getting a ton of errors. The documentation is very unclear, since the API has changed a lot in the past few versions. Even ChatGPT/Bard isn't able to provide much help.

STYPE(STI_UNKNOWN, -2) \
mvadari marked this conversation as resolved.
Show resolved Hide resolved
STYPE(STI_NOTPRESENT, 0) \
STYPE(STI_UINT16, 1) \
mvadari marked this conversation as resolved.
Show resolved Hide resolved
STYPE(STI_UINT32, 2) \
STYPE(STI_UINT64, 3) \
STYPE(STI_UINT128, 4) \
STYPE(STI_UINT256, 5) \
STYPE(STI_AMOUNT, 6) \
STYPE(STI_VL, 7) \
STYPE(STI_ACCOUNT, 8) \
mvadari marked this conversation as resolved.
Show resolved Hide resolved
STYPE(STI_OBJECT, 14) \
STYPE(STI_ARRAY, 15) \
STYPE(STI_UINT8, 16) \
mvadari marked this conversation as resolved.
Show resolved Hide resolved
STYPE(STI_UINT160, 17) \
STYPE(STI_PATHSET, 18) \
STYPE(STI_VECTOR256, 19) \
STYPE(STI_UINT96, 20) \
STYPE(STI_UINT192, 21) \
STYPE(STI_UINT384, 22) \
STYPE(STI_UINT512, 23) \
STYPE(STI_ISSUE, 24) \
STYPE(STI_TRANSACTION, 10001) \
STYPE(STI_LEDGERENTRY, 10002) \
STYPE(STI_VALIDATION, 10003) \
STYPE(STI_METADATA, 10004)
mvadari marked this conversation as resolved.
Show resolved Hide resolved

#pragma push_macro("TO_ENUM")
#undef TO_ENUM
#pragma push_macro("TO_MAP")
#undef TO_MAP

#define TO_ENUM(name, value) name = value,
#define TO_MAP(name, value) {#name, value},

enum SerializedTypeID { XMACRO(TO_ENUM) };

static std::map<char const*, int> const sTypeMap = {XMACRO(TO_MAP)};
mvadari marked this conversation as resolved.
Show resolved Hide resolved

#undef XMACRO
#undef TO_ENUM

#pragma pop_macro("XMACRO")
#pragma pop_macro("TO_ENUM")
#pragma pop_macro("TO_MAP")

// constexpr
inline int
Expand Down Expand Up @@ -264,9 +277,10 @@ class SField
static int
compare(const SField& f1, const SField& f2);

static std::map<int, SField const*> knownCodeToField;
seelabs marked this conversation as resolved.
Show resolved Hide resolved

private:
static int num;
static std::map<int, SField const*> knownCodeToField;
};

/** A field with a type known at compile time. */
Expand Down
10 changes: 10 additions & 0 deletions src/ripple/protocol/TER.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <optional>
#include <ostream>
#include <string>
#include <unordered_map>

namespace ripple {

Expand Down Expand Up @@ -617,6 +618,15 @@ isTecClaim(TER x)
return ((x) >= tecCLAIM);
}

namespace detail {

seelabs marked this conversation as resolved.
Show resolved Hide resolved
std::unordered_map<
TERUnderlyingType,
std::pair<char const* const, char const* const>> const&
transResults();

} // namespace detail

bool
transResultInfo(TER code, std::string& token, std::string& text);

Expand Down
3 changes: 1 addition & 2 deletions src/ripple/protocol/impl/TER.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
#include <ripple/protocol/TER.h>
#include <boost/range/adaptor/transformed.hpp>
#include <type_traits>
#include <unordered_map>

namespace ripple {

namespace detail {

static std::unordered_map<
std::unordered_map<
TERUnderlyingType,
std::pair<char const* const, char const* const>> const&
transResults()
Expand Down
11 changes: 10 additions & 1 deletion src/ripple/protocol/jss.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ JSS(fee_level); // out: AccountInfo
JSS(fee_mult_max); // in: TransactionSign
JSS(fee_ref); // out: NetworkOPs
JSS(fetch_pack); // out: NetworkOPs
JSS(FIELDS); // out: RPC server_definitions
mvadari marked this conversation as resolved.
Show resolved Hide resolved
JSS(first); // out: rpc/Version
JSS(firstSequence); // out: NodeToShardStatus
JSS(firstShardIndex); // out: NodeToShardStatus
Expand Down Expand Up @@ -344,6 +345,9 @@ JSS(invalid_API_version); // out: Many, when a request has an invalid
JSS(io_latency_ms); // out: NetworkOPs
JSS(ip); // in: Connect, out: OverlayImpl
JSS(is_burned); // out: nft_info (clio)
JSS(isSerialized); // out: RPC server_definitions
JSS(isSigningField); // out: RPC server_definitions
JSS(isVLEncoded); // out: RPC server_definitions
JSS(issuer); // in: RipplePathFind, Subscribe,
// Unsubscribe, BookOffers
// out: STPathSet, STAmount
Expand Down Expand Up @@ -383,6 +387,7 @@ JSS(ledger_index_min); // in, out: AccountTx*
JSS(ledger_max); // in, out: AccountTx*
JSS(ledger_min); // in, out: AccountTx*
JSS(ledger_time); // out: NetworkOPs
JSS(LEDGER_ENTRY_TYPES); // out: RPC server_definitions
JSS(levels); // LogLevels
JSS(limit); // in/out: AccountTx*, AccountOffers,
// AccountLines, AccountObjects
Expand Down Expand Up @@ -469,6 +474,7 @@ JSS(node_written_bytes); // out: GetCounts
JSS(node_writes_duration_us); // out: GetCounts
JSS(node_write_retries); // out: GetCounts
JSS(node_writes_delayed); // out::GetCounts
JSS(nth); // out: RPC server_definitions
JSS(obligations); // out: GatewayBalances
JSS(offer); // in: LedgerEntry
JSS(offers); // out: NetworkOPs, AccountOffers, Subscribe
Expand Down Expand Up @@ -659,8 +665,11 @@ JSS(txr_not_enabled_cnt); // out: peers with tx reduce-relay disabled count
JSS(txr_missing_tx_freq); // out: missing tx frequency average
JSS(txs); // out: TxHistory
JSS(type); // in: AccountObjects
// out: NetworkOPs
// out: NetworkOPs RPC server_definitions
// OverlayImpl, Logic
JSS(TRANSACTION_RESULTS); // out: RPC server_definitions
JSS(TRANSACTION_TYPES); // out: RPC server_definitions
JSS(TYPES); // out: RPC server_definitions
JSS(type_hex); // out: STPathSet
JSS(unl); // out: UnlList
JSS(unlimited); // out: Connection.h
Expand Down
2 changes: 2 additions & 0 deletions src/ripple/rpc/handlers/Handlers.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ doPeerReservationsList(RPC::JsonContext&);
Json::Value
doRipplePathFind(RPC::JsonContext&);
Json::Value
doServerDefinitions(RPC::JsonContext&);
Json::Value
doServerInfo(RPC::JsonContext&); // for humans
Json::Value
doServerState(RPC::JsonContext&); // for machines
Expand Down
Loading