Skip to content

Commit

Permalink
Expose consensus parameters for simulation (RIPD-1355)
Browse files Browse the repository at this point in the history
  • Loading branch information
bachase committed Jul 10, 2017
1 parent 3ad4575 commit 1438ae3
Show file tree
Hide file tree
Showing 16 changed files with 441 additions and 282 deletions.
10 changes: 6 additions & 4 deletions Builds/VisualStudio2015/RippleD.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1827,16 +1827,18 @@
</ClInclude>
<ClInclude Include="..\..\src\ripple\conditions\impl\utils.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\consensus\Consensus.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\consensus\Consensus.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\consensus\ConsensusParms.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\consensus\ConsensusProposal.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\consensus\DisputedTx.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\consensus\LedgerTiming.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='debug|x64'">True</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='release|x64'">True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\consensus\LedgerTiming.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\consensus\Validations.h">
Expand Down
9 changes: 6 additions & 3 deletions Builds/VisualStudio2015/RippleD.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -2454,18 +2454,21 @@
<ClInclude Include="..\..\src\ripple\conditions\impl\utils.h">
<Filter>ripple\conditions\impl</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\consensus\Consensus.cpp">
<Filter>ripple\consensus</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\consensus\Consensus.h">
<Filter>ripple\consensus</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\consensus\ConsensusParms.h">
<Filter>ripple\consensus</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\consensus\ConsensusProposal.h">
<Filter>ripple\consensus</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\consensus\DisputedTx.h">
<Filter>ripple\consensus</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\consensus\LedgerTiming.cpp">
<Filter>ripple\consensus</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\consensus\LedgerTiming.h">
<Filter>ripple\consensus</Filter>
</ClInclude>
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/DisputedTx.h \
../src/ripple/consensus/LedgerTiming.h \
../src/ripple/consensus/Validations.h \
../src/ripple/consensus/ConsensusParms.h \
../src/ripple/app/consensus/RCLCxTx.h \
../src/ripple/app/consensus/RCLCxLedger.h \
../src/ripple/app/consensus/RCLConsensus.h \
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/app/consensus/RCLConsensus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ RCLConsensus::RCLConsensus(
InboundTransactions& inboundTransactions,
typename Base::clock_type const& clock,
beast::Journal journal)
: Base(clock, journal)
: Base(clock, ConsensusParms{}, journal)
, app_(app)
, feeVote_(std::move(feeVote))
, ledgerMaster_(ledgerMaster)
Expand Down
4 changes: 2 additions & 2 deletions src/ripple/app/misc/NetworkOPs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <ripple/app/ledger/AcceptedLedger.h>
#include <ripple/app/ledger/InboundLedgers.h>
#include <ripple/app/ledger/LedgerMaster.h>
#include <ripple/consensus/LedgerTiming.h>
#include <ripple/consensus/ConsensusParms.h>
#include <ripple/app/ledger/LedgerToJson.h>
#include <ripple/app/ledger/LocalTxs.h>
#include <ripple/app/ledger/OpenLedger.h>
Expand Down Expand Up @@ -639,7 +639,7 @@ void NetworkOPsImp::setStateTimer ()

void NetworkOPsImp::setHeartbeatTimer ()
{
m_heartbeatTimer.setExpiration (LEDGER_GRANULARITY);
m_heartbeatTimer.setExpiration (mConsensus->parms().ledgerGRANULARITY);
}

void NetworkOPsImp::setClusterTimer ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@

#include <BeastConfig.h>
#include <ripple/basics/Log.h>
#include <ripple/consensus/LedgerTiming.h>
#include <algorithm>
#include <iterator>
#include <ripple/consensus/Consensus.h>

