Skip to content

Commit

Permalink
Add validator list RPC commands (RIPD-1541):
Browse files Browse the repository at this point in the history
In support of dynamic validator list, this changeset:

1. Adds a new `validator_list_expires` field to `server_info` that
indicates when the current validator list will become stale.
2. Adds a new admin only `validator_lists` RPC that returns the
current list of known validators and the most recent published validator
lists.
3. Adds a new admin only `validator_sites` RPC that returns the list of
configured validator publisher sites and when they were most recently
queried.
  • Loading branch information
bachase committed Nov 29, 2017
1 parent 02059a2 commit 044dd53
Show file tree
Hide file tree
Showing 18 changed files with 1,139 additions and 200 deletions.
14 changes: 14 additions & 0 deletions Builds/VisualStudio2015/RippleD.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3025,6 +3025,14 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\rpc\handlers\ValidatorListSites.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\rpc\handlers\Validators.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\rpc\handlers\Version.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\rpc\handlers\WalletPropose.cpp">
Expand Down Expand Up @@ -4761,6 +4769,8 @@
</ClInclude>
<ClInclude Include="..\..\src\test\jtx\trust.h">
</ClInclude>
<ClInclude Include="..\..\src\test\jtx\TrustedPublisherServer.h">
</ClInclude>
<ClInclude Include="..\..\src\test\jtx\txflags.h">
</ClInclude>
<ClInclude Include="..\..\src\test\jtx\utility.h">
Expand Down Expand Up @@ -5047,6 +5057,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\test\rpc\ValidatorRPC_test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\test\server\ServerStatus_test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
Expand Down
12 changes: 12 additions & 0 deletions Builds/VisualStudio2015/RippleD.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -3630,6 +3630,12 @@
<ClCompile Include="..\..\src\ripple\rpc\handlers\ValidationSeed.cpp">
<Filter>ripple\rpc\handlers</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\rpc\handlers\ValidatorListSites.cpp">
<Filter>ripple\rpc\handlers</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\rpc\handlers\Validators.cpp">
<Filter>ripple\rpc\handlers</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\rpc\handlers\Version.h">
<Filter>ripple\rpc\handlers</Filter>
</ClInclude>
Expand Down Expand Up @@ -5523,6 +5529,9 @@
<ClInclude Include="..\..\src\test\jtx\trust.h">
<Filter>test\jtx</Filter>
</ClInclude>
<ClInclude Include="..\..\src\test\jtx\TrustedPublisherServer.h">
<Filter>test\jtx</Filter>
</ClInclude>
<ClInclude Include="..\..\src\test\jtx\txflags.h">
<Filter>test\jtx</Filter>
</ClInclude>
Expand Down Expand Up @@ -5736,6 +5745,9 @@
<ClCompile Include="..\..\src\test\rpc\TransactionHistory_test.cpp">
<Filter>test\rpc</Filter>
</ClCompile>
<ClCompile Include="..\..\src\test\rpc\ValidatorRPC_test.cpp">
<Filter>test\rpc</Filter>
</ClCompile>
<ClCompile Include="..\..\src\test\server\ServerStatus_test.cpp">
<Filter>test\server</Filter>
</ClCompile>
Expand Down
23 changes: 23 additions & 0 deletions src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2148,6 +2148,29 @@ Json::Value NetworkOPsImp::getServerInfo (bool human, bool admin)
info[jss::validation_quorum] = static_cast<Json::UInt>(
app_.validators ().quorum ());

if (admin)
{
if (auto when = app_.validators().expires())
{
if (human)
{
if(*when == TimeKeeper::time_point::max())
info[jss::validator_list_expires] = "never";
else
info[jss::validator_list_expires] = to_string(*when);
}
else
info[jss::validator_list_expires] =
static_cast<Json::UInt>(when->time_since_epoch().count());
}
else
{
if (human)
info[jss::validator_list_expires] = "unknown";
else
info[jss::validator_list_expires] = 0;
}
}
info[jss::io_latency_ms] = static_cast<Json::UInt> (
app_.getIOLatency().count());

