Validators work

This commit is contained in:
Vinnie Falco
2013-10-04 00:07:45 -07:00
parent 2894059b63
commit 48eb92e366
4 changed files with 68 additions and 13 deletions

View File

@@ -264,16 +264,35 @@ public:
// load data from m_store // load data from m_store
} }
// Returns `true` if a Source with the same unique ID already exists
//
bool findSourceByID (String id)
{
SharedState::Access state (m_state);
for (SourcesType::const_iterator iter (state->sources.begin());
iter != state->sources.end(); ++iter)
if (iter->source->uniqueID() == id)
return true;
return false;
}
// Add a one-time static source. // Add a one-time static source.
// Fetch is called right away, this call blocks. // Fetch is called right away, this call blocks.
// //
void addStatic (Source* source) void addStatic (Source* source)
{ {
ScopedPointer <Source> object (source);
if (findSourceByID (source->uniqueID()))
{
m_journal.error << "Duplicate static " << source->name();
return;
}
m_journal.info << "Addding static " << source->name(); m_journal.info << "Addding static " << source->name();
ScopedPointer <Source> object (source);
Source::Result result; Source::Result result;
object->fetch (result, m_journal); source->fetch (result, m_journal);
if (result.success) if (result.success)
{ {
@@ -293,6 +312,13 @@ public:
// //
void add (Source* source) void add (Source* source)
{ {
if (findSourceByID (source->uniqueID()))
{
ScopedPointer <Source> object (source);
m_journal.error << "Duplicate " << source->name();
return;
}
m_journal.info << "Adding " << source->name(); m_journal.info << "Adding " << source->name();
{ {
@@ -301,6 +327,7 @@ public:
SourceDesc& desc (state->sources.back()); SourceDesc& desc (state->sources.back());
desc.source = source; desc.source = source;
m_store.insert (desc); m_store.insert (desc);
merge (desc.result.list, desc.source, state);
} }
} }
@@ -414,8 +441,6 @@ public:
{ {
Source* const source (desc.source); Source* const source (desc.source);
m_journal.info << "fetch " << source->name();
Source::Result result; Source::Result result;
source->fetch (result, m_journal); source->fetch (result, m_journal);
@@ -427,6 +452,10 @@ public:
{ {
SharedState::Access state (m_state); SharedState::Access state (m_state);
// Count the number fetched
std::size_t const numFetched (
result.list.size());
// Add the new source info to the map // Add the new source info to the map
std::size_t const numAdded ( std::size_t const numAdded (
merge (result.list, source, state)); merge (result.list, source, state));
@@ -438,12 +467,27 @@ public:
std::size_t const numRemoved ( std::size_t const numRemoved (
remove (result.list, source, state)); remove (result.list, source, state));
// Report
if (numAdded > numRemoved) if (numAdded > numRemoved)
m_journal.info << "Added " << (numAdded - numRemoved) << {
m_journal.info <<
"Fetched " << numFetched <<
"(" << (numAdded - numRemoved) << " new) " <<
" trusted validators from " << source->name(); " trusted validators from " << source->name();
}
else if (numRemoved > numAdded) else if (numRemoved > numAdded)
m_journal.info << "Removed " << (numRemoved - numAdded) << {
m_journal.info <<
"Fetched " << numFetched <<
"(" << numRemoved - numAdded << " removed) " <<
" trusted validators from " << source->name(); " trusted validators from " << source->name();
}
else
{
m_journal.info <<
"Fetched " << numFetched <<
" trusted validators from " << source->name();
}
// See if we need to rebuild // See if we need to rebuild
checkChosen (); checkChosen ();
@@ -457,6 +501,8 @@ public:
} }
else else
{ {
m_journal.error << "Failed to fetch " << source->name();
++desc.numberOfFailures; ++desc.numberOfFailures;
desc.status = SourceDesc::statusFailed; desc.status = SourceDesc::statusFailed;

View File

@@ -57,11 +57,6 @@ public:
if (httpResult.first == 0) if (httpResult.first == 0)
{ {
#if 0
journal.debug << std::endl << httpResult.second->toString ();
journal.debug << std::endl << httpResult.second->body().to_string();
#endif
Utilities::ParseResultLine lineFunction (result, journal); Utilities::ParseResultLine lineFunction (result, journal);
std::string const s (httpResult.second->body().to_string()); std::string const s (httpResult.second->body().to_string());
Utilities::processLines (s.begin(), s.end(), lineFunction); Utilities::processLines (s.begin(), s.end(), lineFunction);

View File

@@ -206,10 +206,18 @@ bool StoreSqdb::select (SourceDesc& desc)
if (st.execute_and_fetch (error)) if (st.execute_and_fetch (error))
{ {
m_journal.debug << "Found record for " <<
desc.source->name ();
found = true; found = true;
desc.lastFetchTime = Utilities::stringToTime (lastFetchTime); desc.lastFetchTime = Utilities::stringToTime (lastFetchTime);
desc.expirationTime = Utilities::stringToTime (expirationTime); desc.expirationTime = Utilities::stringToTime (expirationTime);
} }
else if (! error)
{
m_journal.info << "No previous record for " <<
desc.source->name ();
}
if (error) if (error)
{ {
@@ -293,6 +301,12 @@ void StoreSqdb::selectList (SourceDesc& desc)
} }
} }
while (st.fetch (error)); while (st.fetch (error));
if (! error)
{
m_journal.info << "Loaded " << desc.result.list.size() <<
" trusted validators for " << desc.source->name ();
}
} }
} }

View File

@@ -614,7 +614,7 @@ public:
// Initialize the Validators object with Config information. // Initialize the Validators object with Config information.
void prepareValidators () void prepareValidators ()
{ {
#if 0 #if 1
{ {
std::vector <std::string> const& strings (getConfig().validators); std::vector <std::string> const& strings (getConfig().validators);
m_validators->addStrings ("rippled.cfg", strings); m_validators->addStrings ("rippled.cfg", strings);
@@ -628,7 +628,7 @@ public:
} }
#endif #endif
#if 0 #if 1
if (getConfig().getValidatorsFile() != File::nonexistent ()) if (getConfig().getValidatorsFile() != File::nonexistent ())
{ {
m_validators->addFile (getConfig().getValidatorsFile()); m_validators->addFile (getConfig().getValidatorsFile());