Skip to content

Commit

Permalink
Add STAmount switchover support to tx queue:
Browse files Browse the repository at this point in the history
* RIPD-1513
* New fix1513 amendment
  • Loading branch information
ximinez authored and seelabs committed Dec 1, 2017
1 parent 6dc79c2 commit 1853c0d
Show file tree
Hide file tree
Showing 10 changed files with 211 additions and 107 deletions.
1 change: 1 addition & 0 deletions src/ripple/app/main/Amendments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ supportedAmendments ()
{ "CC5ABAE4F3EC92E94A59B1908C2BE82D2228B6485C00AFF8F22DF930D89C194E SortedDirectories" },
{ "B4D44CC3111ADD964E846FC57760C8B50FFCD5A82C86A72756F6B058DDDF96AD fix1201" },
{ "6C92211186613F9647A89DFFBAB8F94C99D4C7E956D495270789128569177DA1 fix1512" },
{ "67A34F2CF55BFC0F93AACD5B281413176FEE195269FA6D95219A2DF738671172 fix1513" },
{ "B9E739B8296B4A1BB29BE990B17D66E21B62A300A909F25AC55C22D6C72E1F9D fix1523" },
{ "1D3463A5891F9E589C5AE839FFAC4A917CE96197098A1EF22304E1BC5B98A454 fix1528" }
};
Expand Down
20 changes: 16 additions & 4 deletions src/ripple/app/misc/impl/TxQ.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ TxQ::MaybeTx::MaybeTx(
std::pair<TER, bool>
TxQ::MaybeTx::apply(Application& app, OpenView& view)
{
boost::optional<STAmountSO> saved;
if (view.rules().enabled(fix1513))
saved.emplace(view.info().parentCloseTime);
// If the rules or flags change, preflight again
assert(pfresult);
if (pfresult->rules != view.rules() ||
Expand Down Expand Up @@ -517,8 +520,13 @@ TxQ::tryClearAccountQueue(Application& app, OpenView& view,
}
// Apply the current tx. Because the state of the view has been changed
// by the queued txs, we also need to preclaim again.
auto const pcresult = preclaim(pfresult, app, view);
auto txResult = doApply(pcresult, app, view);
auto txResult = [&]{
boost::optional<STAmountSO> saved;
if (view.rules().enabled(fix1513))
saved.emplace(view.info().parentCloseTime);
auto const pcresult = preclaim(pfresult, app, view);
return doApply(pcresult, app, view);
}();

if (txResult.second)
{
Expand Down Expand Up @@ -614,11 +622,15 @@ TxQ::apply(Application& app, OpenView& view,
auto const transactionID = tx->getTransactionID();
auto const tSeq = tx->getSequence();

boost::optional<STAmountSO> saved;
if (view.rules().enabled(fix1513))
saved.emplace(view.info().parentCloseTime);

// See if the transaction is valid, properly formed,
// etc. before doing potentially expensive queue
// replace and multi-transaction operations.
auto const pfresult = preflight(app, view.rules(),
*tx, flags, j);
*tx, flags, j);
if (pfresult.ter != tesSUCCESS)
return{ pfresult.ter, false };

Expand Down Expand Up @@ -929,7 +941,7 @@ TxQ::apply(Application& app, OpenView& view,
// See if the transaction is likely to claim a fee.
assert(!multiTxn || multiTxn->openView);
auto const pcresult = preclaim(pfresult, app,
multiTxn ? *multiTxn->openView : view);
multiTxn ? *multiTxn->openView : view);
if (!pcresult.likelyToClaimFee)
return{ pcresult.ter, false };

Expand Down
2 changes: 2 additions & 0 deletions src/ripple/protocol/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class FeatureCollections
"SortedDirectories",
"fix1201",
"fix1512",
"fix1513",
"fix1523",
"fix1528"
};
Expand Down Expand Up @@ -168,6 +169,7 @@ extern uint256 const featureEnforceInvariants;
extern uint256 const featureSortedDirectories;
extern uint256 const fix1201;
extern uint256 const fix1512;
extern uint256 const fix1513;
extern uint256 const fix1523;
extern uint256 const fix1528;

Expand Down
1 change: 1 addition & 0 deletions src/ripple/protocol/impl/Feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ uint256 const featureEnforceInvariants = *getRegisteredFeature("EnforceInvariant
uint256 const featureSortedDirectories = *getRegisteredFeature("SortedDirectories");
uint256 const fix1201 = *getRegisteredFeature("fix1201");
uint256 const fix1512 = *getRegisteredFeature("fix1512");
uint256 const fix1513 = *getRegisteredFeature("fix1513");
uint256 const fix1523 = *getRegisteredFeature("fix1523");
uint256 const fix1528 = *getRegisteredFeature("fix1528");

Expand Down
85 changes: 64 additions & 21 deletions src/test/app/Flow_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1254,6 +1254,34 @@ struct Flow_test : public beast::unit_test::suite
ter(temBAD_PATH));
}

template<class... T>
void testWithFeats(bool haveFlow, T&&... fs)
{
testLineQuality({ fs... });
testFalseDry({ fs... });
if (!haveFlow)
return;
testDirectStep({ fs... });
testBookStep({ fs... });
testDirectStep({ featureOwnerPaysFee, fs... });
testBookStep({ featureOwnerPaysFee, fs... });
testTransferRate({ featureOwnerPaysFee, fs... });
testSelfPayment1({ fs... });
testSelfPayment2({ fs... });
testSelfFundedXRPEndpoint(false, { fs... });
testSelfFundedXRPEndpoint(true, { fs... });
testUnfundedOffer(true, { fs... });
testUnfundedOffer(false, { fs... });
testReexecuteDirectStep({ fix1368, fs... });
testSelfPayLowQualityOffer({ fs... });
}

template<class... T>
void testWithFeats(T&&... fs)
{
testWithFeats(!!sizeof...(fs), fs...);
}

void run() override
{
testLimitQuality();
Expand All @@ -1262,35 +1290,50 @@ struct Flow_test : public beast::unit_test::suite
testRIPD1449(true);
testRIPD1449(false);

auto testWithFeats = [this](auto&&... fs)
{
testLineQuality({fs...});
testFalseDry({fs...});
if (!sizeof...(fs))
return;
testDirectStep({fs...});
testBookStep({fs...});
testDirectStep({featureOwnerPaysFee, fs...});
testBookStep({featureOwnerPaysFee, fs...});
testTransferRate({featureOwnerPaysFee, fs...});
testSelfPayment1({fs...});
testSelfPayment2({fs...});
testSelfFundedXRPEndpoint(false, {fs...});
testSelfFundedXRPEndpoint(true, {fs...});
testUnfundedOffer(true, {fs...});
testUnfundedOffer(false, {fs...});
testReexecuteDirectStep({fix1368, fs...});
testSelfPayLowQualityOffer({fs...});
};
testWithFeats(false, featureFeeEscalation, fix1513);
testWithFeats(featureFlow, featureFeeEscalation, fix1513);
testWithFeats(featureFlow, fix1373, featureFeeEscalation, fix1513);
testWithFeats(featureFlow, fix1373, featureFlowCross,
featureFeeEscalation, fix1513);
testEmptyStrand({featureFlow, fix1373, featureFlowCross,
featureFeeEscalation, fix1513 });
}
};

struct Flow_manual_test : public Flow_test
{
void run() override
{
testWithFeats();
testWithFeats(false,
featureFeeEscalation);
testWithFeats(false,
featureFeeEscalation, fix1513);
testWithFeats(featureFlow);
testWithFeats(featureFlow,
featureFeeEscalation);
testWithFeats(featureFlow,
featureFeeEscalation, fix1513);
testWithFeats(featureFlow, fix1373);
testWithFeats(featureFlow, fix1373,
featureFeeEscalation);
testWithFeats(featureFlow, fix1373,
featureFeeEscalation, fix1513);
testWithFeats(featureFlow, fix1373, featureFlowCross);
testEmptyStrand({featureFlow, fix1373, featureFlowCross});
testWithFeats(featureFlow, fix1373, featureFlowCross,
featureFeeEscalation);
testWithFeats(featureFlow, fix1373, featureFlowCross,
featureFeeEscalation, fix1513);
testEmptyStrand({ featureFlow, fix1373, featureFlowCross });
testEmptyStrand({ featureFlow, fix1373, featureFlowCross,
featureFeeEscalation });
testEmptyStrand({ featureFlow, fix1373, featureFlowCross,
featureFeeEscalation, fix1513 });
}
};

BEAST_DEFINE_TESTSUITE(Flow,app,ripple);
BEAST_DEFINE_TESTSUITE_MANUAL(Flow_manual,app,ripple);

} // test
} // ripple
163 changes: 104 additions & 59 deletions src/test/app/Offer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,20 @@ class Offer_test : public beast::unit_test::suite
for (int i=0;i<101;++i)
env (offer (carol, USD (1), EUR (2)));

