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

Add Max Payout Flag #2238

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Add Max Payout Flag #2238

wants to merge 9 commits into from

Conversation

Sneagan
Copy link
Contributor

@Sneagan Sneagan commented Dec 5, 2023

Summary

Add a max payout flag for existing payout tooling.

Type of Change

  • Product feature
  • Bug fix
  • Performance improvement
  • Refactor
  • Other

Tested Environments

  • Development
  • Staging
  • Production

Before Requesting Review

  • Does your code build cleanly without any errors or warnings?
  • Have you used auto closing keywords?
  • Have you added tests for new functionality?
  • Have validated query efficiency for new database queries?
  • Have documented new functionality in README or in comments?
  • Have you squashed all intermediate commits?
  • Is there a clear title that explains what the PR does?
  • Have you used intuitive function, variable and other naming?
  • Have you requested security and/or privacy review if needed
  • Have you performed a self review of this PR?

Copy link
Contributor

@pavelbrm pavelbrm left a comment

Choose a reason for hiding this comment

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

Not ready to approve – unless I am wrong, there is missing part that parses the supplied limit into a decimal, and then that decimal is put in the context. Also, the code can be adjusted so that we don't do the same work again in the loops.

dryRun *bitflyer.DryRunOption,
token string,
settlementRequests []settlement.AggregateTransaction,
) (*bitflyer.WithdrawToDepositIDBulkPayload, error) {
set := []custodian.Transaction{}
sourceFrom := ""
maxAmountInterface := ctx.Value(appctx.PayoutTxnMaxAmountCTXKey)
maxAmount, ok := maxAmountInterface.(decimal.Decimal)
Copy link
Contributor

Choose a reason for hiding this comment

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

I have not seen us anywhere parse from a string value into a decimal.Decimal. Is it missing? From the looks of it, it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Excellent catch.

Comment on lines 247 to 248
maxAmountInterface := ctx.Value(appctx.PayoutTxnMaxAmountCTXKey)
maxAmount, ok := maxAmountInterface.(decimal.Decimal)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar comment as above – nowhere do we parse the string value into a decimal and put it in the context. It's a string here, hence the type assertion never succeeds.

Also, it's a waste to do this step in the loop – is the limit going to change between iterations? Seems unlikely, therefore it must be terminated outside of the loop.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are, of course, correct about the loop. Fixed.

Comment on lines 288 to 289
maxAmountInterface := ctx.Value(appctx.PayoutTxnMaxAmountCTXKey)
maxAmount, ok := maxAmountInterface.(decimal.Decimal)
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to the case above, two issues – it's not a decimal yet, and we are wasting resources doing the same work in the loop.

Copy link
Contributor

@pavelbrm pavelbrm left a comment

Choose a reason for hiding this comment

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

Ready to approve as it is (with some comments), but the CI is showing ❌ , which indicates this is not ready to be merged.

Tag me when the tests have been fixed. 😸

maxAmountAny := ctx.Value(appctx.PayoutTxnMaxAmountCTXKey)
maxAmount, ok := maxAmountAny.(decimal.Decimal)
if !ok {
return nil, errors.New("provided max amount is not an integer")
Copy link
Contributor

Choose a reason for hiding this comment

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

If there's any intent to make this unit-testable in the future, then replacing this with a pre-defined sentinel error (which can be tested against) would be good.

tools/settlement/bitflyer/upload.go Outdated Show resolved Hide resolved
tools/settlement/cmd/uphold.go Outdated Show resolved Hide resolved
maxAmountAny := ctx.Value(appctx.PayoutTxnMaxAmountCTXKey)
maxAmount, ok := maxAmountAny.(decimal.Decimal)
if !ok {
logger.Panic().Err(err).Msg("provided max amount is not a number")
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Surrounding places to use Panic, but the function we are in does return an error. We could return and error and handle it in the caller if we wanted a panic. But also, what value does a panic over error bring here?

for i := 0; i < total; i++ {
settlementTransaction := &settlementState.Transactions[i]

if settlementTransaction.IsComplete() || settlementTransaction.IsFailed() {
continue
}

if settlementTransaction.Amount.GreaterThan(maxAmount) {
logger.Panic().Err(err).Msgf("amount %s exceeds the max %s", settlementTransaction.Amount, maxAmount)
Copy link
Contributor

Choose a reason for hiding this comment

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

Re: panic – same comment as above.

tools/settlement/gemini/upload.go Outdated Show resolved Hide resolved
@pavelbrm
Copy link
Contributor

pavelbrm commented Nov 5, 2024

@Sneagan Can this be closed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants