-
Notifications
You must be signed in to change notification settings - Fork 178
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
fix: cumulative payment dynamo db unit conversion #979
Conversation
5eab313
to
1a58cb6
Compare
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.
does this PR have the changes made on dynamodb storage?
core/meterer/meterer.go
Outdated
func (m *Meterer) PaymentCharged(numSymbols uint) uint64 { | ||
return uint64(m.SymbolsCharged(numSymbols)) * uint64(m.ChainPaymentState.GetPricePerSymbol()) | ||
func (m *Meterer) PaymentCharged(numSymbols uint) *big.Int { | ||
return big.NewInt(int64(m.SymbolsCharged(numSymbols) * m.ChainPaymentState.GetPricePerSymbol())) |
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 m.SymbolsCharged(numSymbols) * m.ChainPaymentState.GetPricePerSymbol()
ever be greater than max int64?
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.
Highly unlikely 😬 If we induct backwards to find what's allowed by uint64 with our expected price per symbol 447,000,000
then the number of symbols uint64 can charge is 2^64/477,000,000=41,267,883,833.8
. With 1 symbol being 32 bytes, we are going to allow 1,320,572,282,681.7bytes=1.3TB
per blob
The reason I updated this is for consistency in the cumulativePayment
calculations, but I'm happy to revert these changes and just convert the numbers to big.Int if you think that's better?
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.
Yeah converting each values to big int and using num0.Mul(num1)
seems more safe?
no, I think the changes are only how we read from dynamodb. Writing to the db is still the same as before |
core/meterer/offchain_store.go
Outdated
prevPayment, err = strconv.ParseUint(smallerResult[0]["CumulativePayments"].(*types.AttributeValueMemberN).Value, 10, 64) | ||
if err != nil { | ||
return 0, 0, 0, fmt.Errorf("failed to parse previous payment: %w", err) | ||
setPrevPayment, success := prevPayment.SetString(smallerResult[0]["CumulativePayments"].(*types.AttributeValueMemberN).Value, 10) |
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 know these values are all expected in the happy path, but this chain seems dangerous
It's missing at least a couple validations: checking if "CumulativePayments"
exists in the map and the result of the type assertion
Here and below as well
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.
added explicit checking for them!
core/meterer/meterer.go
Outdated
func (m *Meterer) PaymentCharged(numSymbols uint) uint64 { | ||
return uint64(m.SymbolsCharged(numSymbols)) * uint64(m.ChainPaymentState.GetPricePerSymbol()) | ||
func (m *Meterer) PaymentCharged(numSymbols uint) *big.Int { | ||
return big.NewInt(int64(m.SymbolsCharged(numSymbols) * m.ChainPaymentState.GetPricePerSymbol())) |
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.
Yeah converting each values to big int and using num0.Mul(num1)
seems more safe?
1a58cb6
to
f53dae8
Compare
Why are these changes needed?
Quick PR to move away from using dynamoDB
cumulativePayment
value touint64
usingstrconv.ParseUint
; directly convert to big.IntChecks