@@ -780,7 +780,10 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
780780 // it to the slasher if an error occurs, because that's the end of this block's journey,
781781 // and it could be a repeat proposal (a likely cause for slashing!).
782782 let header = block. signed_block_header ( ) ;
783- Self :: new_without_slasher_checks ( block, chain) . map_err ( |e| {
783+ // The `SignedBeaconBlock` and `SignedBeaconBlockHeader` have the same canonical root,
784+ // but it's way quicker to calculate root of the header since the hash of the tree rooted
785+ // at `BeaconBlockBody` is already computed in the header.
786+ Self :: new_without_slasher_checks ( block, & header, chain) . map_err ( |e| {
784787 process_block_slash_info :: < _ , BlockError < T :: EthSpec > > (
785788 chain,
786789 BlockSlashInfo :: from_early_error_block ( header, e) ,
@@ -791,6 +794,7 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
791794 /// As for new, but doesn't pass the block to the slasher.
792795 fn new_without_slasher_checks (
793796 block : Arc < SignedBeaconBlock < T :: EthSpec > > ,
797+ block_header : & SignedBeaconBlockHeader ,
794798 chain : & BeaconChain < T > ,
795799 ) -> Result < Self , BlockError < T :: EthSpec > > {
796800 // Ensure the block is the correct structure for the fork at `block.slot()`.
@@ -810,7 +814,7 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
810814 } ) ;
811815 }
812816
813- let block_root = get_block_root ( & block ) ;
817+ let block_root = get_block_header_root ( block_header ) ;
814818
815819 // Disallow blocks that conflict with the anchor (weak subjectivity checkpoint), if any.
816820 check_block_against_anchor_slot ( block. message ( ) , chain) ?;
@@ -1771,6 +1775,19 @@ pub fn get_block_root<E: EthSpec>(block: &SignedBeaconBlock<E>) -> Hash256 {
17711775 block_root
17721776}
17731777
1778+ /// Returns the canonical root of the given `block_header`.
1779+ ///
1780+ /// Use this function to ensure that we report the block hashing time Prometheus metric.
1781+ pub fn get_block_header_root ( block_header : & SignedBeaconBlockHeader ) -> Hash256 {
1782+ let block_root_timer = metrics:: start_timer ( & metrics:: BLOCK_HEADER_PROCESSING_BLOCK_ROOT ) ;
1783+
1784+ let block_root = block_header. message . canonical_root ( ) ;
1785+
1786+ metrics:: stop_timer ( block_root_timer) ;
1787+
1788+ block_root
1789+ }
1790+
17741791/// Verify the parent of `block` is known, returning some information about the parent block from
17751792/// fork choice.
17761793#[ allow( clippy:: type_complexity) ]
0 commit comments