mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
First part of the fix to stop us from publishing ledgers that don't get validated.
This commit is contained in:
@@ -467,6 +467,7 @@ void Ledger::saveAcceptedLedger(bool fromConsensus, LoadEvent::pointer event)
|
||||
theApp->getLedgerMaster().setFullLedger(shared_from_this());
|
||||
event->stop();
|
||||
|
||||
// FIXME: Need to put on hold until the ledger acquires sufficient validations
|
||||
theApp->getOPs().pubLedger(shared_from_this());
|
||||
|
||||
decPendingSaves();
|
||||
|
||||
@@ -49,11 +49,14 @@ void LedgerMaster::pushLedger(Ledger::ref newLCL, Ledger::ref newOL, bool fromCo
|
||||
cLog(lsINFO) << "StashAccepted: " << newLCL->getHash();
|
||||
}
|
||||
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock ml(mLock);
|
||||
mFinalizedLedger = newLCL;
|
||||
mCurrentLedger = newOL;
|
||||
mEngine.setLedger(newOL);
|
||||
}
|
||||
checkPublish(newLCL->getHash(), newLCL->getLedgerSeq());
|
||||
}
|
||||
|
||||
void LedgerMaster::switchLedgers(Ledger::ref lastClosed, Ledger::ref current)
|
||||
{
|
||||
@@ -69,6 +72,7 @@ void LedgerMaster::switchLedgers(Ledger::ref lastClosed, Ledger::ref current)
|
||||
|
||||
assert(!mCurrentLedger->isClosed());
|
||||
mEngine.setLedger(mCurrentLedger);
|
||||
checkPublish(lastClosed->getHash(), lastClosed->getLedgerSeq());
|
||||
}
|
||||
|
||||
void LedgerMaster::storeLedger(Ledger::ref ledger)
|
||||
@@ -306,4 +310,19 @@ void LedgerMaster::setFullLedger(Ledger::ref ledger)
|
||||
}
|
||||
}
|
||||
|
||||
void LedgerMaster::checkPublish(const uint256& hash)
|
||||
{
|
||||
Ledger::pointer ledger = mLedgerHistory.getLedgerByHash(hash);
|
||||
if (ledger)
|
||||
checkPublish(hash, ledger->getLedgerSeq());
|
||||
}
|
||||
|
||||
void LedgerMaster::checkPublish(const uint256& hash, uint32 seq)
|
||||
{ // check if we need to publish any held ledgers
|
||||
boost::recursive_mutex::scoped_lock ml(mLock);
|
||||
|
||||
if (seq <= mLastValidateSeq)
|
||||
return;
|
||||
}
|
||||
|
||||
// vim:ts=4
|
||||
|
||||
@@ -17,6 +17,10 @@
|
||||
|
||||
class LedgerMaster
|
||||
{
|
||||
public:
|
||||
typedef boost::function<void(Ledger::ref)> callback;
|
||||
|
||||
protected:
|
||||
boost::recursive_mutex mLock;
|
||||
|
||||
TransactionEngine mEngine;
|
||||
@@ -33,6 +37,11 @@ class LedgerMaster
|
||||
uint32 mMissingSeq;
|
||||
bool mTooFast; // We are acquiring faster than we're writing
|
||||
|
||||
int mMinValidations; // The minimum validations to publish a ledger
|
||||
uint256 mLastValidateHash;
|
||||
uint32 mLastValidateSeq;
|
||||
std::list<callback> mOnValidate; // Called when a ledger has enough validations
|
||||
|
||||
void applyFutureTransactions(uint32 ledgerIndex);
|
||||
bool isValidTransaction(const Transaction::pointer& trans);
|
||||
bool isTransactionOnFutureList(const Transaction::pointer& trans);
|
||||
@@ -42,7 +51,9 @@ class LedgerMaster
|
||||
|
||||
public:
|
||||
|
||||
LedgerMaster() : mHeldTransactions(uint256()), mMissingSeq(0), mTooFast(false) { ; }
|
||||
LedgerMaster() : mHeldTransactions(uint256()), mMissingSeq(0), mTooFast(false),
|
||||
mMinValidations(0), mLastValidateSeq(0)
|
||||
{ ; }
|
||||
|
||||
uint32 getCurrentLedgerIndex();
|
||||
|
||||
@@ -100,6 +111,11 @@ public:
|
||||
void resumeAcquiring();
|
||||
|
||||
void sweep(void) { mLedgerHistory.sweep(); }
|
||||
|
||||
void addValidateCallback(callback& c) { mOnValidate.push_back(c); }
|
||||
|
||||
void checkPublish(const uint256& hash);
|
||||
void checkPublish(const uint256& hash, uint32 seq);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -75,6 +75,8 @@ bool ValidationCollection::addValidation(const SerializedValidation::pointer& va
|
||||
|
||||
cLog(lsINFO) << "Val for " << hash << " from " << signer.humanNodePublic()
|
||||
<< " added " << (val->isTrusted() ? "trusted/" : "UNtrusted/") << (isCurrent ? "current" : "stale");
|
||||
if (val->isTrusted())
|
||||
theApp->getLedgerMaster().checkPublish(hash);
|
||||
return isCurrent;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user