Skip to content

Commit

Permalink
Merge branch 'refs/heads/master' into upgrade-rocksdb
Browse files Browse the repository at this point in the history
  • Loading branch information
gfukushima committed Sep 2, 2024
2 parents 90ef567 + 16dc699 commit 4391301
Show file tree
Hide file tree
Showing 69 changed files with 1,917 additions and 692 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Copyright Consensys Software Inc., 2022
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.test.acceptance;

import com.google.common.io.Resources;
import java.net.URL;
import java.util.Map;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.ethereum.execution.types.Eth1Address;
import tech.pegasys.teku.infrastructure.time.SystemTimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.test.acceptance.dsl.AcceptanceTestBase;
import tech.pegasys.teku.test.acceptance.dsl.BesuDockerVersion;
import tech.pegasys.teku.test.acceptance.dsl.BesuNode;
import tech.pegasys.teku.test.acceptance.dsl.GenesisGenerator.InitialStateData;
import tech.pegasys.teku.test.acceptance.dsl.TekuBeaconNode;
import tech.pegasys.teku.test.acceptance.dsl.TekuNodeConfig;
import tech.pegasys.teku.test.acceptance.dsl.TekuNodeConfigBuilder;
import tech.pegasys.teku.test.acceptance.dsl.Web3SignerNode;
import tech.pegasys.teku.test.acceptance.dsl.tools.ValidatorKeysApi;
import tech.pegasys.teku.test.acceptance.dsl.tools.deposits.ValidatorKeystores;

