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:
@@ -121,6 +121,7 @@ void Config::setup(const std::string& strConf)
|
||||
|
||||
// a new ledger every minute
|
||||
LEDGER_SECONDS = 60;
|
||||
LEDGER_CREATOR = false;
|
||||
|
||||
RPC_USER = "admin";
|
||||
RPC_PASSWORD = "pass";
|
||||
@@ -201,6 +202,9 @@ void Config::load()
|
||||
if (sectionSingleB(secConfig, SECTION_RPC_PORT, strTemp))
|
||||
RPC_PORT = boost::lexical_cast<int>(strTemp);
|
||||
|
||||
if (sectionSingleB(secConfig, "ledger_creator" , strTemp))
|
||||
LEDGER_CREATOR = boost::lexical_cast<bool>(strTemp);
|
||||
|
||||
if (sectionSingleB(secConfig, SECTION_RPC_ALLOW_REMOTE, strTemp))
|
||||
RPC_ALLOW_REMOTE = boost::lexical_cast<bool>(strTemp);
|
||||
|
||||
|
||||
@@ -54,12 +54,15 @@ public:
|
||||
std::vector<std::string> VALIDATORS; // Validators from newcoind.cfg.
|
||||
std::vector<std::string> IPS; // Peer IPs from newcoind.cfg.
|
||||
|
||||
|
||||
|
||||
// Network parameters
|
||||
int NETWORK_START_TIME; // The Unix time we start ledger 0.
|
||||
int TRANSACTION_FEE_BASE;
|
||||
int LEDGER_SECONDS;
|
||||
int LEDGER_PROPOSAL_DELAY_SECONDS;
|
||||
int LEDGER_AVALANCHE_SECONDS;
|
||||
bool LEDGER_CREATOR; // should be false unless we are starting a new ledger
|
||||
|
||||
// Note: The following parameters do not relate to the UNL or trust at all
|
||||
int NETWORK_QUORUM; // Minimum number of nodes to consider the network present
|
||||
|
||||
@@ -544,7 +544,7 @@ void ConnectionPool::peerVerified(Peer::pointer peer)
|
||||
|
||||
std::string strIpPort = str(boost::format("%s %d") % strIp % iPort);
|
||||
|
||||
Log(lsINFO) << str(boost::format("Pool: Scan: connected: %s %s %s (scanned)") % ADDRESS_SHARED(peer) % strIp % iPort);
|
||||
//Log(lsINFO) << str(boost::format("Pool: Scan: connected: %s %s %s (scanned)") % ADDRESS_SHARED(peer) % strIp % iPort);
|
||||
|
||||
if (peer->getNodePublic() == theApp->getWallet().getNodePublic())
|
||||
{
|
||||
@@ -628,7 +628,7 @@ void ConnectionPool::scanRefresh()
|
||||
|
||||
if (tpNow.is_not_a_date_time())
|
||||
{
|
||||
Log(lsINFO) << "Pool: Scan: stop.";
|
||||
//Log(lsINFO) << "Pool: Scan: stop.";
|
||||
|
||||
(void) mScanTimer.cancel();
|
||||
}
|
||||
@@ -643,8 +643,8 @@ void ConnectionPool::scanRefresh()
|
||||
|
||||
tpNext = tpNow + boost::posix_time::seconds(iInterval);
|
||||
|
||||
Log(lsINFO) << str(boost::format("Pool: Scan: Now: %s %s (next %s, delay=%d)")
|
||||
% mScanIp % mScanPort % tpNext % (tpNext-tpNow).total_seconds());
|
||||
//Log(lsINFO) << str(boost::format("Pool: Scan: Now: %s %s (next %s, delay=%d)")
|
||||
// % mScanIp % mScanPort % tpNext % (tpNext-tpNow).total_seconds());
|
||||
|
||||
iInterval *= 2;
|
||||
|
||||
@@ -668,8 +668,8 @@ void ConnectionPool::scanRefresh()
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(lsINFO) << str(boost::format("Pool: Scan: Next: %s (next %s, delay=%d)")
|
||||
% strIpPort % tpNext % (tpNext-tpNow).total_seconds());
|
||||
//Log(lsINFO) << str(boost::format("Pool: Scan: Next: %s (next %s, delay=%d)")
|
||||
// % strIpPort % tpNext % (tpNext-tpNow).total_seconds());
|
||||
|
||||
mScanTimer.expires_at(tpNext);
|
||||
mScanTimer.async_wait(boost::bind(&ConnectionPool::scanHandler, this, _1));
|
||||
|
||||
@@ -17,6 +17,7 @@ HashedObjectStore::HashedObjectStore(int cacheSize, int cacheAge) :
|
||||
bool HashedObjectStore::store(HashedObjectType type, uint32 index,
|
||||
const std::vector<unsigned char>& data, const uint256& hash)
|
||||
{ // return: false=already in cache, true = added to cache
|
||||
assert(hash == Serializer::getSHA512Half(data));
|
||||
if (!theApp->getHashNodeDB()) return true;
|
||||
if (mCache.touch(hash))
|
||||
{
|
||||
@@ -25,7 +26,7 @@ bool HashedObjectStore::store(HashedObjectType type, uint32 index,
|
||||
}
|
||||
|
||||
HashedObject::pointer object = boost::make_shared<HashedObject>(type, index, data, hash);
|
||||
|
||||
if (!mCache.canonicalize(hash, object))
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mWriteMutex);
|
||||
mWriteSet.push_back(object);
|
||||
@@ -126,6 +127,8 @@ HashedObject::pointer HashedObjectStore::retrieve(const uint256& hash)
|
||||
db->getBinary("Object", &(data.front()), size);
|
||||
db->endIterRows();
|
||||
|
||||
assert(Serializer::getSHA512Half(data) == hash);
|
||||
|
||||
HashedObjectType htype = UNKNOWN;
|
||||
switch(type[0])
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
#include "Application.h"
|
||||
#include "Log.h"
|
||||
#include "SHAMapSync.h"
|
||||
#include "HashPrefixes.h"
|
||||
|
||||
#define LA_DEBUG
|
||||
#define LEDGER_ACQUIRE_TIMEOUT 2
|
||||
@@ -137,6 +138,7 @@ void LedgerAcquire::trigger(Peer::pointer peer)
|
||||
newcoin::TMGetLedger tmGL;
|
||||
tmGL.set_ledgerhash(mHash.begin(), mHash.size());
|
||||
tmGL.set_itype(newcoin::liBASE);
|
||||
*(tmGL.add_nodeids()) = SHAMapNode().getRawString();
|
||||
if (peer)
|
||||
{
|
||||
sendRequest(tmGL, peer);
|
||||
@@ -284,7 +286,7 @@ void PeerSet::sendRequest(const newcoin::TMGetLedger& tmGL)
|
||||
}
|
||||
}
|
||||
|
||||
bool LedgerAcquire::takeBase(const std::string& data, Peer::pointer peer)
|
||||
bool LedgerAcquire::takeBase(const std::string& data)
|
||||
{ // Return value: true=normal, false=bad data
|
||||
#ifdef LA_DEBUG
|
||||
Log(lsTRACE) << "got base acquiring ledger " << mHash.GetHex();
|
||||
@@ -300,17 +302,21 @@ bool LedgerAcquire::takeBase(const std::string& data, Peer::pointer peer)
|
||||
return false;
|
||||
}
|
||||
mHaveBase = true;
|
||||
theApp->getHashedObjectStore().store(LEDGER, mLedger->getLedgerSeq(), strCopy(data), mHash);
|
||||
|
||||
Serializer s(data.size() + 4);
|
||||
s.add32(sHP_Ledger);
|
||||
s.addRaw(data);
|
||||
theApp->getHashedObjectStore().store(LEDGER, mLedger->getLedgerSeq(), s.peekData(), mHash);
|
||||
|
||||
progress();
|
||||
if (!mLedger->getTransHash()) mHaveTransactions = true;
|
||||
if (!mLedger->getAccountHash()) mHaveState = true;
|
||||
mLedger->setAcquiring();
|
||||
trigger(peer);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LedgerAcquire::takeTxNode(const std::list<SHAMapNode>& nodeIDs,
|
||||
const std::list< std::vector<unsigned char> >& data, Peer::pointer peer)
|
||||
const std::list< std::vector<unsigned char> >& data)
|
||||
{
|
||||
if (!mHaveBase) return false;
|
||||
std::list<SHAMapNode>::const_iterator nodeIDit = nodeIDs.begin();
|
||||
@@ -320,7 +326,7 @@ bool LedgerAcquire::takeTxNode(const std::list<SHAMapNode>& nodeIDs,
|
||||
{
|
||||
if (nodeIDit->isRoot())
|
||||
{
|
||||
if (!mLedger->peekTransactionMap()->addRootNode(mLedger->getTransHash(), *nodeDatait))
|
||||
if (!mLedger->peekTransactionMap()->addRootNode(mLedger->getTransHash(), *nodeDatait, STN_ARF_WIRE))
|
||||
return false;
|
||||
}
|
||||
else if (!mLedger->peekTransactionMap()->addKnownNode(*nodeIDit, *nodeDatait, &tFilter))
|
||||
@@ -333,13 +339,12 @@ bool LedgerAcquire::takeTxNode(const std::list<SHAMapNode>& nodeIDs,
|
||||
mHaveTransactions = true;
|
||||
if (mHaveState) mComplete = true;
|
||||
}
|
||||
trigger(peer);
|
||||
progress();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LedgerAcquire::takeAsNode(const std::list<SHAMapNode>& nodeIDs,
|
||||
const std::list< std::vector<unsigned char> >& data, Peer::pointer peer)
|
||||
const std::list< std::vector<unsigned char> >& data)
|
||||
{
|
||||
#ifdef LA_DEBUG
|
||||
Log(lsTRACE) << "got ASdata acquiring ledger " << mHash.GetHex();
|
||||
@@ -352,7 +357,7 @@ bool LedgerAcquire::takeAsNode(const std::list<SHAMapNode>& nodeIDs,
|
||||
{
|
||||
if (nodeIDit->isRoot())
|
||||
{
|
||||
if (!mLedger->peekAccountStateMap()->addRootNode(mLedger->getAccountHash(), *nodeDatait))
|
||||
if (!mLedger->peekAccountStateMap()->addRootNode(mLedger->getAccountHash(), *nodeDatait, STN_ARF_WIRE))
|
||||
return false;
|
||||
}
|
||||
else if (!mLedger->peekAccountStateMap()->addKnownNode(*nodeIDit, *nodeDatait, &tFilter))
|
||||
@@ -365,11 +370,22 @@ bool LedgerAcquire::takeAsNode(const std::list<SHAMapNode>& nodeIDs,
|
||||
mHaveState = true;
|
||||
if (mHaveTransactions) mComplete = true;
|
||||
}
|
||||
trigger(peer);
|
||||
progress();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LedgerAcquire::takeAsRootNode(const std::vector<unsigned char>& data)
|
||||
{
|
||||
if (!mHaveBase) return false;
|
||||
return mLedger->peekAccountStateMap()->addRootNode(mLedger->getAccountHash(), data, STN_ARF_WIRE);
|
||||
}
|
||||
|
||||
bool LedgerAcquire::takeTxRootNode(const std::vector<unsigned char>& data)
|
||||
{
|
||||
if (!mHaveBase) return false;
|
||||
return mLedger->peekTransactionMap()->addRootNode(mLedger->getTransHash(), data, STN_ARF_WIRE);
|
||||
}
|
||||
|
||||
LedgerAcquire::pointer LedgerAcquireMaster::findCreate(const uint256& hash)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
@@ -422,11 +438,34 @@ bool LedgerAcquireMaster::gotLedgerData(newcoin::TMLedgerData& packet, Peer::poi
|
||||
|
||||
if (packet.type() == newcoin::liBASE)
|
||||
{
|
||||
if (packet.nodes_size() != 1) return false;
|
||||
if (packet.nodes_size() < 1)
|
||||
return false;
|
||||
const newcoin::TMLedgerNode& node = packet.nodes(0);
|
||||
return ledger->takeBase(node.nodedata(), peer);
|
||||
if (!ledger->takeBase(node.nodedata()))
|
||||
return false;
|
||||
if (packet.nodes_size() == 1)
|
||||
{
|
||||
ledger->trigger(peer);
|
||||
return true;
|
||||
}
|
||||
Log(lsDEBUG) << "liBASE includes ASbase";
|
||||
if (!ledger->takeAsRootNode(strCopy(packet.nodes(1).nodedata())))
|
||||
{
|
||||
Log(lsWARNING) << "Included ASbase invalid";
|
||||
}
|
||||
if (packet.nodes().size() == 2)
|
||||
{
|
||||
ledger->trigger(peer);
|
||||
return true;
|
||||
}
|
||||
Log(lsDEBUG) << "liBASE includes TXbase";
|
||||
if (!ledger->takeTxRootNode(strCopy(packet.nodes(2).nodedata())))
|
||||
Log(lsWARNING) << "Invcluded TXbase invalid";
|
||||
ledger->trigger(peer);
|
||||
return true;
|
||||
}
|
||||
else if ((packet.type() == newcoin::liTX_NODE) || (packet.type() == newcoin::liAS_NODE))
|
||||
|
||||
if ((packet.type() == newcoin::liTX_NODE) || (packet.type() == newcoin::liAS_NODE))
|
||||
{
|
||||
std::list<SHAMapNode> nodeIDs;
|
||||
std::list< std::vector<unsigned char> > nodeData;
|
||||
@@ -440,8 +479,14 @@ bool LedgerAcquireMaster::gotLedgerData(newcoin::TMLedgerData& packet, Peer::poi
|
||||
nodeIDs.push_back(SHAMapNode(node.nodeid().data(), node.nodeid().size()));
|
||||
nodeData.push_back(std::vector<unsigned char>(node.nodedata().begin(), node.nodedata().end()));
|
||||
}
|
||||
if (packet.type() == newcoin::liTX_NODE) return ledger->takeTxNode(nodeIDs, nodeData, peer);
|
||||
else return ledger->takeAsNode(nodeIDs, nodeData, peer);
|
||||
bool ret;
|
||||
if (packet.type() == newcoin::liTX_NODE)
|
||||
ret = ledger->takeTxNode(nodeIDs, nodeData);
|
||||
else
|
||||
ret = ledger->takeAsNode(nodeIDs, nodeData);
|
||||
if (ret)
|
||||
ledger->trigger(peer);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -73,7 +73,6 @@ protected:
|
||||
void onTimer() { trigger(Peer::pointer()); }
|
||||
|
||||
void newPeer(Peer::pointer peer) { trigger(peer); }
|
||||
void trigger(Peer::pointer);
|
||||
|
||||
boost::weak_ptr<PeerSet> pmDowncast();
|
||||
|
||||
@@ -87,11 +86,12 @@ public:
|
||||
|
||||
void addOnComplete(boost::function<void (LedgerAcquire::pointer)>);
|
||||
|
||||
bool takeBase(const std::string& data, Peer::pointer);
|
||||
bool takeTxNode(const std::list<SHAMapNode>& IDs, const std::list<std::vector<unsigned char> >& data,
|
||||
Peer::pointer);
|
||||
bool takeAsNode(const std::list<SHAMapNode>& IDs, const std::list<std::vector<unsigned char> >& data,
|
||||
Peer::pointer);
|
||||
bool takeBase(const std::string& data);
|
||||
bool takeTxNode(const std::list<SHAMapNode>& IDs, const std::list<std::vector<unsigned char> >& data);
|
||||
bool takeTxRootNode(const std::vector<unsigned char>& data);
|
||||
bool takeAsNode(const std::list<SHAMapNode>& IDs, const std::list<std::vector<unsigned char> >& data);
|
||||
bool takeAsRootNode(const std::vector<unsigned char>& data);
|
||||
void trigger(Peer::pointer);
|
||||
};
|
||||
|
||||
class LedgerAcquireMaster
|
||||
|
||||
@@ -101,7 +101,7 @@ bool TransactionAcquire::takeNodes(const std::list<SHAMapNode>& nodeIDs,
|
||||
Log(lsWARNING) << "Got root TXS node, already have it";
|
||||
return false;
|
||||
}
|
||||
if (!mMap->addRootNode(getHash(), *nodeDatait))
|
||||
if (!mMap->addRootNode(getHash(), *nodeDatait, STN_ARF_WIRE))
|
||||
return false;
|
||||
else mHaveRoot = true;
|
||||
}
|
||||
|
||||
@@ -369,10 +369,15 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerLis
|
||||
}
|
||||
|
||||
Ledger::pointer ourClosed = mLedgerMaster->getClosedLedger();
|
||||
uint256 closedLedger = ourClosed->getHash();
|
||||
ValidationCount& ourVC = ledgers[closedLedger];
|
||||
++ourVC.nodesUsing;
|
||||
ourVC.highNode = theApp->getWallet().getNodePublic();
|
||||
uint256 closedLedger=0;
|
||||
if(theConfig.LEDGER_CREATOR || ourClosed->getLedgerSeq() > 100)
|
||||
{
|
||||
closedLedger = ourClosed->getHash();
|
||||
ValidationCount& ourVC = ledgers[closedLedger];
|
||||
++ourVC.nodesUsing;
|
||||
ourVC.highNode = theApp->getWallet().getNodePublic();
|
||||
}
|
||||
|
||||
|
||||
for (std::vector<Peer::pointer>::const_iterator it = peerList.begin(), end = peerList.end(); it != end; ++it)
|
||||
{
|
||||
@@ -383,7 +388,7 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerLis
|
||||
else if ((*it)->isConnected())
|
||||
{
|
||||
uint256 peerLedger = (*it)->getClosedLedgerHash();
|
||||
if (!!peerLedger)
|
||||
if (peerLedger.isNonZero())
|
||||
{
|
||||
ValidationCount& vc = ledgers[peerLedger];
|
||||
if ((vc.nodesUsing == 0) || ((*it)->getNodePublic() > vc.highNode))
|
||||
@@ -508,7 +513,8 @@ int NetworkOPs::beginConsensus(const uint256& networkClosed, Ledger::pointer clo
|
||||
assert(closingLedger->getParentHash() == mLedgerMaster->getClosedLedger()->getHash());
|
||||
|
||||
// Create a consensus object to get consensus on this ledger
|
||||
if (!!mConsensus) mConsensus->abort();
|
||||
if (!!mConsensus)
|
||||
mConsensus->abort();
|
||||
prevLedger->setImmutable();
|
||||
mConsensus = boost::make_shared<LedgerConsensus>(
|
||||
networkClosed,
|
||||
@@ -798,13 +804,6 @@ void NetworkOPs::pubLedger(const Ledger::pointer& lpAccepted)
|
||||
|
||||
Json::Value NetworkOPs::transJson(const SerializedTransaction& stTxn, TransactionEngineResult terResult, const std::string& strStatus, int iSeq, const std::string& strType)
|
||||
{
|
||||
Json::Value jvAccounts(Json::arrayValue);
|
||||
|
||||
BOOST_FOREACH(const NewcoinAddress& naAccountID, stTxn.getAffectedAccounts())
|
||||
{
|
||||
jvAccounts.append(Json::Value(naAccountID.humanAccountID()));
|
||||
}
|
||||
|
||||
Json::Value jvObj(Json::objectValue);
|
||||
std::string strToken;
|
||||
std::string strHuman;
|
||||
@@ -812,12 +811,10 @@ Json::Value NetworkOPs::transJson(const SerializedTransaction& stTxn, Transactio
|
||||
transResultInfo(terResult, strToken, strHuman);
|
||||
|
||||
jvObj["type"] = strType;
|
||||
jvObj["seq"] = iSeq;
|
||||
jvObj["accounts"] = jvAccounts;
|
||||
jvObj["transaction"] = stTxn.getJson(0);
|
||||
jvObj["status"] = strStatus;
|
||||
jvObj["transaction"]["inLedger"] = iSeq;
|
||||
jvObj["transaction"]["status"] = strStatus;
|
||||
jvObj["result"] = strToken;
|
||||
jvObj["result_message"] = strHuman;
|
||||
jvObj["result_code"] = terResult;
|
||||
|
||||
return jvObj;
|
||||
|
||||
61
src/Peer.cpp
61
src/Peer.cpp
@@ -571,7 +571,14 @@ void Peer::recvHello(newcoin::TMHello& packet)
|
||||
// Cancel verification timeout.
|
||||
(void) mVerifyTimer.cancel();
|
||||
|
||||
if (packet.protoversionmin() < MAKE_VERSION_INT(MIN_PROTO_MAJOR, MIN_PROTO_MINOR))
|
||||
uint64 minTime = theApp->getOPs().getNetworkTimeNC() - 4;
|
||||
uint64 maxTime = minTime + 8;
|
||||
|
||||
if (packet.has_nettime() && ((packet.nettime() < minTime) || (packet.nettime() > maxTime)))
|
||||
{
|
||||
Log(lsINFO) << "Recv(Hello): Disconnect: Clocks are too far off";
|
||||
}
|
||||
else if (packet.protoversionmin() < MAKE_VERSION_INT(MIN_PROTO_MAJOR, MIN_PROTO_MINOR))
|
||||
{
|
||||
Log(lsINFO) << "Recv(Hello): Server requires protocol version " <<
|
||||
GET_VERSION_MAJOR(packet.protoversion()) << "." << GET_VERSION_MINOR(packet.protoversion())
|
||||
@@ -870,7 +877,15 @@ void Peer::recvStatus(newcoin::TMStatusChange& packet)
|
||||
Log(lsTRACE) << "Received status change from peer " << getIP();
|
||||
if (!packet.has_networktime())
|
||||
packet.set_networktime(theApp->getOPs().getNetworkTimeNC());
|
||||
mLastStatus = packet;
|
||||
|
||||
if (!mLastStatus.has_newstatus() || packet.has_newstatus())
|
||||
mLastStatus = packet;
|
||||
else
|
||||
{ // preserve old status
|
||||
newcoin::NodeStatus status = mLastStatus.newstatus();
|
||||
mLastStatus = packet;
|
||||
packet.set_newstatus(status);
|
||||
}
|
||||
|
||||
if (packet.newevent() == newcoin::neLOST_SYNC)
|
||||
{
|
||||
@@ -979,6 +994,31 @@ void Peer::recvGetLedger(newcoin::TMGetLedger& packet)
|
||||
Serializer nData(128);
|
||||
ledger->addRaw(nData);
|
||||
reply.add_nodes()->set_nodedata(nData.getDataPtr(), nData.getLength());
|
||||
|
||||
if (packet.nodeids().size() != 0)
|
||||
{
|
||||
Log(lsINFO) << "Ledger root w/map roots request";
|
||||
SHAMap::pointer map = ledger->peekAccountStateMap();
|
||||
if (map)
|
||||
{
|
||||
Serializer rootNode(768);
|
||||
if (map->getRootNode(rootNode, STN_ARF_WIRE))
|
||||
{
|
||||
reply.add_nodes()->set_nodedata(rootNode.getDataPtr(), rootNode.getLength());
|
||||
if (ledger->getTransHash().isNonZero())
|
||||
{
|
||||
map = ledger->peekTransactionMap();
|
||||
if (map)
|
||||
{
|
||||
rootNode.resize(0);
|
||||
if (map->getRootNode(rootNode, STN_ARF_WIRE))
|
||||
reply.add_nodes()->set_nodedata(rootNode.getDataPtr(), rootNode.getLength());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PackedMessage::pointer oPacket = boost::make_shared<PackedMessage>(reply, newcoin::mtLEDGER_DATA);
|
||||
sendPacket(oPacket);
|
||||
return;
|
||||
@@ -1165,6 +1205,23 @@ Json::Value Peer::getJson()
|
||||
(mHello.protoversion() != MAKE_VERSION_INT(PROTO_VERSION_MAJOR, PROTO_VERSION_MINOR)))
|
||||
ret["protocol"] = boost::lexical_cast<std::string>(GET_VERSION_MAJOR(mHello.protoversion())) + "." +
|
||||
boost::lexical_cast<std::string>(GET_VERSION_MINOR(mHello.protoversion()));
|
||||
|
||||
if (!!mClosedLedgerHash)
|
||||
ret["ledger"] = mClosedLedgerHash.GetHex();
|
||||
|
||||
if (mLastStatus.has_newstatus())
|
||||
{
|
||||
switch (mLastStatus.newstatus())
|
||||
{
|
||||
case newcoin::nsCONNECTING: ret["status"] = "connecting"; break;
|
||||
case newcoin::nsCONNECTED: ret["status"] = "connected"; break;
|
||||
case newcoin::nsMONITORING: ret["status"] = "monitoring"; break;
|
||||
case newcoin::nsVALIDATING: ret["status"] = "validating"; break;
|
||||
case newcoin::nsSHUTTING: ret["status"] = "shutting"; break;
|
||||
default: Log(lsWARNING) << "Peer has unknown status: " << mLastStatus.newstatus();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (!mIpPort.first.empty())
|
||||
{
|
||||
|
||||
@@ -630,11 +630,19 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeExternal(const SHAMapNode& id, const ui
|
||||
throw SHAMapMissingNode(id, hash);
|
||||
assert(Serializer::getSHA512Half(obj->getData()) == hash);
|
||||
|
||||
SHAMapTreeNode::pointer ret = boost::make_shared<SHAMapTreeNode>(id, obj->getData(), mSeq, STN_ARF_PREFIXED);
|
||||
try
|
||||
{
|
||||
SHAMapTreeNode::pointer ret = boost::make_shared<SHAMapTreeNode>(id, obj->getData(), mSeq, STN_ARF_PREFIXED);
|
||||
#ifdef DEBUG
|
||||
assert((ret->getNodeHash() == hash) && (id == *ret));
|
||||
assert((ret->getNodeHash() == hash) && (id == *ret));
|
||||
#endif
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
Log(lsWARNING) << "fetchNodeExternal gets an invalid node: " << hash.GetHex();
|
||||
throw SHAMapMissingNode(id, hash);
|
||||
}
|
||||
}
|
||||
|
||||
void SHAMap::armDirty()
|
||||
|
||||
11
src/SHAMap.h
11
src/SHAMap.h
@@ -157,11 +157,11 @@ public:
|
||||
SHAMapTreeNode(const SHAMapTreeNode& node, uint32 seq); // copy node from older tree
|
||||
SHAMapTreeNode(const SHAMapNode& nodeID, SHAMapItem::pointer item, TNType type, uint32 seq);
|
||||
|
||||
// raw node functions
|
||||
SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned char>& contents, uint32 seq, int format);
|
||||
|
||||
#define STN_ARF_PREFIXED 1
|
||||
#define STN_ARF_WIRE 2
|
||||
|
||||
// raw node functions
|
||||
SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned char>& contents, uint32 seq, int format);
|
||||
void addRaw(Serializer &, int format);
|
||||
|
||||
virtual bool isPopulated() const { return true; }
|
||||
@@ -323,8 +323,9 @@ public:
|
||||
SHAMapSyncFilter* filter);
|
||||
bool getNodeFat(const SHAMapNode& node, std::vector<SHAMapNode>& nodeIDs,
|
||||
std::list<std::vector<unsigned char> >& rawNode, bool fatLeaves);
|
||||
bool addRootNode(const uint256& hash, const std::vector<unsigned char>& rootNode);
|
||||
bool addRootNode(const std::vector<unsigned char>& rootNode);
|
||||
bool getRootNode(Serializer& s, int format);
|
||||
bool addRootNode(const uint256& hash, const std::vector<unsigned char>& rootNode, int format);
|
||||
bool addRootNode(const std::vector<unsigned char>& rootNode, int format);
|
||||
bool addKnownNode(const SHAMapNode& nodeID, const std::vector<unsigned char>& rawNode,
|
||||
SHAMapSyncFilter* filter);
|
||||
|
||||
|
||||
@@ -247,7 +247,10 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned
|
||||
if (format == STN_ARF_PREFIXED)
|
||||
{
|
||||
if (rawNode.size() < 4)
|
||||
{
|
||||
Log(lsINFO) << "size < 4";
|
||||
throw std::runtime_error("invalid P node");
|
||||
}
|
||||
|
||||
uint32 prefix = rawNode[0]; prefix <<= 8; prefix |= rawNode[1]; prefix <<= 8;
|
||||
prefix |= rawNode[2]; prefix <<= 8; prefix |= rawNode[3];
|
||||
@@ -255,19 +258,23 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned
|
||||
|
||||
if (prefix == sHP_TransactionID)
|
||||
{
|
||||
mItem = boost::make_shared<SHAMapItem>(Serializer::getSHA512Half(rawNode), s.peekData());
|
||||
mItem = boost::make_shared<SHAMapItem>(s.getSHA512Half(), s.peekData());
|
||||
mType = tnTRANSACTION;
|
||||
}
|
||||
if (prefix == sHP_LeafNode)
|
||||
else if (prefix == sHP_LeafNode)
|
||||
{
|
||||
uint256 u;
|
||||
s.get256(u, s.getLength() - 32);
|
||||
s.chop(256 / 8);
|
||||
if (u.isZero()) throw std::runtime_error("invalid PLN node");
|
||||
s.chop(32);
|
||||
if (u.isZero())
|
||||
{
|
||||
Log(lsINFO) << "invalid PLN node";
|
||||
throw std::runtime_error("invalid PLN node");
|
||||
}
|
||||
mItem = boost::make_shared<SHAMapItem>(u, s.peekData());
|
||||
mType = tnACCOUNT_STATE;
|
||||
}
|
||||
if (prefix == sHP_InnerNode)
|
||||
else if (prefix == sHP_InnerNode)
|
||||
{
|
||||
if (rawNode.size() != (512 + 4))
|
||||
throw std::runtime_error("invalid PIN node");
|
||||
@@ -276,7 +283,10 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned
|
||||
mType = tnINNER;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log(lsINFO) << "Unknown node prefix " << std::hex << prefix << std::dec;
|
||||
throw std::runtime_error("invalid node prefix");
|
||||
}
|
||||
}
|
||||
|
||||
updateHash();
|
||||
|
||||
@@ -58,7 +58,7 @@ void SHAMap::getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint2
|
||||
std::vector<unsigned char> nodeData;
|
||||
if (filter->haveNode(childID, childHash, nodeData))
|
||||
{
|
||||
d = boost::make_shared<SHAMapTreeNode>(childID, nodeData, mSeq, STN_ARF_WIRE);
|
||||
d = boost::make_shared<SHAMapTreeNode>(childID, nodeData, mSeq, STN_ARF_PREFIXED);
|
||||
if (childHash != d->getNodeHash())
|
||||
{
|
||||
Log(lsERROR) << "Wrong hash from cached object";
|
||||
@@ -122,7 +122,14 @@ bool SHAMap::getNodeFat(const SHAMapNode& wanted, std::vector<SHAMapNode>& nodeI
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SHAMap::addRootNode(const std::vector<unsigned char>& rootNode)
|
||||
bool SHAMap::getRootNode(Serializer& s, int format)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
root->addRaw(s, format);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SHAMap::addRootNode(const std::vector<unsigned char>& rootNode, int format)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
|
||||
@@ -133,7 +140,7 @@ bool SHAMap::addRootNode(const std::vector<unsigned char>& rootNode)
|
||||
return true;
|
||||
}
|
||||
|
||||
SHAMapTreeNode::pointer node = boost::make_shared<SHAMapTreeNode>(SHAMapNode(), rootNode, 0, STN_ARF_WIRE);
|
||||
SHAMapTreeNode::pointer node = boost::make_shared<SHAMapTreeNode>(SHAMapNode(), rootNode, 0, format);
|
||||
if (!node) return false;
|
||||
|
||||
#ifdef DEBUG
|
||||
@@ -153,7 +160,7 @@ bool SHAMap::addRootNode(const std::vector<unsigned char>& rootNode)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SHAMap::addRootNode(const uint256& hash, const std::vector<unsigned char>& rootNode)
|
||||
bool SHAMap::addRootNode(const uint256& hash, const std::vector<unsigned char>& rootNode, int format)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
|
||||
@@ -165,7 +172,7 @@ bool SHAMap::addRootNode(const uint256& hash, const std::vector<unsigned char>&
|
||||
return true;
|
||||
}
|
||||
|
||||
SHAMapTreeNode::pointer node = boost::make_shared<SHAMapTreeNode>(SHAMapNode(), rootNode, 0, STN_ARF_WIRE);
|
||||
SHAMapTreeNode::pointer node = boost::make_shared<SHAMapTreeNode>(SHAMapNode(), rootNode, 0, format);
|
||||
if (!node)
|
||||
return false;
|
||||
if (node->getNodeHash() != hash)
|
||||
@@ -234,7 +241,11 @@ bool SHAMap::addKnownNode(const SHAMapNode& node, const std::vector<unsigned cha
|
||||
return false;
|
||||
|
||||
if (filter)
|
||||
filter->gotNode(node, hash, rawNode, newNode->isLeaf());
|
||||
{
|
||||
Serializer s;
|
||||
newNode->addRaw(s, STN_ARF_PREFIXED);
|
||||
filter->gotNode(node, hash, s.peekData(), newNode->isLeaf());
|
||||
}
|
||||
|
||||
mTNByID[*newNode] = newNode;
|
||||
if (!newNode->isLeaf())
|
||||
@@ -443,7 +454,7 @@ BOOST_AUTO_TEST_CASE( SHAMapSync_test )
|
||||
Log(lsFATAL) << "Didn't get root node " << gotNodes.size();
|
||||
BOOST_FAIL("NodeSize");
|
||||
}
|
||||
if (!destination.addRootNode(*gotNodes.begin()))
|
||||
if (!destination.addRootNode(*gotNodes.begin(), STN_ARF_WIRE))
|
||||
{
|
||||
Log(lsFATAL) << "AddRootNode fails";
|
||||
BOOST_FAIL("AddRootNode");
|
||||
|
||||
Reference in New Issue
Block a user