Skip to content

Conversation

@rodrigo-o
Copy link
Collaborator

@rodrigo-o rodrigo-o commented Feb 4, 2025

Description

This PR solves an issue where we calculated the state and block root twice, once at the end of an slot and at the beginning of the following due to a lack of access to the whole state info.

The solution was to pass the whole state info (instead of the beacon state) and set a new previous_roots map which allowed us to avoid the recalculation when any of the roots was already calculated.

@rodrigo-o
Copy link
Collaborator Author

The block processing has reduced its time by ~3/4 seconds

Before

INFO 19:30:26.903 [Fork choice] Adding new block slot=10997406 root=0x172..b1a8
INFO 19:30:42.722 [Fork choice] Block processed. Recomputing head. 
INFO 19:30:43.274 [Fork choice] Added new block slot=10997406 root=0x172..b1a8
INFO 19:30:43.274 [Fork choice] Recomputed head slot=10997406 root=0x172..b1a8
INFO 19:30:43.274 [Fork choice] Block processing time: 15.819s | Recompute head time: 0.176s 

INFO 19:30:43.276 [Fork choice] Adding new block slot=10997407 root=0xe95..672d
INFO 19:30:59.552 [Fork choice] Block processed. Recomputing head. 
INFO 19:31:00.352 [Fork choice] Added new block slot=10997407 root=0xe95..672d
INFO 19:31:00.353 [Fork choice] Recomputed head slot=10997407 root=0xe95..672d
INFO 19:31:00.353 [Fork choice] Block processing time: 16.276s | Recompute head time: 0.288s

After

INFO 18:22:35.125 [Fork choice] Adding new block slot=11011512 root=0x0b8..3c58
INFO 18:22:47.930 [Fork choice] Block processed. Recomputing head. 
INFO 18:22:48.380 [Fork choice] Added new block slot=11011512 root=0x0b8..3c58
INFO 18:22:48.380 [Fork choice] Recomputed head slot=11011512 root=0x0b8..3c58
INFO 18:22:48.380 [Fork choice] Block processing time: 12.805 s | Head recompute time: 0.451 s 

INFO 18:22:48.382 [Fork choice] Adding new block slot=11011513 root=0xfed..6abf
INFO 18:22:59.945 [Fork choice] Block processed. Recomputing head. 
INFO 18:23:00.447 [Fork choice] Added new block slot=11011513 root=0xfed..6abf
INFO 18:23:00.447 [Fork choice] Recomputed head slot=11011513 root=0xfed..6abf
INFO 18:23:00.447 [Fork choice] Block processing time: 11.563 s | Head recompute time: 0.502 s 

@ElFantasma
Copy link
Contributor

Added telemetry instrumentation for process_slot function to improve Grafana precision in fork choice handler times chart:
Now we can measure this PR impact on charts:
Before:
image

After:
image

@ElFantasma ElFantasma marked this pull request as ready for review February 11, 2025 15:36
@ElFantasma ElFantasma requested a review from a team as a code owner February 11, 2025 15:36
Copy link
Contributor

@ElFantasma ElFantasma left a comment

Choose a reason for hiding this comment

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

Nice 👍

@ElFantasma ElFantasma enabled auto-merge (squash) March 10, 2025 12:09
@ElFantasma ElFantasma disabled auto-merge March 10, 2025 12:10
@rodrigo-o rodrigo-o changed the title perf: state root cache test perf: state root cache for slot n+1 Mar 10, 2025
@rodrigo-o rodrigo-o merged commit 0cf6e65 into main Mar 10, 2025
17 checks passed
@rodrigo-o rodrigo-o deleted the state-root-cache branch March 10, 2025 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants