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

[Bug] Cosmos subgraph indexing wrong 'rewards' event #4998

Closed
1 of 3 tasks
wojciechowskip opened this issue Nov 18, 2023 · 3 comments
Closed
1 of 3 tasks

[Bug] Cosmos subgraph indexing wrong 'rewards' event #4998

wojciechowskip opened this issue Nov 18, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@wojciechowskip
Copy link

Bug report

Hi guys,

I was trying to use cosmoshub subgraph on hosted service to index rewards and proposer_rewards events happening while distributing rewards to validators https://docs.cosmos.network/v0.50/build/modules/distribution#beginblocker.
High level description of events happening
rewards is event which happens every block and this is basically reward for attestation, since there are 180 active validators there should be around 180 rewards events per block
proposer_reward is an event which happens every block but only once, since there is only 1 block proposer chosen before block happens.

Unfortunately even if I am trying to track both events - I am ending up in a situation like both tracked events are resolved to proposer_reward. This can be easily reproduced using example in your documentation -> https://github.com/graphprotocol/graph-tooling/tree/main/examples/cosmos-validator-rewards
Even if query per every block should return around 180 events (since we are not sure validators are always 100% responsive) it is returning only 1 event per block.

My subgraph.yaml:

specVersion: 0.0.5
description: Validator Delegations Example
schema:
  file: ./schema.graphql
dataSources:
  - kind: cosmos
    name: CosmosHub
    network: cosmoshub-4
    source:
      startBlock: 17680000
    mapping:
      apiVersion: 0.0.7
      language: wasm/assemblyscript
      entities:
        - ValidatorReward
      eventHandlers:
        - event: rewards
          handler: handleReward
        - event: proposer_reward
          handler: handleProposerReward
      file: ./src/mapping.ts

My mapping.ts:

export function handleReward(data: cosmos.EventData): void {
  const height = data.block.header.height;

  const amount = data.event.getAttributeValue('amount');
  const validator = data.event.getAttributeValue('validator');

  let reward = new ValidatorReward(`${height}-${validator}`);

  reward.amount = amount;
  reward.validator = validator;
  reward.blockHeight = `${height}`;

  reward.save();
}

export function handleProposerReward(data: cosmos.EventData): void {
  const height = data.block.header.height;

  const amount = data.event.getAttributeValue('reward');
  const validator = data.event.getAttributeValue('validator');

  let reward = new ValidatorProposerReward(`${height}-${validator}`);

  reward.amount = amount;
  reward.validator = validator;
  reward.blockHeight = `${height}`;

  reward.save();
}

My schema:

type ValidatorReward @entity {
  id: ID!
  amount: String!
  validator: String!
  blockHeight: String!
}

type ValidatorProposerReward @entity {
  id: ID!
  amount: String!
  validator: String!
  blockHeight: String!
}

Example query:

query MyQuery {
  validatorRewards(
    first: 10
    where: {blockHeight: "17860023"}
  ) {
    amount
    blockHeight
    validator
  }
  validatorProposerRewards(
    first: 10
    where: {blockHeight: "17860023"}
  ) {
    amount
    blockHeight
    validator
  }
}

Output from query:

{
  "data": {
    "validatorRewards": [
      {
        "amount": "613251.550000000000000000uatom",
        "blockHeight": "17860023",
        "validator": "cosmosvaloper1z8zjv3lntpwxua0rtpvgrcwl0nm0tltgpgs6l7"
      }
    ],
    "validatorProposerRewards": [
      {
        "amount": "",
        "blockHeight": "17860023",
        "validator": "cosmosvaloper1z8zjv3lntpwxua0rtpvgrcwl0nm0tltgpgs6l7"
      }
    ]
  }
}

Problems:

  1. As you can see in attached output - even if we index rewards event there is only one per block - which is not true since there is always around 180 and we can confirm by querying the network
    NODE_RPC_ADDRESS/block_results?height=17860023 (If node was not historical it may be hard to achieve so old data, but every block returns around 180 events of this type)
    What is more validator address related to this indexed rewards event points to an address which did a proposal in this block. So looks like rewards event is trying to point proposer_reward what can be true since there was only one event of that type in this block (and in every other block as well there is only 1).
  2. And the second problem is that if we index proposed_reward and try to extract reward attribute we miss value. Key of this attribute should be 'reward' according to https://docs.cosmos.network/v0.50/build/modules/distribution#beginblocker
    image
    But after some of my tests it looks like it's under 'amount' attribute. Not sure if subgraph is wrong or cosmos documentation is outdated.

Thanks in advance, if needed I can provide more information but I think it should be clear what is the issue and can be easily reproduced even by using example: https://github.com/graphprotocol/graph-tooling/tree/main/examples/cosmos-validator-rewards.

Relevant log output

No response

IPFS hash

No response

Subgraph name or link to explorer

https://thegraph.com/hosted-service/subgraph/wojciechowskip/cosmoshub-4

Some information to help us out

  • Tick this box if this bug is caused by a regression found in the latest release.
  • Tick this box if this bug is specific to the hosted service.
  • I have searched the issue tracker to make sure this issue is not a duplicate.

OS information

None

@wojciechowskip wojciechowskip added the bug Something isn't working label Nov 18, 2023
@cometcrafter
Copy link

Block data from firehose looks fine for this. Looks like it could be an issue in the Graph node end. I'll try to dry-run the logic to find what's the root cause behind this.

@wojciechowskip
Copy link
Author

Hi @cometcrafter, how is it going? :)
Using the graph for Cosmos I've also realized MsgWithdrawDelegatorReward is not present after indexing, meaning that the graph is also failing to catch this one.

@matthewdarwin
Copy link

I believe this issue is fixed with the solution for #5111

@alex-pakalniskis pls close.

@azf20 azf20 closed this as completed Feb 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants