Merge branch 'master' of github.com:jedmccaleb/NewCoin

This commit is contained in:
Arthur Britto
2013-02-10 02:26:53 -08:00
4 changed files with 51 additions and 48 deletions

View File

@@ -88,10 +88,7 @@ Ledger::Ledger(bool /* dummy */, Ledger& prevLedger) :
mCloseResolution = ContinuousLedgerTiming::getNextLedgerTimeResolution(prevLedger.mCloseResolution, mCloseResolution = ContinuousLedgerTiming::getNextLedgerTimeResolution(prevLedger.mCloseResolution,
prevLedger.getCloseAgree(), mLedgerSeq); prevLedger.getCloseAgree(), mLedgerSeq);
if (prevLedger.mCloseTime == 0) if (prevLedger.mCloseTime == 0)
{ mCloseTime = roundCloseTime(theApp->getOPs().getCloseTimeNC(), mCloseResolution);
mCloseTime = theApp->getOPs().getCloseTimeNC() - mCloseResolution;
mCloseTime -= (mCloseTime % mCloseResolution);
}
else else
mCloseTime = prevLedger.mCloseTime + mCloseResolution; mCloseTime = prevLedger.mCloseTime + mCloseResolution;
zeroFees(); zeroFees();
@@ -181,7 +178,7 @@ void Ledger::addRaw(Serializer &s) const
void Ledger::setAccepted(uint32 closeTime, int closeResolution, bool correctCloseTime) void Ledger::setAccepted(uint32 closeTime, int closeResolution, bool correctCloseTime)
{ // used when we witnessed the consensus { // used when we witnessed the consensus
assert(mClosed && !mAccepted); assert(mClosed && !mAccepted);
mCloseTime = correctCloseTime ? (closeTime - (closeTime % closeResolution)) : closeTime; mCloseTime = correctCloseTime ? roundCloseTime(closeTime, closeResolution) : closeTime;
mCloseResolution = closeResolution; mCloseResolution = closeResolution;
mCloseFlags = correctCloseTime ? 0 : sLCF_NoConsensusTime; mCloseFlags = correctCloseTime ? 0 : sLCF_NoConsensusTime;
mAccepted = true; mAccepted = true;
@@ -192,7 +189,7 @@ void Ledger::setAccepted()
{ // used when we acquired the ledger { // used when we acquired the ledger
// FIXME assert(mClosed && (mCloseTime != 0) && (mCloseResolution != 0)); // FIXME assert(mClosed && (mCloseTime != 0) && (mCloseResolution != 0));
if ((mCloseFlags & sLCF_NoConsensusTime) == 0) if ((mCloseFlags & sLCF_NoConsensusTime) == 0)
mCloseTime -= mCloseTime % mCloseResolution; mCloseTime = roundCloseTime(mCloseTime, mCloseResolution);
mAccepted = true; mAccepted = true;
setImmutable(); setImmutable();
} }
@@ -1422,6 +1419,13 @@ int Ledger::getPendingSaves()
return sPendingSaves; return sPendingSaves;
} }
uint32 Ledger::roundCloseTime(uint32 closeTime, uint32 closeResolution)
{
if (closeTime == 0)
return 0;
return closeTime - (closeTime % closeResolution);
}
void Ledger::pendSave(bool fromConsensus) void Ledger::pendSave(bool fromConsensus)
{ {
if (!fromConsensus && !theApp->isNewFlag(getHash(), SF_SAVED)) if (!fromConsensus && !theApp->isNewFlag(getHash(), SF_SAVED))

View File

@@ -123,6 +123,7 @@ public:
static void getSQL2(Ledger::ref); static void getSQL2(Ledger::ref);
static Ledger::pointer getLastFullLedger(); static Ledger::pointer getLastFullLedger();
static int getPendingSaves(); static int getPendingSaves();
static uint32 roundCloseTime(uint32 closeTime, uint32 closeResolution);
void updateHash(); void updateHash();
void setClosed() { mClosed = true; } void setClosed() { mClosed = true; }

View File

@@ -717,9 +717,8 @@ void LedgerConsensus::updateOurPositions()
// Verify freshness of peer positions and compute close times // Verify freshness of peer positions and compute close times
std::map<uint32, int> closeTimes; std::map<uint32, int> closeTimes;
boost::unordered_map<uint160, LedgerProposal::pointer>::iterator boost::unordered_map<uint160, LedgerProposal::pointer>::iterator it = mPeerPositions.begin();
it = mPeerPositions.begin(), end = mPeerPositions.end(); while (it != mPeerPositions.end())
while (it != end)
{ {
if (it->second->isStale(peerCutoff)) if (it->second->isStale(peerCutoff))
{ // proposal is stale { // proposal is stale
@@ -765,7 +764,8 @@ void LedgerConsensus::updateOurPositions()
neededWeight = AV_INIT_CONSENSUS_PCT; neededWeight = AV_INIT_CONSENSUS_PCT;
else if (mClosePercent < AV_LATE_CONSENSUS_TIME) else if (mClosePercent < AV_LATE_CONSENSUS_TIME)
neededWeight = AV_MID_CONSENSUS_PCT; neededWeight = AV_MID_CONSENSUS_PCT;
else neededWeight = AV_LATE_CONSENSUS_PCT; else
neededWeight = AV_LATE_CONSENSUS_PCT;
uint32 closeTime = 0; uint32 closeTime = 0;
mHaveCloseTimeConsensus = false; mHaveCloseTimeConsensus = false;
@@ -802,9 +802,9 @@ void LedgerConsensus::updateOurPositions()
<< " Proposing:" << (mProposing ? "yes" : "no") << " Thresh:" << thresh << " Pos:" << closeTime; << " Proposing:" << (mProposing ? "yes" : "no") << " Thresh:" << thresh << " Pos:" << closeTime;
} }
if ((!changes) && if (!changes &&
((closeTime != (roundCloseTime(mOurPosition->getCloseTime()))) || ((closeTime != roundCloseTime(mOurPosition->getCloseTime())) ||
(mOurPosition->isStale(ourCutoff)))) mOurPosition->isStale(ourCutoff)))
{ // close time changed or our position is stale { // close time changed or our position is stale
ourPosition = mAcquired[mOurPosition->getCurrentHash()]->snapShot(true); ourPosition = mAcquired[mOurPosition->getCurrentHash()]->snapShot(true);
assert(ourPosition); assert(ourPosition);
@@ -835,9 +835,12 @@ bool LedgerConsensus::haveConsensus(bool forReal)
if (it.second->getCurrentHash() == ourPosition) if (it.second->getCurrentHash() == ourPosition)
++agree; ++agree;
else else
{
cLog(lsDEBUG) << it.first.GetHex() << " has " << it.second->getCurrentHash().GetHex();
++disagree; ++disagree;
} }
} }
}
int currentValidations = theApp->getValidations().getNodesAfter(mPrevLedgerHash); int currentValidations = theApp->getValidations().getNodesAfter(mPrevLedgerHash);
cLog(lsDEBUG) << "Checking for TX consensus: agree=" << agree << ", disagree=" << disagree; cLog(lsDEBUG) << "Checking for TX consensus: agree=" << agree << ", disagree=" << disagree;
@@ -849,8 +852,8 @@ bool LedgerConsensus::haveConsensus(bool forReal)
SHAMap::pointer LedgerConsensus::getTransactionTree(const uint256& hash, bool doAcquire) SHAMap::pointer LedgerConsensus::getTransactionTree(const uint256& hash, bool doAcquire)
{ {
boost::unordered_map<uint256, SHAMap::pointer>::iterator it = mAcquired.find(hash); boost::unordered_map<uint256, SHAMap::pointer>::iterator it = mAcquired.find(hash);
if (it == mAcquired.end()) if (it != mAcquired.end())
{ // we have not completed acquiring this ledger return it->second;
if (mState == lcsPRE_CLOSE) if (mState == lcsPRE_CLOSE)
{ {
@@ -879,8 +882,6 @@ SHAMap::pointer LedgerConsensus::getTransactionTree(const uint256& hash, bool do
} }
} }
return SHAMap::pointer(); return SHAMap::pointer();
}
return it->second;
} }
void LedgerConsensus::startAcquiring(const TransactionAcquire::pointer& acquire) void LedgerConsensus::startAcquiring(const TransactionAcquire::pointer& acquire)
@@ -936,9 +937,8 @@ void LedgerConsensus::propose()
void LedgerConsensus::addDisputedTransaction(const uint256& txID, const std::vector<unsigned char>& tx) void LedgerConsensus::addDisputedTransaction(const uint256& txID, const std::vector<unsigned char>& tx)
{ {
if (mDisputes.find(txID) != mDisputes.end()) // Do we already have this entry? if (mDisputes.find(txID) != mDisputes.end())
return; return;
cLog(lsDEBUG) << "Transaction " << txID << " is disputed"; cLog(lsDEBUG) << "Transaction " << txID << " is disputed";
bool ourVote = false; bool ourVote = false;
@@ -950,7 +950,6 @@ void LedgerConsensus::addDisputedTransaction(const uint256& txID, const std::vec
else else
assert(false); // We don't have our own position? assert(false); // We don't have our own position?
} }
cLog(lsDEBUG) << "Transaction " << txID << " is disputed";
LCTransaction::pointer txn = boost::make_shared<LCTransaction>(txID, tx, ourVote); LCTransaction::pointer txn = boost::make_shared<LCTransaction>(txID, tx, ourVote);
mDisputes[txID] = txn; mDisputes[txID] = txn;
@@ -1120,7 +1119,6 @@ void LedgerConsensus::playbackProposals()
theApp->getConnectionPool().relayMessageBut(peers, message); theApp->getConnectionPool().relayMessageBut(peers, message);
} }
#endif #endif
} }
} }
} }
@@ -1249,7 +1247,7 @@ void LedgerConsensus::applyTransactions(SHAMap::ref set, Ledger::ref applyLedger
uint32 LedgerConsensus::roundCloseTime(uint32 closeTime) uint32 LedgerConsensus::roundCloseTime(uint32 closeTime)
{ {
return closeTime - (closeTime % mCloseResolution); return Ledger::roundCloseTime(closeTime, mCloseResolution);
} }
void LedgerConsensus::accept(SHAMap::ref set, LoadEvent::pointer) void LedgerConsensus::accept(SHAMap::ref set, LoadEvent::pointer)

View File

@@ -845,7 +845,7 @@ void Peer::recvTransaction(ripple::TMTransaction& packet)
static void checkPropose(Job& job, boost::shared_ptr<ripple::TMProposeSet> packet, static void checkPropose(Job& job, boost::shared_ptr<ripple::TMProposeSet> packet,
LedgerProposal::pointer proposal, uint256 consensusLCL, RippleAddress nodePublic, boost::weak_ptr<Peer> peer) LedgerProposal::pointer proposal, uint256 consensusLCL, RippleAddress nodePublic, boost::weak_ptr<Peer> peer)
{ { // Called from our JobQueue
bool sigGood = false; bool sigGood = false;
bool isTrusted = (job.getType() == jtPROPOSAL_t); bool isTrusted = (job.getType() == jtPROPOSAL_t);
@@ -877,7 +877,7 @@ static void checkPropose(Job& job, boost::shared_ptr<ripple::TMProposeSet> packe
} }
else else
{ {
cLog(lsWARNING) << "Ledger proposal fails signature check"; cLog(lsWARNING) << "Ledger proposal fails signature check"; // Could be mismatched prev ledger
proposal->setSignature(set.signature()); proposal->setSignature(set.signature());
} }
} }