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: CheckTX Priority #10507

Merged
merged 8 commits into from
Nov 23, 2021
Merged

feat: CheckTX Priority #10507

merged 8 commits into from
Nov 23, 2021

Conversation

alexanderbez
Copy link
Contributor

@alexanderbez alexanderbez commented Nov 8, 2021

Set the Priority in ResponseCheckTx to prioritize txs in Tendermint's mempool. For now, we compute the tx priority naively as the total sum of all fees in a tx.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

@alexanderbez alexanderbez added the S:blocked Status: Blocked label Nov 10, 2021
@alexanderbez alexanderbez marked this pull request as ready for review November 15, 2021 02:20
@tac0turtle tac0turtle removed the S:blocked Status: Blocked label Nov 16, 2021
@tac0turtle
Copy link
Member

unblocked

Copy link
Member

@aaronc aaronc left a comment

Choose a reason for hiding this comment

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

I'm concerned that this doesn't differentiate denoms when doing the naive addition. It would give a lot of priority to txs which add some denom which is cheap or has large exponent (say 10e9) but isn't even a fee denom.

@aaronc
Copy link
Member

aaronc commented Nov 17, 2021

A fix to this would be using only one fee denom to determine the priority. Or if we don't want to add configuration, using the min integer value of all the demons in the fee so it's not easily gameable.

@alexanderbez
Copy link
Contributor Author

@aaronc I don't really understand the concern. What do you mean by "but isn't even a fee denom."?

In any case, I implemented and even documented that this is a naive approach, which will work just fine for the Hub btw. Applications that need a more sophisticated model would just implement their own middleware. In fact, they could do so and release updates and changes to this middleware in point releases (non-breaking).

This PR wasn't intended to solve most uses cases, but rather just get the ball rolling on a basic approach to tx priority.


// GetTxPriority returns a naive tx priority based on the total sum of all fees
// provided in a transaction.
func GetTxPriority(fee sdk.Coins) int64 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

how about renaming to ComputeTxPriority?

@robert-zaremba
Copy link
Collaborator

Aaron concerns is about rebasing the fees (if there are fees in multiple tokens) to a common denominator.
I don't think it's easy - we would need an exchange rate information to do it properly.

Copy link
Collaborator

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

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

lgtm, Let's consider renaming GetTxPriority (made a comment about it).

@aaronc
Copy link
Member

aaronc commented Nov 19, 2021

Aaron concerns is about rebasing the fees (if there are fees in multiple tokens) to a common denominator.
I don't think it's easy - we would need an exchange rate information to do it properly.

I'm not sure why this is so complicated. I suggested a very simple approach to make this non-gameable. I'll make a code suggestion with my approach.

func GetTxPriority(fee sdk.Coins) int64 {
var priority int64
for _, c := range fee {
priority += c.Amount.Int64()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
priority += c.Amount.Int64()
p := c.Amount.Int64()
if priority == 0 || p < priority {
priority = p
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know you're just taking the minimum here. What does this really buy you? If all fees provided are valid denominations, what is the issue exactly?

Copy link
Member

Choose a reason for hiding this comment

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

but the denominations have different prices and settling on the minimum makes it hard to use a cheaper denom alongside the primary denom to boost a tx. the primary denom will take precedence with the minimum

Copy link
Member

Choose a reason for hiding this comment

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

I would say this is out of scope of a naive implementation. Its either we spend time designing a new way to do this, which we have pre open for but no reviews, or we document teams how do this and say they have to do it based on their use case. We don't have the man power to design yet another thing right now

Maybe adding a warning godoc could benefit this.

Copy link
Member

Choose a reason for hiding this comment

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

But why is there a lot of design needed? It seems like just taking the min solves a lot to potential issues and is a very simple code change

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree with Aaron, what if one denom has exponent = 2, and another one 6? Adding 2 = 0.2 (fee from first denom) to 500 = 0.0005 (fee from the secon denom) doesn't really make sense. So at least we should document / add a comment, that his is a naive implementation.

@alexanderbez alexanderbez merged commit f97cf85 into master Nov 23, 2021
@alexanderbez alexanderbez deleted the bez/simple-tx-priority branch November 23, 2021 14:21
blewater pushed a commit to e-money/cosmos-sdk that referenced this pull request Dec 8, 2021
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.

5 participants