Add LES::dirIsEmpty function to check if a directory is empty

This commit is contained in:
David Schwartz
2014-01-03 15:07:17 -08:00
committed by Vinnie Falco
parent d474d68566
commit 00c87ca2dd
3 changed files with 19 additions and 2 deletions

View File

@@ -633,6 +633,22 @@ TER LedgerEntrySet::dirCount (uint256 const& uRootIndex, uint32& uCount)
return tesSUCCESS;
}
bool LedgerEntrySet::dirIsEmpty (uint256 const& uRootIndex)
{
uint64 uNodeDir = 0;
SLE::pointer sleNode = entryCache (ltDIR_NODE, Ledger::getDirNodeIndex (uRootIndex, uNodeDir));
if (!sleNode)
return true;
if (!sleNode->getFieldV256 (sfIndexes).peekValue ().empty ())
return false;
// If there's another page, it must be non-empty
return sleNode->getFieldU64 (sfIndexNext) == 0;
}
// <-- uNodeDir: For deletion, present to make dirDelete efficient.
// --> uRootIndex: The index of the base of the directory. Nodes are based off of this.
// --> uLedgerIndex: Value to add to directory.

View File

@@ -172,6 +172,7 @@ public:
bool dirFirst (uint256 const & uRootIndex, SLE::pointer & sleNode, unsigned int & uDirEntry, uint256 & uEntryIndex);
bool dirNext (uint256 const & uRootIndex, SLE::pointer & sleNode, unsigned int & uDirEntry, uint256 & uEntryIndex);
bool dirIsEmpty (uint256 const & uDirIndex);
TER dirCount (uint256 const & uDirIndex, uint32 & uCount);
uint256 getNextLedgerIndex (uint256 const & uHash);

View File

@@ -59,9 +59,9 @@ TER AccountSetTransactor::doApply ()
if (bSetRequireAuth && !isSetBit (uFlagsIn, lsfRequireAuth))
{
if (mTxnAccount->getFieldU32 (sfOwnerCount))
if (!mEngine->getNodes ().dirIsEmpty (Ledger::getOwnerDirIndex (mTxnAccountID)))
{
WriteLog (lsINFO, AccountSetTransactor) << "AccountSet: Retry: OwnerCount not zero.";
WriteLog (lsINFO, AccountSetTransactor) << "AccountSet: Retry: Owner directory not empty.";
return isSetBit(mParams, tapRETRY) ? terOWNERS : tecOWNERS;
}