Validators work (RIPD-703):

This replaces the experimental validators module with foundational
code to implement a new system for tracking validators, validations and
the UNL. The code is turned off by default, in BeastConfig.h

* Remove obsolete public Manager interfaces
* Remove obsolete database methods
* Remove obsolete ChosenList concept
* Remove obsolete code
* Add missing includes
* Tidy up STValidation.h
* Move factory function to Validators::make_Manager
* Add Connection object for tracking STValidations
This commit is contained in:
Vinnie Falco
2014-11-18 15:43:33 -08:00
parent 628e3ac1eb
commit 2f6af906f4
38 changed files with 666 additions and 3040 deletions

View File

@@ -17,11 +17,7 @@
*/
//==============================================================================
#include <ripple/basics/seconds_clock.h>
#include <ripple/types/RippleLedgerHash.h>
#include <beast/container/aged_unordered_map.h>
#include <random>
#include <utility>
#include <beast/unit_test/suite.h>
namespace ripple {
namespace Validators {
@@ -29,99 +25,14 @@ namespace Validators {
class Validators_test : public beast::unit_test::suite
{
public:
struct Entry
{
bool closed = false; // `true` if the ledger was closed
bool received = false; // `true` if we got a validation
};
typedef beast::aged_unordered_map <RippleLedgerHash, Entry,
std::chrono::steady_clock, beast::hardened_hash<>,
RippleLedgerHash::key_equal> Table;
template <class Gen>
static
void
fillrand (void* buffer, std::size_t bytes, Gen& gen)
run()
{
auto p = reinterpret_cast<std::uint8_t*>(buffer);
typedef typename Gen::result_type result_type;
while (bytes >= sizeof(result_type))
{
*reinterpret_cast<result_type*>(p) = gen();
p += sizeof(result_type);
bytes -= sizeof(result_type);
}
if (bytes > 0)
{
auto const v = gen();
memcpy (p, &v, bytes);
}
}
void
test_aged_insert()
{
testcase ("aged insert");
std::random_device rng;
std::mt19937_64 gen {rng()};
Table table (get_seconds_clock());
for (int i = 0; i < 10000; ++i)
{
std::array <std::uint8_t, RippleLedgerHash::size> buf;
fillrand (buf.data(), buf.size(), gen);
RippleLedgerHash h (buf.data(), buf.data() + buf.size());
table.insert (std::make_pair (h, Entry()));
}
pass();
}
void
test_Validators()
{
int const N (5);
testcase ("Validators");
typedef hardened_hash_map <int, Validator> Validators;
Validators vv;
for (int i = 0; i < N; ++i)
vv.emplace (i, Validator{});
std::random_device rng;
std::mt19937_64 gen {rng()};
std::array <std::uint8_t, RippleLedgerHash::size> buf;
fillrand (buf.data(), buf.size(), gen);
for (int i = 0; i < 100000; ++i)
{
// maybe change the ledger hash
if ((gen() % 20) == 0)
fillrand (buf.data(), buf.size(), gen);
RippleLedgerHash h (buf.data(), buf.data() + buf.size());
// choose random validator
Validator& v (vv[gen() % vv.size()]);
// choose random operation
//int const choice = gen() % 2;
int const choice = 1;
switch (choice)
{
case 0:
v.on_ledger(h);
break;
case 1:
v.on_validation(h);
break;
};
}
pass();
}
void
run ()
{
test_aged_insert();
test_Validators();
}
};
BEAST_DEFINE_TESTSUITE(Validators,validators,ripple);
BEAST_DEFINE_TESTSUITE_MANUAL(Validators,validators,ripple);
}
}