-
Notifications
You must be signed in to change notification settings - Fork 239
fix: make disperser client backwards compatible #1686
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: make disperser client backwards compatible #1686
Conversation
TODO: review the Claude generated getPaymentStateFromLegacyAPI... no idea if its OK or not.
api/clients/v2/disperser_client.go
Outdated
// TODO: this was generated by Claude. I haven't checked that it actually makes sense.... SO DO NOT MERGE BEFORE CHECKING THIS. | ||
func convertLegacyPaymentStateToNew(legacyReply *disperser_rpc.GetPaymentStateReply) *disperser_rpc.GetPaymentStateForAllQuorumsReply { |
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.
@hopeyen can you take a look at this function please?
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 the check for conversion makes sense for backward compatibility, and left a few small comments
api/clients/v2/disperser_client.go
Outdated
if legacyReply.Reservation != nil { | ||
// Apply the reservation to all quorums mentioned in the reservation | ||
quorums := legacyReply.Reservation.QuorumNumbers | ||
if len(quorums) == 0 { |
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.
this should be invalid and error out
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.
also GetPaymentStateForAllQuorumsReply fields
The latest Buf updates on your PR. Results from workflow Buf Proto / buf (pull_request).
|
bytes cumulative_payment = 4; | ||
// on-chain on-demand payment deposited | ||
// The bytes are parsed to a big.Int value. | ||
// This value should always be <= cumulative_payment, as the disperser cumulative_payment kept offchain is only periodically updated onchain. |
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.
we currently don't have payment updates on-chain at all, still something to add in the future. It would look something like disperser sees a request containing payment header, account id, and signature. disperser submits the message onchain, contract verifies, update cumulative_payment_used which would always be onchain_cumulative_payment_used <= onchain_cumulative_payment
. then the field above cumulative_payment
must be within these onchain two ranges
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.
from GetPaymentStateForAllQuorumsRequest
return early when no reservation exists, which makes the logic much simpler
api/clients/v2/disperser_client.go
Outdated
MinNumSymbols: legacyReply.PaymentGlobalParams.MinNumSymbols, | ||
// ReservationAdvanceWindow is not used offchain at the moment so it's okay to set to any value. | ||
// It was added for consistency with the onchain data structure but get removed in the future. | ||
ReservationAdvanceWindow: legacyReply.PaymentGlobalParams.ReservationWindow, |
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: perhaps we set this to 0 similar to all the other "Not available in legacy format" fields, for consistency.
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.
api/clients/v2/disperser_client.go
Outdated
} | ||
|
||
// Apply the global params to all quorums mentioned in on-demand quorum numbers | ||
quorums := legacyReply.PaymentGlobalParams.OnDemandQuorumNumbers |
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.
quorums
won't be able to cover custom quorums, but reservations would rely on quorum configurations and the client should apply global params to all quorums it might use. I would suggest constructing quorums
by taking an union of legacyReply.PaymentGlobalParams.OnDemandQuorumNumbers
and legacyReply.Reservation.QuorumNumbers
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.
good catch. fixed in 689f53d
api/clients/v2/disperser_client.go
Outdated
ReservationAdvanceWindow: legacyReply.PaymentGlobalParams.ReservationWindow, | ||
ReservationRateLimitWindow: legacyReply.PaymentGlobalParams.ReservationWindow, | ||
OnDemandRateLimitWindow: 0, // Not available in legacy format | ||
OnDemandEnabled: true, // we are iterating over on-demand quorums, so this is always true |
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 we update the content of quorums
, we might need a separate loop to set field to true for ondemand quorum numbers whereas the default is false
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.
// dispersers unlimited to EigenLabs. | ||
// off-chain on-demand payment usage. | ||
// The bytes are parsed to a big.Int value. | ||
// This value should always be <= cumulative_payment, as the disperser cumulative_payment kept offchain is only periodically updated onchain. |
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.
this description isn't accurate atm. updating the onchain balance is something we have been putting off for the future. There's some proposal on how it updates, verifies, and handling refunds... but nothing has been decided
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.
* chore(apiserver): refactor GetPaymentState to highlight legacy conversion * wip: attempt to make disperser_client backwards compatible TODO: review the Claude generated getPaymentStateFromLegacyAPI... no idea if its OK or not. * docs(apiserver): document convertAllQuorumsReplyToLegacy function * fix(disperser_client): convertLegacyPaymentStateToNew returns error * fix(disperser_client): set correct value for ReservationRateLimitWindow * style: targetting -> targeting * docs: remove outdated TODO comment * docs: add docstring for getPaymentStateFromLegacyAPI * fix: return error if PaymentGlobalParams==nil * docs(proto): document GetPaymentStateReply fields also GetPaymentStateForAllQuorumsReply fields * docs(proto): document why GetPaymentStateRequest is separate type from GetPaymentStateForAllQuorumsRequest * style: remove outdated comment * fix(disperser_client): onDemandEnabled value in convertLegacyPaymentStateToNew * style: better error message in convertLegacyPaymentStateToNew * refactor: convertLegacyPaymentStateToNew function return early when no reservation exists, which makes the logic much simpler * docs(proto): fix inaccurate cumulative_payment docstring * style(disperser_client): set reservationAdvanceWindow to 0 in convertLegacyPaymentStateToNew * fix(disp_client): convertLegacyPaymentStateToNew quorums setting logic * docs(proto): remove wrong cumulative_payment comment * style: remove unneeded comments * style: add comment explaining why append is ok * docs: move reservation_advance_window comment to proto
* chore(apiserver): refactor GetPaymentState to highlight legacy conversion * wip: attempt to make disperser_client backwards compatible TODO: review the Claude generated getPaymentStateFromLegacyAPI... no idea if its OK or not. * docs(apiserver): document convertAllQuorumsReplyToLegacy function * fix(disperser_client): convertLegacyPaymentStateToNew returns error * fix(disperser_client): set correct value for ReservationRateLimitWindow * style: targetting -> targeting * docs: remove outdated TODO comment * docs: add docstring for getPaymentStateFromLegacyAPI * fix: return error if PaymentGlobalParams==nil * docs(proto): document GetPaymentStateReply fields also GetPaymentStateForAllQuorumsReply fields * docs(proto): document why GetPaymentStateRequest is separate type from GetPaymentStateForAllQuorumsRequest * style: remove outdated comment * fix(disperser_client): onDemandEnabled value in convertLegacyPaymentStateToNew * style: better error message in convertLegacyPaymentStateToNew * refactor: convertLegacyPaymentStateToNew function return early when no reservation exists, which makes the logic much simpler * docs(proto): fix inaccurate cumulative_payment docstring * style(disperser_client): set reservationAdvanceWindow to 0 in convertLegacyPaymentStateToNew * fix(disp_client): convertLegacyPaymentStateToNew quorums setting logic * docs(proto): remove wrong cumulative_payment comment * style: remove unneeded comments * style: add comment explaining why append is ok * docs: move reservation_advance_window comment to proto
* Revert "refactor: account ledger interface incorporates debit slip (#1732)" This reverts commit b4cf3d9. * Revert "fix: period record circular wrapping refresh (#1731)" This reverts commit 1091f46. * Revert "fix: disperser_client v2 nil ptr bug (#1710)" This reverts commit a5acd93. * Revert "fix: disperser_client v2 should use default onDemandQuorums (#1700)" This reverts commit 005e0a6. * Revert "refactor: unify accountant debit slip (#1695)" This reverts commit a9c0868. * Revert "feat: AccountantLedger interface for next step unifications (#1694)" This reverts commit 354e42f. * Revert "feat: extract generic payment logic (#1693)" This reverts commit 1003b98. * Revert "fix: make disperser client backwards compatible (#1686)" This reverts commit 26c612f. * Revert "fix: payment state api doesn't fail at zero valued reservations/ondemand (#1682)" This reverts commit 2031c1d. * Revert "refactor: quorum specific metrics for metered bytes (#1668)" This reverts commit 7ac688d. * Revert "feat: GetPaymentStateForAllQuorums api impl (#1664)" This reverts commit ed89588. * Revert "refactor: core meterer consolidation (#1663)" This reverts commit 319a865. * Revert "refactor: onchain state interface (#1662)" This reverts commit d795dfa. * Revert "refactor: core meterer period record module (#1661)" This reverts commit afbef90. * Revert "refactor: payment common functions (#1653)" This reverts commit 36a3d33. * Revert "fix: period index calculation (#1641)" This reverts commit c229748. * Revert "refactor: use generic column name (#1626)" This reverts commit 4d1994e. * Revert "feat: payment onchain state interface (#1625)" This reverts commit 61e46ac. * Revert "feat: offchain quorum period record getter (#1620)" This reverts commit a309139. * Revert "feat: protobuf payment state api quorum specific variant (#1613)" This reverts commit 58acdfd. * Revert "fix: nil assignment to new account (#1612)" This reverts commit bcbf9f5. * Revert "feat: offchain batch writes (#1580)" This reverts commit ce4d2f5. * Revert "feat: validator authenticate on-demand request by disperser key (#1539)" This reverts commit f545b16. * fix: issues after series of reverts (scary) * chore: add back ErrZeroSymbols error This error was likely removed by mistake during a revert conflict fix from one of the previous set of reverted PRs. * style: fix lint * test: fix accountant_test hardcoded error string * Revert "Revert "fix: period index calculation (#1641)"" This reverts commit b8767ae.
Why are these changes needed?
#1664 made the current clients incompatible with our current testnet and mainnet network. This PR is an attempt to make them backwards compatible, but the conversion function was generated by Claude, so @hopeyen please take a look. We can discuss whether this approach makes sense at all.
If it doesn't, then we probably should not have merged this client to master until the testnet and mainnet dispersers are updated with the new disperser apiserver API.
See also this slack thread.
Checks