Use payment flow code for offer crossing (RIPD-1094):

Replace Taker.cpp with calls to the payment flow() code.

This change required a number of tweaks in the payment flow code.
These tweaks are conditionalized on whether or not offer crossing
is taking place.  The flag is explicitly passed as a parameter to
the flow code.

For testing, a class was added that identifies differences in the
contents of two PaymentSandboxes.  That code may be reusable in
the future.

None of the Taker offer crossing code is removed.  Both versions
of the code are co-resident to support an amendment cut-over.

The code that identifies differences between Taker and Flow offer
crossing is enabled by a feature.  That makes it easy to enable
or disable difference logging by changing the config file.  This
approach models what was done with the payment flow code.  The
differencing code should never be enabled on a production server.

Extensive offer crossing unit tests are added to examine and
verify the behavior of corner cases.  The tests are currently
configured to run against both Taker and Flow offer crossing.
This gives us confidence that most cases run identically and
some of the (few) differences in behavior are documented.
This commit is contained in:
Scott Schurr
2016-03-15 17:17:09 -07:00
parent 2cd55ebf98
commit 369909df84
50 changed files with 5367 additions and 711 deletions

View File

@@ -0,0 +1,104 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2016 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#include <BeastConfig.h>
#include <ripple/ledger/CashDiff.h>
#include <ripple/protocol/STAmount.h>
#include <ripple/beast/unit_test.h>
namespace ripple {
namespace test {
class CashDiff_test : public beast::unit_test::suite
{
// Exercise diffIsDust (STAmount, STAmount)
void
testDust ()
{
testcase ("diffIsDust (STAmount, STAmount)");
Issue const usd (Currency (0x5553440000000000), AccountID (0x4985601));
Issue const usf (Currency (0x5553460000000000), AccountID (0x4985601));
// Positive and negative are never dust.
expect (!diffIsDust (STAmount{usd, 1}, STAmount{usd, -1}));
// Different issues are never dust.
expect (!diffIsDust (STAmount{usd, 1}, STAmount{usf, 1}));
// Native and non-native are never dust.
expect (!diffIsDust (STAmount{usd, 1}, STAmount{1}));
// Equal values are always dust.
expect (diffIsDust (STAmount{0}, STAmount{0}));
{
// Test IOU.
std::uint64_t oldProbe = 0;
std::uint64_t newProbe = 10;
std::uint8_t e10 = 1;
do
{
STAmount large (usd, newProbe + 1);
STAmount small (usd, newProbe);
expect (diffIsDust (large, small, e10));
expect (diffIsDust (large, small, e10+1) == (e10 > 13));
oldProbe = newProbe;
newProbe = oldProbe * 10;
e10 += 1;
} while (newProbe > oldProbe);
}
{
// Test XRP.
// A delta of 2 or less is always dust.
expect (diffIsDust (STAmount{2}, STAmount{0}));
std::uint64_t oldProbe = 0;
std::uint64_t newProbe = 10;
std::uint8_t e10 = 0;
do
{
// Differences of 2 of fewer drops are always treated as dust,
// so use a delta of 3.
STAmount large (newProbe + 3);
STAmount small (newProbe);
expect (diffIsDust (large, small, e10));
expect (diffIsDust (large, small, e10+1) == (e10 >= 20));
oldProbe = newProbe;
newProbe = oldProbe * 10;
e10 += 1;
} while (newProbe > oldProbe);
}
}
public:
void run ()
{
testDust();
}
};
BEAST_DEFINE_TESTSUITE (CashDiff, ledger, ripple);
} // test
} // ripple