-
Notifications
You must be signed in to change notification settings - Fork 1.7k
refactor: Move reserve checks from preclaim to doApply where relevant #7607
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
Changes from all commits
db0371a
49735d1
0c7aa43
f53b810
2ed9a69
2185a1e
3c64c3c
f4cfe0b
a504034
eed58b7
8bb462a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,19 +78,16 @@ PaymentChannelCreate::preclaim(PreclaimContext const& ctx) | |
| return terNO_ACCOUNT; | ||
|
|
||
| // Check reserve and funds availability | ||
| if (!ctx.view.rules().enabled(featureSponsor)) | ||
| { | ||
| auto const balance = (*sle)[sfBalance]; | ||
| auto const sponsorSle = getTxReserveSponsor(ctx.view, ctx.tx); | ||
| if (!sponsorSle) | ||
| return sponsorSle.error(); // LCOV_EXCL_LINE | ||
| if (auto const ret = | ||
| checkInsufficientReserve(ctx.view, ctx.tx, sle, balance, *sponsorSle, 1, 0, ctx.j); | ||
| !isTesSuccess(ret)) | ||
| return ret; | ||
| auto const fees = ctx.view.fees(); | ||
| auto const reserve = fees.reserve + fees.increment * ((*sle)[sfOwnerCount] + 1); | ||
|
|
||
| if (auto const ret = checkInsufficientReserve( | ||
| ctx.view, ctx.tx, sle, balance - ctx.tx[sfAmount], *sponsorSle, 1, 0, ctx.j); | ||
| !isTesSuccess(ret)) | ||
| if (balance < reserve) | ||
| return tecINSUFFICIENT_RESERVE; | ||
|
|
||
| if (balance < reserve + ctx.tx[sfAmount]) | ||
| return tecUNFUNDED; | ||
| } | ||
|
|
||
|
|
@@ -137,6 +134,28 @@ PaymentChannelCreate::doApply() | |
| return tecEXPIRED; | ||
| } | ||
|
|
||
| if (ctx_.view().rules().enabled(featureSponsor)) | ||
| { | ||
| auto const sponsorSle = getTxReserveSponsor(ctx_.view(), ctx_.tx); | ||
| if (!sponsorSle) | ||
| return sponsorSle.error(); | ||
| if (auto const ret = checkInsufficientReserve( | ||
|
depthfirst-app[bot] marked this conversation as resolved.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The mehod name
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would consider that out of scope of this PR but I'll take note of it |
||
| ctx_.view(), ctx_.tx, sle, STAmount{preFeeBalance_}, *sponsorSle, 1, 0, j_); | ||
| !isTesSuccess(ret)) | ||
| return ret; | ||
| if (auto const ret = checkInsufficientReserve( | ||
| ctx_.view(), | ||
| ctx_.tx, | ||
| sle, | ||
| STAmount{preFeeBalance_ - ctx_.tx[sfAmount].xrp()}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unsigned underflow: subtraction can wrap if |
||
| {}, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Second
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Second |
||
| 1, | ||
| 0, | ||
| j_); | ||
| !isTesSuccess(ret)) | ||
| return tecUNFUNDED; | ||
| } | ||
|
|
||
| auto const dst = ctx_.tx[sfDestination]; | ||
|
|
||
| // Create PayChan in ledger. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.