Skip to content

Commit 4046d88

Browse files
committed
Merge branch 'master' into sync-committee-duties
2 parents 2be939b + adc1dd5 commit 4046d88

File tree

15 files changed

+256
-122
lines changed

15 files changed

+256
-122
lines changed

Diff for: ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigElectra.java

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
public interface SpecConfigElectra extends SpecConfigDeneb {
2121

22+
UInt64 UNSET_DEPOSIT_RECEIPTS_START_INDEX = UInt64.MAX_VALUE;
23+
2224
static SpecConfigElectra required(final SpecConfig specConfig) {
2325
return specConfig
2426
.toVersionElectra()
@@ -33,6 +35,8 @@ static SpecConfigElectra required(final SpecConfig specConfig) {
3335

3436
UInt64 getElectraForkEpoch();
3537

38+
int getMaxDepositReceiptsPerPayload();
39+
3640
@Override
3741
Optional<SpecConfigElectra> toVersionElectra();
3842
}

Diff for: ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigElectraImpl.java

+14-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ public class SpecConfigElectraImpl extends DelegatingSpecConfigDeneb implements
2323
private final Bytes4 electraForkVersion;
2424
private final UInt64 electraForkEpoch;
2525

26+
private final int maxDepositReceiptsPerPayload;
27+
2628
public SpecConfigElectraImpl(
2729
final SpecConfigDeneb specConfig,
2830
final Bytes4 electraForkVersion,
29-
final UInt64 electraForkEpoch) {
31+
final UInt64 electraForkEpoch,
32+
final int maxDepositReceiptsPerPayload) {
3033
super(specConfig);
3134
this.electraForkVersion = electraForkVersion;
3235
this.electraForkEpoch = electraForkEpoch;
36+
this.maxDepositReceiptsPerPayload = maxDepositReceiptsPerPayload;
3337
}
3438

3539
@Override
@@ -42,6 +46,11 @@ public UInt64 getElectraForkEpoch() {
4246
return electraForkEpoch;
4347
}
4448

49+
@Override
50+
public int getMaxDepositReceiptsPerPayload() {
51+
return maxDepositReceiptsPerPayload;
52+
}
53+
4554
@Override
4655
public Optional<SpecConfigElectra> toVersionElectra() {
4756
return Optional.of(this);
@@ -58,11 +67,13 @@ public boolean equals(final Object o) {
5867
final SpecConfigElectraImpl that = (SpecConfigElectraImpl) o;
5968
return Objects.equals(specConfig, that.specConfig)
6069
&& Objects.equals(electraForkVersion, that.electraForkVersion)
61-
&& Objects.equals(electraForkEpoch, that.electraForkEpoch);
70+
&& Objects.equals(electraForkEpoch, that.electraForkEpoch)
71+
&& maxDepositReceiptsPerPayload == that.maxDepositReceiptsPerPayload;
6272
}
6373

6474
@Override
6575
public int hashCode() {
66-
return Objects.hash(specConfig, electraForkVersion, electraForkEpoch);
76+
return Objects.hash(
77+
specConfig, electraForkVersion, electraForkEpoch, maxDepositReceiptsPerPayload);
6778
}
6879
}

Diff for: ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/SpecConfigLoader.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
public class SpecConfigLoader {
3333
private static final Logger LOG = LogManager.getLogger();
3434
private static final List<String> AVAILABLE_PRESETS =
35-
List.of("phase0", "altair", "bellatrix", "capella", "deneb");
35+
List.of("phase0", "altair", "bellatrix", "capella", "deneb", "electra");
3636
private static final String CONFIG_PATH = "configs/";
3737
private static final String PRESET_PATH = "presets/";
3838

Diff for: ethereum/spec/src/main/java/tech/pegasys/teku/spec/config/builder/ElectraBuilder.java

+11-1
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ public class ElectraBuilder implements ForkConfigBuilder<SpecConfigDeneb, SpecCo
3131
private Bytes4 electraForkVersion;
3232
private UInt64 electraForkEpoch;
3333

34+
private Integer maxDepositReceiptsPerPayload;
35+
3436
ElectraBuilder() {}
3537

3638
@Override
3739
public SpecConfigElectra build(final SpecConfigDeneb specConfig) {
38-
return new SpecConfigElectraImpl(specConfig, electraForkVersion, electraForkEpoch);
40+
return new SpecConfigElectraImpl(
41+
specConfig, electraForkVersion, electraForkEpoch, maxDepositReceiptsPerPayload);
3942
}
4043

4144
public ElectraBuilder electraForkEpoch(final UInt64 electraForkEpoch) {
@@ -50,6 +53,12 @@ public ElectraBuilder electraForkVersion(final Bytes4 electraForkVersion) {
5053
return this;
5154
}
5255

56+
public ElectraBuilder maxDepositReceiptsPerPayload(final Integer maxDepositReceiptsPerPayload) {
57+
checkNotNull(maxDepositReceiptsPerPayload);
58+
this.maxDepositReceiptsPerPayload = maxDepositReceiptsPerPayload;
59+
return this;
60+
}
61+
5362
@Override
5463
public void validate() {
5564
if (electraForkEpoch == null) {
@@ -71,6 +80,7 @@ public Map<String, Object> getValidationMap() {
7180

7281
constants.put("electraForkEpoch", electraForkEpoch);
7382
constants.put("electraForkVersion", electraForkVersion);
83+
constants.put("maxDepositReceiptsPerPayload", maxDepositReceiptsPerPayload);
7484

7585
return constants;
7686
}
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
# Mainnet preset - Electra
1+
# Mainnet preset - Electra
2+
3+
# Execution
4+
# ---------------------------------------------------------------
5+
# 2**13 (= 8192) receipts
6+
MAX_DEPOSIT_RECEIPTS_PER_PAYLOAD: 8192
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
# Minimal preset - Electra
1+
# Minimal preset - Electra
2+
3+
# Execution
4+
# ---------------------------------------------------------------
5+
# [customized]
6+
MAX_DEPOSIT_RECEIPTS_PER_PAYLOAD: 4
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
# Minimal preset - Electra
1+
# Minimal preset - Electra
2+
3+
# Execution
4+
# ---------------------------------------------------------------
5+
# [customized]
6+
MAX_DEPOSIT_RECEIPTS_PER_PAYLOAD: 4

Diff for: ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigAssertions.java

-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323

2424
public class SpecConfigAssertions {
2525

26-
static void assertAllPhase0FieldsSet(final SpecConfig config) throws Exception {
27-
assertAllFieldsSet(config, SpecConfigPhase0.class);
28-
}
29-
3026
static void assertAllAltairFieldsSet(final SpecConfig config) throws Exception {
3127
assertAllFieldsSet(config, SpecConfigAltair.class);
3228
}

Diff for: ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigBuilderTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import tech.pegasys.teku.spec.config.builder.BellatrixBuilder;
3333
import tech.pegasys.teku.spec.config.builder.CapellaBuilder;
3434
import tech.pegasys.teku.spec.config.builder.DenebBuilder;
35+
import tech.pegasys.teku.spec.config.builder.ElectraBuilder;
3536
import tech.pegasys.teku.spec.config.builder.SpecConfigBuilder;
3637
import tech.pegasys.teku.spec.util.DataStructureUtil;
3738

@@ -45,7 +46,8 @@ class SpecConfigBuilderTest {
4546
AltairBuilder.class,
4647
BellatrixBuilder.class,
4748
CapellaBuilder.class,
48-
DenebBuilder.class);
49+
DenebBuilder.class,
50+
ElectraBuilder.class);
4951

5052
/**
5153
* Ensures Builders have actually non-primitive setters, because primitive setters are silently
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* Copyright Consensys Software Inc., 2022
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package tech.pegasys.teku.spec.config;
15+
16+
import static org.assertj.core.api.Assertions.assertThat;
17+
18+
import org.junit.jupiter.api.Test;
19+
import tech.pegasys.teku.spec.Spec;
20+
import tech.pegasys.teku.spec.TestSpecFactory;
21+
import tech.pegasys.teku.spec.util.DataStructureUtil;
22+
23+
public class SpecConfigElectraTest {
24+
private final Spec spec = TestSpecFactory.createMinimalDeneb();
25+
26+
@Test
27+
public void equals_mainnet() {
28+
final SpecConfigElectra configA =
29+
SpecConfigLoader.loadConfig("mainnet").toVersionElectra().orElseThrow();
30+
final SpecConfigElectra configB =
31+
SpecConfigLoader.loadConfig("mainnet").toVersionElectra().orElseThrow();
32+
33+
assertThat(configA).isEqualTo(configB);
34+
assertThat(configA.hashCode()).isEqualTo(configB.hashCode());
35+
}
36+
37+
@Test
38+
public void equals_sameRandomValues() {
39+
final SpecConfigDeneb specConfigDeneb =
40+
SpecConfigLoader.loadConfig("mainnet").toVersionDeneb().orElseThrow();
41+
final SpecConfigElectra configA = createRandomElectraConfig(specConfigDeneb, 1);
42+
final SpecConfigElectra configB = createRandomElectraConfig(specConfigDeneb, 1);
43+
44+
assertThat(configA).isEqualTo(configB);
45+
assertThat(configA.hashCode()).isEqualTo(configB.hashCode());
46+
}
47+
48+
@Test
49+
public void equals_differentRandomValues() {
50+
final SpecConfigDeneb specConfigDeneb =
51+
SpecConfigLoader.loadConfig("mainnet").toVersionDeneb().orElseThrow();
52+
final SpecConfigElectra configA = createRandomElectraConfig(specConfigDeneb, 1);
53+
final SpecConfigElectra configB = createRandomElectraConfig(specConfigDeneb, 2);
54+
55+
assertThat(configA).isNotEqualTo(configB);
56+
assertThat(configA.hashCode()).isNotEqualTo(configB.hashCode());
57+
}
58+
59+
@Test
60+
public void equals_denebConfigDiffer() {
61+
final SpecConfigDeneb denebA =
62+
SpecConfigLoader.loadConfig("mainnet").toVersionDeneb().orElseThrow();
63+
final SpecConfigDeneb denebB =
64+
SpecConfigLoader.loadConfig(
65+
"mainnet",
66+
b -> b.denebBuilder(db -> db.maxBlobsPerBlock(denebA.getMaxBlobsPerBlock() + 4)))
67+
.toVersionDeneb()
68+
.orElseThrow();
69+
70+
final SpecConfigElectra configA = createRandomElectraConfig(denebA, 1);
71+
final SpecConfigElectra configB = createRandomElectraConfig(denebB, 1);
72+
73+
assertThat(configA).isNotEqualTo(configB);
74+
assertThat(configA.hashCode()).isNotEqualTo(configB.hashCode());
75+
}
76+
77+
private SpecConfigElectra createRandomElectraConfig(
78+
final SpecConfigDeneb denebConfig, final int seed) {
79+
final DataStructureUtil dataStructureUtil = new DataStructureUtil(seed, spec);
80+
81+
return new SpecConfigElectraImpl(
82+
denebConfig,
83+
dataStructureUtil.randomBytes4(),
84+
dataStructureUtil.randomUInt64(),
85+
dataStructureUtil.randomPositiveInt()) {};
86+
}
87+
}

Diff for: ethereum/spec/src/test/java/tech/pegasys/teku/spec/config/SpecConfigLoaderTest.java

+6-29
Original file line numberDiff line numberDiff line change
@@ -27,28 +27,23 @@
2727
import java.net.URL;
2828
import java.nio.file.Files;
2929
import java.nio.file.Path;
30-
import java.util.Arrays;
31-
import java.util.List;
3230
import java.util.Map;
33-
import java.util.stream.Collectors;
34-
import java.util.stream.Stream;
3531
import org.apache.commons.io.IOUtils;
3632
import org.junit.jupiter.api.Test;
3733
import org.junit.jupiter.api.io.TempDir;
3834
import org.junit.jupiter.params.ParameterizedTest;
39-
import org.junit.jupiter.params.provider.Arguments;
40-
import org.junit.jupiter.params.provider.MethodSource;
35+
import org.junit.jupiter.params.provider.EnumSource;
4136
import org.junit.jupiter.params.provider.ValueSource;
4237
import tech.pegasys.teku.spec.networks.Eth2Network;
4338

4439
public class SpecConfigLoaderTest {
4540

4641
@ParameterizedTest(name = "{0}")
47-
@MethodSource("knownNetworks")
48-
public void shouldLoadAllKnownNetworks(final String name, final Class<?> configType)
49-
throws Exception {
50-
final SpecConfig config = SpecConfigLoader.loadConfigStrict(name);
51-
assertAllFieldsSet(config, configType);
42+
@EnumSource(Eth2Network.class)
43+
public void shouldLoadAllKnownNetworks(final Eth2Network network) throws Exception {
44+
final SpecConfig config = SpecConfigLoader.loadConfigStrict(network.configName());
45+
// testing latest SpecConfig ensures all fields will be asserted on
46+
assertAllFieldsSet(config, SpecConfigElectra.class);
5247
}
5348

5449
/**
@@ -143,24 +138,6 @@ public void shouldBeAbleToOverridePresetValues() {
143138
assertThat(config.getMaxCommitteesPerSlot()).isEqualTo(12); // Mainnet preset is 64.
144139
}
145140

146-
@Test
147-
public void shouldTestAllKnownNetworks() {
148-
final List<String> testedNetworks =
149-
knownNetworks().map(args -> (String) args.get()[0]).sorted().collect(Collectors.toList());
150-
final List<String> allKnownNetworks =
151-
Arrays.stream(Eth2Network.values())
152-
.map(Eth2Network::configName)
153-
.sorted()
154-
.collect(Collectors.toList());
155-
156-
assertThat(testedNetworks).isEqualTo(allKnownNetworks);
157-
}
158-
159-
static Stream<Arguments> knownNetworks() {
160-
return Stream.of(Eth2Network.values())
161-
.map(network -> Arguments.of(network.configName(), SpecConfigBellatrix.class));
162-
}
163-
164141
private void writeStreamToFile(final InputStream inputStream, final Path filePath)
165142
throws Exception {
166143
try (final OutputStream outputStream = Files.newOutputStream(filePath)) {

0 commit comments

Comments
 (0)