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

Ethereum transactions not indexed when block only contain native transfers #2575

Closed
3 tasks done
mvanmeerbeck opened this issue Oct 21, 2024 · 1 comment · Fixed by subquery/subql-ethereum#350
Closed
3 tasks done

Comments

@mvanmeerbeck
Copy link

mvanmeerbeck commented Oct 21, 2024

Prerequisites

  • Are you running the latest version(s)?
  • Have you searched the documentation for your issue?
  • Did you search for an existing issue or pull request?

Description

Hello,

When indexing blocks that only contain native transfers, subquery is only indexing logs, therefore those native transfers are ignored. This behaviour was introduced in this PR.
There is a comment about it here

The reason is in the function isFullBlock, which is excluding blocks that don't contain logs (events)

export function isFullBlock(block: BlockContent): block is EthereumBlock {
  // Light etherum block just contains transaction hashes for transactions.
  // If the block has no transactions then both types would be the same

  if (block.transactions.length && block.logs.length) {
    return typeof (block as EthereumBlock).transactions[0] !== 'string';
  }
  return false;
}

Then it only parses logs in this else condition, as a result native transfers are ignored if this kind of blocks

    if (isFullBlock(block)) {
      await this.indexBlockContent(block, dataSources, getVM);

      for (const tx of block.transactions) {
        await this.indexTransaction(tx, dataSources, getVM);

        for (const log of tx.logs ?? []) {
          await this.indexEvent(log, dataSources, getVM);
        }
      }
    } else {
      for (const log of block.logs ?? []) {
        await this.indexEvent(log, dataSources, getVM);
      }
    }

Details

These details can help to reproduce the environment the issue is occurring

Local Environment: @subql/cli/5.2.8
Query Version: I don't know
Indexer Version: I don't know
Network Details:

  • any EVM, but it's easier to reproduce with anvil or hardhat

Steps to Reproduce

  1. run anvil with anvil --host 0.0.0.0 --slots-in-an-epoch 1 --block-time 5
  2. run subquery with a simple native transaction handler like this one

project.ts

          {
            kind: EthereumHandlerKind.Call,
            handler: "handleNativeTransaction",
            filter: {
              function: null, // This picks up native token transfers
            },
          },

mappingHandlers.ts

export async function handleNativeTransaction(tx: EthereumTransaction): Promise<void> {
  logger.info('handleNativeTransaction')
  logger.info(serialize(tx))
}
  1. run subquery node

  2. submit a native tx on anvil

cast send --private-key $PRIVATE_KEY --rpc-url $RPC_URL $TO --value $VALUE

You should have no logs.
Now as a test, if you always return true in node_modules/@subql/node-ethereum/dist/ethereum/block.ethereum.js

 function isFullBlock(block) {
    return true;
    
    // Light etherum block just contains transaction hashes for transactions.
    // If the block has no transactions then both types would be the same
    if (block.transactions.length && block.logs.length) {
        return typeof block.transactions[0] !== 'string';
    }
    return false;
}

Restart subquery and send a new native transfer, the log will appear

@mvanmeerbeck mvanmeerbeck changed the title Ethereum transactions not indexed when block only contain natives transfers Ethereum transactions not indexed when block only contain native transfers Oct 21, 2024
@jamesbayly
Copy link
Contributor

This is being looked at now

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 a pull request may close this issue.

2 participants