mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Merge branch 'master' of github.com:jedmccaleb/NewCoin
This commit is contained in:
@@ -71,11 +71,11 @@ void HashedObjectStore::bulkWrite()
|
||||
char type;
|
||||
switch(it->getType())
|
||||
{
|
||||
case LEDGER: type = 'L'; break;
|
||||
case TRANSACTION: type = 'T'; break;
|
||||
case ACCOUNT_NODE: type = 'A'; break;
|
||||
case TRANSACTION_NODE: type = 'N'; break;
|
||||
default: type = 'U';
|
||||
case hotLEDGER: type= 'L'; break;
|
||||
case hotTRANSACTION: type = 'T'; break;
|
||||
case hotACCOUNT_NODE: type = 'A'; break;
|
||||
case hotTRANSACTION_NODE: type = 'N'; break;
|
||||
default: type = 'U';
|
||||
}
|
||||
std::string rawData;
|
||||
db->escape(&(it->getData().front()), it->getData().size(), rawData);
|
||||
@@ -104,8 +104,6 @@ HashedObject::pointer HashedObjectStore::retrieve(const uint256& hash)
|
||||
sql.append(hash.GetHex());
|
||||
sql.append("';");
|
||||
|
||||
std::string type;
|
||||
uint32 index;
|
||||
std::vector<unsigned char> data;
|
||||
{
|
||||
ScopedLock sl(theApp->getHashNodeDB()->getDBLock());
|
||||
@@ -121,7 +119,7 @@ HashedObject::pointer HashedObjectStore::retrieve(const uint256& hash)
|
||||
db->getStr("ObjType", type);
|
||||
if (type.size() == 0) return HashedObject::pointer();
|
||||
|
||||
index = db->getBigInt("LedgerIndex");
|
||||
uint32 index = db->getBigInt("LedgerIndex");
|
||||
|
||||
int size = db->getBinary("Object", NULL, 0);
|
||||
data.resize(size);
|
||||
@@ -130,13 +128,13 @@ HashedObject::pointer HashedObjectStore::retrieve(const uint256& hash)
|
||||
|
||||
assert(Serializer::getSHA512Half(data) == hash);
|
||||
|
||||
HashedObjectType htype = UNKNOWN;
|
||||
switch(type[0])
|
||||
HashedObjectType htype = hotUNKNOWN;
|
||||
switch (type[0])
|
||||
{
|
||||
case 'L': htype = LEDGER; break;
|
||||
case 'T': htype = TRANSACTION; break;
|
||||
case 'A': htype = ACCOUNT_NODE; break;
|
||||
case 'N': htype = TRANSACTION_NODE; break;
|
||||
case 'L': htype = hotLEDGER; break;
|
||||
case 'T': htype = hotTRANSACTION; break;
|
||||
case 'A': htype = hotACCOUNT_NODE; break;
|
||||
case 'N': htype = hotTRANSACTION_NODE; break;
|
||||
default:
|
||||
Log(lsERROR) << "Invalid hashed object";
|
||||
return HashedObject::pointer();
|
||||
|
||||
@@ -10,11 +10,11 @@
|
||||
|
||||
enum HashedObjectType
|
||||
{
|
||||
UNKNOWN = 0,
|
||||
LEDGER = 1,
|
||||
TRANSACTION = 2,
|
||||
ACCOUNT_NODE = 3,
|
||||
TRANSACTION_NODE = 4
|
||||
hotUNKNOWN = 0,
|
||||
hotLEDGER = 1,
|
||||
hotTRANSACTION = 2,
|
||||
hotACCOUNT_NODE = 3,
|
||||
hotTRANSACTION_NODE = 4
|
||||
};
|
||||
|
||||
class HashedObject
|
||||
|
||||
@@ -154,7 +154,7 @@ void Ledger::setAccepted(uint32 closeTime, int closeResolution, bool correctClos
|
||||
|
||||
void Ledger::setAccepted()
|
||||
{ // used when we acquired the ledger
|
||||
assert(mClosed && (mCloseResolution != 0) && (mCloseResolution != 0));
|
||||
assert(mClosed && (mCloseTime != 0) && (mCloseResolution != 0));
|
||||
mCloseTime -= mCloseTime % mCloseResolution;
|
||||
updateHash();
|
||||
mAccepted = true;
|
||||
@@ -279,9 +279,9 @@ void Ledger::saveAcceptedLedger(Ledger::ref ledger)
|
||||
ledger->mAccountHash.GetHex() % ledger->mTransHash.GetHex()));
|
||||
|
||||
// write out dirty nodes
|
||||
while(ledger->mTransactionMap->flushDirty(256, TRANSACTION_NODE, ledger->mLedgerSeq))
|
||||
while(ledger->mTransactionMap->flushDirty(256, hotTRANSACTION_NODE, ledger->mLedgerSeq))
|
||||
{ ; }
|
||||
while(ledger->mAccountStateMap->flushDirty(256, ACCOUNT_NODE, ledger->mLedgerSeq))
|
||||
while(ledger->mAccountStateMap->flushDirty(256, hotACCOUNT_NODE, ledger->mLedgerSeq))
|
||||
{ ; }
|
||||
ledger->disarmDirty();
|
||||
|
||||
|
||||
@@ -310,7 +310,7 @@ bool LedgerAcquire::takeBase(const std::string& data)
|
||||
Serializer s(data.size() + 4);
|
||||
s.add32(sHP_Ledger);
|
||||
s.addRaw(data);
|
||||
theApp->getHashedObjectStore().store(LEDGER, mLedger->getLedgerSeq(), s.peekData(), mHash);
|
||||
theApp->getHashedObjectStore().store(hotLEDGER, mLedger->getLedgerSeq(), s.peekData(), mHash);
|
||||
|
||||
progress();
|
||||
if (!mLedger->getTransHash())
|
||||
@@ -405,7 +405,8 @@ LedgerAcquire::pointer LedgerAcquireMaster::findCreate(const uint256& hash)
|
||||
assert(hash.isNonZero());
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
LedgerAcquire::pointer& ptr = mLedgers[hash];
|
||||
if (ptr) return ptr;
|
||||
if (ptr)
|
||||
return ptr;
|
||||
ptr = boost::make_shared<LedgerAcquire>(hash);
|
||||
assert(mLedgers[hash] == ptr);
|
||||
ptr->resetTimer(); // Cannot call in constructor
|
||||
@@ -417,7 +418,8 @@ LedgerAcquire::pointer LedgerAcquireMaster::find(const uint256& hash)
|
||||
assert(hash.isNonZero());
|
||||
boost::mutex::scoped_lock sl(mLock);
|
||||
std::map<uint256, LedgerAcquire::pointer>::iterator it = mLedgers.find(hash);
|
||||
if (it != mLedgers.end()) return it->second;
|
||||
if (it != mLedgers.end())
|
||||
return it->second;
|
||||
return LedgerAcquire::pointer();
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +59,8 @@ void TransactionAcquire::trigger(Peer::ref peer, bool timer)
|
||||
}
|
||||
else
|
||||
{
|
||||
std::vector<SHAMapNode> nodeIDs; std::vector<uint256> nodeHashes;
|
||||
std::vector<SHAMapNode> nodeIDs;
|
||||
std::vector<uint256> nodeHashes;
|
||||
ConsensusTransSetSF sf;
|
||||
mMap->getMissingNodes(nodeIDs, nodeHashes, 256, &sf);
|
||||
if (nodeIDs.empty())
|
||||
@@ -68,6 +69,8 @@ void TransactionAcquire::trigger(Peer::ref peer, bool timer)
|
||||
mComplete = true;
|
||||
else
|
||||
mFailed = true;
|
||||
done();
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -77,12 +80,9 @@ void TransactionAcquire::trigger(Peer::ref peer, bool timer)
|
||||
for (std::vector<SHAMapNode>::iterator it = nodeIDs.begin(); it != nodeIDs.end(); ++it)
|
||||
*(tmGL.add_nodeids()) = it->getRawString();
|
||||
sendRequest(tmGL, peer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mComplete || mFailed)
|
||||
done();
|
||||
else if (timer)
|
||||
if (timer)
|
||||
resetTimer();
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ bool TransactionAcquire::takeNodes(const std::list<SHAMapNode>& nodeIDs,
|
||||
}
|
||||
|
||||
void LCTransaction::setVote(const uint160& peer, bool votesYes)
|
||||
{
|
||||
{ // Tracke a peer's yes/no vote on a particular disputed transaction
|
||||
std::pair<boost::unordered_map<uint160, bool>::iterator, bool> res =
|
||||
mVotes.insert(std::make_pair<uint160, bool>(peer, votesYes));
|
||||
|
||||
@@ -162,7 +162,7 @@ void LCTransaction::setVote(const uint160& peer, bool votesYes)
|
||||
}
|
||||
|
||||
void LCTransaction::unVote(const uint160& peer)
|
||||
{
|
||||
{ // Remove a peer's vote on this disputed transasction
|
||||
boost::unordered_map<uint160, bool>::iterator it = mVotes.find(peer);
|
||||
if (it != mVotes.end())
|
||||
{
|
||||
@@ -175,7 +175,7 @@ void LCTransaction::unVote(const uint160& peer)
|
||||
}
|
||||
|
||||
bool LCTransaction::updatePosition(int percentTime, bool proposing)
|
||||
{ // this many seconds after close, should our position change
|
||||
{
|
||||
if (mOurPosition && (mNays == 0))
|
||||
return false;
|
||||
if (!mOurPosition && (mYays == 0))
|
||||
@@ -209,12 +209,10 @@ bool LCTransaction::updatePosition(int percentTime, bool proposing)
|
||||
}
|
||||
|
||||
LedgerConsensus::LedgerConsensus(const uint256& prevLCLHash, Ledger::ref previousLedger, uint32 closeTime)
|
||||
: mState(lcsPRE_CLOSE), mCloseTime(closeTime), mPrevLedgerHash(prevLCLHash),
|
||||
mPreviousLedger(previousLedger), mCurrentMSeconds(0), mClosePercent(0), mHaveCloseTimeConsensus(false)
|
||||
: mState(lcsPRE_CLOSE), mCloseTime(closeTime), mPrevLedgerHash(prevLCLHash), mPreviousLedger(previousLedger),
|
||||
mValSeed(theConfig.VALIDATION_SEED), mCurrentMSeconds(0), mClosePercent(0), mHaveCloseTimeConsensus(false),
|
||||
mConsensusStartTime(boost::posix_time::microsec_clock::universal_time())
|
||||
{
|
||||
mValSeed = theConfig.VALIDATION_SEED;
|
||||
mConsensusStartTime = boost::posix_time::microsec_clock::universal_time();
|
||||
|
||||
Log(lsDEBUG) << "Creating consensus object";
|
||||
Log(lsTRACE) << "LCL:" << previousLedger->getHash() <<", ct=" << closeTime;
|
||||
mPreviousProposers = theApp->getOPs().getPreviousProposers();
|
||||
@@ -249,31 +247,28 @@ void LedgerConsensus::checkLCL()
|
||||
uint256 netLgr = mPrevLedgerHash;
|
||||
int netLgrCount = 0;
|
||||
|
||||
uint256 favorLedger;
|
||||
if (mState != lcsPRE_CLOSE)
|
||||
favorLedger = mPrevLedgerHash;
|
||||
boost::unordered_map<uint256, int> vals = theApp->getValidations().getCurrentValidations(favorLedger);
|
||||
uint256 favoredLedger = (mState == lcsPRE_CLOSE) ? uint256() : mPrevLedgerHash; // Don't get stuck one ledger behind
|
||||
boost::unordered_map<uint256, int> vals =
|
||||
theApp->getValidations().getCurrentValidations(favoredLedger);
|
||||
|
||||
typedef std::pair<const uint256, int> u256_int_pair;
|
||||
BOOST_FOREACH(u256_int_pair& it, vals)
|
||||
{
|
||||
if (it.second > netLgrCount)
|
||||
{
|
||||
netLgr = it.first;
|
||||
netLgrCount = it.second;
|
||||
}
|
||||
}
|
||||
|
||||
if (netLgr != mPrevLedgerHash)
|
||||
{ // LCL change
|
||||
const char *status;
|
||||
switch (mState)
|
||||
{
|
||||
case lcsPRE_CLOSE: status="PreClose"; break;
|
||||
case lcsESTABLISH: status="Establish"; break;
|
||||
case lcsFINISHED: status="Finised"; break;
|
||||
case lcsACCEPTED: status="Accepted"; break;
|
||||
default: status="unknown";
|
||||
case lcsPRE_CLOSE: status = "PreClose"; break;
|
||||
case lcsESTABLISH: status = "Establish"; break;
|
||||
case lcsFINISHED: status = "Finised"; break;
|
||||
case lcsACCEPTED: status = "Accepted"; break;
|
||||
default: status = "unknown";
|
||||
}
|
||||
|
||||
Log(lsWARNING) << "View of consensus changed during consensus (" << netLgrCount << ") status="
|
||||
@@ -305,8 +300,10 @@ void LedgerConsensus::handleLCL(const uint256& lclHash)
|
||||
else
|
||||
{
|
||||
Log(lsWARNING) << "Need consensus ledger " << mPrevLedgerHash;
|
||||
|
||||
mAcquiringLedger = theApp->getMasterLedgerAcquire().findCreate(mPrevLedgerHash);
|
||||
std::vector<Peer::pointer> peerList = theApp->getConnectionPool().getPeerVector();
|
||||
|
||||
bool found = false;
|
||||
BOOST_FOREACH(Peer::ref peer, peerList)
|
||||
{
|
||||
@@ -316,12 +313,14 @@ void LedgerConsensus::handleLCL(const uint256& lclHash)
|
||||
mAcquiringLedger->peerHas(peer);
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
{
|
||||
BOOST_FOREACH(Peer::ref peer, peerList)
|
||||
mAcquiringLedger->peerHas(peer);
|
||||
}
|
||||
if (mHaveCorrectLCL && mProposing)
|
||||
|
||||
if (mHaveCorrectLCL && mProposing && mOurPosition)
|
||||
{
|
||||
Log(lsINFO) << "Bowing out of consensus";
|
||||
mOurPosition->bowOut();
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
#include <boost/make_shared.hpp>
|
||||
|
||||
void LedgerEntrySet::init(const uint256& transactionID, uint32 ledgerID)
|
||||
void LedgerEntrySet::init(Ledger::ref ledger, const uint256& transactionID, uint32 ledgerID)
|
||||
{
|
||||
mEntries.clear();
|
||||
mLedger = ledger;
|
||||
mSet.init(transactionID, ledgerID);
|
||||
mSeq = 0;
|
||||
}
|
||||
@@ -17,7 +18,7 @@ void LedgerEntrySet::clear()
|
||||
|
||||
LedgerEntrySet LedgerEntrySet::duplicate() const
|
||||
{
|
||||
return LedgerEntrySet(mEntries, mSet, mSeq + 1);
|
||||
return LedgerEntrySet(mLedger, mEntries, mSet, mSeq + 1);
|
||||
}
|
||||
|
||||
void LedgerEntrySet::setTo(const LedgerEntrySet& e)
|
||||
@@ -25,11 +26,13 @@ void LedgerEntrySet::setTo(const LedgerEntrySet& e)
|
||||
mEntries = e.mEntries;
|
||||
mSet = e.mSet;
|
||||
mSeq = e.mSeq;
|
||||
mLedger = e.mLedger;
|
||||
}
|
||||
|
||||
void LedgerEntrySet::swapWith(LedgerEntrySet& e)
|
||||
{
|
||||
std::swap(mSeq, e.mSeq);
|
||||
std::swap(mLedger, e.mLedger);
|
||||
mSet.swap(e.mSet);
|
||||
mEntries.swap(e.mEntries);
|
||||
}
|
||||
@@ -53,6 +56,36 @@ SLE::pointer LedgerEntrySet::getEntry(const uint256& index, LedgerEntryAction& a
|
||||
return it->second.mEntry;
|
||||
}
|
||||
|
||||
SLE::pointer LedgerEntrySet::entryCreate(LedgerEntryType letType, const uint256& index)
|
||||
{
|
||||
assert(index.isNonZero());
|
||||
SLE::pointer sleNew = boost::make_shared<SLE>(letType);
|
||||
sleNew->setIndex(index);
|
||||
entryCreate(sleNew);
|
||||
return sleNew;
|
||||
}
|
||||
|
||||
SLE::pointer LedgerEntrySet::entryCache(LedgerEntryType letType, const uint256& index)
|
||||
{
|
||||
SLE::pointer sleEntry;
|
||||
if (index.isNonZero())
|
||||
{
|
||||
LedgerEntryAction action;
|
||||
sleEntry = getEntry(index, action);
|
||||
if (!sleEntry)
|
||||
{
|
||||
sleEntry = mLedger->getSLE(index);
|
||||
if (sleEntry)
|
||||
entryCache(sleEntry);
|
||||
}
|
||||
else if (action == taaDELETE)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
return sleEntry;
|
||||
}
|
||||
|
||||
LedgerEntryAction LedgerEntrySet::hasEntry(const uint256& index) const
|
||||
{
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry>::const_iterator it = mEntries.find(index);
|
||||
@@ -147,7 +180,7 @@ void LedgerEntrySet::entryModify(SLE::ref sle)
|
||||
}
|
||||
}
|
||||
|
||||
void LedgerEntrySet::entryDelete(SLE::ref sle, bool unfunded)
|
||||
void LedgerEntrySet::entryDelete(SLE::ref sle)
|
||||
{
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry>::iterator it = mEntries.find(sle->getIndex());
|
||||
if (it == mEntries.end())
|
||||
@@ -166,15 +199,6 @@ void LedgerEntrySet::entryDelete(SLE::ref sle, bool unfunded)
|
||||
it->second.mSeq = mSeq;
|
||||
it->second.mEntry = sle;
|
||||
it->second.mAction = taaDELETE;
|
||||
if (unfunded)
|
||||
{
|
||||
assert(sle->getType() == ltOFFER); // only offers can be unfunded
|
||||
#if 0
|
||||
mSet.deleteUnfunded(sle->getIndex(),
|
||||
sle->getIValueFieldAmount(sfTakerPays),
|
||||
sle->getIValueFieldAmount(sfTakerGets));
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
|
||||
case taaCREATE:
|
||||
|
||||
@@ -31,12 +31,13 @@ public:
|
||||
class LedgerEntrySet
|
||||
{
|
||||
protected:
|
||||
Ledger::pointer mLedger;
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry> mEntries;
|
||||
TransactionMetaSet mSet;
|
||||
int mSeq;
|
||||
|
||||
LedgerEntrySet(const boost::unordered_map<uint256, LedgerEntrySetEntry> &e, const TransactionMetaSet& s, int m) :
|
||||
mEntries(e), mSet(s), mSeq(m) { ; }
|
||||
LedgerEntrySet(Ledger::ref ledger, const boost::unordered_map<uint256, LedgerEntrySetEntry> &e,
|
||||
const TransactionMetaSet& s, int m) : mLedger(ledger), mEntries(e), mSet(s), mSeq(m) { ; }
|
||||
|
||||
SLE::pointer getForMod(const uint256& node, Ledger::ref ledger,
|
||||
boost::unordered_map<uint256, SLE::pointer>& newMods);
|
||||
@@ -51,6 +52,9 @@ protected:
|
||||
boost::unordered_map<uint256, SLE::pointer>& newMods);
|
||||
|
||||
public:
|
||||
|
||||
LedgerEntrySet(Ledger::ref ledger) : mLedger(ledger), mSeq(0) { ; }
|
||||
|
||||
LedgerEntrySet() : mSeq(0) { ; }
|
||||
|
||||
// set functions
|
||||
@@ -60,7 +64,7 @@ public:
|
||||
|
||||
int getSeq() const { return mSeq; }
|
||||
void bumpSeq() { ++mSeq; }
|
||||
void init(const uint256& transactionID, uint32 ledgerID);
|
||||
void init(Ledger::ref ledger, const uint256& transactionID, uint32 ledgerID);
|
||||
void clear();
|
||||
|
||||
// basic entry functions
|
||||
@@ -68,14 +72,18 @@ public:
|
||||
LedgerEntryAction hasEntry(const uint256& index) const;
|
||||
void entryCache(SLE::ref); // Add this entry to the cache
|
||||
void entryCreate(SLE::ref); // This entry will be created
|
||||
void entryDelete(SLE::ref, bool unfunded);
|
||||
void entryDelete(SLE::ref); // This entry will be deleted
|
||||
void entryModify(SLE::ref); // This entry will be modified
|
||||
|
||||
// higher-level ledger functions
|
||||
SLE::pointer entryCreate(LedgerEntryType letType, const uint256& uIndex);
|
||||
SLE::pointer entryCache(LedgerEntryType letType, const uint256& uIndex);
|
||||
|
||||
Json::Value getJson(int) const;
|
||||
void calcRawMeta(Serializer&, Ledger::ref originalLedger);
|
||||
|
||||
// iterator functions
|
||||
bool isEmpty() const { return mEntries.empty(); }
|
||||
bool isEmpty() const { return mEntries.empty(); }
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry>::const_iterator begin() const { return mEntries.begin(); }
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry>::const_iterator end() const { return mEntries.end(); }
|
||||
boost::unordered_map<uint256, LedgerEntrySetEntry>::iterator begin() { return mEntries.begin(); }
|
||||
|
||||
@@ -446,18 +446,18 @@ bool NetworkOPs::checkLastClosedLedger(const std::vector<Peer::pointer>& peerLis
|
||||
// node is using. THis is kind of fundamental.
|
||||
Log(lsTRACE) << "NetworkOPs::checkLastClosedLedger";
|
||||
|
||||
boost::unordered_map<uint256, ValidationCount> ledgers;
|
||||
Ledger::pointer ourClosed = mLedgerMaster->getClosedLedger();
|
||||
uint256 closedLedger = ourClosed->getHash();
|
||||
uint256 prevClosedLedger = ourClosed->getParentHash();
|
||||
|
||||
boost::unordered_map<uint256, ValidationCount> ledgers;
|
||||
{
|
||||
boost::unordered_map<uint256, int> current = theApp->getValidations().getCurrentValidations();
|
||||
boost::unordered_map<uint256, int> current = theApp->getValidations().getCurrentValidations(closedLedger);
|
||||
typedef std::pair<const uint256, int> u256_int_pair;
|
||||
BOOST_FOREACH(u256_int_pair& it, current)
|
||||
ledgers[it.first].trustedValidations += it.second;
|
||||
}
|
||||
|
||||
Ledger::pointer ourClosed = mLedgerMaster->getClosedLedger();
|
||||
uint256 closedLedger = ourClosed->getHash();
|
||||
uint256 prevClosedLedger = ourClosed->getParentHash();
|
||||
ValidationCount& ourVC = ledgers[closedLedger];
|
||||
|
||||
if ((theConfig.LEDGER_CREATOR) && (mMode >= omTRACKING))
|
||||
|
||||
20
src/Peer.cpp
20
src/Peer.cpp
@@ -649,7 +649,10 @@ void Peer::recvHello(newcoin::TMHello& packet)
|
||||
{
|
||||
memcpy(mClosedLedgerHash.begin(), packet.ledgerclosed().data(), 256 / 8);
|
||||
if ((packet.has_ledgerprevious()) && (packet.ledgerprevious().size() == (256 / 8)))
|
||||
{
|
||||
memcpy(mPreviousLedgerHash.begin(), packet.ledgerprevious().data(), 256 / 8);
|
||||
addLedger(mPreviousLedgerHash);
|
||||
}
|
||||
else mPreviousLedgerHash.zero();
|
||||
}
|
||||
|
||||
@@ -915,6 +918,7 @@ void Peer::recvStatus(newcoin::TMStatusChange& packet)
|
||||
if (packet.has_ledgerhash() && (packet.ledgerhash().size() == (256 / 8)))
|
||||
{ // a peer has changed ledgers
|
||||
memcpy(mClosedLedgerHash.begin(), packet.ledgerhash().data(), 256 / 8);
|
||||
addLedger(mClosedLedgerHash);
|
||||
Log(lsTRACE) << "peer LCL is " << mClosedLedgerHash << " " << getIP();
|
||||
}
|
||||
else
|
||||
@@ -926,6 +930,7 @@ void Peer::recvStatus(newcoin::TMStatusChange& packet)
|
||||
if (packet.has_ledgerhashprevious() && packet.ledgerhashprevious().size() == (256 / 8))
|
||||
{
|
||||
memcpy(mPreviousLedgerHash.begin(), packet.ledgerhashprevious().data(), 256 / 8);
|
||||
addLedger(mPreviousLedgerHash);
|
||||
}
|
||||
else mPreviousLedgerHash.zero();
|
||||
}
|
||||
@@ -1134,7 +1139,20 @@ void Peer::recvLedger(newcoin::TMLedgerData& packet)
|
||||
|
||||
bool Peer::hasLedger(const uint256& hash) const
|
||||
{
|
||||
return (hash == mClosedLedgerHash) || (hash == mPreviousLedgerHash);
|
||||
BOOST_FOREACH(const uint256& ledger, mRecentLedgers)
|
||||
if (ledger == hash)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void Peer::addLedger(const uint256& hash)
|
||||
{
|
||||
BOOST_FOREACH(const uint256& ledger, mRecentLedgers)
|
||||
if (ledger == hash)
|
||||
return;
|
||||
if (mRecentLedgers.size() == 16)
|
||||
mRecentLedgers.pop_front();
|
||||
mRecentLedgers.push_back(hash);
|
||||
}
|
||||
|
||||
// Get session information we can sign to prevent man in the middle attack.
|
||||
|
||||
@@ -44,7 +44,8 @@ private:
|
||||
ipPort mIpPortConnect;
|
||||
uint256 mCookieHash;
|
||||
|
||||
uint256 mClosedLedgerHash, mPreviousLedgerHash;
|
||||
uint256 mClosedLedgerHash, mPreviousLedgerHash;
|
||||
std::list<uint256> mRecentLedgers;
|
||||
|
||||
boost::asio::ssl::stream<boost::asio::ip::tcp::socket> mSocketSsl;
|
||||
|
||||
@@ -116,6 +117,8 @@ protected:
|
||||
|
||||
void getSessionCookie(std::string& strDst);
|
||||
|
||||
void addLedger(const uint256& ledger);
|
||||
|
||||
public:
|
||||
|
||||
//bool operator == (const Peer& other);
|
||||
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
virtual void gotNode(const SHAMapNode& id, const uint256& nodeHash,
|
||||
const std::vector<unsigned char>& nodeData, bool isLeaf)
|
||||
{
|
||||
theApp->getHashedObjectStore().store(ACCOUNT_NODE, mLedgerSeq, nodeData, nodeHash);
|
||||
theApp->getHashedObjectStore().store(hotACCOUNT_NODE, mLedgerSeq, nodeData, nodeHash);
|
||||
}
|
||||
virtual bool haveNode(const SHAMapNode& id, const uint256& nodeHash, std::vector<unsigned char>& nodeData)
|
||||
{ // fetchNodeExternal already tried
|
||||
@@ -58,7 +58,8 @@ public:
|
||||
virtual void gotNode(const SHAMapNode& id, const uint256& nodeHash,
|
||||
const std::vector<unsigned char>& nodeData, bool isLeaf)
|
||||
{
|
||||
theApp->getHashedObjectStore().store(isLeaf ? TRANSACTION : TRANSACTION_NODE, mLedgerSeq, nodeData, nodeHash);
|
||||
theApp->getHashedObjectStore().store(isLeaf ? hotTRANSACTION : hotTRANSACTION_NODE, mLedgerSeq,
|
||||
nodeData, nodeHash);
|
||||
}
|
||||
virtual bool haveNode(const SHAMapNode& id, const uint256& nodeHash, std::vector<unsigned char>& nodeData)
|
||||
{ // fetchNodeExternal already tried
|
||||
|
||||
@@ -9,12 +9,14 @@
|
||||
#include <boost/thread/mutex.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
#include "types.h"
|
||||
|
||||
class SNTPQuery
|
||||
{
|
||||
public:
|
||||
bool mReceivedReply;
|
||||
time_t mLocalTimeSent;
|
||||
int mQueryNonce;
|
||||
uint32 mQueryNonce;
|
||||
|
||||
SNTPQuery(time_t j = (time_t) -1) : mReceivedReply(false), mLocalTimeSent(j) { ; }
|
||||
};
|
||||
|
||||
@@ -582,7 +582,10 @@ public:
|
||||
const uint160& getIssuerID() const { return mIssuerID; }
|
||||
|
||||
bool operator==(const STPathElement& t) const
|
||||
{ return mType == t.mType && mAccountID == t.mAccountID && mCurrencyID == t.mCurrencyID && mIssuerID == mIssuerID; }
|
||||
{
|
||||
return mType == t.mType && mAccountID == t.mAccountID && mCurrencyID == t.mCurrencyID &&
|
||||
mIssuerID == t.mIssuerID;
|
||||
}
|
||||
};
|
||||
|
||||
class STPath
|
||||
|
||||
@@ -111,7 +111,7 @@ template<typename c_Key, typename c_Data> void TaggedCache<c_Key, c_Data>::sweep
|
||||
if (mit->second->expired())
|
||||
{
|
||||
typename boost::unordered_map<key_type, weak_data_ptr>::iterator tmp = mit++;
|
||||
mMap.erase(mit);
|
||||
mMap.erase(mit++);
|
||||
}
|
||||
else
|
||||
++mit;
|
||||
|
||||
@@ -865,50 +865,6 @@ TER TransactionEngine::setAuthorized(const SerializedTransaction& txn, bool bMus
|
||||
return tesSUCCESS;
|
||||
}
|
||||
|
||||
SLE::pointer TransactionEngine::entryCache(LedgerEntryType letType, const uint256& uIndex)
|
||||
{
|
||||
SLE::pointer sleEntry;
|
||||
|
||||
if (!!uIndex)
|
||||
{
|
||||
LedgerEntryAction action;
|
||||
sleEntry = mNodes.getEntry(uIndex, action);
|
||||
if (!sleEntry)
|
||||
{
|
||||
sleEntry = mLedger->getSLE(uIndex);
|
||||
if (sleEntry)
|
||||
mNodes.entryCache(sleEntry);
|
||||
}
|
||||
else if (action == taaDELETE)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
}
|
||||
|
||||
return sleEntry;
|
||||
}
|
||||
|
||||
SLE::pointer TransactionEngine::entryCreate(LedgerEntryType letType, const uint256& uIndex)
|
||||
{
|
||||
assert(!!uIndex);
|
||||
|
||||
SLE::pointer sleNew = boost::make_shared<SerializedLedgerEntry>(letType);
|
||||
sleNew->setIndex(uIndex);
|
||||
mNodes.entryCreate(sleNew);
|
||||
|
||||
return sleNew;
|
||||
}
|
||||
|
||||
void TransactionEngine::entryDelete(SLE::pointer sleEntry, bool bUnfunded)
|
||||
{
|
||||
mNodes.entryDelete(sleEntry, bUnfunded);
|
||||
}
|
||||
|
||||
void TransactionEngine::entryModify(SLE::pointer sleEntry)
|
||||
{
|
||||
mNodes.entryModify(sleEntry);
|
||||
}
|
||||
|
||||
void TransactionEngine::txnWrite()
|
||||
{
|
||||
// Write back the account states and add the transaction to the ledger
|
||||
@@ -956,13 +912,11 @@ void TransactionEngine::txnWrite()
|
||||
}
|
||||
}
|
||||
|
||||
TER TransactionEngine::applyTransaction(const SerializedTransaction& txn,
|
||||
TransactionEngineParams params)
|
||||
TER TransactionEngine::applyTransaction(const SerializedTransaction& txn, TransactionEngineParams params)
|
||||
{
|
||||
Log(lsTRACE) << "applyTransaction>";
|
||||
assert(mLedger);
|
||||
mLedgerParentCloseTime = mLedger->getParentCloseTimeNC();
|
||||
mNodes.init(txn.getTransactionID(), mLedger->getLedgerSeq());
|
||||
mNodes.init(mLedger, txn.getTransactionID(), mLedger->getLedgerSeq());
|
||||
|
||||
#ifdef DEBUG
|
||||
if (1)
|
||||
|
||||
@@ -295,7 +295,6 @@ private:
|
||||
|
||||
protected:
|
||||
Ledger::pointer mLedger;
|
||||
uint64 mLedgerParentCloseTime;
|
||||
|
||||
uint160 mTxnAccountID;
|
||||
SLE::pointer mTxnAccount;
|
||||
@@ -309,10 +308,10 @@ protected:
|
||||
// If the transaction fails to meet some constraint, still need to delete unfunded offers.
|
||||
boost::unordered_set<uint256> musUnfundedFound; // Offers that were found unfunded.
|
||||
|
||||
SLE::pointer entryCreate(LedgerEntryType letType, const uint256& uIndex);
|
||||
SLE::pointer entryCache(LedgerEntryType letType, const uint256& uIndex);
|
||||
void entryDelete(SLE::pointer sleEntry, bool bUnfunded = false);
|
||||
void entryModify(SLE::pointer sleEntry);
|
||||
SLE::pointer entryCreate(LedgerEntryType type, const uint256& index) { return mNodes.entryCreate(type, index); }
|
||||
SLE::pointer entryCache(LedgerEntryType type, const uint256& index) { return mNodes.entryCache(type, index); }
|
||||
void entryDelete(SLE::ref sleEntry) { mNodes.entryDelete(sleEntry); }
|
||||
void entryModify(SLE::ref sleEntry) { mNodes.entryModify(sleEntry); }
|
||||
|
||||
TER offerDelete(const uint256& uOfferIndex);
|
||||
TER offerDelete(const SLE::pointer& sleOffer, const uint256& uOfferIndex, const uint160& uOwnerID);
|
||||
|
||||
@@ -71,7 +71,7 @@ protected:
|
||||
uint32 mPrevLgrSeq;
|
||||
|
||||
public:
|
||||
TMNEThread() : TransactionMetaNodeEntry(TMSThread) { ; }
|
||||
TMNEThread() : TransactionMetaNodeEntry(TMSThread), mPrevLgrSeq(0) { ; }
|
||||
TMNEThread(uint256 prevTx, uint32 prevLgrSeq)
|
||||
: TransactionMetaNodeEntry(TMSThread), mPrevTxID(prevTx), mPrevLgrSeq(prevLgrSeq)
|
||||
{ ; }
|
||||
|
||||
@@ -184,8 +184,6 @@ void UniqueNodeList::scoreCompute()
|
||||
|
||||
Database* db=theApp->getWalletDB()->getDB();
|
||||
|
||||
std::string strSql;
|
||||
|
||||
// For each entry in SeedDomains with a PublicKey:
|
||||
// - Add an entry in umPulicIdx, umDomainIdx, and vsnNodes.
|
||||
{
|
||||
@@ -389,7 +387,7 @@ void UniqueNodeList::scoreCompute()
|
||||
db->executeSQL("BEGIN;");
|
||||
db->executeSQL("UPDATE TrustedNodes SET Score = 0 WHERE Score != 0;");
|
||||
|
||||
if (vsnNodes.size())
|
||||
if (!vsnNodes.empty())
|
||||
{
|
||||
// Load existing Seens from DB.
|
||||
std::vector<std::string> vstrPublicKeys;
|
||||
@@ -410,7 +408,7 @@ void UniqueNodeList::scoreCompute()
|
||||
|
||||
boost::unordered_set<std::string> usUNL;
|
||||
|
||||
if (vsnNodes.size())
|
||||
if (!vsnNodes.empty())
|
||||
{
|
||||
// Update the score old entries and add new entries as needed.
|
||||
std::vector<std::string> vstrValues;
|
||||
@@ -446,7 +444,7 @@ void UniqueNodeList::scoreCompute()
|
||||
|
||||
boost::unordered_map<std::string, int> umValidators;
|
||||
|
||||
if (vsnNodes.size())
|
||||
if (!vsnNodes.empty())
|
||||
{
|
||||
std::vector<std::string> vstrPublicKeys;
|
||||
|
||||
@@ -627,7 +625,7 @@ void UniqueNodeList::processIps(const std::string& strSite, const NewcoinAddress
|
||||
}
|
||||
|
||||
// Add new referral entries.
|
||||
if (pmtVecStrIps && pmtVecStrIps->size()) {
|
||||
if (pmtVecStrIps && !pmtVecStrIps->empty()) {
|
||||
std::vector<std::string> vstrValues;
|
||||
|
||||
vstrValues.resize(MIN(pmtVecStrIps->size(), REFERRAL_IPS_MAX));
|
||||
@@ -712,7 +710,6 @@ int UniqueNodeList::processValidators(const std::string& strSite, const std::str
|
||||
break;
|
||||
|
||||
boost::smatch smMatch;
|
||||
std::string strIP;
|
||||
|
||||
// domain comment?
|
||||
// public_key comment?
|
||||
@@ -779,7 +776,7 @@ int UniqueNodeList::processValidators(const std::string& strSite, const std::str
|
||||
}
|
||||
|
||||
// Given a section with IPs, parse and persist it for a validator.
|
||||
void UniqueNodeList::responseIps(const std::string& strSite, const NewcoinAddress& naNodePublic, const boost::system::error_code& err, const std::string strIpsFile)
|
||||
void UniqueNodeList::responseIps(const std::string& strSite, const NewcoinAddress& naNodePublic, const boost::system::error_code& err, const std::string& strIpsFile)
|
||||
{
|
||||
if (!err)
|
||||
{
|
||||
@@ -819,7 +816,7 @@ void UniqueNodeList::getIpsUrl(const NewcoinAddress& naNodePublic, section secSi
|
||||
}
|
||||
|
||||
// After fetching a newcoin.txt from a web site, given a section with validators, parse and persist it.
|
||||
void UniqueNodeList::responseValidators(const std::string& strValidatorsUrl, const NewcoinAddress& naNodePublic, section secSite, const std::string& strSite, const boost::system::error_code& err, const std::string strValidatorsFile)
|
||||
void UniqueNodeList::responseValidators(const std::string& strValidatorsUrl, const NewcoinAddress& naNodePublic, section secSite, const std::string& strSite, const boost::system::error_code& err, const std::string& strValidatorsFile)
|
||||
{
|
||||
if (!err)
|
||||
{
|
||||
@@ -858,7 +855,7 @@ void UniqueNodeList::getValidatorsUrl(const NewcoinAddress& naNodePublic, sectio
|
||||
}
|
||||
|
||||
// Process a newcoin.txt.
|
||||
void UniqueNodeList::processFile(const std::string strDomain, const NewcoinAddress& naNodePublic, section secSite)
|
||||
void UniqueNodeList::processFile(const std::string& strDomain, const NewcoinAddress& naNodePublic, section secSite)
|
||||
{
|
||||
//
|
||||
// Process Validators
|
||||
@@ -885,7 +882,7 @@ void UniqueNodeList::processFile(const std::string strDomain, const NewcoinAddre
|
||||
}
|
||||
|
||||
// Given a newcoin.txt, process it.
|
||||
void UniqueNodeList::responseFetch(const std::string strDomain, const boost::system::error_code& err, const std::string strSiteFile)
|
||||
void UniqueNodeList::responseFetch(const std::string& strDomain, const boost::system::error_code& err, const std::string& strSiteFile)
|
||||
{
|
||||
section secSite = ParseSection(strSiteFile, true);
|
||||
bool bGood = !err;
|
||||
|
||||
@@ -95,7 +95,7 @@ private:
|
||||
|
||||
bool scoreRound(std::vector<scoreNode>& vsnNodes);
|
||||
|
||||
void responseFetch(const std::string strDomain, const boost::system::error_code& err, const std::string strSiteFile);
|
||||
void responseFetch(const std::string& strDomain, const boost::system::error_code& err, const std::string& strSiteFile);
|
||||
|
||||
boost::posix_time::ptime mtpScoreNext; // When to start scoring.
|
||||
boost::posix_time::ptime mtpScoreStart; // Time currently started scoring.
|
||||
@@ -119,13 +119,13 @@ private:
|
||||
|
||||
void getValidatorsUrl(const NewcoinAddress& naNodePublic, section secSite);
|
||||
void getIpsUrl(const NewcoinAddress& naNodePublic, section secSite);
|
||||
void responseIps(const std::string& strSite, const NewcoinAddress& naNodePublic, const boost::system::error_code& err, const std::string strIpsFile);
|
||||
void responseValidators(const std::string& strValidatorsUrl, const NewcoinAddress& naNodePublic, section secSite, const std::string& strSite, const boost::system::error_code& err, const std::string strValidatorsFile);
|
||||
void responseIps(const std::string& strSite, const NewcoinAddress& naNodePublic, const boost::system::error_code& err, const std::string& strIpsFile);
|
||||
void responseValidators(const std::string& strValidatorsUrl, const NewcoinAddress& naNodePublic, section secSite, const std::string& strSite, const boost::system::error_code& err, const std::string& strValidatorsFile);
|
||||
|
||||
void processIps(const std::string& strSite, const NewcoinAddress& naNodePublic, section::mapped_type* pmtVecStrIps);
|
||||
int processValidators(const std::string& strSite, const std::string& strValidatorsSrc, const NewcoinAddress& naNodePublic, validatorSource vsWhy, section::mapped_type* pmtVecStrValidators);
|
||||
|
||||
void processFile(const std::string strDomain, const NewcoinAddress& naNodePublic, section secSite);
|
||||
void processFile(const std::string& strDomain, const NewcoinAddress& naNodePublic, section secSite);
|
||||
|
||||
bool getSeedDomains(const std::string& strDomain, seedDomain& dstSeedDomain);
|
||||
void setSeedDomains(const seedDomain& dstSeedDomain, bool bNext);
|
||||
|
||||
@@ -16,8 +16,8 @@
|
||||
#include "Application.h"
|
||||
#include "utils.h"
|
||||
|
||||
Wallet::Wallet() : mLedger(0) {
|
||||
}
|
||||
Wallet::Wallet() : mDh512(NULL), mDh1024(NULL), mLedger(0)
|
||||
{ ; }
|
||||
|
||||
void Wallet::start()
|
||||
{
|
||||
@@ -136,8 +136,6 @@ bool Wallet::dataFetch(const std::string& strKey, std::string& strValue)
|
||||
if (db->executeSQL(str(boost::format("SELECT Value FROM RPCData WHERE Key=%s;")
|
||||
% db->escape(strKey))) && db->startIterRows())
|
||||
{
|
||||
std::string strPublicKey, strPrivateKey;
|
||||
|
||||
std::vector<unsigned char> vucData = db->getBinary("Value");
|
||||
strValue.assign(vucData.begin(), vucData.end());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user