Files
xahaud/src/cpp/ripple/ValidationCollection.h
JoelKatz d4323f2ef2 Fix a case where a node that closed slightly ahead of other ledgers can
think it's out of sync with the network and cause it to jump backwards one
ledger, causing it to be out of sync because the network was about to catch
up to it.
2013-03-14 11:48:29 -07:00

61 lines
1.7 KiB
C++

#ifndef __VALIDATION_COLLECTION__
#define __VALIDATION_COLLECTION__
#include <vector>
#include <boost/unordered_map.hpp>
#include <boost/thread/mutex.hpp>
#include "uint256.h"
#include "types.h"
#include "SerializedValidation.h"
#include "TaggedCache.h"
#include "JobQueue.h"
typedef boost::unordered_map<uint160, SerializedValidation::pointer> ValidationSet;
typedef std::pair<int, uint160> currentValidationCount; // nodes validating and highest node ID validating
class ValidationCollection
{
protected:
boost::mutex mValidationLock;
TaggedCache<uint256, ValidationSet> mValidations;
boost::unordered_map<uint160, SerializedValidation::pointer> mCurrentValidations;
std::vector<SerializedValidation::pointer> mStaleValidations;
bool mWriting;
void doWrite(Job&);
void condWrite();
boost::shared_ptr<ValidationSet> findCreateSet(const uint256& ledgerHash);
boost::shared_ptr<ValidationSet> findSet(const uint256& ledgerHash);
public:
ValidationCollection() : mValidations("Validations", 128, 600), mWriting(false)
{ mStaleValidations.reserve(512); }
bool addValidation(SerializedValidation::ref);
ValidationSet getValidations(const uint256& ledger);
void getValidationCount(const uint256& ledger, bool currentOnly, int& trusted, int& untrusted);
void getValidationTypes(const uint256& ledger, int& full, int& partial);
int getTrustedValidationCount(const uint256& ledger);
int getNodesAfter(const uint256& ledger);
int getLoadRatio(bool overLoaded);
boost::unordered_map<uint256, currentValidationCount> getCurrentValidations(
uint256 currentLedger, uint256 previousLedger);
std::list<SerializedValidation::pointer> getCurrentTrustedValidations();
void tune(int size, int age);
void flush();
void sweep();
};
#endif