namespace ripple {

Expand All @@ -33,13 +31,15 @@ shouldCloseLedger(
std::size_t proposersValidated,
std::chrono::milliseconds prevRoundTime,
std::chrono::milliseconds
timeSincePrevClose, // Time since last ledger's close time
timeSincePrevClose, // Time since last ledger's close time
std::chrono::milliseconds openTime, // Time waiting to close this ledger
std::chrono::seconds idleInterval,
std::chrono::milliseconds idleInterval,
ConsensusParms const& parms,
beast::Journal j)
{
using namespace std::chrono_literals;
if ((prevRoundTime < -1s) || (prevRoundTime > 10min) || (timeSincePrevClose > 10min))
if ((prevRoundTime < -1s) || (prevRoundTime > 10min) ||
(timeSincePrevClose > 10min))
{
// These are unexpected cases, we just close the ledger
JLOG(j.warn()) << "shouldCloseLedger Trans="
Expand All @@ -64,7 +64,7 @@ shouldCloseLedger(
}

// Preserve minimum ledger open time
if (openTime < LEDGER_MIN_CLOSE)
if (openTime < parms.ledgerMIN_CLOSE)
{
JLOG(j.debug()) << "Must wait minimum time before closing";
return false;
Expand All @@ -84,7 +84,11 @@ shouldCloseLedger(
}

bool
checkConsensusReached(std::size_t agreeing, std::size_t total, bool count_self)
checkConsensusReached(
std::size_t agreeing,
std::size_t total,
bool count_self,
std::size_t minConsensusPct)
{
// If we are alone, we have a consensus
if (total == 0)
Expand All @@ -96,9 +100,9 @@ checkConsensusReached(std::size_t agreeing, std::size_t total, bool count_self)
++total;
}

int currentPercentage = (agreeing * 100) / total;
std::size_t currentPercentage = (agreeing * 100) / total;

return currentPercentage > minimumConsensusPercentage;
return currentPercentage > minConsensusPct;
}

ConsensusState
Expand All @@ -109,6 +113,7 @@ checkConsensus(
std::size_t currentFinished,
std::chrono::milliseconds previousAgreeTime,
std::chrono::milliseconds currentAgreeTime,
ConsensusParms const& parms,
bool proposing,
beast::Journal j)
{
Expand All @@ -118,14 +123,14 @@ checkConsensus(
<< " time=" << currentAgreeTime.count() << "/"
<< previousAgreeTime.count();

if (currentAgreeTime <= LEDGER_MIN_CONSENSUS)
if (currentAgreeTime <= parms.ledgerMIN_CONSENSUS)
return ConsensusState::No;

if (currentProposers < (prevProposers * 3 / 4))
{
// Less than 3/4 of the last ledger's proposers are present; don't
// rush: we may need more time.
if (currentAgreeTime < (previousAgreeTime + LEDGER_MIN_CONSENSUS))
if (currentAgreeTime < (previousAgreeTime + parms.ledgerMIN_CONSENSUS))
{
JLOG(j.trace()) << "too fast, not enough proposers";
return ConsensusState::No;
Expand All @@ -134,15 +139,17 @@ checkConsensus(

// Have we, together with the nodes on our UNL list, reached the threshold
// to declare consensus?
if (checkConsensusReached(currentAgree, currentProposers, proposing))
if (checkConsensusReached(
currentAgree, currentProposers, proposing, parms.minCONSENSUS_PCT))
{
JLOG(j.debug()) << "normal consensus";
return ConsensusState::Yes;
}

// Have sufficient nodes on our UNL list moved on and reached the threshold
// to declare consensus?
if (checkConsensusReached(currentFinished, currentProposers, false))
if (checkConsensusReached(
currentFinished, currentProposers, false, parms.minCONSENSUS_PCT))
{
JLOG(j.warn()) << "We see no consensus, but 80% of nodes have moved on";
return ConsensusState::MovedOn;
Expand All @@ -153,4 +160,4 @@ checkConsensus(
return ConsensusState::No;
}

} // ripple
} // namespace ripple
Loading

0 comments on commit 1438ae3

Please sign in to comment.