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

Feature/add stake entities and params #26

Merged

Conversation

Alann27
Copy link
Contributor

@Alann27 Alann27 commented Oct 29, 2024

Summary

  • Added the following entities that can be staked and their related messages/events:
    • Application
    • Supplier
    • Gateway.

The functionality to save the this entities from the genesis were added too.

  • Added functionality to parse params from genesis and update the parameters that came in an authz exec transaction.

Details

  • The following entities related to Service were added:
    • Service: This entity represents a specific service with their current state.
    • AddServiceMsg: message emitted when a service is added.
  • The following entities related to Application were added:
    • Application: This entity represents a specific application with their current state.
    • ApplicationDelegatedToGateway: many-to-many relationship between Application and Gateway representing the delegation of an application to a gateway.
    • ApplicationService: many-to-many relationship between Application and Service representing the service staked to an application.
    • TransferApplicationBeginEvent: event emitted when an application started their transfer process.
    • TransferApplicationEndEvent: event emitted when an application ended their transfer process.
    • TransferApplicationErrorEvent: event emitted when an application failed to be transferred.
    • EventApplicationUnbondingBegin: event emitted when an application started their unbonding process.
    • EventApplicationUnbondingEnd: event emitted when an application ended their unbonding process.
    • AppMsgStake: message emitted when an application its staked (or re-staked).
    • AppMsgStakeService: many-to-many relationship between AppMsgStake and Service representing the service staked to an application in a specific AppMsgStake.
    • AppMsgUnstake: message emitted when an application its unstaked.
    • MsgDelegateToGateway: message emitted when an application its delegated to a gateway.
    • MsgUndelegateToGateway: message emitted when an application it's undelegated from a gateway.
    • MsgTransferApplication: message emitted when an application its transferred to another address.
  • The following entities related to Supplier were added:
    • Supplier: This entity represents a specific supplier with their current state.
    • SupplierMsgStake: message emitted when a supplier its staked (or re-staked).
    • SupplierMsgStakeService: many-to-many relationship between SupplierMsgStake and Service representing the service staked to a supplier in a specific SupplierMsgStake.
    • SupplierMsgUnstake: message emitted when a supplier its unstaked.
    • SupplierService: many-to-many relationship between Supplier and Service representing the service staked to a supplier.
    • SupplierUnbondingBeginEvent: event emitted when a supplier started their unbonding process.
    • SupplierUnbondingEndEvent: event emitted when a supplier ended their unbonding process.
  • The following entities related to Gateway were added:
    • Gateway: This entity represents a specific gateway with their current state.
    • GatewayStakeMsg: message emitted when a gateway its staked (or re-staked).
    • GatewayUnstakeMsg: message emitted when a gateway its unstaked.
    • GatewayUnstakedEvent: event emitted when a gateway its unstaked.

To be able to handle the parameters update, we added a new handler called handleAuthzExec. This is a message handler that is called when a message is executed by the authz module and inside of it, it has encoded messages like MsgUpdateParams. We are decoding those MsgUpdateParams and updating the parameters accordingly.

  • The following entities related to parameters were added:
    • AuthzExec: authz module execution message.
    • AuthzExecMessage: many-to-many relationship between AuthzExec and Message representing the message that was executed by the authz module.
    • AppParams: application module parameters.
    • AuthParam: auth module parameters.
    • BankParam: bank module parameters.
    • DistributionParam: distribution module parameters.
    • GatewayParam: gateway module parameters.
    • GovParam: gov module parameters.
    • MintParam: mint module parameters.
    • ProofParam: proof module parameters.
    • ServiceParam: service module parameters.
    • SessionParam: session module parameters.
    • SharedParams: shared module parameters.
    • SlashingParam: slashing module parameters.
    • StakingParam: staking module parameters.
    • SupplierParam: supplier module parameters.
    • TokenomicsParam: tokenomics module parameters.
    • ConsensusParam: consensus module parameters.

Other changes

  • Created genesis.ts file to handle the genesis parsing.
  • Updated import of GeneratedType inside src/cosmjs directory to add type to the import statement.
  • Updated version of @subql/node-cosmos to ^4.1.4. This version includes the fix to the block events not being emitted.
  • Updated version of @subql/cli to ^5.3.0 and @subql/types-cosmos to ^4.0.0.
  • Added global.ts file to fix an issue with the method getFieldsBy of store.
  • Updated code where events were being handled because block events not include msg and tx fields.

Issue

  • Update @subql/node-cosmos to ^4.1.4 so we can handle the block events.
  • Add functionality to save Applications, Suppliers, Gateways, and Services.
  • ADd functionality to parse params from genesis and update the parameters that came in an authz exec transaction.

Type of change

