Merge branch 'master' into ripple

This commit is contained in:
Arthur Britto
2012-08-14 16:10:17 -07:00
20 changed files with 143 additions and 70 deletions

View File

@@ -70,11 +70,11 @@ void Application::run()
if (!theConfig.DEBUG_LOGFILE.empty())
Log::setLogFile(theConfig.DEBUG_LOGFILE);
mSNTPClient.init(theConfig.SNTP_SERVERS);
boost::thread auxThread(boost::bind(&boost::asio::io_service::run, &mAuxService));
auxThread.detach();
mSNTPClient.init(theConfig.SNTP_SERVERS);
//
// Construct databases.
//
@@ -95,13 +95,14 @@ void Application::run()
//
// Set up UNL.
//
getUNL().nodeBootstrap();
if (!theConfig.RUN_STANDALONE)
getUNL().nodeBootstrap();
//
// Allow peer connections.
//
if (!theConfig.PEER_IP.empty() && theConfig.PEER_PORT)
if (!theConfig.RUN_STANDALONE && !theConfig.PEER_IP.empty() && theConfig.PEER_PORT)
{
mPeerDoor = new PeerDoor(mIOService);
}
@@ -127,7 +128,8 @@ void Application::run()
//
// Begin connecting to network.
//
mConnectionPool.start();
if (!theConfig.RUN_STANDALONE)
mConnectionPool.start();
// New stuff.
NewcoinAddress rootSeedMaster = NewcoinAddress::createSeedGeneric("masterpassphrase");
@@ -155,7 +157,14 @@ void Application::run()
}
mNetOps.setStateTimer();
if (theConfig.RUN_STANDALONE)
{
Log(lsWARNING) << "Running in standalone mode";
mNetOps.setStandAlone();
mMasterLedger.runStandAlone();
}
else
mNetOps.setStateTimer();
mIOService.run(); // This blocks

View File

@@ -150,6 +150,8 @@ void Config::setup(const std::string& strConf)
VALIDATORS_SITE = DEFAULT_VALIDATORS_SITE;
RUN_STANDALONE = false;
load();
}

View File

@@ -63,6 +63,7 @@ public:
int LEDGER_PROPOSAL_DELAY_SECONDS;
int LEDGER_AVALANCHE_SECONDS;
bool LEDGER_CREATOR; // should be false unless we are starting a new ledger
bool RUN_STANDALONE;
// Note: The following parameters do not relate to the UNL or trust at all
unsigned int NETWORK_QUORUM; // Minimum number of nodes to consider the network present

View File

