-
Notifications
You must be signed in to change notification settings - Fork 179
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
reservation timestamp check #990
Conversation
1c3a952
to
23f862b
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.
lgtm, just few comments
core/data.go
Outdated
@@ -606,7 +607,7 @@ func ConvertToPaymentMetadata(ph *commonpb.PaymentHeader) *PaymentMetadata { | |||
|
|||
// OperatorInfo contains information about an operator which is stored on the blockchain state, | |||
// corresponding to a particular quorum | |||
type ActiveReservation struct { | |||
type ReservedPayment struct { | |||
SymbolsPerSecond uint64 // reserve number of symbols per second | |||
//TODO: we are not using start and end timestamp, add check or remove |
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 this TODO still relevant? Maybe we can update the documentation here for two timestamps.
Also nit: comments should be line above the fields starting with the name of the field
core/data.go
Outdated
@@ -606,7 +607,7 @@ func ConvertToPaymentMetadata(ph *commonpb.PaymentHeader) *PaymentMetadata { | |||
|
|||
// OperatorInfo contains information about an operator which is stored on the blockchain state, |
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: update the comment?
core/data.go
Outdated
@@ -625,3 +626,8 @@ type BlobVersionParameters struct { | |||
MaxNumOperators uint32 | |||
NumChunks uint32 | |||
} | |||
|
|||
func (ar *ReservedPayment) IsActive() bool { | |||
now := uint64(time.Now().Unix()) |
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.
do we have unit tests for active/inactive reservations?
would be useful to take this timestamp as input for testing
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 unit tests!
core/data.go
Outdated
|
||
func (ar *ReservedPayment) IsActive() bool { | ||
now := uint64(time.Now().Unix()) | ||
return ar.StartTimestamp <= now && ar.EndTimestamp >= now |
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.
are all ReservedPayment
s guaranteed to have these timestamps populated?
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 think yes, because before we make ReservedPayments, they go through the convert function 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.
If reservation has zero timestamps and non-zero values for other fields, looks like it would still get converted successfully
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, that is only for valid reservations, but this check should handle checking if the reservation is active or not
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 don't think I understand what are your concerns 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.
My concern is whether it's possible to have a valid reservation that's missing EndTimestamp
for example.
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 guess the current logic would ignore those reservations if they're missing any timestamps
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.
Yep!
fdc6bed
to
42b42fa
Compare
Why are these changes needed?
Utilize the start and end timestamp to check if the reservation is active. Updated the name from
ActiveReservation
toReservedPayment
to make it less confusing and consistent withOnDemandPayment
Checks