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

Transaction event count differs to length of list of returned events #1983

Closed
friedger opened this issue May 25, 2024 · 1 comment · Fixed by #1994
Closed

Transaction event count differs to length of list of returned events #1983

friedger opened this issue May 25, 2024 · 1 comment · Fixed by #1994
Assignees

Comments

@friedger
Copy link
Contributor

Describe the bug
The api returns a higher number of events than it actually can deliver

To Reproduce
Steps to reproduce the behavior:

  1. Fetch https://api.hiro.so/extended/v1/tx/0xd45e090ac442380cf50655e3d1c904c355a501d6dffa3b5e4799083062469dbc
  2. See event count 24 and event[10] has index 19
  3. Fetch https://api.hiro.so/extended/v1/tx/0xd45e090ac442380cf50655e3d1c904c355a501d6dffa3b5e4799083062469dbc?event_offset=12
  4. See event count 24 and event[0] has index 13 and event[5] has index 24
  5. The total list of events delivered by the api is 13 different events (11 from first call + 2 new event from second call)

Expected behavior
All events with index 0 to 23 can be retrieved.

@github-project-automation github-project-automation bot moved this to 🆕 New in API Board May 25, 2024
@friedger friedger changed the title Transaction event count differs to list of returned events Transaction event count differs to length of list of returned events May 25, 2024
@zone117x zone117x moved this from 🆕 New to 📋 Backlog in API Board Jun 3, 2024
@zone117x
Copy link
Member

zone117x commented Jun 4, 2024

This appears to be caused by a quirk/bug in how pox events are indexed. The pox events are sent as regular smart_contract_log print type events, so initially they are marked for insertion as a regular print type event. Then they are detected as special pox events and also marked for insertion as a special pox type event.

The result is that each pox event takes up two event index slots.

for (const tx of dbData) {
const sortedEvents = [
tx.contractLogEvents,
tx.ftEvents,
tx.nftEvents,
tx.stxEvents,
tx.stxLockEvents,
tx.pox2Events,
tx.pox3Events,
tx.pox4Events,
]
.flat()
.sort((a, b) => a.event_index - b.event_index);
tx.tx.event_count = sortedEvents.length;
for (let i = 0; i < sortedEvents.length; i++) {
sortedEvents[i].event_index = i;
}
}

So luckily there aren't any events actually missing from that endpoint. There are only a total of 12 events for that tx, even though there appears to be more because of the index duplication bug.

It's relatively easy to fix this for new blocks that come in, but difficult to implement a fix to de-duplicate/re-index past events.

@zone117x zone117x moved this from 📋 Backlog to 🏗 In Progress in API Board Jun 10, 2024
zone117x added a commit that referenced this issue Jun 11, 2024
#1994)

* fix: pox events should use same index as associated contract log event #1983

* test: add test
@github-project-automation github-project-automation bot moved this from 🏗 In Progress to ✅ Done in API Board Jun 11, 2024
blockstack-devops pushed a commit that referenced this issue Jun 18, 2024
## [7.12.0-beta.1](v7.11.0...v7.12.0-beta.1) (2024-06-18)

### Features

* tx ordering options ([#2005](#2005)) ([ae78773](ae78773))

### Bug Fixes

* pox events should use same index as associated contract log event ([#1994](#1994)) ([b1d6be9](b1d6be9)), closes [#1983](#1983)
blockstack-devops pushed a commit that referenced this issue Jul 8, 2024
## [7.12.0](v7.11.1...v7.12.0) (2024-07-08)

### Features

* tx list contract id/name filter options ([#2018](#2018)) ([9c2fd78](9c2fd78))
* tx list nonce filter option ([#2023](#2023)) ([88fc5ce](88fc5ce))
* tx list timestamp filter options ([#2015](#2015)) ([e7c224b](e7c224b))
* tx ordering options ([#2005](#2005)) ([ae78773](ae78773))
* tx to/from address options ([#2012](#2012)) ([542973c](542973c))
* update api toolkit ([71da884](71da884))

### Bug Fixes

* pox events should use same index as associated contract log event ([#1994](#1994)) ([b1d6be9](b1d6be9)), closes [#1983](#1983)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
2 participants