Handle errors from ripple state creating.

This commit is contained in:
Arthur Britto
2012-12-25 16:42:33 -08:00
parent 3ccf163fb3
commit f3b216b39f
4 changed files with 64 additions and 34 deletions

View File

@@ -1194,7 +1194,7 @@ TER LedgerEntrySet::trustCreate(
} }
// Direct send w/o fees: redeeming IOUs and/or sending own IOUs. // Direct send w/o fees: redeeming IOUs and/or sending own IOUs.
void LedgerEntrySet::rippleCredit(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount, bool bCheckIssuer) TER LedgerEntrySet::rippleCredit(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount, bool bCheckIssuer)
{ {
uint160 uIssuerID = saAmount.getIssuer(); uint160 uIssuerID = saAmount.getIssuer();
uint160 uCurrencyID = saAmount.getCurrency(); uint160 uCurrencyID = saAmount.getCurrency();
@@ -1205,6 +1205,8 @@ void LedgerEntrySet::rippleCredit(const uint160& uSenderID, const uint160& uRece
uint256 uIndex = Ledger::getRippleStateIndex(uSenderID, uReceiverID, saAmount.getCurrency()); uint256 uIndex = Ledger::getRippleStateIndex(uSenderID, uReceiverID, saAmount.getCurrency());
SLE::pointer sleRippleState = entryCache(ltRIPPLE_STATE, uIndex); SLE::pointer sleRippleState = entryCache(ltRIPPLE_STATE, uIndex);
TER terResult;
assert(!!uSenderID && uSenderID != ACCOUNT_ONE); assert(!!uSenderID && uSenderID != ACCOUNT_ONE);
assert(!!uReceiverID && uReceiverID != ACCOUNT_ONE); assert(!!uReceiverID && uReceiverID != ACCOUNT_ONE);
@@ -1221,8 +1223,7 @@ void LedgerEntrySet::rippleCredit(const uint160& uSenderID, const uint160& uRece
% RippleAddress::createHumanAccountID(uReceiverID) % RippleAddress::createHumanAccountID(uReceiverID)
% saAmount.getFullText()); % saAmount.getFullText());
// XXX Pass back result. terResult = trustCreate(
TER terResult = trustCreate(
bSenderHigh, bSenderHigh,
uSenderID, uSenderID,
entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(uSenderID)), entryCache(ltACCOUNT_ROOT, Ledger::getAccountRootIndex(uSenderID)),
@@ -1252,25 +1253,31 @@ void LedgerEntrySet::rippleCredit(const uint160& uSenderID, const uint160& uRece
sleRippleState->setFieldAmount(sfBalance, saBalance); sleRippleState->setFieldAmount(sfBalance, saBalance);
entryModify(sleRippleState); entryModify(sleRippleState);
terResult = tesSUCCESS;
} }
return terResult;
} }
// Send regardless of limits. // Send regardless of limits.
// --> saAmount: Amount/currency/issuer for receiver to get. // --> saAmount: Amount/currency/issuer for receiver to get.
// <-- saActual: Amount actually sent. Sender pay's fees. // <-- saActual: Amount actually sent. Sender pay's fees.
STAmount LedgerEntrySet::rippleSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount) TER LedgerEntrySet::rippleSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount, STAmount& saActual)
{ {
STAmount saActual;
const uint160 uIssuerID = saAmount.getIssuer(); const uint160 uIssuerID = saAmount.getIssuer();
TER terResult;
assert(!!uSenderID && !!uReceiverID); assert(!!uSenderID && !!uReceiverID);
if (uSenderID == uIssuerID || uReceiverID == uIssuerID || uIssuerID == ACCOUNT_ONE) if (uSenderID == uIssuerID || uReceiverID == uIssuerID || uIssuerID == ACCOUNT_ONE)
{ {
// Direct send: redeeming IOUs and/or sending own IOUs. // Direct send: redeeming IOUs and/or sending own IOUs.
rippleCredit(uSenderID, uReceiverID, saAmount, false); terResult = rippleCredit(uSenderID, uReceiverID, saAmount, false);
saActual = saAmount; saActual = saAmount;
terResult = tesSUCCESS;
} }
else else
{ {
@@ -1282,16 +1289,19 @@ STAmount LedgerEntrySet::rippleSend(const uint160& uSenderID, const uint160& uRe
saActual.setIssuer(uIssuerID); // XXX Make sure this done in + above. saActual.setIssuer(uIssuerID); // XXX Make sure this done in + above.
rippleCredit(uIssuerID, uReceiverID, saAmount); terResult = rippleCredit(uIssuerID, uReceiverID, saAmount);
rippleCredit(uSenderID, uIssuerID, saActual);
if (tesSUCCESS == terResult)
terResult = rippleCredit(uSenderID, uIssuerID, saActual);
} }
return saActual; return terResult;
} }
void LedgerEntrySet::accountSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount) TER LedgerEntrySet::accountSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount)
{ {
assert(!saAmount.isNegative()); assert(!saAmount.isNegative());
TER terResult = tesSUCCESS;
if (!saAmount) if (!saAmount)
{ {
@@ -1334,8 +1344,12 @@ void LedgerEntrySet::accountSend(const uint160& uSenderID, const uint160& uRecei
} }
else else
{ {
rippleSend(uSenderID, uReceiverID, saAmount); STAmount saActual;
terResult = rippleSend(uSenderID, uReceiverID, saAmount, saActual);
} }
return terResult;
} }
// vim:ts=4 // vim:ts=4

View File

@@ -121,12 +121,12 @@ public:
STAmount rippleHolds(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID, bool bAvail=false); STAmount rippleHolds(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID, bool bAvail=false);
STAmount rippleTransferFee(const uint160& uSenderID, const uint160& uReceiverID, const uint160& uIssuerID, const STAmount& saAmount); STAmount rippleTransferFee(const uint160& uSenderID, const uint160& uReceiverID, const uint160& uIssuerID, const STAmount& saAmount);
void rippleCredit(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount, bool bCheckIssuer=true); TER rippleCredit(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount, bool bCheckIssuer=true);
STAmount rippleSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount); TER rippleSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount, STAmount& saActual);
STAmount accountHolds(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID, bool bAvail=false); STAmount accountHolds(const uint160& uAccountID, const uint160& uCurrencyID, const uint160& uIssuerID, bool bAvail=false);
STAmount accountFunds(const uint160& uAccountID, const STAmount& saDefault, bool bAvail=false); STAmount accountFunds(const uint160& uAccountID, const STAmount& saDefault, bool bAvail=false);
void accountSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount); TER accountSend(const uint160& uSenderID, const uint160& uReceiverID, const STAmount& saAmount);
TER trustCreate( TER trustCreate(
const bool bSrcHigh, const bool bSrcHigh,

View File

@@ -200,23 +200,30 @@ TER OfferCreateTransactor::takeOffers(
cLog(lsINFO) << "takeOffers: offer partial claim."; cLog(lsINFO) << "takeOffers: offer partial claim.";
} }
// Offer owner pays taker.
// saSubTakerGot.setIssuer(uTakerGetsAccountID); // XXX Move this earlier?
assert(!!saSubTakerGot.getIssuer()); assert(!!saSubTakerGot.getIssuer());
mEngine->getNodes().accountSend(uOfferOwnerID, uTakerAccountID, saSubTakerGot);
mEngine->getNodes().accountSend(uOfferOwnerID, uTakerGetsAccountID, saOfferIssuerFee);
saTakerGot += saSubTakerGot;
// Taker pays offer owner.
// saSubTakerPaid.setIssuer(uTakerPaysAccountID);
assert(!!saSubTakerPaid.getIssuer()); assert(!!saSubTakerPaid.getIssuer());
mEngine->getNodes().accountSend(uTakerAccountID, uOfferOwnerID, saSubTakerPaid); // Offer owner pays taker.
mEngine->getNodes().accountSend(uTakerAccountID, uTakerPaysAccountID, saTakerIssuerFee); // saSubTakerGot.setIssuer(uTakerGetsAccountID); // XXX Move this earlier?
terResult = mEngine->getNodes().accountSend(uOfferOwnerID, uTakerAccountID, saSubTakerGot);
if (tesSUCCESS == terResult)
terResult = mEngine->getNodes().accountSend(uOfferOwnerID, uTakerGetsAccountID, saOfferIssuerFee);
// Taker pays offer owner.
// saSubTakerPaid.setIssuer(uTakerPaysAccountID);
if (tesSUCCESS == terResult)
terResult = mEngine->getNodes().accountSend(uTakerAccountID, uOfferOwnerID, saSubTakerPaid);
if (tesSUCCESS == terResult)
terResult = mEngine->getNodes().accountSend(uTakerAccountID, uTakerPaysAccountID, saTakerIssuerFee);
saTakerGot += saSubTakerGot;
saTakerPaid += saSubTakerPaid; saTakerPaid += saSubTakerPaid;
if (tesSUCCESS == terResult)
terResult = temUNCERTAIN;
} }
} }
} }

