13591 Commits

Author SHA1 Message Date
Nik Bougalis
086ce21c0d Improve Json::Value memory allocation for strings:
The memory allocation patterns of Json::Value benefit greatly
from the slabbed allocator. This commit adds a global slabbed
allocator dedicated to `Json::Value`.

Real-world data indicates that only 2% of allocation requests
are over 72 bytes long. The remaining 98% of allocations fall
into the following 3 buckets, calculated across 9,500,000,000
allocation calls:

    [ 1, 32]: 17% of all allocations
    [33, 48]: 27% of all allocations
    [49, 72]: 57% of all allocations

This commit should result in improved performance for servers
that have JSON-heavy workloads, typically those servicing RPC
and WebSocket workloads, and less memory fragmentation.
2023-09-24 18:36:15 -07:00
Nik Bougalis
3637cc19f0 Improve ST construction & ser/des interfaces:
The primary motivation of this commit was simplification, although
it may not always be successful at that.

The serialization and deserialization interfaces are split up into
separate classes, hopefully, providing interfaces that are leaner,
cleaner, and less error-prone.

The deserializer is now effectively zero-copy, even for types like
variable-length blobs.

The serializer now comes in two flavors: one that includes a large
stack-based buffer built into the serializer, and a second variant
that writes directly to an external buffer. If used properly, this
can avoid unnecessary copying and memory allocations.

Lastly, multiple ST* constructors have been consolidated, allowing
for more uniform and readable construction of objects, simplifying
code, reducing duplication and (hopefully) avoiding complexity and
unnecessary copying of data.
2023-09-24 18:36:15 -07:00
Nik Bougalis
ce3f0fcc23 Add true partitioning support to TaggedCache:
The primary change introduced in this commit is partitioning of
the `TaggedCache`, with each partition being indepedent of each
other, making it possible to potentially perform multiple cache
operations in parallel. In particular, the `sweep` operation is
now parallelized by default on systems with at least four cores
present.

The `TaggedCache` could also be instantiated in 'key-only' mode
which complicated the interface significantly but was only used
by a single consumer (the `FullBelowCache`). This commit splits
the 'key-only' functionality of `TaggedCache`, and incorporates
directly into `FullBelowCache`, resulting in simple and cleaner
interfaces for both `TaggedCache` and `FullBelowCache` but at a
cost: some code duplication.

Lastly, this commit includes a medley of changes, including the
restructuring of `Transaction`, reducing its size by 48 bytes.
2023-09-24 18:36:15 -07:00
Nik Bougalis
8a7913a996 Harden MITM detection during session establishment:
Even with TLS encrypted connections, it is possible for a determined
attacker to mount certain types of relatively easy man-in-the-middle
attacks which, if successful, could allow an attacker to tamper with
messages exchanged between endpoints.

The risk can be mitigated if each side has a certificate issued by a
CA that the other side trusts. In the context of a decentralized and
permissionless network, this is neither reasonable nor desirable.

To prevent this problem all we need is to allow the two endpoints, A
and B, to be able to independently verify that they are connected to
each other over a single end-to-end TLS session, instead of separate
TLS sessions which the attacker bridges.

The protocol level handshake implements this security check by using
digital signatures: each endpoint derives a fingerprint from the TLS
session, which it signs with the private key associated with its own
node identity. This strongly binds the TLS session to the identities
of the two endpoints of the session.

This commit introduces a new fingerprint derivation that uses modern
and standardized TLS exporter functionality, instead of the existing
derivation whch uses OpenSSL APIs that are non-standard, and derives
different "incoming" and "outgoing" security cookies.

Lastly, this commit refines the "self-connection" check to allow for
the detection of accidental instances of node identity sharing. This
check was first introduced with #4195 but was partially reverted due
to a bug with #4438. By using distinct security cookies for incoming
and outgoing connections, an attacker is no longer able to claim the
identity of its peer by echoing its security cookie.

The change is backwards compatible and servers with this commit will
still generate and verify old-style fingerprints, in addition to the
new style fingerprints.

For a fuller discussion on this topic, please see:
    https://github.com/openssl/openssl/issues/5509
    https://github.com/ripple/rippled/issues/2413

