Skip to content

Commit

Permalink
add Beacon State Accessors
Browse files Browse the repository at this point in the history
  • Loading branch information
mehdi-aouadi committed Jan 14, 2025
1 parent 8315e78 commit 4cf51dc
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import tech.pegasys.teku.spec.logic.versions.capella.operations.validation.OperationValidatorCapella;
import tech.pegasys.teku.spec.logic.versions.deneb.helpers.MiscHelpersDeneb;
import tech.pegasys.teku.spec.logic.versions.deneb.util.ForkChoiceUtilDeneb;
import tech.pegasys.teku.spec.logic.versions.eip7805.helpers.BeaconStateAccessorsEip7805;
import tech.pegasys.teku.spec.logic.versions.electra.block.BlockProcessorElectra;
import tech.pegasys.teku.spec.logic.versions.electra.forktransition.ElectraStateUpgrade;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.BeaconStateAccessorsElectra;
Expand Down Expand Up @@ -101,8 +102,8 @@ public static SpecLogicEip7805 create(
final PredicatesElectra predicates = new PredicatesElectra(config);
final MiscHelpersElectra miscHelpers =
new MiscHelpersElectra(config, predicates, schemaDefinitions);
final BeaconStateAccessorsElectra beaconStateAccessors =
new BeaconStateAccessorsElectra(config, predicates, miscHelpers);
final BeaconStateAccessorsEip7805 beaconStateAccessors =
new BeaconStateAccessorsEip7805(config, predicates, miscHelpers);
final BeaconStateMutatorsElectra beaconStateMutators =
new BeaconStateMutatorsElectra(
config, miscHelpers, beaconStateAccessors, schemaDefinitions);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright Consensys Software Inc., 2025
*
* 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.eip7805.helpers;

import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import org.apache.tuweni.bytes.Bytes32;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.config.SpecConfig;
import tech.pegasys.teku.spec.config.SpecConfigEip7805;
import tech.pegasys.teku.spec.config.SpecConfigElectra;
import tech.pegasys.teku.spec.constants.Domain;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.BeaconStateAccessorsElectra;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.MiscHelpersElectra;
import tech.pegasys.teku.spec.logic.versions.electra.helpers.PredicatesElectra;

public class BeaconStateAccessorsEip7805 extends BeaconStateAccessorsElectra {

private final SpecConfigEip7805 specConfigEip7805;

public BeaconStateAccessorsEip7805(
final SpecConfig specConfig,
final PredicatesElectra predicatesElectra,
final MiscHelpersElectra miscHelpers) {
super(SpecConfigElectra.required(specConfig), predicatesElectra, miscHelpers);
this.specConfigEip7805 = config.toVersionEip7805().orElseThrow();
}

public IntList getInclusionListCommittee(final BeaconState state, final UInt64 slot) {
final UInt64 epoch = miscHelpers.computeEpochAtSlot(slot);
final Bytes32 seed = getSeed(state, epoch, Domain.DOMAIN_IL_COMMITTEE);
final IntList indices = getActiveValidatorIndices(state, epoch);
final int activeValidatorCount = indices.size();
final UInt64 start =
slot.mod(specConfigEip7805.getSlotsPerEpoch())
.times(specConfigEip7805.getIlCommitteeSize());
final UInt64 end = start.plus(specConfigEip7805.getIlCommitteeSize());
final IntList inclusionListCommitteeIndices = new IntArrayList();
for (int index = start.intValue(); index < end.intValue(); index++) {
final int shuffledIndex = miscHelpers.computeShuffledIndex(index, activeValidatorCount, seed);
inclusionListCommitteeIndices.add(indices.getInt(shuffledIndex));
}
return inclusionListCommitteeIndices;
}
}

0 comments on commit 4cf51dc

Please sign in to comment.