Skip to content

Commit

Permalink
Finalize autobridging implementation (RIPD-179):
Browse files Browse the repository at this point in the history
Autobridging uses XRP as a natural bridge currency to allow IOU-to-IOU orders
to be satisfied not only from the direct IOU-to-IOU books but also over the
combined IOU-to-XRP and XRP-to-IOU books.

This commit addresses the following issues:

* RIPD-486: Refactoring the taker into a unit-testable architecture
* RIPD-659: Asset-aware offer crossing
* RIPD-491: Unit tests for IOU to XRP, XRP to IOU and IOU to IOU
* RIPD-441: Handle case when autobridging over same owner offers
* RIPD-665: Handle case when autobridging over own offers
* RIPD-273: Groom order books while crossing
  • Loading branch information
nbougalis committed Jan 26, 2015
1 parent 385a87d commit 3ccbd7c
Show file tree
Hide file tree
Showing 24 changed files with 1,867 additions and 1,122 deletions.
11 changes: 3 additions & 8 deletions Builds/VisualStudio2013/RippleD.vcxproj
Expand Up @@ -1779,6 +1779,9 @@
<ClCompile Include="..\..\src\ripple\app\book\tests\Quality.test.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\app\book\tests\Taker.test.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\app\book\Types.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\consensus\DisputedTx.cpp">
Expand Down Expand Up @@ -2119,14 +2122,6 @@
<ClCompile Include="..\..\src\ripple\app\transactors\CreateOffer.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\app\transactors\CreateOffer.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\transactors\CreateOfferBridged.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\app\transactors\CreateOfferDirect.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\app\transactors\CreateTicket.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
Expand Down
12 changes: 3 additions & 9 deletions Builds/VisualStudio2013/RippleD.vcxproj.filters
Expand Up @@ -2709,6 +2709,9 @@
<ClCompile Include="..\..\src\ripple\app\book\tests\Quality.test.cpp">
<Filter>ripple\app\book\tests</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\app\book\tests\Taker.test.cpp">
<Filter>ripple\app\book\tests</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\app\book\Types.h">
<Filter>ripple\app\book</Filter>
</ClInclude>
Expand Down Expand Up @@ -3114,15 +3117,6 @@
<ClCompile Include="..\..\src\ripple\app\transactors\CreateOffer.cpp">
<Filter>ripple\app\transactors</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\app\transactors\CreateOffer.h">
<Filter>ripple\app\transactors</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\app\transactors\CreateOfferBridged.cpp">
<Filter>ripple\app\transactors</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\app\transactors\CreateOfferDirect.cpp">
<Filter>ripple\app\transactors</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\app\transactors\CreateTicket.cpp">
<Filter>ripple\app\transactors</Filter>
</ClCompile>
Expand Down
2 changes: 1 addition & 1 deletion src/BeastConfig.h
Expand Up @@ -186,7 +186,7 @@
This determines whether ripple implements offer autobridging via XRP.
*/
#ifndef RIPPLE_ENABLE_AUTOBRIDGING
#define RIPPLE_ENABLE_AUTOBRIDGING 0
#define RIPPLE_ENABLE_AUTOBRIDGING 1
#endif

/** Config: RIPPLE_SINGLE_IO_SERVICE_THREAD
Expand Down
58 changes: 40 additions & 18 deletions src/ripple/app/book/Offer.h
Expand Up @@ -30,6 +30,7 @@
#include <beast/utility/noexcept.h>

#include <ostream>
#include <stdexcept>

namespace ripple {
namespace core {
Expand All @@ -42,13 +43,20 @@ class Offer
private:
SLE::pointer m_entry;
Quality m_quality;
Account m_account;

mutable Amounts m_amounts;

public:
Offer() = default;

Offer (SLE::pointer const& entry, Quality quality)
: m_entry (entry)
, m_quality (quality)
, m_account (m_entry->getFieldAccount160 (sfAccount))
, m_amounts (
m_entry->getFieldAmount (sfTakerPays),
m_entry->getFieldAmount (sfTakerGets))
{
}

Expand All @@ -62,54 +70,68 @@ class Offer
original quality.
*/
Quality const
quality() const noexcept
quality () const noexcept
{
return m_quality;
}

/** Returns the account id of the offer's owner. */
Account const
account() const
Account const&
owner () const
{
return m_entry->getFieldAccount160 (sfAccount);
return m_account;
}

/** Returns the in and out amounts.
Some or all of the out amount may be unfunded.
*/
Amounts const
amount() const
Amounts const&
amount () const
{
return Amounts (
m_entry->getFieldAmount (sfTakerPays),
m_entry->getFieldAmount (sfTakerGets));
return m_amounts;
}

/** Returns `true` if no more funds can flow through this offer. */
bool
fully_consumed() const
fully_consumed () const
{
if (m_entry->getFieldAmount (sfTakerPays) <= zero)
if (m_amounts.in <= zero)
return true;
if (m_entry->getFieldAmount (sfTakerGets) <= zero)
if (m_amounts.out <= zero)
return true;
return false;
}

/** Returns the ledger entry underlying the offer. */
// AVOID USING THIS
SLE::pointer
entry() const noexcept
/** Adjusts the offer to indicate that we consumed some (or all) of it. */
void
consume (LedgerView& view, Amounts const& consumed) const
{
if (consumed.in > m_amounts.in)
throw std::logic_error ("can't consume more than is available.");

if (consumed.out > m_amounts.out)
throw std::logic_error ("can't produce more than is available.");

m_amounts.in -= consumed.in;
m_amounts.out -= consumed.out;

m_entry->setFieldAmount (sfTakerPays, m_amounts.in);
m_entry->setFieldAmount (sfTakerGets, m_amounts.out);

view.entryModify (m_entry);
}

std::string id () const
{
return m_entry;
return to_string (m_entry->getIndex());
}
};

inline
std::ostream&
operator<< (std::ostream& os, Offer const& offer)
{
return os << offer.entry()->getIndex();
return os << offer.id ();
}

}
Expand Down
11 changes: 0 additions & 11 deletions src/ripple/app/book/OfferStream.h
Expand Up @@ -104,17 +104,6 @@ class OfferStream
*/
bool
step ();

/** Advance to the next valid offer that is not from the specified account.
This automatically removes:
- Offers with missing ledger entries
- Offers found unfunded
- Offers from the same account
- Expired offers
@return `true` if there is a valid offer.
*/
bool
step_account (Account const& account);
};

}
Expand Down

0 comments on commit 3ccbd7c

Please sign in to comment.