From c3ad3bb873dcbfeea481c7b04b8d5c65772f6746 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Sun, 4 Nov 2012 14:40:44 -0800 Subject: [PATCH] Next phase of improving the way we handle transactions received from peers. --- src/Peer.cpp | 63 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/src/Peer.cpp b/src/Peer.cpp index c9c6df5dbf..7a06d0f861 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -694,6 +694,41 @@ void Peer::recvHello(ripple::TMHello& packet) } } +static void checkTransaction(Job&, int flags, SerializedTransaction::pointer stx, boost::weak_ptr peer) +{ + +#ifndef TRUST_NETWORK + try + { +#endif + Transaction::pointer tx; + + if ((flags & SF_SIGGOOD) != 0) + { + tx = boost::make_shared(stx, true); + if (tx->getStatus() == INVALID) + { + theApp->getSuppression().setFlag(stx->getTransactionID(), SF_BAD); + return; + } + else + theApp->getSuppression().setFlag(stx->getTransactionID(), SF_SIGGOOD); + } + else + tx = boost::make_shared(stx, false); + + theApp->getIOService().post(boost::bind(&NetworkOPs::processTransaction, &theApp->getOPs(), tx)); + +#ifndef TRUST_NETWORK + } + catch (...) + { + theApp->getSuppression().setFlags(stx->getTransactionID(), SF_BAD); + punishPeer(peer, PP_INVALID_REQUEST); + } +#endif +} + void Peer::recvTransaction(ripple::TMTransaction& packet) { cLog(lsDEBUG) << "Got transaction from peer"; @@ -708,12 +743,22 @@ void Peer::recvTransaction(ripple::TMTransaction& packet) SerializerIterator sit(s); SerializedTransaction::pointer stx = boost::make_shared(boost::ref(sit)); - if (!theApp->isNew(stx->getTransactionID(), mPeerId)) - return; + int flags; + if (!theApp->isNew(stx->getTransactionID(), mPeerId, flags)) + { // we have seen this transaction recently + if ((flags & SF_BAD) != 0) + { + punishPeer(PP_INVALID_REQUEST); + return; + } + + if ((flags & SF_RETRY) == 0) + return; + } + + theApp->getJobQueue().addJob(jtTRANSACTION, + boost::bind(&checkTransaction, _1, flags, stx, boost::weak_ptr(shared_from_this()))); - tx = boost::make_shared(stx, true); - if (tx->getStatus() == INVALID) - throw(0); #ifndef TRUST_NETWORK } catch (...) @@ -727,14 +772,6 @@ void Peer::recvTransaction(ripple::TMTransaction& packet) } #endif - tx = theApp->getOPs().processTransaction(tx); - - if(tx->getStatus() != INCLUDED) - { // transaction wasn't accepted into ledger -#ifdef DEBUG - std::cerr << "Transaction from peer won't go in ledger" << std::endl; -#endif - } } void Peer::recvPropose(ripple::TMProposeSet& packet)