-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into merge_beacon_apis
- Loading branch information
Showing
7 changed files
with
357 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
198 changes: 198 additions & 0 deletions
198
ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/merge/SpecLogicMerge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
/* | ||
* Copyright 2021 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.teku.spec.logic.versions.merge; | ||
|
||
import static tech.pegasys.teku.spec.logic.common.helpers.MathHelpers.integerSquareRoot; | ||
|
||
import java.util.Optional; | ||
import org.apache.tuweni.bytes.Bytes32; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
import tech.pegasys.teku.spec.config.SpecConfigAltair; | ||
import tech.pegasys.teku.spec.config.SpecConfigMerge; | ||
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; | ||
import tech.pegasys.teku.spec.logic.common.AbstractSpecLogic; | ||
import tech.pegasys.teku.spec.logic.common.helpers.BeaconStateMutators; | ||
import tech.pegasys.teku.spec.logic.common.helpers.Predicates; | ||
import tech.pegasys.teku.spec.logic.common.operations.OperationSignatureVerifier; | ||
import tech.pegasys.teku.spec.logic.common.operations.validation.OperationValidator; | ||
import tech.pegasys.teku.spec.logic.common.statetransition.attestation.AttestationWorthinessChecker; | ||
import tech.pegasys.teku.spec.logic.common.util.AttestationUtil; | ||
import tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil; | ||
import tech.pegasys.teku.spec.logic.common.util.BlockProposalUtil; | ||
import tech.pegasys.teku.spec.logic.common.util.ForkChoiceUtil; | ||
import tech.pegasys.teku.spec.logic.common.util.SyncCommitteeUtil; | ||
import tech.pegasys.teku.spec.logic.common.util.ValidatorsUtil; | ||
import tech.pegasys.teku.spec.logic.versions.altair.block.BlockProcessorAltair; | ||
import tech.pegasys.teku.spec.logic.versions.altair.forktransition.AltairStateUpgrade; | ||
import tech.pegasys.teku.spec.logic.versions.altair.helpers.BeaconStateAccessorsAltair; | ||
import tech.pegasys.teku.spec.logic.versions.altair.helpers.MiscHelpersAltair; | ||
import tech.pegasys.teku.spec.logic.versions.altair.statetransition.attestation.AttestationWorthinessCheckerAltair; | ||
import tech.pegasys.teku.spec.logic.versions.altair.statetransition.epoch.EpochProcessorAltair; | ||
import tech.pegasys.teku.spec.logic.versions.altair.statetransition.epoch.ValidatorStatusFactoryAltair; | ||
import tech.pegasys.teku.spec.logic.versions.merge.helpers.BeaconStateMutatorsMerge; | ||
import tech.pegasys.teku.spec.logic.versions.merge.statetransition.epoch.EpochProcessorMerge; | ||
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsMerge; | ||
|
||
public class SpecLogicMerge extends AbstractSpecLogic { | ||
|
||
private final SpecConfigAltair specConfig; | ||
private final Optional<SyncCommitteeUtil> syncCommitteeUtil; | ||
|
||
private SpecLogicMerge( | ||
final SpecConfigAltair specConfig, | ||
final Predicates predicates, | ||
final MiscHelpersAltair miscHelpers, | ||
final BeaconStateAccessorsAltair beaconStateAccessors, | ||
final BeaconStateMutators beaconStateMutators, | ||
final OperationSignatureVerifier operationSignatureVerifier, | ||
final ValidatorsUtil validatorsUtil, | ||
final BeaconStateUtil beaconStateUtil, | ||
final AttestationUtil attestationUtil, | ||
final OperationValidator operationValidator, | ||
final ValidatorStatusFactoryAltair validatorStatusFactory, | ||
final EpochProcessorAltair epochProcessor, | ||
final BlockProcessorAltair blockProcessor, | ||
final ForkChoiceUtil forkChoiceUtil, | ||
final BlockProposalUtil blockProposalUtil, | ||
final SyncCommitteeUtil syncCommitteeUtil, | ||
final AltairStateUpgrade stateUpgrade) { | ||
super( | ||
predicates, | ||
miscHelpers, | ||
beaconStateAccessors, | ||
beaconStateMutators, | ||
operationSignatureVerifier, | ||
validatorsUtil, | ||
beaconStateUtil, | ||
attestationUtil, | ||
operationValidator, | ||
validatorStatusFactory, | ||
epochProcessor, | ||
blockProcessor, | ||
forkChoiceUtil, | ||
blockProposalUtil, | ||
Optional.of(stateUpgrade)); | ||
this.specConfig = specConfig; | ||
this.syncCommitteeUtil = Optional.of(syncCommitteeUtil); | ||
} | ||
|
||
public static SpecLogicMerge create( | ||
final SpecConfigMerge config, final SchemaDefinitionsMerge schemaDefinitions) { | ||
// Helpers | ||
final Predicates predicates = new Predicates(); | ||
final MiscHelpersAltair miscHelpers = new MiscHelpersAltair(config); | ||
final BeaconStateAccessorsAltair beaconStateAccessors = | ||
new BeaconStateAccessorsAltair(config, predicates, miscHelpers); | ||
final BeaconStateMutatorsMerge beaconStateMutators = | ||
new BeaconStateMutatorsMerge(config, miscHelpers, beaconStateAccessors); | ||
|
||
// Operation validaton | ||
final OperationSignatureVerifier operationSignatureVerifier = | ||
new OperationSignatureVerifier(miscHelpers, beaconStateAccessors); | ||
|
||
// Util | ||
final ValidatorsUtil validatorsUtil = | ||
new ValidatorsUtil(config, miscHelpers, beaconStateAccessors); | ||
final BeaconStateUtil beaconStateUtil = | ||
new BeaconStateUtil( | ||
config, schemaDefinitions, predicates, miscHelpers, beaconStateAccessors); | ||
final AttestationUtil attestationUtil = new AttestationUtil(beaconStateAccessors, miscHelpers); | ||
final OperationValidator operationValidator = | ||
OperationValidator.create( | ||
config, predicates, miscHelpers, beaconStateAccessors, attestationUtil); | ||
final ValidatorStatusFactoryAltair validatorStatusFactory = | ||
new ValidatorStatusFactoryAltair( | ||
config, | ||
beaconStateUtil, | ||
attestationUtil, | ||
predicates, | ||
miscHelpers, | ||
beaconStateAccessors); | ||
final EpochProcessorMerge epochProcessor = | ||
new EpochProcessorMerge( | ||
config, | ||
miscHelpers, | ||
beaconStateAccessors, | ||
beaconStateMutators, | ||
validatorsUtil, | ||
beaconStateUtil, | ||
validatorStatusFactory); | ||
final BlockProcessorAltair blockProcessor = | ||
new BlockProcessorAltair( | ||
config, | ||
predicates, | ||
miscHelpers, | ||
beaconStateAccessors, | ||
beaconStateMutators, | ||
operationSignatureVerifier, | ||
beaconStateUtil, | ||
attestationUtil, | ||
validatorsUtil, | ||
operationValidator); | ||
final ForkChoiceUtil forkChoiceUtil = | ||
new ForkChoiceUtil( | ||
config, beaconStateAccessors, attestationUtil, blockProcessor, miscHelpers); | ||
final BlockProposalUtil blockProposalUtil = | ||
new BlockProposalUtil(schemaDefinitions, blockProcessor); | ||
final SyncCommitteeUtil syncCommitteeUtil = | ||
new SyncCommitteeUtil( | ||
beaconStateAccessors, validatorsUtil, config, miscHelpers, schemaDefinitions); | ||
|
||
// State upgrade | ||
final AltairStateUpgrade stateUpgrade = | ||
new AltairStateUpgrade( | ||
config, schemaDefinitions, beaconStateAccessors, attestationUtil, miscHelpers); | ||
|
||
return new SpecLogicMerge( | ||
config, | ||
predicates, | ||
miscHelpers, | ||
beaconStateAccessors, | ||
beaconStateMutators, | ||
operationSignatureVerifier, | ||
validatorsUtil, | ||
beaconStateUtil, | ||
attestationUtil, | ||
operationValidator, | ||
validatorStatusFactory, | ||
epochProcessor, | ||
blockProcessor, | ||
forkChoiceUtil, | ||
blockProposalUtil, | ||
syncCommitteeUtil, | ||
stateUpgrade); | ||
} | ||
|
||
@Override | ||
public Optional<SyncCommitteeUtil> getSyncCommitteeUtil() { | ||
return syncCommitteeUtil; | ||
} | ||
|
||
@Override | ||
public AttestationWorthinessChecker createAttestationWorthinessChecker(final BeaconState state) { | ||
final UInt64 currentSlot = state.getSlot(); | ||
final UInt64 startSlot = | ||
miscHelpers.computeStartSlotAtEpoch(miscHelpers.computeEpochAtSlot(currentSlot)); | ||
|
||
final Bytes32 expectedAttestationTarget = | ||
startSlot.compareTo(currentSlot) == 0 || currentSlot.compareTo(startSlot) <= 0 | ||
? state.getLatest_block_header().getRoot() | ||
: beaconStateAccessors.getBlockRootAtSlot(state, startSlot); | ||
|
||
final UInt64 oldestWorthySlotForSourceReward = | ||
state.getSlot().minusMinZero(integerSquareRoot(specConfig.getSlotsPerEpoch())); | ||
return new AttestationWorthinessCheckerAltair( | ||
expectedAttestationTarget, oldestWorthySlotForSourceReward); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...in/java/tech/pegasys/teku/spec/logic/versions/merge/helpers/BeaconStateMutatorsMerge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2021 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.teku.spec.logic.versions.merge.helpers; | ||
|
||
import tech.pegasys.teku.spec.config.SpecConfigMerge; | ||
import tech.pegasys.teku.spec.logic.common.helpers.BeaconStateAccessors; | ||
import tech.pegasys.teku.spec.logic.common.helpers.MiscHelpers; | ||
import tech.pegasys.teku.spec.logic.versions.altair.helpers.BeaconStateMutatorsAltair; | ||
|
||
public class BeaconStateMutatorsMerge extends BeaconStateMutatorsAltair { | ||
|
||
private final SpecConfigMerge specConfigMerge; | ||
|
||
public BeaconStateMutatorsMerge( | ||
final SpecConfigMerge specConfig, | ||
final MiscHelpers miscHelpers, | ||
final BeaconStateAccessors beaconStateAccessors) { | ||
super(specConfig, miscHelpers, beaconStateAccessors); | ||
specConfigMerge = specConfig; | ||
} | ||
|
||
@Override | ||
protected int getMinSlashingPenaltyQuotient() { | ||
return specConfigMerge.getMinSlashingPenaltyQuotientMerge(); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...ech/pegasys/teku/spec/logic/versions/merge/statetransition/epoch/EpochProcessorMerge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2021 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.teku.spec.logic.versions.merge.statetransition.epoch; | ||
|
||
import tech.pegasys.teku.spec.config.SpecConfigMerge; | ||
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; | ||
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.merge.BeaconStateMerge; | ||
import tech.pegasys.teku.spec.logic.common.helpers.BeaconStateMutators; | ||
import tech.pegasys.teku.spec.logic.common.statetransition.epoch.RewardAndPenaltyDeltas; | ||
import tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatusFactory; | ||
import tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatuses; | ||
import tech.pegasys.teku.spec.logic.common.util.BeaconStateUtil; | ||
import tech.pegasys.teku.spec.logic.common.util.ValidatorsUtil; | ||
import tech.pegasys.teku.spec.logic.versions.altair.helpers.BeaconStateAccessorsAltair; | ||
import tech.pegasys.teku.spec.logic.versions.altair.helpers.MiscHelpersAltair; | ||
import tech.pegasys.teku.spec.logic.versions.altair.statetransition.epoch.EpochProcessorAltair; | ||
|
||
public class EpochProcessorMerge extends EpochProcessorAltair { | ||
|
||
private final SpecConfigMerge specConfigMerge; | ||
|
||
public EpochProcessorMerge( | ||
final SpecConfigMerge specConfig, | ||
final MiscHelpersAltair miscHelpers, | ||
final BeaconStateAccessorsAltair beaconStateAccessors, | ||
final BeaconStateMutators beaconStateMutators, | ||
final ValidatorsUtil validatorsUtil, | ||
final BeaconStateUtil beaconStateUtil, | ||
final ValidatorStatusFactory validatorStatusFactory) { | ||
super( | ||
specConfig, | ||
miscHelpers, | ||
beaconStateAccessors, | ||
beaconStateMutators, | ||
validatorsUtil, | ||
beaconStateUtil, | ||
validatorStatusFactory); | ||
specConfigMerge = specConfig; | ||
} | ||
|
||
@Override | ||
public RewardAndPenaltyDeltas getRewardAndPenaltyDeltas( | ||
final BeaconState genericState, final ValidatorStatuses validatorStatuses) { | ||
final BeaconStateMerge state = BeaconStateMerge.required(genericState); | ||
final RewardsAndPenaltiesCalculatorMerge calculator = | ||
new RewardsAndPenaltiesCalculatorMerge( | ||
specConfigMerge, | ||
state, | ||
validatorStatuses, | ||
miscHelpersAltair, | ||
beaconStateAccessorsAltair); | ||
|
||
return calculator.getDeltas(); | ||
} | ||
|
||
@Override | ||
protected int getProportionalSlashingMultiplier() { | ||
return specConfigMerge.getProportionalSlashingMultiplierMerge(); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...u/spec/logic/versions/merge/statetransition/epoch/RewardsAndPenaltiesCalculatorMerge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2021 ConsenSys AG. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.teku.spec.logic.versions.merge.statetransition.epoch; | ||
|
||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
import tech.pegasys.teku.spec.config.SpecConfigMerge; | ||
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.merge.BeaconStateMerge; | ||
import tech.pegasys.teku.spec.logic.common.statetransition.epoch.status.ValidatorStatuses; | ||
import tech.pegasys.teku.spec.logic.versions.altair.helpers.BeaconStateAccessorsAltair; | ||
import tech.pegasys.teku.spec.logic.versions.altair.helpers.MiscHelpersAltair; | ||
import tech.pegasys.teku.spec.logic.versions.altair.statetransition.epoch.RewardsAndPenaltiesCalculatorAltair; | ||
|
||
public class RewardsAndPenaltiesCalculatorMerge extends RewardsAndPenaltiesCalculatorAltair { | ||
|
||
private final SpecConfigMerge specConfigMerge; | ||
|
||
public RewardsAndPenaltiesCalculatorMerge( | ||
final SpecConfigMerge specConfig, | ||
final BeaconStateMerge state, | ||
final ValidatorStatuses validatorStatuses, | ||
final MiscHelpersAltair miscHelpers, | ||
final BeaconStateAccessorsAltair beaconStateAccessors) { | ||
super(specConfig, state, validatorStatuses, miscHelpers, beaconStateAccessors); | ||
specConfigMerge = specConfig; | ||
} | ||
|
||
@Override | ||
protected UInt64 getInactivityPenaltyQuotient() { | ||
return specConfigMerge.getInactivityPenaltyQuotientMerge(); | ||
} | ||
} |