Skip to content

Commit

Permalink
[FOLD] Add ValidatorKeys:
Browse files Browse the repository at this point in the history
Introduce ValidatorKeys struct to store validator key configuration.  This is
loaded from the config at Application creation, so that it can be provided to
RCLConsensus in its constructor.  RCLConsensus can then store the keys as const
members and avoid needing to lock when using them.
  • Loading branch information
bachase committed May 18, 2017
1 parent cc309bd commit 16589d4
Show file tree
Hide file tree
Showing 14 changed files with 328 additions and 80 deletions.
10 changes: 10 additions & 0 deletions Builds/VisualStudio2015/RippleD.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\app\misc\impl\ValidatorKeys.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\app\misc\impl\ValidatorList.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
Expand Down Expand Up @@ -1099,6 +1103,8 @@
</ClCompile>
<ClInclude Include="..\..\src\ripple\app\misc\Validations.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\misc\ValidatorKeys.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\misc\ValidatorList.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\misc\ValidatorSite.h">
Expand Down Expand Up @@ -4293,6 +4299,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\test\app\ValidatorKeys_test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\test\app\ValidatorList_test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
Expand Down
9 changes: 9 additions & 0 deletions Builds/VisualStudio2015/RippleD.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1581,6 +1581,9 @@
<ClCompile Include="..\..\src\ripple\app\misc\impl\TxQ.cpp">
<Filter>ripple\app\misc\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\app\misc\impl\ValidatorKeys.cpp">
<Filter>ripple\app\misc\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\app\misc\impl\ValidatorList.cpp">
<Filter>ripple\app\misc\impl</Filter>
</ClCompile>
Expand Down Expand Up @@ -1623,6 +1626,9 @@
<ClInclude Include="..\..\src\ripple\app\misc\Validations.h">
<Filter>ripple\app\misc</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\misc\ValidatorKeys.h">
<Filter>ripple\app\misc</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\misc\ValidatorList.h">
<Filter>ripple\app\misc</Filter>
</ClInclude>
Expand Down Expand Up @@ -5073,6 +5079,9 @@
<ClCompile Include="..\..\src\test\app\TxQ_test.cpp">
<Filter>test\app</Filter>
</ClCompile>
<ClCompile Include="..\..\src\test\app\ValidatorKeys_test.cpp">
<Filter>test\app</Filter>
</ClCompile>
<ClCompile Include="..\..\src\test\app\ValidatorList_test.cpp">
<Filter>test\app</Filter>
</ClCompile>
Expand Down
21 changes: 6 additions & 15 deletions src/ripple/app/consensus/RCLConsensus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <ripple/app/misc/LoadFeeTrack.h>
#include <ripple/app/misc/NetworkOPs.h>
#include <ripple/app/misc/TxQ.h>
#include <ripple/app/misc/ValidatorKeys.h>
#include <ripple/app/misc/ValidatorList.h>
#include <ripple/app/tx/apply.h>
#include <ripple/basics/make_lock.h>
Expand All @@ -48,13 +49,15 @@ RCLConsensus::RCLConsensus(
LocalTxs& localTxs,
InboundTransactions& inboundTransactions,
Consensus<Adaptor>::clock_type const& clock,
ValidatorKeys const& validatorKeys,
beast::Journal journal)
: adaptor_(
app,
std::move(feeVote),
ledgerMaster,
localTxs,
inboundTransactions,
validatorKeys,
journal)
, consensus_(clock, adaptor_, journal)

Expand All @@ -67,6 +70,7 @@ RCLConsensus::Adaptor::Adaptor(
LedgerMaster& ledgerMaster,
LocalTxs& localTxs,
InboundTransactions& inboundTransactions,
ValidatorKeys const& validatorKeys,
beast::Journal journal)
: app_(app)
, feeVote_(std::move(feeVote))
Expand All @@ -75,6 +79,8 @@ RCLConsensus::Adaptor::Adaptor(
, inboundTransactions_{inboundTransactions}
, j_(journal)
, nodeID_{calcNodeID(app.nodeIdentity().first)}
, valPublic_{validatorKeys.publicKey}
, valSecret_{validatorKeys.secretKey}
{
}

Expand Down Expand Up @@ -862,21 +868,6 @@ RCLConsensus::getJson(bool full) const
return ret;
}

PublicKey const&
RCLConsensus::getValidationPublicKey() const
{
return adaptor_.valPublic_;
}

void
RCLConsensus::setValidationKeys(
SecretKey const& valSecret,
PublicKey const& valPublic)
{
adaptor_.valSecret_ = valSecret;
adaptor_.valPublic_ = valPublic;
}

