mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-27 14:35:52 +00:00
Merge branch 'master' of github.com:jedmccaleb/NewCoin
This commit is contained in:
@@ -14,13 +14,13 @@ SETUP_LOG();
|
||||
DECLARE_INSTANCE(LedgerAcquire);
|
||||
|
||||
#define LA_DEBUG
|
||||
#define LEDGER_ACQUIRE_TIMEOUT 750 // millisecond for each ledger timeout
|
||||
#define LEDGER_TIMEOUT_COUNT 10 // how many timeouts before we giveup
|
||||
#define LEDGER_TIMEOUT_AGGRESSIVE 4 // how many timeouts before we get aggressive
|
||||
#define LEDGER_ACQUIRE_TIMEOUT 1000 // millisecond for each ledger timeout
|
||||
#define LEDGER_TIMEOUT_COUNT 10 // how many timeouts before we giveup
|
||||
#define LEDGER_TIMEOUT_AGGRESSIVE 4 // how many timeouts before we get aggressive
|
||||
#define TRUST_NETWORK
|
||||
|
||||
PeerSet::PeerSet(const uint256& hash, int interval) : mHash(hash), mTimerInterval(interval), mTimeouts(0),
|
||||
mComplete(false), mFailed(false), mProgress(true), mAggressive(true), mTimer(theApp->getIOService())
|
||||
mComplete(false), mFailed(false), mProgress(true), mAggressive(false), mTimer(theApp->getIOService())
|
||||
{
|
||||
mLastAction = upTime();
|
||||
assert((mTimerInterval > 10) && (mTimerInterval < 30000));
|
||||
@@ -195,14 +195,13 @@ void LedgerAcquire::onTimer(bool progress)
|
||||
if (!progress)
|
||||
{
|
||||
mAggressive = true;
|
||||
mByHash = true;
|
||||
cLog(lsDEBUG) << "No progress for ledger " << mHash;
|
||||
if (!getPeerCount())
|
||||
addPeers();
|
||||
else
|
||||
trigger(Peer::pointer());
|
||||
}
|
||||
else
|
||||
mByHash = true;
|
||||
}
|
||||
|
||||
void LedgerAcquire::addPeers()
|
||||
@@ -532,8 +531,7 @@ void LedgerAcquire::filterNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<ui
|
||||
std::vector<bool> duplicates;
|
||||
duplicates.reserve(nodeIDs.size());
|
||||
|
||||
int dupCount=0;
|
||||
|
||||
int dupCount = 0;
|
||||
for (unsigned int i = 0; i < nodeIDs.size(); ++i)
|
||||
{
|
||||
bool isDup = recentNodes.count(nodeIDs[i]) != 0;
|
||||
@@ -733,7 +731,7 @@ LedgerAcquire::pointer LedgerAcquireMaster::findCreate(const uint256& hash)
|
||||
ptr->setTimer(); // Cannot call in constructor
|
||||
}
|
||||
else
|
||||
cLog(lsDEBUG) << "LedgerAcquireMaster acquiring ledger we already have";
|
||||
cLog(lsDEBUG) << "Acquiring ledger we already have: " << hash;
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ Ledger::pointer LedgerMaster::closeLedger(bool recover)
|
||||
mCurrentLedger = boost::make_shared<Ledger>(boost::ref(*closingLedger), true);
|
||||
mEngine.setLedger(mCurrentLedger);
|
||||
|
||||
return closingLedger;
|
||||
return Ledger::pointer(new Ledger(*closingLedger, true));
|
||||
}
|
||||
|
||||
TER LedgerMaster::doTransaction(SerializedTransaction::ref txn, TransactionEngineParams params, bool& didApply)
|
||||
|
||||
@@ -595,10 +595,14 @@ public:
|
||||
|
||||
void NetworkOPs::checkState(const boost::system::error_code& result)
|
||||
{ // Network state machine
|
||||
|
||||
if ((result == boost::asio::error::operation_aborted) || theConfig.RUN_STANDALONE)
|
||||
return;
|
||||
|
||||
setStateTimer();
|
||||
|
||||
ScopedLock(theApp->getMasterLock());
|
||||
|
||||
std::vector<Peer::pointer> peerList = theApp->getConnectionPool().getPeerVector();
|
||||
|
||||
// do we have sufficient peers? If not, we are disconnected.
|
||||
@@ -618,12 +622,9 @@ void NetworkOPs::checkState(const boost::system::error_code& result)
|
||||
cLog(lsINFO) << "Node count (" << peerList.size() << ") is sufficient.";
|
||||
}
|
||||
|
||||
if (mConsensus)
|
||||
{
|
||||
mConsensus->timerEntry();
|
||||
return;
|
||||
}
|
||||
tryStartConsensus();
|
||||
if (!mConsensus)
|
||||
tryStartConsensus();
|
||||
|
||||
if (mConsensus)
|
||||
mConsensus->timerEntry();
|
||||
}
|
||||
@@ -632,7 +633,7 @@ void NetworkOPs::tryStartConsensus()
|
||||
{
|
||||
uint256 networkClosed;
|
||||
bool ledgerChange = checkLastClosedLedger(theApp->getConnectionPool().getPeerVector(), networkClosed);
|
||||
if(networkClosed.isZero())
|
||||
if (networkClosed.isZero())
|
||||
return;
|
||||
|
||||
// WRITEME: Unless we are in omFULL and in the process of doing a consensus,
|
||||
|
||||
@@ -39,8 +39,7 @@ void OrderBookDB::setup(Ledger::ref ledger)
|
||||
|
||||
while (currentIndex.isNonZero())
|
||||
{
|
||||
SLE::pointer entry=ledger->getSLEi(currentIndex);
|
||||
|
||||
SLE::pointer entry = ledger->getSLEi(currentIndex);
|
||||
OrderBook::pointer book = OrderBook::newOrderBook(entry);
|
||||
if (book)
|
||||
{
|
||||
@@ -55,19 +54,14 @@ void OrderBookDB::setup(Ledger::ref ledger)
|
||||
<< " -> "
|
||||
<< STAmount::createHumanCurrency(book->getCurrencyOut());
|
||||
|
||||
if (!book->getCurrencyIn())
|
||||
{
|
||||
// XRP
|
||||
if (!book->getCurrencyIn()) // XRP
|
||||
mXRPOrders.push_back(book);
|
||||
}
|
||||
else
|
||||
{
|
||||
mIssuerMap[book->getIssuerIn()].push_back(book);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentIndex=ledger->getNextLedgerIndex(currentIndex);
|
||||
currentIndex = ledger->getNextLedgerIndex(currentIndex);
|
||||
}
|
||||
|
||||
cLog(lsDEBUG) << "OrderBookDB<";
|
||||
|
||||
@@ -188,7 +188,7 @@ TER PathState::pushNode(
|
||||
else
|
||||
{
|
||||
// Add required intermediate nodes to deliver to current account.
|
||||
cLog(lsDEBUG) << "pushNode: imply for account.";
|
||||
cLog(lsTRACE) << "pushNode: imply for account.";
|
||||
|
||||
terResult = pushImply(
|
||||
pnCur.uAccountID, // Current account.
|
||||
@@ -223,7 +223,7 @@ TER PathState::pushNode(
|
||||
}
|
||||
else
|
||||
{
|
||||
cLog(lsDEBUG) << "pushNode: Credit line found between "
|
||||
cLog(lsTRACE) << "pushNode: Credit line found between "
|
||||
<< RippleAddress::createHumanAccountID(pnBck.uAccountID)
|
||||
<< " and "
|
||||
<< RippleAddress::createHumanAccountID(pnCur.uAccountID)
|
||||
@@ -266,7 +266,7 @@ TER PathState::pushNode(
|
||||
else if (!!pnPrv.uAccountID)
|
||||
{
|
||||
// Previous is an account.
|
||||
cLog(lsDEBUG) << "pushNode: imply for offer.";
|
||||
cLog(lsTRACE) << "pushNode: imply for offer.";
|
||||
|
||||
// Insert intermediary issuer account if needed.
|
||||
terResult = pushImply(
|
||||
@@ -280,7 +280,7 @@ TER PathState::pushNode(
|
||||
vpnNodes.push_back(pnCur);
|
||||
}
|
||||
}
|
||||
cLog(lsDEBUG) << boost::str(boost::format("pushNode< : %s") % transToken(terResult));
|
||||
cLog(lsTRACE) << boost::str(boost::format("pushNode< : %s") % transToken(terResult));
|
||||
|
||||
return terResult;
|
||||
}
|
||||
@@ -1563,7 +1563,7 @@ void RippleCalc::calcNodeRipple(
|
||||
STAmount& saCurAct, // <-> out limit including achieved : <-- <= -->
|
||||
uint64& uRateMax)
|
||||
{
|
||||
cLog(lsINFO) << boost::str(boost::format("calcNodeRipple> uQualityIn=%d uQualityOut=%d saPrvReq=%s saCurReq=%s saPrvAct=%s saCurAct=%s")
|
||||
cLog(lsTRACE) << boost::str(boost::format("calcNodeRipple> uQualityIn=%d uQualityOut=%d saPrvReq=%s saCurReq=%s saPrvAct=%s saCurAct=%s")
|
||||
% uQualityIn
|
||||
% uQualityOut
|
||||
% saPrvReq.getFullText()
|
||||
@@ -1587,7 +1587,7 @@ void RippleCalc::calcNodeRipple(
|
||||
if (uQualityIn >= uQualityOut)
|
||||
{
|
||||
// No fee.
|
||||
cLog(lsINFO) << boost::str(boost::format("calcNodeRipple: No fees"));
|
||||
cLog(lsTRACE) << boost::str(boost::format("calcNodeRipple: No fees"));
|
||||
|
||||
// Only process if we are not worsing previously processed.
|
||||
if (!uRateMax || STAmount::uRateOne <= uRateMax)
|
||||
@@ -1608,7 +1608,7 @@ void RippleCalc::calcNodeRipple(
|
||||
else
|
||||
{
|
||||
// Fee.
|
||||
cLog(lsINFO) << boost::str(boost::format("calcNodeRipple: Fee"));
|
||||
cLog(lsTRACE) << boost::str(boost::format("calcNodeRipple: Fee"));
|
||||
|
||||
uint64 uRate = STAmount::getRate(STAmount(uQualityIn), STAmount(uQualityOut));
|
||||
|
||||
@@ -1620,19 +1620,19 @@ void RippleCalc::calcNodeRipple(
|
||||
|
||||
STAmount saCurIn = STAmount::divide(STAmount::multiply(saCur, uQualityOut, uCurrencyID, uCurIssuerID), uQualityIn, uCurrencyID, uCurIssuerID);
|
||||
|
||||
cLog(lsINFO) << boost::str(boost::format("calcNodeRipple: bPrvUnlimited=%d saPrv=%s saCurIn=%s") % bPrvUnlimited % saPrv.getFullText() % saCurIn.getFullText());
|
||||
cLog(lsTRACE) << boost::str(boost::format("calcNodeRipple: bPrvUnlimited=%d saPrv=%s saCurIn=%s") % bPrvUnlimited % saPrv.getFullText() % saCurIn.getFullText());
|
||||
if (bPrvUnlimited || saCurIn <= saPrv)
|
||||
{
|
||||
// All of cur. Some amount of prv.
|
||||
saCurAct += saCur;
|
||||
saPrvAct += saCurIn;
|
||||
cLog(lsINFO) << boost::str(boost::format("calcNodeRipple:3c: saCurReq=%s saPrvAct=%s") % saCurReq.getFullText() % saPrvAct.getFullText());
|
||||
cLog(lsTRACE) << boost::str(boost::format("calcNodeRipple:3c: saCurReq=%s saPrvAct=%s") % saCurReq.getFullText() % saPrvAct.getFullText());
|
||||
}
|
||||
else
|
||||
{
|
||||
// A part of cur. All of prv. (cur as driver)
|
||||
STAmount saCurOut = STAmount::divide(STAmount::multiply(saPrv, uQualityIn, uCurrencyID, uCurIssuerID), uQualityOut, uCurrencyID, uCurIssuerID);
|
||||
cLog(lsINFO) << boost::str(boost::format("calcNodeRipple:4: saCurReq=%s") % saCurReq.getFullText());
|
||||
cLog(lsTRACE) << boost::str(boost::format("calcNodeRipple:4: saCurReq=%s") % saCurReq.getFullText());
|
||||
|
||||
saCurAct += saCurOut;
|
||||
saPrvAct = saPrvReq;
|
||||
@@ -1643,7 +1643,7 @@ void RippleCalc::calcNodeRipple(
|
||||
}
|
||||
}
|
||||
|
||||
cLog(lsINFO) << boost::str(boost::format("calcNodeRipple< uQualityIn=%d uQualityOut=%d saPrvReq=%s saCurReq=%s saPrvAct=%s saCurAct=%s")
|
||||
cLog(lsTRACE) << boost::str(boost::format("calcNodeRipple< uQualityIn=%d uQualityOut=%d saPrvReq=%s saCurReq=%s saPrvAct=%s saCurAct=%s")
|
||||
% uQualityIn
|
||||
% uQualityOut
|
||||
% saPrvReq.getFullText()
|
||||
|
||||
@@ -24,13 +24,10 @@ DECLARE_INSTANCE(SHAMapTreeNode);
|
||||
void SHAMapNode::setHash() const
|
||||
{
|
||||
std::size_t h = theApp->getNonceST() + (mDepth * 0x9e3779b9);
|
||||
mHash = mNodeID.hash_combine(h);
|
||||
#if 0
|
||||
const unsigned int *ptr = reinterpret_cast<const unsigned int *>(mNodeID.begin());
|
||||
for (int i = (mDepth + 3) / 4; i != 0; --i)
|
||||
boost::hash_combine(h, *ptr++);
|
||||
for (int i = (mDepth + 7) / 8; i != 0; --i)
|
||||
h = (h * 0x9e3779b9) ^ *ptr++;
|
||||
mHash = h;
|
||||
#endif
|
||||
}
|
||||
|
||||
std::size_t hash_value(const SHAMapNode& mn)
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <stack>
|
||||
#include <bitset>
|
||||
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <boost/enable_shared_from_this.hpp>
|
||||
@@ -166,10 +165,10 @@ public:
|
||||
private:
|
||||
uint256 mHash;
|
||||
uint256 mHashes[16];
|
||||
std::bitset<16> mIsBranch;
|
||||
SHAMapItem::pointer mItem;
|
||||
uint32 mSeq, mAccessSeq;
|
||||
TNType mType;
|
||||
int mIsBranch;
|
||||
bool mFullBelow;
|
||||
|
||||
bool updateHash();
|
||||
@@ -208,7 +207,7 @@ public:
|
||||
// inner node functions
|
||||
bool isInnerNode() const { return !mItem; }
|
||||
bool setChildHash(int m, const uint256& hash);
|
||||
bool isEmptyBranch(int m) const { return !mIsBranch.test(m); }
|
||||
bool isEmptyBranch(int m) const { return (mIsBranch & (1 << m)) == 0; }
|
||||
bool isEmpty() const;
|
||||
int getBranchCount() const;
|
||||
void makeInner();
|
||||
|
||||
@@ -102,10 +102,9 @@ uint256 SHAMapNode::getNodeID(int depth, const uint256& hash)
|
||||
return hash & smMasks[depth];
|
||||
}
|
||||
|
||||
SHAMapNode::SHAMapNode(int depth, const uint256 &hash) : mDepth(depth), mHash(0)
|
||||
SHAMapNode::SHAMapNode(int depth, const uint256 &hash) : mDepth(depth), mHash(0), mNodeID(getNodeID(depth, hash))
|
||||
{ // canonicalize the hash to a node ID for this depth
|
||||
assert((depth >= 0) && (depth < 65));
|
||||
mNodeID = getNodeID(depth, hash);
|
||||
}
|
||||
|
||||
SHAMapNode::SHAMapNode(const void *ptr, int len) : mHash(0)
|
||||
@@ -177,12 +176,12 @@ void SHAMapNode::dump() const
|
||||
}
|
||||
|
||||
SHAMapTreeNode::SHAMapTreeNode(uint32 seq, const SHAMapNode& nodeID) : SHAMapNode(nodeID), mHash(0),
|
||||
mSeq(seq), mAccessSeq(seq), mType(tnERROR), mFullBelow(false)
|
||||
mSeq(seq), mAccessSeq(seq), mIsBranch(0), mType(tnERROR), mFullBelow(false)
|
||||
{
|
||||
}
|
||||
|
||||
SHAMapTreeNode::SHAMapTreeNode(const SHAMapTreeNode& node, uint32 seq) : SHAMapNode(node),
|
||||
mHash(node.mHash), mSeq(seq), mType(node.mType), mFullBelow(false)
|
||||
mHash(node.mHash), mSeq(seq), mIsBranch(0), mType(node.mType), mFullBelow(false)
|
||||
{
|
||||
if (node.mItem)
|
||||
mItem = boost::make_shared<SHAMapItem>(*node.mItem);
|
||||
@@ -191,18 +190,19 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapTreeNode& node, uint32 seq) : SHAMapN
|
||||
|
||||
for (int i = 0; i < 16; ++i)
|
||||
if (mHashes[i].isNonZero())
|
||||
mIsBranch.set(i);
|
||||
mIsBranch |= (1 << i);
|
||||
}
|
||||
|
||||
SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& node, SHAMapItem::ref item, TNType type, uint32 seq) :
|
||||
SHAMapNode(node), mItem(item), mSeq(seq), mType(type), mFullBelow(true)
|
||||
SHAMapNode(node), mItem(item), mSeq(seq), mIsBranch(0), mType(type), mFullBelow(true)
|
||||
{
|
||||
assert(item->peekData().size() >= 12);
|
||||
updateHash();
|
||||
}
|
||||
|
||||
SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned char>& rawNode, uint32 seq,
|
||||
SHANodeFormat format, const uint256& hash) : SHAMapNode(id), mSeq(seq), mType(tnERROR), mFullBelow(false)
|
||||
SHANodeFormat format, const uint256& hash) :
|
||||
SHAMapNode(id), mSeq(seq), mIsBranch(0), mType(tnERROR), mFullBelow(false)
|
||||
{
|
||||
if (format == snfWIRE)
|
||||
{
|
||||
@@ -243,7 +243,7 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned
|
||||
{
|
||||
s.get256(mHashes[i], i * 32);
|
||||
if (mHashes[i].isNonZero())
|
||||
mIsBranch.set(i);
|
||||
mIsBranch |= (1 << i);
|
||||
}
|
||||
mType = tnINNER;
|
||||
}
|
||||
@@ -255,10 +255,9 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned
|
||||
s.get8(pos, 32 + (i * 33));
|
||||
if ((pos < 0) || (pos >= 16)) throw std::runtime_error("invalid CI node");
|
||||
s.get256(mHashes[pos], i * 33);
|
||||
if (mHashes[pos].isNonZero())
|
||||
mIsBranch |= (1 << pos);
|
||||
}
|
||||
for (int i = 0; i < 16; ++i)
|
||||
if (mHashes[i].isNonZero())
|
||||
mIsBranch.set(i);
|
||||
mType = tnINNER;
|
||||
}
|
||||
else if (type == 4)
|
||||
@@ -315,7 +314,7 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned
|
||||
{
|
||||
s.get256(mHashes[i] , i * 32);
|
||||
if (mHashes[i].isNonZero())
|
||||
mIsBranch.set(i);
|
||||
mIsBranch |= (1 << i);
|
||||
}
|
||||
mType = tnINNER;
|
||||
}
|
||||
@@ -360,7 +359,7 @@ bool SHAMapTreeNode::updateHash()
|
||||
|
||||
if (mType == tnINNER)
|
||||
{
|
||||
if(mIsBranch.any())
|
||||
if (mIsBranch != 0)
|
||||
{
|
||||
nh = Serializer::getPrefixHash(sHP_InnerNode, reinterpret_cast<unsigned char *>(mHashes), sizeof(mHashes));
|
||||
#ifdef PARANOID
|
||||
@@ -422,10 +421,10 @@ void SHAMapTreeNode::addRaw(Serializer& s, SHANodeFormat format)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (mIsBranch.count() < 12)
|
||||
if (getBranchCount() < 12)
|
||||
{ // compressed node
|
||||
for (int i = 0; i < 16; ++i)
|
||||
if (mIsBranch.test(i))
|
||||
if (!isEmptyBranch(i))
|
||||
{
|
||||
s.add256(mHashes[i]);
|
||||
s.add8(i);
|
||||
@@ -505,19 +504,23 @@ SHAMapItem::pointer SHAMapTreeNode::getItem() const
|
||||
|
||||
bool SHAMapTreeNode::isEmpty() const
|
||||
{
|
||||
return mIsBranch.none();
|
||||
return mIsBranch == 0;
|
||||
}
|
||||
|
||||
int SHAMapTreeNode::getBranchCount() const
|
||||
{
|
||||
assert(isInner());
|
||||
return mIsBranch.count();
|
||||
int count = 0;
|
||||
for (int i = 0; i < 16; ++i)
|
||||
if (!isEmptyBranch(i))
|
||||
++count;
|
||||
return count;
|
||||
}
|
||||
|
||||
void SHAMapTreeNode::makeInner()
|
||||
{
|
||||
mItem.reset();
|
||||
mIsBranch.reset();
|
||||
mIsBranch = 0;
|
||||
memset(mHashes, 0, sizeof(mHashes));
|
||||
mType = tnINNER;
|
||||
mHash.zero();
|
||||
@@ -574,7 +577,10 @@ bool SHAMapTreeNode::setChildHash(int m, const uint256 &hash)
|
||||
if(mHashes[m] == hash)
|
||||
return false;
|
||||
mHashes[m] = hash;
|
||||
mIsBranch.set(m, hash.isNonZero());
|
||||
if (hash.isNonZero())
|
||||
mIsBranch |= (1 << m);
|
||||
else
|
||||
mIsBranch &= ~(1 << m);
|
||||
return updateHash();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user