Skip to content

Commit

Permalink
Refactor Validations (RIPD-1412,RIPD-1356):
Browse files Browse the repository at this point in the history
Introduces a generic Validations class for storing and querying current and
recent validations.  Aditionally migrates the validation related timing
constants from LedgerTiming to the new Validations code.

Introduces RCLValidations as the version of Validations adapted for use in the
RCL.  This adds support for flushing/writing validations to the sqlite log and
also manages concurrent access to the Validations data.

RCLValidations::flush() no longer uses the JobQueue for its database
write at shutdown.  It performs the write directly without
changing threads.
  • Loading branch information
bachase committed Apr 27, 2017
1 parent 1dbc5a5 commit 231984b
Show file tree
Hide file tree
Showing 25 changed files with 2,288 additions and 733 deletions.
18 changes: 12 additions & 6 deletions Builds/VisualStudio2015/RippleD.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,12 @@
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\consensus\RCLCxTx.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\consensus\RCLValidations.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\app\consensus\RCLValidations.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\ledger\AbstractFetchPackContainer.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\ledger\AcceptedLedger.cpp">
Expand Down Expand Up @@ -1093,12 +1099,6 @@
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\misc\TxQ.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\misc\Validations.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\app\misc\Validations.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\misc\ValidatorList.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\misc\ValidatorSite.h">
Expand Down Expand Up @@ -1839,6 +1839,8 @@
</ClCompile>
<ClInclude Include="..\..\src\ripple\consensus\LedgerTiming.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\consensus\Validations.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\core\Config.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\core\ConfigSections.h">
Expand Down Expand Up @@ -4419,6 +4421,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\test\consensus\Validations_test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\test\core\Config_test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
Expand Down
18 changes: 12 additions & 6 deletions Builds/VisualStudio2015/RippleD.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,12 @@
<ClInclude Include="..\..\src\ripple\app\consensus\RCLCxTx.h">
<Filter>ripple\app\consensus</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\consensus\RCLValidations.cpp">
<Filter>ripple\app\consensus</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\app\consensus\RCLValidations.h">
<Filter>ripple\app\consensus</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\app\ledger\AbstractFetchPackContainer.h">
<Filter>ripple\app\ledger</Filter>
</ClInclude>
Expand Down Expand Up @@ -1617,12 +1623,6 @@
<ClInclude Include="..\..\src\ripple\app\misc\TxQ.h">
<Filter>ripple\app\misc</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\misc\Validations.cpp">
<Filter>ripple\app\misc</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\app\misc\Validations.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 @@ -2469,6 +2469,9 @@
<ClInclude Include="..\..\src\ripple\consensus\LedgerTiming.h">
<Filter>ripple\consensus</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\consensus\Validations.h">
<Filter>ripple\consensus</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\core\Config.h">
<Filter>ripple\core</Filter>
</ClInclude>
Expand Down Expand Up @@ -5166,6 +5169,9 @@
<ClCompile Include="..\..\src\test\consensus\LedgerTiming_test.cpp">
<Filter>test\consensus</Filter>
</ClCompile>
<ClCompile Include="..\..\src\test\consensus\Validations_test.cpp">
<Filter>test\consensus</Filter>
</ClCompile>
<ClCompile Include="..\..\src\test\core\Config_test.cpp">
<Filter>test\core</Filter>
</ClCompile>
Expand Down
2 changes: 2 additions & 0 deletions docs/source.dox
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,15 @@ INPUT = \
../src/ripple/consensus/ConsensusProposal.h \
../src/ripple/consensus/DisputedTx.h \
../src/ripple/consensus/LedgerTiming.h \
../src/ripple/consensus/Validations.h \
../src/ripple/app/consensus/RCLCxTx.h \
../src/ripple/app/consensus/RCLCxLedger.h \
../src/ripple/app/consensus/RCLConsensus.h \
../src/ripple/app/consensus/RCLCxPeerPos.h \
../src/ripple/app/tx/apply.h \
../src/ripple/app/tx/applySteps.h \
../src/ripple/app/tx/impl/InvariantCheck.h \
../src/ripple/app/consensus/RCLValidations.h \

INPUT_ENCODING = UTF-8
FILE_PATTERNS =
Expand Down
28 changes: 13 additions & 15 deletions src/ripple/app/consensus/RCLConsensus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#include <BeastConfig.h>
#include <ripple/app/consensus/RCLConsensus.h>
#include <ripple/app/consensus/RCLValidations.h>
#include <ripple/app/ledger/InboundLedgers.h>
#include <ripple/app/ledger/InboundTransactions.h>
#include <ripple/app/ledger/LedgerMaster.h>
Expand Down Expand Up @@ -223,7 +224,7 @@ RCLConsensus::hasOpenTransactions() const
std::size_t
RCLConsensus::proposersValidated(LedgerHash const& h) const
{
return app_.getValidations().getTrustedValidationCount(h);
return app_.getValidations().numTrustedForLedger(h);
}

std::size_t
Expand All @@ -245,20 +246,21 @@ RCLConsensus::getPrevLedger(

// Get validators that are on our ledger, or "close" to being on
// our ledger.
auto vals = app_.getValidations().getCurrentValidations(
ledgerID, parentID, ledgerMaster_.getValidLedgerIndex());
auto vals =
app_.getValidations().currentTrustedDistribution(
ledgerID, parentID, ledgerMaster_.getValidLedgerIndex());

uint256 netLgr = ledgerID;
int netLgrCount = 0;
for (auto& it : vals)
{
// Switch to ledger supported by more peers
// Or stick with ours on a tie
if ((it.second.first > netLgrCount) ||
((it.second.first == netLgrCount) && (it.first == ledgerID)))
if ((it.second.count > netLgrCount) ||
((it.second.count== netLgrCount) && (it.first == ledgerID)))
{
netLgr = it.first;
netLgrCount = it.second.first;
netLgrCount = it.second.count;
}
}

Expand All @@ -270,7 +272,7 @@ RCLConsensus::getPrevLedger(
if (auto stream = j_.debug())
{
for (auto& it : vals)
stream << "V: " << it.first << ", " << it.second.first;
stream << "V: " << it.first << ", " << it.second.count;
stream << getJson(true);
}
}
Expand Down Expand Up @@ -318,14 +320,10 @@ RCLConsensus::onClose(
{
// previous ledger was flag ledger, add pseudo-transactions
auto const validations =
app_.getValidations().getValidations(prevLedger->info().parentHash);
app_.getValidations().getTrustedForLedger (
prevLedger->info().parentHash);

std::size_t const count = std::count_if(
validations.begin(), validations.end(), [](auto const& v) {
return v.second->isTrusted();
});

if (count >= app_.validators().quorum())
if (validations.size() >= app_.validators ().quorum ())
{
feeVote_->doVoting(prevLedger, validations, initialSet);
app_.getAmendmentTable().doVoting(
Expand Down Expand Up @@ -838,7 +836,7 @@ RCLConsensus::validate(RCLCxLedger const& ledger, bool proposing)
v->setTrusted();
// suppress it if we receive it - FIXME: wrong suppression
app_.getHashRouter().addSuppression(signingHash);
app_.getValidations().addValidation(v, "local");
handleNewValidation(app_, v, "local");
Blob validation = v->getSerialized();
protocol::TMValidation val;
val.set_validation(&validation[0], validation.size());
Expand Down
Loading

0 comments on commit 231984b

Please sign in to comment.