Expand Down
43 changes: 37 additions & 6 deletions src/ripple/app/misc/ValidatorList.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <ripple/basics/UnorderedContainers.h>
#include <ripple/core/TimeKeeper.h>
#include <ripple/crypto/csprng.h>
#include <ripple/json/json_value.h>
#include <ripple/protocol/PublicKey.h>
#include <boost/iterator/counting_iterator.hpp>
#include <boost/range/adaptors.hpp>
Expand All @@ -40,6 +41,9 @@ enum class ListDisposition
/// List is valid
accepted = 0,

/// Same sequence as current list
same_sequence,

/// List version is not supported
unsupported_version,

Expand All @@ -50,9 +54,12 @@ enum class ListDisposition
stale,

/// Invalid format or signature
invalid,
invalid
};

std::string
to_string(ListDisposition disposition);

/**
Trusted Validators List
-----------------------
Expand Down Expand Up @@ -103,7 +110,7 @@ class ValidatorList
bool available;
std::vector<PublicKey> list;
std::size_t sequence;
std::size_t expiration;
TimeKeeper::time_point expiration;
};

ManifestCache& validatorManifests_;
Expand All @@ -126,6 +133,9 @@ class ValidatorList

PublicKey localPubKey_;

// Currently supported version of publisher list format
static constexpr std::uint32_t requiredListVersion = 1;

// The minimum number of listed validators required to allow removing
// non-communicative validators from the trusted set. In other words, if the
// number of listed validators is less, then use all of them in the
Expand All @@ -135,6 +145,8 @@ class ValidatorList
// tolerance isn't needed.
std::size_t const BYZANTINE_THRESHOLD {32};



public:
ValidatorList (
ManifestCache& validatorManifests,
Expand Down Expand Up @@ -318,6 +330,26 @@ class ValidatorList
for_each_listed (
std::function<void(PublicKey const&, bool)> func) const;

/** Return the time when the validator list will expire
@note This may be a time in the past if a published list has not
been updated since its expiration. It will be boost::none if any
configured published list has not been fetched.
@par Thread Safety
May be called concurrently
*/
boost::optional<TimeKeeper::time_point>
expires() const;

/** Return a JSON representation of the state of the validator list
@par Thread Safety
May be called concurrently
*/
Json::Value
getJson() const;

private:
/** Check response for trusted valid published list
Expand Down Expand Up @@ -374,10 +406,9 @@ ValidatorList::onConsensusStart (
for (auto const& list : publisherLists_)
{
// Remove any expired published lists
if (list.second.expiration &&
list.second.expiration <=
timeKeeper_.now().time_since_epoch().count())
removePublisherList (list.first);
if (TimeKeeper::time_point{} < list.second.expiration &&
list.second.expiration <= timeKeeper_.now())
removePublisherList(list.first);

if (! list.second.available)
allListsAvailable = false;
Expand Down
13 changes: 13 additions & 0 deletions src/ripple/app/misc/ValidatorSite.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <ripple/app/misc/detail/Work.h>
#include <ripple/basics/Log.h>
#include <ripple/basics/StringUtilities.h>
#include <ripple/json/json_value.h>
#include <boost/asio.hpp>
#include <mutex>

Expand Down Expand Up @@ -68,10 +69,17 @@ class ValidatorSite

struct Site
{
struct Status
{
clock_type::time_point refreshed;
ListDisposition disposition;
};

std::string uri;
parsedURL pUrl;
std::chrono::minutes refreshInterval;
clock_type::time_point nextRefresh;
boost::optional<Status> lastRefreshStatus;
};

boost::asio::io_service& ios_;
Expand Down Expand Up @@ -146,6 +154,11 @@ class ValidatorSite
void
stop ();

/** Return JSON representation of configured validator sites
*/
Json::Value
getJson() const;

private:
/// Queue next site to be fetched
void
Expand Down
Loading

0 comments on commit 044dd53

Please sign in to comment.