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

Numeric type audit: network, consensus, provider, rpc-types #454

Merged
merged 13 commits into from
Apr 5, 2024

Conversation

yash-atreya
Copy link
Member

@yash-atreya yash-atreya commented Apr 3, 2024

Motivation

Ref #433

Solution

  • gas_limit -> u128
  • gas -> u128
  • gas_price -> u128
  • max_fee_per_blob_gas -> u128
  • transaction_type -> u8
  • max_fee_per_gas -> u128
  • max_priority_fee_per_gas -> u128
  • Consequently, changed fn args and return values accordingly.
  • Satisfies clippy, tests will fail.

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

* `gas_limit` -> `u128`
* `gas` -> `u128`
* `gas_price` -> `u128`
* `max_fee_per_blob_gas` -> `u128`
* `transaction_type` -> `u8`
* `max_fee_per_gas` -> `u128`
* `max_priority_fee_per_gas` -> `u128`
* Consequently, changed fn args and return values accordingly.
* Satisfies clippy, tests will fail.
@yash-atreya yash-atreya changed the title num_type_audit: network, consensus, provider, rpc-types Numeric type audit: network, consensus, provider, rpc-types Apr 3, 2024
@yash-atreya yash-atreya marked this pull request as ready for review April 3, 2024 20:36
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

I think all of these make sense, primitive types are preferable imo.
gas being u128 should make some operations easier but should not affect math for any call arguments etc

Copy link
Contributor

@Evalir Evalir left a comment

Choose a reason for hiding this comment

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

This mostly looks good to me, I'd just like to ensure we get the TODOs taken care of and add enough tests to be 100% sure we're not breaking serde

crates/provider/src/layers/gas.rs Outdated Show resolved Hide resolved
crates/provider/src/provider.rs Outdated Show resolved Hide resolved
crates/serde/src/num.rs Outdated Show resolved Hide resolved
crates/rpc-types/src/eth/transaction/tx_type.rs Outdated Show resolved Hide resolved
crates/provider/src/utils.rs Outdated Show resolved Hide resolved
Copy link
Member

@prestwich prestwich left a comment

Choose a reason for hiding this comment

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

just style nit for @mattsse. several more instances that i didn't explicitly mark

@@ -29,8 +29,8 @@ pub struct TxEip2930 {
/// this transaction. This is paid up-front, before any
/// computation is done and may not be increased
/// later; formally Tg.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex_or_decimal"))]
pub gas_limit: u64,
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
Copy link
Member

Choose a reason for hiding this comment

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

do any endpoints use decimal here? in other PRs we've avoided allowing decimal when nobody actually uses it

#[serde(
default,
skip_serializing_if = "Option::is_none",
with = "alloy_serde::num::u128_hex_or_decimal_opt"
Copy link
Member

Choose a reason for hiding this comment

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

same question. pretty sure decimal would be illegal rpc response here? I don't mind tolerating it, but @mattsse asked for removal of decimal in other PRs

Copy link
Contributor

@Evalir Evalir Apr 4, 2024

Choose a reason for hiding this comment

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

+ 1 to removing decimal support

Copy link
Member

Choose a reason for hiding this comment

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

makes sense, let's enforce strict quantity rules everywhere for core eth types

Copy link
Member

Choose a reason for hiding this comment

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

side note, the U*** type deser DO accept decimal. so this is technically a breaking behavior change

@prestwich
Copy link
Member

followup work: #465

@prestwich prestwich merged commit 5c7e246 into alloy-rs:main Apr 5, 2024
18 checks passed
@yash-atreya yash-atreya mentioned this pull request Apr 6, 2024
3 tasks
ben186 pushed a commit to ben186/alloy that referenced this pull request Jul 27, 2024
…#454)

* num_type_audit: network, consensus, provider, rpc-types

* `gas_limit` -> `u128`
* `gas` -> `u128`
* `gas_price` -> `u128`
* `max_fee_per_blob_gas` -> `u128`
* `transaction_type` -> `u8`
* `max_fee_per_gas` -> `u128`
* `max_priority_fee_per_gas` -> `u128`
* Consequently, changed fn args and return values accordingly.
* Satisfies clippy, tests will fail.

* fix(rpc-type): transaction requests tests

* fix(rpc-types): tests - transaction type

* add u128_hex_or_decimal_opt serde

* fix(providers): provider::tests

* fix(providers): layers::gas::tests

* fix: docs ci

* fix(provider): estimate_gas should return u128

* add(serde): unit test for u128_hex_or_decimal_opt

* fix(rpc-types, provider): use primitives in FeeHistory and its related methods

* add u128_vec serde methods

* ci nits

* nit
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.

5 participants