View File

@@ -1127,7 +1127,10 @@ TER RippleCalc::calcNodeDeliverRev(
// Sending could be complicated: could fund a previous offer not yet visited. // Sending could be complicated: could fund a previous offer not yet visited.
// However, these deductions and adjustments are tenative. // However, these deductions and adjustments are tenative.
// Must reset balances when going forward to perform actual transfers. // Must reset balances when going forward to perform actual transfers.
lesActive.accountSend(uOfrOwnerID, uCurIssuerID, saOutPass); terResult = lesActive.accountSend(uOfrOwnerID, uCurIssuerID, saOutPass);
if (tesSUCCESS != terResult)
break;
// Adjust offer // Adjust offer
sleOffer->setFieldAmount(sfTakerGets, saTakerGets - saOutPass); sleOffer->setFieldAmount(sfTakerGets, saTakerGets - saOutPass);
@@ -1147,7 +1150,7 @@ TER RippleCalc::calcNodeDeliverRev(
saPrvDlvReq += saInPassAct; saPrvDlvReq += saInPassAct;
} }
if (!saOutAct) if (tesSUCCESS == terResult && !saOutAct)
terResult = tecPATH_DRY; terResult = tecPATH_DRY;
return terResult; return terResult;
@@ -1253,7 +1256,10 @@ TER RippleCalc::calcNodeDeliverFwd(
% saOutPassAct.getFullText()); % saOutPassAct.getFullText());
// Output: Debit offer owner, send XRP or non-XPR to next account. // Output: Debit offer owner, send XRP or non-XPR to next account.
lesActive.accountSend(uOfrOwnerID, uNxtAccountID, saOutPassAct); terResult = lesActive.accountSend(uOfrOwnerID, uNxtAccountID, saOutPassAct);
if (tesSUCCESS != terResult)
break;
} }
else else
{ {
@@ -1314,7 +1320,10 @@ TER RippleCalc::calcNodeDeliverFwd(
// Do inbound crediting. // Do inbound crediting.
// Credit offer owner from in issuer/limbo (input transfer fees left with owner). // Credit offer owner from in issuer/limbo (input transfer fees left with owner).
lesActive.accountSend(!!uPrvCurrencyID ? uInAccountID : ACCOUNT_XRP, uOfrOwnerID, saInPassAct); terResult = lesActive.accountSend(!!uPrvCurrencyID ? uInAccountID : ACCOUNT_XRP, uOfrOwnerID, saInPassAct);
if (tesSUCCESS != terResult)
break;
// Adjust offer // Adjust offer
// Fees are considered paid from a seperate budget and are not named in the offer. // Fees are considered paid from a seperate budget and are not named in the offer.
@@ -2017,7 +2026,7 @@ TER RippleCalc::calcNodeAccountFwd(
saCurReceive = saPrvRedeemReq+saIssueCrd; saCurReceive = saPrvRedeemReq+saIssueCrd;
// Actually receive. // Actually receive.
lesActive.rippleCredit(uPrvAccountID, uCurAccountID, saPrvRedeemReq+saPrvIssueReq, false); terResult = lesActive.rippleCredit(uPrvAccountID, uCurAccountID, saPrvRedeemReq+saPrvIssueReq, false);
} }
else else
{ {
@@ -2060,7 +2069,7 @@ TER RippleCalc::calcNodeAccountFwd(
} }
// Adjust prv --> cur balance : take all inbound // Adjust prv --> cur balance : take all inbound
lesActive.rippleCredit(uPrvAccountID, uCurAccountID, saPrvRedeemReq + saPrvIssueReq, false); terResult = lesActive.rippleCredit(uPrvAccountID, uCurAccountID, saPrvRedeemReq + saPrvIssueReq, false);
} }
} }
else if (bPrvAccount && !bNxtAccount) else if (bPrvAccount && !bNxtAccount)
@@ -2096,7 +2105,7 @@ TER RippleCalc::calcNodeAccountFwd(
} }
// Adjust prv --> cur balance : take all inbound // Adjust prv --> cur balance : take all inbound
lesActive.rippleCredit(uPrvAccountID, uCurAccountID, saPrvRedeemReq + saPrvIssueReq, false); terResult = lesActive.rippleCredit(uPrvAccountID, uCurAccountID, saPrvRedeemReq + saPrvIssueReq, false);
} }
else else
{ {
@@ -2133,7 +2142,7 @@ TER RippleCalc::calcNodeAccountFwd(
cLog(lsDEBUG) << boost::str(boost::format("calcNodeAccountFwd: ^ --> ACCOUNT -- XRP --> offer")); cLog(lsDEBUG) << boost::str(boost::format("calcNodeAccountFwd: ^ --> ACCOUNT -- XRP --> offer"));
// Deliver XRP to limbo. // Deliver XRP to limbo.
lesActive.accountSend(uCurAccountID, ACCOUNT_XRP, saCurDeliverAct); terResult = lesActive.accountSend(uCurAccountID, ACCOUNT_XRP, saCurDeliverAct);
} }
} }
} }