Skip to content

Commit

Permalink
Add featureImmediateOfferKilled for tfImmediateOrCancel offers:
Browse files Browse the repository at this point in the history
Fixes #4115; #4115
  • Loading branch information
scottschurr committed May 5, 2022
1 parent 7c66747 commit 72834c1
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
6 changes: 6 additions & 0 deletions src/ripple/app/tx/impl/CreateOffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,12 @@ CreateOffer::applyGuts(Sandbox& sb, Sandbox& sbCancel)
if (bImmediateOrCancel)
{
JLOG(j_.trace()) << "Immediate or cancel: offer canceled";
if (!crossed && sb.rules().enabled(featureImmediateOfferKilled))
// If the ImmediateOfferKilled amendment is enabled, any
// ImmediateOrCancel offer that transfers absolutely no funds
// returns tecKILLED rather than tesSUCCESS. Motivation for the
// change is here: https://github.com/ripple/rippled/issues/4115
return {tecKILLED, false};
return {tesSUCCESS, true};
}

Expand Down
1 change: 1 addition & 0 deletions src/ripple/protocol/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ extern uint256 const fixSTAmountCanonicalize;
extern uint256 const fixRmSmallIncreasedQOffers;
extern uint256 const featureCheckCashMakesTrustLine;
extern uint256 const featureNonFungibleTokensV1;
extern uint256 const featureImmediateOfferKilled;

} // namespace ripple

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 @@ -438,6 +438,7 @@ REGISTER_FIX (fixSTAmountCanonicalize, Supported::yes, DefaultVote::yes
REGISTER_FIX (fixRmSmallIncreasedQOffers, Supported::yes, DefaultVote::yes);
REGISTER_FEATURE(CheckCashMakesTrustLine, Supported::yes, DefaultVote::no);
REGISTER_FEATURE(NonFungibleTokensV1, Supported::yes, DefaultVote::no);
REGISTER_FEATURE(ImmediateOfferKilled, Supported::yes, DefaultVote::no);

// The following amendments have been active for at least two years. Their
// pre-amendment code has been removed and the identifiers are deprecated.
Expand Down
2 changes: 1 addition & 1 deletion src/ripple/protocol/impl/TER.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ transResults()
MAKE_ERROR(tecINVARIANT_FAILED, "One or more invariants for the transaction were not satisfied."),
MAKE_ERROR(tecEXPIRED, "Expiration time is passed."),
MAKE_ERROR(tecDUPLICATE, "Ledger object already exists."),
MAKE_ERROR(tecKILLED, "FillOrKill offer killed."),
MAKE_ERROR(tecKILLED, "No funds transferred and no offer created."),
MAKE_ERROR(tecHAS_OBLIGATIONS, "The account cannot be deleted since it has obligations."),
MAKE_ERROR(tecTOO_SOON, "It is too early to attempt the requested operation. Please wait."),
MAKE_ERROR(tecMAX_SEQUENCE_REACHED, "The maximum sequence number was reached."),
Expand Down
27 changes: 17 additions & 10 deletions src/test/app/Offer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -950,9 +950,14 @@ class Offer_test : public beast::unit_test::suite
env(pay(gw, alice, USD(1000)), ter(tesSUCCESS));

// No cross:
env(offer(alice, XRP(1000), USD(1000)),
txflags(tfImmediateOrCancel),
ter(tesSUCCESS));
{
TER const expectedCode = features[featureImmediateOfferKilled]
? static_cast<TER>(tecKILLED)
: static_cast<TER>(tesSUCCESS);
env(offer(alice, XRP(1000), USD(1000)),
txflags(tfImmediateOrCancel),
ter(expectedCode));
}

env.require(
balance(alice, startBalance - f - f),
Expand Down Expand Up @@ -5165,11 +5170,12 @@ class Offer_test : public beast::unit_test::suite
FeatureBitset const flowCross{featureFlowCross};
FeatureBitset const takerDryOffer{fixTakerDryOfferRemoval};
FeatureBitset const rmSmallIncreasedQOffers{fixRmSmallIncreasedQOffers};
FeatureBitset const immediateOfferKilled{featureImmediateOfferKilled};

testAll(all - takerDryOffer);
testAll(all - flowCross - takerDryOffer);
testAll(all - flowCross);
testAll(all - rmSmallIncreasedQOffers);
testAll(all - takerDryOffer - immediateOfferKilled);
testAll(all - flowCross - takerDryOffer - immediateOfferKilled);
testAll(all - flowCross - immediateOfferKilled);
testAll(all - rmSmallIncreasedQOffers - immediateOfferKilled);
testAll(all);
testFalseAssert();
}
Expand All @@ -5184,11 +5190,12 @@ class Offer_manual_test : public Offer_test
FeatureBitset const all{supported_amendments()};
FeatureBitset const flowCross{featureFlowCross};
FeatureBitset const f1513{fix1513};
FeatureBitset const immediateOfferKilled{featureImmediateOfferKilled};
FeatureBitset const takerDryOffer{fixTakerDryOfferRemoval};

testAll(all - flowCross - f1513);
testAll(all - flowCross);
testAll(all - f1513);
testAll(all - flowCross - f1513 - immediateOfferKilled);
testAll(all - flowCross - immediateOfferKilled);
testAll(all - immediateOfferKilled);
testAll(all);

testAll(all - flowCross - takerDryOffer);
Expand Down

0 comments on commit 72834c1

Please sign in to comment.