mirror of
https://github.com/Xahau/xahaud.git
synced 2025-11-20 10:35:50 +00:00
Part of the 'tray' implementation to avoid a burst of load on ledger close
This commit is contained in:
15
SHAMap.cpp
15
SHAMap.cpp
@@ -12,12 +12,14 @@ SHAMap::SHAMap(int leafDataSize, int leafDataOffset) : mLeafDataSize(leafDataSiz
|
|||||||
void SHAMap::dirtyUp(const uint256& id, const std::vector<SHAMapInnerNode::pointer>& path)
|
void SHAMap::dirtyUp(const uint256& id, const std::vector<SHAMapInnerNode::pointer>& path)
|
||||||
{ // walk the tree up from through the inner nodes to the root
|
{ // walk the tree up from through the inner nodes to the root
|
||||||
// update linking hashes and add nodes to dirty list
|
// update linking hashes and add nodes to dirty list
|
||||||
|
if(mDirtyInnerNodes==NULL) return;
|
||||||
|
|
||||||
std::vector<SHAMapInnerNode::pointer>::const_reverse_iterator it;
|
std::vector<SHAMapInnerNode::pointer>::const_reverse_iterator it;
|
||||||
|
|
||||||
it = path.rbegin();
|
it = path.rbegin();
|
||||||
if(it == path.rend()) return;
|
if(it == path.rend()) return;
|
||||||
|
|
||||||
mDirtyInnerNodes[**it]=*it;
|
(*mDirtyInnerNodes)[**it]=*it;
|
||||||
uint256 hVal=(*it)->getNodeHash();
|
uint256 hVal=(*it)->getNodeHash();
|
||||||
if(hVal==0)
|
if(hVal==0)
|
||||||
mInnerNodeByID.erase(**it);
|
mInnerNodeByID.erase(**it);
|
||||||
@@ -26,7 +28,7 @@ void SHAMap::dirtyUp(const uint256& id, const std::vector<SHAMapInnerNode::point
|
|||||||
{
|
{
|
||||||
if(!(*it)->setChildHash((*it)->selectBranch(id), hVal))
|
if(!(*it)->setChildHash((*it)->selectBranch(id), hVal))
|
||||||
return;
|
return;
|
||||||
mDirtyInnerNodes[**it]=*it;
|
(*mDirtyInnerNodes)[**it]=*it;
|
||||||
hVal = (*it)->getNodeHash();
|
hVal = (*it)->getNodeHash();
|
||||||
if(hVal == 0) mInnerNodeByID.erase(**it);
|
if(hVal == 0) mInnerNodeByID.erase(**it);
|
||||||
}
|
}
|
||||||
@@ -132,11 +134,6 @@ SHAMapInnerNode::pointer SHAMap::getInner(const SHAMapNode &id, const uint256& h
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
SHAMapItem::SHAMapItem(const uint256& tag) : mTag(tag)
|
|
||||||
{
|
|
||||||
mData.insert(mData.end(), tag.begin(), tag.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
SHAMapItem::SHAMapItem(const uint256& tag, const std::vector<unsigned char>& data) : mTag(tag), mData(data)
|
SHAMapItem::SHAMapItem(const uint256& tag, const std::vector<unsigned char>& data) : mTag(tag), mData(data)
|
||||||
{ ; }
|
{ ; }
|
||||||
|
|
||||||
@@ -300,7 +297,7 @@ void SHAMap::dump()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TestSHAMap()
|
bool SHAMap::TestSHAMap()
|
||||||
{
|
{
|
||||||
uint256 h1, h2, h3, h4, h5;
|
uint256 h1, h2, h3, h4, h5;
|
||||||
h1.SetHex("436ccbac3347baa1f1e53baeef1f43334da88f1f6d70d963b833afd6dfa289fe");
|
h1.SetHex("436ccbac3347baa1f1e53baeef1f43334da88f1f6d70d963b833afd6dfa289fe");
|
||||||
@@ -310,7 +307,7 @@ void TestSHAMap()
|
|||||||
h5.SetHex("092891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
|
h5.SetHex("092891fe4ef6cee585fdc6fda0e09eb4d386363158ec3321b8123e5a772c6ca7");
|
||||||
|
|
||||||
SHAMap sMap(32);
|
SHAMap sMap(32);
|
||||||
SHAMapItem i1(h1), i2(h2), i3(h3), i4(h4), i5(h5);
|
// SHAMapItem i1(h1), i2(h2), i3(h3), i4(h4), i5(h5);
|
||||||
|
|
||||||
sMap.dump();
|
sMap.dump();
|
||||||
}
|
}
|
||||||
|
|||||||
12
SHAMap.h
12
SHAMap.h
@@ -69,10 +69,14 @@ private:
|
|||||||
std::vector<unsigned char> mData;
|
std::vector<unsigned char> mData;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SHAMapItem(const uint256& tag); // tag is data
|
|
||||||
|
// for transactions
|
||||||
SHAMapItem(const uint256& tag, const std::vector<unsigned char>& data);
|
SHAMapItem(const uint256& tag, const std::vector<unsigned char>& data);
|
||||||
SHAMapItem(const std::vector<unsigned char>& data); // tag by hash
|
SHAMapItem(const std::vector<unsigned char>& data); // tag by hash
|
||||||
|
|
||||||
|
// for account balances
|
||||||
|
SHAMapItem(const uint160& tag, const std::vector<unsigned char>& data);
|
||||||
|
|
||||||
const uint256& getTag(void) const { return mTag; }
|
const uint256& getTag(void) const { return mTag; }
|
||||||
std::vector<unsigned char> getData(void) const { return mData; }
|
std::vector<unsigned char> getData(void) const { return mData; }
|
||||||
const std::vector<unsigned char>& peekData(void) const { return mData; }
|
const std::vector<unsigned char>& peekData(void) const { return mData; }
|
||||||
@@ -169,12 +173,12 @@ public:
|
|||||||
typedef boost::shared_ptr<SHAMap> pointer;
|
typedef boost::shared_ptr<SHAMap> pointer;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int mLeafDataSize, mLeafDataOffset;
|
int mLeafDataSize, mLeafDataOffset, mSeq;
|
||||||
mutable boost::recursive_mutex mLock;
|
mutable boost::recursive_mutex mLock;
|
||||||
std::map<SHAMapNode, SHAMapLeafNode::pointer> mLeafByID;
|
std::map<SHAMapNode, SHAMapLeafNode::pointer> mLeafByID;
|
||||||
std::map<SHAMapNode, SHAMapInnerNode::pointer> mInnerNodeByID;
|
std::map<SHAMapNode, SHAMapInnerNode::pointer> mInnerNodeByID;
|
||||||
std::map<SHAMapNode, SHAMapLeafNode::pointer> mDirtyLeafNodes;
|
boost::shared_ptr<std::map<SHAMapNode, SHAMapLeafNode::pointer> > mDirtyLeafNodes;
|
||||||
std::map<SHAMapNode, SHAMapInnerNode::pointer> mDirtyInnerNodes;
|
boost::shared_ptr<std::map<SHAMapNode, SHAMapInnerNode::pointer> > mDirtyInnerNodes;
|
||||||
|
|
||||||
SHAMapInnerNode::pointer root;
|
SHAMapInnerNode::pointer root;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user