diff --git a/Builds/VisualStudio2012/RippleD.vcxproj b/Builds/VisualStudio2012/RippleD.vcxproj
index f794f0c472..f17341af53 100644
--- a/Builds/VisualStudio2012/RippleD.vcxproj
+++ b/Builds/VisualStudio2012/RippleD.vcxproj
@@ -253,13 +253,13 @@
true
true
-
+
true
true
true
true
-
+
true
true
true
@@ -1381,6 +1381,7 @@
+
@@ -1388,13 +1389,12 @@
-
+
-
-
+
diff --git a/Builds/VisualStudio2012/RippleD.vcxproj.filters b/Builds/VisualStudio2012/RippleD.vcxproj.filters
index 1640566f54..980a8db39e 100644
--- a/Builds/VisualStudio2012/RippleD.vcxproj.filters
+++ b/Builds/VisualStudio2012/RippleD.vcxproj.filters
@@ -648,12 +648,6 @@
[1] Ripple\ripple_app\misc
-
- [1] Ripple\ripple_app\misc
-
-
- [1] Ripple\ripple_app\misc
-
[1] Ripple\ripple_app\misc
@@ -873,6 +867,12 @@
[1] Ripple\ripple_net\rpc
+
+ [1] Ripple\ripple_app\misc
+
+
+ [1] Ripple\ripple_app\misc
+
@@ -1409,9 +1409,6 @@
[1] Ripple\ripple_app\misc
-
- [1] Ripple\ripple_app\misc
-
[1] Ripple\ripple_app\misc
@@ -1424,12 +1421,6 @@
[1] Ripple\ripple_app\misc
-
- [1] Ripple\ripple_app\misc
-
-
- [1] Ripple\ripple_app\misc
-
[1] Ripple\ripple_app\misc
@@ -1694,6 +1685,15 @@
[1] Ripple\ripple_net\basics\impl
+
+ [1] Ripple\ripple_app\misc
+
+
+ [1] Ripple\ripple_app\misc
+
+
+ [1] Ripple\ripple_app\misc
+
diff --git a/modules/ripple_app/main/ripple_Application.cpp b/modules/ripple_app/main/ripple_Application.cpp
index b871a97c5e..ba1ba3938d 100644
--- a/modules/ripple_app/main/ripple_Application.cpp
+++ b/modules/ripple_app/main/ripple_Application.cpp
@@ -174,7 +174,7 @@ public:
, mHashRouter (IHashRouter::New (IHashRouter::getDefaultHoldTime ()))
, mValidations (IValidations::New ())
, mUNL (UniqueNodeList::New ())
- , mProofOfWorkFactory (IProofOfWorkFactory::New ())
+ , mProofOfWorkFactory (ProofOfWorkFactory::New ())
, m_loadManager (LoadManager::New ())
// VFALCO End new stuff
// VFALCO TODO replace all NULL with nullptr
@@ -322,7 +322,7 @@ public:
return *mUNL;
}
- IProofOfWorkFactory& getProofOfWorkFactory ()
+ ProofOfWorkFactory& getProofOfWorkFactory ()
{
return *mProofOfWorkFactory;
}
@@ -698,7 +698,7 @@ private:
ScopedPointer mHashRouter;
ScopedPointer mValidations;
ScopedPointer mUNL;
- ScopedPointer mProofOfWorkFactory;
+ ScopedPointer mProofOfWorkFactory;
ScopedPointer m_peers;
ScopedPointer m_loadManager;
ScopedPointer m_peerDoor;
diff --git a/modules/ripple_app/main/ripple_Application.h b/modules/ripple_app/main/ripple_Application.h
index 394c18d5bd..9fe16d3096 100644
--- a/modules/ripple_app/main/ripple_Application.h
+++ b/modules/ripple_app/main/ripple_Application.h
@@ -13,7 +13,6 @@ class IFeeVote;
class IHashRouter;
class ILoadFeeTrack;
class Peers;
-class IProofOfWorkFactory;
class UniqueNodeList;
class IValidations;
class Validators;
@@ -25,6 +24,7 @@ class LedgerMaster;
class LoadManager;
class NetworkOPs;
class OrderBookDB;
+class ProofOfWorkFactory;
class SerializedLedgerEntry;
class TransactionMaster;
class TXQueue;
@@ -82,9 +82,9 @@ public:
virtual IFeeVote& getFeeVote () = 0;
virtual IHashRouter& getHashRouter () = 0;
virtual ILoadFeeTrack& getFeeTrack () = 0;
- virtual LoadManager& getLoadManager () = 0;
- virtual Peers& getPeers () = 0;
- virtual IProofOfWorkFactory& getProofOfWorkFactory () = 0;
+ virtual LoadManager& getLoadManager () = 0;
+ virtual Peers& getPeers () = 0;
+ virtual ProofOfWorkFactory& getProofOfWorkFactory () = 0;
virtual UniqueNodeList& getUNL () = 0;
virtual IValidations& getValidations () = 0;
diff --git a/modules/ripple_app/misc/PowResult.h b/modules/ripple_app/misc/PowResult.h
new file mode 100644
index 0000000000..d71942b50f
--- /dev/null
+++ b/modules/ripple_app/misc/PowResult.h
@@ -0,0 +1,20 @@
+//------------------------------------------------------------------------------
+/*
+ Copyright (c) 2011-2013, OpenCoin, Inc.
+*/
+//==============================================================================
+
+#ifndef RIPPLE_POWRESULT_H_INCLUDED
+#define RIPPLE_POWRESULT_H_INCLUDED
+
+enum PowResult
+{
+ powOK = 0,
+ powREUSED = 1, // already submitted
+ powBADNONCE = 2, // you didn't solve it
+ powEXPIRED = 3, // time is up
+ powCORRUPT = 4,
+ powTOOEASY = 5, // the difficulty increased too much while you solved it
+};
+
+#endif
diff --git a/modules/ripple_app/misc/ripple_ProofOfWork.cpp b/modules/ripple_app/misc/ProofOfWork.cpp
similarity index 90%
rename from modules/ripple_app/misc/ripple_ProofOfWork.cpp
rename to modules/ripple_app/misc/ProofOfWork.cpp
index d80dc395a0..748d4eef2e 100644
--- a/modules/ripple_app/misc/ripple_ProofOfWork.cpp
+++ b/modules/ripple_app/misc/ProofOfWork.cpp
@@ -6,42 +6,8 @@
SETUP_LOG (ProofOfWork)
-bool powResultInfo (POWResult powCode, std::string& strToken, std::string& strHuman)
-{
- static struct
- {
- 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." },
- };
-
- int iIndex = NUMBER (powResultInfoA);
-
- while (iIndex-- && powResultInfoA[iIndex].powCode != powCode)
- ;
-
- if (iIndex >= 0)
- {
- strToken = powResultInfoA[iIndex].cpToken;
- strHuman = powResultInfoA[iIndex].cpHuman;
- }
-
- return iIndex >= 0;
-}
-
-// VFALCO TODO Move these to a header because they are used by ripple_ProofOfWorkFactory.cpp
+// VFALCO TODO Move these to a header
const uint256 ProofOfWork::sMinTarget ("00000000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF");
-const int ProofOfWork::sMaxIterations (1 << 23);
-const int ProofOfWork::sMaxDifficulty (30);
ProofOfWork::ProofOfWork (const std::string& token,
int iterations,
@@ -70,7 +36,7 @@ ProofOfWork::ProofOfWork (const std::string& token)
bool ProofOfWork::isValid () const
{
- if ((mIterations <= sMaxIterations) && (mTarget >= sMinTarget))
+ if ((mIterations <= kMaxIterations) && (mTarget >= sMinTarget))
return true;
WriteLog (lsWARNING, ProofOfWork) << "Invalid PoW: " << mIterations << ", " << mTarget;
@@ -80,10 +46,10 @@ bool ProofOfWork::isValid () const
uint64 ProofOfWork::getDifficulty (uint256 const& target, int iterations)
{
// calculate the approximate number of hashes required to solve this proof of work
- if ((iterations > sMaxIterations) || (target < sMinTarget))
+ if ((iterations > kMaxIterations) || (target < sMinTarget))
{
WriteLog (lsINFO, ProofOfWork) << "Iterations:" << iterations;
- WriteLog (lsINFO, ProofOfWork) << "MaxIterat: " << sMaxIterations;
+ WriteLog (lsINFO, ProofOfWork) << "MaxIterat: " << kMaxIterations;
WriteLog (lsINFO, ProofOfWork) << "Target: " << target;
WriteLog (lsINFO, ProofOfWork) << "MinTarget: " << sMinTarget;
throw std::runtime_error ("invalid proof of work target/iteration");
@@ -149,7 +115,7 @@ uint256 ProofOfWork::solve (int maxIterations) const
bool ProofOfWork::checkSolution (uint256 const& solution) const
{
- if (mIterations > sMaxIterations)
+ if (mIterations > kMaxIterations)
return false;
std::vector buf1;
@@ -179,3 +145,35 @@ bool ProofOfWork::validateToken (const std::string& strToken)
//------------------------------------------------------------------------------
+bool ProofOfWork::calcResultInfo (PowResult powCode, std::string& strToken, std::string& strHuman)
+{
+ static struct
+ {
+ 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." },
+ };
+
+ int iIndex = NUMBER (powResultInfoA);
+
+ while (iIndex-- && powResultInfoA[iIndex].powCode != powCode)
+ ;
+
+ if (iIndex >= 0)
+ {
+ strToken = powResultInfoA[iIndex].cpToken;
+ strHuman = powResultInfoA[iIndex].cpHuman;
+ }
+
+ return iIndex >= 0;
+}
+
diff --git a/modules/ripple_app/misc/ripple_ProofOfWork.h b/modules/ripple_app/misc/ProofOfWork.h
similarity index 83%
rename from modules/ripple_app/misc/ripple_ProofOfWork.h
rename to modules/ripple_app/misc/ProofOfWork.h
index 5bff7d4fb0..57f05f72e0 100644
--- a/modules/ripple_app/misc/ripple_ProofOfWork.h
+++ b/modules/ripple_app/misc/ProofOfWork.h
@@ -10,7 +10,10 @@
class ProofOfWork : LeakChecked
{
public:
- static const int sMaxDifficulty;
+ enum
+ {
+ kMaxIterations = (1 << 23)
+ };
typedef boost::shared_ptr pointer;
@@ -23,7 +26,7 @@ public:
bool isValid () const;
- uint256 solve (int maxIterations = 2 * sMaxIterations) const;
+ uint256 solve (int maxIterations = 2 * kMaxIterations) const;
bool checkSolution (uint256 const& solution) const;
const std::string& getToken () const
@@ -45,6 +48,8 @@ public:
static bool validateToken (const std::string& strToken);
+ static bool calcResultInfo (PowResult powCode, std::string& strToken, std::string& strHuman);
+
private:
std::string mToken;
uint256 mChallenge;
@@ -52,7 +57,7 @@ private:
int mIterations;
static const uint256 sMinTarget;
- static const int sMaxIterations;
+ static const int maxIterations;
};
#endif
diff --git a/modules/ripple_app/misc/ProofOfWorkFactory.cpp b/modules/ripple_app/misc/ProofOfWorkFactory.cpp
new file mode 100644
index 0000000000..22a68c56da
--- /dev/null
+++ b/modules/ripple_app/misc/ProofOfWorkFactory.cpp
@@ -0,0 +1,409 @@
+//------------------------------------------------------------------------------
+/*
+ Copyright (c) 2011-2013, OpenCoin, Inc.
+*/
+//==============================================================================
+
+class ProofOfWorkFactoryImp
+ : public ProofOfWorkFactory
+ , public LeakChecked
+{
+public:
+ typedef boost::bimap< boost::bimaps::multiset_of, boost::bimaps::unordered_set_of > powMap_t;
+ typedef powMap_t::value_type powMap_vt;
+
+ //--------------------------------------------------------------------------
+
+ ProofOfWorkFactoryImp ()
+ : mLock (this, "PoWFactory", __FILE__, __LINE__)
+ , mValidTime (180)
+ {
+ setDifficulty (1);
+ RandomNumbers::getInstance ().fillBytes (mSecret.begin (), mSecret.size ());
+ }
+
+ //--------------------------------------------------------------------------
+
+ enum
+ {
+ numPowEntries = kMaxDifficulty + 1
+ };
+
+ struct PowEntry
+ {
+ const char* target;
+ int iterations;
+ };
+
+ typedef std::vector PowEntries;
+
+ static PowEntries const& getPowEntries ()
+ {
+ struct StaticPowEntries
+ {
+ StaticPowEntries ()
+ {
+ // VFALCO TODO Make this array know its own size.
+ //
+ PowEntry entries [numPowEntries] =
+ {
+ // target iterations hashes memory
+ { "0CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 65536 }, // 1451874, 2 MB
+ { "0CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 98304 }, // 2177811, 3 MB
+ { "07FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 98304 }, // 3538944, 3 MB
+ { "0CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 196608}, // 4355623, 6 MB
+
+ { "07FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 131072}, // 4718592, 4 MB
+ { "0CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 5807497, 8 MB
+ { "07FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 196608}, // 7077888, 6 MB
+ { "07FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 9437184, 8 MB
+
+ { "07FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 14155776, 12MB
+ { "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 28311552, 12MB
+ { "00CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 92919965, 8 MB
+ { "00CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 139379948, 12MB
+
+ { "007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 150994944, 8 MB
+ { "007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 226492416, 12MB
+ { "000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 49152 }, // 278759896, 1.5MB
+ { "003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 301989888, 8 MB
+
+ { "003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 452984832, 12MB
+ { "0007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 98304 }, // 905969664, 3 MB
+ { "000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 196608}, // 1115039586, 6 MB
+ { "000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 1486719448 8 MB
+
+ { "000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 2230079172 12MB
+ { "0007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 2415919104, 8 MB
+ { "0007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 3623878656, 12MB
+ { "0003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 7247757312, 12MB
+
+ { "0000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 23787511177, 8 MB
+ { "0000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 35681266766, 12MB
+ { "00003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 131072}, // 38654705664, 4 MB
+ { "00007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 38654705664, 8 MB
+
+ { "00003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 196608}, // 57982058496, 6 MB
+ { "00007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 57982058496, 12MB
+ { "00003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 77309411328, 8 MB
+ };
+
+ data.reserve (numPowEntries);
+
+ for (int i = 0; i < numPowEntries; ++i)
+ data.push_back (entries [i]);
+ }
+
+ std::vector data;
+ };
+
+ static StaticPowEntries list;
+
+ return list.data;
+ }
+
+ //--------------------------------------------------------------------------
+
+ static int getPowEntry (uint256 const& target, int iterations)
+ {
+ PowEntries const& entries (getPowEntries ());
+
+ for (int i = 0; i < numPowEntries; ++i)
+ {
+ if (entries [i].iterations == iterations)
+ {
+ uint256 t;
+ t.SetHex (entries [i].target);
+
+ if (t == target)
+ return i;
+ }
+ }
+
+ return -1;
+ }
+
+ //--------------------------------------------------------------------------
+
+ ProofOfWork getProof ()
+ {
+ // challenge - target - iterations - time - validator
+ static boost::format f ("%s-%s-%d-%d");
+
+ int now = static_cast (time (NULL) / 4);
+
+ uint256 challenge;
+ RandomNumbers::getInstance ().fillBytes (challenge.begin (), challenge.size ());
+
+ ScopedLockType sl (mLock, __FILE__, __LINE__);
+
+ std::string s = boost::str (boost::format (f) % challenge.GetHex () % mTarget.GetHex () % mIterations % now);
+ std::string c = mSecret.GetHex () + s;
+ s += "-" + Serializer::getSHA512Half (c).GetHex ();
+
+ return ProofOfWork (s, mIterations, challenge, mTarget);
+ }
+
+ //--------------------------------------------------------------------------
+
+ PowResult checkProof (const std::string& token, uint256 const& solution)
+ {
+ // VFALCO COmmented this out because Dave said it wasn't used
+ // and also we dont have the lexicalCast from a vector of strings to a time_t
+
+ // challenge - target - iterations - time - validator
+
+ std::vector fields;
+ boost::split (fields, token, boost::algorithm::is_any_of ("-"));
+
+ if (fields.size () != 5)
+ {
+ WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " is corrupt";
+ return powCORRUPT;
+ }
+
+ std::string v = mSecret.GetHex () + fields[0] + "-" + fields[1] + "-" + fields[2] + "-" + fields[3];
+
+ if (fields[4] != Serializer::getSHA512Half (v).GetHex ())
+ {
+ WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " has a bad token";
+ return powCORRUPT;
+ }
+
+ uint256 challenge, target;
+ challenge.SetHex (fields[0]);
+ target.SetHex (fields[1]);
+
+ time_t t;
+ #if 0
+ // Broken with lexicalCast<> changes
+ t = lexicalCast (fields[3]);
+ #else
+ t = static_cast (lexicalCast (fields [3]));
+ #endif
+
+ time_t now = time (NULL);
+
+ int iterations = lexicalCast (fields[2]);
+
+ {
+ ScopedLockType sl (mLock, __FILE__, __LINE__);
+
+ if ((t * 4) > (now + mValidTime))
+ {
+ WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " has expired";
+ return powEXPIRED;
+ }
+
+ if (((iterations != mIterations) || (target != mTarget)) && getPowEntry (target, iterations) < (mPowEntry - 2))
+ {
+ // difficulty has increased more than two times since PoW requested
+ WriteLog (lsINFO, ProofOfWork) << "Difficulty has increased since PoW requested";
+ return powTOOEASY;
+ }
+ }
+
+ ProofOfWork pow (token, iterations, challenge, target);
+
+ if (!pow.checkSolution (solution))
+ {
+ WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " has a bad nonce";
+ return powBADNONCE;
+ }
+
+ {
+ ScopedLockType sl (mLock, __FILE__, __LINE__);
+
+ if (!mSolvedChallenges.insert (powMap_vt (now, challenge)).second)
+ {
+ WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " has been reused";
+ return powREUSED;
+ }
+ }
+
+ return powOK;
+ }
+
+ //--------------------------------------------------------------------------
+
+ void sweep ()
+ {
+ time_t expire = time (NULL) - mValidTime;
+
+ ScopedLockType sl (mLock, __FILE__, __LINE__);
+
+ do
+ {
+ powMap_t::left_map::iterator it = mSolvedChallenges.left.begin ();
+
+ if (it == mSolvedChallenges.left.end ())
+ return;
+
+ if (it->first >= expire)
+ return;
+
+ mSolvedChallenges.left.erase (it);
+ }
+ while (1);
+ }
+
+ //--------------------------------------------------------------------------
+
+ void loadHigh ()
+ {
+ time_t now = time (NULL);
+
+ ScopedLockType sl (mLock, __FILE__, __LINE__);
+
+ if (mLastDifficultyChange == now)
+ return;
+
+ if (mPowEntry == 30)
+ return;
+
+ ++mPowEntry;
+ mLastDifficultyChange = now;
+ }
+
+ //--------------------------------------------------------------------------
+
+ void loadLow ()
+ {
+ time_t now = time (NULL);
+
+ ScopedLockType sl (mLock, __FILE__, __LINE__);
+
+ if (mLastDifficultyChange == now)
+ return;
+
+ if (mPowEntry == 0)
+ return;
+
+ --mPowEntry;
+ mLastDifficultyChange = now;
+ }
+
+ //--------------------------------------------------------------------------
+
+ void setDifficulty (int i)
+ {
+ assert ((i >= 0) && (i <= kMaxDifficulty));
+ time_t now = time (NULL);
+
+ ScopedLockType sl (mLock, __FILE__, __LINE__);
+ mPowEntry = i;
+ PowEntries const& entries (getPowEntries ());
+ mIterations = entries [i].iterations;
+ mTarget.SetHex (entries [i].target);
+ mLastDifficultyChange = now;
+ }
+
+ //--------------------------------------------------------------------------
+
+ uint64 getDifficulty ()
+ {
+ return ProofOfWork::getDifficulty (mTarget, mIterations);
+ }
+
+ uint256 const& getSecret () const
+ {
+ return mSecret;
+ }
+
+ void setSecret (uint256 const& secret)
+ {
+ mSecret = secret;
+ }
+
+private:
+ typedef RippleMutex LockType;
+ typedef LockType::ScopedLockType ScopedLockType;
+ LockType mLock;
+
+ uint256 mSecret;
+ int mIterations;
+ uint256 mTarget;
+ time_t mLastDifficultyChange;
+ int mValidTime;
+ int mPowEntry;
+
+ powMap_t mSolvedChallenges;
+};
+
+//------------------------------------------------------------------------------
+
+ProofOfWorkFactory* ProofOfWorkFactory::New ()
+{
+ ScopedPointer object (new ProofOfWorkFactoryImp);
+ return object.release ();
+}
+
+//------------------------------------------------------------------------------
+
+class ProofOfWorkTests : public UnitTest
+{
+public:
+ ProofOfWorkTests () : UnitTest ("ProofOfWork", "ripple", runManual)
+ {
+ }
+
+ void runTest ()
+ {
+ using namespace ripple;
+
+ ProofOfWorkFactoryImp gen;
+ ProofOfWork pow = gen.getProof ();
+
+ String s;
+
+ s << "solve difficulty " << String (pow.getDifficulty ());
+ beginTestCase ("solve");
+
+ uint256 solution = pow.solve (16777216);
+
+ expect (! solution.isZero (), "Should be solved");
+
+ expect (pow.checkSolution (solution), "Should be checked");
+
+ // Why is this emitted?
+ //WriteLog (lsDEBUG, ProofOfWork) << "A bad nonce error is expected";
+
+ PowResult r = gen.checkProof (pow.getToken (), uint256 ());
+
+ expect (r == powBADNONCE, "Should show bad nonce for empty solution");
+
+ expect (gen.checkProof (pow.getToken (), solution) == powOK, "Solution should check with issuer");
+
+ //WriteLog (lsDEBUG, ProofOfWork) << "A reused nonce error is expected";
+
+ expect (gen.checkProof (pow.getToken (), solution) == powREUSED, "Reuse solution should be detected");
+
+ #ifdef SOLVE_POWS
+
+ for (int i = 0; i < 12; ++i)
+ {
+ gen.setDifficulty (i);
+ ProofOfWork pow = gen.getProof ();
+ WriteLog (lsINFO, ProofOfWork) << "Level: " << i << ", Estimated difficulty: " << pow.getDifficulty ();
+ uint256 solution = pow.solve (131072);
+
+ if (solution.isZero ())
+ {
+ //WriteLog (lsINFO, ProofOfWork) << "Giving up";
+ }
+ else
+ {
+ //WriteLog (lsINFO, ProofOfWork) << "Solution found";
+
+ if (gen.checkProof (pow.getToken (), solution) != powOK)
+ {
+ //WriteLog (lsFATAL, ProofOfWork) << "Solution fails";
+ }
+ }
+ }
+
+ #endif
+ }
+};
+
+static ProofOfWorkTests proofOfWorkTests;
diff --git a/modules/ripple_app/misc/ProofOfWorkFactory.h b/modules/ripple_app/misc/ProofOfWorkFactory.h
new file mode 100644
index 0000000000..9c16038e37
--- /dev/null
+++ b/modules/ripple_app/misc/ProofOfWorkFactory.h
@@ -0,0 +1,41 @@
+//------------------------------------------------------------------------------
+/*
+ Copyright (c) 2011-2013, OpenCoin, Inc.
+*/
+//==============================================================================
+
+#ifndef RIPPLE_PROOFOFWORKFACTORY_H_INCLUDED
+#define RIPPLE_PROOFOFWORKFACTORY_H_INCLUDED
+
+class ProofOfWorkFactory
+{
+public:
+ enum
+ {
+ kMaxDifficulty = 30,
+ };
+
+ static ProofOfWorkFactory* New ();
+
+ virtual ~ProofOfWorkFactory () { }
+
+ virtual ProofOfWork getProof () = 0;
+
+ virtual PowResult checkProof (const std::string& token, uint256 const& solution) = 0;
+
+ virtual uint64 getDifficulty () = 0;
+
+ virtual void setDifficulty (int i) = 0;
+
+ virtual void loadHigh () = 0;
+
+ virtual void loadLow () = 0;
+
+ virtual void sweep () = 0;
+
+ virtual uint256 const& getSecret () const = 0;
+
+ virtual void setSecret (uint256 const& secret) = 0;
+};
+
+#endif
diff --git a/modules/ripple_app/misc/ripple_IProofOfWorkFactory.h b/modules/ripple_app/misc/ripple_IProofOfWorkFactory.h
deleted file mode 100644
index c9ac0e4bb4..0000000000
--- a/modules/ripple_app/misc/ripple_IProofOfWorkFactory.h
+++ /dev/null
@@ -1,60 +0,0 @@
-//------------------------------------------------------------------------------
-/*
- Copyright (c) 2011-2013, OpenCoin, Inc.
-*/
-//==============================================================================
-
-#ifndef RIPPLE_IPROOFOFWORKFACTORY_H
-#define RIPPLE_IPROOFOFWORKFACTORY_H
-
-enum POWResult
-{
- powOK = 0,
- powREUSED = 1, // already submitted
- powBADNONCE = 2, // you didn't solve it
- powEXPIRED = 3, // time is up
- powCORRUPT = 4,
- powTOOEASY = 5, // the difficulty increased too much while you solved it
-};
-
-// VFALCO TODO move this to the class as a static member and rename it
-bool powResultInfo (POWResult powCode, std::string& strToken, std::string& strHuman);
-
-class IProofOfWorkFactory : LeakChecked
-{
-public:
- typedef boost::bimap< boost::bimaps::multiset_of, boost::bimaps::unordered_set_of > powMap_t;
- typedef powMap_t::value_type powMap_vt;
-
-public:
- static IProofOfWorkFactory* New ();
-
- virtual ~IProofOfWorkFactory () { }
-
- // VFALCO TODO which members can be const?
-
- virtual ProofOfWork getProof () = 0;
-
- virtual POWResult checkProof (const std::string& token, uint256 const& solution) = 0;
-
- virtual uint64 getDifficulty () = 0;
-
- virtual void setDifficulty (int i) = 0;
-
- virtual void loadHigh () = 0;
-
- virtual void loadLow () = 0;
-
- virtual void sweep () = 0;
-
- virtual uint256 const& getSecret () const = 0;
-
- virtual void setSecret (uint256 const& secret) = 0;
-
-public:
- static int getPowEntry (uint256 const& target, int iterations);
-};
-
-#endif
-
-// vim:ts=4
diff --git a/modules/ripple_app/misc/ripple_ProofOfWorkFactory.cpp b/modules/ripple_app/misc/ripple_ProofOfWorkFactory.cpp
deleted file mode 100644
index 54e6acbcf1..0000000000
--- a/modules/ripple_app/misc/ripple_ProofOfWorkFactory.cpp
+++ /dev/null
@@ -1,314 +0,0 @@
-//------------------------------------------------------------------------------
-/*
- Copyright (c) 2011-2013, OpenCoin, Inc.
-*/
-//==============================================================================
-
-ProofOfWorkFactory::ProofOfWorkFactory ()
- : mLock (this, "PoWFactory", __FILE__, __LINE__)
- , mValidTime (180)
-{
- setDifficulty (1);
- RandomNumbers::getInstance ().fillBytes (mSecret.begin (), mSecret.size ());
-}
-
-ProofOfWork ProofOfWorkFactory::getProof ()
-{
- // challenge - target - iterations - time - validator
- static boost::format f ("%s-%s-%d-%d");
-
- int now = static_cast (time (NULL) / 4);
-
- uint256 challenge;
- RandomNumbers::getInstance ().fillBytes (challenge.begin (), challenge.size ());
-
- ScopedLockType sl (mLock, __FILE__, __LINE__);
-
- std::string s = boost::str (boost::format (f) % challenge.GetHex () % mTarget.GetHex () % mIterations % now);
- std::string c = mSecret.GetHex () + s;
- s += "-" + Serializer::getSHA512Half (c).GetHex ();
-
- return ProofOfWork (s, mIterations, challenge, mTarget);
-}
-
-POWResult ProofOfWorkFactory::checkProof (const std::string& token, uint256 const& solution)
-{
- // VFALCO COmmented this out because Dave said it wasn't used
- // and also we dont have the lexicalCast from a vector of strings to a time_t
-
- // challenge - target - iterations - time - validator
-
- std::vector fields;
- boost::split (fields, token, boost::algorithm::is_any_of ("-"));
-
- if (fields.size () != 5)
- {
- WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " is corrupt";
- return powCORRUPT;
- }
-
- std::string v = mSecret.GetHex () + fields[0] + "-" + fields[1] + "-" + fields[2] + "-" + fields[3];
-
- if (fields[4] != Serializer::getSHA512Half (v).GetHex ())
- {
- WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " has a bad token";
- return powCORRUPT;
- }
-
- uint256 challenge, target;
- challenge.SetHex (fields[0]);
- target.SetHex (fields[1]);
-
- time_t t;
-#if 0
- // Broken with lexicalCast<> changes
- t = lexicalCast (fields[3]);
-#else
- t = static_cast (lexicalCast (fields [3]));
-#endif
-
- time_t now = time (NULL);
-
- int iterations = lexicalCast (fields[2]);
-
- {
- ScopedLockType sl (mLock, __FILE__, __LINE__);
-
- if ((t * 4) > (now + mValidTime))
- {
- WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " has expired";
- return powEXPIRED;
- }
-
- if (((iterations != mIterations) || (target != mTarget)) && getPowEntry (target, iterations) < (mPowEntry - 2))
- {
- // difficulty has increased more than two times since PoW requested
- WriteLog (lsINFO, ProofOfWork) << "Difficulty has increased since PoW requested";
- return powTOOEASY;
- }
- }
-
- ProofOfWork pow (token, iterations, challenge, target);
-
- if (!pow.checkSolution (solution))
- {
- WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " has a bad nonce";
- return powBADNONCE;
- }
-
- {
- ScopedLockType sl (mLock, __FILE__, __LINE__);
-
- if (!mSolvedChallenges.insert (powMap_vt (now, challenge)).second)
- {
- WriteLog (lsDEBUG, ProofOfWork) << "PoW " << token << " has been reused";
- return powREUSED;
- }
- }
-
- return powOK;
-}
-
-void ProofOfWorkFactory::sweep ()
-{
- time_t expire = time (NULL) - mValidTime;
-
- ScopedLockType sl (mLock, __FILE__, __LINE__);
-
- do
- {
- powMap_t::left_map::iterator it = mSolvedChallenges.left.begin ();
-
- if (it == mSolvedChallenges.left.end ())
- return;
-
- if (it->first >= expire)
- return;
-
- mSolvedChallenges.left.erase (it);
- }
- while (1);
-}
-
-void ProofOfWorkFactory::loadHigh ()
-{
- time_t now = time (NULL);
-
- ScopedLockType sl (mLock, __FILE__, __LINE__);
-
- if (mLastDifficultyChange == now)
- return;
-
- if (mPowEntry == 30)
- return;
-
- ++mPowEntry;
- mLastDifficultyChange = now;
-}
-
-void ProofOfWorkFactory::loadLow ()
-{
- time_t now = time (NULL);
-
- ScopedLockType sl (mLock, __FILE__, __LINE__);
-
- if (mLastDifficultyChange == now)
- return;
-
- if (mPowEntry == 0)
- return;
-
- --mPowEntry;
- mLastDifficultyChange = now;
-}
-
-struct PowEntry
-{
- const char* target;
- int iterations;
-};
-
-PowEntry PowEntries[ProofOfWork::sMaxDifficulty + 1] =
-{
- // target iterations hashes memory
- { "0CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 65536 }, // 1451874, 2 MB
- { "0CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 98304 }, // 2177811, 3 MB
- { "07FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 98304 }, // 3538944, 3 MB
- { "0CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 196608}, // 4355623, 6 MB
-
- { "07FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 131072}, // 4718592, 4 MB
- { "0CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 5807497, 8 MB
- { "07FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 196608}, // 7077888, 6 MB
- { "07FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 9437184, 8 MB
-
- { "07FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 14155776, 12MB
- { "03FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 28311552, 12MB
- { "00CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 92919965, 8 MB
- { "00CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 139379948, 12MB
-
- { "007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 150994944, 8 MB
- { "007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 226492416, 12MB
- { "000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 49152 }, // 278759896, 1.5MB
- { "003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 301989888, 8 MB
-
- { "003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 452984832, 12MB
- { "0007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 98304 }, // 905969664, 3 MB
- { "000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 196608}, // 1115039586, 6 MB
- { "000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 1486719448 8 MB
-
- { "000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 2230079172 12MB
- { "0007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 2415919104, 8 MB
- { "0007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 3623878656, 12MB
- { "0003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 7247757312, 12MB
-
- { "0000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 23787511177, 8 MB
- { "0000CFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 35681266766, 12MB
- { "00003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 131072}, // 38654705664, 4 MB
- { "00007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 38654705664, 8 MB
-
- { "00003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 196608}, // 57982058496, 6 MB
- { "00007FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 393216}, // 57982058496, 12MB
- { "00003FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", 262144}, // 77309411328, 8 MB
-};
-
-int ProofOfWorkFactory::getPowEntry (uint256 const& target, int iterations)
-{
- for (int i = 0; i < 31; ++i)
- if (PowEntries[i].iterations == iterations)
- {
- uint256 t;
- t.SetHex (PowEntries[i].target);
-
- if (t == target)
- return i;
- }
-
- return -1;
-}
-
-void ProofOfWorkFactory::setDifficulty (int i)
-{
- assert ((i >= 0) && (i <= ProofOfWork::sMaxDifficulty));
- time_t now = time (NULL);
-
- ScopedLockType sl (mLock, __FILE__, __LINE__);
- mPowEntry = i;
- mIterations = PowEntries[i].iterations;
- mTarget.SetHex (PowEntries[i].target);
- mLastDifficultyChange = now;
-}
-
-IProofOfWorkFactory* IProofOfWorkFactory::New ()
-{
- return new ProofOfWorkFactory;
-}
-
-//------------------------------------------------------------------------------
-
-class ProofOfWorkTests : public UnitTest
-{
-public:
- ProofOfWorkTests () : UnitTest ("ProofOfWork", "ripple", runManual)
- {
- }
-
- void runTest ()
- {
- using namespace ripple;
-
- ProofOfWorkFactory gen;
- ProofOfWork pow = gen.getProof ();
-
- String s;
-
- s << "solve difficulty " << String (pow.getDifficulty ());
- beginTestCase ("solve");
-
- uint256 solution = pow.solve (16777216);
-
- expect (! solution.isZero (), "Should be solved");
-
- expect (pow.checkSolution (solution), "Should be checked");
-
- // Why is this emitted?
- //WriteLog (lsDEBUG, ProofOfWork) << "A bad nonce error is expected";
-
- POWResult r = gen.checkProof (pow.getToken (), uint256 ());
-
- expect (r == powBADNONCE, "Should show bad nonce for empty solution");
-
- expect (gen.checkProof (pow.getToken (), solution) == powOK, "Solution should check with issuer");
-
- //WriteLog (lsDEBUG, ProofOfWork) << "A reused nonce error is expected";
-
- expect (gen.checkProof (pow.getToken (), solution) == powREUSED, "Reuse solution should be detected");
-
- #ifdef SOLVE_POWS
-
- for (int i = 0; i < 12; ++i)
- {
- gen.setDifficulty (i);
- ProofOfWork pow = gen.getProof ();
- WriteLog (lsINFO, ProofOfWork) << "Level: " << i << ", Estimated difficulty: " << pow.getDifficulty ();
- uint256 solution = pow.solve (131072);
-
- if (solution.isZero ())
- {
- //WriteLog (lsINFO, ProofOfWork) << "Giving up";
- }
- else
- {
- //WriteLog (lsINFO, ProofOfWork) << "Solution found";
-
- if (gen.checkProof (pow.getToken (), solution) != powOK)
- {
- //WriteLog (lsFATAL, ProofOfWork) << "Solution fails";
- }
- }
- }
-
- #endif
- }
-};
-
-static ProofOfWorkTests proofOfWorkTests;
diff --git a/modules/ripple_app/misc/ripple_ProofOfWorkFactory.h b/modules/ripple_app/misc/ripple_ProofOfWorkFactory.h
deleted file mode 100644
index c82b2cfb0f..0000000000
--- a/modules/ripple_app/misc/ripple_ProofOfWorkFactory.h
+++ /dev/null
@@ -1,57 +0,0 @@
-//------------------------------------------------------------------------------
-/*
- Copyright (c) 2011-2013, OpenCoin, Inc.
-*/
-//==============================================================================
-
-#ifndef RIPPLE_PROOFOFWORKFACTORY_RIPPLEHEADER
-#define RIPPLE_PROOFOFWORKFACTORY_RIPPLEHEADER
-
-// PRIVATE HEADER
-
-class ProofOfWorkFactory
- : public IProofOfWorkFactory
- , LeakChecked
-{
-public:
- ProofOfWorkFactory ();
-
- ProofOfWork getProof ();
- POWResult checkProof (const std::string& token, uint256 const& solution);
- uint64 getDifficulty ()
- {
- return ProofOfWork::getDifficulty (mTarget, mIterations);
- }
- void setDifficulty (int i);
-
- void loadHigh ();
- void loadLow ();
- void sweep (void);
-
- uint256 const& getSecret () const
- {
- return mSecret;
- }
- void setSecret (uint256 const& secret)
- {
- mSecret = secret;
- }
-
- static int getPowEntry (uint256 const& target, int iterations);
-
-private:
- typedef RippleMutex LockType;
- typedef LockType::ScopedLockType ScopedLockType;
- LockType mLock;
-
- uint256 mSecret;
- int mIterations;
- uint256 mTarget;
- time_t mLastDifficultyChange;
- int mValidTime;
- int mPowEntry;
-
- powMap_t mSolvedChallenges;
-};
-
-#endif
diff --git a/modules/ripple_app/peers/ripple_Peer.cpp b/modules/ripple_app/peers/ripple_Peer.cpp
index fb30a6fc1a..dc268181fb 100644
--- a/modules/ripple_app/peers/ripple_Peer.cpp
+++ b/modules/ripple_app/peers/ripple_Peer.cpp
@@ -1779,7 +1779,7 @@ void PeerImp::recvProofWork (protocol::TMProofWork& packet)
uint256 response;
memcpy (response.begin (), packet.response ().data (), 256 / 8);
- POWResult r = getApp().getProofOfWorkFactory ().checkProof (packet.token (), response);
+ PowResult r = getApp().getProofOfWorkFactory ().checkProof (packet.token (), response);
if (r == powOK)
{
diff --git a/modules/ripple_app/ripple_app.cpp b/modules/ripple_app/ripple_app.cpp
index 2b7cb3a41a..05190cf00a 100644
--- a/modules/ripple_app/ripple_app.cpp
+++ b/modules/ripple_app/ripple_app.cpp
@@ -30,6 +30,9 @@ namespace ripple
#include "main/ripple_FatalErrorReporter.cpp"
# include "rpc/RPCHandler.h"
+# include "misc/PowResult.h"
+# include "misc/ProofOfWork.h"
+# include "misc/ProofOfWorkFactory.h"
#include "rpc/RPCHandler.cpp"
# include "rpc/RPCServerHandler.h"
#include "rpc/RPCServerHandler.cpp"
diff --git a/modules/ripple_app/ripple_app.h b/modules/ripple_app/ripple_app.h
index 83b087d675..ed6d90e4f4 100644
--- a/modules/ripple_app/ripple_app.h
+++ b/modules/ripple_app/ripple_app.h
@@ -19,6 +19,7 @@
// purely abstract and move implementation into .cpp files.
//
+#if 1
#include
#include
#include
@@ -44,7 +45,6 @@
#include
#include
#include
-#include
#include
#include
#include
@@ -55,6 +55,7 @@
#include
#include
#include
+#endif
//------------------------------------------------------------------------------
@@ -95,7 +96,6 @@ namespace ripple
#include "ledger/Ledger.h"
#include "ledger/SerializedValidation.h"
#include "main/ripple_LoadManager.h"
-#include "misc/ripple_ProofOfWork.h"
#include "misc/ripple_OrderBook.h"
#include "shamap/ripple_SHAMapSyncFilters.h"
#include "misc/ripple_IFeatures.h"
@@ -103,7 +103,6 @@ namespace ripple
#include "misc/ripple_IHashRouter.h"
#include "peers/ripple_Peer.h"
#include "peers/ripple_Peers.h"
-#include "misc/ripple_IProofOfWorkFactory.h"
#include "peers/ripple_ClusterNodeStatus.h"
#include "peers/ripple_UniqueNodeList.h"
#include "misc/ripple_IValidations.h"
diff --git a/modules/ripple_app/ripple_app_pt1.cpp b/modules/ripple_app/ripple_app_pt1.cpp
index 33be255cd0..2c7c87832a 100644
--- a/modules/ripple_app/ripple_app_pt1.cpp
+++ b/modules/ripple_app/ripple_app_pt1.cpp
@@ -13,9 +13,11 @@ namespace ripple
#include "peers/ripple_PeerSet.cpp"
#include "misc/ripple_OrderBook.cpp"
-#include "misc/ripple_ProofOfWork.cpp"
-#include "misc/ripple_ProofOfWorkFactory.h"
-#include "misc/ripple_ProofOfWorkFactory.cpp" // requires ProofOfWork.cpp for ProofOfWork::sMaxDifficulty
+# include "misc/PowResult.h"
+# include "misc/ProofOfWork.h"
+# include "misc/ProofOfWorkFactory.h"
+#include "misc/ProofOfWorkFactory.cpp"
+#include "misc/ProofOfWork.cpp"
#include "misc/ripple_SerializedTransaction.cpp"
#include "shamap/ripple_SHAMapSyncFilters.cpp" // requires Application
diff --git a/modules/ripple_app/ripple_app_pt5.cpp b/modules/ripple_app/ripple_app_pt5.cpp
index eb09a8170c..f8d15c0e4e 100644
--- a/modules/ripple_app/ripple_app_pt5.cpp
+++ b/modules/ripple_app/ripple_app_pt5.cpp
@@ -19,6 +19,9 @@ namespace ripple
#include "tx/OfferCreateTransactor.cpp"
#include "tx/WalletAddTransactor.cpp"
#include "misc/ripple_FeeVote.cpp"
+# include "misc/PowResult.h"
+# include "misc/ProofOfWork.h"
+# include "misc/ProofOfWorkFactory.h"
#include "peers/ripple_Peer.cpp"
}
diff --git a/modules/ripple_app/rpc/RPCHandler.cpp b/modules/ripple_app/rpc/RPCHandler.cpp
index e55a35c989..93c1973a3d 100644
--- a/modules/ripple_app/rpc/RPCHandler.cpp
+++ b/modules/ripple_app/rpc/RPCHandler.cpp
@@ -893,7 +893,7 @@ Json::Value RPCHandler::doProofCreate (Json::Value params, LoadType* loadType, A
if (params.isMember ("difficulty") || params.isMember ("secret"))
{
// VFALCO TODO why aren't we using the app's factory?
- beast::ScopedPointer pgGen (IProofOfWorkFactory::New ());
+ beast::ScopedPointer pgGen (ProofOfWorkFactory::New ());
if (params.isMember ("difficulty"))
{
@@ -902,7 +902,7 @@ Json::Value RPCHandler::doProofCreate (Json::Value params, LoadType* loadType, A
int iDifficulty = params["difficulty"].asInt ();
- if (iDifficulty < 0 || iDifficulty > ProofOfWork::sMaxDifficulty)
+ if (iDifficulty < 0 || iDifficulty > ProofOfWorkFactory::kMaxDifficulty)
return rpcError (rpcINVALID_PARAMS);
pgGen->setDifficulty (iDifficulty);
@@ -974,12 +974,12 @@ Json::Value RPCHandler::doProofVerify (Json::Value params, LoadType* loadType, A
std::string strToken = params["token"].asString ();
uint256 uSolution (params["solution"].asString ());
- POWResult prResult;
+ PowResult prResult;
if (params.isMember ("difficulty") || params.isMember ("secret"))
{
// VFALCO TODO why aren't we using the app's factory?
- beast::ScopedPointer pgGen (IProofOfWorkFactory::New ());
+ beast::ScopedPointer pgGen (ProofOfWorkFactory::New ());
if (params.isMember ("difficulty"))
{
@@ -988,7 +988,7 @@ Json::Value RPCHandler::doProofVerify (Json::Value params, LoadType* loadType, A
int iDifficulty = params["difficulty"].asInt ();
- if (iDifficulty < 0 || iDifficulty > ProofOfWork::sMaxDifficulty)
+ if (iDifficulty < 0 || iDifficulty > ProofOfWorkFactory::kMaxDifficulty)
return rpcError (rpcINVALID_PARAMS);
pgGen->setDifficulty (iDifficulty);
@@ -1013,7 +1013,7 @@ Json::Value RPCHandler::doProofVerify (Json::Value params, LoadType* loadType, A
std::string sToken;
std::string sHuman;
- powResultInfo (prResult, sToken, sHuman);
+ ProofOfWork::calcResultInfo (prResult, sToken, sHuman);
jvResult["proof_result"] = sToken;
jvResult["proof_result_code"] = prResult;
diff --git a/modules/ripple_data/protocol/ripple.proto b/modules/ripple_data/protocol/ripple.proto
index de65a5ba5a..bd28719600 100644
--- a/modules/ripple_data/protocol/ripple.proto
+++ b/modules/ripple_data/protocol/ripple.proto
@@ -47,7 +47,7 @@ message TMProofWork
optional bytes challenge = 4;
optional bytes response = 5;
- enum POWResult
+ enum PowResult
{
powrOK = 0;
powrREUSED = 1;
@@ -56,7 +56,7 @@ message TMProofWork
powrINVALID = 4;
powrDISCONNECT = 5; // We are disconnecting
}
- optional POWResult result = 6;
+ optional PowResult result = 6;
}
// Sent on connect