Skip to content

Commit

Permalink
Use LedgerTrie for preferred ledger (RIPD-1551):
Browse files Browse the repository at this point in the history
These changes augment the Validations class with a LedgerTrie to better
track the history of support for validated ledgers. This improves the
selection of the preferred working ledger for consensus. The Validations
class now tracks both full and partial validations. Partial validations
are only used to determine the working ledger; full validations are
required for any quorum related function. Validators are also now
explicitly restricted to sending validations with increasing ledger
sequence number.
  • Loading branch information
bachase committed Feb 3, 2018
1 parent 1c44c4a commit 94c6a2a
Show file tree
Hide file tree
Showing 26 changed files with 3,611 additions and 1,006 deletions.
10 changes: 10 additions & 0 deletions Builds/VisualStudio2015/RippleD.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,8 @@
</ClInclude>
<ClInclude Include="..\..\src\ripple\consensus\LedgerTiming.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\consensus\LedgerTrie.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\consensus\Validations.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\core\ClosureCounter.h">
Expand Down Expand Up @@ -4501,6 +4503,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\test\app\RCLValidations_test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\test\app\Regression_test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
Expand Down Expand Up @@ -4685,6 +4691,10 @@
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\test\consensus\LedgerTrie_test.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\test\consensus\ScaleFreeSim_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 @@ -2151,6 +2151,9 @@
<ClInclude Include="..\..\src\ripple\consensus\LedgerTiming.h">
<Filter>ripple\consensus</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\consensus\LedgerTrie.h">
<Filter>ripple\consensus</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\consensus\Validations.h">
<Filter>ripple\consensus</Filter>
</ClInclude>
Expand Down Expand Up @@ -5268,6 +5271,9 @@
<ClCompile Include="..\..\src\test\app\PseudoTx_test.cpp">
<Filter>test\app</Filter>
</ClCompile>
<ClCompile Include="..\..\src\test\app\RCLValidations_test.cpp">
<Filter>test\app</Filter>
</ClCompile>
<ClCompile Include="..\..\src\test\app\Regression_test.cpp">
<Filter>test\app</Filter>
</ClCompile>
Expand Down Expand Up @@ -5406,6 +5412,9 @@
<ClCompile Include="..\..\src\test\consensus\LedgerTiming_test.cpp">
<Filter>test\consensus</Filter>
</ClCompile>
<ClCompile Include="..\..\src\test\consensus\LedgerTrie_test.cpp">
<Filter>test\consensus</Filter>
</ClCompile>
<ClCompile Include="..\..\src\test\consensus\ScaleFreeSim_test.cpp">
<Filter>test\consensus</Filter>
</ClCompile>
Expand Down
1 change: 1 addition & 0 deletions docs/source.dox
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ INPUT = \
../src/ripple/consensus/ConsensusTypes.h \
../src/ripple/consensus/DisputedTx.h \
../src/ripple/consensus/LedgerTiming.h \
../src/ripple/consensus/LedgerTrie.h \
../src/ripple/consensus/Validations.h \
../src/ripple/consensus/ConsensusParms.h \
../src/ripple/app/consensus/RCLCxTx.h \
Expand Down
38 changes: 17 additions & 21 deletions src/ripple/app/consensus/RCLConsensus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,13 @@ RCLConsensus::Adaptor::proposersValidated(LedgerHash const& h) const
}

std::size_t
RCLConsensus::Adaptor::proposersFinished(LedgerHash const& h) const
RCLConsensus::Adaptor::proposersFinished(
RCLCxLedger const& ledger,
LedgerHash const& h) const
{
return app_.getValidations().getNodesAfter(h);
RCLValidations& vals = app_.getValidations();
return vals.getNodesAfter(
RCLValidatedLedger(ledger.ledger_, vals.adaptor().journal()), h);
}

uint256
Expand All @@ -244,29 +248,17 @@ RCLConsensus::Adaptor::getPrevLedger(
RCLCxLedger const& ledger,
ConsensusMode mode)
{
uint256 parentID;
// Only set the parent ID if we believe ledger is the right ledger
if (mode != ConsensusMode::wrongLedger)
parentID = ledger.parentID();

// Get validators that are on our ledger, or "close" to being on
// our ledger.
hash_map<uint256, std::uint32_t> ledgerCounts =
app_.getValidations().currentTrustedDistribution(
ledgerID, parentID, ledgerMaster_.getValidLedgerIndex());

uint256 netLgr = getPreferredLedger(ledgerID, ledgerCounts);
RCLValidations& vals = app_.getValidations();
uint256 netLgr = vals.getPreferred(
RCLValidatedLedger{ledger.ledger_, vals.adaptor().journal()},
ledgerMaster_.getValidLedgerIndex());

if (netLgr != ledgerID)
{
if (mode != ConsensusMode::wrongLedger)
app_.getOPs().consensusViewChange();

if (auto stream = j_.debug())
{
for (auto const & it : ledgerCounts)
stream << "V: " << it.first << ", " << it.second;
}
JLOG(j_.debug())<< Json::Compact(app_.getValidations().getJsonTrie());
}

return netLgr;
Expand Down Expand Up @@ -454,7 +446,8 @@ RCLConsensus::Adaptor::doAccept(
app_.journal("LedgerConsensus").warn(),
"Not validating");

if (validating_ && !consensusFail)
if (validating_ && !consensusFail &&
app_.getValidations().canValidateSeq(sharedLCL.seq()))
{
validate(sharedLCL, proposing);
JLOG(j_.info()) << "CNF Val " << newLCLHash;
Expand Down Expand Up @@ -841,7 +834,10 @@ RCLConsensus::Adaptor::validate(RCLCxLedger const& ledger, bool proposing)

// Build validation
auto v = std::make_shared<STValidation>(
ledger.id(), validationTime, valPublic_, proposing);
ledger.id(),
validationTime,
valPublic_,
proposing /* full if proposed */);
v->setFieldU32(sfLedgerSequence, ledger.seq());

// Add our load fee to the validation
Expand Down
7 changes: 4 additions & 3 deletions src/ripple/app/consensus/RCLConsensus.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,13 @@ class RCLConsensus
/** Number of proposers that have validated a ledger descended from
requested ledger.
@param h The hash of the ledger of interest.
@param ledger The current working ledger
@param h The hash of the preferred working ledger
@return The number of validating peers that have validated a ledger
succeeding the one provided.
descended from the preferred working ledger.
*/
std::size_t
proposersFinished(LedgerHash const& h) const;
proposersFinished(RCLCxLedger const & ledger, LedgerHash const& h) const;

/** Propose the given position to my peers.
Expand Down
Loading

0 comments on commit 94c6a2a

Please sign in to comment.