This commit was previously introduced as #3929, which was closed. If
merged, it also fixes #2413 (which had been closed as a 'WONTFIX').
2023-09-24 18:36:15 -07:00
Nik Bougalis
8b2ef17be3 Miscellaneous cleanups in SHAMap-related code 2023-09-24 18:36:15 -07:00
Nik Bougalis
b06bdde3db Avoid using std::shared_ptr when not necessary: (#4218)
The `Ledger` class contains two `SHAMap` instances: the state and
transaction maps. Previously, the maps were dynamically allocated using
`std::make_shared` despite the fact that they did not require lifetime
management separate from the lifetime of the `Ledger` instance to which
they belong.

The two `SHAMap` instances are now regular member variables. Some smart
pointers and dynamic memory allocation was avoided by using stack-based
alternatives.

Commit 3 of 3 in #4218.
2023-09-24 18:36:15 -07:00
Nik Bougalis
e446dab1b9 Improve Slab Allocator & SHAMapItem slabber:
The existing slab allocator has significant performance advantages over
normal dynamic memory allocation codepaths (e.g. via `new` or `malloc`)
but sacrifices the ability to release memory back to the system.

As a result, otherwise transient spikes in memory usage might result in
increased memory usage for the lifetime of the process.

This commit retains the lock-free management of individual slabs, while
also making it possible to reclamation memory from slabs that are empty
and improving the slab selection strategy to favor fuller slabs.

The commit also adjusts the sizes of slabs used to back `SHAMapItem` to
better match the characteristics of the XRP Ledger "mainnet."
2023-09-24 18:36:15 -07:00
Nik Bougalis
b5cb4afa3c Optimize SHAMapItem and leverage new slab allocator: (#4218)
The `SHAMapItem` class contains a variable-sized buffer that
holds the serialized data associated with a particular item
inside a `SHAMap`.

Prior to this commit, the buffer for the serialized data was
allocated separately. Coupled with the fact that most instances
of `SHAMapItem` were wrapped around a `std::shared_ptr` meant
that an instantiation might result in up to three separate
memory allocations.

This commit switches away from `std::shared_ptr` for `SHAMapItem`
and uses `boost::intrusive_ptr` instead, allowing the reference
count for an instance to live inside the instance itself. Coupled
with using a slab-based allocator to optimize memory allocation
for the most commonly sized buffers, the net result is significant
memory savings. In testing, the reduction in memory usage hovers
between 400MB and 650MB. Other scenarios might result in larger
savings.

In performance testing with NFTs, this commit reduces memory size by
about 15% sustained over long duration.

Commit 2 of 3 in #4218.
2023-09-24 18:36:15 -07:00
Nik Bougalis
9b81394698 Introduce support for a slabbed allocator: (#4218)
When instantiating a large amount of fixed-sized objects on the heap
the overhead that dynamic memory allocation APIs impose will quickly
become significant.

In some cases, allocating a large amount of memory at once and using
a slabbing allocator to carve the large block into fixed-sized units
that are used to service requests for memory out will help to reduce
memory fragmentation significantly and, potentially, improve overall
performance.

This commit introduces a new `SlabAllocator<>` class that exposes an
API that is _similar_ to the C++ concept of an `Allocator` but it is
not meant to be a general-purpose allocator.

It should not be used unless profiling and analysis of specific memory
allocation patterns indicates that the additional complexity introduced
will improve the performance of the system overall, and subsequent
profiling proves it.

A helper class, `SlabAllocatorSet<>` simplifies handling of variably
sized objects that benefit from slab allocations.

This commit incorporates improvements suggested by Greg Popovitch
(@greg7mdp).

Commit 1 of 3 in #4218.
2023-09-24 18:36:15 -07:00
Nik Bougalis
08202a071c Refactor LocalTxs 2023-09-24 18:36:15 -07:00
Nik Bougalis
81cc278cab Refactor of InboundTransactions et al:
This refactor was primarily aimed at reducing the size of
objects derived from TimeoutCounter, by improving packing
of structures. Other potential improvements also surfaced
during this process and where implemented.
2023-09-24 18:36:13 -07:00
Chenna Keshava B S
266ce2b755 Protect coroutine construction:
The existing code attempted to restrict the instantiation of `Coro`
only to a subset of helper functions, by using the `Coro_create_t`
helper structure. But the structure was public, which limited the
effectiveness of this method.

This commit uses a private type, fixing the issue.
2023-09-24 18:32:29 -07:00
Nik Bougalis
f57800c645 Refactor the JobQueue infrastructure and improve load tracking:
This commit cleans up and modernizes the JobQueue but does not change
the queueing logic. It focuses on simplifying the code by eliminating
awkward code constructs, like "invalid jobs" and the need for default
constructors.

It leverages modern C++ to initialize tables and data structures at
compile time and replaces `std:map` instances with directly indexed
arrays.

Lastly, it restructures the load tracking infrastructure and reduces
the need for dynamic memory allocations by supporting move semantics
and value types.
2023-09-24 18:32:29 -07:00
Nik Bougalis
3379b4c950 Optimize thread pool implementation:
The existing thread pool code uses several layers of indirection which
uses a custom lock-free stack, and offers functionality that supports
features that are never used (e.g. the ability to dynamically adjust
the number of threads in the pool).

This refactoring aims to simplify the code, making it easier to reason
about (although lock-free multi-threaded code is always tricky) what
is happening, and reduce the latency of the thread pool internals.
2023-09-24 18:32:29 -07:00
Richard Holland
3502e016e9 legacy tests passing 2023-09-24 22:19:47 +00:00
Richard Holland
f9a43f262c more test cases fixes 2023-09-24 20:49:27 +00:00
Richard Holland
dd6e21c38b more unit test fixes 2023-09-24 19:51:04 +00:00
Richard Holland
d7e4ba8254 fix various tests 2023-09-24 18:09:53 +00:00
Richard Holland
18a90ec432 remove debug memos from nftoken test 2023-09-24 12:29:54 +00:00
Richard Holland
25b5b7134d remove (now) incorrect test case for xahaugen 2023-09-24 10:43:12 +00:00
Richard Holland
92e5e08025 allow deletable accounts but make importsequence on accountroot a blocker 2023-09-24 10:16:39 +00:00
Denis Angell
517c7a494b Fix warnings (#108)
* remove unused variable

* rewrite function for transparancy

* unnecessary move

* remove unused variable

* remove unused variables

* fix `nodiscard` warning and ogical-op-parentheses
2023-09-24 11:49:22 +02:00
Richard Holland
2aae0b667c remove XRP_LEDGER_EARLIEST_FEES, return defaultAmendmentTime to 5 days, other fixes 2023-09-24 09:49:09 +00:00
Richard Holland
401a666f4d debug governance tests, all passing 2023-09-23 18:06:21 +00:00
Richard Holland
a6b84caea2 fix reference count on governance hook 2023-09-23 15:38:34 +00:00
Richard Holland
d568761fdf L2 tests done 2023-09-23 12:14:34 +00:00
Denis Angell
3c35024bf9 Update Magic Enum (#103)
* update magic_enum

* update server definitions `magic_enum`

* add server definitions test

* Update ServerInfo.cpp

* Update ServerInfo.cpp
2023-09-23 11:18:45 +02:00
Denis Angell
f4e738ac64 claim reward tests (#105) 2023-09-23 11:17:37 +02:00
Richard Holland
838898e758 more L2 gov 2023-09-23 09:16:39 +00:00
Richard Holland
88ded30810 Merge branch 'dev' of github.com:Xahau/xahaud into dev 2023-09-22 11:42:18 +00:00
Richard Holland
6b8cc6dd9b governance L2 hook tests 2023-09-22 11:42:05 +00:00
Denis Angell
37d3d7dae7 fix failing tests add rpc test (#104) 2023-09-20 10:48:15 +02:00
Richard Holland
d6a0746f99 make mac-specific libraries optional 2023-09-19 12:58:48 +00:00
Denis Angell
aa6d05c8b9 patch m1/llvm14 (#50)
* patch wasm cmake

* patch UNL Report

* patch change

* patch import

* patch invoke

* patch xahau genesis test
2023-09-19 14:41:55 +02:00
Richard Holland
b6b6e0fe5c more l2 governance tests 2023-09-19 12:41:31 +00:00
Richard Holland
28650cb14b inline some enum functions 2023-09-19 11:05:41 +00:00
Richard Holland
0a291371c9 fix levelisation for soci, more L2 governance tests 2023-09-19 10:36:45 +00:00
Denis Angell
ab6d3d505f add uritoken test (#98) 2023-09-19 11:26:49 +02:00
Denis Angell
debf178546 Update Import Tests (#99)
* add fee multiplier

* add warn logs

* add unl sequence json

* add import sequence tests

* Update TER.cpp

* remove issuer xpop

* Update Import_test.cpp

* update max xpop

* update/add max & fee change tests

* fixup issuer/hook test
2023-09-19 11:26:16 +02:00
Denis Angell
89df87dec8 UNL Report tests (#100)
* Update Change.cpp

* add UNLReport Tests

* remove comments
2023-09-19 11:25:41 +02:00
Denis Angell
cfa46934ed Sync extern.h (#101)
* update hook error codes

* reorder and remove unused externs

* add HOOK_STATE_DIR keylet

* Delete types.h

* move transaction types
2023-09-19 11:24:09 +02:00
RichardAH
e7cd845d93 Merge pull request #102 from Xahau/invoke-tests
add invoke tests
2023-09-19 11:23:16 +02:00
Richard Holland
9b089bee94 more layer2 tests 2023-09-19 09:22:28 +00:00
Richard Holland
e15f9244de start L2 table tests 2023-09-18 10:52:10 +00:00
Richard Holland
ab67ddeeb6 modify xahaugenesis to support l2 table setup 2023-09-15 16:16:46 +00:00
Richard Holland
e55820e7c6 all governance L1 tests passing 2023-09-15 12:14:09 +00:00
Richard Holland
4d87210e01 more governance testing 2023-09-15 10:23:57 +00:00
Richard Holland
457c64088b governance L1 hook topic tests 2023-09-14 12:19:43 +00:00
Denis Angell
fb44359988 add invoke tests 2023-09-14 11:00:16 +02:00
Richard Holland
9bcf186aa2 fixes for reward delay 2023-09-13 17:56:56 +00:00