-
Notifications
You must be signed in to change notification settings - Fork 90
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
refactor(backend): move fee calculation to backend #1755
Conversation
✅ Deploy Preview for brilliant-pasca-3e80ec canceled.
|
// renames sendAmount keys (if any) to debitAmount in limits jsonb column | ||
return knex('accesses') | ||
.update({ | ||
limits: knex.raw( | ||
"limits - 'sendAmount' || jsonb_build_object('debitAmount', limits->'sendAmount')" | ||
) | ||
}) | ||
.whereRaw("limits \\? 'sendAmount'") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is hard to read but I could not find a simpler way. Addresses #1755 (comment)
To test I initialized rafiki with this extra test migration (before 20230907201006_rename-limits-jsonb-keys.js
) which seeds some dummy data: https://gist.github.com/BlairCurrey/094b5df41f36f94befacbf727c3535ef
Then I verified the accesses records matched expectations after rebuilding rafiki from migrations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have to run but here is a first part of a review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that to be backwards compatible? Do we think that is necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, to ensure our renaming efforts dont cause any errors on pre-existing data. There is some discussion in the main body of the PR. My initial reasoning is here: #1755 (comment)
I think it probably is necessary because any existing records will have the old name and the application code has been changed to expect the new one. So it might break something on testnet if we dont do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. I wasn't aware of the discussion and didn't think about testnet. My bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries... I fee like higher level discussion on PR's on gh is kind of a mess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same question as above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this one I guess we could rename it in the model with a get
and set
but I think this is simpler.
debitAmountValue < quote.debitAmount.value || | ||
debitAmountValue <= BigInt(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How would that happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This check already existed and I considered if it was still necessary since we aren't getting the value from the ASE but I wasn't sure, so I left it. I looked at it again though and think it can be removed.
debitAmountValue < quote.debitAmount.value
- would be true if fees are negative (aside from
fees
,debitAmountValue === quote.debitAmount.value
). not possible since we're checking that on fee create
debitAmountValue <= BigInt(0)
- true if
quote.debitAmount.value + fees
is negative. and if fees cant be negative the thequote.debitAmount.value
would have to be, and it cant because we're checking that before returning the ilp quote fromstartQuote
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize it was just a refactor. I also looked more closely now and I think you are right. This can probably be removed since it checks the quote after it is returned from the ASE in the current flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could remove this one OK but I tried the same for fixed send and an existing test failed (which was explicitly looking for this case). Perhaps the inputs shouldn't cause these errors but I think it's probably safer to leave them just in case.
debitAmountValue < quote.debitAmount.value || | ||
debitAmountValue <= BigInt(0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't realize it was just a refactor. I also looked more closely now and I think you are right. This can probably be removed since it checks the quote after it is returned from the ASE in the current flow.
@@ -160,7 +160,7 @@ components: | |||
- createdAt | |||
- updatedAt | |||
- expiresAt | |||
- sendAmount | |||
- debitAmount |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like we have some validation error here. Check in "files changed" if you can't see it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sabineschaller Hmm, I see it. More details from the CI job show the warning:
OpenAPI "servers" must be present and non-empty array
Looks unrelated to this change and we've been getting it for a while:
- 2 months ago: f5c1f66#diff-90da7214f1ef2d21dca042e424b4079b684ab3017fb6c278e4abab4453855f24
- 3 months ago: 22ef1dc#diff-90da7214f1ef2d21dca042e424b4079b684ab3017fb6c278e4abab4453855f24R1
Seems like it needs the servers
attribute defined like we do in some of our other specs. Not sure what would be appropriate. What about something like this (similar to exchange rate yaml)?
servers:
- url: 'https://account-servicing-entity.com/webhooks'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Found the webhook url in some config files and concluded that url is right. I added it which seems to have fixed the warning.
@@ -88,8 +88,6 @@ export const Config = { | |||
incomingPaymentWorkers: envInt('INCOMING_PAYMENT_WORKERS', 1), | |||
incomingPaymentWorkerIdle: envInt('INCOMING_PAYMENT_WORKER_IDLE', 200), // milliseconds | |||
|
|||
quoteUrl: envString('QUOTE_URL', 'http://127.0.0.1:4001/quote'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove that from the integration docs, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also recommend running pnpm generate:types
in the token-introspection package to update the types properly.
Also, I'm not sure if we discussed, but for the documentation API schema, we should be seeing sendAmount
be changed to debitAmount
as well, correct?
@@ -19,7 +19,7 @@ export type Quote = { | |||
paymentType: PaymentType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could remove this file altogether now, right?
will be removed in Nathan's PR
Accept: string | ||
'Content-Type': string | ||
'Rafiki-Signature'?: string | ||
function getFees(fee: Fee | undefined, principal: bigint): bigint { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this method can live in feeService? just a suggestion
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered that as well. I think that's probably a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the method to the model since we already had the fee model here. It felt wrong to pass the fee into the fee service like feeService.calculate(fee, principal)
or to re-lookup the fee. Later if we just have the feeId
or assetId
we can do feeService.calculate(id, principal)
which gets the fee then calls the calculate
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
Co-authored-by: Max Kurapov <max@interledger.org>
Changes proposed in this pull request
sendAmount
todebitAmount
across backendContext
Fixes: #1639 and Fixes: #1640
There are lots of file changes, but it's mostly renaming. More interesting code changes are the
packages/backend/src/open_payments/quote/service.ts
ones.Checklist
fixes #number