use of tech.pegasys.teku.spec.datastructures.operations.Deposit 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.Deposit in project teku by ConsenSys.
the class DepositProviderTest method mockDepositsFromEth1Block.
private void mockDepositsFromEth1Block(int startIndex, int n) {
allSeenDepositsList.subList(startIndex, n).stream().map(depositUtil::convertDepositEventToOperationDeposit).map(Deposit::getData).map(DepositData::hashTreeRoot).forEachOrdered(depositMerkleTree::add);
DepositsFromBlockEvent depositsFromBlockEvent = mock(DepositsFromBlockEvent.class);
when(depositsFromBlockEvent.getDeposits()).thenReturn(allSeenDepositsList.subList(startIndex, startIndex + n));
when(depositsFromBlockEvent.getBlockHash()).thenReturn(Bytes32.ZERO);
depositProvider.onDepositsFromBlock(depositsFromBlockEvent);
}
use of tech.pegasys.teku.spec.datastructures.operations.Deposit 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);
}
use of tech.pegasys.teku.spec.datastructures.operations.Deposit in project teku by ConsenSys.
the class GenesisGeneratorTest method shouldIgnoreInvalidDeposits.
@Test
public void shouldIgnoreInvalidDeposits() {
List<Deposit> deposits = new ArrayList<>(initialDeposits);
// Add an invalid deposit at the start with the same key as a later, valid deposit
final int expectedIndex = 3;
final DepositData validData = deposits.get(expectedIndex).getData();
final DepositData invalidData = new DepositData(validData.getPubkey(), validData.getWithdrawal_credentials(), validData.getAmount(), BLSSignature.empty());
deposits.add(0, new Deposit(invalidData));
genesisGenerator.updateCandidateState(Bytes32.ZERO, UInt64.ZERO, deposits);
final BeaconState state = genesisGenerator.getGenesisState();
// All deposits were processed
assertThat(state.getEth1_deposit_index()).isEqualTo(UInt64.valueOf(deposits.size()));
// But one didn't result in a new validator
assertThat(state.getValidators()).hasSize(deposits.size() - 1);
assertThat(genesisGenerator.getActiveValidatorCount()).isEqualTo(deposits.size() - 1);
// And the validator with an invalid deposit should wind up at index 3, not 0 because their
// first deposit was completely ignored
final Validator validator = state.getValidators().get(expectedIndex);
assertThat(validator.getPubkeyBytes()).isEqualTo(validData.getPubkey().toBytesCompressed());
assertThat(genesisSpec.predicates().isActiveValidator(validator, GENESIS_EPOCH)).isTrue();
}
use of tech.pegasys.teku.spec.datastructures.operations.Deposit in project teku by ConsenSys.
the class BlockProcessorTest method processDepositHelper.
private BeaconState processDepositHelper(BeaconState beaconState, DepositData depositData) throws BlockProcessingException {
// Add the deposit to a Merkle tree so that we can get the root to put into the state Eth1 data
MerkleTree depositMerkleTree = new OptimizedMerkleTree(specConfig.getDepositContractTreeDepth());
depositMerkleTree.add(depositData.hashTreeRoot());
beaconState = beaconState.updated(state -> state.setEth1_data(new Eth1Data(depositMerkleTree.getRoot(), UInt64.valueOf(1), Bytes32.ZERO)));
SszListSchema<Deposit, ?> schema = SszListSchema.create(DepositWithIndex.SSZ_SCHEMA, specConfig.getMaxDeposits());
SszBytes32Vector proof = Deposit.SSZ_SCHEMA.getProofSchema().of(depositMerkleTree.getProof(0));
SszList<Deposit> deposits = schema.of(new DepositWithIndex(proof, depositData, UInt64.valueOf(0)));
// Attempt to process deposit with above data.
return beaconState.updated(state -> blockProcessor.processDeposits(state, deposits));
}
Aggregations