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] Deduplication logic for Cosmos Event is faulty leading to missed event #5111

Closed
2 of 3 tasks
betterclever opened this issue Jan 5, 2024 · 6 comments
Closed
2 of 3 tasks
Labels
bug Something isn't working

Comments

@betterclever
Copy link
Contributor

betterclever commented Jan 5, 2024

Bug report

Hi team!
I am an engineer at Persistence Labs where we maintain a self-hosted deployment of Graph Node for usage with Persistence Core-1 chain (a Cosmos SDK based L1).

I noticed that a few events were being missed in our subgraph which were similar but not exactly duplicates. Only first of them was being indexed, and the rest were being ignored and the handler actually never reached the subgraph.

On going deep, I realized this is happening due to a bug in the dedup logic for the events for the Cosmos Blockchain.

The dedup call happens here:

trigger_data.dedup();

Rust stdlib dedup function uses PartialEq implementation for the dedup.

The PartialEq for BlockStream is defined here:

impl PartialEq for CosmosTrigger {
fn eq(&self, other: &Self) -> bool {
match (self, other) {
(Self::Block(a_ptr), Self::Block(b_ptr)) => a_ptr == b_ptr,
(
Self::Event {
event_data: a_event_data,
origin: a_origin,
},
Self::Event {
event_data: b_event_data,
origin: b_origin,
},
) => {
if let (Ok(a_event), Ok(b_event)) = (a_event_data.event(), b_event_data.event()) {
a_event.event_type == b_event.event_type && a_origin == b_origin
} else {
false
}
}
(Self::Transaction(a_ptr), Self::Transaction(b_ptr)) => a_ptr == b_ptr,
(Self::Message(a_ptr), Self::Message(b_ptr)) => a_ptr == b_ptr,
_ => false,
}
}
}

Particularly, the line 90 has an issue where only the source and event name is checked for duplicate. There's a possibility that events with the same name are emitted multiple times in the same block in Cosmos in the same transaction with different attribute values.

Error Analysis and reproducible scenario

I have made a fork branch with a test-case where I downloaded a block from the PersistenceCore Core-1 Firehose and copied it's base64 data. I later processed the triggers exactly as in the current 0.33 release, and then ran the dedup operation to demonstrate that non-duplicate data is being removed leading to ignored events during indexing.

Link to test case in the fork:

fn test_decode_block() {

Run the test using:
cargo test --package graph-chain-cosmos --lib -- chain::test::test_decode_block --exact --nocapture

Fix

The fix is pretty straightforward. We need to update the PartialEq logic also include block data scenario. Only the name and source doesn't suffice.

Possible remediation for older releases where wrong data was indexed

As I can imagine, a lot of past indexed data must have been missed due to this issue. All those subgraphs would have to be re-indexed on a fixed Graph-node release binary to have data without any missing pieces.

Relevant log output

No response

IPFS hash

No response

Subgraph name or link to explorer

No response

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

Linux

@betterclever betterclever added the bug Something isn't working label Jan 5, 2024
@betterclever
Copy link
Contributor Author

As I see from the older raised bugs, this also is related and the root cause is exactly the same, however the error is much clearly highlighted in the current bug report with a reproducible scenario.

#4998

@wojciechowskip
Copy link

Hmm, so when it will be possible to re-index data? When can we expect new version of graph node to be released?

@p-diogo
Copy link

p-diogo commented Jan 10, 2024

@wojciechowskip do you intend to re-index using the Hosted Service?

@wojciechowskip
Copy link

@wojciechowskip do you intend to re-index using the Hosted Service?

Yes, I am just waiting for the release to test it :)

@incrypto32
Copy link
Member

@wojciechowskip its live on Hosted service.

@azf20
Copy link
Contributor

azf20 commented Feb 24, 2024

Closing, thanks so much @betterclever !

@azf20 azf20 closed this as completed Feb 24, 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

5 participants