mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Merge branch 'master' of github.com:jedmccaleb/NewCoin
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include "NetworkOPs.h"
|
||||
#include "TaggedCache.h"
|
||||
#include "ValidationCollection.h"
|
||||
#include "Suppression.h"
|
||||
#include "../database/database.h"
|
||||
|
||||
|
||||
@@ -46,6 +47,7 @@ class Application
|
||||
NetworkOPs mNetOps;
|
||||
NodeCache mNodeCache;
|
||||
ValidationCollection mValidations;
|
||||
SuppressionTable mSuppressions;
|
||||
|
||||
DatabaseCon *mTxnDB, *mLedgerDB, *mWalletDB, *mHashNodeDB, *mNetNodeDB;
|
||||
|
||||
@@ -77,6 +79,8 @@ public:
|
||||
TransactionMaster& getMasterTransaction() { return mMasterTransaction; }
|
||||
NodeCache& getNodeCache() { return mNodeCache; }
|
||||
ValidationCollection& getValidations() { return mValidations; }
|
||||
bool suppress(const uint256& s) { return mSuppressions.addSuppression(s); }
|
||||
bool suppress(const uint160& s) { return mSuppressions.addSuppression(s); }
|
||||
|
||||
DatabaseCon* getTxnDB() { return mTxnDB; }
|
||||
DatabaseCon* getLedgerDB() { return mLedgerDB; }
|
||||
|
||||
@@ -42,13 +42,6 @@ bool u160ToHuman(uint160& buf, std::string& retStr)
|
||||
|
||||
#endif
|
||||
|
||||
base_uint160 uint256::to160() const
|
||||
{
|
||||
uint160 m;
|
||||
memcpy(m.begin(), begin(), m.size());
|
||||
return m;
|
||||
}
|
||||
|
||||
base_uint256 uint160::to256() const
|
||||
{
|
||||
uint256 m;
|
||||
|
||||
@@ -217,7 +217,7 @@ void LedgerConsensus::takeInitialPosition(Ledger::pointer initialLedger)
|
||||
|
||||
mOurPosition = boost::make_shared<LedgerProposal>
|
||||
(theConfig.VALIDATION_SEED, initialLedger->getParentHash(), txSet);
|
||||
mapComplete(txSet, initialSet);
|
||||
mapComplete(txSet, initialSet, false);
|
||||
propose(std::vector<uint256>(), std::vector<uint256>());
|
||||
}
|
||||
|
||||
@@ -241,9 +241,10 @@ void LedgerConsensus::createDisputes(SHAMap::pointer m1, SHAMap::pointer m2)
|
||||
}
|
||||
}
|
||||
|
||||
void LedgerConsensus::mapComplete(const uint256& hash, SHAMap::pointer map)
|
||||
void LedgerConsensus::mapComplete(const uint256& hash, SHAMap::pointer map, bool acquired)
|
||||
{
|
||||
Log(lsINFO) << "We have acquired TXS " << hash.GetHex();
|
||||
if (acquired)
|
||||
Log(lsINFO) << "We have acquired TXS " << hash.GetHex();
|
||||
mAcquiring.erase(hash);
|
||||
|
||||
if (!map)
|
||||
@@ -281,8 +282,8 @@ void LedgerConsensus::mapComplete(const uint256& hash, SHAMap::pointer map)
|
||||
}
|
||||
if (!peers.empty())
|
||||
adjustCount(map, peers);
|
||||
else if (!hash)
|
||||
Log(lsWARNING) << "By the time we got the map, no peers were proposing it";
|
||||
else if (acquired)
|
||||
Log(lsWARNING) << "By the time we got the map " << hash.GetHex() << " no peers were proposing it";
|
||||
|
||||
sendHaveTxSet(hash, true);
|
||||
}
|
||||
@@ -448,7 +449,7 @@ bool LedgerConsensus::updateOurPositions(int sinceClose)
|
||||
uint256 newHash = ourPosition->getHash();
|
||||
mOurPosition->changePosition(newHash);
|
||||
propose(addedTx, removedTx);
|
||||
mapComplete(newHash, ourPosition);
|
||||
mapComplete(newHash, ourPosition, false);
|
||||
Log(lsINFO) << "We change our position to " << newHash.GetHex();
|
||||
}
|
||||
|
||||
@@ -468,7 +469,7 @@ SHAMap::pointer LedgerConsensus::getTransactionTree(const uint256& hash, bool do
|
||||
if (!hash)
|
||||
{
|
||||
SHAMap::pointer empty = boost::make_shared<SHAMap>();
|
||||
mapComplete(hash, empty);
|
||||
mapComplete(hash, empty, false);
|
||||
return empty;
|
||||
}
|
||||
acquiring = boost::make_shared<TransactionAcquire>(hash);
|
||||
|
||||
@@ -138,7 +138,7 @@ public:
|
||||
|
||||
SHAMap::pointer getTransactionTree(const uint256& hash, bool doAcquire);
|
||||
TransactionAcquire::pointer getAcquiring(const uint256& hash);
|
||||
void mapComplete(const uint256& hash, SHAMap::pointer map);
|
||||
void mapComplete(const uint256& hash, SHAMap::pointer map, bool acquired);
|
||||
|
||||
void abort();
|
||||
int timerEntry();
|
||||
|
||||
@@ -98,6 +98,18 @@ Transaction::pointer NetworkOPs::processTransaction(Transaction::pointer trans,
|
||||
}
|
||||
|
||||
Log(lsDEBUG) << "Status other than success " << r ;
|
||||
if ((mMode != omFULL) && (theApp->suppress(trans->getID())))
|
||||
{
|
||||
newcoin::TMTransaction tx;
|
||||
Serializer s;
|
||||
trans->getSTransaction()->add(s);
|
||||
tx.set_rawtransaction(&s.getData().front(), s.getLength());
|
||||
tx.set_status(newcoin::tsCURRENT);
|
||||
tx.set_receivetimestamp(getNetworkTimeNC());
|
||||
tx.set_ledgerindexpossible(tgtLedger);
|
||||
PackedMessage::pointer packet = boost::make_shared<PackedMessage>(tx, newcoin::mtTRANSACTION);
|
||||
theApp->getConnectionPool().relayMessage(source, packet);
|
||||
}
|
||||
|
||||
trans->setStatus(INVALID);
|
||||
return trans;
|
||||
@@ -472,10 +484,11 @@ bool NetworkOPs::recvPropose(uint32 proposeSeq, const uint256& proposeHash,
|
||||
// XXX Take a vuc for pubkey.
|
||||
NewcoinAddress naPeerPublic = NewcoinAddress::createNodePublic(strCopy(pubKey));
|
||||
|
||||
if (mMode != omFULL) // FIXME: Should we relay?
|
||||
if (mMode != omFULL)
|
||||
{
|
||||
Log(lsINFO) << "Received proposal when not full: " << mMode;
|
||||
return false; // FIXME: Need suppression table
|
||||
Serializer s(signature);
|
||||
return theApp->suppress(s.getSHA512Half());
|
||||
}
|
||||
if (!mConsensus)
|
||||
{
|
||||
@@ -528,7 +541,7 @@ bool NetworkOPs::hasTXSet(boost::shared_ptr<Peer> peer, const uint256& set, newc
|
||||
void NetworkOPs::mapComplete(const uint256& hash, SHAMap::pointer map)
|
||||
{
|
||||
if (mConsensus)
|
||||
mConsensus->mapComplete(hash, map);
|
||||
mConsensus->mapComplete(hash, map, true);
|
||||
}
|
||||
|
||||
void NetworkOPs::endConsensus()
|
||||
|
||||
37
src/Suppression.cpp
Normal file
37
src/Suppression.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
#include "Suppression.h"
|
||||
|
||||
bool SuppressionTable::addSuppression(const uint160& suppression)
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mSuppressionMutex);
|
||||
|
||||
if (mSuppressionMap.find(suppression) != mSuppressionMap.end())
|
||||
return false;
|
||||
|
||||
time_t now = time(NULL);
|
||||
|
||||
boost::unordered_map< time_t, std::list<uint160> >::iterator it = mSuppressionTimes.begin();
|
||||
while (it != mSuppressionTimes.end())
|
||||
{
|
||||
if ((it->first + mHoldTime) < now)
|
||||
{
|
||||
for (std::list<uint160>::iterator lit = it->second.begin(), end = it->second.end();
|
||||
lit != end; ++lit)
|
||||
mSuppressionMap.erase(*lit);
|
||||
mSuppressionTimes.erase(it++);
|
||||
}
|
||||
else ++it;
|
||||
}
|
||||
|
||||
mSuppressionMap[suppression] = now;
|
||||
mSuppressionTimes[now].push_back(suppression);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SuppressionTable::addSuppression(const uint256& suppression)
|
||||
{
|
||||
uint160 u;
|
||||
memcpy(u.begin(), suppression.begin() + (suppression.size() - u.size()), u.size());
|
||||
return addSuppression(u);
|
||||
}
|
||||
34
src/Suppression.h
Normal file
34
src/Suppression.h
Normal file
@@ -0,0 +1,34 @@
|
||||
#ifndef __SUPPRESSION__
|
||||
#define __SUPPRESSION__
|
||||
|
||||
#include <list>
|
||||
|
||||
#include <boost/unordered_map.hpp>
|
||||
#include <boost/thread/mutex.hpp>
|
||||
|
||||
#include "uint256.h"
|
||||
|
||||
extern std::size_t hash_value(const uint160& u);
|
||||
|
||||
class SuppressionTable
|
||||
{
|
||||
protected:
|
||||
|
||||
boost::mutex mSuppressionMutex;
|
||||
|
||||
// Stores all suppressed hashes and their expiration time
|
||||
boost::unordered_map<uint160, time_t> mSuppressionMap;
|
||||
|
||||
// Stores all expiration times and the hashes indexed for them
|
||||
boost::unordered_map< time_t, std::list<uint160> > mSuppressionTimes;
|
||||
|
||||
int mHoldTime;
|
||||
|
||||
public:
|
||||
SuppressionTable(int holdTime = 120) : mHoldTime(holdTime) { ; }
|
||||
|
||||
bool addSuppression(const uint256& suppression);
|
||||
bool addSuppression(const uint160& suppression);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -511,8 +511,6 @@ public:
|
||||
zero();
|
||||
}
|
||||
}
|
||||
|
||||
base_uint160 to160() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user