graphprotocol / graph-node

Graph Node indexes data from blockchains such as Ethereum and serves it over GraphQL
https://thegraph.com
Apache License 2.0
2.92k stars 978 forks source link

[Bug] Substreams BigDecimal encoding issue when value is zero #5644

Closed DenisCarriere closed 2 months ago

DenisCarriere commented 2 months ago

Bug report

tables
    .create_row("Balance", token.as_str())
    .set("owner", owner)
    .set_bigdecimal("balance", &0.to_string());

Using set_bigint_or_zero does work in the event the value is 0, however this forces to use BigInt GraphQL type.

Using Substreams Entity Changes https://github.com/streamingfast/substreams-sink-entity-changes

Relevant log output

postgres    | 2024-09-15 04:12:42.032 UTC [577] ERROR:  invalid byte sequence for encoding "UTF8": 0x00
postgres    | 2024-09-15 04:12:42.032 UTC [577] CONTEXT:  unnamed portal parameter $2
postgres    | 2024-09-15 04:12:42.032 UTC [577] STATEMENT:  select $1 as entity, to_jsonb(e.*) as data
postgres    |     from "sgd1"."balance" e
postgres    |    where exists (select 1 from unnest($2) as p(g$id) where id = p.g$id) and e.block_range @> $3
postgres    |   union all
postgres    |   select $4 as entity, to_jsonb(e.*) as data
postgres    |     from "sgd1"."block" e
postgres    |    where exists (select 1 from unnest($5) as p(g$id) where id = p.g$id) and e.block_range @> $6

IPFS hash

No response

Subgraph name or link to explorer

No response

Some information to help us out

OS information

macOS

YaroShkvorets commented 2 months ago

@DenisCarriere seems to work. Make sure you declare balance: BigDecimal! in the schema.graphql

Quick example: https://github.com/YaroShkvorets/common-subgraphs/tree/main/substreams-entities

DenisCarriere commented 2 months ago

@YaroShkvorets thanks for looking into this

This issue doesn't seem to be related to BigDecimal but instead a missing Entity in one of the pointer fields

Will be closing this issue