Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ripple calc #410

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/ripple/module/app/book/Taker.h
Original file line number Diff line number Diff line change
@@ -70,7 +70,6 @@ class Taker
// The amounts still left over for us to try and take.
Amounts m_remain;

private:
Amounts
flow (Amounts amount, Offer const& offer, Account const& taker);

38 changes: 0 additions & 38 deletions src/ripple/module/app/book/Types.h
Original file line number Diff line number Diff line change
@@ -30,38 +30,6 @@
namespace ripple {
namespace core {

namespace detail {

class AccountTag {};
class CurrencyTag {};

} // detail

typedef base_uint<160, detail::AccountTag> Account;
typedef base_uint<160, detail::CurrencyTag> Currency;

inline std::string to_string(Currency const& c)
{
return STAmount::createHumanCurrency(c);
}

inline std::string to_string(Account const& a)
{
return RippleAddress::createHumanAccountID(a);
}

inline std::ostream& operator<< (std::ostream& os, Account const& x)
{
os << to_string (x);
return os;
}

inline std::ostream& operator<< (std::ostream& os, Currency const& x)
{
os << to_string (x);
return os;
}

/** A mutable view that overlays an immutable ledger to track changes. */
typedef LedgerEntrySet LedgerView;

@@ -85,12 +53,6 @@ class Clock // : public abstract_clock <std::chrono::seconds>
};

} // core

inline bool isXRP(core::Currency const& c)
{
return c == zero;
}

} // ripple

#endif
29 changes: 0 additions & 29 deletions src/ripple/module/app/book/impl/Types.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/ripple/module/app/book/tests/Quality.test.cpp
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ class Quality_test : public beast::unit_test::suite
Amount
static raw (std::uint64_t mantissa, int exponent)
{
return Amount (uint160(3), uint160(3), mantissa, exponent);
return Amount (Currency(3), Account(3), mantissa, exponent);
}