@@ -42,6 +42,9 @@ ConnectionPool::ConnectionPool(boost::asio::io_service& io_service) :
void ConnectionPool::start()
{
if (theConfig.RUN_STANDALONE)
return;
// Start running policy.
policyEnforce();
@@ -243,6 +246,8 @@ void ConnectionPool::relayMessage(Peer* fromPeer, PackedMessage::pointer msg)
// Requires sane IP and port.
void ConnectionPool::connectTo(const std::string& strIp, int iPort)
{
if (theConfig.RUN_STANDALONE)
return;
{
Database* db = theApp->getWalletDB()->getDB();
ScopedLock sl(theApp->getWalletDB()->getDBLock());

View File

@@ -21,7 +21,9 @@ bool HashedObjectStore::store(HashedObjectType type, uint32 index,
if (!theApp->getHashNodeDB()) return true;
if (mCache.touch(hash))
{
#ifdef HS_DEBUG
Log(lsTRACE) << "HOS: " << hash.GetHex() << " store: incache";
#endif
return false;
}

View File

@@ -57,7 +57,7 @@ Ledger::Ledger(Ledger& ledger, bool isMutable) : mTotCoins(ledger.mTotCoins), mL
}
Ledger::Ledger(bool dummy, Ledger& prevLedger) :
Ledger::Ledger(bool /* dummy */, Ledger& prevLedger) :
mTotCoins(prevLedger.mTotCoins), mLedgerSeq(prevLedger.mLedgerSeq + 1),
mParentCloseTime(prevLedger.mCloseTime), mCloseResolution(prevLedger.mCloseResolution),
mCloseFlags(0), mClosed(false), mValidHash(false), mAccepted(false), mImmutable(false),

View File

@@ -11,7 +11,7 @@
#include "HashPrefixes.h"
// #define LA_DEBUG
#define LEDGER_ACQUIRE_TIMEOUT 2
#define LEDGER_ACQUIRE_TIMEOUT 1
#define TRUST_NETWORK
PeerSet::PeerSet(const uint256& hash, int interval) : mHash(hash), mTimerInterval(interval), mTimeouts(0),

View File

@@ -26,7 +26,10 @@ TransactionAcquire::TransactionAcquire(const uint256& hash) : PeerSet(hash, 1),
void TransactionAcquire::done()
{
if (mFailed)
{
Log(lsWARNING) << "Failed to acqiure TXs " << mHash.GetHex();
theApp->getOPs().mapComplete(mHash, SHAMap::pointer());
}
else
theApp->getOPs().mapComplete(mHash, mMap);
}
@@ -48,7 +51,7 @@ void TransactionAcquire::trigger(Peer::pointer peer, bool timer)
*(tmGL.add_nodeids()) = SHAMapNode().getRawString();
sendRequest(tmGL, peer);
}
if (mHaveRoot)
else
{
std::vector<SHAMapNode> nodeIDs; std::vector<uint256> nodeHashes;
ConsensusTransSetSF sf;
@@ -67,10 +70,7 @@ void TransactionAcquire::trigger(Peer::pointer peer, bool timer)
tmGL.set_itype(newcoin::liTS_CANDIDATE);
for (std::vector<SHAMapNode>::iterator it = nodeIDs.begin(); it != nodeIDs.end(); ++it)
*(tmGL.add_nodeids()) = it->getRawString();
if (peer)
sendRequest(tmGL, peer);
else
sendRequest(tmGL);
sendRequest(tmGL, peer);
return;
}
}
@@ -224,7 +224,7 @@ LedgerConsensus::LedgerConsensus(const uint256& prevLCLHash, Ledger::pointer pre
}
else
{
Log(lsINFO) << "Entering consensus process, proposing";
Log(lsINFO) << "Entering consensus process, watching";
mHaveCorrectLCL = true;
mProposing = mValidating = false;
}
@@ -249,6 +249,9 @@ void LedgerConsensus::checkLCL()
mPrevLedgerHash = netLgr;
mAcquiringLedger = theApp->getMasterLedgerAcquire().findCreate(mPrevLedgerHash);
std::vector<Peer::pointer> peerList = theApp->getConnectionPool().getPeerVector();
mHaveCorrectLCL = false;
mProposing = false;
mValidating = false;
bool found = false;
for (std::vector<Peer::pointer>::const_iterator it = peerList.begin(), end = peerList.end(); it != end; ++it)
if ((*it)->hasLedger(mPrevLedgerHash))
@@ -405,7 +408,12 @@ void LedgerConsensus::statePreClose()
int proposersClosed = mPeerPositions.size();
// This ledger is open. This computes how long since the last ledger closed
int sinceClose = 1000 * (theApp->getOPs().getCloseTimeNC() - theApp->getOPs().getLastCloseNetTime());
int lastCloseTime;
if (!anyTransactions && mPreviousLedger->getCloseAgree())
lastCloseTime = mPreviousLedger->getCloseTimeNC();
else
lastCloseTime = theApp->getOPs().getLastCloseNetTime();
int sinceClose = 1000 * (theApp->getOPs().getCloseTimeNC() - lastCloseTime);
if (sinceClose >= ContinuousLedgerTiming::shouldClose(anyTransactions, mPreviousProposers, proposersClosed,
mPreviousMSeconds, sinceClose))
@@ -418,6 +426,8 @@ void LedgerConsensus::statePreClose()
statusChange(newcoin::neCLOSING_LEDGER, *mPreviousLedger);
takeInitialPosition(*theApp->getMasterLedger().closeLedger());
}
else
checkLCL();
}
void LedgerConsensus::stateEstablish()
@@ -441,9 +451,7 @@ void LedgerConsensus::stateEstablish()
void LedgerConsensus::stateFinished()
{ // we are processing the finished ledger
// logic of calculating next ledger advances us out of this state
// CHECKME: Should we count proposers that didn't converge to our consensus set?
theApp->getOPs().newLCL(mPeerPositions.size(), mCurrentMSeconds, mNewLedgerHash);
// nothing to do
}
void LedgerConsensus::stateAccepted()
@@ -770,6 +778,7 @@ void LedgerConsensus::beginAccept()
return;
}
theApp->getOPs().newLCL(mPeerPositions.size(), mCurrentMSeconds, mNewLedgerHash);
boost::thread thread(boost::bind(&LedgerConsensus::Saccept, shared_from_this(), consensusSet));
thread.detach();
}
@@ -907,12 +916,12 @@ void LedgerConsensus::accept(SHAMap::pointer set)
SerializedValidation::pointer v = boost::make_shared<SerializedValidation>
(newLCLHash, newLCL->getCloseTimeNC(), mValSeed, mProposing);
v->setTrusted();
Log(lsINFO) << "CNF Val " << newLCLHash.GetHex();
theApp->getValidations().addValidation(v);
std::vector<unsigned char> validation = v->getSigned();
newcoin::TMValidation val;
val.set_validation(&validation[0], validation.size());
theApp->getConnectionPool().relayMessage(NULL, boost::make_shared<PackedMessage>(val, newcoin::mtVALIDATION));
Log(lsINFO) << "CNF Val " << newLCLHash.GetHex();
}
else
Log(lsINFO) << "CNF newLCL " << newLCLHash.GetHex();

