Skip to content

Commit

Permalink
Make code self-documenting by using symbolic constants
Browse files Browse the repository at this point in the history
  • Loading branch information
nbougalis authored and seelabs committed Jul 31, 2017
1 parent 397410b commit 3666948
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 33 deletions.
8 changes: 4 additions & 4 deletions src/ripple/app/tx/impl/Transactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/Indexes.h>
#include <ripple/protocol/types.h>
#include <ripple/protocol/Protocol.h>

namespace ripple {

Expand Down Expand Up @@ -557,12 +558,11 @@ void removeUnfundedOffers (ApplyView& view, std::vector<uint256> const& offers,

for (auto const& index : offers)
{
auto const sleOffer = view.peek (keylet::offer (index));
if (sleOffer)
if (auto const sleOffer = view.peek (keylet::offer (index)))
{
// offer is unfunded
offerDelete (view, sleOffer, viewJ);
if (++removed == 1000)
if (++removed == unfundedOfferRemoveLimit)
return;
}
}
Expand Down Expand Up @@ -648,7 +648,7 @@ Transactor::operator()()
bool didApply = isTesSuccess (terResult);
auto fee = ctx_.tx.getFieldAmount(sfFee).xrp ();

if (ctx_.size() > 5200)
if (ctx_.size() > oversizeMetaDataCap)
terResult = tecOVERSIZE;

if ((terResult == tecOVERSIZE) ||
Expand Down
11 changes: 2 additions & 9 deletions src/ripple/ledger/impl/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <ripple/basics/Log.h>
#include <ripple/basics/StringUtilities.h>
#include <ripple/protocol/st.h>
#include <ripple/protocol/Protocol.h>
#include <ripple/protocol/Quality.h>
#include <boost/algorithm/string.hpp>
#include <cassert>
Expand Down Expand Up @@ -100,14 +101,6 @@ bool fix1449 (NetClock::time_point const closeTime)
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
Expand Down Expand Up @@ -864,7 +857,7 @@ dirAdd (ApplyView& view,

svIndexes = sleNode->getFieldV256 (sfIndexes);

if (DIR_NODE_MAX != svIndexes.size ())
if (dirNodeMaxEntries != svIndexes.size ())
{
// Add to current node.
view.update(sleNode);
Expand Down
35 changes: 19 additions & 16 deletions src/ripple/protocol/Protocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,27 @@ namespace ripple {

/** Protocol specific constants, types, and data.
This information is part of the Ripple protocol. Specifically,
it is required for peers to be able to communicate with each other.
This information is, implicitly, part of the Ripple
protocol.
@note Changing these will create a hard fork.
@ingroup protocol
@defgroup protocol
@note Changing these values without adding code to the
server to detect "pre-change" and "post-change"
will result in a hard fork.
*/
struct Protocol
{
/** Smallest legal byte size of a transaction.
*/
static int const txMinSizeBytes = 32;
/** Smallest legal byte size of a transaction. */
std::size_t constexpr txMinSizeBytes = 32;

/** Largest legal byte size of a transaction. */
std::size_t constexpr txMaxSizeBytes = 1024 * 1024;

/** 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;

/** Largest legal byte size of a transaction.
*/
static int const txMaxSizeBytes = 1024 * 1024; // 1048576
};
/** The maximum number of entries per directory page */
std::size_t constexpr dirNodeMaxEntries = 32;

/** A ledger index. */
using LedgerIndex = std::uint32_t;
Expand All @@ -59,4 +62,4 @@ using TxSeq = std::uint32_t;

} // ripple

#endif
#endif
2 changes: 1 addition & 1 deletion src/ripple/protocol/impl/STTx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ STTx::STTx (SerialIter& sit)
{
int length = sit.getBytesLeft ();

if ((length < Protocol::txMinSizeBytes) || (length > Protocol::txMaxSizeBytes))
if ((length < txMinSizeBytes) || (length > txMaxSizeBytes))
Throw<std::runtime_error> ("Transaction length invalid");

set (sit);
Expand Down
5 changes: 2 additions & 3 deletions src/test/ledger/View_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <ripple/ledger/Sandbox.h>
#include <ripple/core/ConfigSections.h>
#include <ripple/protocol/Feature.h>
#include <ripple/protocol/Protocol.h>
#include <type_traits>

namespace ripple {
Expand Down Expand Up @@ -873,9 +874,7 @@ class DirIsEmpty_test
env.fund(XRP(10000), becky, gw);
env.close();

// The DIR_NODE_MAX constant is hidden in View.cpp (Feb 2016). But,
// ideally, we'd verify we're doing a good test with the following:
// static_assert (64 >= (2 * DIR_NODE_MAX), "");
static_assert (64 >= (2 * dirNodeMaxEntries), "");

// Generate 64 currencies named AAA -> AAP and ADA -> ADP.
std::vector<IOU> currencies;
Expand Down

0 comments on commit 3666948

Please sign in to comment.