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

feat: Add support for multiple chain ids in EpochChainsInfo API #369

Merged
merged 26 commits into from
May 3, 2023

Conversation

gusin13
Copy link
Contributor

@gusin13 gusin13 commented Apr 30, 2023

Description

This PR is part of optimizations done to improve babylon-api performance.

Explorer currently calls EpochChainInfo ( /babylon/zoneconcierge/v1/chain_info/{chain_id}/epochs/{epoch_num} ) multiple times for each chain. This PR replaces EpochChainInfo with EpochChainsInfo which can ingest a range of chain ids for a given epoch and retrieve epoch info for multiple chains at once.

Testing

Added fuzz , e2e tests and cli query.

@gusin13 gusin13 marked this pull request as ready for review May 2, 2023 10:45
@gusin13 gusin13 changed the base branch from BM-603-api-add-new-rpc-queries-finalized to dev May 2, 2023 17:42
@gusin13 gusin13 force-pushed the BM-606-optimize-epoch-chains-info-rpc branch from 3d268ea to ed2aa8a Compare May 2, 2023 17:47
Copy link
Member

@vitsalis vitsalis left a comment

Choose a reason for hiding this comment

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

Looks good! Some suggestions:

s.FailNow("Epoch 2 should be finalized")
}
// Check we have epoch info for opposing chain and some basic assertions
epochChainsInfo, err := nonValidatorNode.QueryEpochChainsInfo(3, []string{initialization.ChainBID})
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
epochChainsInfo, err := nonValidatorNode.QueryEpochChainsInfo(3, []string{initialization.ChainBID})
epochChainsInfo, err := nonValidatorNode.QueryEpochChainsInfo(endEpoch, []string{initialization.ChainBID})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure fixed.

return cmd
}

func CmdChainsInfo() *cobra.Command {
cmd := &cobra.Command{
Use: "chains-info <chain-ids>",
Short: "retrieves the latest info for a list of chains with given IDs",
Short: "returns the latest info for a given list of chains",
Copy link
Member

Choose a reason for hiding this comment

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

Here we changed "retrieves" to "returns", but the method below still has "retrieves". tbh I prefer the "retrieves" but np with both, but let's be consistent

Copy link
Contributor Author

@gusin13 gusin13 May 3, 2023

Choose a reason for hiding this comment

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

sure np, have changed back to retrieve

Comment on lines 84 to 88
var epoch uint64
_, err := fmt.Sscanf(args[0], "%d", &epoch)
if err != nil {
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var epoch uint64
_, err := fmt.Sscanf(args[0], "%d", &epoch)
if err != nil {
return err
}
epoch, err := strconv.ParseUint(args[0], 10, 64)
if err != nil {
return err
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure fixed.

x/zoneconcierge/client/cli/query.go Show resolved Hide resolved
for i := uint64(0); i < numReqs; i++ {
resp, err := zcKeeper.EpochChainInfo(ctx, &zctypes.QueryEpochChainInfoRequest{EpochNum: epochNumList[i], ChainId: czChain.ChainID})
for epoch, info := range epochToChainInfo {
resp, err := zcKeeper.EpochChainsInfo(ctx, &zctypes.QueryEpochChainsInfoRequest{EpochNum: epoch, ChainIds: []string{info.chainID}})
Copy link
Member

Choose a reason for hiding this comment

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

Now that we have the capability to query for multiple chains we should take advantage of it. This test looks like the convertion of the 1-chainID case to work with the new syntax. Let's test the fact that we can query many different chains at the same time. Let's also test that we handle duplicates properly and reject stuff that's over the request limit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, have added more tests now.

@gusin13 gusin13 requested a review from vitsalis May 3, 2023 15:22
@gusin13 gusin13 merged commit 58ba7e5 into dev May 3, 2023
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