Track and re-appply LocalTransactions as needed

This commit is contained in:
David Schwartz
2014-03-24 12:31:56 -07:00
parent 5d1aec6280
commit be9e18ddb8
12 changed files with 335 additions and 11 deletions

View File

@@ -43,6 +43,7 @@ public:
: NetworkOPs (parent)
, m_clock (clock)
, m_journal (journal)
, m_localTX (LocalTxs::New ())
, mMode (omDISCONNECTED)
, mNeedNetworkLedger (false)
, mProposing (false)
@@ -323,6 +324,19 @@ public:
void storeProposal (LedgerProposal::ref proposal, const RippleAddress& peerPublic);
uint256 getConsensusLCL ();
void reportFeeChange ();
void updateLocalTx (Ledger::ref newValidLedger) override
{
m_localTX->sweep (newValidLedger);
}
void addLocalTx (Ledger::ref openLedger, SerializedTransaction::ref txn) override
{
m_localTX->push_back (openLedger->getLedgerSeq(), txn);
}
std::size_t getLocalTxCount () override
{
return m_localTX->size ();
}
//Helper function to generate SQL query to get transactions
std::string transactionsSQL (std::string selection, const RippleAddress& account,
@@ -435,6 +449,9 @@ private:
typedef std::lock_guard <LockType> ScopedLockType;
beast::Journal m_journal;
std::unique_ptr <LocalTxs> m_localTX;
LockType mLock;
OperatingMode mMode;
@@ -945,6 +962,7 @@ Transaction::pointer NetworkOPsImp::processTransactionCb (
if (callback)
callback (trans, r);
if (r == tefFAILURE)
{
// VFALCO TODO All callers use a try block so this should be changed to
@@ -952,6 +970,8 @@ Transaction::pointer NetworkOPsImp::processTransactionCb (
throw Fault (IO_ERROR);
}
bool addLocal = bLocal;
if (r == tesSUCCESS)
{
m_journal.info << "Transaction is now included in open ledger";
@@ -968,13 +988,15 @@ Transaction::pointer NetworkOPsImp::processTransactionCb (
}
else if (isTerRetry (r))
{
if (!bFailHard)
if (bFailHard)
addLocal = false;
else
{
// transaction should be held
m_journal.debug << "Transaction should be held: " << r;
trans->setStatus (HELD);
getApp().getMasterTransaction ().canonicalize (&trans);
m_ledgerMaster.addHeldTransaction (trans);
// transaction should be held
m_journal.debug << "Transaction should be held: " << r;
trans->setStatus (HELD);
getApp().getMasterTransaction ().canonicalize (&trans);
m_ledgerMaster.addHeldTransaction (trans);
}
}
else
@@ -983,6 +1005,9 @@ Transaction::pointer NetworkOPsImp::processTransactionCb (
trans->setStatus (INVALID);
}
if (addLocal)
addLocalTx (m_ledgerMaster.getCurrentLedger (), trans->getSTransaction ());
if (didApply || ((mMode != omFULL) && !bFailHard && bLocal))
{
std::set<Peer::ShortId> peers;
@@ -1435,7 +1460,7 @@ int NetworkOPsImp::beginConsensus (uint256 const& networkClosed, Ledger::pointer
assert (!mConsensus);
prevLedger->setImmutable ();
mConsensus = LedgerConsensus::New (m_clock,
mConsensus = LedgerConsensus::New (m_clock, *m_localTX,
networkClosed, prevLedger,
m_ledgerMaster.getCurrentLedger ()->getCloseTimeNC ());

View File

@@ -273,6 +273,10 @@ public:
virtual void reportFeeChange () = 0;
virtual void updateLocalTx (Ledger::ref newValidLedger) = 0;
virtual void addLocalTx (Ledger::ref openLedger, SerializedTransaction::ref txn) = 0;
virtual std::size_t getLocalTxCount () = 0;
//Helper function to generate SQL query to get transactions
virtual std::string transactionsSQL (std::string selection,
const RippleAddress& account, std::int32_t minLedger, std::int32_t maxLedger,