From faaedb806f2a7620a38c3c81ef7e8f40e7251c55 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Thu, 30 Aug 2012 11:43:20 -0700 Subject: [PATCH] Start of the proposal defer/playback code. Clean up tem codes to tap codes. --- src/LedgerConsensus.cpp | 19 +++++++++++++++++-- src/LedgerConsensus.h | 5 +++++ src/NetworkOPs.cpp | 6 ++++-- src/NetworkOPs.h | 2 +- src/Peer.cpp | 2 +- src/TransactionEngine.cpp | 6 +++--- src/TransactionEngine.h | 15 ++++++++++----- 7 files changed, 41 insertions(+), 14 deletions(-) diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index e4df9584d2..916290d6dd 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -299,6 +299,7 @@ void LedgerConsensus::handleLCL(const uint256& lclHash) mCloseResolution = ContinuousLedgerTiming::getNextLedgerTimeResolution( mPreviousLedger->getCloseResolution(), mPreviousLedger->getCloseAgree(), mPreviousLedger->getLedgerSeq() + 1); + playbackProposals(); } void LedgerConsensus::takeInitialPosition(Ledger& initialLedger) @@ -810,10 +811,24 @@ void LedgerConsensus::Saccept(boost::shared_ptr This, SHAMap::p This->accept(txSet); } +void LedgerConsensus::deferProposal(const LedgerProposal::pointer& proposal, const NewcoinAddress& peerPublic) +{ + /**/ +} + +void LedgerConsensus::playbackProposals() +{ + for ( boost::unordered_map< uint160, std::list >::iterator + it = mDeferredProposals.begin(), end = mDeferredProposals.end(); it != end; ++it) + { + /**/ + } +} + void LedgerConsensus::applyTransaction(TransactionEngine& engine, const SerializedTransaction::pointer& txn, const Ledger::pointer& ledger, CanonicalTXSet& failedTransactions, bool openLedger) { - TransactionEngineParams parms = openLedger ? temOPEN_LEDGER : temFINAL; + TransactionEngineParams parms = openLedger ? tapOPEN_LEDGER : tapNONE; #ifndef TRUST_NETWORK try { @@ -846,7 +861,7 @@ void LedgerConsensus::applyTransaction(TransactionEngine& engine, const Serializ void LedgerConsensus::applyTransactions(const SHAMap::pointer& set, const Ledger::pointer& applyLedger, const Ledger::pointer& checkLedger, CanonicalTXSet& failedTransactions, bool openLgr) { - TransactionEngineParams parms = openLgr ? temOPEN_LEDGER : temFINAL; + TransactionEngineParams parms = openLgr ? tapOPEN_LEDGER : tapNONE; TransactionEngine engine(applyLedger); for (SHAMapItem::pointer item = set->peekFirstItem(); !!item; item = set->peekNextItem(item->getTag())) diff --git a/src/LedgerConsensus.h b/src/LedgerConsensus.h index 538b21152c..eae19d222b 100644 --- a/src/LedgerConsensus.h +++ b/src/LedgerConsensus.h @@ -111,6 +111,9 @@ protected: // Close time estimates std::map mCloseTimes; + // deferred proposals (node ID -> proposals from that peer) + boost::unordered_map< uint160, std::list > mDeferredProposals; + // final accept logic static void Saccept(boost::shared_ptr This, SHAMap::pointer txSet); void accept(const SHAMap::pointer& txSet); @@ -136,6 +139,7 @@ protected: void statusChange(newcoin::NodeEvent, Ledger& ledger); void takeInitialPosition(Ledger& initialLedger); void updateOurPositions(); + void playbackProposals(); int getThreshold(); void beginAccept(); void endConsensus(); @@ -167,6 +171,7 @@ public: bool haveConsensus(); bool peerPosition(const LedgerProposal::pointer&); + void deferProposal(const LedgerProposal::pointer& proposal, const NewcoinAddress& peerPublic); bool peerHasSet(const Peer::pointer& peer, const uint256& set, newcoin::TxSetStatus status); diff --git a/src/NetworkOPs.cpp b/src/NetworkOPs.cpp index 2d210b78db..642877bd95 100644 --- a/src/NetworkOPs.cpp +++ b/src/NetworkOPs.cpp @@ -84,7 +84,7 @@ Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans, return trans; } - TER r = mLedgerMaster->doTransaction(*trans->getSTransaction(), tgtLedger, temOPEN_LEDGER); + TER r = mLedgerMaster->doTransaction(*trans->getSTransaction(), tgtLedger, tapOPEN_LEDGER); if (r == tefFAILURE) throw Fault(IO_ERROR); if (r == terPRE_SEQ) @@ -599,7 +599,7 @@ int NetworkOPs::beginConsensus(const uint256& networkClosed, Ledger::pointer clo // <-- bool: true to relay bool NetworkOPs::recvPropose(uint32 proposeSeq, const uint256& proposeHash, uint32 closeTime, - const std::string& pubKey, const std::string& signature) + const std::string& pubKey, const std::string& signature, const NewcoinAddress& nodePublic) { // JED: does mConsensus need to be locked? @@ -638,6 +638,8 @@ bool NetworkOPs::recvPropose(uint32 proposeSeq, const uint256& proposeHash, uint if (!proposal->checkSign(signature)) { // Note that if the LCL is different, the signature check will fail Log(lsWARNING) << "Ledger proposal fails signature check"; + if ((mMode != omFULL) && (mMode != omTRACKING) && theApp->getUNL().nodeInUNL(proposal->peekPublic())) + mConsensus->deferProposal(proposal, nodePublic); return false; } diff --git a/src/NetworkOPs.h b/src/NetworkOPs.h index 9c16caac19..5e53b98194 100644 --- a/src/NetworkOPs.h +++ b/src/NetworkOPs.h @@ -160,7 +160,7 @@ public: // ledger proposal/close functions bool recvPropose(uint32 proposeSeq, const uint256& proposeHash, uint32 closeTime, - const std::string& pubKey, const std::string& signature); + const std::string& pubKey, const std::string& signature, const NewcoinAddress& nodePublic); bool gotTXData(const boost::shared_ptr& peer, const uint256& hash, const std::list& nodeIDs, const std::list< std::vector >& nodeData); bool recvValidation(const SerializedValidation::pointer& val); diff --git a/src/Peer.cpp b/src/Peer.cpp index 75a5f2f656..1ca2d8fa58 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -726,7 +726,7 @@ void Peer::recvPropose(newcoin::TMProposeSet& packet) memcpy(currentTxHash.begin(), packet.currenttxhash().data(), 32); if(theApp->getOPs().recvPropose(proposeSeq, currentTxHash, packet.closetime(), - packet.nodepubkey(), packet.signature())) + packet.nodepubkey(), packet.signature(), mNodePublic)) { // FIXME: Not all nodes will want proposals PackedMessage::pointer message = boost::make_shared(packet, newcoin::mtPROPOSE_LEDGER); theApp->getConnectionPool().relayMessage(this, message); diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index 2e755c975d..8cde2efd83 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -973,7 +973,7 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn, naSigningPubKey = NewcoinAddress::createAccountPublic(txn.peekSigningPubKey()); // Consistency: really signed. - if ((tesSUCCESS == terResult) && ((params & temNO_CHECK_SIGN) == 0) && !txn.checkSign(naSigningPubKey)) + if ((tesSUCCESS == terResult) && ((params & tapNO_CHECK_SIGN) == 0) && !txn.checkSign(naSigningPubKey)) { Log(lsWARNING) << "applyTransaction: Invalid transaction: bad signature"; @@ -1032,7 +1032,7 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn, STAmount saPaid = txn.getTransactionFee(); - if (tesSUCCESS == terResult && (params & temOPEN_LEDGER) != temNONE) + if (tesSUCCESS == terResult && (params & tapOPEN_LEDGER) != tapNONE) { // Applying to open ledger, check fee if (!!saCost) { @@ -1322,7 +1322,7 @@ TER TransactionEngine::applyTransaction(const SerializedTransaction& txn, if (!mLedger->addTransaction(txID, s)) assert(false); - if ((params & temOPEN_LEDGER) == temNONE) + if ((params & tapOPEN_LEDGER) == tapNONE) mLedger->destroyCoins(saPaid.getNValue()); } diff --git a/src/TransactionEngine.h b/src/TransactionEngine.h index 08481fcefa..71183b58e5 100644 --- a/src/TransactionEngine.h +++ b/src/TransactionEngine.h @@ -93,11 +93,16 @@ bool transResultInfo(TER terCode, std::string& strToken, std::string& strHuman); enum TransactionEngineParams { - temNONE = 0x00, - temNO_CHECK_SIGN = 0x01, // Signature already checked - temOPEN_LEDGER = 0x10, // Transaction is running against an open ledger - temRETRY_OK = 0x20, // It was voted into a ledger anyway - temFINAL = 0x40, // This may be the transaction's last pass + tapNONE = 0x00, + + tapNO_CHECK_SIGN = 0x01, // Signature already checked + + tapOPEN_LEDGER = 0x10, // Transaction is running against an open ledger + // true = failures are not forwarded, check transaction fee + // false = debit ledger for consumed funds + + tapRETRY = 0x20, // This is not the transaction's last pass + // Transaction can be retried, soft failures allowed }; typedef struct {