14
14
package tech .pegasys .teku .spec .logic .common .block ;
15
15
16
16
import static com .google .common .base .Preconditions .checkArgument ;
17
- import static tech .pegasys .teku .spec .config .SpecConfig .FAR_FUTURE_EPOCH ;
18
17
19
18
import com .google .common .annotations .VisibleForTesting ;
20
19
import it .unimi .dsi .fastutil .ints .IntList ;
54
53
import tech .pegasys .teku .spec .datastructures .operations .AttesterSlashing ;
55
54
import tech .pegasys .teku .spec .datastructures .operations .Deposit ;
56
55
import tech .pegasys .teku .spec .datastructures .operations .DepositData ;
57
- import tech .pegasys .teku .spec .datastructures .operations .DepositMessage ;
58
56
import tech .pegasys .teku .spec .datastructures .operations .IndexedAttestation ;
59
57
import tech .pegasys .teku .spec .datastructures .operations .ProposerSlashing ;
60
58
import tech .pegasys .teku .spec .datastructures .operations .SignedVoluntaryExit ;
@@ -682,7 +680,7 @@ private boolean batchVerifyDepositSignatures(final SszList<Deposit> deposits) {
682
680
final BLSPublicKey pubkey = deposit .getData ().getPubkey ();
683
681
publicKeys .add (List .of (pubkey ));
684
682
messages .add (
685
- computeDepositSigningRoot (
683
+ miscHelpers . computeDepositSigningRoot (
686
684
pubkey ,
687
685
deposit .getData ().getWithdrawalCredentials (),
688
686
deposit .getData ().getAmount ()));
@@ -760,34 +758,18 @@ public void applyDeposit(
760
758
// Verify the deposit signature (proof of possession) which is not checked by the deposit
761
759
// contract
762
760
if (signatureAlreadyVerified
763
- || isValidDepositSignature (pubkey , withdrawalCredentials , amount , signature )) {
764
- addValidatorToRegistry (state , pubkey , withdrawalCredentials , amount );
761
+ || miscHelpers .isValidDepositSignature (
762
+ pubkey , withdrawalCredentials , amount , signature )) {
763
+ beaconStateMutators .addValidatorToRegistry (state , pubkey , withdrawalCredentials , amount );
765
764
} else {
766
765
handleInvalidDeposit (pubkey , maybePubkeyToIndexMap );
767
766
}
768
767
} else {
769
- applyDepositToValidatorIndex (
770
- state ,
771
- withdrawalCredentials ,
772
- signatureAlreadyVerified ,
773
- existingIndex .get (),
774
- amount ,
775
- pubkey ,
776
- signature );
768
+ // Increase balance by deposit amount
769
+ beaconStateMutators .increaseBalance (state , existingIndex .get (), amount );
777
770
}
778
771
}
779
772
780
- protected void applyDepositToValidatorIndex (
781
- final MutableBeaconState state ,
782
- final Bytes32 withdrawalCredentials ,
783
- final boolean signatureAlreadyVerified ,
784
- final int validatorIndex ,
785
- final UInt64 amount ,
786
- final BLSPublicKey pubkey ,
787
- final BLSSignature signature ) {
788
- beaconStateMutators .increaseBalance (state , validatorIndex , amount );
789
- }
790
-
791
773
protected void handleInvalidDeposit (
792
774
final BLSPublicKey pubkey ,
793
775
final Optional <Object2IntMap <BLSPublicKey >> maybePubkeyToIndexMap ) {
@@ -799,55 +781,6 @@ protected void handleInvalidDeposit(
799
781
});
800
782
}
801
783
802
- /** is_valid_deposit_signature */
803
- protected boolean isValidDepositSignature (
804
- final BLSPublicKey pubkey ,
805
- final Bytes32 withdrawalCredentials ,
806
- final UInt64 amount ,
807
- final BLSSignature signature ) {
808
- try {
809
- return depositSignatureVerifier .verify (
810
- pubkey , computeDepositSigningRoot (pubkey , withdrawalCredentials , amount ), signature );
811
- } catch (final BlsException e ) {
812
- return false ;
813
- }
814
- }
815
-
816
- private Bytes computeDepositSigningRoot (
817
- final BLSPublicKey pubkey , final Bytes32 withdrawalCredentials , final UInt64 amount ) {
818
- final Bytes32 domain = miscHelpers .computeDomain (Domain .DEPOSIT );
819
- final DepositMessage depositMessage = new DepositMessage (pubkey , withdrawalCredentials , amount );
820
- return miscHelpers .computeSigningRoot (depositMessage , domain );
821
- }
822
-
823
- protected void addValidatorToRegistry (
824
- final MutableBeaconState state ,
825
- final BLSPublicKey pubkey ,
826
- final Bytes32 withdrawalCredentials ,
827
- final UInt64 amount ) {
828
- final Validator validator = getValidatorFromDeposit (pubkey , withdrawalCredentials , amount );
829
- LOG .debug ("Adding new validator with index {} to state" , state .getValidators ().size ());
830
- state .getValidators ().append (validator );
831
- state .getBalances ().appendElement (amount );
832
- }
833
-
834
- protected Validator getValidatorFromDeposit (
835
- final BLSPublicKey pubkey , final Bytes32 withdrawalCredentials , final UInt64 amount ) {
836
- final UInt64 effectiveBalance =
837
- amount
838
- .minus (amount .mod (specConfig .getEffectiveBalanceIncrement ()))
839
- .min (specConfig .getMaxEffectiveBalance ());
840
- return new Validator (
841
- pubkey ,
842
- withdrawalCredentials ,
843
- effectiveBalance ,
844
- false ,
845
- FAR_FUTURE_EPOCH ,
846
- FAR_FUTURE_EPOCH ,
847
- FAR_FUTURE_EPOCH ,
848
- FAR_FUTURE_EPOCH );
849
- }
850
-
851
784
@ Override
852
785
public void processVoluntaryExits (
853
786
final MutableBeaconState state ,
@@ -905,13 +838,6 @@ protected BlockValidationResult verifyVoluntaryExits(
905
838
return BlockValidationResult .SUCCESSFUL ;
906
839
}
907
840
908
- protected void processWithdrawalRequests (
909
- final MutableBeaconState state ,
910
- final BeaconBlockBody beaconBlockBody ,
911
- final Supplier <ValidatorExitContext > validatorExitContextSupplier ) {
912
- // No WithdrawalRequests until Electra
913
- }
914
-
915
841
@ Override
916
842
public void processDepositRequests (
917
843
final MutableBeaconState state , final List <DepositRequest > depositRequests ) {
@@ -952,13 +878,6 @@ protected void safelyProcess(final BlockProcessingAction action) throws BlockPro
952
878
}
953
879
}
954
880
955
- protected void assertCondition (final boolean condition , final String errorMessage )
956
- throws BlockProcessingException {
957
- if (!condition ) {
958
- throw new BlockProcessingException (errorMessage );
959
- }
960
- }
961
-
962
881
public interface IndexedAttestationProvider {
963
882
964
883
IndexedAttestation getIndexedAttestation (final Attestation attestation );
0 commit comments