Skip to content

Permission DEX #5404

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 21 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 33 additions & 7 deletions include/xrpl/protocol/Book.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#define RIPPLE_PROTOCOL_BOOK_H_INCLUDED

#include <xrpl/basics/CountedObject.h>
#include <xrpl/basics/base_uint.h>
#include <xrpl/protocol/Issue.h>

#include <boost/utility/base_from_member.hpp>
Expand All @@ -36,12 +37,17 @@ class Book final : public CountedObject<Book>
public:
Issue in;
Issue out;
std::optional<uint256> domain;

Book()
{
}

Book(Issue const& in_, Issue const& out_) : in(in_), out(out_)
Book(
Issue const& in_,
Issue const& out_,
std::optional<uint256> const& domain_ = std::nullopt)
: in(in_), out(out_), domain(domain_)
{
}
};
Expand All @@ -61,6 +67,8 @@ hash_append(Hasher& h, Book const& b)
{
using beast::hash_append;
hash_append(h, b.in, b.out);
if (b.domain)
hash_append(h, *(b.domain));
}

Book
Expand All @@ -71,7 +79,8 @@ reversed(Book const& book);
[[nodiscard]] inline constexpr bool
operator==(Book const& lhs, Book const& rhs)
{
return (lhs.in == rhs.in) && (lhs.out == rhs.out);
return (lhs.in == rhs.in) && (lhs.out == rhs.out) &&
(lhs.domain == rhs.domain);
}
/** @} */

Expand All @@ -82,7 +91,18 @@ operator<=>(Book const& lhs, Book const& rhs)
{
if (auto const c{lhs.in <=> rhs.in}; c != 0)
return c;
return lhs.out <=> rhs.out;
if (auto const c{lhs.out <=> rhs.out}; c != 0)
return c;

// Manually compare optionals
if (lhs.domain && rhs.domain)
return *lhs.domain <=> *rhs.domain; // Compare values if both exist
if (!lhs.domain && rhs.domain)
return std::weak_ordering::less; // Empty is considered less
if (lhs.domain && !rhs.domain)
return std::weak_ordering::greater; // Non-empty is greater

return std::weak_ordering::equivalent; // Both are empty
}
/** @} */

Expand Down Expand Up @@ -126,9 +146,11 @@ template <>
struct hash<ripple::Book>
{
private:
using hasher = std::hash<ripple::Issue>;
using issue_hasher = std::hash<ripple::Issue>;
using uint256_hasher = ripple::uint256::hasher;

hasher m_hasher;
issue_hasher m_issue_hasher;
uint256_hasher m_uint256_hasher;

public:
explicit hash() = default;
Expand All @@ -139,8 +161,12 @@ struct hash<ripple::Book>
value_type
operator()(argument_type const& value) const
{
value_type result(m_hasher(value.in));
boost::hash_combine(result, m_hasher(value.out));
value_type result(m_issue_hasher(value.in));
boost::hash_combine(result, m_issue_hasher(value.out));

if (value.domain)
boost::hash_combine(result, m_uint256_hasher(*value.domain));

return result;
}
};
Expand Down
5 changes: 4 additions & 1 deletion include/xrpl/protocol/ErrorCodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,10 @@ enum error_code_i {
// Simulate
rpcTX_SIGNED = 96,

rpcLAST = rpcTX_SIGNED // rpcLAST should always equal the last code.
// Pathfinding
rpcDOMAIN_MALFORMED = 97,

rpcLAST = rpcDOMAIN_MALFORMED // rpcLAST should always equal the last code.
};

