use of tech.pegasys.teku.core.AttestationGenerator in project teku by ConsenSys.
the class DefaultPerformanceTrackerTest method shouldDisplayIncorrectHeadBlockRoot.
@Test
void shouldDisplayIncorrectHeadBlockRoot() {
chainUpdater.updateBestBlock(chainUpdater.advanceChainUntil(1));
ChainBuilder chainBuilderFork = chainBuilder.fork();
ChainUpdater chainUpdaterFork = new ChainUpdater(storageSystem.recentChainData(), chainBuilderFork);
chainUpdater.updateBestBlock(chainUpdater.advanceChainUntil(9));
ChainBuilder.BlockOptions block1Options = ChainBuilder.BlockOptions.create();
Attestation attestation1 = createAttestation(10, 9);
block1Options.addAttestation(attestation1);
SignedBlockAndState blockAndState1 = chainBuilder.generateBlockAtSlot(10, block1Options);
chainUpdater.saveBlock(blockAndState1);
chainUpdater.updateBestBlock(blockAndState1);
SignedBlockAndState blockAndState = chainUpdaterFork.advanceChainUntil(8);
ChainBuilder.BlockOptions block2Options = ChainBuilder.BlockOptions.create();
AttestationGenerator attestationGenerator = new AttestationGenerator(spec, chainBuilder.getValidatorKeys());
Attestation attestation2 = attestationGenerator.validAttestation(blockAndState.toUnsigned(), UInt64.valueOf(9));
block2Options.addAttestation(attestation2);
SignedBlockAndState blockAndState2 = chainBuilder.generateBlockAtSlot(11, block2Options);
chainUpdater.saveBlock(blockAndState2);
chainUpdater.updateBestBlock(blockAndState2);
performanceTracker.saveProducedAttestation(attestation1);
performanceTracker.saveProducedAttestation(attestation2);
when(validatorTracker.getNumberOfValidatorsForEpoch(any())).thenReturn(2);
UInt64 slot = spec.computeStartSlotAtEpoch(ATTESTATION_INCLUSION_RANGE.plus(1));
performanceTracker.onSlot(slot);
UInt64 attestationEpoch = spec.computeEpochAtSlot(slot).minus(ATTESTATION_INCLUSION_RANGE);
AttestationPerformance expectedAttestationPerformance = new AttestationPerformance(attestationEpoch, 2, 2, 2, 2, 1, 1.5, 2, 1);
verify(log).performance(expectedAttestationPerformance.toString());
}
use of tech.pegasys.teku.core.AttestationGenerator in project teku by ConsenSys.
the class Generator method generateBlocks.
@Disabled
@Test
public void generateBlocks() throws Exception {
final Spec spec = TestSpecFactory.createMainnetAltair();
AbstractBlockProcessor.BLS_VERIFY_DEPOSIT = false;
System.out.println("Generating keypairs...");
int validatorsCount = 32 * 1024;
List<BLSKeyPair> validatorKeys = BlsKeyPairIO.createReaderForResource("/bls-key-pairs/bls-key-pairs-200k-seed-0.txt.gz").readAll(validatorsCount);
System.out.println("Keypairs done.");
RecentChainData localStorage = MemoryOnlyRecentChainData.create(spec);
BeaconChainUtil localChain = BeaconChainUtil.builder().specProvider(spec).recentChainData(localStorage).validatorKeys(validatorKeys).signDeposits(false).build();
localChain.initializeStorage();
AttestationGenerator attestationGenerator = new AttestationGenerator(spec, validatorKeys);
UInt64 currentSlot = localStorage.getHeadSlot();
List<Attestation> attestations = Collections.emptyList();
final int slotsPerEpoch = spec.getGenesisSpecConfig().getSlotsPerEpoch();
String blocksFile = "blocks_epoch_" + slotsPerEpoch + "_validators_" + validatorsCount + ".ssz.gz";
try (Writer writer = BlockIO.createFileWriter(blocksFile)) {
for (int j = 0; j < 50; j++) {
for (int i = 0; i < slotsPerEpoch; i++) {
long s = System.currentTimeMillis();
currentSlot = currentSlot.plus(UInt64.ONE);
final SignedBeaconBlock block = localChain.createAndImportBlockAtSlotWithAttestations(currentSlot, AttestationGenerator.groupAndAggregateAttestations(attestations));
writer.accept(block);
final StateAndBlockSummary postState = localStorage.getStore().retrieveStateAndBlockSummary(block.getMessage().hashTreeRoot()).join().orElseThrow();
attestations = UInt64.ONE.equals(currentSlot) ? Collections.emptyList() : attestationGenerator.getAttestationsForSlot(postState, currentSlot);
System.out.println("Processed: " + currentSlot + ", " + getCommittees(spec, postState.getState()) + ", " + (System.currentTimeMillis() - s) + " ms");
}
Optional<BeaconState> bestState = localStorage.retrieveBlockState(localStorage.getBestBlockRoot().orElse(null)).join();
System.out.println("Epoch done: " + bestState);
}
}
}
use of tech.pegasys.teku.core.AttestationGenerator in project teku by ConsenSys.
the class BlockImporterTest method importBlock_validAttestations.
@Test
public void importBlock_validAttestations() throws Exception {
UInt64 currentSlot = UInt64.ONE;
SignedBeaconBlock block1 = localChain.createAndImportBlockAtSlot(currentSlot);
currentSlot = currentSlot.plus(UInt64.ONE);
AttestationGenerator attestationGenerator = new AttestationGenerator(spec, validatorKeys);
final StateAndBlockSummary stateAndBlock = recentChainData.getStore().retrieveStateAndBlockSummary(block1.getRoot()).join().orElseThrow();
List<Attestation> attestations = attestationGenerator.getAttestationsForSlot(stateAndBlock, currentSlot);
List<Attestation> aggregatedAttestations = AttestationGenerator.groupAndAggregateAttestations(attestations);
currentSlot = currentSlot.plus(UInt64.ONE);
localChain.createAndImportBlockAtSlotWithAttestations(currentSlot, aggregatedAttestations);
}
use of tech.pegasys.teku.core.AttestationGenerator in project teku by ConsenSys.
the class BlockImporterTest method importBlock_attestationWithInvalidSignature.
@Test
public void importBlock_attestationWithInvalidSignature() throws Exception {
UInt64 currentSlot = UInt64.ONE;
SignedBeaconBlock block1 = localChain.createAndImportBlockAtSlot(currentSlot);
currentSlot = currentSlot.plus(UInt64.ONE);
AttestationGenerator attestationGenerator = new AttestationGenerator(spec, validatorKeys);
final StateAndBlockSummary stateAndBlock = recentChainData.getStore().retrieveStateAndBlockSummary(block1.getRoot()).join().orElseThrow();
List<Attestation> attestations = attestationGenerator.getAttestationsForSlot(stateAndBlock, currentSlot);
List<Attestation> aggregatedAttestations = AttestationGenerator.groupAndAggregateAttestations(attestations);
// make one attestation signature invalid
int invalidAttIdx = aggregatedAttestations.size() / 2;
Attestation att = aggregatedAttestations.get(invalidAttIdx);
Attestation invalidAtt = attestationSchema.create(att.getAggregationBits(), att.getData(), BLSTestUtil.randomSignature(1));
aggregatedAttestations.set(invalidAttIdx, invalidAtt);
UInt64 currentSlotFinal = currentSlot.plus(UInt64.ONE);
assertThatCode(() -> {
localChain.createAndImportBlockAtSlotWithAttestations(currentSlotFinal, aggregatedAttestations);
}).hasMessageContaining("signature");
}
use of tech.pegasys.teku.core.AttestationGenerator in project teku by ConsenSys.
the class BlockImporterTest method importBlock_wrongChain.
@Test
public void importBlock_wrongChain() throws Exception {
UInt64 currentSlot = recentChainData.getHeadSlot();
for (int i = 0; i < 3; i++) {
currentSlot = currentSlot.plus(UInt64.ONE);
localChain.createAndImportBlockAtSlot(currentSlot);
}
// Update finalized epoch
final StoreTransaction tx = recentChainData.startStoreTransaction();
final Bytes32 finalizedRoot = recentChainData.getBestBlockRoot().orElseThrow();
final UInt64 finalizedEpoch = UInt64.ONE;
final Checkpoint finalized = new Checkpoint(finalizedEpoch, finalizedRoot);
tx.setFinalizedCheckpoint(finalized);
tx.commit().join();
// Now create a new block that is not descendant from the finalized block
AttestationGenerator attestationGenerator = new AttestationGenerator(spec, validatorKeys);
final StateAndBlockSummary blockAndState = safeJoin(otherStorage.getChainHead().orElseThrow().asStateAndBlockSummary());
final Attestation attestation = attestationGenerator.validAttestation(blockAndState);
final SignedBeaconBlock block = otherChain.createAndImportBlockAtSlotWithAttestations(currentSlot, List.of(attestation));
final BlockImportResult result = blockImporter.importBlock(block).get();
assertImportFailed(result, FailureReason.UNKNOWN_PARENT);
}
Aggregations