View File

@@ -43,6 +43,8 @@ public:
// The finalized ledger is the last closed/accepted ledger
Ledger::pointer getClosedLedger() { return mFinalizedLedger; }
void runStandAlone() { mFinalizedLedger = mCurrentLedger; }
TransactionEngineResult doTransaction(const SerializedTransaction& txn, uint32 targetLedger,
TransactionEngineParams params);

View File

@@ -22,8 +22,8 @@ int ContinuousLedgerTiming::shouldClose(
if ((previousMSeconds < -1000) || (previousMSeconds > 600000) ||
(currentMSeconds < -1000) || (currentMSeconds > 600000))
{
Log(lsFATAL) <<
boost::str(boost::format("CLC::shouldClose range error Trans=%s, Prop: %d/%d, Secs: %d (last:%d)")
Log(lsWARNING) <<
boost::str(boost::format("CLC::shouldClose range Trans=%s, Prop: %d/%d, Secs: %d (last:%d)")
% (anyTransactions ? "yes" : "no") % previousProposers % proposersClosed
% currentMSeconds % previousMSeconds);
return currentMSeconds;

View File

@@ -4,8 +4,14 @@
// The number of seconds a ledger may remain idle before closing
# define LEDGER_IDLE_INTERVAL 15
// The number of seconds a validation remains current
# define LEDGER_MAX_INTERVAL (LEDGER_IDLE_INTERVAL * 4)
// The number of seconds a validation remains current after its ledger's close time
// This is a safety to protect against very old validations and the time it takes to adjust
// the close time accuracy window
# define LEDGER_VAL_INTERVAL 600
// The number of seconds before a close time that we consider a validation acceptable
// This protects against extreme clock errors
# define LEDGER_EARLY_INTERVAL 240
// The number of milliseconds we wait minimum to ensure participation
# define LEDGER_MIN_CONSENSUS 2000

View File

@@ -322,16 +322,20 @@ public:
{
if (trustedValidations > v.trustedValidations) return true;
if (trustedValidations < v.trustedValidations) return false;
if (nodesUsing > v.nodesUsing) return true;
if (nodesUsing < v.nodesUsing) return false;
if (trustedValidations == 0)
{
if (nodesUsing > v.nodesUsing) return true;
if (nodesUsing < v.nodesUsing) return false;
}
return highNode > v.highNode;
}
};
void NetworkOPs::checkState(const boost::system::error_code& result)
{ // Network state machine
if (result == boost::asio::error::operation_aborted)
if ((result == boost::asio::error::operation_aborted) || theConfig.RUN_STANDALONE)
return;
setStateTimer();
std::vector<Peer::pointer> peerList = theApp->getConnectionPool().getPeerVector();
@@ -344,7 +348,6 @@ void NetworkOPs::checkState(const boost::system::error_code& result)
Log(lsWARNING) << "Node count (" << peerList.size() <<
") has fallen below quorum (" << theConfig.NETWORK_QUORUM << ").";
}
setStateTimer();
return;
}
if (mMode == omDISCONNECTED)
@@ -356,7 +359,6 @@ void NetworkOPs::checkState(const boost::system::error_code& result)
if (mConsensus)
{
mConsensus->timerEntry();
setStateTimer();
return;
}
@@ -383,15 +385,13 @@ void NetworkOPs::checkState(const boost::system::error_code& result)
// check if the ledger is good enough to go to omFULL
// Note: Do not go to omFULL if we don't have the previous ledger
// check if the ledger is bad enough to go to omCONNECTED -- TODO
if (theApp->getOPs().getNetworkTimeNC() <
(theApp->getMasterLedger().getCurrentLedger()->getCloseTimeNC() + 4))
if (theApp->getOPs().getNetworkTimeNC() < theApp->getMasterLedger().getCurrentLedger()->getCloseTimeNC())
setMode(omFULL);
else
Log(lsINFO) << "Will try to go to FULL in consensus window";
}
if (mMode == omFULL)
{
// WRITEME
// check if the ledger is bad enough to go to omTRACKING
}
@@ -399,7 +399,6 @@ void NetworkOPs::checkState(const boost::system::error_code& result)
beginConsensus(networkClosed, theApp->getMasterLedger().getCurrentLedger());
if (mConsensus)
mConsensus->timerEntry();
setStateTimer();
}
bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerList, uint256& networkClosed)
@@ -458,9 +457,10 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerLis
for (boost::unordered_map<uint256, ValidationCount>::iterator it = ledgers.begin(), end = ledgers.end();
it != end; ++it)
{
Log(lsTRACE) << "L: " << it->first.GetHex() <<
" t=" << it->second.trustedValidations << ", n=" << it->second.nodesUsing;
if ((it->second > bestVC) && !theApp->getValidations().isDeadLedger(it->first))
bool isDead = theApp->getValidations().isDeadLedger(it->first);
Log(lsTRACE) << "L: " << it->first.GetHex() << ((isDead) ? " dead" : " live") <<
" t=" << it->second.trustedValidations << ", n=" << it->second.nodesUsing;
if ((it->second > bestVC) && !isDead)
{
bestVC = it->second;
closedLedger = it->first;
@@ -632,20 +632,23 @@ bool NetworkOPs::recvPropose(uint32 proposeSeq, const uint256& proposeHash, uint
SHAMap::pointer NetworkOPs::getTXMap(const uint256& hash)
{
if (!mConsensus) return SHAMap::pointer();
if (!mConsensus)
return SHAMap::pointer();
return mConsensus->getTransactionTree(hash, false);
}
bool NetworkOPs::gotTXData(boost::shared_ptr<Peer> peer, const uint256& hash,
const std::list<SHAMapNode>& nodeIDs, const std::list< std::vector<unsigned char> >& nodeData)
{
if (!mConsensus) return false;
if (!mConsensus)
return false;
return mConsensus->peerGaveNodes(peer, hash, nodeIDs, nodeData);
}
bool NetworkOPs::hasTXSet(boost::shared_ptr<Peer> peer, const uint256& set, newcoin::TxSetStatus status)
{
if (!mConsensus) return false;
if (!mConsensus)
return false;
return mConsensus->peerHasSet(peer, set, status);
}
@@ -675,11 +678,15 @@ void NetworkOPs::setMode(OperatingMode om)
if (mMode == om) return;
if ((om >= omCONNECTED) && (mMode == omDISCONNECTED))
mConnectTime = boost::posix_time::second_clock::universal_time();
Log l((om < mMode) ? lsWARNING : lsINFO);
if (om == omDISCONNECTED) l << "STATE->Disonnected";
else if (om == omCONNECTED) l << "STATE->Connected";
else if (om == omTRACKING) l << "STATE->Tracking";
else l << "STATE->Full";
Log lg((om < mMode) ? lsWARNING : lsINFO);
if (om == omDISCONNECTED)
lg << "STATE->Disconnected";
else if (om == omCONNECTED)
lg << "STATE->Connected";
else if (om == omTRACKING)
lg << "STATE->Tracking";
else
lg << "STATE->Full";
mMode = om;
}

View File

@@ -188,6 +188,7 @@ public:
bool checkLastClosedLedger(const std::vector<Peer::pointer>&, uint256& networkClosed);
int beginConsensus(const uint256& networkClosed, Ledger::pointer closingLedger);
void endConsensus(bool correctLCL);
void setStandAlone() { setMode(omFULL); }
void setStateTimer();
void newLCL(int proposers, int convergeTime, const uint256& ledgerHash);
int getPreviousProposers() { return mLastCloseProposers; }

View File

@@ -928,7 +928,7 @@ void Peer::recvGetLedger(newcoin::TMGetLedger& packet)
{
SHAMap::pointer map;
newcoin::TMLedgerData reply;
bool fatLeaves = true;
bool fatLeaves = true, fatRoot = false;
if (packet.itype() == newcoin::liTS_CANDIDATE)
{ // Request is for a transaction candidate set
@@ -952,6 +952,7 @@ void Peer::recvGetLedger(newcoin::TMGetLedger& packet)
reply.set_ledgerhash(txHash.begin(), txHash.size());
reply.set_type(newcoin::liTS_CANDIDATE);
fatLeaves = false; // We'll already have most transactions
fatRoot = true; // Save a pass
}
else
{ // Figure out what ledger they want
@@ -1057,7 +1058,7 @@ void Peer::recvGetLedger(newcoin::TMGetLedger& packet)
}
std::vector<SHAMapNode> nodeIDs;
std::list< std::vector<unsigned char> > rawNodes;
if(map->getNodeFat(mn, nodeIDs, rawNodes, fatLeaves))
if(map->getNodeFat(mn, nodeIDs, rawNodes, fatRoot, fatLeaves))
{
std::vector<SHAMapNode>::iterator nodeIDIterator;
std::list< std::vector<unsigned char> >::iterator rawNodeIterator;
@@ -1074,7 +1075,8 @@ void Peer::recvGetLedger(newcoin::TMGetLedger& packet)
}
}
}
if (packet.has_requestcookie()) reply.set_requestcookie(packet.requestcookie());
if (packet.has_requestcookie())
reply.set_requestcookie(packet.requestcookie());
PackedMessage::pointer oPacket = boost::make_shared<PackedMessage>(reply, newcoin::mtLEDGER_DATA);
sendPacket(oPacket);
}