template <class Integer>
42 changes: 23 additions & 19 deletions src/ripple/module/app/consensus/DisputedTx.cpp
Original file line number Diff line number Diff line change
@@ -22,48 +22,50 @@ namespace ripple {
// #define TRUST_NETWORK

// Track a peer's yes/no vote on a particular disputed transaction
void DisputedTx::setVote (const uint160& peer, bool votesYes)
void DisputedTx::setVote (NodeID const& peer, bool votesYes)
{
// VFALCO TODO Simplify this declaration. It doesn't exactly roll off the tongue!
std::pair <ripple::unordered_map <uint160, bool>::iterator, bool> res =
mVotes.insert (std::make_pair (peer, votesYes));
auto res = mVotes.insert (std::make_pair (peer, votesYes));

// new vote
if (res.second)
{
if (votesYes)
{
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer << " votes YES on " << mTransactionID;
WriteLog (lsDEBUG, LedgerConsensus)
<< "Peer " << peer << " votes YES on " << mTransactionID;
++mYays;
}
else
{
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer << " votes NO on " << mTransactionID;
WriteLog (lsDEBUG, LedgerConsensus)
<< "Peer " << peer << " votes NO on " << mTransactionID;
++mNays;
}
}
// changes vote to yes
else if (votesYes && !res.first->second)
{
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer << " now votes YES on " << mTransactionID;
WriteLog (lsDEBUG, LedgerConsensus)
<< "Peer " << peer << " now votes YES on " << mTransactionID;
--mNays;
++mYays;
res.first->second = true;
}
// changes vote to no
else if (!votesYes && res.first->second)
{
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer << " now votes NO on " << mTransactionID;
WriteLog (lsDEBUG, LedgerConsensus) << "Peer " << peer
<< " now votes NO on " << mTransactionID;
++mNays;
--mYays;
res.first->second = false;
}
}

// Remove a peer's vote on this disputed transasction
void DisputedTx::unVote (const uint160& peer)
void DisputedTx::unVote (NodeID const& peer)
{
ripple::unordered_map<uint160, bool>::iterator it = mVotes.find (peer);
auto it = mVotes.find (peer);

if (it != mVotes.end ())
{
@@ -95,10 +97,12 @@ bool DisputedTx::updateVote (int percentTime, bool proposing)
// This is basically the percentage of nodes voting 'yes' (including us)
weight = (mYays * 100 + (mOurVote ? 100 : 0)) / (mNays + mYays + 1);

// VFALCO TODO Rename these macros and turn them into language constructs.
// consolidate them into a class that collects all these related values.
// VFALCO TODO Rename these macros and turn them into language
// constructs. consolidate them into a class that collects
// all these related values.
//
// To prevent avalanche stalls, we increase the needed weight slightly over time
// To prevent avalanche stalls, we increase the needed weight slightly
// over time.
if (percentTime < AV_MID_CONSENSUS_TIME)
newPosition = weight > AV_INIT_CONSENSUS_PCT;
else if (percentTime < AV_LATE_CONSENSUS_TIME)
@@ -116,14 +120,17 @@ bool DisputedTx::updateVote (int percentTime, bool proposing)

if (newPosition == mOurVote)
{
WriteLog (lsINFO, LedgerConsensus) <<
"No change (" << (mOurVote ? "YES" : "NO") << ") : weight " << weight << ", percent " << percentTime;
WriteLog (lsINFO, LedgerConsensus)
<< "No change (" << (mOurVote ? "YES" : "NO") << ") : weight "
<< weight << ", percent " << percentTime;
WriteLog (lsDEBUG, LedgerConsensus) << getJson ();
return false;
}

mOurVote = newPosition;
WriteLog (lsDEBUG, LedgerConsensus) << "We now vote " << (mOurVote ? "YES" : "NO") << " on " << mTransactionID;
WriteLog (lsDEBUG, LedgerConsensus)
<< "We now vote " << (mOurVote ? "YES" : "NO")
<< " on " << mTransactionID;
WriteLog (lsDEBUG, LedgerConsensus) << getJson ();
return true;
}
@@ -140,14 +147,11 @@ Json::Value DisputedTx::getJson ()
{
Json::Value votesj (Json::objectValue);
for (auto& vote : mVotes)
{
votesj[to_string (vote.first)] = vote.second;
}
ret["votes"] = votesj;
}

return ret;
}

} // ripple

10 changes: 4 additions & 6 deletions src/ripple/module/app/consensus/DisputedTx.h
Original file line number Diff line number Diff line change
@@ -66,8 +66,8 @@ class DisputedTx

// VFALCO NOTE its not really a peer, its the 160 bit hash of the validator's public key
//
void setVote (uint160 const& peer, bool votesYes);
void unVote (uint160 const& peer);
void setVote (NodeID const& peer, bool votesYes);
void unVote (NodeID const& peer);

bool updateVote (int percentTime, bool proposing);
Json::Value getJson ();
@@ -78,12 +78,10 @@ class DisputedTx
int mNays;
bool mOurVote;
Serializer transaction;
ripple::unordered_map <uint160, bool> mVotes;

ripple::unordered_map <NodeID, bool> mVotes;
};

// VFALCO TODO Rename and put these in a tidy place
typedef std::map<uint256, DisputedTx::pointer>::value_type u256_lct_pair;
typedef std::map<uint160, LedgerProposal::pointer>::value_type u160_prop_pair;
#define LEDGER_TOTAL_PASSES 8
#define LEDGER_RETRY_PASSES 5

26 changes: 10 additions & 16 deletions src/ripple/module/app/consensus/LedgerConsensus.cpp
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@
//==============================================================================

#include <ripple/overlay/predicates.h>
#include <ripple/types/api/UintTypes.h>