/** Codes returned in the `warnings` array of certain RPC commands.
Expand Down
1 change: 1 addition & 0 deletions include/xrpl/protocol/LedgerFormats.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ enum LedgerSpecificFlags {
// ltOFFER
lsfPassive = 0x00010000,
lsfSell = 0x00020000, // True, offer was placed as a sell.
lsfHybrid = 0x00040000, // True, offer is hybrid.

// ltRIPPLE_STATE
lsfLowReserve = 0x00010000, // True, if entry counts toward reserve.
Expand Down
3 changes: 2 additions & 1 deletion include/xrpl/protocol/TxFlags.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,9 @@ constexpr std::uint32_t tfPassive = 0x00010000;
constexpr std::uint32_t tfImmediateOrCancel = 0x00020000;
constexpr std::uint32_t tfFillOrKill = 0x00040000;
constexpr std::uint32_t tfSell = 0x00080000;
constexpr std::uint32_t tfHybrid = 0x00100000;
constexpr std::uint32_t tfOfferCreateMask =
~(tfUniversal | tfPassive | tfImmediateOrCancel | tfFillOrKill | tfSell);
~(tfUniversal | tfPassive | tfImmediateOrCancel | tfFillOrKill | tfSell | tfHybrid);

// Payment flags:
constexpr std::uint32_t tfNoRippleDirect = 0x00010000;
Expand Down
1 change: 1 addition & 0 deletions include/xrpl/protocol/detail/features.macro
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
// If you add an amendment here, then do not forget to increment `numFeatures`
// in include/xrpl/protocol/Feature.h.

XRPL_FEATURE(PermissionedDEX, Supported::yes, VoteBehavior::DefaultNo)
XRPL_FIX (PayChanCancelAfter, Supported::yes, VoteBehavior::DefaultNo)
// Check flags in Credential transactions
XRPL_FIX (InvalidTxFlags, Supported::yes, VoteBehavior::DefaultNo)
Expand Down
3 changes: 3 additions & 0 deletions include/xrpl/protocol/detail/ledger_entries.macro
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ LEDGER_ENTRY(ltDIR_NODE, 0x0064, DirectoryNode, directory, ({
{sfNFTokenID, soeOPTIONAL},
{sfPreviousTxnID, soeOPTIONAL},
{sfPreviousTxnLgrSeq, soeOPTIONAL},
{sfDomainID, soeOPTIONAL}
}))

/** The ledger object which lists details about amendments on the network.
Expand Down Expand Up @@ -248,6 +249,8 @@ LEDGER_ENTRY(ltOFFER, 0x006f, Offer, offer, ({
{sfPreviousTxnID, soeREQUIRED},
{sfPreviousTxnLgrSeq, soeREQUIRED},
{sfExpiration, soeOPTIONAL},
{sfDomainID, soeOPTIONAL},
{sfAdditionalBooks, soeOPTIONAL},
}))

/** A ledger object which describes a deposit preauthorization.
Expand Down
2 changes: 2 additions & 0 deletions include/xrpl/protocol/detail/sfields.macro
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,7 @@ UNTYPED_SFIELD(sfSignerEntry, OBJECT, 11)
UNTYPED_SFIELD(sfNFToken, OBJECT, 12)
UNTYPED_SFIELD(sfEmitDetails, OBJECT, 13)
UNTYPED_SFIELD(sfHook, OBJECT, 14)
UNTYPED_SFIELD(sfBook, OBJECT, 15)

// inner object (uncommon)
UNTYPED_SFIELD(sfSigner, OBJECT, 16)
Expand Down Expand Up @@ -362,6 +363,7 @@ UNTYPED_SFIELD(sfMemos, ARRAY, 9)
UNTYPED_SFIELD(sfNFTokens, ARRAY, 10)
UNTYPED_SFIELD(sfHooks, ARRAY, 11)
UNTYPED_SFIELD(sfVoteSlots, ARRAY, 12)
UNTYPED_SFIELD(sfAdditionalBooks, ARRAY, 13)

// array of objects (uncommon)
UNTYPED_SFIELD(sfMajorities, ARRAY, 16)
Expand Down
3 changes: 2 additions & 1 deletion include/xrpl/protocol/detail/transactions.macro
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ TRANSACTION(ttPAYMENT, 0, Payment, ({
{sfDestinationTag, soeOPTIONAL},
{sfDeliverMin, soeOPTIONAL, soeMPTSupported},
{sfCredentialIDs, soeOPTIONAL},
{sfDomainID, soeOPTIONAL},
}))

/** This transaction type creates an escrow object. */
Expand Down Expand Up @@ -93,6 +94,7 @@ TRANSACTION(ttOFFER_CREATE, 7, OfferCreate, ({
{sfTakerGets, soeREQUIRED},
{sfExpiration, soeOPTIONAL},
{sfOfferSequence, soeOPTIONAL},
{sfDomainID, soeOPTIONAL},
}))

/** This transaction type cancels existing offers to trade one asset for another. */
Expand Down Expand Up @@ -499,4 +501,3 @@ TRANSACTION(ttUNL_MODIFY, 102, UNLModify, ({
{sfLedgerSequence, soeREQUIRED},
{sfUNLModifyValidator, soeREQUIRED},
}))

3 changes: 2 additions & 1 deletion src/libxrpl/protocol/ErrorCodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ constexpr static ErrorInfo unorderedErrorInfos[]{
{rpcUNKNOWN_COMMAND, "unknownCmd", "Unknown method.", 405},
{rpcORACLE_MALFORMED, "oracleMalformed", "Oracle request is malformed.", 400},
{rpcBAD_CREDENTIALS, "badCredentials", "Credentials do not exist, are not accepted, or have expired.", 400},
{rpcTX_SIGNED, "transactionSigned", "Transaction should not be signed.", 400}};
{rpcTX_SIGNED, "transactionSigned", "Transaction should not be signed.", 400},
{rpcDOMAIN_MALFORMED, "domainMalformed", "Domain is malformed", 400}};
// clang-format on

// Sort and validate unorderedErrorInfos at compile time. Should be
Expand Down
19 changes: 13 additions & 6 deletions src/libxrpl/protocol/Indexes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,19 @@ getBookBase(Book const& book)
XRPL_ASSERT(
isConsistent(book), "ripple::getBookBase : input is consistent");

