Search in sources :

Example 1 with MockStartValidatorKeyPairFactory

use of tech.pegasys.teku.spec.datastructures.interop.MockStartValidatorKeyPairFactory in project teku by ConsenSys.

the class MockStartBeaconStateGeneratorTest method shouldCreateInitialBeaconChainState.

@Test
public void shouldCreateInitialBeaconChainState() {
    final UInt64 genesisTime = UInt64.valueOf(498294294824924924L);
    final int validatorCount = 10;
    final List<BLSKeyPair> validatorKeyPairs = new MockStartValidatorKeyPairFactory().generateKeyPairs(0, validatorCount);
    final List<DepositData> deposits = new MockStartDepositGenerator(spec).createDeposits(validatorKeyPairs);
    final BeaconState initialBeaconState = new MockStartBeaconStateGenerator(spec).createInitialBeaconState(genesisTime, deposits, Optional.empty());
    assertEquals(validatorCount, initialBeaconState.getValidators().size());
    assertEquals(validatorCount, initialBeaconState.getEth1_data().getDeposit_count().longValue());
    final List<BLSPublicKey> actualValidatorPublicKeys = initialBeaconState.getValidators().stream().map(Validator::getPubkeyBytes).map(BLSPublicKey::fromBytesCompressed).collect(Collectors.toList());
    final List<BLSPublicKey> expectedValidatorPublicKeys = validatorKeyPairs.stream().map(BLSKeyPair::getPublicKey).collect(Collectors.toList());
    assertEquals(expectedValidatorPublicKeys, actualValidatorPublicKeys);
}
Also used : DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) MockStartBeaconStateGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartBeaconStateGenerator) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) BLSPublicKey(tech.pegasys.teku.bls.BLSPublicKey) MockStartValidatorKeyPairFactory(tech.pegasys.teku.spec.datastructures.interop.MockStartValidatorKeyPairFactory) Validator(tech.pegasys.teku.spec.datastructures.state.Validator) Test(org.junit.jupiter.api.Test)

Example 2 with MockStartValidatorKeyPairFactory

use of tech.pegasys.teku.spec.datastructures.interop.MockStartValidatorKeyPairFactory in project teku by ConsenSys.

the class InMemoryStorageSystemBuilder method build.

public StorageSystem build() {
    final Database database;
    switch(version) {
        case LEVELDB_TREE:
            database = createLevelDbTreeDatabase();
            break;
        // Leveldb only varies by db type which doesn't apply to in-memory
        case LEVELDB2:
        case V6:
            database = createV6Database();
            break;
        // Leveldb only varies by db type which doesn't apply to in-memory
        case LEVELDB1:
        case V5:
            database = createV5Database();
            break;
        case V4:
            database = createV4Database();
            break;
        default:
            throw new UnsupportedOperationException("Unsupported database version: " + version);
    }
    final List<BLSKeyPair> validatorKeys = new MockStartValidatorKeyPairFactory().generateKeyPairs(0, numberOfValidators);
    return StorageSystem.create(database, createRestartSupplier(), storageMode, storeConfig, spec, ChainBuilder.create(spec, validatorKeys));
}
Also used : Database(tech.pegasys.teku.storage.server.Database) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) MockStartValidatorKeyPairFactory(tech.pegasys.teku.spec.datastructures.interop.MockStartValidatorKeyPairFactory)

Example 3 with MockStartValidatorKeyPairFactory

use of tech.pegasys.teku.spec.datastructures.interop.MockStartValidatorKeyPairFactory in project teku by ConsenSys.

the class GenesisCommand method generate.

@Command(name = "mock", description = "Generate a mock genesis state", mixinStandardHelpOptions = true, showDefaultValues = true, abbreviateSynopsis = true, versionProvider = PicoCliVersionProvider.class, synopsisHeading = "%n", descriptionHeading = "%nDescription:%n%n", optionListHeading = "%nOptions:%n", footerHeading = "%n", footer = "Teku is licensed under the Apache License 2.0")
public void generate(@Mixin MockGenesisParams genesisParams, @Mixin MinimalEth2NetworkOptions networkOptions) throws IOException {
    // Output to stdout if no file is specified
    final Spec spec = networkOptions.getSpec();
    final boolean outputToFile = genesisParams.outputFile != null && !genesisParams.outputFile.isBlank();
    try (final OutputStream fileStream = outputToFile ? new FileOutputStream(genesisParams.outputFile) : System.out) {
        if (outputToFile) {
            SUB_COMMAND_LOG.generatingMockGenesis(genesisParams.validatorCount, genesisParams.genesisTime);
        }
        final long genesisTime = genesisParams.genesisTime;
        final List<BLSKeyPair> validatorKeys = new MockStartValidatorKeyPairFactory().generateKeyPairs(0, genesisParams.validatorCount);
        final BeaconState genesisState = InteropStartupUtil.createMockedStartInitialBeaconState(spec, genesisTime, validatorKeys);
        if (outputToFile) {
            SUB_COMMAND_LOG.storingGenesis(genesisParams.outputFile, false);
        }
        fileStream.write(genesisState.sszSerialize().toArrayUnsafe());
        if (outputToFile) {
            SUB_COMMAND_LOG.storingGenesis(genesisParams.outputFile, true);
        }
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) Spec(tech.pegasys.teku.spec.Spec) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) MockStartValidatorKeyPairFactory(tech.pegasys.teku.spec.datastructures.interop.MockStartValidatorKeyPairFactory) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Command(picocli.CommandLine.Command)

Aggregations

BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)3 MockStartValidatorKeyPairFactory (tech.pegasys.teku.spec.datastructures.interop.MockStartValidatorKeyPairFactory)3 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)2 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 Test (org.junit.jupiter.api.Test)1 Command (picocli.CommandLine.Command)1 BLSPublicKey (tech.pegasys.teku.bls.BLSPublicKey)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1 Spec (tech.pegasys.teku.spec.Spec)1 MockStartBeaconStateGenerator (tech.pegasys.teku.spec.datastructures.interop.MockStartBeaconStateGenerator)1 MockStartDepositGenerator (tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator)1 DepositData (tech.pegasys.teku.spec.datastructures.operations.DepositData)1 Validator (tech.pegasys.teku.spec.datastructures.state.Validator)1 Database (tech.pegasys.teku.storage.server.Database)1