namespace ripple {

@@ -340,7 +341,7 @@ class LedgerConsensusImp
mAcquiring.erase (hash);

// Adjust tracking for each peer that takes this position
std::vector<uint160> peers;
std::vector<NodeID> peers;
for (auto& it : mPeerPositions)
{
if (it.second->getCurrentHash () == map->getHash ())
@@ -392,7 +393,7 @@ class LedgerConsensusImp
if (mHaveCorrectLCL)
priorLedger = mPreviousLedger->getParentHash (); // don't jump back

ripple::unordered_map<uint256, currentValidationCount> vals =
ripple::unordered_map<uint256, ValidationCounter> vals =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this be auto?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it could. But in this case I actually like the explicit type. On lines 404 and 453 in for-range loops, it is so much easier to see what the value_type is that the loops are working on with the type spelled out explicitly on line 400. I.e. the for loops are using the first and second types of the value_type, which we now know are uint256 and ValidationCounter. With auto we would have to go looking.

I don't yet have a good guideline for when auto is harmful and and when it is helpful. This type of experience will hopefully lead us towards such a guideline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been playing with auto for a while now (before I got here).

My new theory is that I should always use auto when possible - simply because it frees me of the cognitive burden of deciding when I should use it and makes the code as short as possible.

It should take you almost no time to "go looking" for the actual type if your IDE is any good - or even if it isn't, I mainly work in emacs which is less good and it's still not an issue.

But I didn't go looking for trouble here. I only changed things I was "forced to" - i.e. Accounts and Currencies where I wanted to create code that was good before and after the change of type.

getApp().getValidations ().getCurrentValidations
(favoredLedger, priorLedger);

@@ -701,7 +702,7 @@ class LedgerConsensusImp
*/
bool peerPosition (LedgerProposal::ref newPosition)
{
uint160 peerID = newPosition->getPeerID ();
auto peerID = newPosition->getPeerID ();

if (mDeadNodes.find (peerID) != mDeadNodes.end ())
{
@@ -761,8 +762,6 @@ class LedgerConsensusImp
{
WriteLog (lsDEBUG, LedgerConsensus)
<< "Don't have tx set for peer";
// BOOST_FOREACH(u256_lct_pair& it, mDisputes)
// it.second->unVote(peerID);
}

return true;
@@ -1194,7 +1193,7 @@ class LedgerConsensusImp
/** Adjust the counts on all disputed transactions based
on the set of peers taking this position
*/
void adjustCount (SHAMap::ref map, const std::vector<uint160>& peers)
void adjustCount (SHAMap::ref map, const std::vector<NodeID>& peers)
{
for (auto& it : mDisputes)
{
@@ -1380,7 +1379,7 @@ class LedgerConsensusImp
return resultSuccess;
}

if (isTefFailure (result) || isTemMalformed (result) ||
if (isTefFailure (result) || isTemMalformed (result) ||
isTelLocal (result))
{
// failure
@@ -1696,15 +1695,10 @@ class LedgerConsensusImp
*/
void playbackProposals ()
{
ripple::unordered_map < uint160,
std::list<LedgerProposal::pointer> > & storedProposals
= getApp().getOPs ().peekStoredProposals ();

for (auto it = storedProposals.begin ()
, end = storedProposals.end (); it != end; ++it)
for (auto it: getApp().getOPs ().peekStoredProposals ())
{
bool relay = false;
for (auto proposal : it->second)
for (auto proposal : it.second)
{
if (proposal->hasSignature ())
{
@@ -1892,7 +1886,7 @@ class LedgerConsensusImp
int mPreviousMSeconds;

// Convergence tracking, trusted peers indexed by hash of public key
ripple::unordered_map<uint160, LedgerProposal::pointer> mPeerPositions;
ripple::unordered_map<NodeID, LedgerProposal::pointer> mPeerPositions;

// Transaction Sets, indexed by hash of transaction tree
ripple::unordered_map<uint256, SHAMap::pointer> mAcquired;
@@ -1910,7 +1904,7 @@ class LedgerConsensusImp
std::map<std::uint32_t, int> mCloseTimes;

// nodes that have bowed out of this consensus process
boost::unordered_set<uint160> mDeadNodes;
NodeIDSet mDeadNodes;
};

//------------------------------------------------------------------------------
48 changes: 0 additions & 48 deletions src/ripple/module/app/contracts/Contract.cpp

This file was deleted.

Loading