View File

@@ -832,6 +832,9 @@ Json::Value RPCServer::doAccountWalletSet(const Json::Value& params) {
Json::Value RPCServer::doConnect(const Json::Value& params)
{
if (theConfig.RUN_STANDALONE)
return "cannot connect in standalone mode";
// connect <ip> [port]
std::string strIp;
int iPort = -1;

View File

@@ -327,7 +327,7 @@ public:
void getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint256>& hashes, int max,
SHAMapSyncFilter* filter);
bool getNodeFat(const SHAMapNode& node, std::vector<SHAMapNode>& nodeIDs,
std::list<std::vector<unsigned char> >& rawNode, bool fatLeaves);
std::list<std::vector<unsigned char> >& rawNode, bool fatRoot, bool fatLeaves);
bool getRootNode(Serializer& s, SHANodeFormat format);
bool addRootNode(const uint256& hash, const std::vector<unsigned char>& rootNode, SHANodeFormat format);
bool addRootNode(const std::vector<unsigned char>& rootNode, SHANodeFormat format);

View File

@@ -86,7 +86,7 @@ void SHAMap::getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint2
}
bool SHAMap::getNodeFat(const SHAMapNode& wanted, std::vector<SHAMapNode>& nodeIDs,
std::list<std::vector<unsigned char> >& rawNodes, bool fatLeaves)
std::list<std::vector<unsigned char> >& rawNodes, bool fatRoot, bool fatLeaves)
{ // Gets a node and some of its children
boost::recursive_mutex::scoped_lock sl(mLock);
@@ -102,7 +102,7 @@ bool SHAMap::getNodeFat(const SHAMapNode& wanted, std::vector<SHAMapNode>& nodeI
node->addRaw(s, snfWIRE);
rawNodes.push_back(s.peekData());
if (node->isRoot() || node->isLeaf()) // don't get a fat root, can't get a fat leaf
if ((!fatRoot && node->isRoot()) || node->isLeaf()) // don't get a fat root, can't get a fat leaf
return true;
for (int i = 0; i < 16; ++i)
@@ -141,7 +141,8 @@ bool SHAMap::addRootNode(const std::vector<unsigned char>& rootNode, SHANodeForm
}
SHAMapTreeNode::pointer node = boost::make_shared<SHAMapTreeNode>(SHAMapNode(), rootNode, 0, format);
if (!node) return false;
if (!node)
return false;
#ifdef DEBUG
node->dump();
@@ -444,7 +445,7 @@ BOOST_AUTO_TEST_CASE( SHAMapSync_test )
destination.setSynching();
if (!source.getNodeFat(SHAMapNode(), nodeIDs, gotNodes, (rand() % 2) == 0))
if (!source.getNodeFat(SHAMapNode(), nodeIDs, gotNodes, (rand() % 2) == 0, (rand() % 2) == 0))
{
Log(lsFATAL) << "GetNodeFat(root) fails";
BOOST_FAIL("GetNodeFat");
@@ -481,7 +482,7 @@ BOOST_AUTO_TEST_CASE( SHAMapSync_test )
// get as many nodes as possible based on this information
for (nodeIDIterator = nodeIDs.begin(); nodeIDIterator != nodeIDs.end(); ++nodeIDIterator)
{
if (!source.getNodeFat(*nodeIDIterator, gotNodeIDs, gotNodes, (rand() % 2) == 0))
if (!source.getNodeFat(*nodeIDIterator, gotNodeIDs, gotNodes, (rand() % 2) == 0, (rand() % 2) == 0))
{
Log(lsFATAL) << "GetNodeFat fails";
BOOST_FAIL("GetNodeFat");

View File

@@ -5,16 +5,18 @@
#include "LedgerTiming.h"
#include "Log.h"
bool ValidationCollection::addValidation(SerializedValidation::pointer val)
// #define VC_DEBUG
bool ValidationCollection::addValidation(SerializedValidation::pointer& val)
{
NewcoinAddress signer = val->getSignerPublic();
bool isCurrent = false;
if (theApp->getUNL().nodeInUNL(signer))
if (theApp->getUNL().nodeInUNL(signer) || val->isTrusted())
{
val->setTrusted();
uint32 now = theApp->getOPs().getCloseTimeNC();
uint32 valClose = val->getCloseTime();
if ((now > (valClose - 4)) && (now < (valClose + LEDGER_MAX_INTERVAL)))
if ((now > (valClose - LEDGER_EARLY_INTERVAL)) && (now < (valClose + LEDGER_VAL_INTERVAL)))
isCurrent = true;
else
Log(lsWARNING) << "Received stale validation now=" << now << ", close=" << valClose;
@@ -51,7 +53,7 @@ bool ValidationCollection::addValidation(SerializedValidation::pointer val)
}
Log(lsINFO) << "Val for " << hash.GetHex() << " from " << signer.humanNodePublic()
<< " added " << (val->isTrusted() ? "trusted" : "UNtrusted");
<< " added " << (val->isTrusted() ? "trusted/" : "UNtrusted/") << (isCurrent ? "current" : "stale");
return isCurrent;
}
@@ -81,8 +83,14 @@ void ValidationCollection::getValidationCount(const uint256& ledger, bool curren
if (isTrusted && currentOnly)
{
uint32 closeTime = vit->second->getCloseTime();
if ((now < closeTime) || (now > (closeTime + 2 * LEDGER_MAX_INTERVAL)))
if ((now < (closeTime - LEDGER_EARLY_INTERVAL)) || (now > (closeTime + LEDGER_VAL_INTERVAL)))
isTrusted = false;
else
{
#ifdef VC_DEBUG
Log(lsINFO) << "VC: Untrusted due to time " << ledger.GetHex();
#endif
}
}
if (isTrusted)
++trusted;
@@ -90,6 +98,9 @@ void ValidationCollection::getValidationCount(const uint256& ledger, bool curren
++untrusted;
}
}
#ifdef VC_DEBUG
Log(lsINFO) << "VC: " << ledger.GetHex() << "t:" << trusted << " u:" << untrusted;
#endif
}
int ValidationCollection::getTrustedValidationCount(const uint256& ledger)
@@ -129,22 +140,27 @@ boost::unordered_map<uint256, int> ValidationCollection::getCurrentValidations()
{
boost::mutex::scoped_lock sl(mValidationLock);
boost::unordered_map<uint160, ValidationPair>::iterator it = mCurrentValidations.begin();
bool anyNew = false;
while (it != mCurrentValidations.end())
{
ValidationPair& pair = it->second;
if (pair.oldest && (now > (pair.oldest->getCloseTime() + LEDGER_MAX_INTERVAL)))
if (pair.oldest && (now > (pair.oldest->getCloseTime() + LEDGER_VAL_INTERVAL)))
{
#ifdef VC_DEBUG
Log(lsINFO) << "VC: " << it->first.GetHex() << " removeOldestStale";
#endif
mStaleValidations.push_back(pair.oldest);
pair.oldest = SerializedValidation::pointer();
anyNew = true;
condWrite();
}
if (pair.newest && (now > (pair.newest->getCloseTime() + LEDGER_MAX_INTERVAL)))
if (pair.newest && (now > (pair.newest->getCloseTime() + LEDGER_VAL_INTERVAL)))
{
#ifdef VC_DEBUG
Log(lsINFO) << "VC: " << it->first.GetHex() << " removeNewestStale";
#endif
mStaleValidations.push_back(pair.newest);
pair.newest = SerializedValidation::pointer();
anyNew = true;
condWrite();
}
if (!pair.newest && !pair.oldest)
it = mCurrentValidations.erase(it);
@@ -152,21 +168,23 @@ boost::unordered_map<uint256, int> ValidationCollection::getCurrentValidations()
{
if (pair.oldest)
{
Log(lsTRACE) << "OLD " << pair.oldest->getLedgerHash().GetHex() << " " <<
#ifdef VC_DEBUG
Log(lsTRACE) << "VC: OLD " << pair.oldest->getLedgerHash().GetHex() << " " <<
boost::lexical_cast<std::string>(pair.oldest->getCloseTime());
#endif
++ret[pair.oldest->getLedgerHash()];
}
if (pair.newest)
{
Log(lsTRACE) << "NEW " << pair.newest->getLedgerHash().GetHex() << " " <<
#ifdef VC_DEBUG
Log(lsTRACE) << "VC: NEW " << pair.newest->getLedgerHash().GetHex() << " " <<
boost::lexical_cast<std::string>(pair.newest->getCloseTime());
#endif
++ret[pair.newest->getLedgerHash()];
}
++it;
}
}
if (anyNew)
condWrite();
}
return ret;
@@ -227,8 +245,7 @@ void ValidationCollection::condWrite()
void ValidationCollection::doWrite()
{
static boost::format insVal("INSERT INTO LedgerValidations "
"(LedgerHash,NodePubKey,Flags,CloseTime,Signature) VALUES "
"('%s','%s','%u','%u',%s);");
"(LedgerHash,NodePubKey,Flags,CloseTime,Signature) VALUES ('%s','%s','%u','%u',%s);");
boost::mutex::scoped_lock sl(mValidationLock);
assert(mWriting);

View File

@@ -38,7 +38,7 @@ protected:
public:
ValidationCollection() : mWriting(false) { ; }
bool addValidation(SerializedValidation::pointer);
bool addValidation(SerializedValidation::pointer&);
ValidationSet getValidations(const uint256& ledger);
void getValidationCount(const uint256& ledger, bool currentOnly, int& trusted, int& untrusted);

View File

@@ -93,6 +93,7 @@ int main(int argc, char* argv[])
("help,h", "Display this message.")
("conf", po::value<std::string>(), "Specify the configuration file.")
("rpc", "Perform rpc command (default).")
("standalone,a", "Run with no peers.")
("test,t", "Perform unit tests.")
("parameters", po::value< vector<string> >(), "Specify comma separated parameters.")
("verbose,v", "Increase log level")
@@ -145,6 +146,11 @@ int main(int argc, char* argv[])
if (!iResult)
{
theConfig.setup(vm.count("conf") ? vm["conf"].as<std::string>() : "");
if (vm.count("standalone"))
{
theConfig.RUN_STANDALONE = true;
}
}
if (iResult)