Skip to content

Conversation

ak88
Copy link
Contributor

@ak88 ak88 commented Sep 11, 2025

This is an attempt to make hash calculation more dynamic, since header hash is done through an extension method and cannot be overridden.

An alternative could be to have a virtual method returning ValueHash256 in BlockHeader itself, and have it return null in BlockHeader since the decoders doesn't live in Core namespace.

@ak88 ak88 changed the title call static rlp class Refactor CalculateValueHash for header Sep 11, 2025
if (rlpStreamDecoder is null)
throw new RlpException($"Decoder not found for {typeof(T).Name}");

int totalLength = rlpStreamDecoder.GetLength(item, behaviors);
Copy link
Member

Choose a reason for hiding this comment

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

not used?

KeccakRlpStream stream = new();
IRlpStreamDecoder<T>? rlpStreamDecoder = GetStreamDecoder<T>();
if (rlpStreamDecoder is null)
throw new RlpException($"Decoder not found for {typeof(T).Name}");
Copy link
Member

Choose a reason for hiding this comment

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

Move to ThrowXXX method for performance

public static ValueHash256 EncodeForHash<T>(T item, RlpBehaviors behaviors = RlpBehaviors.None)
{
KeccakRlpStream stream = new();
IRlpStreamDecoder<T>? rlpStreamDecoder = GetStreamDecoder<T>();
Copy link
Member

Choose a reason for hiding this comment

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

bit of cost for every hash calculation, but we probably have to pay it

@ak88 ak88 marked this pull request as draft September 12, 2025 07:35
@ak88 ak88 marked this pull request as ready for review September 12, 2025 10:17
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.

3 participants