Push clean up code for bad ripple nodes.

This commit is contained in:
Arthur Britto
2012-12-25 18:08:13 -08:00
parent e1330badda
commit dc578a8085
3 changed files with 43 additions and 11 deletions

View File

@@ -621,7 +621,8 @@ TER LedgerEntrySet::dirDelete(
const uint64& uNodeDir, // --> Node containing entry.
const uint256& uRootIndex, // --> The index of the base of the directory. Nodes are based off of this.
const uint256& uLedgerIndex, // --> Value to remove from directory.
const bool bStable) // --> True, not to change relative order of entries.
const bool bStable, // --> True, not to change relative order of entries.
const bool bSoft) // --> True, uNodeDir is not hard and fast (pass uNodeDir=0).
{
uint64 uNodeCur = uNodeDir;
SLE::pointer sleNode = entryCache(ltDIR_NODE, uNodeCur ? Ledger::getDirNodeIndex(uRootIndex, uNodeCur) : uRootIndex);
@@ -634,9 +635,22 @@ TER LedgerEntrySet::dirDelete(
% strHex(uNodeDir)
% uLedgerIndex.ToString());
if (!bSoft)
{
assert(false);
return tefBAD_LEDGER;
}
else if (uNodeDir < 20)
{
// Go the extra mile. Even if node doesn't exist, try the next node.
return dirDelete(bKeepRoot, uNodeDir+1, uRootIndex, uLedgerIndex, bStable, true);
}
else
{
return tefBAD_LEDGER;
}
}
STVector256 svIndexes = sleNode->getFieldV256(sfIndexes);
std::vector<uint256>& vuiIndexes = svIndexes.peekValue();
@@ -646,6 +660,8 @@ TER LedgerEntrySet::dirDelete(
assert(vuiIndexes.end() != it);
if (vuiIndexes.end() == it)
{
if (!bSoft)
{
assert(false);
@@ -653,6 +669,17 @@ TER LedgerEntrySet::dirDelete(
return tefBAD_LEDGER;
}
else if (uNodeDir < 20)
{
// Go the extra mile. Even if entry not in node, try the next node.
return dirDelete(bKeepRoot, uNodeDir+1, uRootIndex, uLedgerIndex, bStable, true);
}
else
{
return tefBAD_LEDGER;
}
}
// Remove the element.
if (vuiIndexes.size() > 1)
@@ -866,8 +893,9 @@ void LedgerEntrySet::ownerCountAdjust(const uint160& uOwnerID, int iAmount, SLE:
TER LedgerEntrySet::offerDelete(const SLE::pointer& sleOffer, const uint256& uOfferIndex, const uint160& uOwnerID)
{
bool bOwnerNode = sleOffer->isFieldPresent(sfOwnerNode); // Detect legacy dirs.
uint64 uOwnerNode = sleOffer->getFieldU64(sfOwnerNode);
TER terResult = dirDelete(false, uOwnerNode, Ledger::getOwnerDirIndex(uOwnerID), uOfferIndex, false);
TER terResult = dirDelete(false, uOwnerNode, Ledger::getOwnerDirIndex(uOwnerID), uOfferIndex, false, !bOwnerNode);
if (tesSUCCESS == terResult)
{
@@ -876,7 +904,8 @@ TER LedgerEntrySet::offerDelete(const SLE::pointer& sleOffer, const uint256& uOf
uint256 uDirectory = sleOffer->getFieldH256(sfBookDirectory);
uint64 uBookNode = sleOffer->getFieldU64(sfBookNode);
terResult = dirDelete(false, uBookNode, uDirectory, uOfferIndex, true);
// Offer delete is always hard. Always have hints.
terResult = dirDelete(false, uBookNode, uDirectory, uOfferIndex, true, true);
}
entryDelete(sleOffer);

View File

@@ -97,7 +97,8 @@ public:
const uint64& uNodeDir, // Node item is mentioned in.
const uint256& uRootIndex,
const uint256& uLedgerIndex, // Item being deleted
const bool bStable);
const bool bStable,
const bool bSoft);
bool dirFirst(const uint256& uRootIndex, SLE::pointer& sleNode, unsigned int& uDirEntry, uint256& uEntryIndex);
bool dirNext(const uint256& uRootIndex, SLE::pointer& sleNode, unsigned int& uDirEntry, uint256& uEntryIndex);

View File

@@ -221,16 +221,18 @@ TER TrustSetTransactor::doApply()
{
// Can delete.
bool bLowNode = sleRippleState->isFieldPresent(sfLowNode); // Detect legacy dirs.
bool bHighNode = sleRippleState->isFieldPresent(sfHighNode);
uint64 uLowNode = sleRippleState->getFieldU64(sfLowNode);
uint64 uHighNode = sleRippleState->getFieldU64(sfHighNode);
cLog(lsTRACE) << "doTrustSet: Deleting ripple line: low";
terResult = mEngine->getNodes().dirDelete(false, uLowNode, Ledger::getOwnerDirIndex(uLowAccountID), sleRippleState->getIndex(), false);
terResult = mEngine->getNodes().dirDelete(false, uLowNode, Ledger::getOwnerDirIndex(uLowAccountID), sleRippleState->getIndex(), false, !bLowNode);
if (tesSUCCESS == terResult)
{
cLog(lsTRACE) << "doTrustSet: Deleting ripple line: high";
terResult = mEngine->getNodes().dirDelete(false, uHighNode, Ledger::getOwnerDirIndex(uHighAccountID), sleRippleState->getIndex(), false);
terResult = mEngine->getNodes().dirDelete(false, uHighNode, Ledger::getOwnerDirIndex(uHighAccountID), sleRippleState->getIndex(), false, !bHighNode);
}
cLog(lsINFO) << "doTrustSet: Deleting ripple line: state";