-
Notifications
You must be signed in to change notification settings - Fork 31
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
base: master
Are you sure you want to change the base?
Add Max Payout Flag #2238
Conversation
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.
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.
tools/settlement/bitflyer/upload.go
Outdated
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) |
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 not seen us anywhere parse from a string value into a decimal.Decimal
. Is it missing? From the looks of it, it is.
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.
Excellent catch.
tools/settlement/cmd/uphold.go
Outdated
maxAmountInterface := ctx.Value(appctx.PayoutTxnMaxAmountCTXKey) | ||
maxAmount, ok := maxAmountInterface.(decimal.Decimal) |
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.
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.
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.
You are, of course, correct about the loop. Fixed.
tools/settlement/gemini/upload.go
Outdated
maxAmountInterface := ctx.Value(appctx.PayoutTxnMaxAmountCTXKey) | ||
maxAmount, ok := maxAmountInterface.(decimal.Decimal) |
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.
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.
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.
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") |
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.
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.
maxAmountAny := ctx.Value(appctx.PayoutTxnMaxAmountCTXKey) | ||
maxAmount, ok := maxAmountAny.(decimal.Decimal) | ||
if !ok { | ||
logger.Panic().Err(err).Msg("provided max amount is not a number") |
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.
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) |
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.
Re: panic – same comment as above.
Co-authored-by: Pavel Brm <[email protected]>
Co-authored-by: Pavel Brm <[email protected]>
Co-authored-by: Pavel Brm <[email protected]>
@Sneagan Can this be closed? |
Summary
Add a max payout flag for existing payout tooling.
Type of Change
Tested Environments
Before Requesting Review