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: suggested changes for optimization and code organisation #133

Closed

Conversation

dhruv-chauhan
Copy link
Contributor

The PR changes:

  • upgrade API, specVersion, and @graphprotocol packages
  • make event entities immutable
  • contract calls only when required, inside getOrCreate methods
  • refactored code to make it more organized and readable, without changing schema/logic

Dev deployment: https://thegraph.com/hosted-service/subgraph/dhruv-chauhan/venus-subgraph-2
*(though the dev deployment is still syncing, checking initial data with the official subgraph looks good)

Copy link

@jmulq jmulq left a comment

Choose a reason for hiding this comment

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

Left a comment regarding a function change. Have any RPC calls been removed in these optimisations? If so, which ones?

@dhruv-chauhan
Copy link
Contributor Author

Have any RPC calls been removed in these optimisations? If so, which ones?

Other than one time - non avoidable RPC calls to create Comptroller and Market entities, updating Market entities on change in accrualBlockNumber is very RPC calls heavy - which again looks necessary. Hence, there's not much we can do about these calls.

@jmulq

getOrCreateAccountVTokenTransaction,
getOrCreateComptroller,
getOrCreateMarket,
} from '../operations/getOrCreate';
Copy link
Collaborator

Choose a reason for hiding this comment

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

It looks like we lost some things here like update and create functions.

The update helpers ideally wouldn't create an entity but would only update existing entities. Create would be used when we know that an entity doesn't exist and getOrCreate is used mostly for convenience and typing because get isn't guaranteed.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Another difference between create and update is that create would have default values while update would not have default values

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @coreyar, the new getOrCreate methods handles all - creating, getting and updating internally and just calling it will give you an updated entity at any point. There is no loss of functionality.

// earlier
market = getMarket(id)
if (!market) market = createMarket(id)
updateMarket(market)

// is same as
market = getOrCreateMarket(id)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I like the organization of the functions so that you had fine grained control over interactions with the subgraph.
For example, we want to use get in situations where an entity should be guaranteed and throw a critical error if it doesn't exist. Or explicitly create when we know it doesn't exist. The idea was to be more imperative in the interactions with the store. All other repos we reworked to follow this pattern as well.

If I was to revisit this I'd want to define a new approach and then update all the subgraphs to match it. My goal is to keep all of our subgraphs as consistent in style and patterns as possible.

@coreyar coreyar changed the base branch from develop to main January 24, 2024 15:01
comptroller.closeFactor = comptrollerContract.closeFactorMantissa();
comptroller.liquidationIncentive = comptrollerContract.liquidationIncentiveMantissa();
comptroller.maxAssets = comptrollerContract.maxAssets();
const marketId = marketAddress.toHexString();
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: Could use the market getter here

import { nullAddress } from '../constants/addresses';

// checks if a call reverted, in case it is we return -1 to indicate the wanted value is not available
export function valueOrNotAvailableIntIfReverted(
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: organize in separate files like other subgraphs

@coreyar
Copy link
Collaborator

coreyar commented Jan 29, 2024

@dhruv-chauhan Great work on this! Thank you for contributing. I pulled your changes into another branch so I could open a PR and run some tests. I made a couple more commits for consistency with the other subgraph repos and fixed 1 failing test. Thanks again! 🙌

Edit: Changes were added to #138

@coreyar coreyar closed this Jan 29, 2024
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.

3 participants