@@ -599,6 +599,40 @@ impl SlashingDatabase {
599
599
Ok ( safe)
600
600
}
601
601
602
+ /// Check whether a block would be safe to sign if we were to sign it now.
603
+ ///
604
+ /// The database is not modified, and therefore multiple threads reading the database might get
605
+ /// the same result. Therefore:
606
+ ///
607
+ /// DO NOT USE THIS FUNCTION TO DECIDE IF A BLOCK IS SAFE TO SIGN!
608
+ pub fn preliminary_check_block_proposal (
609
+ & self ,
610
+ validator_pubkey : & PublicKeyBytes ,
611
+ block_header : & BeaconBlockHeader ,
612
+ domain : Hash256 ,
613
+ ) -> Result < Safe , NotSafe > {
614
+ #[ allow( clippy:: disallowed_methods) ]
615
+ self . preliminary_check_block_signing_root (
616
+ validator_pubkey,
617
+ block_header. slot ,
618
+ block_header. signing_root ( domain) . into ( ) ,
619
+ )
620
+ }
621
+
622
+ /// As for `preliminary_check_block_proposal` but without requiring the whole `BeaconBlockHeader`.
623
+ ///
624
+ /// DO NOT USE THIS FUNCTION TO DECIDE IF A BLOCK IS SAFE TO SIGN!
625
+ pub fn preliminary_check_block_signing_root (
626
+ & self ,
627
+ validator_pubkey : & PublicKeyBytes ,
628
+ slot : Slot ,
629
+ signing_root : SigningRoot ,
630
+ ) -> Result < Safe , NotSafe > {
631
+ let mut conn = self . conn_pool . get ( ) ?;
632
+ let txn = conn. transaction_with_behavior ( TransactionBehavior :: Exclusive ) ?;
633
+ self . check_block_proposal ( & txn, validator_pubkey, slot, signing_root)
634
+ }
635
+
602
636
/// Check an attestation for slash safety, and if it is safe, record it in the database.
603
637
///
604
638
/// The checking and inserting happen atomically and exclusively. We enforce exclusivity
@@ -670,6 +704,49 @@ impl SlashingDatabase {
670
704
Ok ( safe)
671
705
}
672
706
707
+ /// Check whether an attestation would be safe to sign if we were to sign it now.
708
+ ///
709
+ /// The database is not modified, and therefore multiple threads reading the database might get
710
+ /// the same result. Therefore:
711
+ ///
712
+ /// DO NOT USE THIS FUNCTION TO DECIDE IF AN ATTESTATION IS SAFE TO SIGN!
713
+ pub fn preliminary_check_attestation (
714
+ & self ,
715
+ validator_pubkey : & PublicKeyBytes ,
716
+ attestation : & AttestationData ,
717
+ domain : Hash256 ,
718
+ ) -> Result < Safe , NotSafe > {
719
+ let attestation_signing_root = attestation. signing_root ( domain) . into ( ) ;
720
+ #[ allow( clippy:: disallowed_methods) ]
721
+ self . preliminary_check_attestation_signing_root (
722
+ validator_pubkey,
723
+ attestation. source . epoch ,
724
+ attestation. target . epoch ,
725
+ attestation_signing_root,
726
+ )
727
+ }
728
+
729
+ /// As for `preliminary_check_attestation` but without requiring the whole `AttestationData`.
730
+ ///
731
+ /// DO NOT USE THIS FUNCTION TO DECIDE IF AN ATTESTATION IS SAFE TO SIGN!
732
+ pub fn preliminary_check_attestation_signing_root (
733
+ & self ,
734
+ validator_pubkey : & PublicKeyBytes ,
735
+ att_source_epoch : Epoch ,
736
+ att_target_epoch : Epoch ,
737
+ att_signing_root : SigningRoot ,
738
+ ) -> Result < Safe , NotSafe > {
739
+ let mut conn = self . conn_pool . get ( ) ?;
740
+ let txn = conn. transaction_with_behavior ( TransactionBehavior :: Exclusive ) ?;
741
+ self . check_attestation (
742
+ & txn,
743
+ validator_pubkey,
744
+ att_source_epoch,
745
+ att_target_epoch,
746
+ att_signing_root,
747
+ )
748
+ }
749
+
673
750
/// Import slashing protection from another client in the interchange format.
674
751
///
675
752
/// This function will atomically import the entire interchange, failing if *any*
0 commit comments