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