Various cleanups:

* Replace SYSTEM_NAME and other macros with C++ constructs
* Remove RIPPLE_ARRAYSIZE and use std::extent or ranged for loops
* Remove old-style, unused offer crossing unit test
* Make STAmount::saFromRate free and remove default argument
This commit is contained in:
Nik Bougalis
2014-12-04 03:16:41 -08:00
parent 8e792855e0
commit 4a49fefdd9
27 changed files with 305 additions and 1152 deletions

View File

@@ -92,7 +92,7 @@ Taker::flow (Amounts amount, Offer const& offer, Account const& taker)
}
else
{
Amount const taker_charge (Amount::saFromRate (taker_charge_rate));
Amount const taker_charge (amountFromRate (taker_charge_rate));
amount = offer.quality ().ceil_in (amount,
divide (taker_funds, taker_charge));
}
@@ -116,7 +116,7 @@ Taker::flow (Amounts amount, Offer const& offer, Account const& taker)
}
else
{
Amount const owner_charge (Amount::saFromRate (owner_charge_rate));
Amount const owner_charge (amountFromRate (owner_charge_rate));
owner_amount = offer.quality ().ceil_out (owner_amount,
divide (owner_funds, owner_charge));
}

View File

@@ -1276,12 +1276,8 @@ STAmount LedgerEntrySet::rippleTransferFee (
if (QUALITY_ONE != uTransitRate)
{
// NIKB use STAmount::saFromRate
STAmount saTransitRate (
noIssue(), static_cast<std::uint64_t> (uTransitRate), -9);
STAmount saTransferTotal = multiply (
saAmount, saTransitRate, saAmount.issue ());
saAmount, amountFromRate (uTransitRate), saAmount.issue ());
STAmount saTransferFee = saTransferTotal - saAmount;
WriteLog (lsDEBUG, LedgerEntrySet) << "rippleTransferFee:" <<

View File

@@ -84,7 +84,7 @@ void startServer ()
void printHelp (const po::options_description& desc)
{
std::cerr
<< SYSTEM_NAME "d [options] <command> <params>\n"
<< systemName () << "d [options] <command> <params>\n"
<< desc << std::endl
<< "Commands: \n"
" account_info <account>|<seed>|<pass_phrase>|<key> [<ledger>] [strict]\n"

View File

@@ -17,9 +17,9 @@
*/
//==============================================================================
#include <ripple/basics/ArraySize.h>
#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
#include <type_traits>
namespace ripple {
@@ -154,8 +154,15 @@ bool ProofOfWork::checkSolution (uint256 const& solution) const
bool ProofOfWork::validateToken (std::string const& strToken)
{
static boost::regex reToken ("[[:xdigit:]]{64}-[[:xdigit:]]{64}-[[:digit:]]+-[[:digit:]]+-[[:xdigit:]]{64}");
boost::smatch smMatch;
static boost::regex const reToken (
"[[:xdigit:]]{64}-"
"[[:xdigit:]]{64}-"
"[[:digit:]]+-"
"[[:digit:]]+-"
"[[:xdigit:]]{64}",
boost::regex_constants::optimize);
boost::smatch smMatch;
return boost::regex_match (strToken, smMatch, reToken);
}
@@ -164,34 +171,35 @@ bool ProofOfWork::validateToken (std::string const& strToken)
bool ProofOfWork::calcResultInfo (PowResult powCode, std::string& strToken, std::string& strHuman)
{
static struct
struct PowResultInfo
{
PowResult powCode;
const char* cpToken;
const char* cpHuman;
} powResultInfoA[] =
{
{ powREUSED, "powREUSED", "Proof-of-work has already been used." },
{ powBADNONCE, "powBADNONCE", "The solution does not meet the required difficulty." },
{ powEXPIRED, "powEXPIRED", "Token is expired." },
{ powCORRUPT, "powCORRUPT", "Invalid token." },
{ powTOOEASY, "powTOOEASY", "Difficulty has increased since token was issued." },
{ powOK, "powOK", "Valid proof-of-work." },
PowResult code;
char const* token;
char const* text;
};
int iIndex = RIPPLE_ARRAYSIZE (powResultInfoA);
while (iIndex-- && powResultInfoA[iIndex].powCode != powCode)
;
if (iIndex >= 0)
static
PowResultInfo const results[] =
{
strToken = powResultInfoA[iIndex].cpToken;
strHuman = powResultInfoA[iIndex].cpHuman;
{ powOK, "powOK", "Valid proof-of-work." },
{ powREUSED, "powREUSED", "Proof-of-work has already been used." },
{ powBADNONCE, "powBADNONCE", "The solution does not meet the required difficulty." },
{ powEXPIRED, "powEXPIRED", "Token is expired." },
{ powCORRUPT, "powCORRUPT", "Invalid token." },
{ powTOOEASY, "powTOOEASY", "Difficulty has increased since token was issued." },
};
for (auto const& result : results)
{
if (powCode == result.code)
{
strToken = result.token;
strHuman = result.text;
return true;
}
}
return iIndex >= 0;
return false;
}
} // ripple

View File

@@ -17,8 +17,8 @@
*/
//==============================================================================
#include <ripple/basics/ArraySize.h>
#include <ripple/app/node/SqliteFactory.h>
#include <type_traits>
namespace ripple {
@@ -44,8 +44,6 @@ static const char* s_nodeStoreDBInit [] =
"END TRANSACTION;"
};
static int s_nodeStoreDBCount = RIPPLE_ARRAYSIZE (s_nodeStoreDBInit);
//------------------------------------------------------------------------------
class SqliteBackend : public NodeStore::Backend
@@ -53,8 +51,8 @@ class SqliteBackend : public NodeStore::Backend
public:
explicit SqliteBackend (std::string const& path, int hashnode_cache_size)
: m_name (path)
, m_db (new DatabaseCon(setup_DatabaseCon (getConfig()),
path, s_nodeStoreDBInit, s_nodeStoreDBCount))
, m_db (new DatabaseCon(setup_DatabaseCon (getConfig()), path,
s_nodeStoreDBInit, std::extent<decltype(s_nodeStoreDBInit)>::value))
{
std::string s ("PRAGMA cache_size=-");
s += std::to_string (hashnode_cache_size);

View File

@@ -230,7 +230,7 @@ TER RippleCalc::rippleCalculate ()
<< "rippleCalc: AFTER:"
<< " mIndex=" << pathState->index()
<< " uQuality=" << pathState->quality()
<< " rate=" << STAmount::saFromRate (pathState->quality());
<< " rate=" << amountFromRate (pathState->quality());
if (!pathState->quality())
{
@@ -257,7 +257,7 @@ TER RippleCalc::rippleCalculate ()
lsDEBUG, RippleCalc)
<< "rippleCalc: better:"
<< " uQuality="
<< STAmount::saFromRate (pathState->quality())
<< amountFromRate (pathState->quality())
<< " inPass()=" << pathState->inPass()
<< " saOutPass=" << pathState->outPass();
@@ -278,7 +278,7 @@ TER RippleCalc::rippleCalculate ()
<< " mIndex=" << pathState->index()
<< " uQuality=" << pathState->quality()
<< " rate="
<< STAmount::saFromRate (pathState->quality())
<< amountFromRate (pathState->quality())
<< " inPass()=" << pathState->inPass()
<< " saOutPass=" << pathState->outPass();
@@ -306,7 +306,7 @@ TER RippleCalc::rippleCalculate ()
<< "rippleCalc: "
<< "Summary: " << pathState->index()
<< " rate: "
<< STAmount::saFromRate (pathState->quality())
<< amountFromRate (pathState->quality())
<< " quality:" << pathState->quality()
<< " best: " << (iBest == pathState->index ());
}
@@ -320,7 +320,7 @@ TER RippleCalc::rippleCalculate ()
WriteLog (lsDEBUG, RippleCalc)
<< "rippleCalc: best:"
<< " uQuality="
<< STAmount::saFromRate (pathState->quality())
<< amountFromRate (pathState->quality())
<< " inPass()=" << pathState->inPass()
<< " saOutPass=" << pathState->outPass();

View File

@@ -52,7 +52,7 @@ TER PathCursor::reverseLiquidity () const
// a fee when third parties transfer that account's own issuances.
// node.transferRate_ caches the output transfer rate for this node.
node().transferRate_ = STAmount::saFromRate (
node().transferRate_ = amountFromRate (
rippleTransferRate (ledger(), node().issue_.account));
if (node().isAccount ())

View File

@@ -205,7 +205,7 @@ TER PathCursor::reverseLiquidityForAccount () const
<< " (available) previousNode.saRevRedeem="
<< previousNode().saRevRedeem
<< " uRateMax="
<< STAmount::saFromRate (uRateMax).getText ();
<< amountFromRate (uRateMax).getText ();
}
else
{

View File

@@ -39,8 +39,6 @@ namespace ripple {
#define NODE_FETCH_JOBS 10
#define NODE_FETCH_SECONDS 10
#define NODE_FILE_BYTES_MAX (50<<10) // 50k
#define NODE_FILE_NAME SYSTEM_NAME ".txt"
#define NODE_FILE_PATH "/" NODE_FILE_NAME
// Wait for validation information to be stable before scoring.
// #define SCORE_DELAY_SECONDS 20
@@ -118,6 +116,8 @@ public:
, mFetchActive (0)
, m_fetchTimer (this)
{
node_file_name_ = std::string (systemName ()) + ".txt";
node_file_path_ = "/" + node_file_name_;
}
//--------------------------------------------------------------------------
@@ -1161,19 +1161,19 @@ private:
if (!bReject)
{
IniFileSections secSite = parseIniFile (strSiteFile, true);
bool bGood = !err;
IniFileSections secSite = parseIniFile (strSiteFile, true);
bool bGood = !err;
if (bGood)
{
WriteLog (lsTRACE, UniqueNodeList) << boost::format ("Validator: '%s' received " NODE_FILE_NAME ".") % strDomain;
WriteLog (lsTRACE, UniqueNodeList) << strDomain
<< ": retrieved configuration";
}
else
{
WriteLog (lsTRACE, UniqueNodeList)
<< boost::format ("Validator: '%s' unable to retrieve " NODE_FILE_NAME ": %s")
% strDomain
% err.message ();
WriteLog (lsTRACE, UniqueNodeList) << strDomain
<< ": unable to retrieve configuration: "
<< err.message ();
}
//
@@ -1185,19 +1185,17 @@ private:
{
bGood = false;
WriteLog (lsTRACE, UniqueNodeList)
<< boost::format ("Validator: '%s' bad " NODE_FILE_NAME " missing single entry for " SECTION_DOMAIN ".")
% strDomain;
WriteLog (lsTRACE, UniqueNodeList) << strDomain
<< ": " << SECTION_DOMAIN
<< "entry missing.";
}
if (bGood && strSite != strDomain)
{
bGood = false;
WriteLog (lsTRACE, UniqueNodeList)
<< boost::format ("Validator: '%s' bad " NODE_FILE_NAME " " SECTION_DOMAIN " does not match: %s")
% strDomain
% strSite;
WriteLog (lsTRACE, UniqueNodeList) << strDomain
<< ": " << SECTION_DOMAIN << " does not match " << strSite;
}
//
@@ -1210,9 +1208,8 @@ private:
// Bad [validation_public_key] IniFileSections.
bGood = false;
WriteLog (lsTRACE, UniqueNodeList)
<< boost::format ("Validator: '%s' bad " NODE_FILE_NAME " " SECTION_PUBLIC_KEY " does not have single entry.")
% strDomain;
WriteLog (lsTRACE, UniqueNodeList) << strDomain
<< ": " << SECTION_PUBLIC_KEY << " entry missing.";
}
RippleAddress naNodePublic;
@@ -1222,16 +1219,13 @@ private:
// Bad public key.
bGood = false;
WriteLog (lsTRACE, UniqueNodeList)
<< boost::format ("Validator: '%s' bad " NODE_FILE_NAME " " SECTION_PUBLIC_KEY " is bad: ")
% strDomain
% strNodePublicKey;
WriteLog (lsTRACE, UniqueNodeList) << strDomain
<< ": " << SECTION_PUBLIC_KEY << " is not a public key: "
<< strNodePublicKey;
}
if (bGood)
{
// WriteLog (lsTRACE, UniqueNodeList) << boost::format("naNodePublic: '%s'") % naNodePublic.humanNodePublic();
seedDomain sdCurrent;
bool bFound = getSeedDomains (strDomain, sdCurrent);
@@ -1255,12 +1249,14 @@ private:
if (bChangedB)
{
WriteLog (lsTRACE, UniqueNodeList) << boost::format ("Validator: '%s' processing new " NODE_FILE_NAME ".") % strDomain;
WriteLog (lsTRACE, UniqueNodeList) << strDomain
<< ": processing new " << node_file_name_ << ".";
processFile (strDomain, naNodePublic, secSite);
}
else
{
WriteLog (lsTRACE, UniqueNodeList) << boost::format ("Validator: '%s' no change for " NODE_FILE_NAME ".") % strDomain;
WriteLog (lsTRACE, UniqueNodeList) << strDomain
<< ": no change in " << node_file_name_ << ".";
fetchFinish ();
}
}
@@ -1361,7 +1357,8 @@ private:
setSeedDomains (sdCurrent, false);
WriteLog (lsTRACE, UniqueNodeList) << "Validator: '" << strDomain << "' fetching " NODE_FILE_NAME ".";
WriteLog (lsTRACE, UniqueNodeList) << strDomain
<< " fetching " << node_file_name_ << ".";
fetchProcess (strDomain); // Go get it.
@@ -1401,14 +1398,15 @@ private:
// Get the ripple.txt and process it.
void fetchProcess (std::string strDomain)
{
WriteLog (lsTRACE, UniqueNodeList) << "Fetching '" NODE_FILE_NAME "' from '" << strDomain << "'.";
WriteLog (lsTRACE, UniqueNodeList) << strDomain
<< ": fetching " << node_file_name_ << ".";
std::deque<std::string> deqSites;
// Order searching from most specifically for purpose to generic.
// This order allows the client to take the most burden rather than the servers.
deqSites.push_back (str (boost::format (SYSTEM_NAME ".%s") % strDomain));
deqSites.push_back (str (boost::format ("www.%s") % strDomain));
deqSites.push_back (systemName () + strDomain);
deqSites.push_back ("www." + strDomain);
deqSites.push_back (strDomain);
HTTPClient::get (
@@ -1416,7 +1414,7 @@ private:
getApp().getIOService (),
deqSites,
443,
NODE_FILE_PATH,
node_file_path_,
NODE_FILE_BYTES_MAX,
boost::posix_time::seconds (NODE_FETCH_SECONDS),
std::bind (&UniqueNodeListImp::responseFetch, this, strDomain,
@@ -1734,7 +1732,8 @@ private:
//
// Process Validators
//
processValidators (strDomain, NODE_FILE_NAME, naNodePublic, vsReferral, getIniFileSection (secSite, SECTION_VALIDATORS));
processValidators (strDomain, node_file_name_, naNodePublic,
vsReferral, getIniFileSection (secSite, SECTION_VALIDATORS));
//
// Process ips
@@ -2047,6 +2046,9 @@ private:
beast::DeadlineTimer m_fetchTimer; // Timer to start fetching.
std::map<RippleAddress, ClusterNodeStatus> m_clusterNodes;
std::string node_file_name_;
std::string node_file_path_;
};
//------------------------------------------------------------------------------

View File

@@ -461,10 +461,9 @@ public:
}
cpClient->set_body (
"<!DOCTYPE html><html><head><title>" SYSTEM_NAME " Test</title>"
"</head><body><h1>" SYSTEM_NAME " Test</h1>"
"<p>This page shows that http(s) connectivity is working."
"</p></body></html>");
"<!DOCTYPE html><html><head><title>" + systemName () +
" Test</title></head>" + "<body><h1>" + systemName () +
" Test</h1><p>This page shows http(s) connectivity is working.</p></body></html>");
return true;
}
};