Skip to content
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

fixPayChanV1 #4717

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 10 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
19 changes: 19 additions & 0 deletions src/ripple/app/tx/impl/PayChan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ namespace ripple {

//------------------------------------------------------------------------------

/** Has the specified time passed?

@param now the current time
@param mark the cutoff point
@return true if \a now refers to a time strictly after \a mark, else false.
*/
static inline bool
after(NetClock::time_point now, std::uint32_t mark)
dangell7 marked this conversation as resolved.
Show resolved Hide resolved
{
return now.time_since_epoch().count() > mark;
}

static TER
closeChannel(
std::shared_ptr<SLE> const& slep,
Expand Down Expand Up @@ -271,6 +283,13 @@ PayChanCreate::doApply()
(*slep)[~sfSourceTag] = ctx_.tx[~sfSourceTag];
(*slep)[~sfDestinationTag] = ctx_.tx[~sfDestinationTag];

if (ctx_.view().rules().enabled(fixPayChanV1))
{
auto const closeTime = ctx_.view().info().parentCloseTime;
if (ctx_.tx[~sfCancelAfter] && after(closeTime, ctx_.tx[sfCancelAfter]))
return tecEXPIRED;
}

ctx_.view().insert(slep);

// Add PayChan to owner directory
Expand Down
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 = 62;
static constexpr std::size_t numFeatures = 63;

/** 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 @@ -349,6 +349,7 @@ extern uint256 const fixNFTokenRemint;
extern uint256 const fixReducedOffersV1;
extern uint256 const featureClawback;
extern uint256 const featureXChainBridge;
extern uint256 const fixPayChanV1;
dangell7 marked this conversation as resolved.
Show resolved Hide resolved

} // 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 @@ -456,6 +456,7 @@ REGISTER_FIX (fixReducedOffersV1, Supported::yes, VoteBehavior::De
REGISTER_FEATURE(Clawback, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FEATURE(AMM, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FEATURE(XChainBridge, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX (fixPayChanV1, Supported::yes, VoteBehavior::DefaultNo);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be Yes by default? Per my understanding, every fix amendment shout have vote by default set to yes.

REGISTER_FEATURE(fixPayChanV1, Supported::yes, VoteBehavior::DefaultYes);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look above at all the fixes that don't have the VoteBehavior::DefaultYes.

Yes is reserved for things that need immediate approval. This doesn't need immediate approval imo.

I'm happy to change it though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would advocate for keeping it as is, to avoid risk of amendment blocking, since this is not critical.


// The following amendments are obsolete, but must remain supported
// because they could potentially get enabled.
Expand Down
46 changes: 46 additions & 0 deletions src/test/app/PayChan_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,52 @@ struct PayChan_test : public beast::unit_test::suite
BEAST_EXPECT(!channelExists(*env.current(), chan));
BEAST_EXPECT(env.balance(alice) == preAlice + channelFunds);
}
// fixPayChanV1
// CancelAfter should be greater than close time
{
for (bool const withFixPayChanV1 : {true, false})
{
auto const amend =
withFixPayChanV1 ? features : features - fixPayChanV1;
Env env{*this, amend};
env.fund(XRP(10000), alice, bob);
env.close();

auto const pk = alice.pk();
auto const settleDelay = 100s;
auto const channelFunds = XRP(1000);
NetClock::time_point const cancelAfter =
env.current()->info().parentCloseTime - 1s;
auto const txResult =
withFixPayChanV1 ? ter(tecEXPIRED) : ter(tesSUCCESS);
env(create(
alice, bob, channelFunds, settleDelay, pk, cancelAfter),
txResult);
}
}
// fixPayChanV1
// CancelAfter can be equal to the close time
{
for (bool const withFixPayChanV1 : {true, false})
{
auto const amend =
withFixPayChanV1 ? features : features - fixPayChanV1;
Env env{*this, amend};
env.fund(XRP(10000), alice, bob);
env.close();

auto const pk = alice.pk();
auto const settleDelay = 100s;
auto const channelFunds = XRP(1000);
NetClock::time_point const cancelAfter =
env.current()->info().parentCloseTime;
auto const txResult =
withFixPayChanV1 ? ter(tesSUCCESS) : ter(tesSUCCESS);
dangell7 marked this conversation as resolved.
Show resolved Hide resolved
env(create(
alice, bob, channelFunds, settleDelay, pk, cancelAfter),
txResult);
}
}
}

void
Expand Down