1
1
use beacon_node_fallback:: { ApiTopic , BeaconNodeFallback , Error as FallbackError , Errors } ;
2
2
use bls:: SignatureBytes ;
3
- use eth2:: types:: { FullBlockContents , PublishBlockRequest } ;
4
3
use eth2:: { BeaconNodeHttpClient , StatusCode } ;
5
4
use graffiti_file:: { determine_graffiti, GraffitiFile } ;
6
5
use logging:: crit;
@@ -13,11 +12,8 @@ use std::time::Duration;
13
12
use task_executor:: TaskExecutor ;
14
13
use tokio:: sync:: mpsc;
15
14
use tracing:: { debug, error, info, trace, warn} ;
16
- use types:: {
17
- BlindedBeaconBlock , BlockType , ChainSpec , EthSpec , Graffiti , PublicKeyBytes ,
18
- SignedBlindedBeaconBlock , Slot ,
19
- } ;
20
- use validator_store:: { Error as ValidatorStoreError , ValidatorStore } ;
15
+ use types:: { BlockType , ChainSpec , EthSpec , Graffiti , PublicKeyBytes , Slot } ;
16
+ use validator_store:: { Error as ValidatorStoreError , SignedBlock , UnsignedBlock , ValidatorStore } ;
21
17
22
18
#[ derive( Debug ) ]
23
19
pub enum BlockError {
@@ -335,26 +331,10 @@ impl<S: ValidatorStore + 'static, T: SlotClock + 'static> BlockService<S, T> {
335
331
) -> Result < ( ) , BlockError > {
336
332
let signing_timer = validator_metrics:: start_timer ( & validator_metrics:: BLOCK_SIGNING_TIMES ) ;
337
333
338
- let ( block, maybe_blobs) = match unsigned_block {
339
- UnsignedBlock :: Full ( block_contents) => {
340
- let ( block, maybe_blobs) = block_contents. deconstruct ( ) ;
341
- ( block. into ( ) , maybe_blobs)
342
- }
343
- UnsignedBlock :: Blinded ( block) => ( block. into ( ) , None ) ,
344
- } ;
345
-
346
334
let res = self
347
335
. validator_store
348
- . sign_block ( * validator_pubkey, block, slot)
349
- . await
350
- . map ( |block| match block {
351
- validator_store:: SignedBlock :: Full ( block) => {
352
- SignedBlock :: Full ( PublishBlockRequest :: new ( Arc :: new ( block) , maybe_blobs) )
353
- }
354
- validator_store:: SignedBlock :: Blinded ( block) => {
355
- SignedBlock :: Blinded ( Arc :: new ( block) )
356
- }
357
- } ) ;
336
+ . sign_block ( * validator_pubkey, unsigned_block, slot)
337
+ . await ;
358
338
359
339
let signed_block = match res {
360
340
Ok ( block) => block,
@@ -398,12 +378,13 @@ impl<S: ValidatorStore + 'static, T: SlotClock + 'static> BlockService<S, T> {
398
378
} )
399
379
. await ?;
400
380
381
+ let metadata = BlockMetadata :: from ( & signed_block) ;
401
382
info ! (
402
- block_type = ?signed_block . block_type( ) ,
403
- deposits = signed_block . num_deposits( ) ,
404
- attestations = signed_block . num_attestations( ) ,
383
+ block_type = ?metadata . block_type,
384
+ deposits = metadata . num_deposits,
385
+ attestations = metadata . num_attestations,
405
386
graffiti = ?graffiti. map( |g| g. as_utf8_lossy( ) ) ,
406
- slot = signed_block . slot( ) . as_u64( ) ,
387
+ slot = metadata . slot. as_u64( ) ,
407
388
"Successfully published block"
408
389
) ;
409
390
Ok ( ( ) )
@@ -508,7 +489,6 @@ impl<S: ValidatorStore + 'static, T: SlotClock + 'static> BlockService<S, T> {
508
489
signed_block : & SignedBlock < S :: E > ,
509
490
beacon_node : BeaconNodeHttpClient ,
510
491
) -> Result < ( ) , BlockError > {
511
- let slot = signed_block. slot ( ) ;
512
492
match signed_block {
513
493
SignedBlock :: Full ( signed_block) => {
514
494
let _post_timer = validator_metrics:: start_timer_vec (
@@ -518,7 +498,9 @@ impl<S: ValidatorStore + 'static, T: SlotClock + 'static> BlockService<S, T> {
518
498
beacon_node
519
499
. post_beacon_blocks_v2_ssz ( signed_block, None )
520
500
. await
521
- . or_else ( |e| handle_block_post_error ( e, slot) ) ?
501
+ . or_else ( |e| {
502
+ handle_block_post_error ( e, signed_block. signed_block ( ) . message ( ) . slot ( ) )
503
+ } ) ?
522
504
}
523
505
SignedBlock :: Blinded ( signed_block) => {
524
506
let _post_timer = validator_metrics:: start_timer_vec (
@@ -528,7 +510,7 @@ impl<S: ValidatorStore + 'static, T: SlotClock + 'static> BlockService<S, T> {
528
510
beacon_node
529
511
. post_beacon_blinded_blocks_v2_ssz ( signed_block, None )
530
512
. await
531
- . or_else ( |e| handle_block_post_error ( e, slot) ) ?
513
+ . or_else ( |e| handle_block_post_error ( e, signed_block . message ( ) . slot ( ) ) ) ?
532
514
}
533
515
}
534
516
Ok :: < _ , BlockError > ( ( ) )
@@ -557,13 +539,17 @@ impl<S: ValidatorStore + 'static, T: SlotClock + 'static> BlockService<S, T> {
557
539
) )
558
540
} ) ?;
559
541
560
- let unsigned_block = match block_response. data {
561
- eth2:: types:: ProduceBlockV3Response :: Full ( block) => UnsignedBlock :: Full ( block) ,
562
- eth2:: types:: ProduceBlockV3Response :: Blinded ( block) => UnsignedBlock :: Blinded ( block) ,
542
+ let ( block_proposer, unsigned_block) = match block_response. data {
543
+ eth2:: types:: ProduceBlockV3Response :: Full ( block) => {
544
+ ( block. block ( ) . proposer_index ( ) , UnsignedBlock :: Full ( block) )
545
+ }
546
+ eth2:: types:: ProduceBlockV3Response :: Blinded ( block) => {
547
+ ( block. proposer_index ( ) , UnsignedBlock :: Blinded ( block) )
548
+ }
563
549
} ;
564
550
565
551
info ! ( slot = slot. as_u64( ) , "Received unsigned block" ) ;
566
- if proposer_index != Some ( unsigned_block . proposer_index ( ) ) {
552
+ if proposer_index != Some ( block_proposer ) {
567
553
return Err ( BlockError :: Recoverable (
568
554
"Proposer index does not match block proposer. Beacon chain re-orged" . to_string ( ) ,
569
555
) ) ;
@@ -573,49 +559,30 @@ impl<S: ValidatorStore + 'static, T: SlotClock + 'static> BlockService<S, T> {
573
559
}
574
560
}
575
561
576
- pub enum UnsignedBlock < E : EthSpec > {
577
- Full ( FullBlockContents < E > ) ,
578
- Blinded ( BlindedBeaconBlock < E > ) ,
579
- }
580
-
581
- impl < E : EthSpec > UnsignedBlock < E > {
582
- pub fn proposer_index ( & self ) -> u64 {
583
- match self {
584
- UnsignedBlock :: Full ( block) => block. block ( ) . proposer_index ( ) ,
585
- UnsignedBlock :: Blinded ( block) => block. proposer_index ( ) ,
586
- }
587
- }
562
+ /// Wrapper for values we want to log about a block we signed, for easy extraction from the possible
563
+ /// variants.
564
+ struct BlockMetadata {
565
+ block_type : BlockType ,
566
+ slot : Slot ,
567
+ num_deposits : usize ,
568
+ num_attestations : usize ,
588
569
}
589
570
590
- #[ derive( Debug ) ]
591
- pub enum SignedBlock < E : EthSpec > {
592
- Full ( PublishBlockRequest < E > ) ,
593
- Blinded ( Arc < SignedBlindedBeaconBlock < E > > ) ,
594
- }
595
-
596
- impl < E : EthSpec > SignedBlock < E > {
597
- pub fn block_type ( & self ) -> BlockType {
598
- match self {
599
- SignedBlock :: Full ( _) => BlockType :: Full ,
600
- SignedBlock :: Blinded ( _) => BlockType :: Blinded ,
601
- }
602
- }
603
- pub fn slot ( & self ) -> Slot {
604
- match self {
605
- SignedBlock :: Full ( block) => block. signed_block ( ) . message ( ) . slot ( ) ,
606
- SignedBlock :: Blinded ( block) => block. message ( ) . slot ( ) ,
607
- }
608
- }
609
- pub fn num_deposits ( & self ) -> usize {
610
- match self {
611
- SignedBlock :: Full ( block) => block. signed_block ( ) . message ( ) . body ( ) . deposits ( ) . len ( ) ,
612
- SignedBlock :: Blinded ( block) => block. message ( ) . body ( ) . deposits ( ) . len ( ) ,
613
- }
614
- }
615
- pub fn num_attestations ( & self ) -> usize {
616
- match self {
617
- SignedBlock :: Full ( block) => block. signed_block ( ) . message ( ) . body ( ) . attestations_len ( ) ,
618
- SignedBlock :: Blinded ( block) => block. message ( ) . body ( ) . attestations_len ( ) ,
571
+ impl < E : EthSpec > From < & SignedBlock < E > > for BlockMetadata {
572
+ fn from ( value : & SignedBlock < E > ) -> Self {
573
+ match value {
574
+ SignedBlock :: Full ( block) => BlockMetadata {
575
+ block_type : BlockType :: Full ,
576
+ slot : block. signed_block ( ) . message ( ) . slot ( ) ,
577
+ num_deposits : block. signed_block ( ) . message ( ) . body ( ) . deposits ( ) . len ( ) ,
578
+ num_attestations : block. signed_block ( ) . message ( ) . body ( ) . attestations_len ( ) ,
579
+ } ,
580
+ SignedBlock :: Blinded ( block) => BlockMetadata {
581
+ block_type : BlockType :: Blinded ,
582
+ slot : block. message ( ) . slot ( ) ,
583
+ num_deposits : block. message ( ) . body ( ) . deposits ( ) . len ( ) ,
584
+ num_attestations : block. message ( ) . body ( ) . attestations_len ( ) ,
585
+ } ,
619
586
}
620
587
}
621
588
}
0 commit comments