Skip to content

Conversation

@rafaelcr
Copy link
Collaborator

@rafaelcr rafaelcr commented May 12, 2025

The API has Stacks 2.x logic to avoid re-inserting transactions to the DB during a /new_block event when those transactions were previously inserted during a /new_microblock event. However, the new /extended/v2 balance endpoint logic only considers /new_block transactions when adding/subtracting from account balances. This is causing some old 2.x blocks to warp balances in accounts that happened to have transactions confirmed in previous microblocks.

This PR changes this behavior so these balance calculations always include all transactions regardless of microblocks. It also includes a migration that will execute a query to recompute all transaction balances to correct the issue on deployed environments.

Fixes #2267

@github-actions
Copy link

github-actions bot commented May 12, 2025

Vercel deployment URL: https://stacks-blockchain-6kzt0wrg5-hirosystems.vercel.app 🚀

@codecov
Copy link

codecov bot commented May 13, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@rafaelcr rafaelcr changed the title fix: balances after microblocks fix: consider microblock transactions in balance calculations May 13, 2025
@rafaelcr rafaelcr marked this pull request as ready for review May 13, 2025 15:54
@rafaelcr rafaelcr requested a review from zone117x May 13, 2025 15:54
Copy link
Contributor

@zone117x zone117x left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@rafaelcr rafaelcr merged commit 3418863 into develop May 15, 2025
26 checks passed
@rafaelcr rafaelcr deleted the fix/balance-mbs2 branch May 15, 2025 15:33
hirosystems-release-bot bot added a commit that referenced this pull request May 26, 2025
## [8.11.0](v8.10.0...v8.11.0) (2025-05-26)

### Features

* add /extended/v2/block-tenures/:height/blocks endpoint ([#2285](#2285)) ([f5c2e01](f5c2e01))
* stacks core event and rpc proxy body limits configurable via env ([#2278](#2278)) ([8a54e9d](8a54e9d))
* store and expose vm_error for failed transactions ([#2286](#2286)) ([7ac7513](7ac7513))

### Bug Fixes

* consider microblock transactions in balance calculations ([#2277](#2277)) ([3418863](3418863))
* count stx mint data at block 0 towards account balances ([#2289](#2289)) ([a0cd9f2](a0cd9f2))
* ignore unanchored param for BNS names endpoint ([#2263](#2263)) ([3d33725](3d33725))
* keep a table of latest stacks node event timestamps ([#2266](#2266)) ([6f111ad](6f111ad))
* module imports in block tenure routes ([#2287](#2287)) ([2cb442e](2cb442e))
* **rosetta:** get current block should only join by stacks chain tip information ([#2265](#2265)) ([78ebad0](78ebad0))
* simplify transaction events query ([#2279](#2279)) ([517ca68](517ca68))
@hirosystems-release-bot
Copy link
Contributor

🎉 This PR is included in version 8.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

new stx balance endpoint returning incorrect amounts in some cases

3 participants