Enable rm funded offer fix after a switch over date

This commit is contained in:
seelabs
2015-07-15 11:54:53 -04:00
committed by Vinnie Falco
parent 2b91e62d5d
commit a0dcc4da8c
2 changed files with 78 additions and 37 deletions

View File

@@ -24,6 +24,15 @@
namespace ripple { namespace ripple {
namespace path { namespace path {
static
bool enableDirRestartFix (
std::uint32_t parentCloseTime)
{
// Mon Aug 3 11:00:00am PDT
static std::uint32_t const enableAfter = 491940000;
return parentCloseTime > enableAfter;
}
// At the right most node of a list of consecutive offer nodes, given the amount // At the right most node of a list of consecutive offer nodes, given the amount
// requested to be delivered, push towards the left nodes the amount requested // requested to be delivered, push towards the left nodes the amount requested
// for the right nodes so we can compute how much to deliver from the source. // for the right nodes so we can compute how much to deliver from the source.
@@ -44,6 +53,12 @@ TER PathCursor::deliverNodeReverseImpl (
) const ) const
{ {
TER resultCode = tesSUCCESS; TER resultCode = tesSUCCESS;
if (!enableDirRestartFix (rippleCalc_.view.info ().parentCloseTime))
{
node().directory.restart(multiQuality_);
}
// Accumulation of what the previous node must deliver. // Accumulation of what the previous node must deliver.
// Possible optimization: Note this gets zeroed on each increment, ideally // Possible optimization: Note this gets zeroed on each increment, ideally
// only on first increment, then it could be a limit on the forward pass. // only on first increment, then it could be a limit on the forward pass.
@@ -350,9 +365,12 @@ TER PathCursor::deliverNodeReverse (
STAmount& saOutAct // <-- Funds actually delivered for an STAmount& saOutAct // <-- Funds actually delivered for an
// increment // increment
) const ) const
{
if (enableDirRestartFix (rippleCalc_.view.info ().parentCloseTime))
{ {
for (int i = nodeIndex_; i >= 0 && !node (i).isAccount(); --i) for (int i = nodeIndex_; i >= 0 && !node (i).isAccount(); --i)
node (i).directory.restart (multiQuality_); node (i).directory.restart (multiQuality_);
}
return deliverNodeReverseImpl(uOutAccountID, saOutReq, saOutAct); return deliverNodeReverseImpl(uOutAccountID, saOutReq, saOutAct);
} }

View File

@@ -41,8 +41,30 @@ public:
// would remove the first "taker gets" xrp offer, even though the offer is // would remove the first "taker gets" xrp offer, even though the offer is
// still funded and not used for the payment. // still funded and not used for the payment.
// Mon Aug 3 11:00:00am PDT
static NetClock::time_point const switchoverTime (
std::chrono::seconds (491940000));
for(int i=0; i<2; ++i)
{
using namespace jtx; using namespace jtx;
Env env (*this); Env env (*this);
auto const tp = switchoverTime + std::chrono::seconds (i);
bool const enableFix = tp > switchoverTime;
expect (enableFix == bool(i));
// ledger close times have a dynamic resolution depending on network
// conditions it appears the resolution in test is 10 seconds
env.close (tp);
NetClock::time_point const pct (
std::chrono::seconds (env.open ()->info ().parentCloseTime));
if (enableFix)
expect (pct > switchoverTime);
else
expect (pct <= switchoverTime);
auto const gw = Account ("gateway"); auto const gw = Account ("gateway");
auto const USD = gw["USD"]; auto const USD = gw["USD"];
auto const BTC = gw["BTC"]; auto const BTC = gw["BTC"];
@@ -73,18 +95,19 @@ public:
// Offers for the good quality path // Offers for the good quality path
env (offer (carol, BTC (1), USD (100))); env (offer (carol, BTC (1), USD (100)));
PathSet paths ( PathSet paths (Path (XRP, USD), Path (USD));
Path (XRP, USD),
Path (USD));
env (pay ("alice", "bob", USD (100)), env (pay ("alice", "bob", USD (100)), json (paths.json ()),
json (paths.json ()), sendmax (BTC (1000)), txflags (tfPartialPayment));
sendmax (BTC (1000)),
txflags (tfPartialPayment));
require (balance ("bob", USD (100))); require (balance ("bob", USD (100)));
if (enableFix)
expect (!isOffer (env, "carol", BTC (1), USD (100)) && expect (!isOffer (env, "carol", BTC (1), USD (100)) &&
isOffer (env, "carol", BTC (49), XRP (49))); isOffer (env, "carol", BTC (49), XRP (49)));
else
expect (!isOffer (env, "carol", BTC (1), USD (100)) &&
!isOffer (env, "carol", BTC (49), XRP (49)));
}
} }
void testCanceledOffer () void testCanceledOffer ()
{ {