auto hasFeature = [](Env& env, uint256 const& f)
{
return (env.app().config().features.find(f) !=
env.app().config().features.end());
};

for (auto d : {-1, 1})
{
auto const closeTime = STAmountSO::soTime +
d * env.closed()->info().closeTimeResolution;
env.close (closeTime);
*stAmountCalcSwitchover = closeTime > STAmountSO::soTime;
*stAmountCalcSwitchover = closeTime > STAmountSO::soTime ||
(hasFeature(env, featureFeeEscalation) &&
!hasFeature(env, fix1513));
// Will fail without the underflow fix
auto expectedResult = *stAmountCalcSwitchover ?
tesSUCCESS : tecPATH_PARTIAL;
Expand Down Expand Up @@ -4519,74 +4527,111 @@ class Offer_test : public beast::unit_test::suite
BEAST_EXPECT (++it == offers.end());
}

void run ()
void testAll(std::initializer_list<uint256> fs)
{
testCanceledOffer(fs);
testRmFundedOffer(fs);
testTinyPayment(fs);
testXRPTinyPayment(fs);
testEnforceNoRipple(fs);
testInsufficientReserve(fs);
testFillModes(fs);
testMalformed(fs);
testExpiration(fs);
testUnfundedCross(fs);
testSelfCross(false, fs);
testSelfCross(true, fs);
testNegativeBalance(fs);
testOfferCrossWithXRP(true, fs);
testOfferCrossWithXRP(false, fs);
testOfferCrossWithLimitOverride(fs);
testOfferAcceptThenCancel(fs);
testOfferCancelPastAndFuture(fs);
testCurrencyConversionEntire(fs);
testCurrencyConversionIntoDebt(fs);
testCurrencyConversionInParts(fs);
testCrossCurrencyStartXRP(fs);
testCrossCurrencyEndXRP(fs);
testCrossCurrencyBridged(fs);
testOfferFeesConsumeFunds(fs);
testOfferCreateThenCross(fs);
testSellFlagBasic(fs);
testSellFlagExceedLimit(fs);
testGatewayCrossCurrency(fs);
testPartialCross(fs);
testXRPDirectCross(fs);
testDirectCross(fs);
testBridgedCross(fs);
testSellOffer(fs);
testSellWithFillOrKill(fs);
testTransferRateOffer(fs);
testSelfCrossOffer(fs);
testSelfIssueOffer(fs);
testBadPathAssert(fs);
testDirectToDirectPath(fs);
testSelfCrossLowQualityOffer(fs);
testOfferInScaling(fs);
testOfferInScalingWithXferRate(fs);
testOfferThresholdWithReducedFunds(fs);
testTinyOffer(fs);
testSelfPayXferFeeOffer(fs);
testSelfPayUnlimitedFunds(fs);
testRequireAuth(fs);
testMissingAuth(fs);
testRCSmoketest(fs);
testSelfAuth(fs);
testTickSize(fs);
}
void run () override
{
auto testAll = [this](std::initializer_list<uint256> fs) {
testCanceledOffer(fs);
testRmFundedOffer(fs);
testTinyPayment(fs);
testXRPTinyPayment(fs);
testEnforceNoRipple(fs);
testInsufficientReserve(fs);
testFillModes(fs);
testMalformed(fs);
testExpiration(fs);
testUnfundedCross(fs);
testSelfCross(false, fs);
testSelfCross(true, fs);
testNegativeBalance(fs);
testOfferCrossWithXRP(true, fs);
testOfferCrossWithXRP(false, fs);
testOfferCrossWithLimitOverride(fs);
testOfferAcceptThenCancel(fs);
testOfferCancelPastAndFuture(fs);
testCurrencyConversionEntire(fs);
testCurrencyConversionIntoDebt(fs);
testCurrencyConversionInParts(fs);
testCrossCurrencyStartXRP(fs);
testCrossCurrencyEndXRP(fs);
testCrossCurrencyBridged(fs);
testOfferFeesConsumeFunds(fs);
testOfferCreateThenCross(fs);
testSellFlagBasic(fs);
testSellFlagExceedLimit(fs);
testGatewayCrossCurrency(fs);
testPartialCross (fs);
testXRPDirectCross (fs);
testDirectCross (fs);
testBridgedCross (fs);
testSellOffer (fs);
testSellWithFillOrKill (fs);
testTransferRateOffer(fs);
testSelfCrossOffer (fs);
testSelfIssueOffer (fs);
testBadPathAssert (fs);
testDirectToDirectPath (fs);
testSelfCrossLowQualityOffer (fs);
testOfferInScaling (fs);
testOfferInScalingWithXferRate (fs);
testOfferThresholdWithReducedFunds (fs);
testTinyOffer (fs);
testSelfPayXferFeeOffer (fs);
testSelfPayUnlimitedFunds (fs);
testRequireAuth (fs);
testMissingAuth (fs);
testRCSmoketest (fs);
testSelfAuth (fs);
testTickSize (fs);
};
// The first three test variants below passed at one time in the past (and
// should still pass) but are commented out to conserve test time.
// testAll(jtx::no_features );
// testAll({ featureFlowCross });
// testAll({featureFlow });
testAll({featureFlow, featureFlowCross });
testAll({featureFlow, fix1373 });
testAll({featureFlow, fix1373, featureFlowCross });
testAll({featureFlow, featureFlowCross,
featureFeeEscalation, fix1513 });
testAll({ featureFlow, fix1373,
featureFeeEscalation, fix1513 });
testAll({featureFlow, fix1373, featureFlowCross,
featureFeeEscalation, fix1513 });
}
};

