Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Use H64 for Block Nonce #1396

Merged
merged 2 commits into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Unreleased

- Use H64 for Block Nonce [#1396](https://github.com/gakonst/ethers-rs/pull/1396)
- Add `as_*_mut` methods on `TypedTransaction`
[#1310](https://github.com/gakonst/ethers-rs/pull/1310)
- AWS EIP712 data signing no longer signs with EIP155
Expand Down
4 changes: 2 additions & 2 deletions ethers-core/src/types/block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Taken from <https://github.com/tomusdrw/rust-web3/blob/master/src/types/block.rs>
use crate::types::{Address, Bloom, Bytes, Transaction, TxHash, H256, U256, U64};
use crate::types::{Address, Bloom, Bytes, Transaction, TxHash, H256, H64, U256, U64};
use chrono::{DateTime, TimeZone, Utc};
#[cfg(not(feature = "celo"))]
use core::cmp::Ordering;
Expand Down Expand Up @@ -81,7 +81,7 @@ pub struct Block<TX> {
pub mix_hash: Option<H256>,
/// Nonce
#[cfg(not(feature = "celo"))]
pub nonce: Option<U64>,
pub nonce: Option<H64>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

how does H64 serialize, deserialize compared to U64?

H64 is a hash type, and since nonce is an uint, this change doesn't seem necessary,

also H64 lacks common conversion trait impls for primitive types and I'm not sure it even as a as_u64 function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

H64 will encode as a byte array, and not like number so it won't serialize to the most compact representation and it will expect the length to be 16 on deserialization. The reason this change is necessary is because a client of anvil (in my experience here graph-node) may expect the the value to have a length of 16 (or 18 with 0x prefix) and will fail to deserialize something like 0x0. Because the specs say this value is Bytes8 https://github.com/ethereum/execution-specs/blob/master/src/ethereum/muir_glacier/eth_types.py#L118 and geth also implements it as such, I think failing to deserialize 0x0 for the nonce is reasonable

/// Base fee per unit of gas (if past London)
#[serde(rename = "baseFeePerGas")]
pub base_fee_per_gas: Option<U256>,
Expand Down
2 changes: 1 addition & 1 deletion ethers-core/src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub type Selector = [u8; 4];
/// A transaction Hash
pub use ethabi::ethereum_types::H256 as TxHash;

pub use ethabi::ethereum_types::{Address, Bloom, H160, H256, H512, U128, U256, U64};
pub use ethabi::ethereum_types::{Address, Bloom, H160, H256, H512, H64, U128, U256, U64};

pub mod transaction;
pub use transaction::{
Expand Down