Shell: avoid head validation request on blocks know as current head
This MR aims to reduce the number validation request of a block that is already known as the current head. Indeed, each time a node receives a new head (mainly because of the mempool broadcast), it notifies it to the validation tool chain as a potential validation of a new head. This could introduce an overhead in the workers as it is call many times. This MR reduces such calls. It seems to improve a bit the performances as well, but profiling it is a bit complicated and thus, only the naive approach (sum of all the spans of all the peer validators) is considered here.
Here are some results (means) of the validation of several heads on mainnet.
Before:
- Peer_validator.notify_head: 12.8031ms / x2329
- Chain_validator.on_notify_head: 16ms / x 2329
- Peer_validator.may_validate_new_head: 5524ms / x 1258 -- naive elapsed time
After:
- Peer_validator.notify_head: 0.46ms / x87
- Discarded Peer_validator.notify_head (the
else): 2.64ms / x2023 - Chain_validator.on_notify_head: 12ms / x 2079
- Peer_validator.may_validate_new_head: 1689ms / x 44 -- naive elapsed time
Manually testing the MR
Checklist
-
Document the interface of any function added or modified (see the coding guidelines) -
Document any change to the user interface, including configuration parameters (see node configuration) -
Provide automatic testing (see the testing guide). -
For new features and bug fixes, add an item in the appropriate changelog ( docs/protocols/alpha.rstfor the protocol and the environment,CHANGES.rstat the root of the repository for everything else). -
Select suitable reviewers using the Reviewersfield below. -
Select as Assigneethe next person who should take action on that MR