class Offer_manual_test : public Offer_test
{
void run() override
{
testAll({});
testAll({ featureFeeEscalation });
testAll({ featureFeeEscalation, fix1513 });
testAll({ featureFlowCross });
testAll({ featureFlowCross,
featureFeeEscalation });
testAll({ featureFlowCross,
featureFeeEscalation, fix1513 });
testAll({featureFlow });
testAll({ featureFlow, featureFeeEscalation });
testAll({ featureFlow, featureFeeEscalation, fix1513 });
testAll({featureFlow, featureFlowCross});
testAll({featureFlow, featureFlowCross,
featureFeeEscalation });
testAll({featureFlow, featureFlowCross,
featureFeeEscalation, fix1513 });
testAll({featureFlow, fix1373 });
testAll({ featureFlow, fix1373, featureFeeEscalation });
testAll({ featureFlow, fix1373, featureFeeEscalation, fix1513 });
testAll({ featureFlow, fix1373, featureFlowCross });
testAll({featureFlow, fix1373, featureFlowCross,
featureFeeEscalation });
testAll({featureFlow, fix1373, featureFlowCross,
featureFeeEscalation, fix1513 });

}
};

BEAST_DEFINE_TESTSUITE (Offer, tx, ripple);
BEAST_DEFINE_TESTSUITE_MANUAL (Offer_manual, tx, ripple);

} // test
} // ripple
2 changes: 1 addition & 1 deletion src/test/app/Regression_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ struct Regression_test : public beast::unit_test::suite
.set("minimum_txn_in_ledger_standalone", "3");
return cfg;
}),
with_features(featureFeeEscalation));
with_features(featureFeeEscalation, fix1513));
Env_ss envs(env);

auto const alice = Account("alice");
Expand Down
Loading

0 comments on commit 1853c0d

Please sign in to comment.