mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Merge branch 'master' into continuousClose
This commit is contained in:
@@ -138,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);
|
||||
@@ -285,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();
|
||||
@@ -311,12 +312,11 @@ bool LedgerAcquire::takeBase(const std::string& data, Peer::pointer peer)
|
||||
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();
|
||||
@@ -339,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();
|
||||
@@ -371,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);
|
||||
@@ -428,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;
|
||||
@@ -446,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
|
||||
|
||||
@@ -387,7 +387,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))
|
||||
@@ -512,7 +512,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, prevLedger, theApp->getMasterLedger().getCurrentLedger()->getCloseTimeNC());
|
||||
|
||||
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())
|
||||
@@ -871,7 +878,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)
|
||||
{
|
||||
@@ -980,6 +995,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;
|
||||
@@ -1166,6 +1206,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()
|
||||
|
||||
@@ -323,6 +323,7 @@ public:
|
||||
SHAMapSyncFilter* filter);
|
||||
bool getNodeFat(const SHAMapNode& node, std::vector<SHAMapNode>& nodeIDs,
|
||||
std::list<std::vector<unsigned char> >& rawNode, bool fatLeaves);
|
||||
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,
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -122,6 +122,13 @@ bool SHAMap::getNodeFat(const SHAMapNode& wanted, std::vector<SHAMapNode>& nodeI
|
||||
return true;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user