Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into ximinez/db-lock
Browse files Browse the repository at this point in the history
* upstream/develop:
  fix: Replace charge() by fee_.update() in OnMessage functions (5269)
  docs: ensure build_type and CMAKE_BUILD_TYPE match (5274)
  • Loading branch information
ximinez committed Feb 13, 2025
2 parents ba94c0e + 97e3dae commit a38d43d
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 27 deletions.
34 changes: 28 additions & 6 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,15 @@ It fixes some source files to add missing `#include`s.
the `install-folder` or `-if` option to every `conan install` command
in the next step.

2. Generate CMake files for every configuration you want to build.
2. Use conan to generate CMake files for every configuration you want to build:

```
conan install .. --output-folder . --build missing --settings build_type=Release
conan install .. --output-folder . --build missing --settings build_type=Debug
```
To build Debug, in the next step, be sure to set `-DCMAKE_BUILD_TYPE=Debug`
For a single-configuration generator, e.g. `Unix Makefiles` or `Ninja`,
you only need to run this command once.
For a multi-configuration generator, e.g. `Visual Studio`, you may want to
Expand Down Expand Up @@ -258,13 +260,16 @@ It fixes some source files to add missing `#include`s.
Single-config generators:
Pass the CMake variable [`CMAKE_BUILD_TYPE`][build_type]
and make sure it matches the one of the `build_type` settings
you chose in the previous step.
For example, to build Debug, in the next command, replace "Release" with "Debug"
```
cmake -DCMAKE_TOOLCHAIN_FILE:FILEPATH=build/generators/conan_toolchain.cmake -DCMAKE_BUILD_TYPE=Release -Dxrpld=ON -Dtests=ON ..
```
Pass the CMake variable [`CMAKE_BUILD_TYPE`][build_type]
and make sure it matches the `build_type` setting you chose in the previous
step.
Multi-config generators:
Expand All @@ -274,7 +279,7 @@ It fixes some source files to add missing `#include`s.
**Note:** You can pass build options for `rippled` in this step.
4. Build `rippled`.
5. Build `rippled`.
For a single-configuration generator, it will build whatever configuration
you passed for `CMAKE_BUILD_TYPE`. For a multi-configuration generator,
Expand All @@ -293,7 +298,7 @@ It fixes some source files to add missing `#include`s.
cmake --build . --config Debug
```
5. Test rippled.
6. Test rippled.
Single-config generators:
Expand Down Expand Up @@ -403,6 +408,23 @@ After any updates or changes to dependencies, you may need to do the following:
4. Re-run [conan install](#build-and-test).
### 'protobuf/port_def.inc' file not found
If `cmake --build .` results in an error due to a missing a protobuf file, then you might have generated CMake files for a different `build_type` than the `CMAKE_BUILD_TYPE` you passed to conan.
```
/rippled/.build/pb-xrpl.libpb/xrpl/proto/ripple.pb.h:10:10: fatal error: 'google/protobuf/port_def.inc' file not found
10 | #include <google/protobuf/port_def.inc>
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
```
For example, if you want to build Debug:
1. For conan install, pass `--settings build_type=Debug`
2. For cmake, pass `-DCMAKE_BUILD_TYPE=Debug`
### no std::result_of
If your compiler version is recent enough to have removed `std::result_of` as
Expand Down
3 changes: 3 additions & 0 deletions include/xrpl/resource/Charge.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class Charge
std::strong_ordering
operator<=>(Charge const&) const;

Charge
operator*(value_type m) const;

private:
value_type m_cost;
std::string m_label;
Expand Down
6 changes: 6 additions & 0 deletions src/libxrpl/resource/Charge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,11 @@ Charge::operator<=>(Charge const& c) const
return m_cost <=> c.m_cost;
}

Charge
Charge::operator*(value_type m) const
{
return Charge(m_cost * m, m_label);
}

} // namespace Resource
} // namespace ripple
53 changes: 32 additions & 21 deletions src/xrpld/overlay/detail/PeerImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,11 @@
#include <xrpld/overlay/Cluster.h>
#include <xrpld/overlay/detail/PeerImp.h>
#include <xrpld/overlay/detail/Tuning.h>
#include <xrpld/overlay/predicates.h>
#include <xrpld/perflog/PerfLog.h>
#include <xrpl/basics/UptimeClock.h>
#include <xrpl/basics/base64.h>
#include <xrpl/basics/random.h>
#include <xrpl/basics/safe_cast.h>
#include <xrpl/beast/core/LexicalCast.h>
// #include <xrpl/beast/core/SemanticVersion.h>
#include <xrpl/protocol/digest.h>

#include <boost/algorithm/string/predicate.hpp>
Expand Down Expand Up @@ -1111,7 +1108,7 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMCluster> const& m)
// VFALCO NOTE I think we should drop the peer immediately
if (!cluster())
{
fee_.fee = Resource::feeUselessData;
fee_.update(Resource::feeUselessData, "unknown cluster");
return;
}

Expand Down Expand Up @@ -1189,13 +1186,14 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMEndpoints> const& m)
// implication for the protocol.
if (m->endpoints_v2().size() >= 1024)
{
charge(Resource::feeInvalidData, "endpoints too large");
fee_.update(Resource::feeUselessData, "endpoints too large");
return;
}

std::vector<PeerFinder::Endpoint> endpoints;
endpoints.reserve(m->endpoints_v2().size());

auto malformed = 0;
for (auto const& tm : m->endpoints_v2())
{
auto result = beast::IP::Endpoint::from_string_checked(tm.endpoint());
Expand All @@ -1204,7 +1202,7 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMEndpoints> const& m)
{
JLOG(p_journal_.error()) << "failed to parse incoming endpoint: {"
<< tm.endpoint() << "}";
charge(Resource::feeInvalidData, "endpoints malformed");
malformed++;
continue;
}

Expand All @@ -1220,6 +1218,15 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMEndpoints> const& m)
endpoints.emplace_back(*result, tm.hops());
}

// Charge the peer for each malformed endpoint. As there still may be
// multiple valid endpoints we don't return early.
if (malformed > 0)
{
fee_.update(
Resource::feeInvalidData * malformed,
std::to_string(malformed) + " malformed endpoints");
}

if (!endpoints.empty())
overlay_.peerFinder().on_endpoints(slot_, endpoints);
}
Expand Down Expand Up @@ -1340,7 +1347,7 @@ void
PeerImp::onMessage(std::shared_ptr<protocol::TMGetLedger> const& m)
{
auto badData = [&](std::string const& msg) {
charge(Resource::feeInvalidData, "get_ledger " + msg);
fee_.update(Resource::feeInvalidData, "get_ledger " + msg);
JLOG(p_journal_.warn()) << "TMGetLedger: " << msg;
};
auto const itype{m->itype()};
Expand Down Expand Up @@ -1431,7 +1438,8 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMProofPathRequest> const& m)
JLOG(p_journal_.trace()) << "onMessage, TMProofPathRequest";
if (!ledgerReplayEnabled_)
{
charge(Resource::feeMalformedRequest, "proof_path_request disabled");
fee_.update(
Resource::feeMalformedRequest, "proof_path_request disabled");
return;
}

Expand Down Expand Up @@ -1468,13 +1476,14 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMProofPathResponse> const& m)
{
if (!ledgerReplayEnabled_)
{
charge(Resource::feeMalformedRequest, "proof_path_response disabled");
fee_.update(
Resource::feeMalformedRequest, "proof_path_response disabled");
return;
}

if (!ledgerReplayMsgHandler_.processProofPathResponse(m))
{
charge(Resource::feeInvalidData, "proof_path_response");
fee_.update(Resource::feeInvalidData, "proof_path_response");
}
}

Expand All @@ -1484,7 +1493,8 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMReplayDeltaRequest> const& m)
JLOG(p_journal_.trace()) << "onMessage, TMReplayDeltaRequest";
if (!ledgerReplayEnabled_)
{
charge(Resource::feeMalformedRequest, "replay_delta_request disabled");
fee_.update(
Resource::feeMalformedRequest, "replay_delta_request disabled");
return;
}

Expand Down Expand Up @@ -1521,13 +1531,14 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMReplayDeltaResponse> const& m)
{
if (!ledgerReplayEnabled_)
{
charge(Resource::feeMalformedRequest, "replay_delta_response disabled");
fee_.update(
Resource::feeMalformedRequest, "replay_delta_response disabled");
return;
}

if (!ledgerReplayMsgHandler_.processReplayDeltaResponse(m))
{
charge(Resource::feeInvalidData, "replay_delta_response");
fee_.update(Resource::feeInvalidData, "replay_delta_response");
}
}

Expand Down Expand Up @@ -2408,10 +2419,6 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMGetObjectByHash> const& m)
return;
}

fee_.update(
Resource::feeModerateBurdenPeer,
" received a get object by hash request");

protocol::TMGetObjectByHash reply;

reply.set_query(false);
Expand All @@ -2432,6 +2439,10 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMGetObjectByHash> const& m)
reply.set_ledgerhash(packet.ledgerhash());
}

fee_.update(
Resource::feeModerateBurdenPeer,
" received a get object by hash request");

// This is a very minimal implementation
for (int i = 0; i < packet.objects_size(); ++i)
{
Expand Down Expand Up @@ -2628,22 +2639,22 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMSquelch> const& m)

if (!m->has_validatorpubkey())
{
charge(Resource::feeInvalidData, "squelch no pubkey");
fee_.update(Resource::feeInvalidData, "squelch no pubkey");
return;
}
auto validator = m->validatorpubkey();
auto const slice{makeSlice(validator)};
if (!publicKeyType(slice))
{
charge(Resource::feeInvalidData, "squelch bad pubkey");
fee_.update(Resource::feeInvalidData, "squelch bad pubkey");
return;
}
PublicKey key(slice);

// Ignore non-validator squelch
if (!app_.validators().listed(key))
{
charge(Resource::feeInvalidData, "squelch non-validator");
fee_.update(Resource::feeInvalidData, "squelch non-validator");
JLOG(p_journal_.debug())
<< "onMessage: TMSquelch discarding non-validator squelch "
<< slice;
Expand All @@ -2663,7 +2674,7 @@ PeerImp::onMessage(std::shared_ptr<protocol::TMSquelch> const& m)
if (!m->squelch())
squelch_.removeSquelch(key);
else if (!squelch_.addSquelch(key, std::chrono::seconds{duration}))
charge(Resource::feeInvalidData, "squelch duration");
fee_.update(Resource::feeInvalidData, "squelch duration");

JLOG(p_journal_.debug())
<< "onMessage: TMSquelch " << slice << " " << id() << " " << duration;
Expand Down

0 comments on commit a38d43d

Please sign in to comment.