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

refactor: required quorum number contract read #1148

Merged
merged 2 commits into from
Jan 24, 2025

Conversation

hopeyen
Copy link
Contributor

@hopeyen hopeyen commented Jan 23, 2025

Why are these changes needed?

Disperser client making On-demand request occasionally runs into this failure from the disperser

panic: error while calling DisperseBlob: rpc error: code = ResourceExhausted desc = invalid on-demand request: failed to get on-demand quorum numbers: abi: attempting to unmarshal an empty string while arguments are expected

Since required quorum number is unlikely to change and is refreshed occasionally, I think we are comfortable using the cached value in case the contract read fails, instead of failing the dispersal request

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 :(

@@ -67,7 +67,11 @@ func NewOnchainPaymentState(ctx context.Context, tx *eth.Reader) (*OnchainPaymen
}

func (pcs *OnchainPaymentState) GetPaymentVaultParams(ctx context.Context) (*PaymentVaultParams, error) {
quorumNumbers, err := pcs.GetOnDemandQuorumNumbers(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

don't we need to keep this in order to make the cache work?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, we still have this on line#74 and it is calling tx directly instead of using the helper function, and the helper function is basically this but with cache

Copy link
Contributor

Choose a reason for hiding this comment

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

ah got it!

@@ -192,7 +196,13 @@ func (pcs *OnchainPaymentState) GetOnDemandQuorumNumbers(ctx context.Context) ([
if err != nil {
return nil, err
}
return pcs.tx.GetRequiredQuorumNumbers(ctx, blockNumber)
quorumNumbers, err := pcs.tx.GetRequiredQuorumNumbers(ctx, blockNumber)
if err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

log error?

if err != nil {
// On demand required quorum is unlikely to change, so we are comfortable using the cached value
// in case the contract read fails
return pcs.PaymentVaultParams.Load().OnDemandQuorumNumbers, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

what if pcs.PaymentVaultParams.Load() is nil or pcs.PaymentVaultParams.Load().OnDemandQuorumNumbers is empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hmm I don't think we can get here if payment vault params is nil, because this only get called after Meterer has obtained the onchain state successfully, and can OnDemandQuorumNumbers ever be empty? If the protocol set it as empty on-chain, we should be okay to return an empty array as well and have the later checks be consistent with 'no required quroum numbers', would you agree?

I am going to add the checks anyway for additional security and not rely on the external logic 🤔

@hopeyen hopeyen force-pushed the hope/contract-read-fallback branch from 38200f2 to 73d4cf0 Compare January 23, 2025 21:39
@@ -192,7 +198,21 @@ func (pcs *OnchainPaymentState) GetOnDemandQuorumNumbers(ctx context.Context) ([
if err != nil {
return nil, err
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 want to read from cache if this fails too?

Copy link
Contributor Author

@hopeyen hopeyen Jan 24, 2025

Choose a reason for hiding this comment

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

Payment vault doesn't cache block number so we can't read from cache. I don't think it makes sense to cache block number neither, because block number updates should be consistent and constant, while required quorums might never get updated. If we failed to read a block number, I don't think we should continue reading the chain from a historical block

in short, no? if you have other concerns I'm open to change

@@ -67,7 +67,11 @@ func NewOnchainPaymentState(ctx context.Context, tx *eth.Reader) (*OnchainPaymen
}

func (pcs *OnchainPaymentState) GetPaymentVaultParams(ctx context.Context) (*PaymentVaultParams, error) {
quorumNumbers, err := pcs.GetOnDemandQuorumNumbers(ctx)
Copy link
Contributor

Choose a reason for hiding this comment

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

ah got it!

@hopeyen hopeyen merged commit 0e2be0c into master Jan 24, 2025
9 checks passed
@hopeyen hopeyen deleted the hope/contract-read-fallback branch January 24, 2025 03:50
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