mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-30 16:05:51 +00:00
Validators work
This commit is contained in:
@@ -1694,6 +1694,7 @@
|
||||
<ClInclude Include="..\..\src\ripple\validators\api\Types.h" />
|
||||
<ClInclude Include="..\..\src\ripple\validators\api\Manager.h" />
|
||||
<ClInclude Include="..\..\src\ripple\validators\impl\ChosenList.h" />
|
||||
<ClInclude Include="..\..\src\ripple\validators\impl\Ledger.h" />
|
||||
<ClInclude Include="..\..\src\ripple\validators\impl\Logic.h" />
|
||||
<ClInclude Include="..\..\src\ripple\validators\impl\SourceDesc.h" />
|
||||
<ClInclude Include="..\..\src\ripple\validators\impl\SourceFile.h" />
|
||||
@@ -1701,7 +1702,9 @@
|
||||
<ClInclude Include="..\..\src\ripple\validators\impl\SourceURL.h" />
|
||||
<ClInclude Include="..\..\src\ripple\validators\impl\Store.h" />
|
||||
<ClInclude Include="..\..\src\ripple\validators\impl\StoreSqdb.h" />
|
||||
<ClInclude Include="..\..\src\ripple\validators\impl\Tuning.h" />
|
||||
<ClInclude Include="..\..\src\ripple\validators\impl\Utilities.h" />
|
||||
<ClInclude Include="..\..\src\ripple\validators\impl\Validator.h" />
|
||||
<ClInclude Include="..\..\src\ripple\validators\ripple_validators.h" />
|
||||
<ClInclude Include="..\..\src\ripple_app\consensus\DisputedTx.h" />
|
||||
<ClInclude Include="..\..\src\ripple_app\consensus\LedgerConsensus.h" />
|
||||
|
||||
@@ -2184,6 +2184,15 @@
|
||||
<ClInclude Include="..\..\src\ripple\peerfinder\api\Manager.h">
|
||||
<Filter>[1] Ripple\peerfinder\api</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\validators\impl\Ledger.h">
|
||||
<Filter>[1] Ripple\validators\impl</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\validators\impl\Validator.h">
|
||||
<Filter>[1] Ripple\validators\impl</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\src\ripple\validators\impl\Tuning.h">
|
||||
<Filter>[1] Ripple\validators\impl</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<CustomBuild Include="..\..\src\ripple_data\protocol\ripple.proto">
|
||||
|
||||
43
src/ripple/validators/impl/Ledger.h
Normal file
43
src/ripple/validators/impl/Ledger.h
Normal file
@@ -0,0 +1,43 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_VALIDATORS_LEDGER_H_INCLUDED
|
||||
#define RIPPLE_VALIDATORS_LEDGER_H_INCLUDED
|
||||
|
||||
namespace ripple {
|
||||
namespace Validators {
|
||||
|
||||
// Stored each time a ledger is closed
|
||||
//
|
||||
struct Ledger
|
||||
{
|
||||
Ledger() : when (RelativeTime::fromStartup())
|
||||
{
|
||||
}
|
||||
|
||||
RelativeTime when;
|
||||
};
|
||||
|
||||
typedef AgedHistory <boost::unordered_map <
|
||||
RippleLedgerHash, Ledger, RippleLedgerHash::hasher> > LedgerMap;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -23,202 +23,12 @@
|
||||
namespace ripple {
|
||||
namespace Validators {
|
||||
|
||||
// Tunable constants
|
||||
enum
|
||||
{
|
||||
#if 0
|
||||
// We will fetch a source at this interval
|
||||
hoursBetweenFetches = 24
|
||||
,secondsBetweenFetches = hoursBetweenFetches * 60 * 60
|
||||
// We check Source expirations on this time interval
|
||||
,checkEverySeconds = 60 * 60
|
||||
#else
|
||||
secondsBetweenFetches = 59
|
||||
,checkEverySeconds = 60
|
||||
#endif
|
||||
|
||||
// This tunes the preallocated arrays
|
||||
,expectedNumberOfResults = 1000
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
enum
|
||||
{
|
||||
maxSizeBeforeSwap = 100
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
struct Ledger
|
||||
{
|
||||
Ledger() : when (Time::getCurrentTime())
|
||||
{
|
||||
}
|
||||
|
||||
Time when;
|
||||
};
|
||||
|
||||
typedef AgedHistory <boost::unordered_map <
|
||||
RippleLedgerHash, Ledger, RippleLedgerHash::hasher> > Ledgers;
|
||||
|
||||
// Information associated with each distinguishable validator
|
||||
struct Validator
|
||||
{
|
||||
Validator ()
|
||||
: refCount (0)
|
||||
{
|
||||
}
|
||||
|
||||
void receiveValidation (RippleLedgerHash const& ledgerHash)
|
||||
{
|
||||
typedef Ledgers::container_type::iterator iterator;
|
||||
|
||||
++count->seen;
|
||||
|
||||
// If we already have it in the expected list, close it out
|
||||
//
|
||||
iterator iter (expected->find (ledgerHash));
|
||||
if (iter != expected->end())
|
||||
{
|
||||
expected->erase (iter);
|
||||
expected.back().erase (ledgerHash);
|
||||
return;
|
||||
}
|
||||
else if ((iter = expected.back().find(ledgerHash)) !=
|
||||
expected.back().end())
|
||||
{
|
||||
expected.back().erase (iter);
|
||||
return;
|
||||
}
|
||||
|
||||
// Ledger hasn't closed yet so put it in the received list
|
||||
//
|
||||
std::pair <iterator, bool> result (
|
||||
received->emplace (ledgerHash, Ledger()));
|
||||
bassert (result.second);
|
||||
if (received->size() >= maxSizeBeforeSwap)
|
||||
swap();
|
||||
}
|
||||
|
||||
void ledgerClosed (RippleLedgerHash const& ledgerHash)
|
||||
{
|
||||
typedef Ledgers::container_type::iterator iterator;
|
||||
|
||||
++count->closed;
|
||||
|
||||
// If the Validator already gave us the ledger
|
||||
// then count it and remove it from both tables.
|
||||
//
|
||||
iterator iter (received->find (ledgerHash));
|
||||
if (iter != received->end())
|
||||
{
|
||||
received->erase (iter);
|
||||
received.back().erase (ledgerHash);
|
||||
return;
|
||||
}
|
||||
else if ((iter = received.back().find (ledgerHash)) !=
|
||||
received.back().end())
|
||||
{
|
||||
received.back().erase (iter);
|
||||
return;
|
||||
}
|
||||
|
||||
// We haven't seen this ledger hash from the
|
||||
// validator yet so put it on the expected list
|
||||
//
|
||||
std::pair <iterator, bool> result (
|
||||
expected->emplace (ledgerHash, Ledger ()));
|
||||
bassert (result.second);
|
||||
if (expected->size() >= maxSizeBeforeSwap)
|
||||
swap();
|
||||
}
|
||||
|
||||
void swap()
|
||||
{
|
||||
// Count anything in the old expected list as missing
|
||||
count->missing += expected.back().size();
|
||||
|
||||
// Count anything in the old received list as orphaned
|
||||
count->orphans += received.back().size();
|
||||
|
||||
// Rotate and clear
|
||||
count.swap();
|
||||
expected.swap();
|
||||
received.swap();
|
||||
count->clear();
|
||||
expected->clear();
|
||||
received->clear();
|
||||
}
|
||||
|
||||
struct Count
|
||||
{
|
||||
Count()
|
||||
: closed (0)
|
||||
, seen (0)
|
||||
, missing (0)
|
||||
, orphans (0)
|
||||
{
|
||||
}
|
||||
|
||||
void clear ()
|
||||
{
|
||||
*this = Count();
|
||||
}
|
||||
|
||||
// How many ledgers we've seen
|
||||
std::size_t closed;
|
||||
|
||||
// How many validation's we've seen
|
||||
std::size_t seen;
|
||||
|
||||
// Estimate of validation's that were missed
|
||||
std::size_t missing;
|
||||
|
||||
// Estimate of validations not belonging to any ledger
|
||||
std::size_t orphans;
|
||||
};
|
||||
|
||||
int refCount;
|
||||
|
||||
AgedHistory <Count> count;
|
||||
Ledgers received;
|
||||
Ledgers expected;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
// Encapsulates the logic for creating the chosen validators.
|
||||
// This is a separate class to facilitate the unit tests.
|
||||
//
|
||||
class Logic
|
||||
{
|
||||
public:
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
typedef boost::unordered_map <
|
||||
RipplePublicKey, Validator,
|
||||
RipplePublicKey::hasher> MapType;
|
||||
|
||||
// The master in-memory database of Validator, indexed by all the
|
||||
// possible things that we need to care about, and even some that we don't.
|
||||
//
|
||||
/*
|
||||
typedef boost::multi_index_container <
|
||||
Validator, boost::multi_index::indexed_by <
|
||||
|
||||
boost::multi_index::hashed_unique <
|
||||
BOOST_MULTI_INDEX_MEMBER(Logic::Validator,UniqueID,uniqueID)>,
|
||||
|
||||
boost::multi_index::hashed_unique <
|
||||
BOOST_MULTI_INDEX_MEMBER(Logic::Validator,IPEndpoint,endpoint),
|
||||
Connectible::HashAddress>
|
||||
>
|
||||
> ValidationsMap;
|
||||
*/
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
struct State
|
||||
{
|
||||
State ()
|
||||
@@ -226,7 +36,7 @@ public:
|
||||
//sources.reserve (64);
|
||||
}
|
||||
|
||||
MapType map;
|
||||
ValidatorMap validators;
|
||||
SourcesType sources;
|
||||
};
|
||||
|
||||
@@ -238,12 +48,6 @@ public:
|
||||
ChosenList::Ptr m_chosenList;
|
||||
SharedState m_state;
|
||||
|
||||
// Used to filter duplicate public keys
|
||||
//
|
||||
typedef AgedHistory <boost::unordered_set <
|
||||
RipplePublicKey, RipplePublicKey::hasher> > SeenPublicKeys;
|
||||
SeenPublicKeys m_seenPublicKeys;
|
||||
|
||||
// Used to filter duplicate ledger hashes
|
||||
//
|
||||
typedef AgedHistory <boost::unordered_set <
|
||||
@@ -252,7 +56,7 @@ public:
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
Logic (Store& store, Journal journal = Journal ())
|
||||
explicit Logic (Store& store, Journal journal = Journal ())
|
||||
: m_store (store)
|
||||
, m_journal (journal)
|
||||
, m_rebuildChosenList (false)
|
||||
@@ -279,10 +83,8 @@ public:
|
||||
// Add a one-time static source.
|
||||
// Fetch is called right away, this call blocks.
|
||||
//
|
||||
void addStatic (Source* source)
|
||||
void addStatic (SharedPtr <Source> source)
|
||||
{
|
||||
ScopedPointer <Source> object (source);
|
||||
|
||||
if (findSourceByID (source->uniqueID()))
|
||||
{
|
||||
m_journal.error << "Duplicate static " << source->name();
|
||||
@@ -310,7 +112,7 @@ public:
|
||||
|
||||
// Add a live source to the list of sources.
|
||||
//
|
||||
void add (Source* source)
|
||||
void add (SharedPtr <Source> source)
|
||||
{
|
||||
if (findSourceByID (source->uniqueID()))
|
||||
{
|
||||
@@ -341,8 +143,8 @@ public:
|
||||
for (std::size_t i = 0; i < list.size (); ++i)
|
||||
{
|
||||
Source::Info const& info (list [i]);
|
||||
std::pair <MapType::iterator, bool> result (
|
||||
state->map.emplace (info.publicKey, Validator ()));
|
||||
std::pair <ValidatorMap::iterator, bool> result (
|
||||
state->validators.emplace (info.publicKey, Validator ()));
|
||||
Validator& validatorInfo (result.first->second);
|
||||
++validatorInfo.refCount;
|
||||
if (result.second)
|
||||
@@ -366,14 +168,14 @@ public:
|
||||
for (std::size_t i = 0; i < list.size (); ++i)
|
||||
{
|
||||
Source::Info const& info (list [i]);
|
||||
MapType::iterator iter (state->map.find (info.publicKey));
|
||||
bassert (iter != state->map.end ());
|
||||
ValidatorMap::iterator iter (state->validators.find (info.publicKey));
|
||||
bassert (iter != state->validators.end ());
|
||||
Validator& validatorInfo (iter->second);
|
||||
if (--validatorInfo.refCount == 0)
|
||||
{
|
||||
// Last reference removed
|
||||
++numRemoved;
|
||||
state->map.erase (iter);
|
||||
state->validators.erase (iter);
|
||||
dirtyChosen ();
|
||||
}
|
||||
}
|
||||
@@ -390,10 +192,10 @@ public:
|
||||
void buildChosen ()
|
||||
{
|
||||
SharedState::ConstAccess state (m_state);
|
||||
ChosenList::Ptr list (new ChosenList (state->map.size ()));
|
||||
ChosenList::Ptr list (new ChosenList (state->validators.size ()));
|
||||
|
||||
for (MapType::const_iterator iter = state->map.begin ();
|
||||
iter != state->map.end (); ++iter)
|
||||
for (ValidatorMap::const_iterator iter = state->validators.begin ();
|
||||
iter != state->validators.end (); ++iter)
|
||||
{
|
||||
ChosenList::Info info;
|
||||
list->insert (iter->first, info);
|
||||
@@ -569,13 +371,13 @@ public:
|
||||
ChosenList::Ptr list (m_chosenList);
|
||||
if (list != nullptr)
|
||||
{
|
||||
for (ChosenList::MapType::const_iterator iter (list->map().begin());
|
||||
for (ChosenList::ValidatorMap::const_iterator iter (list->map().begin());
|
||||
iter != list->map().end(); ++iter)
|
||||
{
|
||||
Json::Value entry (Json::objectValue);
|
||||
ChosenList::MapType::key_type const& key (iter->first);
|
||||
ChosenList::ValidatorMap::key_type const& key (iter->first);
|
||||
entry ["key"] = key.to_string();
|
||||
//ChosenList::MapType::mapped_type const& value (iter->second);
|
||||
//ChosenList::ValidatorMap::mapped_type const& value (iter->second);
|
||||
//entry ["value"] = value.to_string();
|
||||
entries.append (entry);
|
||||
}
|
||||
@@ -585,9 +387,9 @@ public:
|
||||
{
|
||||
SharedState::ConstAccess state (m_state);
|
||||
std::size_t count (0);
|
||||
result ["validators"] = state->map.size();
|
||||
for (MapType::const_iterator iter (state->map.begin());
|
||||
iter != state->map.end(); ++iter)
|
||||
result ["validators"] = state->validators.size();
|
||||
for (ValidatorMap::const_iterator iter (state->validators.begin());
|
||||
iter != state->validators.end(); ++iter)
|
||||
count += iter->second.map.size();
|
||||
result ["signatures"] = count;
|
||||
}
|
||||
@@ -595,9 +397,9 @@ public:
|
||||
Json::Value entries (Json::arrayValue);
|
||||
{
|
||||
SharedState::ConstAccess state (m_state);
|
||||
result ["count"] = int(state->map.size());
|
||||
for (MapType::const_iterator iter (state->map.begin());
|
||||
iter != state->map.end(); ++iter)
|
||||
result ["count"] = int(state->validators.size());
|
||||
for (ValidatorMap::const_iterator iter (state->validators.begin());
|
||||
iter != state->validators.end(); ++iter)
|
||||
{
|
||||
Validator const& v (iter->second);
|
||||
Json::Value entry (Json::objectValue);
|
||||
@@ -681,6 +483,13 @@ public:
|
||||
|
||||
// Called when we receive a signed validation
|
||||
//
|
||||
// Used to filter duplicate public keys
|
||||
//
|
||||
typedef AgedCache <RipplePublicKey,
|
||||
typedef AgedHistory <boost::unordered_set <
|
||||
RipplePublicKey, RipplePublicKey::hasher> > SeenPublicKeys;
|
||||
SeenPublicKeys m_seenPublicKeys;
|
||||
|
||||
void receiveValidation (ReceivedValidation const& rv)
|
||||
{
|
||||
// Filter duplicates
|
||||
@@ -697,16 +506,18 @@ public:
|
||||
}
|
||||
|
||||
SharedState::Access state (m_state);
|
||||
#if 0
|
||||
MapType::iterator iter (state->map.find (rv.publicKey));
|
||||
if (iter != state->map.end ())
|
||||
#if 1
|
||||
// Accept validation from the trusted list
|
||||
ValidatorMap::iterator iter (state->validators.find (rv.publicKey));
|
||||
if (iter != state->validators.end ())
|
||||
{
|
||||
Validator& v (iter->second);
|
||||
v.receiveValidation (rv.ledgerHash);
|
||||
}
|
||||
#else
|
||||
std::pair <MapType::iterator, bool> result (
|
||||
state->map.emplace (rv.publicKey, Validator()));
|
||||
// Accept any validation (for testing)
|
||||
std::pair <ValidatorMap::iterator, bool> result (
|
||||
state->validators.emplace (rv.publicKey, Validator()));
|
||||
Validator& v (result.first->second);
|
||||
v.receiveValidation (rv.ledgerHash);
|
||||
#endif
|
||||
@@ -730,8 +541,8 @@ public:
|
||||
}
|
||||
|
||||
SharedState::Access state (m_state);
|
||||
for (MapType::iterator iter (state->map.begin());
|
||||
iter != state->map.end(); ++iter)
|
||||
for (ValidatorMap::iterator iter (state->validators.begin());
|
||||
iter != state->validators.end(); ++iter)
|
||||
{
|
||||
Validator& v (iter->second);
|
||||
v.ledgerClosed (ledgerHash);
|
||||
|
||||
149
src/ripple/validators/impl/Tuning.h
Normal file
149
src/ripple/validators/impl/Tuning.h
Normal file
@@ -0,0 +1,149 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_VALIDATORS_TUNING_H_INCLUDED
|
||||
#define RIPPLE_VALIDATORS_TUNING_H_INCLUDED
|
||||
|
||||
namespace ripple {
|
||||
namespace Validators {
|
||||
|
||||
// Tunable constants
|
||||
//
|
||||
enum
|
||||
{
|
||||
#if 0
|
||||
// We will fetch a source at this interval
|
||||
hoursBetweenFetches = 24
|
||||
,secondsBetweenFetches = hoursBetweenFetches * 60 * 60
|
||||
// We check Source expirations on this time interval
|
||||
,checkEverySeconds = 60 * 60
|
||||
#else
|
||||
secondsBetweenFetches = 59
|
||||
,checkEverySeconds = 60
|
||||
#endif
|
||||
|
||||
// This tunes the preallocated arrays
|
||||
,expectedNumberOfResults = 1000
|
||||
|
||||
// How many elements in the aged history before we swap containers
|
||||
,maxSizeBeforeSwap = 100
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** Associative container of unique keys. */
|
||||
template <class Key,
|
||||
class T,
|
||||
class Hash = typename Key::hasher, // class Hash = boost::hash <Key>
|
||||
class KeyEqual = std::equal_to <Key>,
|
||||
class Allocator = std::allocator <std::pair <const Key, T> > >
|
||||
class CycledMap
|
||||
{
|
||||
private:
|
||||
typedef boost::unordered_map <Key, T, Hash, KeyEqual, Allocator> ContainerType;
|
||||
|
||||
public:
|
||||
typedef typename ContainerType::key_type key_type;
|
||||
typedef typename ContainerType::value_type value_type;
|
||||
typedef typename ContainerType::size_type size_type;
|
||||
typedef typename ContainerType::difference_type difference_type;
|
||||
typedef typename ContainerType::hasher hasher;
|
||||
typedef typename ContainerType::allocator_type allocator_type;
|
||||
typedef typename ContainerType::reference reference;
|
||||
typedef typename ContainerType::const_reference const_reference;
|
||||
typedef typename ContainerType::pointer pointer;
|
||||
typedef typename ContainerType::const_pointer const_pointer;
|
||||
|
||||
void cycle ()
|
||||
{
|
||||
m_front.clear ();
|
||||
std::swap (m_front, m_back);
|
||||
}
|
||||
|
||||
private:
|
||||
ContainerType m_front;
|
||||
ContainerType m_back;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/** Associative container of unique keys. */
|
||||
template <class Key,
|
||||
class Hash = typename Key::hasher, // class Hash = boost::hash <Key>
|
||||
class KeyEqual = std::equal_to <Key>,
|
||||
class Allocator = std::allocator <Key> >
|
||||
class CycledSet
|
||||
{
|
||||
private:
|
||||
typedef boost::unordered_set <Key, Hash, KeyEqual, Allocator> ContainerType;
|
||||
|
||||
public:
|
||||
typedef typename ContainerType::key_type key_type;
|
||||
typedef typename ContainerType::value_type value_type;
|
||||
typedef typename ContainerType::size_type size_type;
|
||||
typedef typename ContainerType::difference_type difference_type;
|
||||
typedef typename ContainerType::hasher hasher;
|
||||
typedef typename ContainerType::key_equal key_equal;
|
||||
typedef typename ContainerType::allocator_type allocator_type;
|
||||
typedef typename ContainerType::reference reference;
|
||||
typedef typename ContainerType::const_reference const_reference;
|
||||
typedef typename ContainerType::pointer pointer;
|
||||
typedef typename ContainerType::const_pointer const_pointer;
|
||||
|
||||
explicit CycledSet (
|
||||
size_type item_max,
|
||||
Hash hash = Hash(),
|
||||
KeyEqual equal = KeyEqual(),
|
||||
Allocator alloc = Allocator())
|
||||
: m_max (item_max)
|
||||
, m_hash (hash)
|
||||
, m_equal (equal)
|
||||
, m_alloc (alloc)
|
||||
, m_front (hash, equal, alloc)
|
||||
, m_back (hash, equal, alloc)
|
||||
{
|
||||
m_front.reserve (m_max);
|
||||
m_back.reserve (m_max);
|
||||
}
|
||||
|
||||
void cycle ()
|
||||
{
|
||||
m_front.clear ();
|
||||
std::swap (m_front, m_back);
|
||||
}
|
||||
|
||||
bool insert (value_type const& value)
|
||||
{
|
||||
std::size_t const hash (m_hash (value));
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
size_type m_max;
|
||||
hasher m_hash;
|
||||
key_equal m_equal;
|
||||
allocator_type m_alloc;
|
||||
ContainerType m_front;
|
||||
ContainerType m_back;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -88,14 +88,14 @@ bool Utilities::parseInfoLine (
|
||||
std::string const encodedKey (match [1]);
|
||||
std::string const commentText (match [2]);
|
||||
|
||||
RippleAddress deprecatedPublicKey;
|
||||
std::pair <RipplePublicKey, bool> result (
|
||||
RipplePublicKey::from_string (encodedKey));
|
||||
|
||||
if (deprecatedPublicKey.setNodePublic (encodedKey))
|
||||
if (result.second)
|
||||
{
|
||||
// We got a public key.
|
||||
RipplePublicKey publicKey (deprecatedPublicKey);
|
||||
info.label = commentText;
|
||||
info.publicKey = publicKey;
|
||||
info.publicKey = result.first;
|
||||
success = true;
|
||||
}
|
||||
else
|
||||
|
||||
178
src/ripple/validators/impl/Validator.h
Normal file
178
src/ripple/validators/impl/Validator.h
Normal file
@@ -0,0 +1,178 @@
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
This file is part of rippled: https://github.com/ripple/rippled
|
||||
Copyright (c) 2012, 2013 Ripple Labs Inc.
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any
|
||||
purpose with or without fee is hereby granted, provided that the above
|
||||
copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
//==============================================================================
|
||||
|
||||
#ifndef RIPPLE_VALIDATORS_VALIDATOR_H_INCLUDED
|
||||
#define RIPPLE_VALIDATORS_VALIDATOR_H_INCLUDED
|
||||
|
||||
namespace ripple {
|
||||
namespace Validators {
|
||||
|
||||
// Stored for each distinguishable Validator in the trusted list.
|
||||
// These are kept in an associative container or multi-index container.
|
||||
//
|
||||
class Validator
|
||||
{
|
||||
public:
|
||||
Validator () : refCount (0)
|
||||
{
|
||||
}
|
||||
|
||||
void receiveValidation (RippleLedgerHash const& ledgerHash)
|
||||
{
|
||||
typedef LedgerMap::container_type::iterator iterator;
|
||||
|
||||
++count->seen;
|
||||
|
||||
// If we already have it in the expected list, close it out
|
||||
//
|
||||
iterator iter (expected->find (ledgerHash));
|
||||
if (iter != expected->end())
|
||||
{
|
||||
expected->erase (iter);
|
||||
expected.back().erase (ledgerHash);
|
||||
return;
|
||||
}
|
||||
else if ((iter = expected.back().find(ledgerHash)) !=
|
||||
expected.back().end())
|
||||
{
|
||||
expected.back().erase (iter);
|
||||
return;
|
||||
}
|
||||
|
||||
// Ledger hasn't closed yet so put it in the received list
|
||||
//
|
||||
std::pair <iterator, bool> result (
|
||||
received->emplace (ledgerHash, Ledger()));
|
||||
bassert (result.second);
|
||||
if (received->size() >= maxSizeBeforeSwap)
|
||||
swap();
|
||||
}
|
||||
|
||||
void ledgerClosed (RippleLedgerHash const& ledgerHash)
|
||||
{
|
||||
typedef LedgerMap::container_type::iterator iterator;
|
||||
|
||||
++count->closed;
|
||||
|
||||
// If the Validator already gave us the ledger
|
||||
// then count it and remove it from both tables.
|
||||
//
|
||||
iterator iter (received->find (ledgerHash));
|
||||
if (iter != received->end())
|
||||
{
|
||||
received->erase (iter);
|
||||
received.back().erase (ledgerHash);
|
||||
return;
|
||||
}
|
||||
else if ((iter = received.back().find (ledgerHash)) !=
|
||||
received.back().end())
|
||||
{
|
||||
received.back().erase (iter);
|
||||
return;
|
||||
}
|
||||
|
||||
// We haven't seen this ledger hash from the
|
||||
// validator yet so put it on the expected list
|
||||
//
|
||||
std::pair <iterator, bool> result (
|
||||
expected->emplace (ledgerHash, Ledger ()));
|
||||
bassert (result.second);
|
||||
if (expected->size() >= maxSizeBeforeSwap)
|
||||
swap();
|
||||
}
|
||||
|
||||
void swap()
|
||||
{
|
||||
// Count anything in the old expected list as missing
|
||||
count->missing += expected.back().size();
|
||||
|
||||
// Count anything in the old received list as orphaned
|
||||
count->orphans += received.back().size();
|
||||
|
||||
// Rotate and clear
|
||||
count.swap();
|
||||
expected.swap();
|
||||
received.swap();
|
||||
count->clear();
|
||||
expected->clear();
|
||||
received->clear();
|
||||
}
|
||||
|
||||
struct Count
|
||||
{
|
||||
Count()
|
||||
: closed (0)
|
||||
, seen (0)
|
||||
, missing (0)
|
||||
, orphans (0)
|
||||
{
|
||||
}
|
||||
|
||||
void clear ()
|
||||
{
|
||||
*this = Count();
|
||||
}
|
||||
|
||||
// How many LedgerMap we've seen
|
||||
std::size_t closed;
|
||||
|
||||
// How many validation's we've seen
|
||||
std::size_t seen;
|
||||
|
||||
// Estimate of validation's that were missed
|
||||
std::size_t missing;
|
||||
|
||||
// Estimate of validations not belonging to any ledger
|
||||
std::size_t orphans;
|
||||
};
|
||||
|
||||
int refCount;
|
||||
|
||||
AgedHistory <Count> count;
|
||||
LedgerMap received;
|
||||
LedgerMap expected;
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
typedef boost::unordered_map <
|
||||
RipplePublicKey, Validator,
|
||||
RipplePublicKey::hasher> ValidatorMap;
|
||||
|
||||
// The master in-memory database of Validator, indexed by all the
|
||||
// possible things that we need to care about, and even some that we don't.
|
||||
//
|
||||
/*
|
||||
typedef boost::multi_index_container <
|
||||
Validator, boost::multi_index::indexed_by <
|
||||
|
||||
boost::multi_index::hashed_unique <
|
||||
BOOST_MULTI_INDEX_MEMBER(Logic::Validator,UniqueID,uniqueID)>,
|
||||
|
||||
boost::multi_index::hashed_unique <
|
||||
BOOST_MULTI_INDEX_MEMBER(Logic::Validator,IPEndpoint,endpoint),
|
||||
Connectible::HashAddress>
|
||||
>
|
||||
> ValidationsMap;
|
||||
*/
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
#include "beast/modules/beast_core/system/BeforeBoost.h"
|
||||
#include <boost/regex.hpp>
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/unordered_set.hpp>
|
||||
#include <boost/multi_index_container.hpp>
|
||||
#include <boost/multi_index/hashed_index.hpp>
|
||||
@@ -33,14 +34,13 @@
|
||||
#include "beast/modules/beast_asio/beast_asio.h"
|
||||
#include "beast/modules/beast_sqdb/beast_sqdb.h"
|
||||
|
||||
#include "../ripple_data/ripple_data.h" // for RippleAddress REMOVE ASAP
|
||||
|
||||
#include "../testoverlay/ripple_testoverlay.h" // for unit test
|
||||
|
||||
namespace ripple {
|
||||
using namespace beast;
|
||||
}
|
||||
|
||||
# include "impl/Tuning.h"
|
||||
# include "impl/ChosenList.h"
|
||||
# include "impl/SourceFile.h"
|
||||
# include "impl/SourceStrings.h"
|
||||
@@ -49,6 +49,8 @@ using namespace beast;
|
||||
# include "impl/SourceDesc.h"
|
||||
# include "impl/Store.h"
|
||||
# include "impl/StoreSqdb.h"
|
||||
# include "impl/Ledger.h"
|
||||
# include "impl/Validator.h"
|
||||
#include "impl/Logic.h"
|
||||
|
||||
#include "impl/Manager.cpp"
|
||||
|
||||
@@ -117,9 +117,8 @@ public:
|
||||
|
||||
, m_txQueue (TxQueue::New ())
|
||||
|
||||
, m_validators (m_rpcServiceManager->add (
|
||||
Validators::Manager::New (*this, LogJournal::get <ValidatorsLog> ())
|
||||
))
|
||||
, m_validators (Validators::Manager::New (
|
||||
*this, LogJournal::get <ValidatorsLog> ()))
|
||||
|
||||
, mFeatures (IFeatures::New (2 * 7 * 24 * 60 * 60, 200)) // two weeks, 200/256
|
||||
|
||||
@@ -643,6 +642,8 @@ public:
|
||||
|
||||
void onPrepare ()
|
||||
{
|
||||
m_rpcServiceManager->add (*m_validators);
|
||||
|
||||
prepareValidators ();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user