mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Merge branch 'master' of github.com:jedmccaleb/NewCoin
This commit is contained in:
@@ -44,10 +44,12 @@ void CanonicalTXSet::push_back(SerializedTransaction::pointer txn)
|
||||
mMap.insert(std::make_pair(CanonicalTXKey(effectiveAccount, txn->getSequence(), txn->getTransactionID()), txn));
|
||||
}
|
||||
|
||||
void CanonicalTXSet::eraseInc(iterator& it)
|
||||
CanonicalTXSet::iterator CanonicalTXSet::erase(const iterator& it)
|
||||
{
|
||||
iterator tmp = it++;
|
||||
mMap.erase(tmp);
|
||||
iterator tmp = it;
|
||||
++tmp;
|
||||
mMap.erase(it);
|
||||
return tmp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -39,8 +39,7 @@ public:
|
||||
CanonicalTXSet(const uint256& lclHash) : mSetHash(lclHash) { ; }
|
||||
|
||||
void push_back(SerializedTransaction::pointer txn);
|
||||
void erase(const iterator& it) { mMap.erase(it); }
|
||||
void eraseInc(iterator& it);
|
||||
iterator erase(const iterator& it);
|
||||
|
||||
iterator begin() { return mMap.begin(); }
|
||||
iterator end() { return mMap.end(); }
|
||||
|
||||
@@ -352,9 +352,7 @@ void ConnectionPool::peerDisconnected(Peer::pointer peer, const ipPort& ipPeer,
|
||||
|
||||
if (naPeer.isValid())
|
||||
{
|
||||
boost::unordered_map<NewcoinAddress, Peer::pointer>::iterator itCm;
|
||||
|
||||
itCm = mConnectedMap.find(naPeer);
|
||||
boost::unordered_map<NewcoinAddress, Peer::pointer>::iterator itCm = mConnectedMap.find(naPeer);
|
||||
|
||||
if (itCm == mConnectedMap.end())
|
||||
{
|
||||
@@ -369,9 +367,7 @@ void ConnectionPool::peerDisconnected(Peer::pointer peer, const ipPort& ipPeer,
|
||||
}
|
||||
}
|
||||
|
||||
boost::unordered_map<ipPort, Peer::pointer>::iterator itIp;
|
||||
|
||||
itIp = mIpMap.find(ipPeer);
|
||||
boost::unordered_map<ipPort, Peer::pointer>::iterator itIp = mIpMap.find(ipPeer);
|
||||
|
||||
if (itIp == mIpMap.end())
|
||||
{
|
||||
|
||||
@@ -370,10 +370,10 @@ bool LedgerAcquireMaster::hasLedger(const uint256& hash)
|
||||
return mLedgers.find(hash) != mLedgers.end();
|
||||
}
|
||||
|
||||
bool LedgerAcquireMaster::dropLedger(const uint256& hash)
|
||||
void LedgerAcquireMaster::dropLedger(const uint256& hash)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
return mLedgers.erase(hash);
|
||||
mLedgers.erase(hash);
|
||||
}
|
||||
|
||||
bool LedgerAcquireMaster::gotLedgerData(newcoin::TMLedgerData& packet, Peer::pointer peer)
|
||||
|
||||
@@ -128,7 +128,7 @@ public:
|
||||
LedgerAcquire::pointer findCreate(const uint256& hash);
|
||||
LedgerAcquire::pointer find(const uint256& hash);
|
||||
bool hasLedger(const uint256& ledgerHash);
|
||||
bool dropLedger(const uint256& ledgerHash);
|
||||
void dropLedger(const uint256& ledgerHash);
|
||||
bool gotLedgerData(newcoin::TMLedgerData& packet, Peer::pointer);
|
||||
};
|
||||
|
||||
|
||||
@@ -694,7 +694,7 @@ void LedgerConsensus::applyTransactions(SHAMap::pointer set, Ledger::pointer led
|
||||
if (result <= 0)
|
||||
{
|
||||
if (result == 0) ++successes;
|
||||
failedTransactions.eraseInc(it);
|
||||
it = failedTransactions.erase(it);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -704,7 +704,7 @@ void LedgerConsensus::applyTransactions(SHAMap::pointer set, Ledger::pointer led
|
||||
catch (...)
|
||||
{
|
||||
Log(lsWARNING) << " Throws";
|
||||
failedTransactions.eraseInc(it);
|
||||
it = failedTransactions.erase(it);
|
||||
}
|
||||
}
|
||||
} while (successes > 0);
|
||||
|
||||
@@ -246,15 +246,17 @@ RippleState::pointer NetworkOPs::getRippleState(const uint256& uLedger, const ui
|
||||
|
||||
void NetworkOPs::setStateTimer(int sec)
|
||||
{ // set timer early if ledger is closing
|
||||
uint64 consensusTime = mLedgerMaster->getCurrentLedger()->getCloseTimeNC() - LEDGER_WOBBLE_TIME;
|
||||
uint64 now = getNetworkTimeNC();
|
||||
|
||||
if ((mMode == omFULL) && !mConsensus)
|
||||
if (!mConsensus && ((mMode == omFULL) || (mMode == omTRACKING)))
|
||||
{
|
||||
if (now >= consensusTime) sec = 0;
|
||||
else if (sec > (consensusTime - now)) sec = (consensusTime - now);
|
||||
}
|
||||
uint64 consensusTime = mLedgerMaster->getCurrentLedger()->getCloseTimeNC() - LEDGER_WOBBLE_TIME;
|
||||
uint64 now = getNetworkTimeNC();
|
||||
|
||||
if ((mMode == omFULL) && !mConsensus)
|
||||
{
|
||||
if (now >= consensusTime) sec = 0;
|
||||
else if (sec > (consensusTime - now)) sec = (consensusTime - now);
|
||||
}
|
||||
}
|
||||
mNetTimer.expires_from_now(boost::posix_time::seconds(sec));
|
||||
mNetTimer.async_wait(boost::bind(&NetworkOPs::checkState, this, boost::asio::placeholders::error));
|
||||
}
|
||||
@@ -366,9 +368,9 @@ void NetworkOPs::checkState(const boost::system::error_code& result)
|
||||
if (switchLedgers)
|
||||
{
|
||||
Log(lsWARNING) << "We are not running on the consensus ledger";
|
||||
Log(lsINFO) << "Our LCL " << currentClosed->getHash().GetHex() ;
|
||||
Log(lsINFO) << "Net LCL " << closedLedger.GetHex() ;
|
||||
if ((mMode == omTRACKING) || (mMode == omFULL)) setMode(omTRACKING);
|
||||
Log(lsINFO) << "Our LCL " << currentClosed->getHash().GetHex();
|
||||
Log(lsINFO) << "Net LCL " << closedLedger.GetHex();
|
||||
if ((mMode == omTRACKING) || (mMode == omFULL)) setMode(omCONNECTED);
|
||||
Ledger::pointer consensus = mLedgerMaster->getLedgerByHash(closedLedger);
|
||||
if (!consensus)
|
||||
{
|
||||
@@ -412,7 +414,14 @@ 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 ((!switchLedgers) && theConfig.VALIDATION_SEED.isValid()) setMode(omFULL);
|
||||
if ((!switchLedgers) && theConfig.VALIDATION_SEED.isValid())
|
||||
{
|
||||
if (theApp->getOPs().getNetworkTimeNC() <
|
||||
(theApp->getMasterLedger().getCurrentLedger()->getCloseTimeNC() + 4))
|
||||
setMode(omFULL);
|
||||
else
|
||||
Log(lsWARNING) << "Too late to go to full, try next ledger";
|
||||
}
|
||||
}
|
||||
|
||||
if (mMode == omFULL)
|
||||
@@ -420,6 +429,12 @@ void NetworkOPs::checkState(const boost::system::error_code& result)
|
||||
// check if the ledger is bad enough to go to omTRACKING
|
||||
}
|
||||
|
||||
if (mMode != omFULL)
|
||||
{
|
||||
setStateTimer(4);
|
||||
return;
|
||||
}
|
||||
|
||||
int secondsToClose = theApp->getMasterLedger().getCurrentLedger()->getCloseTimeNC() -
|
||||
theApp->getOPs().getNetworkTimeNC();
|
||||
if ((!mConsensus) && (secondsToClose < LEDGER_WOBBLE_TIME)) // pre close wobble
|
||||
@@ -444,12 +459,15 @@ void NetworkOPs::switchLastClosedLedger(Ledger::pointer newLedger)
|
||||
Ledger::pointer openLedger = boost::make_shared<Ledger>(false, boost::ref(*newLedger));
|
||||
mLedgerMaster->switchLedgers(newLedger, openLedger);
|
||||
|
||||
if (getNetworkTimeNC() > openLedger->getCloseTimeNC())
|
||||
{ // this ledger has already closed
|
||||
}
|
||||
|
||||
newcoin::TMStatusChange s;
|
||||
s.set_newevent(newcoin::neSWITCHED_LEDGER);
|
||||
s.set_ledgerseq(newLedger->getLedgerSeq());
|
||||
s.set_networktime(theApp->getOPs().getNetworkTimeNC());
|
||||
uint256 plhash = newLedger->getParentHash();
|
||||
s.set_previousledgerhash(plhash.begin(), plhash.size());
|
||||
PackedMessage::pointer packet = boost::make_shared<PackedMessage>(s, newcoin::mtSTATUS_CHANGE);
|
||||
theApp->getConnectionPool().relayMessage(NULL, packet);
|
||||
}
|
||||
// vim:ts=4
|
||||
|
||||
int NetworkOPs::beginConsensus(Ledger::pointer closingLedger)
|
||||
{
|
||||
@@ -596,4 +614,23 @@ bool NetworkOPs::recvValidation(SerializedValidation::pointer val)
|
||||
return theApp->getValidations().addValidation(val);
|
||||
}
|
||||
|
||||
Json::Value NetworkOPs::getServerInfo()
|
||||
{
|
||||
Json::Value info = Json::objectValue;
|
||||
|
||||
switch (mMode)
|
||||
{
|
||||
case omDISCONNECTED: info["network_state"] = "disconected"; break;
|
||||
case omCONNECTED: info["network_state"] = "connected"; break;
|
||||
case omTRACKING: info["network_state"] = "tracking"; break;
|
||||
case omFULL: info["network_state"] = "validating"; break;
|
||||
default: info["network_state"] = "unknown";
|
||||
}
|
||||
|
||||
if (!theConfig.VALIDATION_SEED.isValid()) info["validation_seed"] = "none";
|
||||
else info["validation_seed"] = NewcoinAddress::createNodePublic(theConfig.VALIDATION_SEED).humanNodePublic();
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -127,6 +127,7 @@ public:
|
||||
int beginConsensus(Ledger::pointer closingLedger);
|
||||
void endConsensus();
|
||||
void setStateTimer(int seconds);
|
||||
Json::Value getServerInfo();
|
||||
|
||||
// client information retrieval functions
|
||||
std::vector< std::pair<uint32, uint256> >
|
||||
|
||||
@@ -1231,6 +1231,11 @@ Json::Value RPCServer::doSend(Json::Value& params)
|
||||
}
|
||||
}
|
||||
|
||||
Json::Value RPCServer::doServerInfo(Json::Value& params)
|
||||
{
|
||||
return theApp->getOPs().getServerInfo();
|
||||
}
|
||||
|
||||
// transit_set <seed> <paying_account> <transit_rate> <starts> <expires>
|
||||
Json::Value RPCServer::doTransitSet(Json::Value& params)
|
||||
{
|
||||
@@ -1988,6 +1993,7 @@ Json::Value RPCServer::doCommand(const std::string& command, Json::Value& params
|
||||
{ "password_set", &RPCServer::doPasswordSet, 2, 3, optNetwork },
|
||||
{ "peers", &RPCServer::doPeers, 0, 0, },
|
||||
{ "send", &RPCServer::doSend, 3, 7, optCurrent },
|
||||
{ "server_info", &RPCServer::doServerInfo, 0, 0, },
|
||||
{ "stop", &RPCServer::doStop, 0, 0, },
|
||||
{ "transit_set", &RPCServer::doTransitSet, 5, 5, optCurrent },
|
||||
{ "tx", &RPCServer::doTx, 1, 1, },
|
||||
|
||||
@@ -127,6 +127,7 @@ private:
|
||||
Json::Value doPasswordSet(Json::Value& params);
|
||||
Json::Value doPeers(Json::Value& params);
|
||||
Json::Value doSend(Json::Value& params);
|
||||
Json::Value doServerInfo(Json::Value& params);
|
||||
Json::Value doSessionClose(Json::Value& params);
|
||||
Json::Value doSessionOpen(Json::Value& params);
|
||||
Json::Value doStop(Json::Value& params);
|
||||
|
||||
Reference in New Issue
Block a user