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());
}
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));
}
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;
}
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));
}
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);
}
Aggregations