Make code self-documenting by using symbolic constants

This commit is contained in:
Nik Bougalis
2017-04-13 11:31:38 -07:00
committed by seelabs
parent 397410bac6
commit 3666948610
5 changed files with 28 additions and 33 deletions

View File

@@ -31,6 +31,7 @@
#include <ripple/protocol/Feature.h> #include <ripple/protocol/Feature.h>
#include <ripple/protocol/Indexes.h> #include <ripple/protocol/Indexes.h>
#include <ripple/protocol/types.h> #include <ripple/protocol/types.h>
#include <ripple/protocol/Protocol.h>
namespace ripple { namespace ripple {
@@ -557,12 +558,11 @@ void removeUnfundedOffers (ApplyView& view, std::vector<uint256> const& offers,
for (auto const& index : offers) for (auto const& index : offers)
{ {
auto const sleOffer = view.peek (keylet::offer (index)); if (auto const sleOffer = view.peek (keylet::offer (index)))
if (sleOffer)
{ {
// offer is unfunded // offer is unfunded
offerDelete (view, sleOffer, viewJ); offerDelete (view, sleOffer, viewJ);
if (++removed == 1000) if (++removed == unfundedOfferRemoveLimit)
return; return;
} }
} }
@@ -648,7 +648,7 @@ Transactor::operator()()
bool didApply = isTesSuccess (terResult); bool didApply = isTesSuccess (terResult);
auto fee = ctx_.tx.getFieldAmount(sfFee).xrp (); auto fee = ctx_.tx.getFieldAmount(sfFee).xrp ();
if (ctx_.size() > 5200) if (ctx_.size() > oversizeMetaDataCap)
terResult = tecOVERSIZE; terResult = tecOVERSIZE;
if ((terResult == tecOVERSIZE) || if ((terResult == tecOVERSIZE) ||

View File

@@ -25,6 +25,7 @@
#include <ripple/basics/Log.h> #include <ripple/basics/Log.h>
#include <ripple/basics/StringUtilities.h> #include <ripple/basics/StringUtilities.h>
#include <ripple/protocol/st.h> #include <ripple/protocol/st.h>
#include <ripple/protocol/Protocol.h>
#include <ripple/protocol/Quality.h> #include <ripple/protocol/Quality.h>
#include <boost/algorithm/string.hpp> #include <boost/algorithm/string.hpp>
#include <cassert> #include <cassert>
@@ -100,14 +101,6 @@ bool fix1449 (NetClock::time_point const closeTime)
return closeTime > fix1449Time(); return closeTime > fix1449Time();
} }
// VFALCO NOTE A copy of the other one for now
/** Maximum number of entries in a directory page
A change would be protocol-breaking.
*/
#ifndef DIR_NODE_MAX
#define DIR_NODE_MAX 32
#endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// //
// Observers // Observers
@@ -864,7 +857,7 @@ dirAdd (ApplyView& view,
svIndexes = sleNode->getFieldV256 (sfIndexes); svIndexes = sleNode->getFieldV256 (sfIndexes);
if (DIR_NODE_MAX != svIndexes.size ()) if (dirNodeMaxEntries != svIndexes.size ())
{ {
// Add to current node. // Add to current node.
view.update(sleNode); view.update(sleNode);

View File

@@ -27,24 +27,27 @@ namespace ripple {
/** Protocol specific constants, types, and data. /** Protocol specific constants, types, and data.
This information is part of the Ripple protocol. Specifically, This information is, implicitly, part of the Ripple
it is required for peers to be able to communicate with each other. protocol.
@note Changing these will create a hard fork. @note Changing these values without adding code to the
server to detect "pre-change" and "post-change"
@ingroup protocol will result in a hard fork.
@defgroup protocol
*/ */
struct Protocol /** Smallest legal byte size of a transaction. */
{ std::size_t constexpr txMinSizeBytes = 32;
/** Smallest legal byte size of a transaction.
*/
static int const txMinSizeBytes = 32;
/** Largest legal byte size of a transaction. /** Largest legal byte size of a transaction. */
*/ std::size_t constexpr txMaxSizeBytes = 1024 * 1024;
static int const txMaxSizeBytes = 1024 * 1024; // 1048576
}; /** The maximum number of unfunded offers to delete at once */
std::size_t constexpr unfundedOfferRemoveLimit = 1000;
/** The maximum number of metadata entries allowed in one transaction */
std::size_t constexpr oversizeMetaDataCap = 5200;
/** The maximum number of entries per directory page */
std::size_t constexpr dirNodeMaxEntries = 32;
/** A ledger index. */ /** A ledger index. */
using LedgerIndex = std::uint32_t; using LedgerIndex = std::uint32_t;

View File

@@ -72,7 +72,7 @@ STTx::STTx (SerialIter& sit)
{ {
int length = sit.getBytesLeft (); int length = sit.getBytesLeft ();
if ((length < Protocol::txMinSizeBytes) || (length > Protocol::txMaxSizeBytes)) if ((length < txMinSizeBytes) || (length > txMaxSizeBytes))
Throw<std::runtime_error> ("Transaction length invalid"); Throw<std::runtime_error> ("Transaction length invalid");
set (sit); set (sit);

View File

@@ -26,6 +26,7 @@
#include <ripple/ledger/Sandbox.h> #include <ripple/ledger/Sandbox.h>
#include <ripple/core/ConfigSections.h> #include <ripple/core/ConfigSections.h>
#include <ripple/protocol/Feature.h> #include <ripple/protocol/Feature.h>
#include <ripple/protocol/Protocol.h>
#include <type_traits> #include <type_traits>
namespace ripple { namespace ripple {
@@ -873,9 +874,7 @@ class DirIsEmpty_test
env.fund(XRP(10000), becky, gw); env.fund(XRP(10000), becky, gw);
env.close(); env.close();
// The DIR_NODE_MAX constant is hidden in View.cpp (Feb 2016). But, static_assert (64 >= (2 * dirNodeMaxEntries), "");
// ideally, we'd verify we're doing a good test with the following:
// static_assert (64 >= (2 * DIR_NODE_MAX), "");
// Generate 64 currencies named AAA -> AAP and ADA -> ADP. // Generate 64 currencies named AAA -> AAP and ADA -> ADP.
std::vector<IOU> currencies; std::vector<IOU> currencies;