public class CapellaRemoteSignerAcceptanceTest extends AcceptanceTestBase {

private static final String NETWORK_NAME = "swift";
public static final Eth1Address WITHDRAWAL_ADDRESS =
Eth1Address.fromHexString("0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
private static final URL JWT_FILE = Resources.getResource("auth/ee-jwt-secret.hex");

@Test
void denebWithRemoteSigner() throws Exception {
final UInt64 currentTime = new SystemTimeProvider().getTimeInSeconds();
final int genesisTime =
currentTime.intValue() + 10; // genesis in 10 seconds to give node time to start

final Web3SignerNode web3SignerNode =
createWeb3SignerNode(
config ->
config
.withNetwork(NETWORK_NAME)
.withAltairEpoch(UInt64.ZERO)
.withBellatrixEpoch(UInt64.ZERO)
.withCapellaEpoch(UInt64.ZERO));

web3SignerNode.start();
final ValidatorKeysApi signerApi = web3SignerNode.getValidatorKeysApi();
final BesuNode besuNode = createBesuNode(genesisTime);
besuNode.start();

final ValidatorKeystores validatorKeys =
createTekuDepositSender(NETWORK_NAME).generateValidatorKeys(4, WITHDRAWAL_ADDRESS);

signerApi.addLocalValidatorsAndExpect(validatorKeys, "imported");
signerApi.assertLocalValidatorListing(validatorKeys.getPublicKeys());

final InitialStateData initialStateData =
createGenesisGenerator()
.network(NETWORK_NAME)
.withGenesisTime(genesisTime)
.genesisDelaySeconds(0)
.withAltairEpoch(UInt64.ZERO)
.withBellatrixEpoch(UInt64.ZERO)
.withCapellaEpoch(UInt64.ZERO)
.withTotalTerminalDifficulty(0)
.genesisExecutionPayloadHeaderSource(besuNode::createGenesisExecutionPayload)
.validatorKeys(validatorKeys)
.generate();

final TekuBeaconNode tekuNode =
createTekuBeaconNode(
beaconNode(
genesisTime, besuNode, initialStateData, web3SignerNode.getValidatorRestApiUrl()));

tekuNode.start();

tekuNode.waitForNextEpoch();
tekuNode.waitForNewBlock();
tekuNode.waitForFullSyncCommitteeAggregate();
}

private BesuNode createBesuNode(final int genesisTime) {
final int shanghai =
genesisTime + 2; // 4 slots, 2 seconds each (swift) - activate Prague on first slot
final Map<String, String> genesisOverrides = Map.of("shanghaiTime", String.valueOf(shanghai));

return createBesuNode(
BesuDockerVersion.DEVELOP,
config ->
config
.withMergeSupport()
.withGenesisFile("besu/mergedGenesis.json")
.withP2pEnabled(true)
.withJwtTokenAuthorization(JWT_FILE),
genesisOverrides);
}

private static TekuNodeConfig beaconNode(
final int genesisTime,
final BesuNode besuNode,
final InitialStateData initialStateData,
final String signerUrl)
throws Exception {
return TekuNodeConfigBuilder.createBeaconNode()
.withInitialState(initialStateData)
.withInteropModeDisabled()
.withNetwork(NETWORK_NAME)
.withAltairEpoch(UInt64.ZERO)
.withBellatrixEpoch(UInt64.ZERO)
.withCapellaEpoch(UInt64.ZERO)
.withTotalTerminalDifficulty(0)
.withGenesisTime(genesisTime)
.withExecutionEngine(besuNode)
.withJwtSecretFile(JWT_FILE)
.withExternalSignerUrl(signerUrl)
.withExternalSignerPublicKeys("external-signer")
.withValidatorProposerDefaultFeeRecipient("0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73")
.withStartupTargetPeerCount(0)
.withRealNetwork()
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.google.common.io.Resources;
import java.net.URL;
import java.util.Map;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.infrastructure.time.SystemTimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
Expand All @@ -27,19 +26,12 @@
import tech.pegasys.teku.test.acceptance.dsl.TekuBeaconNode;
import tech.pegasys.teku.test.acceptance.dsl.TekuNodeConfigBuilder;

/**
* The test is based on `shanghaiTime` in Besu EL genesis config as the only option to start
* Shanghai on Besu. There is a bit of magic on assumption of node starting time, which should be
* eliminated when there will be an option `shanghaiBlock`. When it's available, please, upgrade the
* test to use it instead of time.
*/
public class CapellaUpgradeAcceptanceTest extends AcceptanceTestBase {
private final SystemTimeProvider timeProvider = new SystemTimeProvider();

private static final URL JWT_FILE = Resources.getResource("auth/ee-jwt-secret.hex");

@Test
@Disabled("Switch to shanghaiBlock Besu genesis when it's available and enable")
void shouldUpgradeToCapella() throws Exception {
final UInt64 currentTime = timeProvider.getTimeInSeconds();
final int genesisTime = currentTime.plus(30).intValue(); // magic node startup time
Expand All @@ -49,7 +41,8 @@ void shouldUpgradeToCapella() throws Exception {

BesuNode primaryEL =
createBesuNode(
BesuDockerVersion.STABLE,
// "Waiting for Besu 24.9.0 release (https://github.com/Consensys/teku/issues/8535)"
BesuDockerVersion.DEVELOP,
config ->
config
.withMergeSupport()
Expand All @@ -61,7 +54,8 @@ void shouldUpgradeToCapella() throws Exception {

BesuNode secondaryEL =
createBesuNode(
BesuDockerVersion.STABLE,
// "Waiting for Besu 24.9.0 release (https://github.com/Consensys/teku/issues/8535)"
BesuDockerVersion.DEVELOP,
config ->
config
.withMergeSupport()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import com.google.common.io.Resources;
import java.net.URL;
import java.util.Map;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.infrastructure.time.SystemTimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
Expand All @@ -27,19 +26,12 @@
import tech.pegasys.teku.test.acceptance.dsl.TekuBeaconNode;
import tech.pegasys.teku.test.acceptance.dsl.TekuNodeConfigBuilder;

/**
* The test is based on `shanghaiTime` and `cancunTime` in Besu EL genesis config as the only option
* to start these forks on Besu. There is a bit of magic on assumption of node starting time, which
* should be eliminated when there will be an options `shanghaiBlock` and `cancunBlock`. When it's
* available, please, upgrade the test to use them instead of time and enable it.
*/
public class DenebUpgradeAcceptanceTest extends AcceptanceTestBase {
private final SystemTimeProvider timeProvider = new SystemTimeProvider();

private static final URL JWT_FILE = Resources.getResource("auth/ee-jwt-secret.hex");

@Test
@Disabled("Switch Besu genesis to shanghaiBlock and cancunBlock when it's available and enable")
void shouldUpgradeToDeneb() throws Exception {
final UInt64 currentTime = timeProvider.getTimeInSeconds();
final int genesisTime = currentTime.plus(30).intValue(); // magic node startup time
Expand All @@ -54,7 +46,8 @@ void shouldUpgradeToDeneb() throws Exception {

BesuNode primaryEL =
createBesuNode(
BesuDockerVersion.STABLE,
// "Waiting for Besu 24.9.0 release (https://github.com/Consensys/teku/issues/8535)"
BesuDockerVersion.DEVELOP,
config ->
config
.withMergeSupport()
Expand All @@ -66,7 +59,8 @@ void shouldUpgradeToDeneb() throws Exception {

BesuNode secondaryEL =
createBesuNode(
BesuDockerVersion.STABLE,
// "Waiting for Besu 24.9.0 release (https://github.com/Consensys/teku/issues/8535)"
BesuDockerVersion.DEVELOP,
config ->
config
.withMergeSupport()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright Consensys Software Inc., 2022
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package tech.pegasys.teku.test.acceptance;

import com.google.common.io.Resources;
import java.net.URL;
import java.util.Map;
import org.junit.jupiter.api.Test;
import tech.pegasys.teku.ethereum.execution.types.Eth1Address;
import tech.pegasys.teku.infrastructure.time.SystemTimeProvider;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.SpecMilestone;
import tech.pegasys.teku.test.acceptance.dsl.AcceptanceTestBase;
import tech.pegasys.teku.test.acceptance.dsl.BesuDockerVersion;
import tech.pegasys.teku.test.acceptance.dsl.BesuNode;
import tech.pegasys.teku.test.acceptance.dsl.GenesisGenerator.InitialStateData;
import tech.pegasys.teku.test.acceptance.dsl.TekuBeaconNode;
import tech.pegasys.teku.test.acceptance.dsl.TekuNodeConfig;
import tech.pegasys.teku.test.acceptance.dsl.TekuNodeConfigBuilder;
import tech.pegasys.teku.test.acceptance.dsl.tools.deposits.ValidatorKeystores;

public class ElectraUpgradeAcceptanceTest extends AcceptanceTestBase {

private static final String NETWORK_NAME = "swift";
public static final Eth1Address WITHDRAWAL_ADDRESS =
Eth1Address.fromHexString("0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee");
private static final URL JWT_FILE = Resources.getResource("auth/ee-jwt-secret.hex");

@Test
void upgradeFromDeneb() throws Exception {
final UInt64 currentTime = new SystemTimeProvider().getTimeInSeconds();
final int genesisTime =
currentTime.intValue() + 30; // genesis in 30 seconds to give node time to start

final BesuNode besuNode = createBesuNode(genesisTime);
besuNode.start();

final ValidatorKeystores validatorKeys =
createTekuDepositSender(NETWORK_NAME).generateValidatorKeys(4, WITHDRAWAL_ADDRESS);

final InitialStateData initialStateData =
createGenesisGenerator()
.network(NETWORK_NAME)
.withGenesisTime(genesisTime)
.genesisDelaySeconds(0)
.withAltairEpoch(UInt64.ZERO)
.withBellatrixEpoch(UInt64.ZERO)
.withCapellaEpoch(UInt64.ZERO)
.withDenebEpoch(UInt64.ZERO)
.withElectraEpoch(UInt64.ONE)
.withTotalTerminalDifficulty(0)
.genesisExecutionPayloadHeaderSource(besuNode::createGenesisExecutionPayload)
.validatorKeys(validatorKeys)
.generate();

final TekuBeaconNode tekuNode =
createTekuBeaconNode(beaconNode(genesisTime, besuNode, initialStateData, validatorKeys));
tekuNode.start();

tekuNode.waitForMilestone(SpecMilestone.ELECTRA);
tekuNode.waitForNewBlock();
}

private BesuNode createBesuNode(final int genesisTime) {
final int pragueTime =
genesisTime + 4 * 2; // 4 slots, 2 seconds each (swift) - activate Prague on first slot
final Map<String, String> genesisOverrides = Map.of("pragueTime", String.valueOf(pragueTime));

return createBesuNode(
// "Waiting for Besu 24.9.0 release (https://github.com/Consensys/teku/issues/8535)"
BesuDockerVersion.DEVELOP,
config ->
config
.withMergeSupport()
.withGenesisFile("besu/pragueGenesis.json")
.withP2pEnabled(true)
.withJwtTokenAuthorization(JWT_FILE),
genesisOverrides);
}

private static TekuNodeConfig beaconNode(
final int genesisTime,
final BesuNode besuNode,
final InitialStateData initialStateData,
final ValidatorKeystores validatorKeys)
throws Exception {
return TekuNodeConfigBuilder.createBeaconNode()
.withInitialState(initialStateData)
.withNetwork(NETWORK_NAME)
.withAltairEpoch(UInt64.ZERO)
.withBellatrixEpoch(UInt64.ZERO)
.withCapellaEpoch(UInt64.ZERO)
.withDenebEpoch(UInt64.ZERO)
.withElectraEpoch(UInt64.ONE)
.withTotalTerminalDifficulty(0)
.withGenesisTime(genesisTime)
.withExecutionEngine(besuNode)
.withJwtSecretFile(JWT_FILE)
.withTrustedSetupFromClasspath("mainnet-trusted-setup.txt")
.withReadOnlyKeystorePath(validatorKeys)
.withValidatorProposerDefaultFeeRecipient("0xFE3B557E8Fb62b89F4916B721be55cEb828dBd73")
.withStartupTargetPeerCount(0)
.withRealNetwork()
.build();
}
}
Loading

0 comments on commit 4391301

Please sign in to comment.