Skip to content

Commit

Permalink
Introduce the NonFungibleTokensV1_1 amendment:
Browse files Browse the repository at this point in the history
The XLS-20 implementation contained two bugs that would require the
introduction of amendments. This complicates the adoption of XLS-20
by requiring a staggered amendment activation, first of the two fix
amendments, followed by the `NonFungibleTokensV1` amendment.

After consideration, the consensus among node operators is that the
process should be simplified by the introduction of a new amendment
that, if enabled, would behaves as if the `NonFungibleTokensV1` and
the two fix amendments (`fixNFTokenDirV1` and `fixNFTokenNegOffer`)
were activated at once.

This commit implements this proposal; it does not introduce any new
functionality or additional features, above and beyond that offered
by the existing amendments.
  • Loading branch information
nbougalis committed Jul 18, 2022
1 parent 9eb303f commit 59326bb
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/ripple/protocol/Feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace detail {
// Feature.cpp. Because it's only used to reserve storage, and determine how
// large to make the FeatureBitset, it MAY be larger. It MUST NOT be less than
// the actual number of amendments. A LogicError on startup will verify this.
static constexpr std::size_t numFeatures = 49;
static constexpr std::size_t numFeatures = 50;

/** Amendments that this server supports and the default voting behavior.
Whether they are enabled depends on the Rules defined in the validated
Expand Down Expand Up @@ -337,6 +337,7 @@ extern uint256 const featureNonFungibleTokensV1;
extern uint256 const featureExpandedSignerList;
extern uint256 const fixNFTokenDirV1;
extern uint256 const fixNFTokenNegOffer;
extern uint256 const featureNonFungibleTokensV1_1;

} // namespace ripple

Expand Down
1 change: 1 addition & 0 deletions src/ripple/protocol/impl/Feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ REGISTER_FEATURE(NonFungibleTokensV1, Supported::yes, DefaultVote::no)
REGISTER_FEATURE(ExpandedSignerList, Supported::yes, DefaultVote::no);
REGISTER_FIX (fixNFTokenDirV1, Supported::yes, DefaultVote::no);
REGISTER_FIX (fixNFTokenNegOffer, Supported::yes, DefaultVote::no);
REGISTER_FEATURE(NonFungibleTokensV1_1, Supported::yes, DefaultVote::no);

// The following amendments have been active for at least two years. Their
// pre-amendment code has been removed and the identifiers are deprecated.
Expand Down
18 changes: 14 additions & 4 deletions src/ripple/protocol/impl/Rules.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@
*/
//==============================================================================

#include <ripple/protocol/Feature.h>
#include <ripple/protocol/Rules.h>

#include <ripple/protocol/Indexes.h>

namespace ripple {

class Rules::Impl
Expand All @@ -40,9 +39,8 @@ class Rules::Impl
std::unordered_set<uint256, beast::uhash<>> const& presets,
std::optional<uint256> const& digest,
STVector256 const& amendments)
: presets_(presets)
: presets_(presets), digest_(digest)
{
digest_ = digest;
set_.reserve(amendments.size());
set_.insert(amendments.begin(), amendments.end());
}
Expand Down Expand Up @@ -83,6 +81,18 @@ bool
Rules::enabled(uint256 const& feature) const
{
assert(impl_);

// The functionality of the "NonFungibleTokensV1_1" amendment is
// precisely the functionality of the following three amendments
// so if their status is ever queried individually, we inject an
// extra check here to simplify the checking elsewhere.
if (feature == featureNonFungibleTokensV1 ||
feature == fixNFTokenNegOffer || feature == fixNFTokenDirV1)
{
if (impl_->enabled(featureNonFungibleTokensV1_1))
return true;
}

return impl_->enabled(feature);
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/app/NFTokenDir_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,8 @@ class NFTokenDir_test : public beast::unit_test::suite
{
using namespace test::jtx;
FeatureBitset const all{supported_amendments()};
FeatureBitset const fixNFTDir{fixNFTokenDirV1};
FeatureBitset const fixNFTDir{
fixNFTokenDirV1, featureNonFungibleTokensV1_1};

testWithFeats(all - fixNFTDir);
testWithFeats(all);
Expand Down
15 changes: 11 additions & 4 deletions src/test/app/NFToken_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ class NFToken_test : public beast::unit_test::suite
{
// If the NFT amendment is not enabled, you should not be able
// to create or burn NFTs.
Env env{*this, features - featureNonFungibleTokensV1};
Env env{
*this,
features - featureNonFungibleTokensV1 -
featureNonFungibleTokensV1_1};
Account const& master = env.master;

BEAST_EXPECT(ownerCount(env, master) == 0);
Expand Down Expand Up @@ -4650,7 +4653,8 @@ class NFToken_test : public beast::unit_test::suite

// Test both with and without fixNFTokenNegOffer
for (auto const& tweakedFeatures :
{features - fixNFTokenNegOffer, features | fixNFTokenNegOffer})
{features - fixNFTokenNegOffer - featureNonFungibleTokensV1_1,
features | fixNFTokenNegOffer})
{
// There was a bug in the initial NFT implementation that
// allowed offers to be placed with negative amounts. Verify
Expand Down Expand Up @@ -4759,7 +4763,9 @@ class NFToken_test : public beast::unit_test::suite
// Test what happens if NFTokenOffers are created with negative amounts
// and then fixNFTokenNegOffer goes live. What does an acceptOffer do?
{
Env env{*this, features - fixNFTokenNegOffer};
Env env{
*this,
features - fixNFTokenNegOffer - featureNonFungibleTokensV1_1};

env.fund(XRP(1000000), issuer, buyer, gw);
env.close();
Expand Down Expand Up @@ -4844,7 +4850,8 @@ class NFToken_test : public beast::unit_test::suite
// Test buy offers with a destination with and without
// fixNFTokenNegOffer.
for (auto const& tweakedFeatures :
{features - fixNFTokenNegOffer, features | fixNFTokenNegOffer})
{features - fixNFTokenNegOffer - featureNonFungibleTokensV1_1,
features | fixNFTokenNegOffer})
{
Env env{*this, tweakedFeatures};

Expand Down

0 comments on commit 59326bb

Please sign in to comment.