Select one or more:

  • New feature, functionality or library
  • Bug fix
  • Code health or cleanup
  • Documentation
  • Other (specify)

Sanity Checklist

  • I have tested my changes using the available tooling
  • I have commented my code
  • I have performed a self-review of my own code; both comments & source code
  • I create and reference any new tickets, if applicable
  • I have left TODOs throughout the codebase, if applicable

…s, added global.ts file to fix an issue caused via the new version of `@subql/types-cosmos` dependency, changed type of computeUnitsPerRelay to BigInt
@Alann27 Alann27 marked this pull request as ready for review November 6, 2024 16:49
@jorgecuesta jorgecuesta added the enhancement New feature or request label Nov 6, 2024
@Olshansk Olshansk removed their request for review November 6, 2024 19:08
@Olshansk
Copy link
Member

Olshansk commented Nov 6, 2024

@bryanchriswhite PTAL when you have a chance.

…he fields of the entities, changed enums for int, added missing params to block
@Alann27 Alann27 force-pushed the feature/add-stake-entities-and-params branch from 5838bd8 to 3609a42 Compare November 7, 2024 19:53
Copy link
Collaborator

@jorgecuesta jorgecuesta left a comment

Choose a reason for hiding this comment

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

LGTM. Great job @Alann27

schema.graphql Show resolved Hide resolved
schema.graphql Show resolved Hide resolved
schema.graphql Show resolved Hide resolved
src/mappings/authz/exec.ts Outdated Show resolved Hide resolved
src/mappings/authz/exec.ts Outdated Show resolved Hide resolved
src/mappings/authz/exec.ts Outdated Show resolved Hide resolved
src/mappings/authz/exec.ts Outdated Show resolved Hide resolved
src/mappings/genesis.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@bryanchriswhite bryanchriswhite left a comment

Choose a reason for hiding this comment

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

Great work @Alann27! 🙌 Thanks for all the effort it undoubtedly took to get to this point, I love seeing the indexer come together! 😍 🚀

I'm out of time on this for this morning but will resume review again after I've made some progress on other things:

image


Some very general feedback: there's waaaay too much going on here for anyone to review as thoroughly as this deserves to be reviewed, especially at this particular stage of the project. High quality review depends on reviewers being able to reason about the entire change holistically. In my view, this perspective is what makes the review context so incredibly useful as compared to the development context. Without clear boundaries between changes though, it becomes extremely difficult to form a holistic picture without risking omitting some relevant detail that's gotten lost in the noise of unrelated changes or being otherwise distracted by unrelated changes.

Going forward, (pretty) please prefer to open several smaller PRs over one large one. It makes review orders of magnitude easier for everyone. 🙏🙏🙏🙏

My number 1 recommendation to facilitate this is to commit related changes frequently. Even if it's not clear from the outset what changes you're going to be making and how it naturally makes sense to organize them, if you prefer many small commits over fewer larger ones, it becomes much more easy to rearrange and squash related changes such that it is then trivial to split the unrelated changes into separate branches, prior to review. If you would like to chat about this in more detail, I would be more than happy to discuss it over a screensharing session or something.

To give you a concrete example, I would've split this PR into the following:

  • Update poktroll protobuf files
  • Add parameter update indexing
  • Add service module indexing
  • Add gateway module indexing
  • Add application module indexing
  • Add supplier module indexing
  • Refactor genesis processing
  • Add authz message indexing

src/cosmjs/proto/bank.ts Show resolved Hide resolved
src/mappings/utils.ts Outdated Show resolved Hide resolved
src/mappings/authz/exec.ts Outdated Show resolved Hide resolved
src/mappings/authz/exec.ts Outdated Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

NO ACTION REQUIRED AT THIS TIME

I think we should start thinking about how to split this file up and reorganize the contents. Additionally, there seems to be another utils.ts file in src/cosmjs. IMHO "utils" files/packages/modules/etc. are generally an antipattern, indicative of a need to reorganize/restructure.

schema.graphql Outdated Show resolved Hide resolved
schema.graphql Outdated
id: ID!
source: Application!
destination: Application!
transaction: Transaction
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
transaction: Transaction
transaction: Transaction # End-block event; never has tx

Copy link
Contributor

Choose a reason for hiding this comment

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

(bump)

schema.graphql Outdated
source: Application!
destination: Account!
error: String!
transaction: Transaction
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
transaction: Transaction
transaction: Transaction # End-block event; never has tx

Copy link
Contributor

Choose a reason for hiding this comment

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

(bump)

schema.graphql Outdated
reason: Int!
sessionEndHeight: BigInt!
unstakingEndHeight: BigInt!
transaction: Transaction
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
transaction: Transaction
transaction: Transaction # End-block event; never has tx

Copy link
Contributor

