mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-02 08:55:53 +00:00
Track the type of map in the SHAMap. This will make it easier to parse missing nodes
at ledger level.
This commit is contained in:
@@ -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<AccountState>(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<SHAMap>(mTransHash);
|
||||
mAccountStateMap = boost::make_shared<SHAMap>(mAccountHash);
|
||||
mTransactionMap = boost::make_shared<SHAMap>(smtTRANSACTION, mTransHash);
|
||||
mAccountStateMap = boost::make_shared<SHAMap>(smtSTATE, mAccountHash);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ SETUP_LOG();
|
||||
|
||||
TransactionAcquire::TransactionAcquire(const uint256& hash) : PeerSet(hash, TX_ACQUIRE_TIMEOUT), mHaveRoot(false)
|
||||
{
|
||||
mMap = boost::make_shared<SHAMap>(hash);
|
||||
mMap = boost::make_shared<SHAMap>(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>();
|
||||
SHAMap::pointer empty = boost::make_shared<SHAMap>(smtTRANSACTION);
|
||||
mapComplete(hash, empty, false);
|
||||
return empty;
|
||||
}
|
||||
|
||||
@@ -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<SHAMapTreeNode>(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<SHAMapTreeNode>(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>();
|
||||
SHAMap::pointer ret = boost::make_shared<SHAMap>(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");
|
||||
|
||||
13
src/SHAMap.h
13
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<SHAMapTreeNode::pointer>& 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; }
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user