Skip to content

Add utils module with script to display top address balances #819

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

Merged
merged 9 commits into from
Nov 9, 2021

Conversation

rafaelcr
Copy link
Collaborator

@rafaelcr rafaelcr commented Oct 22, 2021

Description

This PR adds a new utils module to the API that will allow us to write and use utility scripts to help us debug issues much faster.

To start this module, a first script is added that displays the top N addresses that have the most STX transfer events in the stx_events table along with their reported balances both by the API database and a Stacks node. This function will help us debug block and microblock re-org bugs that cause balance discrepancies (such as #804).

An example usage for this script is:

utils$ npm run build
utils$ node ./lib/utils/src/index.js stx-balances --count=5 --block-height=25000
Calculating balances for top 5 accounts at block height 25000...
╔═════════════╤══════════════════════════════════════════════════════╤════════════════╤════════════════╤═════════╗
║ event count │ address                                              │ api balance    │ node balance   │ delta   ║
╟─────────────┼──────────────────────────────────────────────────────┼────────────────┼────────────────┼─────────╢
║ 31530       │ SP1P72Z3704VMT3DMHPP2CB8TGQWGDBHD3RPR9GZS            │ 54622132931302 │ 54622132931302 │ 0       ║
╟─────────────┼──────────────────────────────────────────────────────┼────────────────┼────────────────┼─────────╢
║ 26515       │ SP3HXJJMJQ06GNAZ8XWDN1QM48JEDC6PP6W3YZPZJ            │ 16613397639131 │ 16613397639131 │ 0       ║
╟─────────────┼──────────────────────────────────────────────────────┼────────────────┼────────────────┼─────────╢
║ 23312       │ SPJW1XE278YMCEYMXB8ZFGJMH8ZVAAEDP2S2PJYG.stacks-pops │ 0              │ 0              │ 0       ║
╟─────────────┼──────────────────────────────────────────────────────┼────────────────┼────────────────┼─────────╢
║ 22725       │ SP1K1A1PMGW2ZJCNF46NWZWHG8TS1D23EGH1KNK60            │ 6444565689     │ 6443305689     │ 1260000 ║
╟─────────────┼──────────────────────────────────────────────────────┼────────────────┼────────────────┼─────────╢
║ 18654       │ SPX8T06E8FJQ33CX8YVR9CC6D9DSTF6JE0Y8R7DS             │ 84277084935    │ 84277084935    │ 0       ║
╚═════════════╧══════════════════════════════════════════════════════╧════════════════╧════════════════╧═════════╝

Type of Change

  • New feature
  • Bug fix
  • API reference/documentation update
  • Other

Does this introduce a breaking change?

No

Are documentation updates required?

No

Testing information

N/A

Checklist

  • Code is commented where needed
  • Unit test coverage for new or modified code paths
  • npm run test passes
  • Changelog is updated
  • Tag 1 of @kyranjamie or @zone117x for review

@rafaelcr rafaelcr requested a review from zone117x October 22, 2021 02:06
@vercel
Copy link

vercel bot commented Oct 22, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/blockstack/stacks-blockchain-api/FfpnKvmVWWV4MQ8WukZfZfRcVx5y
✅ Preview: https://stacks-blockchain-api-git-feat-reorg-debug-script-blockstack.vercel.app

@codecov
Copy link

codecov bot commented Oct 22, 2021

Codecov Report

Merging #819 (fe66a63) into develop (4ade5ee) will increase coverage by 2.43%.
The diff coverage is 75.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #819      +/-   ##
===========================================
+ Coverage    65.39%   67.82%   +2.43%     
===========================================
  Files           90       90              
  Lines         9122    10121     +999     
  Branches      1459     1650     +191     
===========================================
+ Hits          5965     6865     +900     
- Misses        3152     3251      +99     
  Partials         5        5              
Impacted Files Coverage Δ
src/core-rpc/client.ts 74.44% <75.00%> (-0.27%) ⬇️
src/datastore/postgres-store.ts 85.95% <0.00%> (+2.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4ade5ee...fe66a63. Read the comment docs.

@zone117x zone117x mentioned this pull request Oct 22, 2021
@rafaelcr rafaelcr marked this pull request as ready for review October 22, 2021 16:41
@rafaelcr
Copy link
Collaborator Author

Ready for review when you get a chance @zone117x , thanks 👍

@rafaelcr rafaelcr self-assigned this Nov 4, 2021
Copy link
Member

@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.

Super useful, thanks @rafaelcr!
Would be nice to have a mode that went through every address with a non-zero balance -- would take a long time but be helpful for a through sanity test. Could be done in a later PR if we want.

@rafaelcr rafaelcr merged commit 67553ff into develop Nov 9, 2021
@rafaelcr rafaelcr deleted the feat/reorg-debug-script branch November 9, 2021 21:27
@blockstack-devops
Copy link

🎉 This PR is included in version 1.0.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.

3 participants