From 00c87ca2dd0638a75828e5cc8cea1edec015d6fc Mon Sep 17 00:00:00 2001 From: David Schwartz Date: Fri, 3 Jan 2014 15:07:17 -0800 Subject: [PATCH] Add LES::dirIsEmpty function to check if a directory is empty --- src/ripple_app/ledger/LedgerEntrySet.cpp | 16 ++++++++++++++++ src/ripple_app/ledger/LedgerEntrySet.h | 1 + src/ripple_app/tx/AccountSetTransactor.cpp | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/ripple_app/ledger/LedgerEntrySet.cpp b/src/ripple_app/ledger/LedgerEntrySet.cpp index 741bcdd18..bb15d956a 100644 --- a/src/ripple_app/ledger/LedgerEntrySet.cpp +++ b/src/ripple_app/ledger/LedgerEntrySet.cpp @@ -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. diff --git a/src/ripple_app/ledger/LedgerEntrySet.h b/src/ripple_app/ledger/LedgerEntrySet.h index b75b67fe0..c490e7038 100644 --- a/src/ripple_app/ledger/LedgerEntrySet.h +++ b/src/ripple_app/ledger/LedgerEntrySet.h @@ -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); diff --git a/src/ripple_app/tx/AccountSetTransactor.cpp b/src/ripple_app/tx/AccountSetTransactor.cpp index 75dd53453..9fd497fb6 100644 --- a/src/ripple_app/tx/AccountSetTransactor.cpp +++ b/src/ripple_app/tx/AccountSetTransactor.cpp @@ -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; }