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

Automatic transaction repricing / replacement #847

Merged
merged 25 commits into from
Nov 23, 2020

Conversation

iamdefinitelyahuman
Copy link
Member

@iamdefinitelyahuman iamdefinitelyahuman commented Nov 17, 2020

What I did

Automatic repricing of transactions.

Closes #727

How I did it

When setting gas_price, you may now use an object that subclasses from GasABC:

  • SimpleGasStrategy for simple strategies that are called once
  • BlockGasStrategy which is called every n blocks
  • TimeGasStrategy which is called every n seconds

For strategies that trigger tx replacement, returning a non-None value broadcasts a new transaction.

Thus far I have created two actual strategies, based around the gasnow API.

How to verify it

Try it out!

TODO

  • more strategies
  • consideration / updates to logic re: console output while waiting for a tx to confirm
  • detailed natspec for strategies and ABCs
  • documentation
  • unit testing (not sure how this will look)

@iamdefinitelyahuman iamdefinitelyahuman force-pushed the feat-replace-tx-auto branch 4 times, most recently from 848a93a to f2efb90 Compare November 18, 2020 14:27
@iamdefinitelyahuman iamdefinitelyahuman marked this pull request as ready for review November 19, 2020 01:38
@iamdefinitelyahuman
Copy link
Member Author

Still need to add another strategy or two here, but this is close!

cc @banteg @fubuloubu

@banteg
Copy link
Collaborator

banteg commented Nov 19, 2020

Another potentially useful default strategy for Geth with graphql enabled:

def gas_price(position=500):
    query = "{ pending { transactions { gasPrice }}}"
    resp = requests.post(f"{ETH_RPC_URL}/graphql", json={"query": query})
    data = resp.json()["data"]["pending"]["transactions"]
    prices = [int(x["gasPrice"], 16) for x in data]
    return Wei(sorted(prices, reverse=True)[:position][-1])

@iamdefinitelyahuman iamdefinitelyahuman force-pushed the feat-replace-tx-auto branch 6 times, most recently from 4a15f97 to 8c22a84 Compare November 20, 2020 18:38
banteg
banteg previously approved these changes Nov 20, 2020
@iamdefinitelyahuman
Copy link
Member Author

This should be gtg now

banteg
banteg previously approved these changes Nov 22, 2020
fubuloubu
fubuloubu previously approved these changes Nov 23, 2020
Copy link
Contributor

@fubuloubu fubuloubu left a comment

Choose a reason for hiding this comment

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

Gave it a shot, looks pretty good to me.

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.

Automatic transaction repricing
3 participants