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

reservation timestamp check #990

Merged
merged 5 commits into from
Dec 12, 2024
Merged

reservation timestamp check #990

merged 5 commits into from
Dec 12, 2024

Conversation

hopeyen
Copy link
Contributor

@hopeyen hopeyen commented Dec 12, 2024

Why are these changes needed?

Utilize the start and end timestamp to check if the reservation is active. Updated the name from ActiveReservation to ReservedPayment to make it less confusing and consistent with OnDemandPayment

Checks

  • I've made sure the tests are passing. Note that there might be a few flaky tests, in that case, please comment that they are not relevant.
  • I've checked the new test coverage and the coverage percentage didn't drop.
  • Testing Strategy
    • Unit tests
    • Integration tests
    • This PR is not tested :(

@hopeyen hopeyen force-pushed the hope/reservations-time-check branch 2 times, most recently from 1c3a952 to 23f862b Compare December 12, 2024 17:36
@hopeyen hopeyen requested a review from ian-shim December 12, 2024 17:36
Copy link
Contributor

@ian-shim ian-shim left a 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
Copy link
Contributor

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,
Copy link
Contributor

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())
Copy link
Contributor

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

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

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

are all ReservedPayments guaranteed to have these timestamps populated?

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor Author

@hopeyen hopeyen Dec 12, 2024

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 🤔 ?

Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep!

@hopeyen hopeyen force-pushed the hope/reservations-time-check branch from fdc6bed to 42b42fa Compare December 12, 2024 20:53
@hopeyen hopeyen requested a review from ian-shim December 12, 2024 21:08
@hopeyen hopeyen merged commit 7b12ebf into master Dec 12, 2024
9 checks passed
@hopeyen hopeyen deleted the hope/reservations-time-check branch December 12, 2024 22:23
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