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:
@@ -1446,7 +1446,7 @@ static void mulTest(int a, int b)
|
||||
if (prod1.isNative())
|
||||
BOOST_FAIL("product is native");
|
||||
|
||||
STAmount prod2(CURRENCY_ONE, ACCOUNT_ONE, a * b);
|
||||
STAmount prod2(CURRENCY_ONE, ACCOUNT_ONE, static_cast<uint64>(a) * static_cast<uint64>(b));
|
||||
if (prod1 != prod2)
|
||||
{
|
||||
Log(lsWARNING) << "nn(" << aa.getFullText() << " * " << bb.getFullText() << ") = " << prod1.getFullText()
|
||||
@@ -1489,8 +1489,8 @@ BOOST_AUTO_TEST_CASE( CurrencyMulDivTests )
|
||||
roundTest(1, 3, 3); roundTest(2, 3, 9); roundTest(1, 7, 21); roundTest(1, 2, 4);
|
||||
roundTest(3, 9, 18); roundTest(7, 11, 44);
|
||||
|
||||
mulTest(100, 1000); mulTest(1, 2); mulTest(32, 15); mulTest(981, 4012);
|
||||
mulTest(100, 5);
|
||||
for (int i = 0; i <= 100000; ++i)
|
||||
mulTest(rand() % 10000000, rand() % 10000000);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
@@ -139,11 +139,14 @@ void SHAMap::dirtyUp(std::stack<SHAMapTreeNode::pointer>& stack, const uint256&
|
||||
}
|
||||
}
|
||||
|
||||
SHAMapTreeNode::pointer SHAMap::checkCacheNode(const SHAMapNode& iNode)
|
||||
static const SHAMapTreeNode::pointer no_node;
|
||||
|
||||
SHAMapTreeNode::ref SHAMap::checkCacheNode(const SHAMapNode& iNode)
|
||||
{
|
||||
boost::unordered_map<SHAMapNode, SHAMapTreeNode::pointer>::iterator it = mTNByID.find(iNode);
|
||||
if (it == mTNByID.end())
|
||||
return SHAMapTreeNode::pointer();
|
||||
return no_node;
|
||||
it->second->touch(mSeq);
|
||||
return it->second;
|
||||
}
|
||||
|
||||
@@ -170,7 +173,7 @@ SHAMapTreeNode::pointer SHAMap::walkTo(const uint256& id, bool modify)
|
||||
}
|
||||
}
|
||||
if (inNode->getTag() != id)
|
||||
return SHAMapTreeNode::pointer();
|
||||
return no_node;
|
||||
if (modify)
|
||||
returnNode(inNode, true);
|
||||
return inNode;
|
||||
@@ -185,8 +188,7 @@ SHAMapTreeNode* SHAMap::walkToPointer(const uint256& id)
|
||||
const uint256& nextHash = inNode->getChildHash(branch);
|
||||
if (nextHash.isZero()) return NULL;
|
||||
inNode = getNodePointer(inNode->getChildNodeID(branch), nextHash);
|
||||
if (!inNode)
|
||||
throw SHAMapMissingNode(mType, inNode->getChildNodeID(branch), nextHash, id);
|
||||
assert(inNode);
|
||||
}
|
||||
return (inNode->getTag() == id) ? inNode : NULL;
|
||||
}
|
||||
@@ -211,11 +213,7 @@ SHAMapTreeNode::pointer SHAMap::getNode(const SHAMapNode& id, const uint256& has
|
||||
return node;
|
||||
}
|
||||
|
||||
node = fetchNodeExternal(id, hash);
|
||||
if (!mTNByID.insert(std::make_pair(id, node)).second)
|
||||
assert(false);
|
||||
trackNewNode(node);
|
||||
return node;
|
||||
return fetchNodeExternal(id, hash);
|
||||
}
|
||||
|
||||
SHAMapTreeNode* SHAMap::getNodePointer(const SHAMapNode& id, const uint256& hash)
|
||||
@@ -224,11 +222,7 @@ SHAMapTreeNode* SHAMap::getNodePointer(const SHAMapNode& id, const uint256& hash
|
||||
if (it != mTNByID.end())
|
||||
return it->second.get();
|
||||
|
||||
SHAMapTreeNode::pointer node = fetchNodeExternal(id, hash);
|
||||
if (!mTNByID.insert(std::make_pair(id, node)).second)
|
||||
assert(false);
|
||||
trackNewNode(node);
|
||||
return node.get();
|
||||
return fetchNodeExternal(id, hash).get();
|
||||
}
|
||||
|
||||
void SHAMap::returnNode(SHAMapTreeNode::pointer& node, bool modify)
|
||||
@@ -369,42 +363,44 @@ void SHAMap::eraseChildren(SHAMapTreeNode::pointer node)
|
||||
return;
|
||||
}
|
||||
|
||||
SHAMapItem::pointer SHAMap::peekFirstItem()
|
||||
static const SHAMapItem::pointer no_item;
|
||||
|
||||
SHAMapItem::ref SHAMap::peekFirstItem()
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
SHAMapTreeNode *node = firstBelow(root.get());
|
||||
if (!node)
|
||||
return SHAMapItem::pointer();
|
||||
return no_item;
|
||||
return node->peekItem();
|
||||
}
|
||||
|
||||
SHAMapItem::pointer SHAMap::peekFirstItem(SHAMapTreeNode::TNType& type)
|
||||
SHAMapItem::ref SHAMap::peekFirstItem(SHAMapTreeNode::TNType& type)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
SHAMapTreeNode *node = firstBelow(root.get());
|
||||
if (!node)
|
||||
return SHAMapItem::pointer();
|
||||
return no_item;
|
||||
type = node->getType();
|
||||
return node->peekItem();
|
||||
}
|
||||
|
||||
SHAMapItem::pointer SHAMap::peekLastItem()
|
||||
SHAMapItem::ref SHAMap::peekLastItem()
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
SHAMapTreeNode *node = lastBelow(root.get());
|
||||
if (!node)
|
||||
return SHAMapItem::pointer();
|
||||
return no_item;
|
||||
return node->peekItem();
|
||||
}
|
||||
|
||||
SHAMapItem::pointer SHAMap::peekNextItem(const uint256& id)
|
||||
SHAMapItem::ref SHAMap::peekNextItem(const uint256& id)
|
||||
{
|
||||
SHAMapTreeNode::TNType type;
|
||||
return peekNextItem(id, type);
|
||||
}
|
||||
|
||||
|
||||
SHAMapItem::pointer SHAMap::peekNextItem(const uint256& id, SHAMapTreeNode::TNType& type)
|
||||
SHAMapItem::ref SHAMap::peekNextItem(const uint256& id, SHAMapTreeNode::TNType& type)
|
||||
{ // Get a pointer to the next item in the tree after a given item - item must be in tree
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
|
||||
@@ -427,8 +423,7 @@ SHAMapItem::pointer SHAMap::peekNextItem(const uint256& id, SHAMapTreeNode::TNTy
|
||||
if (!node->isEmptyBranch(i))
|
||||
{
|
||||
SHAMapTreeNode *firstNode = getNodePointer(node->getChildNodeID(i), node->getChildHash(i));
|
||||
if (!firstNode)
|
||||
throw std::runtime_error("missing node");
|
||||
assert(firstNode);
|
||||
firstNode = firstBelow(firstNode);
|
||||
if (!firstNode)
|
||||
throw std::runtime_error("missing node");
|
||||
@@ -437,10 +432,10 @@ SHAMapItem::pointer SHAMap::peekNextItem(const uint256& id, SHAMapTreeNode::TNTy
|
||||
}
|
||||
}
|
||||
// must be last item
|
||||
return SHAMapItem::pointer();
|
||||
return no_item;
|
||||
}
|
||||
|
||||
SHAMapItem::pointer SHAMap::peekPrevItem(const uint256& id)
|
||||
SHAMapItem::ref SHAMap::peekPrevItem(const uint256& id)
|
||||
{ // Get a pointer to the previous item in the tree after a given item - item must be in tree
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
|
||||
@@ -466,24 +461,24 @@ SHAMapItem::pointer SHAMap::peekPrevItem(const uint256& id)
|
||||
}
|
||||
}
|
||||
// must be last item
|
||||
return SHAMapItem::pointer();
|
||||
return no_item;
|
||||
}
|
||||
|
||||
SHAMapItem::pointer SHAMap::peekItem(const uint256& id)
|
||||
SHAMapItem::ref SHAMap::peekItem(const uint256& id)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
SHAMapTreeNode* leaf = walkToPointer(id);
|
||||
if (!leaf)
|
||||
return SHAMapItem::pointer();
|
||||
return no_item;
|
||||
return leaf->peekItem();
|
||||
}
|
||||
|
||||
SHAMapItem::pointer SHAMap::peekItem(const uint256& id, SHAMapTreeNode::TNType& type)
|
||||
SHAMapItem::ref SHAMap::peekItem(const uint256& id, SHAMapTreeNode::TNType& type)
|
||||
{
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
SHAMapTreeNode* leaf = walkToPointer(id);
|
||||
if (!leaf)
|
||||
return SHAMapItem::pointer();
|
||||
return no_item;
|
||||
type = leaf->getType();
|
||||
return leaf->peekItem();
|
||||
}
|
||||
@@ -675,7 +670,8 @@ bool SHAMap::updateGiveItem(SHAMapItem::ref item, bool isTransaction, bool hasMe
|
||||
assert(mState != smsImmutable);
|
||||
|
||||
std::stack<SHAMapTreeNode::pointer> stack = getStack(tag, true, false);
|
||||
if (stack.empty()) throw std::runtime_error("missing node");
|
||||
if (stack.empty())
|
||||
throw std::runtime_error("missing node");
|
||||
|
||||
SHAMapTreeNode::pointer node = stack.top();
|
||||
stack.pop();
|
||||
@@ -730,6 +726,11 @@ SHAMapTreeNode::pointer SHAMap::fetchNodeExternal(const SHAMapNode& id, const ui
|
||||
assert(false);
|
||||
return SHAMapTreeNode::pointer();
|
||||
}
|
||||
if (id.isRoot())
|
||||
mTNByID[id] = ret;
|
||||
else if (!mTNByID.insert(std::make_pair(id, ret)).second)
|
||||
assert(false);
|
||||
trackNewNode(ret);
|
||||
return ret;
|
||||
}
|
||||
catch (...)
|
||||
@@ -751,7 +752,6 @@ void SHAMap::fetchRoot(const uint256& hash)
|
||||
Log(lsTRACE) << "Fetch root SHAMap node " << hash;
|
||||
}
|
||||
root = fetchNodeExternal(SHAMapNode(), hash);
|
||||
mTNByID[*root] = root;
|
||||
assert(root->getNodeHash() == hash);
|
||||
}
|
||||
|
||||
@@ -799,7 +799,8 @@ SHAMapTreeNode::pointer SHAMap::getNode(const SHAMapNode& nodeID)
|
||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||
|
||||
SHAMapTreeNode::pointer node = checkCacheNode(nodeID);
|
||||
if (node) return node;
|
||||
if (node)
|
||||
return node;
|
||||
|
||||
node = root;
|
||||
while (nodeID != *node)
|
||||
@@ -810,7 +811,7 @@ SHAMapTreeNode::pointer SHAMap::getNode(const SHAMapNode& nodeID)
|
||||
return SHAMapTreeNode::pointer();
|
||||
|
||||
node = getNode(node->getChildNodeID(branch), node->getChildHash(branch), false);
|
||||
if (!node) throw std::runtime_error("missing node");
|
||||
assert(node);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
@@ -833,8 +834,7 @@ bool SHAMap::getPath(const uint256& index, std::vector< std::vector<unsigned cha
|
||||
if (inNode->isEmptyBranch(branch)) // paths leads to empty branch
|
||||
return false;
|
||||
inNode = getNodePointer(inNode->getChildNodeID(branch), inNode->getChildHash(branch));
|
||||
if (!inNode)
|
||||
throw SHAMapMissingNode(mType, inNode->getChildNodeID(branch), inNode->getChildHash(branch), index);
|
||||
assert(inNode);
|
||||
}
|
||||
|
||||
if (inNode->getTag() != index) // path leads to different leaf
|
||||
|
||||
@@ -161,7 +161,7 @@ private:
|
||||
uint256 mHash;
|
||||
uint256 mHashes[16];
|
||||
SHAMapItem::pointer mItem;
|
||||
uint32 mSeq;
|
||||
uint32 mSeq, mAccessSeq;
|
||||
TNType mType;
|
||||
bool mFullBelow;
|
||||
|
||||
@@ -183,7 +183,8 @@ public:
|
||||
|
||||
// node functions
|
||||
uint32 getSeq() const { return mSeq; }
|
||||
void setSeq(uint32 s) { mSeq = s; }
|
||||
void setSeq(uint32 s) { mAccessSeq = mSeq = s; }
|
||||
void touch(uint32 s) { mAccessSeq = s; }
|
||||
const uint256& getNodeHash() const { return mHash; }
|
||||
TNType getType() const { return mType; }
|
||||
|
||||
@@ -348,7 +349,7 @@ protected:
|
||||
std::stack<SHAMapTreeNode::pointer> getStack(const uint256& id, bool include_nonmatching_leaf, bool partialOk);
|
||||
SHAMapTreeNode::pointer walkTo(const uint256& id, bool modify);
|
||||
SHAMapTreeNode* walkToPointer(const uint256& id);
|
||||
SHAMapTreeNode::pointer checkCacheNode(const SHAMapNode&);
|
||||
SHAMapTreeNode::ref checkCacheNode(const SHAMapNode&);
|
||||
void returnNode(SHAMapTreeNode::pointer&, bool modify);
|
||||
void trackNewNode(SHAMapTreeNode::pointer&);
|
||||
|
||||
@@ -395,16 +396,16 @@ public:
|
||||
bool addGiveItem(SHAMapItem::ref, bool isTransaction, bool hasMeta);
|
||||
|
||||
// save a copy if you only need a temporary
|
||||
SHAMapItem::pointer peekItem(const uint256& id);
|
||||
SHAMapItem::pointer peekItem(const uint256& id, SHAMapTreeNode::TNType& type);
|
||||
SHAMapItem::ref peekItem(const uint256& id);
|
||||
SHAMapItem::ref peekItem(const uint256& id, SHAMapTreeNode::TNType& type);
|
||||
|
||||
// traverse functions
|
||||
SHAMapItem::pointer peekFirstItem();
|
||||
SHAMapItem::pointer peekFirstItem(SHAMapTreeNode::TNType& type);
|
||||
SHAMapItem::pointer peekLastItem();
|
||||
SHAMapItem::pointer peekNextItem(const uint256&);
|
||||
SHAMapItem::pointer peekNextItem(const uint256&, SHAMapTreeNode::TNType& type);
|
||||
SHAMapItem::pointer peekPrevItem(const uint256&);
|
||||
SHAMapItem::ref peekFirstItem();
|
||||
SHAMapItem::ref peekFirstItem(SHAMapTreeNode::TNType& type);
|
||||
SHAMapItem::ref peekLastItem();
|
||||
SHAMapItem::ref peekNextItem(const uint256&);
|
||||
SHAMapItem::ref peekNextItem(const uint256&, SHAMapTreeNode::TNType& type);
|
||||
SHAMapItem::ref peekPrevItem(const uint256&);
|
||||
|
||||
// comparison/sync functions
|
||||
void getMissingNodes(std::vector<SHAMapNode>& nodeIDs, std::vector<uint256>& hashes, int max,
|
||||
|
||||
@@ -173,8 +173,8 @@ void SHAMapNode::dump() const
|
||||
Log(lsDEBUG) << getString();
|
||||
}
|
||||
|
||||
SHAMapTreeNode::SHAMapTreeNode(uint32 seq, const SHAMapNode& nodeID) : SHAMapNode(nodeID), mHash(0), mSeq(seq),
|
||||
mType(tnERROR), mFullBelow(false)
|
||||
SHAMapTreeNode::SHAMapTreeNode(uint32 seq, const SHAMapNode& nodeID) : SHAMapNode(nodeID), mHash(0),
|
||||
mSeq(seq), mAccessSeq(seq), mType(tnERROR), mFullBelow(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
@@ -141,10 +141,12 @@ public:
|
||||
boost::shared_ptr< WSConnection<endpoint_type> > conn;
|
||||
{
|
||||
boost::mutex::scoped_lock sl(mMapLock);
|
||||
conn = mMap[cpClient];
|
||||
typedef boost::shared_ptr< WSConnection<endpoint_type> > wsc_ptr;
|
||||
typename boost::unordered_map<connection_ptr, wsc_ptr>::iterator it = mMap.find(cpClient);
|
||||
if (it == mMap.end())
|
||||
return;
|
||||
conn = it->second;
|
||||
}
|
||||
if (!conn)
|
||||
return;
|
||||
send(cpClient, conn->invokeCommand(jvRequest));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,7 +51,10 @@ public:
|
||||
boost::asio::io_service& get_io_service() {
|
||||
return m_io_service;
|
||||
}
|
||||
|
||||
|
||||
static void handle_shutdown(tls_socket_ptr, const boost::system::error_code&) {
|
||||
}
|
||||
|
||||
// should be private friended?
|
||||
tls_socket::handshake_type get_handshake_type() {
|
||||
if (static_cast< endpoint_type* >(this)->is_server()) {
|
||||
@@ -137,7 +140,13 @@ public:
|
||||
bool shutdown() {
|
||||
boost::system::error_code ignored_ec;
|
||||
|
||||
m_socket_ptr->shutdown(ignored_ec);
|
||||
m_socket_ptr->async_shutdown( // Don't block on connection shutdown DJS
|
||||
boost::bind(
|
||||
&tls<endpoint_type>::handle_shutdown,
|
||||
m_socket_ptr,
|
||||
boost::asio::placeholders::error
|
||||
)
|
||||
);
|
||||
|
||||
if (ignored_ec) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user