Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP-6110 Implement beacon-chain and validator logic #8124

Merged
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ the [releases page](https://github.com/Consensys/teku/releases).
### Additions and Improvements
- Introduced [Validator Slashing Prevention feature](https://docs.teku.consensys.io/how-to/prevent-slashing/detect-slashing).
- If the EL supports the `engine_getClientVersionV1` Engine API method, the default graffiti (when no graffiti has been configured by the validator) will include EL as well as CL version information. For more details, please see https://github.com/ethereum/execution-apis/pull/517.
- `-p2p-private-key-file` command line option supports reading a binary private key file.
- `--p2p-private-key-file` command line option supports reading a binary private key file.
- Updated libp2p seen cache configuration to reflect EIP-7045 spec changes. This reduces CPU and network bandwidth consumption.
- Increased the attestation cache capacity to allow Teku a bigger pool of attestations when block building.
- Default `--builder-bid-compare-factor` to 90. This makes it necessary for external block builders to give at least 10% additional profit compared to a local build before being taken into consideration. If you would like to go back to the previous default, set `--builder-bid-compare-factor` to 100
- Added `--p2p-direct-peers` command line option to configure explicit peers as per [Explicit Peering Agreements](https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.1.md#explicit-peering-agreements) libp2p spec
- Defaulted `--builder-bid-compare-factor` to 90. This makes it necessary for external block builders to give at least 10% additional profit compared to a local build before being taken into consideration. If you would like to go back to the previous default, set `--builder-bid-compare-factor` to 100.
- Added `--p2p-direct-peers` command line option to configure explicit peers as per [Explicit Peering Agreements](https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/gossipsub-v1.1.md#explicit-peering-agreements) libp2p spec.

### Bug Fixes
- Fix incompatibility between Teku validator client and Lighthouse beacon nodes [#8117](https://github.com/Consensys/teku/pull/8117)
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public class DepositProvider
private boolean inSync = false;

public DepositProvider(
MetricsSystem metricsSystem,
RecentChainData recentChainData,
final MetricsSystem metricsSystem,
final RecentChainData recentChainData,
final Eth1DataCache eth1DataCache,
final StorageUpdateChannel storageUpdateChannel,
final Eth1DepositStorageChannel eth1DepositStorageChannel,
Expand All @@ -99,7 +99,7 @@ public DepositProvider(
}

@Override
public synchronized void onDepositsFromBlock(DepositsFromBlockEvent event) {
public synchronized void onDepositsFromBlock(final DepositsFromBlockEvent event) {
event.getDeposits().stream()
.map(depositUtil::convertDepositEventToOperationDeposit)
.forEach(
Expand Down Expand Up @@ -171,7 +171,7 @@ public void onEth1Block(
}

@Override
public void onMinGenesisTimeBlock(MinGenesisTimeBlockEvent event) {}
public void onMinGenesisTimeBlock(final MinGenesisTimeBlockEvent event) {}

@Override
public void onSlot(final UInt64 slot) {
Expand Down Expand Up @@ -201,33 +201,54 @@ public void onSlot(final UInt64 slot) {
.ifExceptionGetsHereRaiseABug();
}

public void onSyncingStatusChanged(boolean inSync) {
public void onSyncingStatusChanged(final boolean inSync) {
this.inSync = inSync;
}

public synchronized SszList<Deposit> getDeposits(BeaconState state, Eth1Data eth1Data) {
public synchronized SszList<Deposit> getDeposits(
final BeaconState state, final Eth1Data eth1Data) {
final long maxDeposits = spec.getMaxDeposits(state);
final SszListSchema<Deposit, ?> depositsSchema = depositsSchemaCache.get(maxDeposits);
// no Eth1 deposits needed if already transitioned to the EIP-6110 mechanism
if (spec.isFormerDepositMechanismDisabled(state)) {
return depositsSchema.createFromElements(emptyList());
}
final UInt64 eth1DepositCount;
if (spec.isEnoughVotesToUpdateEth1Data(state, eth1Data, 1)) {
eth1DepositCount = eth1Data.getDepositCount();
} else {
eth1DepositCount = state.getEth1Data().getDepositCount();
}

final UInt64 eth1DepositIndex = state.getEth1DepositIndex();

final UInt64 eth1PendingDepositCount =
state
.toVersionElectra()
.map(
stateElectra -> {
// EIP-6110
final UInt64 eth1DepositIndexLimit =
eth1DepositCount.min(stateElectra.getDepositReceiptsStartIndex());
return eth1DepositIndexLimit.minusMinZero(eth1DepositIndex).min(maxDeposits);
})
.orElseGet(
() -> {
// Phase0
return eth1DepositCount.minusMinZero(eth1DepositIndex).min(maxDeposits);
});

// No deposits to include
if (eth1PendingDepositCount.isZero()) {
return depositsSchema.createFromElements(emptyList());
}

// We need to have all the deposits that can be included in the state available to ensure
// the generated proofs are valid
checkRequiredDepositsAvailable(eth1DepositCount, eth1DepositIndex);

final long maxDeposits = spec.getMaxDeposits(state);
final UInt64 latestDepositIndexWithMaxBlock = eth1DepositIndex.plus(spec.getMaxDeposits(state));

final UInt64 toDepositIndex =
latestDepositIndexWithMaxBlock.isGreaterThan(eth1DepositCount)
? eth1DepositCount
: latestDepositIndexWithMaxBlock;
final UInt64 toDepositIndex = eth1DepositIndex.plus(eth1PendingDepositCount);

return getDepositsWithProof(eth1DepositIndex, toDepositIndex, eth1DepositCount, maxDeposits);
return getDepositsWithProof(eth1DepositIndex, toDepositIndex, eth1DepositCount, depositsSchema);
}

protected synchronized List<DepositWithIndex> getAvailableDeposits() {
Expand Down Expand Up @@ -261,14 +282,12 @@ public synchronized int getDepositMapSize() {
* @param eth1DepositCount number of deposits in the merkle tree according to Eth1Data in state
*/
private SszList<Deposit> getDepositsWithProof(
UInt64 fromDepositIndex, UInt64 toDepositIndex, UInt64 eth1DepositCount, long maxDeposits) {
final UInt64 fromDepositIndex,
final UInt64 toDepositIndex,
final UInt64 eth1DepositCount,
final SszListSchema<Deposit, ?> depositsSchema) {
final AtomicReference<UInt64> expectedDepositIndex = new AtomicReference<>(fromDepositIndex);
final SszListSchema<Deposit, ?> depositsSchema = depositsSchemaCache.get(maxDeposits);
final SszBytes32VectorSchema<?> depositProofSchema = Deposit.SSZ_SCHEMA.getProofSchema();
// No deposits to include so don't bother rewinding the merkle tree.
if (fromDepositIndex.equals(toDepositIndex)) {
return depositsSchema.createFromElements(emptyList());
}
if (depositMerkleTree.getDepositCount() < eth1DepositCount.intValue()) {
throw MissingDepositsException.missingRange(
UInt64.valueOf(depositMerkleTree.getDepositCount()), eth1DepositCount);
Expand Down
Loading