Skip to content

Commit 2a391ce

Browse files
authored
Merge of #9294
2 parents 75a7488 + d57ce1b commit 2a391ce

2 files changed

Lines changed: 76 additions & 276 deletions

File tree

consensus/types/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ merkle_proof = { workspace = true }
4444
metastruct = "0.1.0"
4545
milhouse = { workspace = true }
4646
parking_lot = { workspace = true }
47+
paste = { workspace = true }
4748
rand = { workspace = true }
4849
rand_xorshift = { workspace = true }
4950
rayon = { workspace = true }
@@ -67,7 +68,6 @@ yaml_serde = { workspace = true }
6768
[dev-dependencies]
6869
beacon_chain = { workspace = true }
6970
criterion = { workspace = true }
70-
paste = { workspace = true }
7171
state_processing = { workspace = true }
7272
tokio = { workspace = true }
7373
types = { path = ".", features = ["arbitrary"] }

consensus/types/src/block/signed_beacon_block.rs

Lines changed: 75 additions & 275 deletions
Original file line numberDiff line numberDiff line change
@@ -433,285 +433,85 @@ impl<E: EthSpec> From<SignedBeaconBlockAltair<E, BlindedPayload<E>>>
433433
}
434434

435435
// Post-Bellatrix blocks can be "unblinded" by adding the full payload.
436-
// NOTE: It might be nice to come up with a `superstruct` pattern to abstract over this before
437-
// the first fork after Bellatrix.
438-
impl<E: EthSpec> SignedBeaconBlockBellatrix<E, BlindedPayload<E>> {
439-
pub fn into_full_block(
440-
self,
441-
execution_payload: ExecutionPayloadBellatrix<E>,
442-
) -> SignedBeaconBlockBellatrix<E, FullPayload<E>> {
443-
let SignedBeaconBlockBellatrix {
444-
message:
445-
BeaconBlockBellatrix {
446-
slot,
447-
proposer_index,
448-
parent_root,
449-
state_root,
450-
body:
451-
BeaconBlockBodyBellatrix {
452-
randao_reveal,
453-
eth1_data,
454-
graffiti,
455-
proposer_slashings,
456-
attester_slashings,
457-
attestations,
458-
deposits,
459-
voluntary_exits,
460-
sync_aggregate,
461-
execution_payload: BlindedPayloadBellatrix { .. },
462-
},
463-
},
464-
signature,
465-
} = self;
466-
SignedBeaconBlockBellatrix {
467-
message: BeaconBlockBellatrix {
468-
slot,
469-
proposer_index,
470-
parent_root,
471-
state_root,
472-
body: BeaconBlockBodyBellatrix {
473-
randao_reveal,
474-
eth1_data,
475-
graffiti,
476-
proposer_slashings,
477-
attester_slashings,
478-
attestations,
479-
deposits,
480-
voluntary_exits,
481-
sync_aggregate,
482-
execution_payload: FullPayloadBellatrix { execution_payload },
483-
},
484-
},
485-
signature,
486-
}
487-
}
488-
}
489-
490-
impl<E: EthSpec> SignedBeaconBlockCapella<E, BlindedPayload<E>> {
491-
pub fn into_full_block(
492-
self,
493-
execution_payload: ExecutionPayloadCapella<E>,
494-
) -> SignedBeaconBlockCapella<E, FullPayload<E>> {
495-
let SignedBeaconBlockCapella {
496-
message:
497-
BeaconBlockCapella {
498-
slot,
499-
proposer_index,
500-
parent_root,
501-
state_root,
502-
body:
503-
BeaconBlockBodyCapella {
504-
randao_reveal,
505-
eth1_data,
506-
graffiti,
507-
proposer_slashings,
508-
attester_slashings,
509-
attestations,
510-
deposits,
511-
voluntary_exits,
512-
sync_aggregate,
513-
execution_payload: BlindedPayloadCapella { .. },
514-
bls_to_execution_changes,
515-
},
516-
},
517-
signature,
518-
} = self;
519-
SignedBeaconBlockCapella {
520-
message: BeaconBlockCapella {
521-
slot,
522-
proposer_index,
523-
parent_root,
524-
state_root,
525-
body: BeaconBlockBodyCapella {
526-
randao_reveal,
527-
eth1_data,
528-
graffiti,
529-
proposer_slashings,
530-
attester_slashings,
531-
attestations,
532-
deposits,
533-
voluntary_exits,
534-
sync_aggregate,
535-
execution_payload: FullPayloadCapella { execution_payload },
536-
bls_to_execution_changes,
537-
},
538-
},
539-
signature,
540-
}
541-
}
542-
}
543-
544-
impl<E: EthSpec> SignedBeaconBlockDeneb<E, BlindedPayload<E>> {
545-
pub fn into_full_block(
546-
self,
547-
execution_payload: ExecutionPayloadDeneb<E>,
548-
) -> SignedBeaconBlockDeneb<E, FullPayload<E>> {
549-
let SignedBeaconBlockDeneb {
550-
message:
551-
BeaconBlockDeneb {
552-
slot,
553-
proposer_index,
554-
parent_root,
555-
state_root,
556-
body:
557-
BeaconBlockBodyDeneb {
558-
randao_reveal,
559-
eth1_data,
560-
graffiti,
561-
proposer_slashings,
562-
attester_slashings,
563-
attestations,
564-
deposits,
565-
voluntary_exits,
566-
sync_aggregate,
567-
execution_payload: BlindedPayloadDeneb { .. },
568-
bls_to_execution_changes,
569-
blob_kzg_commitments,
570-
},
571-
},
572-
signature,
573-
} = self;
574-
SignedBeaconBlockDeneb {
575-
message: BeaconBlockDeneb {
576-
slot,
577-
proposer_index,
578-
parent_root,
579-
state_root,
580-
body: BeaconBlockBodyDeneb {
581-
randao_reveal,
582-
eth1_data,
583-
graffiti,
584-
proposer_slashings,
585-
attester_slashings,
586-
attestations,
587-
deposits,
588-
voluntary_exits,
589-
sync_aggregate,
590-
execution_payload: FullPayloadDeneb { execution_payload },
591-
bls_to_execution_changes,
592-
blob_kzg_commitments,
593-
},
594-
},
595-
signature,
596-
}
597-
}
598-
}
599-
600-
impl<E: EthSpec> SignedBeaconBlockElectra<E, BlindedPayload<E>> {
601-
pub fn into_full_block(
602-
self,
603-
execution_payload: ExecutionPayloadElectra<E>,
604-
) -> SignedBeaconBlockElectra<E, FullPayload<E>> {
605-
let SignedBeaconBlockElectra {
606-
message:
607-
BeaconBlockElectra {
608-
slot,
609-
proposer_index,
610-
parent_root,
611-
state_root,
612-
body:
613-
BeaconBlockBodyElectra {
614-
randao_reveal,
615-
eth1_data,
616-
graffiti,
617-
proposer_slashings,
618-
attester_slashings,
619-
attestations,
620-
deposits,
621-
voluntary_exits,
622-
sync_aggregate,
623-
execution_payload: BlindedPayloadElectra { .. },
624-
bls_to_execution_changes,
625-
blob_kzg_commitments,
626-
execution_requests,
436+
macro_rules! impl_into_full_block {
437+
($fork:ident, [ $($extra_field:ident),* $(,)? ]) => {
438+
paste::paste! {
439+
impl<E: EthSpec> [<SignedBeaconBlock $fork>]<E, BlindedPayload<E>> {
440+
pub fn into_full_block(
441+
self,
442+
execution_payload: [<ExecutionPayload $fork>]<E>,
443+
) -> [<SignedBeaconBlock $fork>]<E, FullPayload<E>> {
444+
let [<SignedBeaconBlock $fork>] {
445+
message:
446+
[<BeaconBlock $fork>] {
447+
slot,
448+
proposer_index,
449+
parent_root,
450+
state_root,
451+
body:
452+
[<BeaconBlockBody $fork>] {
453+
randao_reveal,
454+
eth1_data,
455+
graffiti,
456+
proposer_slashings,
457+
attester_slashings,
458+
attestations,
459+
deposits,
460+
voluntary_exits,
461+
sync_aggregate,
462+
execution_payload: [<BlindedPayload $fork>] { .. },
463+
$($extra_field,)*
464+
},
465+
},
466+
signature,
467+
} = self;
468+
[<SignedBeaconBlock $fork>] {
469+
message: [<BeaconBlock $fork>] {
470+
slot,
471+
proposer_index,
472+
parent_root,
473+
state_root,
474+
body: [<BeaconBlockBody $fork>] {
475+
randao_reveal,
476+
eth1_data,
477+
graffiti,
478+
proposer_slashings,
479+
attester_slashings,
480+
attestations,
481+
deposits,
482+
voluntary_exits,
483+
sync_aggregate,
484+
execution_payload: [<FullPayload $fork>] { execution_payload },
485+
$($extra_field,)*
486+
},
627487
},
628-
},
629-
signature,
630-
} = self;
631-
SignedBeaconBlockElectra {
632-
message: BeaconBlockElectra {
633-
slot,
634-
proposer_index,
635-
parent_root,
636-
state_root,
637-
body: BeaconBlockBodyElectra {
638-
randao_reveal,
639-
eth1_data,
640-
graffiti,
641-
proposer_slashings,
642-
attester_slashings,
643-
attestations,
644-
deposits,
645-
voluntary_exits,
646-
sync_aggregate,
647-
execution_payload: FullPayloadElectra { execution_payload },
648-
bls_to_execution_changes,
649-
blob_kzg_commitments,
650-
execution_requests,
651-
},
652-
},
653-
signature,
488+
signature,
489+
}
490+
}
491+
}
654492
}
655-
}
493+
};
656494
}
657495

658-
impl<E: EthSpec> SignedBeaconBlockFulu<E, BlindedPayload<E>> {
659-
pub fn into_full_block(
660-
self,
661-
execution_payload: ExecutionPayloadFulu<E>,
662-
) -> SignedBeaconBlockFulu<E, FullPayload<E>> {
663-
let SignedBeaconBlockFulu {
664-
message:
665-
BeaconBlockFulu {
666-
slot,
667-
proposer_index,
668-
parent_root,
669-
state_root,
670-
body:
671-
BeaconBlockBodyFulu {
672-
randao_reveal,
673-
eth1_data,
674-
graffiti,
675-
proposer_slashings,
676-
attester_slashings,
677-
attestations,
678-
deposits,
679-
voluntary_exits,
680-
sync_aggregate,
681-
execution_payload: BlindedPayloadFulu { .. },
682-
bls_to_execution_changes,
683-
blob_kzg_commitments,
684-
execution_requests,
685-
},
686-
},
687-
signature,
688-
} = self;
689-
SignedBeaconBlockFulu {
690-
message: BeaconBlockFulu {
691-
slot,
692-
proposer_index,
693-
parent_root,
694-
state_root,
695-
body: BeaconBlockBodyFulu {
696-
randao_reveal,
697-
eth1_data,
698-
graffiti,
699-
proposer_slashings,
700-
attester_slashings,
701-
attestations,
702-
deposits,
703-
voluntary_exits,
704-
sync_aggregate,
705-
execution_payload: FullPayloadFulu { execution_payload },
706-
bls_to_execution_changes,
707-
blob_kzg_commitments,
708-
execution_requests,
709-
},
710-
},
711-
signature,
712-
}
713-
}
714-
}
496+
impl_into_full_block!(Bellatrix, []);
497+
impl_into_full_block!(Capella, [bls_to_execution_changes]);
498+
impl_into_full_block!(Deneb, [bls_to_execution_changes, blob_kzg_commitments]);
499+
impl_into_full_block!(
500+
Electra,
501+
[
502+
bls_to_execution_changes,
503+
blob_kzg_commitments,
504+
execution_requests
505+
]
506+
);
507+
impl_into_full_block!(
508+
Fulu,
509+
[
510+
bls_to_execution_changes,
511+
blob_kzg_commitments,
512+
execution_requests
513+
]
514+
);
715515

716516
// We can convert gloas blocks without payloads into blocks "with" payloads.
717517
// TODO(EIP-7732) Look into whether we can remove this in the future since no blinded blocks post-gloas

0 commit comments

Comments
 (0)