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

Update geth test fixture to v1.10.8 + some refactoring #2118

Merged
merged 3 commits into from
Aug 27, 2021

Conversation

fselmo
Copy link
Collaborator

@fselmo fselmo commented Aug 25, 2021

What was wrong?

  • New geth versions were released including a hotfix for a security vulnerability (1.10.8). Our geth test fixture should be up to date with the latest.

How was it fixed?

  • Update the geth fixture to use version 1.10.8
  • One-liner doc fix on contracts.rst that I caught along the way
  • There were some JSON-RPC changes that now append a gasPrice to pending dynamic fee transactions that is equal to the value of the provided maxFeePerGas. This broke some tests that needed to be fixed as well as the validation for modify_transaction since we pull the params from the pending transaction and that now included a gasPrice
  • Added some utility methods to improve code readability and ended up changing usage of "1559 transaction" to "dynamic fee transaction" to keep consistency across our code base

Todo:

Cute Animal Picture

Put a link to a cute animal picture inside the parenthesis-->

Copy link
Collaborator

@kclowes kclowes left a comment

Choose a reason for hiding this comment

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

Once tests pass, 🚢 !

@fselmo fselmo force-pushed the geth-fixture-bump-1.10.8 branch 5 times, most recently from b19f73c to db0287e Compare August 26, 2021 16:01
Copy link
Collaborator

@kclowes kclowes left a comment

Choose a reason for hiding this comment

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

Looks good! I just left one comment, feel free to take it or leave it!

Comment on lines 174 to 177
if all(_ is not None for _ in (
extracted_params.get('maxFeePerGas'), extracted_params.get('maxPriorityFeePerGas'))
):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is bending my brain a little 😆 maybe worth pulling out into it's own function or assigning to a variable?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

agreed... I split it into two if statements rather than just one to try to clarify it but I still wasn't happy with how this looks. Let me see if I can make this readable 🤔

- Minor fix on formatting in contracts.rst docs
Geth now adds a gasPrice to dynamic fee transactions. The value for gasPrice that is set is equal to the maxFeePerGas value. Changes were made to modify_transaction since we build a new transaction based on values from the original, pending transaction. This transaction would now have all 3 fields and eth_sendTransaction would fail. We need to pop this value back out before replacing the transaction if it is equal to the expected value (maxFeePerGas).
@fselmo fselmo changed the title Update geth test fixture to use v1.10.8 Update geth test fixture to v1.10.8 + Some refactoring Aug 26, 2021
@fselmo fselmo changed the title Update geth test fixture to v1.10.8 + Some refactoring Update geth test fixture to v1.10.8 + some refactoring Aug 26, 2021
@fselmo fselmo force-pushed the geth-fixture-bump-1.10.8 branch 3 times, most recently from 5b0199d to d524aa2 Compare August 26, 2021 21:59
@fselmo
Copy link
Collaborator Author

fselmo commented Aug 26, 2021

@kclowes As I mentioned I kind of went far in refactoring some things but I wanted to cut through most of the noise by highlighting the most important changes:

  • The new web3/_utils/utility_methods.py to house some helpful, reusable utility methods. So far only the dict ones I mentioned are there to help with readability.
  • Uses of the above dict utility methods only happen in transactions.py and gas_price_strategy.py so please check those usages to make sure it looks good (though note that all tests pass so I don't think anything changed)
  • Added a new constant: DYNAMIC_FEE_TXN_PARAMS = ('maxFeePerGas', 'maxPriorityFeePerGas')
  • Check that the newsfragments (both doc and misc) make sense / are formatted properly since I updated them

The rest should all be clarifying name changes for variables in the prepare_replacement_transaction method and renaming "EIP-1559 transaction" to "dynamic fee transaction". I was careful not to rename this in any exception messages or in releases.rst so as to not introduce any breaking changes but see if you spot something that is not ideal in the renaming?

Added utility helper functions to look for certain values among dict-like objects to improve readability among the code base. Added the DYNAMIC_FEE_TXN_PARAMS constant since they are increasingly being used across our code base for validation. Did some general refactoring along the way and renamed any EIP-1559 transaction usage to dynamic fee transaction to keep the naming consistency across code bases since this seems to be the adopted name for the new type=2 transactions. This did not include messages within exceptions since this would be a breaking change.
Copy link
Collaborator

@kclowes kclowes left a comment

Choose a reason for hiding this comment

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

💥 I like those refactors! :shipit:

if key == 'gasPrice' and any(_ in transaction for _ in (
'maxFeePerGas', 'maxPriorityFeePerGas'
)): # if EIP-1559 params in transaction, do not set a default gasPrice if missing
if key == 'gasPrice' and any_in_dict(DYNAMIC_FEE_TXN_PARAMS, transaction):
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is much better 😆 Nice!

@@ -26,40 +34,38 @@


def validate_transaction_params(
transaction: TxParams, latest_block: BlockData, generated_gas_price: Wei
transaction: TxParams, latest_block: BlockData, strategy_based_gas_price: Wei
Copy link
Collaborator

Choose a reason for hiding this comment

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

In this case it doesn't matter because I believe this is just an internal function that gets called by the middleware below, but... since python allows users to pass in arguments either positionally or by name, changing the names of the parameters can be a breaking change if it's part of the public API. Just something to watch out for :)

@fselmo fselmo merged commit 2603d3f into ethereum:master Aug 27, 2021
@fselmo fselmo deleted the geth-fixture-bump-1.10.8 branch April 3, 2024 20:51
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.

2 participants