Merge branch 'develop' of github.com:jedmccaleb/NewCoin into develop

This commit is contained in:
Arthur Britto
2013-04-14 22:38:52 -07:00
12 changed files with 1602 additions and 830 deletions

View File

@@ -153,7 +153,7 @@ LedgerConsensus::LedgerConsensus(const uint256& prevLCLHash, Ledger::ref previou
mCloseResolution = ContinuousLedgerTiming::getNextLedgerTimeResolution(
mPreviousLedger->getCloseResolution(), mPreviousLedger->getCloseAgree(), previousLedger->getLedgerSeq() + 1);
if (mValPublic.isValid() && mValPrivate.isValid() && !theApp->getOPs().isNeedNetworkLedger())
if (mValPublic.isSet() && mValPrivate.isSet() && !theApp->getOPs().isNeedNetworkLedger())
{
cLog(lsINFO) << "Entering consensus process, validating";
mValidating = true;
@@ -183,7 +183,7 @@ LedgerConsensus::LedgerConsensus(const uint256& prevLCLHash, Ledger::ref previou
void LedgerConsensus::checkOurValidation()
{ // This only covers some cases - Fix for the case where we can't ever acquire the consensus ledger
if (!mHaveCorrectLCL || !mValPublic.isValid() || !mValPrivate.isValid() || theApp->getOPs().isNeedNetworkLedger())
if (!mHaveCorrectLCL || !mValPublic.isSet() || !mValPrivate.isSet() || theApp->getOPs().isNeedNetworkLedger())
return;
SerializedValidation::pointer lastVal = theApp->getOPs().getLastValidation();

View File

@@ -39,18 +39,20 @@ LedgerEntrySet LedgerEntrySet::duplicate() const
void LedgerEntrySet::setTo(const LedgerEntrySet& e)
{
mLedger = e.mLedger;
mEntries = e.mEntries;
mSet = e.mSet;
mParams = e.mParams;
mSeq = e.mSeq;
mLedger = e.mLedger;
}
void LedgerEntrySet::swapWith(LedgerEntrySet& e)
{
std::swap(mSeq, e.mSeq);
std::swap(mLedger, e.mLedger);
mSet.swap(e.mSet);
mEntries.swap(e.mEntries);
mSet.swap(e.mSet);
std::swap(mParams, e.mParams);
std::swap(mSeq, e.mSeq);
}
// Find an entry in the set. If it has the wrong sequence number, copy it and update the sequence number.
@@ -65,6 +67,7 @@ SLE::pointer LedgerEntrySet::getEntry(const uint256& index, LedgerEntryAction& a
}
if (it->second.mSeq != mSeq)
{
assert(it->second.mSeq < mSeq);
it->second.mEntry = boost::make_shared<SerializedLedgerEntry>(*it->second.mEntry);
it->second.mSeq = mSeq;
}
@@ -82,6 +85,7 @@ SLE::pointer LedgerEntrySet::entryCreate(LedgerEntryType letType, const uint256&
SLE::pointer LedgerEntrySet::entryCache(LedgerEntryType letType, const uint256& index)
{
assert(mLedger);
SLE::pointer sleEntry;
if (index.isNonZero())
{
@@ -89,6 +93,7 @@ SLE::pointer LedgerEntrySet::entryCache(LedgerEntryType letType, const uint256&
sleEntry = getEntry(index, action);
if (!sleEntry)
{
assert(action != taaDELETE);
sleEntry = mLedger->getSLE(index);
if (sleEntry)
entryCache(sleEntry);
@@ -109,6 +114,7 @@ LedgerEntryAction LedgerEntrySet::hasEntry(const uint256& index) const
void LedgerEntrySet::entryCache(SLE::ref sle)
{
assert(mLedger);
assert(sle->isMutable());
std::map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex());
if (it == mEntries.end())
@@ -120,6 +126,7 @@ void LedgerEntrySet::entryCache(SLE::ref sle)
switch (it->second.mAction)
{
case taaCACHED:
assert(sle == it->second.mEntry);
it->second.mSeq = mSeq;
it->second.mEntry = sle;
return;
@@ -131,6 +138,7 @@ void LedgerEntrySet::entryCache(SLE::ref sle)
void LedgerEntrySet::entryCreate(SLE::ref sle)
{
assert(mLedger);
assert(sle->isMutable());
std::map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex());
if (it == mEntries.end())
@@ -143,6 +151,7 @@ void LedgerEntrySet::entryCreate(SLE::ref sle)
{
case taaDELETE:
cLog(lsDEBUG) << "Create after Delete = Modify";
it->second.mEntry = sle;
it->second.mAction = taaMODIFY;
it->second.mSeq = mSeq;
@@ -167,6 +176,7 @@ void LedgerEntrySet::entryCreate(SLE::ref sle)
void LedgerEntrySet::entryModify(SLE::ref sle)
{
assert(sle->isMutable());
assert(mLedger);
std::map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex());
if (it == mEntries.end())
{
@@ -175,7 +185,7 @@ void LedgerEntrySet::entryModify(SLE::ref sle)
}
assert(it->second.mSeq == mSeq);
assert(*it->second.mEntry == *sle);
assert(it->second.mEntry == sle);
switch (it->second.mAction)
{
@@ -200,15 +210,17 @@ void LedgerEntrySet::entryModify(SLE::ref sle)
void LedgerEntrySet::entryDelete(SLE::ref sle)
{
assert(sle->isMutable());
assert(mLedger);
std::map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex());
if (it == mEntries.end())
{
assert(false); // deleting an entry not cached?
mEntries.insert(std::make_pair(sle->getIndex(), LedgerEntrySetEntry(sle, taaDELETE, mSeq)));
return;
}
assert(it->second.mSeq == mSeq);
assert(*it->second.mEntry == *sle);
assert(it->second.mEntry == sle);
switch (it->second.mAction)
{
@@ -541,8 +553,7 @@ TER LedgerEntrySet::dirAdd(
const uint256& uLedgerIndex,
FUNCTION_TYPE<void (SLE::ref)> fDescriber)
{
cLog(lsDEBUG)
<< boost::str(boost::format("dirAdd: uRootIndex=%s uLedgerIndex=%s")
cLog(lsDEBUG) << boost::str(boost::format("dirAdd: uRootIndex=%s uLedgerIndex=%s")
% uRootIndex.ToString()
% uLedgerIndex.ToString());

View File

@@ -78,6 +78,8 @@ public:
LedgerEntrySet duplicate() const; // Make a duplicate of this set
void setTo(const LedgerEntrySet&); // Set this set to have the same contents as another
void swapWith(LedgerEntrySet&); // Swap the contents of two sets
void invalidate() { mLedger.reset(); }
bool isValid() const { return !!mLedger; }
int getSeq() const { return mSeq; }
TransactionEngineParams getParams() const { return mParams; }

View File

@@ -88,7 +88,7 @@ bool Pathfinder::bDefaultPath(const STPath& spPath)
return false; // Didn't generate a default path. So can't match.
}
PathState::pointer pspCurrent = boost::make_shared<PathState>(mDstAmount, mSrcAmount, mLedger);
PathState::pointer pspCurrent = boost::make_shared<PathState>(mDstAmount, mSrcAmount);
if (pspCurrent)
{
@@ -163,7 +163,7 @@ Pathfinder::Pathfinder(Ledger::ref ledger,
// Construct the default path for later comparison.
PathState::pointer psDefault = boost::make_shared<PathState>(mDstAmount, mSrcAmount, mLedger);
PathState::pointer psDefault = boost::make_shared<PathState>(mDstAmount, mSrcAmount);
if (psDefault)
{

View File

@@ -46,6 +46,11 @@ void RippleAddress::clear()
vchData.clear();
}
bool RippleAddress::isSet() const
{
return nVersion != VER_NONE;
}
std::string RippleAddress::humanAddressType() const
{
switch (nVersion)

View File

@@ -29,7 +29,9 @@ public:
// For public and private key, checks if they are legal.
bool isValid() const;
void clear();
bool isSet() const;
std::string humanAddressType() const;

View File

@@ -884,9 +884,13 @@ TER RippleCalc::calcNodeAdvance(
}
if (bDirectAdvance)
{
// Get next quality.
{ // Get next quality.
// FIXME: This looks at the original ledger and doesn't take into account any changes
// in the LedgerEntrySet. If this code, for example, created offers, this would
// not return the pages they're in.
uDirectTip = lesActive.getLedger()->getNextLedgerIndex(uDirectTip, uDirectEnd);
bDirectDirDirty = true;
bDirectAdvance = false;
@@ -2584,8 +2588,7 @@ void RippleCalc::pathNext(PathState::ref psrCur, const bool bMultiQuality, const
assert(psrCur->vpnNodes.size() >= 2);
lesCurrent = lesCheckpoint; // Restore from checkpoint.
lesCurrent.bumpSeq(); // Begin ledger variance.
lesCurrent = lesCheckpoint.duplicate(); // Restore from checkpoint.
psrCur->terStatus = calcNodeRev(uLast, *psrCur, bMultiQuality);
@@ -2594,8 +2597,7 @@ void RippleCalc::pathNext(PathState::ref psrCur, const bool bMultiQuality, const
if (tesSUCCESS == psrCur->terStatus)
{
// Do forward.
lesCurrent = lesCheckpoint; // Restore from checkpoint.
lesCurrent.bumpSeq(); // Begin ledger variance.
lesCurrent = lesCheckpoint.duplicate(); // Restore from checkpoint.
psrCur->terStatus = calcNodeFwd(0, *psrCur, bMultiQuality);
}
@@ -2647,6 +2649,7 @@ TER RippleCalc::rippleCalc(
const bool bOpenLedger
)
{
assert(lesActive.isValid());
RippleCalc rc(lesActive, bOpenLedger);
cLog(lsTRACE) << boost::str(boost::format("rippleCalc> saMaxAmountReq=%s saDstAmountReq=%s")
@@ -2672,7 +2675,7 @@ TER RippleCalc::rippleCalc(
// Build a default path. Use saDstAmountReq and saMaxAmountReq to imply nodes.
// XXX Might also make a XRP bridge by default.
PathState::pointer pspDirect = boost::make_shared<PathState>(saDstAmountReq, saMaxAmountReq, lesActive.getLedgerRef());
PathState::pointer pspDirect = boost::make_shared<PathState>(saDstAmountReq, saMaxAmountReq);
if (!pspDirect)
return temUNKNOWN;
@@ -2702,10 +2705,10 @@ cLog(lsDEBUG) << boost::str(boost::format("rippleCalc: Build direct: status: %s"
cLog(lsTRACE) << "rippleCalc: Paths in set: " << spsPaths.size();
int iIndex = 0;
int iIndex = 0;
BOOST_FOREACH(const STPath& spPath, spsPaths)
{
PathState::pointer pspExpanded = boost::make_shared<PathState>(saDstAmountReq, saMaxAmountReq, lesActive.getLedgerRef());
PathState::pointer pspExpanded = boost::make_shared<PathState>(saDstAmountReq, saMaxAmountReq);
if (!pspExpanded)
return temUNKNOWN;
@@ -2805,7 +2808,10 @@ int iPass = 0;
% pspCur->saInPass.getFullText()
% pspCur->saOutPass.getFullText());
assert(lesActive.isValid());
lesActive.swapWith(pspCur->lesEntries); // For the path, save ledger state.
lesActive.invalidate();
iBest = pspCur->getIndex();
}
}
@@ -2840,7 +2846,9 @@ int iPass = 0;
vuUnfundedBecame.insert(vuUnfundedBecame.end(), pspBest->vUnfundedBecame.begin(), pspBest->vUnfundedBecame.end());
// Record best pass' LedgerEntrySet to build off of and potentially return.
assert(pspBest->lesEntries.isValid());
lesActive.swapWith(pspBest->lesEntries);
pspBest->lesEntries.invalidate();
saMaxAmountAct += pspBest->saInPass;
saDstAmountAct += pspBest->saOutPass;

View File

@@ -71,8 +71,6 @@ extern std::size_t hash_value(const aciSource& asValue);
class PathState
{
protected:
Ledger::pointer mLedger;
TER pushNode(const int iType, const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID);
TER pushImply(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID);
@@ -116,12 +114,11 @@ public:
PathState(
const STAmount& saSend,
const STAmount& saSendMax,
Ledger::pointer lrLedger = Ledger::pointer()
) : mLedger(lrLedger), saInReq(saSendMax), saOutReq(saSend) { ; }
const STAmount& saSendMax
) : saInReq(saSendMax), saOutReq(saSend) { ; }
PathState(const PathState& psSrc, bool bUnused)
: mLedger(psSrc.mLedger), saInReq(psSrc.saInReq), saOutReq(psSrc.saOutReq) { ; }
: saInReq(psSrc.saInReq), saOutReq(psSrc.saOutReq) { ; }
void setExpanded(
const LedgerEntrySet& lesSource,