use of tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List in project teku by ConsenSys.
the class DataStructureUtil method randomIndexedAttestation.
public IndexedAttestation randomIndexedAttestation(final UInt64... attestingIndices) {
final IndexedAttestationSchema indexedAttestationSchema = spec.getGenesisSchemaDefinitions().getIndexedAttestationSchema();
SszUInt64List attesting_indices = indexedAttestationSchema.getAttestingIndicesSchema().of(attestingIndices);
return indexedAttestationSchema.create(attesting_indices, randomAttestationData(), randomSignature());
}
use of tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List in project teku by ConsenSys.
the class ActiveValidatorCacheTest method shouldAcceptAttestations.
@Test
void shouldAcceptAttestations() {
final Attestation attestation = mock(Attestation.class);
final AttestationData attestationData = mock(AttestationData.class);
final IndexedAttestation indexedAttestation = mock(IndexedAttestation.class);
final ValidateableAttestation validateableAttestation = ValidateableAttestation.from(spec, attestation);
validateableAttestation.setIndexedAttestation(indexedAttestation);
when(indexedAttestation.getData()).thenReturn(attestationData);
when(attestationData.getSlot()).thenReturn(UInt64.valueOf(8), UInt64.valueOf(16), UInt64.valueOf(24));
final SszUInt64List validators = SszUInt64ListSchema.create(2).of(UInt64.valueOf(11), UInt64.valueOf(21));
when(indexedAttestation.getAttesting_indices()).thenReturn(validators);
// each attestation will have 2 validators.
// getSlot will return 8, then 16, then 24; and each validator will be processed
cache.onAttestation(validateableAttestation);
cache.onAttestation(validateableAttestation);
cache.onAttestation(validateableAttestation);
assertThat(cache.getValidatorEpochs(UInt64.valueOf(11))).containsExactly(THREE, ONE, TWO);
assertThat(cache.getValidatorEpochs(UInt64.valueOf(21))).containsExactly(THREE, ONE, TWO);
}
use of tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List in project teku by ConsenSys.
the class ExpectedDeltas method getDeltas.
public RewardAndPenaltyDeltas getDeltas() {
final SszUInt64List rewards = getField0();
final SszUInt64List penalties = getField1();
final RewardAndPenaltyDeltas deltas = new RewardAndPenaltyDeltas(rewards.size());
for (int i = 0; i < rewards.size(); i++) {
deltas.getDelta(i).reward(rewards.get(i).get());
deltas.getDelta(i).penalize(penalties.get(i).get());
}
return deltas;
}
use of tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List in project teku by ConsenSys.
the class BlockProcessorAltair method processAttestation.
@Override
protected void processAttestation(final MutableBeaconState genericState, final Attestation attestation, final IndexedAttestationProvider indexedAttestationProvider) {
final MutableBeaconStateAltair state = MutableBeaconStateAltair.required(genericState);
final AttestationData data = attestation.getData();
final List<Integer> participationFlagIndices = beaconStateAccessorsAltair.getAttestationParticipationFlagIndices(state, data, state.getSlot().minus(data.getSlot()));
// Update epoch participation flags
final SszMutableList<SszByte> epochParticipation;
if (data.getTarget().getEpoch().equals(beaconStateAccessors.getCurrentEpoch(state))) {
epochParticipation = state.getCurrentEpochParticipation();
} else {
epochParticipation = state.getPreviousEpochParticipation();
}
UInt64 proposerRewardNumerator = UInt64.ZERO;
final SszUInt64List attestingIndices = indexedAttestationProvider.getIndexedAttestation(attestation).getAttesting_indices();
for (SszUInt64 attestingIndex : attestingIndices) {
final int index = attestingIndex.get().intValue();
byte participationFlags = epochParticipation.get(index).get();
final UInt64 baseReward = beaconStateAccessorsAltair.getBaseReward(state, index);
boolean shouldUpdate = false;
for (int flagIndex = 0; flagIndex < PARTICIPATION_FLAG_WEIGHTS.size(); flagIndex++) {
final UInt64 weight = PARTICIPATION_FLAG_WEIGHTS.get(flagIndex);
if (participationFlagIndices.contains(flagIndex) && !miscHelpersAltair.hasFlag(participationFlags, flagIndex)) {
shouldUpdate = true;
participationFlags = miscHelpersAltair.addFlag(participationFlags, flagIndex);
proposerRewardNumerator = proposerRewardNumerator.plus(baseReward.times(weight));
}
}
if (shouldUpdate) {
epochParticipation.set(index, SszByte.of(participationFlags));
}
}
if (!proposerRewardNumerator.isZero()) {
final int proposerIndex = beaconStateAccessors.getBeaconProposerIndex(state);
final UInt64 proposerRewardDenominator = WEIGHT_DENOMINATOR.minus(PROPOSER_WEIGHT).times(WEIGHT_DENOMINATOR).dividedBy(PROPOSER_WEIGHT);
final UInt64 proposerReward = proposerRewardNumerator.dividedBy(proposerRewardDenominator);
beaconStateMutators.increaseBalance(state, proposerIndex, proposerReward);
}
}
use of tech.pegasys.teku.infrastructure.ssz.collections.SszUInt64List in project teku by ConsenSys.
the class AttestationUtil method isValidIndexedAttestationAsync.
public SafeFuture<AttestationProcessingResult> isValidIndexedAttestationAsync(Fork fork, BeaconState state, IndexedAttestation indexed_attestation, AsyncBLSSignatureVerifier signatureVerifier) {
SszUInt64List indices = indexed_attestation.getAttesting_indices();
if (indices.isEmpty() || !Comparators.isInStrictOrder(indices.asListUnboxed(), Comparator.naturalOrder())) {
return completedFuture(AttestationProcessingResult.invalid("Attesting indices are not sorted"));
}
List<BLSPublicKey> pubkeys = indices.streamUnboxed().flatMap(i -> beaconStateAccessors.getValidatorPubKey(state, i).stream()).collect(toList());
if (pubkeys.size() < indices.size()) {
return completedFuture(AttestationProcessingResult.invalid("Attesting indices include non-existent validator"));
}
BLSSignature signature = indexed_attestation.getSignature();
Bytes32 domain = beaconStateAccessors.getDomain(Domain.BEACON_ATTESTER, indexed_attestation.getData().getTarget().getEpoch(), fork, state.getGenesis_validators_root());
Bytes signing_root = miscHelpers.computeSigningRoot(indexed_attestation.getData(), domain);
return signatureVerifier.verify(pubkeys, signing_root, signature).thenApply(isValidSignature -> {
if (isValidSignature) {
return AttestationProcessingResult.SUCCESSFUL;
} else {
LOG.debug("AttestationUtil.is_valid_indexed_attestation: Verify aggregate signature");
return AttestationProcessingResult.invalid("Signature is invalid");
}
});
}
Aggregations