void
RCLConsensus::timerEntry(NetClock::time_point const& now)
{
Expand Down
15 changes: 5 additions & 10 deletions src/ripple/app/consensus/RCLConsensus.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace ripple {
class InboundTransactions;
class LocalTxs;
class LedgerMaster;
class ValidatorKeys;

/** Manges the generic consensus algorithm for use by the RCL.
Expand Down Expand Up @@ -67,8 +68,8 @@ class RCLConsensus
beast::Journal j_;

NodeID nodeID_;
PublicKey valPublic_;
SecretKey valSecret_;
PublicKey const valPublic_;
SecretKey const valSecret_;
LedgerHash acquiringLedger_;

// The timestamp of the last validation we used, in network time. This
Expand All @@ -84,6 +85,7 @@ class RCLConsensus
LedgerMaster& ledgerMaster,
LocalTxs& localTxs,
InboundTransactions& inboundTransactions,
ValidatorKeys const & validatorKeys,
beast::Journal journal);

/** Attempt to acquire a specific ledger.
Expand Down Expand Up @@ -311,6 +313,7 @@ class RCLConsensus
LocalTxs& localTxs,
InboundTransactions& inboundTransactions,
Consensus<Adaptor>::clock_type const& clock,
ValidatorKeys const & validatorKeys,
beast::Journal journal);

RCLConsensus(RCLConsensus const&) = delete;
Expand Down Expand Up @@ -362,14 +365,6 @@ class RCLConsensus
void
gotTxSet(NetClock::time_point const& now, RCLTxSet const& txSet);

/** Returns validation public key */
PublicKey const&
getValidationPublicKey() const;

/** Set validation private and public key pair. */
void
setValidationKeys(SecretKey const& valSecret, PublicKey const& valPublic);

RCLCxLedger::ID
prevLedgerID() const
{
Expand Down
50 changes: 15 additions & 35 deletions src/ripple/app/main/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include <ripple/app/misc/SHAMapStore.h>
#include <ripple/app/misc/TxQ.h>
#include <ripple/app/misc/ValidatorSite.h>
#include <ripple/app/misc/ValidatorKeys.h>
#include <ripple/app/paths/PathRequests.h>
#include <ripple/app/tx/apply.h>
#include <ripple/basics/ResolverAsio.h>
Expand Down Expand Up @@ -304,6 +305,7 @@ class ApplicationImp
std::unique_ptr <CollectorManager> m_collectorManager;
CachedSLEs cachedSLEs_;
std::pair<PublicKey, SecretKey> nodeIdentity_;
ValidatorKeys const validatorKeys_;

std::unique_ptr <Resource::Manager> m_resourceManager;

Expand Down Expand Up @@ -393,7 +395,7 @@ class ApplicationImp

, m_collectorManager (CollectorManager::New (
config_->section (SECTION_INSIGHT), logs_->journal("Collector")))

, validatorKeys_(*config_, m_journal)
, cachedSLEs_ (std::chrono::minutes(1), stopwatch())

, m_resourceManager (Resource::make_Manager (
Expand Down Expand Up @@ -444,7 +446,7 @@ class ApplicationImp

, m_networkOPs (make_NetworkOPs (*this, stopwatch(),
config_->standalone(), config_->NETWORK_QUORUM, config_->START_VALID,
*m_jobQueue, *m_ledgerMaster, *m_jobQueue,
*m_jobQueue, *m_ledgerMaster, *m_jobQueue, validatorKeys_,
logs_->journal("NetworkOPs")))

, cluster_ (std::make_unique<Cluster> (
Expand Down Expand Up @@ -568,6 +570,13 @@ class ApplicationImp
return nodeIdentity_;
}

virtual
PublicKey const &
getValidationPublicKey() const override
{
return validatorKeys_.publicKey;
}

NetworkOPs& getOPs () override
{
return *m_networkOPs;
Expand Down Expand Up @@ -1082,38 +1091,11 @@ bool ApplicationImp::setup()
}

{
PublicKey valPublic;
SecretKey valSecret;
std::string manifest;
if (config().exists (SECTION_VALIDATOR_TOKEN))
{
if (auto const token = ValidatorToken::make_ValidatorToken (
config().section (SECTION_VALIDATOR_TOKEN).lines ()))
{
valSecret = token->validationSecret;
valPublic = derivePublicKey (KeyType::secp256k1, valSecret);
manifest = std::move(token->manifest);
}
else
{
JLOG(m_journal.fatal()) <<
"Invalid entry in validator token configuration.";
return false;
}
}
else if (config().exists (SECTION_VALIDATION_SEED))
{
auto const seed = parseBase58<Seed>(
config().section (SECTION_VALIDATION_SEED).lines ().front());
if (!seed)
Throw<std::runtime_error> (
"Invalid seed specified in [" SECTION_VALIDATION_SEED "]");
valSecret = generateSecretKey (KeyType::secp256k1, *seed);
valPublic = derivePublicKey (KeyType::secp256k1, valSecret);
}
if(validatorKeys_.configInvalid())
return false;

if (!validatorManifests_->load (
getWalletDB (), "ValidatorManifests", manifest,
getWalletDB (), "ValidatorManifests", validatorKeys_.manifest,
config().section (SECTION_VALIDATOR_KEY_REVOCATION).values ()))
{
JLOG(m_journal.fatal()) << "Invalid configured validator manifest.";
Expand All @@ -1123,11 +1105,9 @@ bool ApplicationImp::setup()
publisherManifests_->load (
getWalletDB (), "PublisherManifests");

m_networkOPs->setValidationKeys (valSecret, valPublic);

// Setup trusted validators
if (!validators_->load (
valPublic,
validatorKeys_.publicKey,
config().section (SECTION_VALIDATORS).values (),
config().section (SECTION_VALIDATOR_LIST_KEYS).values ()))
{
Expand Down
4 changes: 4 additions & 0 deletions src/ripple/app/main/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ class Application : public beast::PropertyStream::Source
std::pair<PublicKey, SecretKey> const&
nodeIdentity () = 0;

virtual
PublicKey const &
getValidationPublicKey() const = 0;

virtual Resource::Manager& getResourceManager () = 0;
virtual PathRequests& getPathRequests () = 0;
virtual SHAMapStore& getSHAMapStore () = 0;
Expand Down
20 changes: 7 additions & 13 deletions src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <ripple/app/misc/LoadFeeTrack.h>
#include <ripple/app/misc/Transaction.h>
#include <ripple/app/misc/TxQ.h>
#include <ripple/app/misc/ValidatorKeys.h>
#include <ripple/app/misc/ValidatorList.h>
#include <ripple/app/misc/impl/AccountTxPaging.h>
#include <ripple/app/tx/apply.h>
Expand Down Expand Up @@ -186,7 +187,7 @@ class NetworkOPsImp final
Application& app, clock_type& clock, bool standalone,
std::size_t network_quorum, bool start_valid, JobQueue& job_queue,
LedgerMaster& ledgerMaster, Stoppable& parent,
beast::Journal journal)
ValidatorKeys const & validatorKeys, beast::Journal journal)
: NetworkOPs (parent)
, app_ (app)
, m_clock (clock)
Expand All @@ -204,6 +205,7 @@ class NetworkOPsImp final
*m_localTX,
app.getInboundTransactions(),
stopwatch(),
validatorKeys,
app_.logs().journal("LedgerConsensus")))
, m_ledgerMaster (ledgerMaster)
, m_job_queue (job_queue)
Expand Down Expand Up @@ -354,15 +356,7 @@ class NetworkOPsImp final
}
void setAmendmentBlocked () override;
void consensusViewChange () override;
PublicKey const& getValidationPublicKey () const override
{
return mConsensus->getValidationPublicKey ();
}
void setValidationKeys (
SecretKey const& valSecret, PublicKey const& valPublic) override
{
mConsensus->setValidationKeys (valSecret, valPublic);
}

Json::Value getConsensusInfo () override;
Json::Value getServerInfo (bool human, bool admin) override;
void clearLedgerFetch () override;
Expand Down Expand Up @@ -2128,7 +2122,7 @@ Json::Value NetworkOPsImp::getServerInfo (bool human, bool admin)

if (admin)
{
if (getValidationPublicKey().size ())
if (app_.getValidationPublicKey().size ())
{
info[jss::pubkey_validator] = toBase58 (
TokenType::TOKEN_NODE_PUBLIC,
Expand Down Expand Up @@ -3321,10 +3315,10 @@ std::unique_ptr<NetworkOPs>
make_NetworkOPs (Application& app, NetworkOPs::clock_type& clock, bool standalone,
std::size_t network_quorum, bool startvalid,
JobQueue& job_queue, LedgerMaster& ledgerMaster,
Stoppable& parent, beast::Journal journal)
Stoppable& parent, ValidatorKeys const & validatorKeys, beast::Journal journal)
{
return std::make_unique<NetworkOPsImp> (app, clock, standalone, network_quorum,
startvalid, job_queue, ledgerMaster, parent, journal);
startvalid, job_queue, ledgerMaster, parent, validatorKeys, journal);
}

} // ripple
6 changes: 2 additions & 4 deletions src/ripple/app/misc/NetworkOPs.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ namespace ripple {
class Peer;
class LedgerMaster;
class Transaction;
class ValidatorKeys;

// This is the primary interface into the "client" portion of the program.
// Code that wants to do normal operations on the network such as
Expand Down Expand Up @@ -174,9 +175,6 @@ class NetworkOPs
virtual bool isAmendmentBlocked () = 0;
virtual void setAmendmentBlocked () = 0;
virtual void consensusViewChange () = 0;
virtual PublicKey const& getValidationPublicKey () const = 0;
virtual void setValidationKeys (
SecretKey const& valSecret, PublicKey const& valPublic) = 0;

virtual Json::Value getConsensusInfo () = 0;
virtual Json::Value getServerInfo (bool human, bool admin) = 0;
Expand Down Expand Up @@ -242,7 +240,7 @@ std::unique_ptr<NetworkOPs>
make_NetworkOPs (Application& app, NetworkOPs::clock_type& clock, bool standalone,
std::size_t network_quorum, bool start_valid,
JobQueue& job_queue, LedgerMaster& ledgerMaster,
Stoppable& parent, beast::Journal journal);
Stoppable& parent, ValidatorKeys const & validatorKeys, beast::Journal journal);

} // ripple

Expand Down
Loading

0 comments on commit 16589d4

Please sign in to comment.