use of tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread in project teku by ConsenSys.
the class AbstractDataBackedRestAPIIntegrationTest method setupStorage.
private void setupStorage(final StateStorageMode storageMode, final boolean useMockForkChoice, final SpecMilestone specMilestone) {
this.spec = TestSpecFactory.createMinimal(specMilestone);
this.specConfig = spec.getGenesisSpecConfig();
this.storageSystem = InMemoryStorageSystemBuilder.create().specProvider(spec).storageMode(storageMode).build();
activeValidatorChannel = new ActiveValidatorCache(spec, 10);
recentChainData = storageSystem.recentChainData();
chainBuilder = ChainBuilder.create(spec, VALIDATOR_KEYS);
chainUpdater = new ChainUpdater(recentChainData, chainBuilder, spec);
forkChoice = useMockForkChoice ? mock(ForkChoice.class) : new ForkChoice(spec, new InlineEventThread(), recentChainData, new StubForkChoiceNotifier(), new MergeTransitionBlockValidator(spec, recentChainData, ExecutionEngineChannel.NOOP));
}
use of tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread in project teku by ConsenSys.
the class EpochTransitionBenchmark method init.
@Setup(Level.Trial)
public void init() throws Exception {
AbstractBlockProcessor.BLS_VERIFY_DEPOSIT = false;
String blocksFile = "/blocks/blocks_epoch_" + spec.getSlotsPerEpoch(UInt64.ZERO) + "_validators_" + validatorsCount + ".ssz.gz";
String keysFile = "/bls-key-pairs/bls-key-pairs-200k-seed-0.txt.gz";
System.out.println("Generating keypairs from " + keysFile);
List<BLSKeyPair> validatorKeys = BlsKeyPairIO.createReaderForResource(keysFile).readAll(validatorsCount);
final BlockImportNotifications blockImportNotifications = mock(BlockImportNotifications.class);
spec = TestSpecFactory.createMainnetPhase0();
epochProcessor = spec.getGenesisSpec().getEpochProcessor();
wsValidator = WeakSubjectivityFactory.lenientValidator();
recentChainData = MemoryOnlyRecentChainData.create(spec);
final MergeTransitionBlockValidator transitionBlockValidator = new MergeTransitionBlockValidator(spec, recentChainData, ExecutionEngineChannel.NOOP);
ForkChoice forkChoice = new ForkChoice(spec, new InlineEventThread(), recentChainData, new StubForkChoiceNotifier(), transitionBlockValidator);
localChain = BeaconChainUtil.create(spec, recentChainData, validatorKeys, false);
localChain.initializeStorage();
blockImporter = new BlockImporter(spec, blockImportNotifications, recentChainData, forkChoice, wsValidator, ExecutionEngineChannel.NOOP);
blockIterator = BlockIO.createResourceReader(spec, blocksFile).iterator();
System.out.println("Importing 63 blocks from " + blocksFile);
for (int i = 0; i < 63; i++) {
SignedBeaconBlock block = blockIterator.next();
localChain.setSlot(block.getSlot());
lastResult = blockImporter.importBlock(block).join();
}
preEpochTransitionState = safeJoin(recentChainData.getBestState().orElseThrow());
validatorStatuses = spec.getGenesisSpec().getValidatorStatusFactory().createValidatorStatuses(preEpochTransitionState);
preEpochTransitionState.updated(mbs -> preEpochTransitionMutableState = mbs);
attestationDeltas = epochProcessor.getRewardAndPenaltyDeltas(preEpochTransitionState, validatorStatuses);
System.out.println("Done!");
}
use of tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread in project teku by ConsenSys.
the class ForkChoiceTestExecutor method runTest.
@Override
public void runTest(final TestDefinition testDefinition) throws Throwable {
if (testsToSkip.contains(testDefinition.getTestName())) {
throw new TestAbortedException("Test " + testDefinition.getDisplayName() + " has been ignored");
}
// Note: The fork choice spec says there may be settings in a meta.yaml file but currently no
// tests actually have one, so we currently don't bother trying to load it.
final BeaconState anchorState = TestDataUtils.loadStateFromSsz(testDefinition, "anchor_state.ssz_snappy");
final Spec spec = testDefinition.getSpec();
final SignedBeaconBlock anchorBlock = loadAnchorBlock(testDefinition);
final StorageSystem storageSystem = InMemoryStorageSystemBuilder.create().specProvider(spec).build();
final RecentChainData recentChainData = storageSystem.recentChainData();
recentChainData.initializeFromAnchorPoint(AnchorPoint.fromInitialBlockAndState(spec, new SignedBlockAndState(anchorBlock, anchorState)), spec.getSlotStartTime(anchorBlock.getSlot(), anchorState.getGenesis_time()));
final MergeTransitionBlockValidator transitionBlockValidator = new MergeTransitionBlockValidator(spec, recentChainData, ExecutionEngineChannel.NOOP);
final ForkChoice forkChoice = new ForkChoice(spec, new InlineEventThread(), recentChainData, new StubForkChoiceNotifier(), transitionBlockValidator, true);
final StubExecutionEngineChannel executionEngine = new StubExecutionEngineChannel(spec);
runSteps(testDefinition, spec, recentChainData, forkChoice, executionEngine);
}
use of tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread in project teku by ConsenSys.
the class BlockImporterTest method importBlock_nonFinalizingChain_skipWSPChecks.
@Test
public void importBlock_nonFinalizingChain_skipWSPChecks() throws Exception {
final StorageSystem storageSystem = InMemoryStorageSystemBuilder.buildDefault();
storageSystem.chainUpdater().initializeGenesis();
final ForkChoice forkChoice = new ForkChoice(spec, new InlineEventThread(), storageSystem.recentChainData(), forkChoiceNotifier, transitionBlockValidator);
final BlockImporter blockImporter = new BlockImporter(spec, blockImportNotifications, storageSystem.recentChainData(), forkChoice, weakSubjectivityValidator, ExecutionEngineChannel.NOOP);
// Set current time to be several WSP's ahead of finalized checkpoint
final UInt64 wsPeriod = UInt64.valueOf(10);
final UInt64 wsPeriodInSlots = wsPeriod.times(genesisConfig.getSlotsPerEpoch());
when(weakSubjectivityValidator.getWSPeriod(any())).thenReturn(Optional.of(wsPeriod));
final UInt64 currentSlot = wsPeriodInSlots.times(3).plus(1);
storageSystem.chainUpdater().setCurrentSlot(currentSlot);
// Add a recent block
final SignedBlockAndState recentBlock = storageSystem.chainUpdater().advanceChain(currentSlot.minus(wsPeriodInSlots));
storageSystem.chainUpdater().updateBestBlock(recentBlock);
// Import block new block
final SignedBlockAndState blockToImport = storageSystem.chainBuilder().generateBlockAtSlot(currentSlot);
// Import wsBlock
final BlockImportResult result = blockImporter.importBlock(blockToImport.getBlock()).get();
assertSuccessfulResult(result);
// Verify ws period checks were skipped
verify(weakSubjectivityValidator, never()).validateLatestFinalizedCheckpoint(any(), any());
}
use of tech.pegasys.teku.infrastructure.async.eventthread.InlineEventThread in project teku by ConsenSys.
the class ForkChoiceTestExecutor method runForkChoiceTests.
@ParameterizedTest(name = "{index}.{2} fork choice test")
@MethodSource("loadForkChoiceTests")
void runForkChoiceTests(BeaconState genesis, List<Object> steps, String testName, boolean protoArrayFC) {
RecentChainData storageClient = MemoryOnlyRecentChainData.create(SPEC);
storageClient.initializeFromGenesis(genesis, UInt64.ZERO);
final InlineEventThread forkChoiceExecutor = new InlineEventThread();
final MergeTransitionBlockValidator transitionBlockValidator = new MergeTransitionBlockValidator(SPEC, storageClient, ExecutionEngineChannel.NOOP);
ForkChoice forkChoice = new ForkChoice(SPEC, forkChoiceExecutor, storageClient, new StubForkChoiceNotifier(), transitionBlockValidator);
@SuppressWarnings("ModifiedButNotUsed") List<SignedBeaconBlock> blockBuffer = new ArrayList<>();
@SuppressWarnings("ModifiedButNotUsed") List<Attestation> attestationBuffer = new ArrayList<>();
for (Object step : steps) {
blockBuffer.removeIf(block -> processBlock(forkChoice, block));
attestationBuffer.removeIf(attestation -> processAttestation(forkChoice, attestation));
if (step instanceof UInt64) {
UpdatableStore.StoreTransaction transaction = storageClient.startStoreTransaction();
while (SPEC.getCurrentSlot(transaction).compareTo((UInt64) step) < 0) {
SPEC.onTick(transaction, transaction.getTime().plus(UInt64.ONE));
}
assertEquals(step, SPEC.getCurrentSlot(transaction));
transaction.commit().join();
} else if (step instanceof SignedBeaconBlock) {
for (Attestation attestation : ((SignedBeaconBlock) step).getMessage().getBody().getAttestations()) {
attestationBuffer.add(attestation);
}
if (!processBlock(forkChoice, (SignedBeaconBlock) step)) {
blockBuffer.add((SignedBeaconBlock) step);
}
} else if (step instanceof Attestation) {
if (!processAttestation(forkChoice, (Attestation) step)) {
attestationBuffer.add((Attestation) step);
}
} else if (step instanceof Map) {
@SuppressWarnings("unchecked") Map<String, Object> checks = (Map<String, Object>) step;
for (Map.Entry<String, Object> e : checks.entrySet()) {
String check = e.getKey();
switch(check) {
case "block_in_store":
{
Bytes32 root = Bytes32.fromHexString((String) e.getValue());
assertTrue(storageClient.retrieveBlockByRoot(root).join().isPresent(), "Block is missing from store :" + root);
break;
}
case "block_not_in_store":
{
Bytes32 root = Bytes32.fromHexString((String) e.getValue());
assertTrue(storageClient.retrieveBlockByRoot(root).join().isEmpty(), "Block should not have been in store :" + root);
break;
}
case "head":
{
Bytes32 root = Bytes32.fromHexString((String) e.getValue());
forkChoice.processHead().join();
Bytes32 head = storageClient.getBestBlockRoot().orElseThrow();
assertEquals(root, head, "Head does not match expected head: \n head: " + head + "\n expectedHead: " + root);
break;
}
case "justified_checkpoint_epoch":
{
UInt64 expected = UInt64.valueOf((Integer) e.getValue());
UInt64 actual = storageClient.getStore().getJustifiedCheckpoint().getEpoch();
assertEquals(expected, actual, "Justified checkpoint epoch does not match expected: \n actual: " + actual + "\n expected: " + expected);
break;
}
default:
throw new IllegalArgumentException();
}
}
} else {
throw new IllegalArgumentException();
}
}
}
Aggregations