Search in sources :

Example 1 with DepositGenerator

use of tech.pegasys.teku.spec.datastructures.util.DepositGenerator in project teku by ConsenSys.

the class DataStructureUtil method newDeposits.

public List<DepositWithIndex> newDeposits(int numDeposits) {
    List<DepositWithIndex> deposits = new ArrayList<>();
    final DepositGenerator depositGenerator = new DepositGenerator(spec);
    for (int i = 0; i < numDeposits; i++) {
        BLSKeyPair keypair = BLSTestUtil.randomKeyPair(i);
        DepositData depositData = depositGenerator.createDepositData(keypair, getMaxEffectiveBalance(), keypair.getPublicKey());
        DepositWithIndex deposit = new DepositWithIndex(Deposit.SSZ_SCHEMA.getProofSchema().getDefault(), depositData, UInt64.valueOf(i));
        deposits.add(deposit);
    }
    return deposits;
}
Also used : DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) DepositGenerator(tech.pegasys.teku.spec.datastructures.util.DepositGenerator) DepositWithIndex(tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex) ArrayList(java.util.ArrayList) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) AnchorPoint(tech.pegasys.teku.spec.datastructures.state.AnchorPoint)

Example 2 with DepositGenerator

use of tech.pegasys.teku.spec.datastructures.util.DepositGenerator in project teku by ConsenSys.

the class GenesisGeneratorTest method shouldActivateToppedUpValidator.

@Test
public void shouldActivateToppedUpValidator() {
    MockStartDepositGenerator mockStartDepositGenerator = new MockStartDepositGenerator(spec, new DepositGenerator(spec, true));
    DepositData PARTIAL_DEPOSIT_DATA = mockStartDepositGenerator.createDeposits(VALIDATOR_KEYS.subList(0, 1), UInt64.valueOf(1000000000L)).get(0);
    DepositData TOP_UP_DEPOSIT_DATA = mockStartDepositGenerator.createDeposits(VALIDATOR_KEYS.subList(0, 1), UInt64.valueOf(31000000000L)).get(0);
    List<DepositData> INITIAL_DEPOSIT_DATA = List.of(PARTIAL_DEPOSIT_DATA, TOP_UP_DEPOSIT_DATA);
    List<Deposit> INITIAL_DEPOSITS = IntStream.range(0, INITIAL_DEPOSIT_DATA.size()).mapToObj(index -> {
        final DepositData data = INITIAL_DEPOSIT_DATA.get(index);
        return new DepositWithIndex(data, UInt64.valueOf(index));
    }).collect(toList());
    genesisGenerator.updateCandidateState(Bytes32.ZERO, UInt64.ZERO, INITIAL_DEPOSITS);
    final BeaconState state = genesisGenerator.getGenesisState();
    Assertions.<Integer>assertThat(spec.getActiveValidatorIndices(state, GENESIS_EPOCH)).hasSize(1);
    assertThat(genesisGenerator.getActiveValidatorCount()).isEqualTo(1);
}
Also used : DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) IntStream(java.util.stream.IntStream) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) BLSKeyPair(tech.pegasys.teku.bls.BLSKeyPair) SpecVersion(tech.pegasys.teku.spec.SpecVersion) ArrayList(java.util.ArrayList) ExecutionPayloadHeader(tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) Assertions(org.assertj.core.api.Assertions) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Spec(tech.pegasys.teku.spec.Spec) Bytes32(org.apache.tuweni.bytes.Bytes32) Validator(tech.pegasys.teku.spec.datastructures.state.Validator) BeaconStateBellatrix(tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.bellatrix.BeaconStateBellatrix) BLSSignature(tech.pegasys.teku.bls.BLSSignature) GENESIS_EPOCH(tech.pegasys.teku.spec.config.SpecConfig.GENESIS_EPOCH) Deposit(tech.pegasys.teku.spec.datastructures.operations.Deposit) Test(org.junit.jupiter.api.Test) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) DepositWithIndex(tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex) TestSpecFactory(tech.pegasys.teku.spec.TestSpecFactory) DepositGenerator(tech.pegasys.teku.spec.datastructures.util.DepositGenerator) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Optional(java.util.Optional) Collections(java.util.Collections) BLSKeyGenerator(tech.pegasys.teku.bls.BLSKeyGenerator) DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Deposit(tech.pegasys.teku.spec.datastructures.operations.Deposit) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) DepositGenerator(tech.pegasys.teku.spec.datastructures.util.DepositGenerator) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) DepositWithIndex(tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Test(org.junit.jupiter.api.Test)

Example 3 with DepositGenerator

use of tech.pegasys.teku.spec.datastructures.util.DepositGenerator in project teku by ConsenSys.

the class StateUpgradeTransitionTest method createGenesis.

private BeaconState createGenesis(final Spec spec) {
    final List<DepositData> initialDepositData = new MockStartDepositGenerator(spec, new DepositGenerator(spec, true)).createDeposits(VALIDATOR_KEYS, spec.getGenesisSpecConfig().getMaxEffectiveBalance());
    final List<DepositWithIndex> deposits = new ArrayList<>();
    for (int index = 0; index < initialDepositData.size(); index++) {
        final DepositData data = initialDepositData.get(index);
        DepositWithIndex deposit = new DepositWithIndex(data, UInt64.valueOf(index));
        deposits.add(deposit);
    }
    final BeaconState initialState = spec.initializeBeaconStateFromEth1(Bytes32.ZERO, UInt64.ZERO, deposits, Optional.empty());
    return initialState.updated(state -> state.setGenesis_time(UInt64.ZERO));
}
Also used : DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) DepositGenerator(tech.pegasys.teku.spec.datastructures.util.DepositGenerator) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) DepositWithIndex(tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex) ArrayList(java.util.ArrayList) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 4 with DepositGenerator