Choose a reason for hiding this comment

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

(bump)

schema.graphql Show resolved Hide resolved
Copy link
Contributor

@bryanchriswhite bryanchriswhite left a comment

Choose a reason for hiding this comment

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

I have to stop again for this morning but this is coming along amazingly! 🙌 Thank you for your persistence and patience. 💪 🙏

image

ACK re: enum types. We can revisit once SubQuery releases the update that makes GQL enums indexable.

My feedback seems to mostly be about consistency in the following areas:

  1. Message and event types include relations to all their primitives
  2. Message and event entity naming (with protobuf types)
  3. Join table entity naming (i.e. Entity1Entity2)
  4. "Similar" field names (e.g. begin/end block/height fields) AND which fields (blocks / heights / both).

schema.graphql Outdated Show resolved Hide resolved
schema.graphql Outdated
id: ID!
source: Application!
destination: Application!
transaction: Transaction
Copy link
Contributor

Choose a reason for hiding this comment

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

(bump)

schema.graphql Outdated
source: Application!
destination: Account!
error: String!
transaction: Transaction
Copy link
Contributor

Choose a reason for hiding this comment

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

(bump)

schema.graphql Outdated
reason: Int!
sessionEndHeight: BigInt!
unstakingEndHeight: BigInt!
transaction: Transaction
Copy link
Contributor

Choose a reason for hiding this comment

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

(bump)

schema.graphql Outdated Show resolved Hide resolved
schema.graphql Outdated Show resolved Hide resolved
schema.graphql Outdated Show resolved Hide resolved
schema.graphql Outdated Show resolved Hide resolved
schema.graphql Show resolved Hide resolved
schema.graphql Outdated Show resolved Hide resolved
src/mappings/poktroll/suppliers.ts Outdated Show resolved Hide resolved
Comment on lines +307 to +309
service: Service!
revShare: [SupplierRevShare]!
endpoints: [SupplierEndpoint]!
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
service: Service!
revShare: [SupplierRevShare]!
endpoints: [SupplierEndpoint]!
serviceConfigs: [SupplierServiceConfig]!

schema.graphql Show resolved Hide resolved
schema.graphql Outdated Show resolved Hide resolved
schema.graphql Outdated Show resolved Hide resolved
Copy link
Contributor

@bryanchriswhite bryanchriswhite left a comment

Choose a reason for hiding this comment

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

Almost there! 😅

image

schema.graphql Show resolved Hide resolved
schema.graphql Show resolved Hide resolved
Comment on lines +307 to +309
service: Service!
revShare: [SupplierRevShare]!
endpoints: [SupplierEndpoint]!
Copy link
Contributor

Choose a reason for hiding this comment

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

(bump)

Do you disagree here?

src/mappings/poktroll/suppliers.ts Outdated Show resolved Hide resolved
src/mappings/poktroll/suppliers.ts Outdated Show resolved Hide resolved
schema.graphql Outdated Show resolved Hide resolved
schema.graphql Outdated Show resolved Hide resolved
schema.graphql Outdated Show resolved Hide resolved
src/mappings/genesis.ts Show resolved Hide resolved
src/mappings/utils.ts Show resolved Hide resolved
Copy link
Contributor

@bryanchriswhite bryanchriswhite left a comment

Choose a reason for hiding this comment

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

I think this may be the last round of feedback - thank you so much for bearing with me! 🙌 🙇‍♂️

This is great work @Alann27! 🚀 🚀

src/mappings/genesis.ts Outdated Show resolved Hide resolved
src/mappings/genesis.ts Outdated Show resolved Hide resolved
src/mappings/genesis.ts Show resolved Hide resolved
src/mappings/genesis.ts Show resolved Hide resolved
src/mappings/poktroll/applications.ts Show resolved Hide resolved
src/mappings/poktroll/gateways.ts Show resolved Hide resolved
src/mappings/types/global.ts Show resolved Hide resolved
@jorgecuesta jorgecuesta mentioned this pull request Nov 18, 2024
10 tasks
Copy link
Contributor

@bryanchriswhite bryanchriswhite left a comment

Choose a reason for hiding this comment

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

🚀 🚀 🚀 🚀 🚀

Comment on lines +3 to +6
// This declaration resolves a type mismatch with the `store.getByField` method
// in the generated files. The original method from the library does not
// support a generic type, which causes TypeScript errors when used with generics.
// To fix this, we redefine the `getByField` method to explicitly accept a generic type.
Copy link
Contributor

Choose a reason for hiding this comment

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

👌

@jorgecuesta jorgecuesta merged commit 5ecfc6b into pokt-network:main Nov 19, 2024
4 checks passed
@jorgecuesta jorgecuesta mentioned this pull request Nov 19, 2024
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

4 participants