From 5bc6adcd649e19bf854790b7fca7e28e9c7c2bf9 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 15 May 2012 17:18:17 -0700 Subject: [PATCH 1/6] I broke it! --- src/SerializedObject.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SerializedObject.cpp b/src/SerializedObject.cpp index 7d1ed46803..aef0f9cf75 100644 --- a/src/SerializedObject.cpp +++ b/src/SerializedObject.cpp @@ -117,7 +117,7 @@ STObject::STObject(SOElement* elem, SerializerIterator& sit, const char *name) : if ((flags&elem->e_flags) == 0) { done = true; - giveObject(makeDefaultObject(elem->e_id, elem->e_name)); + giveObject(makeDefaultObject(STI_NOTPRESENT, elem->e_name)); } } else if (elem->e_type == SOE_IFNFLAG) @@ -126,7 +126,7 @@ STObject::STObject(SOElement* elem, SerializerIterator& sit, const char *name) : if ((flags&elem->e_flags) != 0) { done = true; - giveObject(makeDefaultObject(STI_NOTPRESENT, elem->e_name)); + giveObject(makeDefaultObject(elem->e_id, elem->e_name)); } } else if (elem->e_type == SOE_FLAGS) From 64616ec94577d3e65d8b232729695bfbff09c96f Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 15 May 2012 17:32:18 -0700 Subject: [PATCH 2/6] Bugfixes. --- src/Ledger.h | 14 +++++++------- src/TransactionEngine.cpp | 11 ++++++----- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Ledger.h b/src/Ledger.h index 4d9b5fb614..4d330c9648 100644 --- a/src/Ledger.h +++ b/src/Ledger.h @@ -18,17 +18,17 @@ enum LedgerStateParms { - lepNONE = 0, // no special flags + lepNONE = 0, // no special flags // input flags - lepCREATE, // Create if not present + lepCREATE = 1, // Create if not present // output flags - lepOKAY, // success - lepMISSING, // No node in that slot - lepWRONGTYPE, // Node of different type there - lepCREATED, // Node was created - lepERROR, // error + lepOKAY = 2, // success + lepMISSING = 4, // No node in that slot + lepWRONGTYPE = 8, // Node of different type there + lepCREATED = 16, // Node was created + lepERROR = 32, // error }; class Ledger : public boost::enable_shared_from_this diff --git a/src/TransactionEngine.cpp b/src/TransactionEngine.cpp index aba6aa276b..3f8490e4b0 100644 --- a/src/TransactionEngine.cpp +++ b/src/TransactionEngine.cpp @@ -191,12 +191,13 @@ TransactionEngineResult TransactionEngine::applyTransaction(const SerializedTran // WRITEME: Special case code for changing transaction key for (std::vector::iterator it=accounts.begin(), end=accounts.end(); it != end; ++it) - { if (it->first == taaCREATE) + { + if (it->first == taaCREATE) { if (mLedger->writeBack(lepCREATE, it->second) & lepERROR) assert(false); } - else if (it->first==taaMODIFY) + else if (it->first == taaMODIFY) { if (mLedger->writeBack(lepNONE, it->second) & lepERROR) assert(false); @@ -235,7 +236,7 @@ TransactionEngineResult TransactionEngine::doClaim(const SerializedTransaction& } LedgerStateParms qry = lepNONE; - SerializedLedgerEntry::pointer dest = mLedger->getAccountRoot(qry, sourceAccountID); + SerializedLedgerEntry::pointer dest = accounts[0].second; if (!dest) { @@ -265,8 +266,6 @@ TransactionEngineResult TransactionEngine::doClaim(const SerializedTransaction& // Set the public key needed to use the account. dest->setIFieldH160(sfAuthorizedKey, hGeneratorID); - accounts.push_back(std::make_pair(taaMODIFY, dest)); - // Construct a generator map entry. gen = boost::make_shared(ltGENERATOR_MAP); @@ -289,6 +288,8 @@ TransactionEngineResult TransactionEngine::doPayment(const SerializedTransaction // Does the destination account exist? if (!destAccount) return tenINVALID; LedgerStateParms qry = lepNONE; + + // FIXME: If this transfer is to the same account, bad things will happen SerializedLedgerEntry::pointer dest = mLedger->getAccountRoot(qry, destAccount); if (!dest) { // can this transaction create an account From 0efeedffdcd77ce39643a2222ca1f04a150ee564 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Tue, 15 May 2012 17:37:57 -0700 Subject: [PATCH 3/6] 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 4dbff7f955..45425efcc8 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 3f8490e4b0..dd300e5bfe 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 4/6] 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 25f7133d57..6bb3ceee82 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 5/6] 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 6bb3ceee82..badd100ad6 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 6/6] Cosmetic changes. --- src/SHAMap.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/SHAMap.cpp b/src/SHAMap.cpp index 45425efcc8..a307d2943f 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;