use of tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary 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.spec.datastructures.blocks.StateAndBlockSummary 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.spec.datastructures.blocks.StateAndBlockSummary 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.spec.datastructures.blocks.StateAndBlockSummary 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);
}
use of tech.pegasys.teku.spec.datastructures.blocks.StateAndBlockSummary in project teku by ConsenSys.
the class AggregateAttestationValidatorTest method shouldReturnValidForValidAggregate.
@Test
public void shouldReturnValidForValidAggregate() {
final StateAndBlockSummary chainHead = storageSystem.getChainHead();
final SignedAggregateAndProof aggregate = generator.validAggregateAndProof(chainHead);
whenAttestationIsValid(aggregate);
assertThat(validator.validate(ValidateableAttestation.aggregateFromValidator(spec, aggregate))).isCompletedWithValue(InternalValidationResult.ACCEPT);
}
Aggregations