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 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
13 changes: 0 additions & 13 deletions src/ripple/app/tx/impl/Escrow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
#include <ripple/app/misc/HashRouter.h>
#include <ripple/basics/Log.h>
#include <ripple/basics/XRPAmount.h>
#include <ripple/basics/chrono.h>
#include <ripple/basics/safe_cast.h>
#include <ripple/conditions/Condition.h>
#include <ripple/conditions/Fulfillment.h>
Expand Down Expand Up @@ -78,18 +77,6 @@ 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)
{
return now.time_since_epoch().count() > mark;
}

TxConsequences
EscrowCreate::makeTxConsequences(PreflightContext const& ctx)
{
Expand Down
8 changes: 7 additions & 1 deletion src/ripple/app/tx/impl/PayChan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <ripple/app/tx/impl/PayChan.h>
#include <ripple/basics/Log.h>
#include <ripple/basics/XRPAmount.h>
#include <ripple/basics/chrono.h>
#include <ripple/ledger/ApplyView.h>
#include <ripple/ledger/View.h>
#include <ripple/protocol/Feature.h>
Expand Down Expand Up @@ -249,6 +248,13 @@ PayChanCreate::doApply()
if (!sle)
return tefINTERNAL;

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

auto const dst = ctx_.tx[sfDestination];

// Create PayChan in ledger.
Expand Down
9 changes: 9 additions & 0 deletions src/ripple/ledger/View.h
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,15 @@ deleteAMMTrustLine(
std::optional<AccountID> const& ammAccountID,
beast::Journal j);

/** 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.
*/
bool
after(NetClock::time_point now, std::uint32_t mark);

} // namespace ripple

#endif
6 changes: 6 additions & 0 deletions src/ripple/ledger/impl/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1652,4 +1652,10 @@ deleteAMMTrustLine(
return tesSUCCESS;
}

bool
after(NetClock::time_point now, std::uint32_t mark)
{
return now.time_since_epoch().count() > mark;
}

} // namespace ripple
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 = 64;
static constexpr std::size_t numFeatures = 65;

/** 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 @@ -351,6 +351,7 @@ extern uint256 const featureClawback;
extern uint256 const featureXChainBridge;
extern uint256 const fixDisallowIncomingV1;
extern uint256 const featureDID;
extern uint256 const fixPayChanCancelAfter;

} // 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 @@ -458,6 +458,7 @@ REGISTER_FEATURE(AMM, Supported::yes, VoteBehavior::De
REGISTER_FEATURE(XChainBridge, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX (fixDisallowIncomingV1, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FEATURE(DID, Supported::yes, VoteBehavior::DefaultNo);
REGISTER_FIX (fixPayChanCancelAfter, Supported::yes, VoteBehavior::DefaultNo);

// 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);
}
// fixPayChanCancelAfter
// CancelAfter should be greater than close time
{
for (bool const withFixPayChan : {true, false})
{
auto const amend = withFixPayChan
? features
: features - fixPayChanCancelAfter;
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 =
withFixPayChan ? ter(tecEXPIRED) : ter(tesSUCCESS);
env(create(
alice, bob, channelFunds, settleDelay, pk, cancelAfter),
txResult);
}
}
// fixPayChanCancelAfter
// CancelAfter can be equal to the close time
{
for (bool const withFixPayChan : {true, false})
{
auto const amend = withFixPayChan
? features
: features - fixPayChanCancelAfter;
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;
env(create(
alice, bob, channelFunds, settleDelay, pk, cancelAfter),
ter(tesSUCCESS));
}
}
}

void
Expand Down
Loading