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

feat: consider tenure block fullness for transaction fee estimations #2203

Merged
merged 11 commits into from
Jan 27, 2025

Conversation

rafaelcr
Copy link
Collaborator

@rafaelcr rafaelcr commented Jan 22, 2025

Modifies the Stacks core fee estimator proxy to follow this algorithm:

  • If the current and recent tenure costs are not full, always return the minimum transaction fee
  • If tenures start receiving transactions but do not yet reach a 90% fullness in any dimension, keep returning the minimum fee
  • Once a dimension exceeds 90% based on a weighted average of past tenures, use the Stacks core estimation (with a configured multiplier)
  • If at any time the current tenure has at least 5 blocks and less than 50% utilization, return to minimum fees

All previous numbers are configurable via ENV:

# Enables the enhanced transaction fee estimator that will alter results for `POST
# /v2/fees/transaction`.
STACKS_CORE_FEE_ESTIMATOR_ENABLED=0

# Multiplier for all fee estimations returned by Stacks core. Must be between 0.0 and 1.0.
STACKS_CORE_FEE_ESTIMATION_MODIFIER=1.0

# How many past tenures the fee estimator will look at to determine if there is a fee market for
# transactions.
STACKS_CORE_FEE_PAST_TENURE_FULLNESS_WINDOW=5

# Percentage at which past tenure cost dimensions will be considered "full".
STACKS_CORE_FEE_PAST_DIMENSION_FULLNESS_THRESHOLD=0.9

# Percentage at which current cost tenures will be considered "busy" in order to determine if we
# should check previous tenures for a fee market.
STACKS_CORE_FEE_CURRENT_DIMENSION_FULLNESS_THRESHOLD=0.5

# Minimum number of blocks the current tenure must have in order to check for "busyness".
STACKS_CORE_FEE_CURRENT_BLOCK_COUNT_MINIMUM=5

Copy link

codecov bot commented Jan 22, 2025

Codecov Report

Attention: Patch coverage is 88.07339% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/api/routes/core-node-rpc-proxy.ts 85.71% 13 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link

github-actions bot commented Jan 22, 2025

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

Copy link
Member

@diwakergupta diwakergupta left a comment

Choose a reason for hiding this comment

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

How are you testing this @rafaelcr ?

src/api/routes/core-node-rpc-proxy.ts Show resolved Hide resolved
src/api/routes/core-node-rpc-proxy.ts Outdated Show resolved Hide resolved
src/api/routes/core-node-rpc-proxy.ts Outdated Show resolved Hide resolved
@rafaelcr
Copy link
Collaborator Author

Thanks for the review @diwakergupta !

How are you testing this @rafaelcr ?

Once logic is verified by Brice/core team I will add unit tests simulating different tenure fullness scenarios. Once merged, we'll follow the same procedure we did for the initial fee estimation proxy (deploy to testnet and validate before moving deployment to mainnet)

Copy link
Member

@obycode obycode left a comment

Choose a reason for hiding this comment

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

This looks good. I noted a couple of thoughts.

It may also be nice to take the current tenure into account, so that it would react quickly when the traffic dies down after a surge. This could be something really simple/naive like, if the current tenure has at least 5 blocks and all cost dimensions are < 50% of the limit, then use the min fee.

src/api/routes/core-node-rpc-proxy.ts Outdated Show resolved Hide resolved
src/datastore/pg-store.ts Outdated Show resolved Hide resolved
@rafaelcr rafaelcr changed the title feat: consider average tenure block fullness for tx fee estimations feat: consider tenure block fullness for transaction fee estimations Jan 23, 2025
@rafaelcr rafaelcr marked this pull request as ready for review January 23, 2025 20:26
@rafaelcr
Copy link
Collaborator Author

@obycode @diwakergupta can you take another look? Easiest is to follow the unit test scenarios starting here: https://github.com/hirosystems/stacks-blockchain-api/pull/2203/files#diff-22bb01d2b4337f97428b33c9aed8d5d87611b43381a61b04611f26606f50c94fR203

Thanks

Copy link
Member

@obycode obycode left a comment

Choose a reason for hiding this comment

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

I'll leave the details of the SQL queries for someone else to review, but everything else looks great!

@rafaelcr rafaelcr requested a review from zone117x January 23, 2025 21:58
@obycode
Copy link
Member

obycode commented Jan 27, 2025

What do you think about always including the minimum fee in this response, along with the estimated fee, so that wallets could easily include that in their UI? I think this would be nice from a user perspective, if I have a low priority transaction that I'd like to get included whenever, I just want to pay the min fee.

@rafaelcr
Copy link
Collaborator Author

@obycode that's a good idea. Would this be the first value of the 3 estimations returned by core? (it always returns an array of 3 estimations)

@obycode
Copy link
Member

obycode commented Jan 27, 2025

@obycode that's a good idea. Would this be the first value of the 3 estimations returned by core? (it always returns an array of 3 estimations)

Looks like it is just "low", "medium", and "high", but low is not necessarily the minimum fee, but I think it could be fine if we just take over the "low" for this minimum value. I guess we should check with the wallets.

@rafaelcr
Copy link
Collaborator Author

@obycode sounds good. I think we can make that tweak in a next PR once we've touched base with them.

@rafaelcr rafaelcr merged commit 396e2ea into develop Jan 27, 2025
27 checks passed
@rafaelcr rafaelcr deleted the feat/tenure-fees branch January 27, 2025 18:24
blockstack-devops pushed a commit that referenced this pull request Jan 28, 2025
## [8.6.0-beta.1](v8.5.0...v8.6.0-beta.1) (2025-01-28)

### Features

* consider tenure block fullness for transaction fee estimations ([#2203](#2203)) ([396e2ea](396e2ea))
* store total transaction size in blocks table ([#2204](#2204)) ([ac7c41b](ac7c41b))

### Bug Fixes

* make tx_total_size column nullable ([#2207](#2207)) ([77bd2f8](77bd2f8))
@blockstack-devops
Copy link

🎉 This PR is included in version 8.6.0-beta.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

blockstack-devops pushed a commit that referenced this pull request Feb 6, 2025
## [8.6.0](v8.5.0...v8.6.0) (2025-02-06)

### Features

* consider tenure block fullness for transaction fee estimations ([#2203](#2203)) ([396e2ea](396e2ea))
* store total transaction size in blocks table ([#2204](#2204)) ([ac7c41b](ac7c41b))

### Bug Fixes

* make tx_total_size column nullable ([#2207](#2207)) ([77bd2f8](77bd2f8))
* use an independent sql connection for mempool stats ([#2217](#2217)) ([f8137e4](f8137e4))
@blockstack-devops
Copy link

🎉 This PR is included in version 8.6.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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants