mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-19 10:35:50 +00:00
fix: fixPayChanV1 (#4717)
This change introduces a new fix amendment (`fixPayChanV1`) that prevents the creation of new `PaymentChannelCreate` transaction with a `CancelAfter` time less than the current ledger time. It piggy backs off of fix1571. Once the amendment is activated, creating a new `PaymentChannel` will require that if you specify the `CancelAfter` time/value, that value must be greater than or equal to the current ledger time. Currently users can create a payment channel where the `CancelAfter` time is before the current ledger time. This results in the payment channel being immediately closed on the next PaymentChannel transaction.
This commit is contained in:
@@ -32,6 +32,7 @@
|
|||||||
// If you add an amendment here, then do not forget to increment `numFeatures`
|
// If you add an amendment here, then do not forget to increment `numFeatures`
|
||||||
// in include/xrpl/protocol/Feature.h.
|
// in include/xrpl/protocol/Feature.h.
|
||||||
|
|
||||||
|
XRPL_FIX (PayChanCancelAfter, Supported::yes, VoteBehavior::DefaultNo)
|
||||||
// Check flags in Credential transactions
|
// Check flags in Credential transactions
|
||||||
XRPL_FIX (InvalidTxFlags, Supported::yes, VoteBehavior::DefaultNo)
|
XRPL_FIX (InvalidTxFlags, Supported::yes, VoteBehavior::DefaultNo)
|
||||||
XRPL_FIX (FrozenLPTokenTransfer, Supported::yes, VoteBehavior::DefaultNo)
|
XRPL_FIX (FrozenLPTokenTransfer, Supported::yes, VoteBehavior::DefaultNo)
|
||||||
|
|||||||
@@ -402,6 +402,52 @@ struct PayChan_test : public beast::unit_test::suite
|
|||||||
BEAST_EXPECT(!channelExists(*env.current(), chan));
|
BEAST_EXPECT(!channelExists(*env.current(), chan));
|
||||||
BEAST_EXPECT(env.balance(alice) == preAlice + channelFunds);
|
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
|
void
|
||||||
|
|||||||
@@ -76,18 +76,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
|
TxConsequences
|
||||||
EscrowCreate::makeTxConsequences(PreflightContext const& ctx)
|
EscrowCreate::makeTxConsequences(PreflightContext const& ctx)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -252,6 +252,13 @@ PayChanCreate::doApply()
|
|||||||
if (!sle)
|
if (!sle)
|
||||||
return tefINTERNAL;
|
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];
|
auto const dst = ctx_.tx[sfDestination];
|
||||||
|
|
||||||
// Create PayChan in ledger.
|
// Create PayChan in ledger.
|
||||||
|
|||||||
@@ -592,6 +592,15 @@ deleteAMMTrustLine(
|
|||||||
std::optional<AccountID> const& ammAccountID,
|
std::optional<AccountID> const& ammAccountID,
|
||||||
beast::Journal j);
|
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
|
} // namespace ripple
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -2123,4 +2123,10 @@ rippleCredit(
|
|||||||
saAmount.asset().value());
|
saAmount.asset().value());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool
|
||||||
|
after(NetClock::time_point now, std::uint32_t mark)
|
||||||
|
{
|
||||||
|
return now.time_since_epoch().count() > mark;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace ripple
|
} // namespace ripple
|
||||||
|
|||||||
Reference in New Issue
Block a user