use of tech.pegasys.teku.spec.datastructures.util.DepositGenerator in project teku by ConsenSys.

the class ChainBuilder method generateGenesis.

public SignedBlockAndState generateGenesis(final UInt64 genesisTime, final boolean signDeposits, final UInt64 depositAmount, final Optional<ExecutionPayloadHeader> payloadHeader) {
    checkState(blocks.isEmpty(), "Genesis already created");
    // Generate genesis state
    final List<DepositData> initialDepositData = new MockStartDepositGenerator(spec, new DepositGenerator(spec, signDeposits)).createDeposits(validatorKeys, depositAmount);
    BeaconState genesisState = new MockStartBeaconStateGenerator(spec).createInitialBeaconState(genesisTime, initialDepositData, payloadHeader);
    // Generate genesis block
    BeaconBlock genesisBlock = BeaconBlock.fromGenesisState(spec, genesisState);
    final SignedBeaconBlock signedBlock = SignedBeaconBlock.create(spec, genesisBlock, BLSSignature.empty());
    final SignedBlockAndState blockAndState = new SignedBlockAndState(signedBlock, genesisState);
    trackBlock(blockAndState);
    return blockAndState;
}
Also used : DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) MockStartBeaconStateGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartBeaconStateGenerator) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) DepositGenerator(tech.pegasys.teku.spec.datastructures.util.DepositGenerator) MockStartDepositGenerator(tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator) BeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SignedBeaconBlock(tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock) SignedBlockAndState(tech.pegasys.teku.spec.datastructures.blocks.SignedBlockAndState) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Aggregations

DepositData (tech.pegasys.teku.spec.datastructures.operations.DepositData)4 DepositGenerator (tech.pegasys.teku.spec.datastructures.util.DepositGenerator)4 ArrayList (java.util.ArrayList)3 MockStartDepositGenerator (tech.pegasys.teku.spec.datastructures.interop.MockStartDepositGenerator)3 DepositWithIndex (tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex)3 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)3 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)2 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors.toList (java.util.stream.Collectors.toList)1 IntStream (java.util.stream.IntStream)1 Bytes32 (org.apache.tuweni.bytes.Bytes32)1 Assertions (org.assertj.core.api.Assertions)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Test (org.junit.jupiter.api.Test)1 BLSKeyGenerator (tech.pegasys.teku.bls.BLSKeyGenerator)1 BLSSignature (tech.pegasys.teku.bls.BLSSignature)1 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)1