From 0efeedffdcd77ce39643a2222ca1f04a150ee564 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 15 May 2012 17:37:57 -0700 Subject: [PATCH 1/7] Cleanups. --- src/SHAMap.cpp | 12 ++++++------ src/TransactionEngine.cpp | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/SHAMap.cpp b/src/SHAMap.cpp index 4dbff7f95..45425efcc 100644 --- a/src/SHAMap.cpp +++ b/src/SHAMap.cpp @@ -111,7 +111,7 @@ SHAMapTreeNode::pointer SHAMap::getNode(const SHAMapNode& id, const uint256& has SHAMapTreeNode::pointer node = checkCacheNode(id); if (node) { - if (node->getNodeHash()!=hash) + if (node->getNodeHash() != hash) { #ifdef DEBUG std::cerr << "Attempt to get node, hash not in tree" << std::endl; @@ -127,7 +127,7 @@ SHAMapTreeNode::pointer SHAMap::getNode(const SHAMapNode& id, const uint256& has } std::vector nodeData; - if(!fetchNode(hash, nodeData)) return SHAMapTreeNode::pointer(); + if (!fetchNode(hash, nodeData)) return SHAMapTreeNode::pointer(); node = boost::make_shared(id, nodeData, mSeq); if (node->getNodeHash() != hash) throw SHAMapException(InvalidNode); @@ -344,10 +344,10 @@ SHAMapItem::pointer SHAMap::peekItem(const uint256& id) bool SHAMap::hasItem(const uint256& id) { // does the tree have an item with this ID boost::recursive_mutex::scoped_lock sl(mLock); - SHAMapTreeNode::pointer leaf=walkTo(id, false); - if(!leaf) return false; - SHAMapItem::pointer item=leaf->peekItem(); - if(!item || item->getTag()!=id) return false; + SHAMapTreeNode::pointer leaf = walkTo(id, false); + if (!leaf) return false; + SHAMapItem::pointer item = leaf->peekItem(); + if (!item || item->getTag() != id) return false; return true; } diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index 3f8490e4b..dd300e5bf 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -189,7 +189,7 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran if (result == terSUCCESS) { // Write back the account states and add the transaction to the ledger // WRITEME: Special case code for changing transaction key - for (std::vector::iterator it=accounts.begin(), end=accounts.end(); + for (std::vector::iterator it = accounts.begin(), end = accounts.end(); it != end; ++it) { if (it->first == taaCREATE) From c19994e6df14953cd3171a53020d82e18e1b01dd Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 15 May 2012 17:47:47 -0700 Subject: [PATCH 2/7] Don't truncate account state indexes. --- src/SHAMapNodes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SHAMapNodes.cpp b/src/SHAMapNodes.cpp index 25f7133d5..6bb3ceee8 100644 --- a/src/SHAMapNodes.cpp +++ b/src/SHAMapNodes.cpp @@ -278,7 +278,7 @@ bool SHAMapTreeNode::updateHash() { Serializer s; mItem->addRaw(s); - s.add160(mItem->getTag().to160()); + s.add256(mItem->getTag()); nh = s.getSHA512Half(); } else if (mType == tnTRANSACTION) From 32f3c7049fa922dc61cc229da340af5954bba447 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 15 May 2012 18:09:45 -0700 Subject: [PATCH 3/7] Part of the bug. Return value from setItem was incorrect. --- src/SHAMapNodes.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SHAMapNodes.cpp b/src/SHAMapNodes.cpp index 6bb3ceee8..badd100ad 100644 --- a/src/SHAMapNodes.cpp +++ b/src/SHAMapNodes.cpp @@ -299,7 +299,7 @@ bool SHAMapTreeNode::setItem(SHAMapItem::pointer& i, TNType type) mItem = i; assert(isLeaf()); updateHash(); - return getNodeHash() == hash; + return getNodeHash() != hash; } SHAMapItem::pointer SHAMapTreeNode::getItem() const From 169da7d5e8167f3d7883a85ff5074cf3610b5acd Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 15 May 2012 18:10:44 -0700 Subject: [PATCH 4/7] Cosmetic changes. --- src/SHAMap.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SHAMap.cpp b/src/SHAMap.cpp index 45425efcc..a307d2943 100644 --- a/src/SHAMap.cpp +++ b/src/SHAMap.cpp @@ -140,7 +140,7 @@ SHAMapTreeNode::pointer SHAMap::getNode(const SHAMapNode& id, const uint256& has void SHAMap::returnNode(SHAMapTreeNode::pointer& node, bool modify) { // make sure the node is suitable for the intended operation (copy on write) assert(node->isValid()); - if (node && modify && (node->getSeq()!=mSeq)) + if (node && modify && (node->getSeq() != mSeq)) { #ifdef DEBUG std::cerr << "returnNode COW" << std::endl; @@ -516,17 +516,17 @@ bool SHAMap::addItem(const SHAMapItem& i, bool isTransaction) bool SHAMap::updateGiveItem(SHAMapItem::pointer item, bool isTransaction) { // can't change the tag but can change the hash - uint256 tag=item->getTag(); + uint256 tag = item->getTag(); boost::recursive_mutex::scoped_lock sl(mLock); std::stack stack = getStack(tag, true); if (stack.empty()) throw SHAMapException(MissingNode); - SHAMapTreeNode::pointer node=stack.top(); + SHAMapTreeNode::pointer node = stack.top(); stack.pop(); - if (!node->isLeaf() || (node->peekItem()->getTag() != tag) ) + if (!node->isLeaf() || (node->peekItem()->getTag() != tag)) { assert(false); return false; From 4ad353203789c1d057fa0f62e4c02a5821fbe64f Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 15 May 2012 18:13:59 -0700 Subject: [PATCH 5/7] Cosmetic changes. --- src/SHAMap.cpp | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/src/SHAMap.cpp b/src/SHAMap.cpp index a307d2943..9c2eea361 100644 --- a/src/SHAMap.cpp +++ b/src/SHAMap.cpp @@ -430,16 +430,13 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction) boost::recursive_mutex::scoped_lock sl(mLock); std::stack stack=getStack(tag, true); - if(stack.empty()) throw SHAMapException(MissingNode); + if (stack.empty()) throw SHAMapException(MissingNode); SHAMapTreeNode::pointer node=stack.top(); stack.pop(); - if( node->isLeaf() && (node->peekItem()->getTag()==tag) ) - { - std::cerr << "addGiveItem ends on leaf with same tag" << std::endl; - return false; - } + if (node->isLeaf() && (node->peekItem()->getTag() == tag)) + throw std::runtime_error("addGiveItem ends on leaf with same tag"); uint256 prevHash; returnNode(node, true); @@ -449,9 +446,9 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction) #ifdef ST_DEBUG std::cerr << "aGI inner " << node->getString() << std::endl; #endif - int branch=node->selectBranch(tag); + int branch = node->selectBranch(tag); assert(node->isEmptyBranch(branch)); - SHAMapTreeNode::pointer newNode= + SHAMapTreeNode::pointer newNode = boost::make_shared(node->getChildNodeID(branch), item, type, mSeq); if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second) { @@ -467,14 +464,14 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction) #ifdef ST_DEBUG std::cerr << "aGI leaf " << node->getString() << std::endl; #endif - SHAMapItem::pointer otherItem=node->peekItem(); - assert(otherItem && (tag!=otherItem->getTag()) ); + SHAMapItem::pointer otherItem = node->peekItem(); + assert(otherItem && (tag != otherItem->getTag()) ); node->makeInner(); int b1, b2; - while( (b1=node->selectBranch(tag)) == (b2=node->selectBranch(otherItem->getTag())) ) + while ((b1 = node->selectBranch(tag)) == (b2 = node->selectBranch(otherItem->getTag()))) { // we need a new inner node, since both go on same branch at this level #ifdef ST_DEBUG std::cerr << "need new inner node at " << node->getDepth() << std::endl; @@ -484,26 +481,26 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction) if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second) assert(false); stack.push(node); - node=newNode; + node = newNode; } // we can add the two leaf nodes here assert(node->isInner()); - SHAMapTreeNode::pointer newNode= + SHAMapTreeNode::pointer newNode = boost::make_shared(node->getChildNodeID(b1), item, type, mSeq); assert(newNode->isValid() && newNode->isLeaf()); - if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second) + if (!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second) assert(false); node->setChildHash(b1, newNode->getNodeHash()); // OPTIMIZEME hash op not needed - newNode=boost::make_shared(node->getChildNodeID(b2), otherItem, type, mSeq); + newNode = boost::make_shared(node->getChildNodeID(b2), otherItem, type, mSeq); assert(newNode->isValid() && newNode->isLeaf()); if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second) assert(false); node->setChildHash(b2, newNode->getNodeHash()); } - prevHash=node->getNodeHash(); + prevHash = node->getNodeHash(); assert(prevHash.isNonZero()); dirtyUp(stack, tag, prevHash); return true; @@ -534,7 +531,7 @@ bool SHAMap::updateGiveItem(SHAMapItem::pointer item, bool isTransaction) returnNode(node, true); if (!node->setItem(item, isTransaction ? SHAMapTreeNode::tnTRANSACTION : SHAMapTreeNode::tnACCOUNT_STATE)) - return true; + return false; dirtyUp(stack, tag, node->getNodeHash()); return true; From 27851257d1df33f35674d75e6de5d4635e96bd49 Mon Sep 17 00:00:00 2001 From: jed Date: Tue, 15 May 2012 18:16:43 -0700 Subject: [PATCH 6/7] . --- newcoin.vcxproj | 2 +- src/RPCServer.cpp | 2 +- src/main.cpp | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/newcoin.vcxproj b/newcoin.vcxproj index da9d0d013..6cb762b94 100644 --- a/newcoin.vcxproj +++ b/newcoin.vcxproj @@ -48,7 +48,7 @@ NotUsing Level3 Disabled - BOOST_TEST_NO_MAIN;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=0x0501;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + BOOST_TEST_ALTERNATIVE_INIT_API;BOOST_TEST_NO_MAIN;_CRT_SECURE_NO_WARNINGS;_WIN32_WINNT=0x0501;WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) ..\OpenSSL\include;..\boost_1_47_0;..\protobuf-2.4.1\src\ diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index b0a7536c0..22c4b71e8 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -557,7 +557,7 @@ Json::Value RPCServer::doLedger(Json::Value& params) int paramCount = getParamCount(params); - if (paramCount == 0); + if (paramCount == 0) { Json::Value ret(Json::objectValue), current(Json::objectValue), closed(Json::objectValue); theApp->getMasterLedger().getCurrentLedger()->addJson(current); diff --git a/src/main.cpp b/src/main.cpp index 489e0b733..95181c49d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -70,10 +70,10 @@ int main(int argc, char* argv[]) ("help,h", "Display this message.") ("rpc", "Perform rpc command (default).") ("test,t", "Perform unit tests.") - ("parameters", po::value< vector >(), "Specify comma seperated parameters.") + ("parameters", po::value< vector >(), "Specify comma separated parameters.") ; - // Interpert positional arguments as --parameters. + // Interpret positional arguments as --parameters. po::positional_options_description p; p.add("parameters", -1); @@ -124,7 +124,7 @@ int main(int argc, char* argv[]) pvCmd.push_back(const_cast(param.c_str())); } -// iResult = unit_test_main(init_unit_test, iCmd, &pvCmd[0]); + iResult = unit_test_main(init_unit_test, iCmd, &pvCmd[0]); } else if (!vm.count("parameters")) { From 98d273370610d5b836d862bdc3e6070f8c4cacc8 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 15 May 2012 18:20:07 -0700 Subject: [PATCH 7/7] Cosmetic changes. --- src/SHAMap.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/SHAMap.cpp b/src/SHAMap.cpp index 9c2eea361..c0f6b21f7 100644 --- a/src/SHAMap.cpp +++ b/src/SHAMap.cpp @@ -56,7 +56,7 @@ void SHAMap::dirtyUp(std::stack& stack, const uint256& while (!stack.empty()) { - SHAMapTreeNode::pointer node=stack.top(); + SHAMapTreeNode::pointer node = stack.top(); stack.pop(); assert(node->isInnerNode()); @@ -424,12 +424,12 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction) std::cerr << "aGI " << item->getTag().GetHex() << std::endl; #endif - uint256 tag=item->getTag(); - SHAMapTreeNode::TNType type=isTransaction ? SHAMapTreeNode::tnTRANSACTION : SHAMapTreeNode::tnACCOUNT_STATE; + uint256 tag = item->getTag(); + SHAMapTreeNode::TNType type = isTransaction ? SHAMapTreeNode::tnTRANSACTION : SHAMapTreeNode::tnACCOUNT_STATE; boost::recursive_mutex::scoped_lock sl(mLock); - std::stack stack=getStack(tag, true); + std::stack stack = getStack(tag, true); if (stack.empty()) throw SHAMapException(MissingNode); SHAMapTreeNode::pointer node=stack.top(); @@ -476,7 +476,8 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction) #ifdef ST_DEBUG std::cerr << "need new inner node at " << node->getDepth() << std::endl; #endif - SHAMapTreeNode::pointer newNode=boost::make_shared(node->getChildNodeID(b1), mSeq); + SHAMapTreeNode::pointer newNode = + boost::make_shared(node->getChildNodeID(b1), mSeq); newNode->makeInner(); if(!mTNByID.insert(std::make_pair(SHAMapNode(*newNode), newNode)).second) assert(false); @@ -500,9 +501,7 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction) node->setChildHash(b2, newNode->getNodeHash()); } - prevHash = node->getNodeHash(); - assert(prevHash.isNonZero()); - dirtyUp(stack, tag, prevHash); + dirtyUp(stack, tag, node->getNodeHash()); return true; }