diff --git a/Builds/VisualStudio2013/RippleD.vcxproj b/Builds/VisualStudio2013/RippleD.vcxproj
index 90ed293e97..38e2a61142 100644
--- a/Builds/VisualStudio2013/RippleD.vcxproj
+++ b/Builds/VisualStudio2013/RippleD.vcxproj
@@ -3573,6 +3573,9 @@
+
+ True
+
@@ -3936,6 +3939,57 @@
+
+ True
+
+
+ True
+
+
+ True
+
+
+ True
+
+
+
+
+
+
+ True
+
+
+ True
+
+
+
+
+ True
+
+
+
+
+ True
+
+
+ True
+
+
+
+
+
+
+
+
+ True
+
+
+
+
+ True
+
+
+
True
@@ -4109,57 +4163,6 @@
-
- True
-
-
- True
-
-
- True
-
-
- True
-
-
-
-
-
-
- True
-
-
- True
-
-
-
-
- True
-
-
-
-
- True
-
-
- True
-
-
-
-
-
-
-
-
- True
-
-
-
-
- True
-
-
-
diff --git a/Builds/VisualStudio2013/RippleD.vcxproj.filters b/Builds/VisualStudio2013/RippleD.vcxproj.filters
index 7bc1834bbc..34f7c5f85e 100644
--- a/Builds/VisualStudio2013/RippleD.vcxproj.filters
+++ b/Builds/VisualStudio2013/RippleD.vcxproj.filters
@@ -541,6 +541,9 @@
{3D1F0CBE-9B69-D29E-EAAE-E5A1204068BC}
+
+ {663AE0EE-6781-C2F4-8D04-0D5D30AC0773}
+
{A6DBE85A-1595-E8FB-25F1-D5A133237168}
@@ -4935,6 +4938,9 @@
ripple\validators
+
+ ripple\validators\tests
+
ripple\validators
@@ -5397,6 +5403,66 @@
rocksdb\third-party\rapidjson
+
+ rocksdb\utilities\backupable
+
+
+ rocksdb\utilities\document
+
+
+ rocksdb\utilities\document
+
+
+ rocksdb\utilities\geodb
+
+
+ rocksdb\utilities\geodb
+
+
+ rocksdb\utilities
+
+
+ rocksdb\utilities\merge_operators
+
+
+ rocksdb\utilities\merge_operators\string_append
+
+
+ rocksdb\utilities\merge_operators\string_append
+
+
+ rocksdb\utilities\merge_operators\string_append
+
+
+ rocksdb\utilities\merge_operators\string_append
+
+
+ rocksdb\utilities\merge_operators
+
+
+ rocksdb\utilities\redis
+
+
+ rocksdb\utilities\redis
+
+
+ rocksdb\utilities\redis
+
+
+ rocksdb\utilities\redis
+
+
+ rocksdb\utilities\spatialdb
+
+
+ rocksdb\utilities\spatialdb
+
+
+ rocksdb\utilities\ttl
+
+
+ rocksdb\utilities\ttl
+
rocksdb\util
@@ -5601,66 +5667,6 @@
rocksdb\util
-
- rocksdb\utilities\backupable
-
-
- rocksdb\utilities\document
-
-
- rocksdb\utilities\document
-
-
- rocksdb\utilities\geodb
-
-
- rocksdb\utilities\geodb
-
-
- rocksdb\utilities
-
-
- rocksdb\utilities\merge_operators
-
-
- rocksdb\utilities\merge_operators\string_append
-
-
- rocksdb\utilities\merge_operators\string_append
-
-
- rocksdb\utilities\merge_operators\string_append
-
-
- rocksdb\utilities\merge_operators\string_append
-
-
- rocksdb\utilities\merge_operators
-
-
- rocksdb\utilities\redis
-
-
- rocksdb\utilities\redis
-
-
- rocksdb\utilities\redis
-
-
- rocksdb\utilities\redis
-
-
- rocksdb\utilities\spatialdb
-
-
- rocksdb\utilities\spatialdb
-
-
- rocksdb\utilities\ttl
-
-
- rocksdb\utilities\ttl
-
snappy\config
diff --git a/src/ripple/unity/validators.cpp b/src/ripple/unity/validators.cpp
index 65fb84397a..3daa1fd027 100644
--- a/src/ripple/unity/validators.cpp
+++ b/src/ripple/unity/validators.cpp
@@ -59,4 +59,4 @@
#include
#include
-//#include
+#include
diff --git a/src/ripple/validators/impl/Validator.h b/src/ripple/validators/impl/Validator.h
index 6d3c59db5d..f123170662 100644
--- a/src/ripple/validators/impl/Validator.h
+++ b/src/ripple/validators/impl/Validator.h
@@ -43,10 +43,8 @@ private:
// Holds the Entry of all recent ledgers for this validator.
#if 1
typedef beast::aged_unordered_map ,
- std::hash,
- RippleLedgerHash::key_equal> Table;
+ std::chrono::seconds, beast::hardened_hash<>,
+ RippleLedgerHash::key_equal> Table;
#else
typedef beast::aged_map > Table;
@@ -97,6 +95,7 @@ public:
void
on_validation (RippleLedgerHash const& ledgerHash)
{
+ //expire();
auto const result (table_.insert (
std::make_pair (ledgerHash, Entry())));
auto& entry (result.first->second);
@@ -107,19 +106,19 @@ public:
{
--count_.expected;
++count_.closed;
- //table_.erase (result.first);
+ table_.erase (result.first);
}
else
{
++count_.received;
}
- //expire();
}
/** Called when a ledger is closed. */
void
on_ledger (RippleLedgerHash const& ledgerHash)
{
+ //expire();
auto const result (table_.insert (
std::make_pair (ledgerHash, Entry())));
auto& entry (result.first->second);
@@ -130,13 +129,12 @@ public:
{
--count_.received;
++count_.closed;
- //table_.erase (result.first);
+ table_.erase (result.first);
}
else
{
++count_.expected;
}
- //expire();
}
/** Prunes old entries. */
@@ -145,22 +143,6 @@ public:
{
beast::expire (table_, std::chrono::minutes(5));
}
-
-private:
- void dump ()
- {
- std::cout << "Validator: " << this << std::endl;
- std::cout << "Size: " << table_.size() << std::endl;
- std::cout << "end at: " << &(*table_.end()) << std::endl;
- for (auto const& ledgerKeyAndState : table_)
- {
- std::cout << "keyAndState at: " << &ledgerKeyAndState.first << std::endl;
- std::cout << " Hash: " << ledgerKeyAndState.first << std::endl;
- std::cout << " closed: " << ledgerKeyAndState.second.closed <<
- " received: " << ledgerKeyAndState.second.received <<
- std::endl;
- }
- }
};
}
diff --git a/src/ripple/validators/tests/Validators.test.cpp b/src/ripple/validators/tests/Validators.test.cpp
new file mode 100644
index 0000000000..9e02893603
--- /dev/null
+++ b/src/ripple/validators/tests/Validators.test.cpp
@@ -0,0 +1,127 @@
+//------------------------------------------------------------------------------
+/*
+ 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.
+*/
+//==============================================================================
+
+#include
+#include
+#include
+#include
+#include
+
+namespace ripple {
+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::key_equal> Table;
+
+ template
+ static
+ void
+ fillrand (void* buffer, std::size_t bytes, Gen& gen)
+ {
+ auto p = reinterpret_cast(buffer);
+ typedef typename Gen::result_type result_type;
+ while (bytes >= sizeof(result_type))
+ {
+ *reinterpret_cast(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 buf;
+ fillrand (buf.data(), buf.size(), gen);
+ RippleLedgerHash h (buf.data(), buf.data() + buf.size());
+ auto const result (table.insert (std::make_pair (h, Entry())));
+ }
+ pass();
+ }
+
+ void
+ test_Validators()
+ {
+ int const N (5);
+ testcase ("Validators");
+ typedef hardened_hash_map 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 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);
+
+}
+}