diff --git a/src/Ledger.cpp b/src/Ledger.cpp index f52e1f1e7..35ffc7dcf 100644 --- a/src/Ledger.cpp +++ b/src/Ledger.cpp @@ -24,7 +24,7 @@ SETUP_LOG(); Ledger::Ledger(const NewcoinAddress& masterID, uint64 startAmount) : mTotCoins(startAmount), mLedgerSeq(1), mCloseTime(0), mParentCloseTime(0), mCloseResolution(LEDGER_TIME_ACCURACY), mCloseFlags(0), mClosed(false), mValidHash(false), mAccepted(false), mImmutable(false), - mTransactionMap(new SHAMap()), mAccountStateMap(new SHAMap()) + mTransactionMap(new SHAMap(smtTRANSACTION)), mAccountStateMap(new SHAMap(smtFREE)) { // special case: put coins in root account AccountState::pointer startAccount = boost::make_shared(masterID); @@ -62,7 +62,7 @@ Ledger::Ledger(bool /* dummy */, Ledger& prevLedger) : mTotCoins(prevLedger.mTotCoins), mLedgerSeq(prevLedger.mLedgerSeq + 1), mParentCloseTime(prevLedger.mCloseTime), mCloseResolution(prevLedger.mCloseResolution), mCloseFlags(0), mClosed(false), mValidHash(false), mAccepted(false), mImmutable(false), - mTransactionMap(new SHAMap()), mAccountStateMap(prevLedger.mAccountStateMap->snapShot(true)) + mTransactionMap(new SHAMap(smtTRANSACTION)), mAccountStateMap(prevLedger.mAccountStateMap->snapShot(true)) { // Create a new ledger that follows this one prevLedger.updateHash(); mParentHash = prevLedger.getHash(); @@ -123,8 +123,8 @@ void Ledger::setRaw(const Serializer &s) updateHash(); if(mValidHash) { - mTransactionMap = boost::make_shared(mTransHash); - mAccountStateMap = boost::make_shared(mAccountHash); + mTransactionMap = boost::make_shared(smtTRANSACTION, mTransHash); + mAccountStateMap = boost::make_shared(smtSTATE, mAccountHash); } } diff --git a/src/LedgerConsensus.cpp b/src/LedgerConsensus.cpp index a07965ae6..c915faad7 100644 --- a/src/LedgerConsensus.cpp +++ b/src/LedgerConsensus.cpp @@ -27,7 +27,7 @@ SETUP_LOG(); TransactionAcquire::TransactionAcquire(const uint256& hash) : PeerSet(hash, TX_ACQUIRE_TIMEOUT), mHaveRoot(false) { - mMap = boost::make_shared(hash); + mMap = boost::make_shared(smtTRANSACTION, hash); } void TransactionAcquire::done() @@ -759,7 +759,7 @@ SHAMap::pointer LedgerConsensus::getTransactionTree(const uint256& hash, bool do { if (!hash) { - SHAMap::pointer empty = boost::make_shared(); + SHAMap::pointer empty = boost::make_shared(smtTRANSACTION); mapComplete(hash, empty, false); return empty; } diff --git a/src/SHAMap.cpp b/src/SHAMap.cpp index 533b9d671..97580186e 100644 --- a/src/SHAMap.cpp +++ b/src/SHAMap.cpp @@ -41,14 +41,14 @@ std::size_t hash_value(const uint160& u) } -SHAMap::SHAMap(uint32 seq) : mSeq(seq), mState(smsModifying) +SHAMap::SHAMap(SHAMapType t, uint32 seq) : mSeq(seq), mState(smsModifying), mType(t) { root = boost::make_shared(mSeq, SHAMapNode(0, uint256())); root->makeInner(); mTNByID[*root] = root; } -SHAMap::SHAMap(const uint256& hash) : mSeq(0), mState(smsSynching) +SHAMap::SHAMap(SHAMapType t, const uint256& hash) : mSeq(0), mState(smsSynching), mType(t) { // FIXME: Need to acquire root node root = boost::make_shared(mSeq, SHAMapNode(0, uint256())); root->makeInner(); @@ -58,7 +58,7 @@ SHAMap::SHAMap(const uint256& hash) : mSeq(0), mState(smsSynching) SHAMap::pointer SHAMap::snapShot(bool isMutable) { // Return a new SHAMap that is an immutable snapshot of this one // Initially nodes are shared, but CoW is forced on both ledgers - SHAMap::pointer ret = boost::make_shared(); + SHAMap::pointer ret = boost::make_shared(mType); SHAMap& newMap = *ret; newMap.mSeq = ++mSeq; newMap.mTNByID = mTNByID; @@ -808,7 +808,7 @@ BOOST_AUTO_TEST_CASE( SHAMap_test ) h4.SetHex("b92891fe4ef6cee585fdc6fda2e09eb4d386363158ec3321b8123e5a772c6ca8"); h5.SetHex("a92891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7"); - SHAMap sMap; + SHAMap sMap(smtFREE); SHAMapItem i1(h1, IntToVUC(1)), i2(h2, IntToVUC(2)), i3(h3, IntToVUC(3)), i4(h4, IntToVUC(4)), i5(h5, IntToVUC(5)); if (!sMap.addItem(i2, true, false)) BOOST_FAIL("no add"); diff --git a/src/SHAMap.h b/src/SHAMap.h index a942943b1..11c34a74d 100644 --- a/src/SHAMap.h +++ b/src/SHAMap.h @@ -128,6 +128,13 @@ enum SHANodeFormat snfWIRE = 2, // Compressed form used on the wire }; +enum SHAMapType +{ + smtTRANSACTION =1, // A tree of transactions + smtSTATE =2, // A tree of state nodes + smtFREE =3, // A tree not part of a ledger +}; + class SHAMapTreeNode : public SHAMapNode { friend class SHAMap; @@ -282,6 +289,8 @@ private: SHAMapState mState; + SHAMapType mType; + protected: void dirtyUp(std::stack& stack, const uint256& target, uint256 prevHash); @@ -306,8 +315,8 @@ protected: public: // build new map - SHAMap(uint32 seq = 0); - SHAMap(const uint256& hash); + SHAMap(SHAMapType t, uint32 seq = 0); + SHAMap(SHAMapType t, const uint256& hash); ~SHAMap() { mState = smsInvalid; } diff --git a/src/SHAMapSync.cpp b/src/SHAMapSync.cpp index baf7de950..7fdfac494 100644 --- a/src/SHAMapSync.cpp +++ b/src/SHAMapSync.cpp @@ -421,7 +421,7 @@ BOOST_AUTO_TEST_CASE( SHAMapSync_test ) srand(seed); cLog(lsTRACE) << "Constructing maps"; - SHAMap source, destination; + SHAMap source(smtFREE), destination(smtFREE); // add random data to the source map cLog(lsTRACE) << "Adding random data";