mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
This makes more sense. Fetch pack, phase one.
This commit is contained in:
@@ -2009,6 +2009,8 @@ void NetworkOPs::getBookPage(Ledger::pointer lpLedger, const uint160& uTakerPays
|
||||
void NetworkOPs::makeFetchPack(Job&, boost::weak_ptr<Peer> wPeer, boost::shared_ptr<ripple::TMGetObjectByHash> request,
|
||||
Ledger::pointer prevLedger, Ledger::pointer reqLedger)
|
||||
{
|
||||
try
|
||||
{
|
||||
Peer::pointer peer = wPeer.lock();
|
||||
if (!peer)
|
||||
return;
|
||||
@@ -2019,35 +2021,34 @@ void NetworkOPs::makeFetchPack(Job&, boost::weak_ptr<Peer> wPeer, boost::shared_
|
||||
reply.set_seq(request->seq());
|
||||
reply.set_ledgerhash(reply.ledgerhash());
|
||||
|
||||
// WRITEME
|
||||
#if 0
|
||||
std::list< std::pair<uint256, std::vector<unsigned char> > > pack1 = getSyncInfo(prevLedger->peekAccountStateMap(),
|
||||
reqLedger->peekAccountStateMap(), 1024);
|
||||
|
||||
typedef std::pair< uint256, std::vector<unsigned char> > uvpair_t;
|
||||
BOOST_FOREACH(uvpair_t& node, pack1)
|
||||
std::list<SHAMap::fetchPackEntry_t> pack =
|
||||
reqLedger->peekAccountStateMap()->getFetchPack(prevLedger->peekAccountStateMap().get(), false, 1024);
|
||||
BOOST_FOREACH(SHAMap::fetchPackEntry_t& node, pack)
|
||||
{
|
||||
ripple::TMIndexedObject& newObj = *reply.add_objects();
|
||||
newObj.set_hash(node.first.begin(), 256 / 8);
|
||||
newObj.set_data(&node.second[0], node.second.size());
|
||||
}
|
||||
|
||||
if (reqLedger->getAccountHash().isNonZero())
|
||||
if (reqLedger->getAccountHash().isNonZero() && (pack.size() < 768))
|
||||
{
|
||||
SHAMapIterator it(*reqLedger->peekTransactionMap(), true, true);
|
||||
for (SHAMapTreeNode* node = it.getNext(); node != NULL; node = it.getNext())
|
||||
pack = reqLedger->peekTransactionMap()->getFetchPack(NULL, true, 256);
|
||||
BOOST_FOREACH(SHAMap::fetchPackEntry_t& node, pack)
|
||||
{
|
||||
Serializer s;
|
||||
node->addRaw(s, snfPREFIX);
|
||||
ripple::TMIndexedObject& newObj = *reply.add_objects();
|
||||
newObj.set_hash(node->getNodeHash().begin(), 256 / 8);
|
||||
newObj.set_data(&s.peekData()[0], s.peekData().size());
|
||||
newObj.set_hash(node.first.begin(), 256 / 8);
|
||||
newObj.set_data(&node.second[0], node.second.size());
|
||||
}
|
||||
}
|
||||
|
||||
cLog(lsINFO) << "Built fetch pack with " << reply.objects().size() << " nodes";
|
||||
PackedMessage::pointer msg = boost::make_shared<PackedMessage>(reply, ripple::mtGET_OBJECTS);
|
||||
peer->sendPacket(msg, false);
|
||||
#endif
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
cLog(lsWARNING) << "Exception building fetch pach";
|
||||
}
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -333,7 +333,6 @@ extern bool SMANCombine(SMAddNode& existing, const SMAddNode& additional);
|
||||
|
||||
class SHAMap : public IS_INSTANCE(SHAMap)
|
||||
{
|
||||
friend class SHAMapIterator;
|
||||
|
||||
public:
|
||||
typedef boost::shared_ptr<SHAMap> pointer;
|
||||
@@ -375,6 +374,7 @@ protected:
|
||||
SHAMapItem::pointer onlyBelow(SHAMapTreeNode*);
|
||||
void eraseChildren(SHAMapTreeNode::pointer);
|
||||
void dropBelow(SHAMapTreeNode*);
|
||||
bool hasNode(const SHAMapNode& id, const uint256& hash);
|
||||
|
||||
bool walkBranch(SHAMapTreeNode* node, SHAMapItem::ref otherMapItem, bool isFirstMap,
|
||||
SHAMapDiff& differences, int& maxCount);
|
||||
@@ -476,11 +476,11 @@ public:
|
||||
bool deepCompare(SHAMap& other);
|
||||
virtual void dump(bool withHashes = false);
|
||||
|
||||
typedef std::pair< uint256, std::vector<unsigned char> > fetchPackEntry_t;
|
||||
std::list<fetchPackEntry_t> getFetchPack(SHAMap* prior, bool includeLeaves, int max);
|
||||
|
||||
static void sweep() { fullBelowCache.sweep(); }
|
||||
};
|
||||
|
||||
extern std::list< std::pair<uint256, std::vector<unsigned char> > >
|
||||
getSyncInfo(SHAMap::pointer have, SHAMap::pointer want, int max);
|
||||
|
||||
#endif
|
||||
// vim:ts=4
|
||||
|
||||
@@ -469,6 +469,81 @@ bool SHAMap::deepCompare(SHAMap& other)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SHAMap::hasNode(const SHAMapNode& nodeID, const uint256& nodeHash)
|
||||
{
|
||||
SHAMapTreeNode* node = root.get();
|
||||
while (node->isInner() && (node->getDepth() <= nodeID.getDepth()))
|
||||
{
|
||||
int branch = node->selectBranch(nodeID.getNodeID());
|
||||
node = getNodePointer(node->getChildNodeID(branch), node->getChildHash(branch));
|
||||
}
|
||||
return node->getNodeHash() == nodeHash;
|
||||
}
|
||||
|
||||
std::list<SHAMap::fetchPackEntry_t> SHAMap::getFetchPack(SHAMap* prior, bool includeLeaves, int max)
|
||||
{
|
||||
std::list<fetchPackEntry_t> ret;
|
||||
|
||||
if (root->isLeaf())
|
||||
{
|
||||
if (includeLeaves &&
|
||||
(!prior || !prior->hasNode(*root, root->getNodeHash())))
|
||||
{
|
||||
Serializer s;
|
||||
root->addRaw(s, snfPREFIX);
|
||||
ret.push_back(fetchPackEntry_t(root->getNodeHash(), s.peekData()));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
if (prior && (root->getNodeHash() == prior->root->getNodeHash()))
|
||||
return ret;
|
||||
|
||||
std::stack<SHAMapTreeNode*> stack; // contains unexplored non-matching inner node entries
|
||||
stack.push(root.get());
|
||||
|
||||
while (!stack.empty())
|
||||
{
|
||||
SHAMapTreeNode* node = stack.top();
|
||||
stack.pop();
|
||||
|
||||
// 1) Add this node to the pack
|
||||
Serializer s;
|
||||
node->addRaw(s, snfPREFIX);
|
||||
ret.push_back(fetchPackEntry_t(node->getNodeHash(), s.peekData()));
|
||||
--max;
|
||||
|
||||
// 2) push non-matching child inner nodes
|
||||
for (int i = 0; i < 16; ++i)
|
||||
{
|
||||
if (!node->isEmptyBranch(i))
|
||||
{
|
||||
const uint256& childHash = node->getChildHash(i);
|
||||
SHAMapNode childID = node->getChildNodeID(i);
|
||||
|
||||
SHAMapTreeNode *next = getNodePointer(childID, childHash);
|
||||
if (next->isInner())
|
||||
{
|
||||
if (!prior || !prior->hasNode(*next, childHash))
|
||||
stack.push(next);
|
||||
}
|
||||
else if (includeLeaves && (!prior || !prior->hasNode(childID, childHash)))
|
||||
{
|
||||
Serializer s;
|
||||
node->addRaw(s, snfPREFIX);
|
||||
ret.push_back(fetchPackEntry_t(node->getNodeHash(), s.peekData()));
|
||||
--max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (max <= 0)
|
||||
break;
|
||||
}
|
||||
|
||||
cLog(lsINFO) << "Fetch pack has " << ret.size() << " entries";
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
#define SMS_DEBUG
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user