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: use OnceCell for Signed::hash #2025

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

feat: use OnceCell for Signed::hash #2025

wants to merge 4 commits into from

Conversation

klkvr
Copy link
Member

@klkvr klkvr commented Feb 7, 2025

Motivation

closes #1987

Lazily computes hash for the transaction in Signed. Methods relying on hash are now bounded by T: RlpEcdsaTx which works for all of the transactions we have but would likely get trickier for custom signature usecases

Solution

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

@klkvr klkvr marked this pull request as draft February 7, 2025 13:57
@klkvr klkvr force-pushed the klkvr/lazy-hash branch 2 times, most recently from 2b43842 to f58fb6a Compare February 7, 2025 14:03
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 like this,

we should make it very clear that this Signed type is specifically for transactions, it's already mentioned but I think we can make this even clearer

@klkvr klkvr marked this pull request as ready for review February 7, 2025 14:11
@DaniPopes
Copy link
Member

Why can't we use std here?

@klkvr
Copy link
Member Author

klkvr commented Feb 7, 2025

we can but we'd still need once_cell in no-std

@mattsse
Copy link
Member

mattsse commented Feb 7, 2025

@jenpaff jenpaff added this to the v1.0 milestone Feb 20, 2025
@klkvr klkvr force-pushed the klkvr/lazy-hash branch 2 times, most recently from 6a74e0e to 93003ba Compare March 1, 2025 22:10
@klkvr klkvr force-pushed the klkvr/lazy-hash branch from 93003ba to 185f83b Compare March 1, 2025 22:13
@klkvr
Copy link
Member Author

klkvr commented Mar 1, 2025

We need Signed<TypedTransaction to still be usable as it seems that there are people relying on it e.g #2070

So this means we need to somehow have a helper tx_hash(&self, signature) -> B256 on it. RIght now it's only present on RlpEcdsaTx which has a transaction type AT which is irrelevant for TypedTransaction. For now I've extended SignableTransaction with a tx_hash_with_signature method doing the same thing

Also I've changed into_signed to have default impl using new_unhashed

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.

lgtm!

but blocking until we finalize #2138

Comment on lines -273 to -275
fn into_signed(self, signature: Signature) -> Signed<Self> {
let tx_hash = self.tx_hash(&signature);
Signed::new_unchecked(self, signature, tx_hash)
Copy link
Member

Choose a reason for hiding this comment

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

ah these we no longer need because part of SignableTransaction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Reviewed
Development

Successfully merging this pull request may close these issues.

[Feature] Use lazy hashing for Signed
4 participants