mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Various cleanups.
This commit is contained in:
@@ -72,7 +72,7 @@ void LedgerAcquire::trigger(bool timer)
|
|||||||
std::vector<SHAMapNode> nodeIDs;
|
std::vector<SHAMapNode> nodeIDs;
|
||||||
std::vector<uint256> nodeHashes;
|
std::vector<uint256> nodeHashes;
|
||||||
mLedger->peekTransactionMap()->getMissingNodes(nodeIDs, nodeHashes, 128);
|
mLedger->peekTransactionMap()->getMissingNodes(nodeIDs, nodeHashes, 128);
|
||||||
if(!nodeIDs.size())
|
if(nodeIDs.empty())
|
||||||
{
|
{
|
||||||
if(!mLedger->peekTransactionMap()->isValid()) mFailed=true;
|
if(!mLedger->peekTransactionMap()->isValid()) mFailed=true;
|
||||||
else
|
else
|
||||||
@@ -111,7 +111,7 @@ void LedgerAcquire::trigger(bool timer)
|
|||||||
std::vector<SHAMapNode> nodeIDs;
|
std::vector<SHAMapNode> nodeIDs;
|
||||||
std::vector<uint256> nodeHashes;
|
std::vector<uint256> nodeHashes;
|
||||||
mLedger->peekAccountStateMap()->getMissingNodes(nodeIDs, nodeHashes, 128);
|
mLedger->peekAccountStateMap()->getMissingNodes(nodeIDs, nodeHashes, 128);
|
||||||
if(!nodeIDs.size())
|
if(nodeIDs.empty())
|
||||||
{
|
{
|
||||||
if(!mLedger->peekAccountStateMap()->isValid()) mFailed=true;
|
if(!mLedger->peekAccountStateMap()->isValid()) mFailed=true;
|
||||||
else
|
else
|
||||||
@@ -141,7 +141,8 @@ void LedgerAcquire::trigger(bool timer)
|
|||||||
|
|
||||||
void LedgerAcquire::sendRequest(boost::shared_ptr<newcoin::TMGetLedger> tmGL)
|
void LedgerAcquire::sendRequest(boost::shared_ptr<newcoin::TMGetLedger> tmGL)
|
||||||
{
|
{
|
||||||
if(!mPeers.size()) return;
|
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||||
|
if(mPeers.empty()) return;
|
||||||
|
|
||||||
PackedMessage::pointer packet=boost::make_shared<PackedMessage>(tmGL, newcoin::mtGET_LEDGER);
|
PackedMessage::pointer packet=boost::make_shared<PackedMessage>(tmGL, newcoin::mtGET_LEDGER);
|
||||||
|
|
||||||
@@ -151,7 +152,7 @@ void LedgerAcquire::sendRequest(boost::shared_ptr<newcoin::TMGetLedger> tmGL)
|
|||||||
if(it->expired())
|
if(it->expired())
|
||||||
mPeers.erase(it++);
|
mPeers.erase(it++);
|
||||||
else
|
else
|
||||||
{ // FIXME: Possible race if peer has error
|
{
|
||||||
// FIXME: Track last peer sent to and time sent
|
// FIXME: Track last peer sent to and time sent
|
||||||
it->lock()->sendPacket(packet);
|
it->lock()->sendPacket(packet);
|
||||||
return;
|
return;
|
||||||
@@ -252,17 +253,16 @@ LedgerAcquire::pointer LedgerAcquireMaster::findCreate(const uint256& hash)
|
|||||||
{
|
{
|
||||||
boost::mutex::scoped_lock sl(mLock);
|
boost::mutex::scoped_lock sl(mLock);
|
||||||
LedgerAcquire::pointer& ptr=mLedgers[hash];
|
LedgerAcquire::pointer& ptr=mLedgers[hash];
|
||||||
if(!ptr) ptr=LedgerAcquire::pointer(new LedgerAcquire(hash));
|
if(ptr) return ptr;
|
||||||
return ptr;
|
return boost::make_shared<LedgerAcquire>(hash);
|
||||||
}
|
}
|
||||||
|
|
||||||
LedgerAcquire::pointer LedgerAcquireMaster::find(const uint256& hash)
|
LedgerAcquire::pointer LedgerAcquireMaster::find(const uint256& hash)
|
||||||
{
|
{
|
||||||
LedgerAcquire::pointer ret;
|
|
||||||
boost::mutex::scoped_lock sl(mLock);
|
boost::mutex::scoped_lock sl(mLock);
|
||||||
std::map<uint256, LedgerAcquire::pointer>::iterator it=mLedgers.find(hash);
|
std::map<uint256, LedgerAcquire::pointer>::iterator it=mLedgers.find(hash);
|
||||||
if(it!=mLedgers.end()) ret=it->second;
|
if(it!=mLedgers.end()) return it->second;
|
||||||
return ret;
|
return LedgerAcquire::pointer();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LedgerAcquireMaster::hasLedger(const uint256& hash)
|
bool LedgerAcquireMaster::hasLedger(const uint256& hash)
|
||||||
|
|||||||
@@ -428,7 +428,7 @@ bool SHAMap::addGiveItem(SHAMapItem::pointer item, bool isTransaction)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint256 tag=item->getTag();
|
uint256 tag=item->getTag();
|
||||||
SHAMapTreeNode::TNType type=isTransaction ? SHAMapTreeNode::TRANSACTION : SHAMapTreeNode::ACCOUNT_STATE;
|
SHAMapTreeNode::TNType type=isTransaction ? SHAMapTreeNode::tnTRANSACTION : SHAMapTreeNode::tnACCOUNT_STATE;
|
||||||
|
|
||||||
boost::recursive_mutex::scoped_lock sl(mLock);
|
boost::recursive_mutex::scoped_lock sl(mLock);
|
||||||
|
|
||||||
@@ -533,7 +533,7 @@ bool SHAMap::updateGiveItem(SHAMapItem::pointer item, bool isTransaction)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
returnNode(node, true);
|
returnNode(node, true);
|
||||||
if(!node->setItem(item, isTransaction ? SHAMapTreeNode::TRANSACTION : SHAMapTreeNode::ACCOUNT_STATE))
|
if(!node->setItem(item, isTransaction ? SHAMapTreeNode::tnTRANSACTION : SHAMapTreeNode::tnACCOUNT_STATE))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
dirtyUp(stack, tag, node->getNodeHash());
|
dirtyUp(stack, tag, node->getNodeHash());
|
||||||
|
|||||||
18
SHAMap.h
18
SHAMap.h
@@ -134,10 +134,10 @@ public:
|
|||||||
|
|
||||||
enum TNType
|
enum TNType
|
||||||
{
|
{
|
||||||
ERROR =0,
|
tnERROR =0,
|
||||||
INNER =1,
|
tnINNER =1,
|
||||||
TRANSACTION =2,
|
tnTRANSACTION =2,
|
||||||
ACCOUNT_STATE =3
|
tnACCOUNT_STATE =3
|
||||||
};
|
};
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -171,11 +171,11 @@ public:
|
|||||||
TNType getType() const { return mType; }
|
TNType getType() const { return mType; }
|
||||||
|
|
||||||
// type functions
|
// type functions
|
||||||
bool isLeaf() const { return (mType==TRANSACTION) || (mType==ACCOUNT_STATE); }
|
bool isLeaf() const { return (mType==tnTRANSACTION) || (mType==tnACCOUNT_STATE); }
|
||||||
bool isInner() const { return mType==INNER; }
|
bool isInner() const { return mType==tnINNER; }
|
||||||
bool isValid() const { return mType!=ERROR; }
|
bool isValid() const { return mType!=tnERROR; }
|
||||||
bool isTransaction() const { return mType!=TRANSACTION; }
|
bool isTransaction() const { return mType!=tnTRANSACTION; }
|
||||||
bool isAccountState() const { return mType!=ACCOUNT_STATE; }
|
bool isAccountState() const { return mType!=tnACCOUNT_STATE; }
|
||||||
|
|
||||||
// inner node functions
|
// inner node functions
|
||||||
bool isInnerNode() const { return !mItem; }
|
bool isInnerNode() const { return !mItem; }
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ void SHAMapNode::dump() const
|
|||||||
}
|
}
|
||||||
|
|
||||||
SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& nodeID, uint32 seq) : SHAMapNode(nodeID), mHash(0), mSeq(seq),
|
SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& nodeID, uint32 seq) : SHAMapNode(nodeID), mHash(0), mSeq(seq),
|
||||||
mType(ERROR), mFullBelow(false)
|
mType(tnERROR), mFullBelow(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +177,7 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& node, SHAMapItem::pointer item,
|
|||||||
}
|
}
|
||||||
|
|
||||||
SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned char>& rawNode, uint32 seq)
|
SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned char>& rawNode, uint32 seq)
|
||||||
: SHAMapNode(id), mSeq(seq), mType(ERROR), mFullBelow(false)
|
: SHAMapNode(id), mSeq(seq), mType(tnERROR), mFullBelow(false)
|
||||||
{
|
{
|
||||||
Serializer s(rawNode);
|
Serializer s(rawNode);
|
||||||
|
|
||||||
@@ -188,7 +188,7 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned
|
|||||||
if(type==0)
|
if(type==0)
|
||||||
{ // transaction
|
{ // transaction
|
||||||
mItem=boost::make_shared<SHAMapItem>(s.getSHA512Half(), s.peekData());
|
mItem=boost::make_shared<SHAMapItem>(s.getSHA512Half(), s.peekData());
|
||||||
mType=TRANSACTION;
|
mType=tnTRANSACTION;
|
||||||
}
|
}
|
||||||
else if(type==1)
|
else if(type==1)
|
||||||
{ // account state
|
{ // account state
|
||||||
@@ -197,14 +197,14 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned
|
|||||||
s.chop(20);
|
s.chop(20);
|
||||||
if(u.isZero()) throw SHAMapException(InvalidNode);
|
if(u.isZero()) throw SHAMapException(InvalidNode);
|
||||||
mItem=boost::make_shared<SHAMapItem>(u, s.peekData());
|
mItem=boost::make_shared<SHAMapItem>(u, s.peekData());
|
||||||
mType=ACCOUNT_STATE;
|
mType=tnACCOUNT_STATE;
|
||||||
}
|
}
|
||||||
else if(type==2)
|
else if(type==2)
|
||||||
{ // full inner
|
{ // full inner
|
||||||
if(len!=512) throw SHAMapException(InvalidNode);
|
if(len!=512) throw SHAMapException(InvalidNode);
|
||||||
for(int i=0; i<16; i++)
|
for(int i=0; i<16; i++)
|
||||||
s.get256(mHashes[i], i*32);
|
s.get256(mHashes[i], i*32);
|
||||||
mType=INNER;
|
mType=tnINNER;
|
||||||
}
|
}
|
||||||
else if(type==3)
|
else if(type==3)
|
||||||
{ // compressed inner
|
{ // compressed inner
|
||||||
@@ -215,7 +215,7 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned
|
|||||||
if( (pos<0) || (pos>=16)) throw SHAMapException(InvalidNode);
|
if( (pos<0) || (pos>=16)) throw SHAMapException(InvalidNode);
|
||||||
s.get256(mHashes[pos], i*33);
|
s.get256(mHashes[pos], i*33);
|
||||||
}
|
}
|
||||||
mType=INNER;
|
mType=tnINNER;
|
||||||
}
|
}
|
||||||
|
|
||||||
updateHash();
|
updateHash();
|
||||||
@@ -223,9 +223,9 @@ SHAMapTreeNode::SHAMapTreeNode(const SHAMapNode& id, const std::vector<unsigned
|
|||||||
|
|
||||||
void SHAMapTreeNode::addRaw(Serializer &s)
|
void SHAMapTreeNode::addRaw(Serializer &s)
|
||||||
{
|
{
|
||||||
if(mType==ERROR) throw SHAMapException(InvalidNode);
|
if(mType==tnERROR) throw SHAMapException(InvalidNode);
|
||||||
|
|
||||||
if(mType==TRANSACTION)
|
if(mType==tnTRANSACTION)
|
||||||
{
|
{
|
||||||
mItem->addRaw(s);
|
mItem->addRaw(s);
|
||||||
s.add8(0);
|
s.add8(0);
|
||||||
@@ -233,7 +233,7 @@ void SHAMapTreeNode::addRaw(Serializer &s)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(mType==ACCOUNT_STATE)
|
if(mType==tnACCOUNT_STATE)
|
||||||
{
|
{
|
||||||
mItem->addRaw(s);
|
mItem->addRaw(s);
|
||||||
s.add160(mItem->getTag().to160());
|
s.add160(mItem->getTag().to160());
|
||||||
@@ -262,7 +262,7 @@ bool SHAMapTreeNode::updateHash()
|
|||||||
{
|
{
|
||||||
uint256 nh;
|
uint256 nh;
|
||||||
|
|
||||||
if(mType==INNER)
|
if(mType==tnINNER)
|
||||||
{
|
{
|
||||||
bool empty=true;
|
bool empty=true;
|
||||||
for(int i=0; i<16; i++)
|
for(int i=0; i<16; i++)
|
||||||
@@ -274,14 +274,14 @@ bool SHAMapTreeNode::updateHash()
|
|||||||
if(!empty)
|
if(!empty)
|
||||||
nh=Serializer::getSHA512Half(reinterpret_cast<unsigned char *>(mHashes), sizeof(mHashes));
|
nh=Serializer::getSHA512Half(reinterpret_cast<unsigned char *>(mHashes), sizeof(mHashes));
|
||||||
}
|
}
|
||||||
else if(mType==ACCOUNT_STATE)
|
else if(mType==tnACCOUNT_STATE)
|
||||||
{
|
{
|
||||||
Serializer s;
|
Serializer s;
|
||||||
mItem->addRaw(s);
|
mItem->addRaw(s);
|
||||||
s.add160(mItem->getTag().to160());
|
s.add160(mItem->getTag().to160());
|
||||||
nh=s.getSHA512Half();
|
nh=s.getSHA512Half();
|
||||||
}
|
}
|
||||||
else if(mType==TRANSACTION)
|
else if(mType==tnTRANSACTION)
|
||||||
{
|
{
|
||||||
nh=Serializer::getSHA512Half(mItem->peekData());
|
nh=Serializer::getSHA512Half(mItem->peekData());
|
||||||
}
|
}
|
||||||
@@ -321,7 +321,7 @@ void SHAMapTreeNode::makeInner()
|
|||||||
{
|
{
|
||||||
mItem=SHAMapItem::pointer();
|
mItem=SHAMapItem::pointer();
|
||||||
memset(mHashes, 0, sizeof(mHashes));
|
memset(mHashes, 0, sizeof(mHashes));
|
||||||
mType=INNER;
|
mType=tnINNER;
|
||||||
mHash.zero();
|
mHash.zero();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,7 +356,7 @@ std::string SHAMapTreeNode::getString() const
|
|||||||
bool SHAMapTreeNode::setChildHash(int m, const uint256 &hash)
|
bool SHAMapTreeNode::setChildHash(int m, const uint256 &hash)
|
||||||
{
|
{
|
||||||
assert( (m>=0) && (m<16) );
|
assert( (m>=0) && (m<16) );
|
||||||
assert(mType==INNER);
|
assert(mType==tnINNER);
|
||||||
if(mHashes[m]==hash)
|
if(mHashes[m]==hash)
|
||||||
return false;
|
return false;
|
||||||
mHashes[m]=hash;
|
mHashes[m]=hash;
|
||||||
@@ -365,6 +365,6 @@ bool SHAMapTreeNode::setChildHash(int m, const uint256 &hash)
|
|||||||
|
|
||||||
const uint256& SHAMapTreeNode::getChildHash(int m) const
|
const uint256& SHAMapTreeNode::getChildHash(int m) const
|
||||||
{
|
{
|
||||||
assert( (m>=0) && (m<16) && (mType==INNER) );
|
assert( (m>=0) && (m<16) && (mType==tnINNER) );
|
||||||
return mHashes[m];
|
return mHashes[m];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -415,7 +415,9 @@ bool SHAMap::syncTest()
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
std::cerr << "ROOT COMPLETE, INNER SYNCHING" << std::endl;
|
std::cerr << "ROOT COMPLETE, INNER SYNCHING" << std::endl;
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef SMS_DEBUG
|
||||||
int bytes=0;
|
int bytes=0;
|
||||||
|
#endif
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@@ -424,7 +426,7 @@ bool SHAMap::syncTest()
|
|||||||
|
|
||||||
// get the list of nodes we know we need
|
// get the list of nodes we know we need
|
||||||
destination.getMissingNodes(nodeIDs, hashes, 2048);
|
destination.getMissingNodes(nodeIDs, hashes, 2048);
|
||||||
if(!nodeIDs.size()) break;
|
if(nodeIDs.empty()) break;
|
||||||
|
|
||||||
#ifdef SMS_DEBUG
|
#ifdef SMS_DEBUG
|
||||||
std::cerr << nodeIDs.size() << " needed nodes" << std::endl;
|
std::cerr << nodeIDs.size() << " needed nodes" << std::endl;
|
||||||
@@ -442,7 +444,7 @@ bool SHAMap::syncTest()
|
|||||||
nodeIDs.clear();
|
nodeIDs.clear();
|
||||||
hashes.clear();
|
hashes.clear();
|
||||||
|
|
||||||
if(!gotNodeIDs.size())
|
if(gotNodeIDs.empty())
|
||||||
{
|
{
|
||||||
std::cerr << "No nodes gotten" << std::endl;
|
std::cerr << "No nodes gotten" << std::endl;
|
||||||
assert(false);
|
assert(false);
|
||||||
@@ -456,7 +458,9 @@ bool SHAMap::syncTest()
|
|||||||
nodeIDIterator!=gotNodeIDs.end(); ++nodeIDIterator, ++rawNodeIterator)
|
nodeIDIterator!=gotNodeIDs.end(); ++nodeIDIterator, ++rawNodeIterator)
|
||||||
{
|
{
|
||||||
nodes++;
|
nodes++;
|
||||||
|
#ifdef SMS_DEBUG
|
||||||
bytes+=rawNodeIterator->size();
|
bytes+=rawNodeIterator->size();
|
||||||
|
#endif
|
||||||
if(!destination.addKnownNode(*nodeIDIterator, *rawNodeIterator))
|
if(!destination.addKnownNode(*nodeIDIterator, *rawNodeIterator))
|
||||||
{
|
{
|
||||||
std::cerr << "AddKnownNode fails" << std::endl;
|
std::cerr << "AddKnownNode fails" << std::endl;
|
||||||
|
|||||||
@@ -13,10 +13,8 @@ using namespace boost;
|
|||||||
Only needs to start once we determine the network time
|
Only needs to start once we determine the network time
|
||||||
*/
|
*/
|
||||||
|
|
||||||
TimingService::TimingService()
|
TimingService::TimingService() : mLedgerTimer(NULL), mPropTimer(NULL), mValidTimer(NULL)
|
||||||
{
|
{
|
||||||
mLedgerTimer=NULL;
|
|
||||||
mPropTimer=NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TimingService::start(boost::asio::io_service& ioService)
|
void TimingService::start(boost::asio::io_service& ioService)
|
||||||
|
|||||||
Reference in New Issue
Block a user