Search in sources :

Example 1 with DepositWithIndex

use of tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex in project teku by ConsenSys.

the class DepositProvider method getDepositsWithProof.

/**
 * @param fromDepositIndex inclusive
 * @param toDepositIndex exclusive
 * @param eth1DepositCount number of deposits in the merkle tree according to Eth1Data in state
 * @return
 */
private SszList<Deposit> getDepositsWithProof(UInt64 fromDepositIndex, UInt64 toDepositIndex, UInt64 eth1DepositCount, long maxDeposits) {
    final AtomicReference<UInt64> expectedDepositIndex = new AtomicReference<>(fromDepositIndex);
    SszListSchema<Deposit, ?> depositsSchema = depositsSchemaCache.get(maxDeposits);
    return depositNavigableMap.subMap(fromDepositIndex, true, toDepositIndex, false).values().stream().map(deposit -> {
        if (!deposit.getIndex().equals(expectedDepositIndex.get())) {
            throw MissingDepositsException.missingRange(expectedDepositIndex.get(), deposit.getIndex());
        }
        expectedDepositIndex.set(deposit.getIndex().plus(ONE));
        SszBytes32Vector proof = Deposit.SSZ_SCHEMA.getProofSchema().of(depositMerkleTree.getProofWithViewBoundary(deposit.getIndex().intValue(), eth1DepositCount.intValue()));
        return new DepositWithIndex(proof, deposit.getData(), deposit.getIndex());
    }).collect(depositsSchema.collector());
}
Also used : SszBytes32Vector(tech.pegasys.teku.infrastructure.ssz.collections.SszBytes32Vector) SszList(tech.pegasys.teku.infrastructure.ssz.SszList) MinGenesisTimeBlockEvent(tech.pegasys.teku.ethereum.pow.api.MinGenesisTimeBlockEvent) ONE(tech.pegasys.teku.infrastructure.unsigned.UInt64.ONE) AtomicReference(java.util.concurrent.atomic.AtomicReference) Eth1Data(tech.pegasys.teku.spec.datastructures.blocks.Eth1Data) SszListSchema(tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64) MerkleTree(tech.pegasys.teku.spec.datastructures.util.MerkleTree) DepositUtil(tech.pegasys.teku.spec.datastructures.util.DepositUtil) DepositsFromBlockEvent(tech.pegasys.teku.ethereum.pow.api.DepositsFromBlockEvent) Spec(tech.pegasys.teku.spec.Spec) FinalizedCheckpointChannel(tech.pegasys.teku.storage.api.FinalizedCheckpointChannel) Bytes32(org.apache.tuweni.bytes.Bytes32) NavigableMap(java.util.NavigableMap) Deposit(tech.pegasys.teku.spec.datastructures.operations.Deposit) DepositWithIndex(tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex) Logger(org.apache.logging.log4j.Logger) TekuMetricCategory(tech.pegasys.teku.infrastructure.metrics.TekuMetricCategory) TreeMap(java.util.TreeMap) RecentChainData(tech.pegasys.teku.storage.client.RecentChainData) MetricsSystem(org.hyperledger.besu.plugin.services.MetricsSystem) LogManager(org.apache.logging.log4j.LogManager) Eth1EventsChannel(tech.pegasys.teku.pow.api.Eth1EventsChannel) Checkpoint(tech.pegasys.teku.spec.datastructures.state.Checkpoint) OptimizedMerkleTree(tech.pegasys.teku.spec.datastructures.util.OptimizedMerkleTree) Counter(org.hyperledger.besu.plugin.services.metrics.Counter) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState) Deposit(tech.pegasys.teku.spec.datastructures.operations.Deposit) SszBytes32Vector(tech.pegasys.teku.infrastructure.ssz.collections.SszBytes32Vector) DepositWithIndex(tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex) AtomicReference(java.util.concurrent.atomic.AtomicReference) UInt64(tech.pegasys.teku.infrastructure.unsigned.UInt64)

Example 2 with DepositWithIndex

use of tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex in project teku by ConsenSys.

the class MockStartBeaconStateGenerator method createInitialBeaconState.

public BeaconState createInitialBeaconState(final UInt64 genesisTime, final List<DepositData> initialDepositData, final Optional<ExecutionPayloadHeader> payloadHeader) {
    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(BLOCK_HASH, genesisTime, deposits, payloadHeader);
    return initialState.updated(state -> state.setGenesis_time(genesisTime));
}
Also used : DepositData(tech.pegasys.teku.spec.datastructures.operations.DepositData) DepositWithIndex(tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex) ArrayList(java.util.ArrayList) BeaconState(tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)

Example 3 with DepositWithIndex

use of tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex 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 4 with DepositWithIndex

use of tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex in project teku by ConsenSys.

the class DataStructureUtil method randomDepositWithIndex.

public DepositWithIndex randomDepositWithIndex(long depositIndex) {
    Bytes32 randomBytes32 = randomBytes32();
    SszBytes32VectorSchema<?> proofSchema = Deposit.SSZ_SCHEMA.getProofSchema();
    return new DepositWithIndex(Stream.generate(() -> randomBytes32).limit(proofSchema.getLength()).collect(proofSchema.collectorUnboxed()), randomDepositData(), UInt64.valueOf(depositIndex));
}
Also used : DepositWithIndex(tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex) Bytes32(org.apache.tuweni.bytes.Bytes32)

Example 5 with DepositWithIndex

use of tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex 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)

Aggregations

DepositWithIndex (tech.pegasys.teku.spec.datastructures.operations.DepositWithIndex)10 DepositData (tech.pegasys.teku.spec.datastructures.operations.DepositData)7 BeaconState (tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState)6 ArrayList (java.util.ArrayList)5 Bytes32 (org.apache.tuweni.bytes.Bytes32)4 UInt64 (tech.pegasys.teku.infrastructure.unsigned.UInt64)4 Test (org.junit.jupiter.api.Test)3 Spec (tech.pegasys.teku.spec.Spec)3 Deposit (tech.pegasys.teku.spec.datastructures.operations.Deposit)3 DepositGenerator (tech.pegasys.teku.spec.datastructures.util.DepositGenerator)3 List (java.util.List)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)2 BLSKeyPair (tech.pegasys.teku.bls.BLSKeyPair)2 BLSSignature (tech.pegasys.teku.bls.BLSSignature)2 SszList (tech.pegasys.teku.infrastructure.ssz.SszList)2 SszBytes32Vector (tech.pegasys.teku.infrastructure.ssz.collections.SszBytes32Vector)2 SszListSchema (tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema)2 SpecVersion (tech.pegasys.teku.spec.SpecVersion)2 Eth1Data (tech.pegasys.teku.spec.datastructures.blocks.Eth1Data)2