Skip to content

Commit

Permalink
Enforce rippling constraints during payments
Browse files Browse the repository at this point in the history
  • Loading branch information
seelabs authored and nbougalis committed Mar 14, 2017
1 parent d8a5f5b commit 0b187a6
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/ripple/app/paths/impl/BookStep.cpp
Expand Up @@ -684,6 +684,26 @@ BookStep<TIn, TOut>::check(StrandContext const& ctx) const
return temBAD_PATH_LOOP;
}

if (amendmentRIPD1443(ctx.view.info().parentCloseTime))
{
if (ctx.prevStep)
{
if (auto const prev = ctx.prevStep->directStepSrcAcct())
{
auto const& view = ctx.view;
auto const& cur = book_.in.account;

auto sle =
view.read(keylet::line(*prev, cur, book_.in.currency));
if (!sle)
return terNO_LINE;
if ((*sle)[sfFlags] &
((cur > *prev) ? lsfHighNoRipple : lsfLowNoRipple))
return terNO_RIPPLE;
}
}
}

return tesSUCCESS;
}

Expand Down
2 changes: 2 additions & 0 deletions src/ripple/ledger/View.h
Expand Up @@ -344,6 +344,8 @@ bool amendmentRIPD1274 (NetClock::time_point const closeTime);
NetClock::time_point const& amendmentRIPD1298SoTime ();
bool amendmentRIPD1298 (NetClock::time_point const closeTime);

NetClock::time_point const& amendmentRIPD1443SoTime ();
bool amendmentRIPD1443 (NetClock::time_point const closeTime);

} // ripple

Expand Down
14 changes: 14 additions & 0 deletions src/ripple/ledger/impl/View.cpp
Expand Up @@ -72,6 +72,20 @@ bool amendmentRIPD1298 (NetClock::time_point const closeTime)
return closeTime > amendmentRIPD1298SoTime();
}

NetClock::time_point const& amendmentRIPD1443SoTime ()
{
using namespace std::chrono_literals;
// Sat Mar 11, 2017 05:00:00pm PST
static NetClock::time_point const soTime{542595600s};

return soTime;
}

bool amendmentRIPD1443 (NetClock::time_point const closeTime)
{
return closeTime > amendmentRIPD1443SoTime();
}

// VFALCO NOTE A copy of the other one for now
/** Maximum number of entries in a directory page
A change would be protocol-breaking.
Expand Down
55 changes: 55 additions & 0 deletions src/test/app/Flow_test.cpp
Expand Up @@ -1379,6 +1379,59 @@ struct Flow_test : public beast::unit_test::suite
}
}

void
testRIPD1443(bool withFix)
{
testcase("ripd1443");

using namespace jtx;
Env env(*this, features(featureFlow));
auto const timeDelta = env.closed ()->info ().closeTimeResolution;
auto const d = withFix ? timeDelta*100 : -timeDelta*100;
auto closeTime = amendmentRIPD1443SoTime() + d;
env.close(closeTime);

auto const alice = Account("alice");
auto const bob = Account("bob");
auto const carol = Account("carol");
auto const gw = Account("gw");

env.fund(XRP(100000000), alice, noripple(bob), carol, gw);
env.trust(gw["USD"](10000), alice, carol);
env(trust(bob, gw["USD"](10000), tfSetNoRipple));
env.trust(gw["USD"](10000), bob);
env.close();

// set no ripple between bob and the gateway

env(pay(gw, alice, gw["USD"](1000)));
env.close();

env(offer(alice, bob["USD"](1000), XRP(1)));
env.close();

env(pay(alice, alice, XRP(1)), path(gw, bob, ~XRP),
sendmax(gw["USD"](1000)), txflags(tfNoRippleDirect),
ter(withFix ? tecPATH_DRY : tesSUCCESS));
env.close();

if (withFix)
{
env.trust(bob["USD"](10000), alice);
env(pay(bob, alice, bob["USD"](1000)));
}

env(offer(alice, XRP(1000), bob["USD"](1000)));
env.close();

env(pay (carol, carol, gw["USD"](1000)), path(~bob["USD"], gw),
sendmax(XRP(100000)), txflags(tfNoRippleDirect),
ter(withFix ? tecPATH_DRY : tesSUCCESS));
env.close();

pass();
}

void run() override
{
testDirectStep ();
Expand All @@ -1394,6 +1447,8 @@ struct Flow_test : public beast::unit_test::suite
testSelfFundedXRPEndpoint(true);
testUnfundedOffer(true);
testUnfundedOffer(false);
testRIPD1443(true);
testRIPD1443(false);
}
};

Expand Down

0 comments on commit 0b187a6

Please sign in to comment.