Skip to content

fix(api-server): page token transactions by offset instead of cursor - #2135

Closed
nullPointerEnjoyer wants to merge 10 commits into
release-v1.4.1from
fix/token-transactions-paging
Closed

nullPointerEnjoyer wants to merge 10 commits into
release-v1.4.1from
fix/token-transactions-paging

Conversation

@nullPointerEnjoyer

Copy link
Copy Markdown
Collaborator

Summary

  • GET /api/v2/token/{id}/transactions returned an empty page for every token: the route passes
    the request's page offset (skip-N, default 0), but the storage layer interpreted the parameter
    as a cursor (WHERE tx_global_index < $2). With the default offset of 0 the predicate matched
    nothing, so the endpoint always returned an empty list.
  • Align the storage layer with the skip-N semantics the HTTP API (and every other paginated
    endpoint) uses: newest-first list, offset entries skipped, empty page at or past the end.
    Trait parameter renamed to offset across trait, both backends, and wrappers.
  • Guard oversized offsets uniformly: an offset too big for a bigint is past the end of any result
    set, so both backends return an empty page (postgres previously wrapped as i64 in five other
    queries, yielding 500s; the in-memory backend previously truncated as usize in seven queries).
  • Wire behavior of other endpoints unchanged; this only fixes paging contract mismatches.

Test plan

  • New storage-level regression test token_transactions_offset_paging (runs against both
    backends): default page starts at the newest transaction, offset skips entries, offsets at/past
    the end (including u64::MAX) yield an empty page instead of an error.
  • Existing storage tests updated to the offset semantics; scanner-lib sync tests pass.
  • ./do_checks.sh green; OCR review clean.

- Bump workspace version to 1.4.1
- Changelog: 1.4.1 section (wallet rescan fix; neutral PoS seal indexing entry)
- Extend testnet checkpoints to height 818500 (step 500, from local synced
  testnet node via chainstate_get_block_ids_as_checkpoints; ~2.5k blocks
  behind tip 821011 at generation time)
- release_linux.yml: the RPM smoke-test step never sourced
  packaging/images.env, so $FEDORA_IMAGE was empty and docker tried to
  pull the script path as an image name.
- win installers: declare TARGETDISTARCH x64. Without it the installers
  are 32-bit, so their HKLM\SOFTWARE uninstall entries land in
  WOW6432Node and the (64-bit PowerShell) smoke check cannot see them;
  files and PATH install fine, masking the issue until the registry
  assertion.
- rpc docs: regenerate node-daemon/docs/RPC{,_DEV}.md and
  wallet-rpc-daemon/docs/RPC.md for the 1.4.1 version bump; the
  expect-file tests embed CARGO_PKG_VERSION and failed on all three
  OS legs of the build workflow.

- win installers: replace the invalid TARGETDISTARCH x64 line with the
  proper NSIS mechanism: a shared MintlayerRequireX64 macro
  (common.nsh) that aborts on 32-bit Windows and switches the registry
  view to 64-bit via SetRegView, inserted from .onInit and un.onInit
  (the uninstaller is a separate process). This keeps the uninstall
  entries in the native HKLM\SOFTWARE hive as the smoke test expects,
  which the previous commit intended but implemented as a command NSIS
  rejects ("Invalid command: TARGETDISTARCH").

- arch smoke test: pacman has no IgnoreArch directive (that is a
  makepkg flag), so installing the foreign-architecture package failed
  with "package architecture is not valid". Add the foreign arch to
  the Architecture option of /etc/pacman.conf instead, and update the
  stale IgnoreArch comments in test-local.sh and release_linux.yml.
The previous fix added the foreign arch to pacman's Architecture list,
which lets the amd64-only Arch image *install* the aarch64 package, but
its binaries still cannot execute there: there is no aarch64 userland,
so every binary dies under qemu with exit 255 (the ELF interpreter
/lib/ld-linux-aarch64.so.1 does not exist). Docker Hub publishes no
arm64 Arch image at all (library/archlinux and archlinux/archlinux are
both amd64-only), so unlike the deb/rpm legs there is no --platform
linux/arm64 escape hatch.

For foreign-architecture packages, smoke-arch.sh now assembles a chroot
of the Arch Linux ARM rootfs and runs the same checks inside it: pacman
-U installs the package with dependencies from the arm repos, pacman
hooks run under emulation (sysusers creates the mintlayer user), and
the binaries execute through the host's qemu binfmt handlers already
registered for the deb/rpm arm64 legs.

Chroot quirks handled:
- pacman's download sandbox user switch fails under the container
  seccomp profile: pass --disable-sandbox inside the chroot
- /proc is not mounted, so /etc/mtab (pacman free-space check) is a
  static copy of the container's mount table
- pacman-key --populate needs process substitution (/dev/fd), which
  requires /proc: initialize the chroot keyring with the container's
  amd64 pacman-key via --gpgdir instead of the emulated one
- /work is not visible in the chroot: script, lib.sh and the package
  are copied in

Verified locally against the pinned CI image with a synthetic aarch64
package exercising install, sysusers hook, binaries, systemd-analyze,
and man page checks, plus an x86_64 package for the native path.
The route handler for GET /api/v2/token/{id}/transactions passes the
request's page offset (skip-N, default 0) but the storage layer treated
the parameter as a cursor (return transactions older than the given
tx_global_index). With the default offset of 0, the cursor predicate
matched nothing and the endpoint returned an empty page for every token
that had no transaction at global index zero.

Align the storage layer with the offset semantics the HTTP API (and every
other paginated endpoint) documents: return the newest transactions
starting at the given offset. An offset past the end of the result set
yields an empty page. Rename the parameter to offset in the trait,
implementations, and wrappers.
Add a storage-level regression test pinning the skip-N semantics of the
get_token_transactions offset parameter: the default page starts at the
newest transaction, the offset skips entries, and an offset at or past
the end of the list yields an empty page instead of an error, including
for offsets too large to represent in the database's integer type.
Five postgres queries cast the page offset to a bigint with , which
wraps offsets above i64::MAX to a negative number. Postgres then rejects
the negative OFFSET and the endpoint fails with an internal error.

Guard the conversion the same way the token id queries already do: an
offset too big for a bigint is past the end of any result set, so return
an empty page.
Truncating the offset to usize with 'as' can wrap an offset that exceeds
the pointer width into a small number, silently returning the first page
instead of an empty one. Skip by usize::MAX instead, which is always past
the end of any in-memory result set.

Also deduplicate the bigint offset guard in the postgres queries into a
single helper.
@nullPointerEnjoyer

Copy link
Copy Markdown
Collaborator Author

Closing: v1.4.1 has already shipped with this bug, so the release branch won't take the fix. The fix rides the master port in #2136 instead.

@nullPointerEnjoyer
nullPointerEnjoyer deleted the fix/token-transactions-paging branch October 8, 2026 08:55
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 this pull request may close these issues.

1 participant