auto const index = indexHash(
LedgerNameSpace::BOOK_DIR,
book.in.currency,
book.out.currency,
book.in.account,
book.out.account);
auto const index = book.domain ? indexHash(
LedgerNameSpace::BOOK_DIR,
book.in.currency,
book.out.currency,
book.in.account,
book.out.account,
*(book.domain))
: indexHash(
LedgerNameSpace::BOOK_DIR,
book.in.currency,
book.out.currency,
book.in.account,
book.out.account);

// Return with quality 0.
auto k = keylet::quality({ltDIR_NODE, index}, 0);
Expand Down
7 changes: 7 additions & 0 deletions src/libxrpl/protocol/InnerObjectFormats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ InnerObjectFormats::InnerObjectFormats()
{sfIssuer, soeREQUIRED},
{sfCredentialType, soeREQUIRED},
});

add(sfBook.jsonName,
sfBook.getCode(),
{
{sfBookDirectory, soeREQUIRED},
{sfBookNode, soeREQUIRED},
});
}

InnerObjectFormats const&
Expand Down
1 change: 1 addition & 0 deletions src/test/app/AMMExtended_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2156,6 +2156,7 @@ struct AMMExtended_test : public jtx::AMMTest
OfferCrossing::no,
std::nullopt,
smax,
std::nullopt,
flowJournal);
}();

Expand Down
7 changes: 5 additions & 2 deletions src/test/app/CrossingLimits_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,8 +558,11 @@ class CrossingLimits_test : public beast::unit_test::suite
using namespace jtx;
auto const sa = supported_amendments();
testAll(sa);
testAll(sa - featureFlowSortStrands);
testAll(sa - featureFlowCross - featureFlowSortStrands);
testAll(sa - featurePermissionedDEX);
testAll(sa - featureFlowSortStrands - featurePermissionedDEX);
testAll(
sa - featureFlowCross - featureFlowSortStrands -
featurePermissionedDEX);
}
};

Expand Down
4 changes: 3 additions & 1 deletion src/test/app/DeliverMin_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,9 @@ class DeliverMin_test : public beast::unit_test::suite
{
using namespace jtx;
auto const sa = supported_amendments();
test_convert_all_of_an_asset(sa - featureFlowCross);
test_convert_all_of_an_asset(
sa - featureFlowCross - featurePermissionedDEX);
test_convert_all_of_an_asset(sa - featurePermissionedDEX);
test_convert_all_of_an_asset(sa);
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/test/app/Discrepancy_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ class Discrepancy_test : public beast::unit_test::suite
{
using namespace test::jtx;
auto const sa = supported_amendments();
testXRPDiscrepancy(sa - featureFlowCross);
testXRPDiscrepancy(sa - featureFlowCross - featurePermissionedDEX);
testXRPDiscrepancy(sa - featurePermissionedDEX);
testXRPDiscrepancy(sa);
}
};
Expand Down
15 changes: 10 additions & 5 deletions src/test/app/Flow_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,7 @@ struct Flow_test : public beast::unit_test::suite
OfferCrossing::no,
std::nullopt,
smax,
std::nullopt,
flowJournal);
}();

Expand Down Expand Up @@ -1475,7 +1476,8 @@ struct Flow_test : public beast::unit_test::suite

using namespace jtx;
auto const sa = supported_amendments();
testWithFeats(sa - featureFlowCross);
testWithFeats(sa - featureFlowCross - featurePermissionedDEX);
testWithFeats(sa - featurePermissionedDEX);
testWithFeats(sa);
testEmptyStrand(sa);
}
Expand All @@ -1490,13 +1492,16 @@ struct Flow_manual_test : public Flow_test
auto const all = supported_amendments();
FeatureBitset const flowCross{featureFlowCross};
FeatureBitset const f1513{fix1513};
FeatureBitset const permDex{featurePermissionedDEX};

testWithFeats(all - flowCross - f1513);
testWithFeats(all - flowCross);
testWithFeats(all - f1513);
testWithFeats(all - flowCross - f1513 - permDex);
testWithFeats(all - flowCross - permDex);
testWithFeats(all - f1513 - permDex);
testWithFeats(all - permDex);
testWithFeats(all);

testEmptyStrand(all - f1513);
testEmptyStrand(all - f1513 - permDex);
testEmptyStrand(all - permDex);
testEmptyStrand(all);
}
};
Expand Down
8 changes: 5 additions & 3 deletions src/test/app/Freeze_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2020,9 +2020,11 @@ class Freeze_test : public beast::unit_test::suite
};
using namespace test::jtx;
auto const sa = supported_amendments();
testAll(sa - featureFlowCross - featureDeepFreeze);
testAll(sa - featureFlowCross);
testAll(sa - featureDeepFreeze);
testAll(
sa - featureFlowCross - featureDeepFreeze - featurePermissionedDEX);
testAll(sa - featureFlowCross - featurePermissionedDEX);
testAll(sa - featureDeepFreeze - featurePermissionedDEX);
testAll(sa - featurePermissionedDEX);
testAll(sa);
}
};
Expand Down
Loading
Loading