Skip to content

Commit 17e437e

Browse files
Merge branch 'master' into p2p-dump
2 parents e7d6be9 + aa47053 commit 17e437e

File tree

38 files changed

+834
-84
lines changed

38 files changed

+834
-84
lines changed

Diff for: beacon/validator/src/main/java/tech/pegasys/teku/validator/coordinator/ValidatorApiHandler.java

+3
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,9 @@ public SafeFuture<Optional<Attestation>> createAggregate(
490490
@Override
491491
public SafeFuture<Optional<SyncCommitteeContribution>> createSyncCommitteeContribution(
492492
final UInt64 slot, final int subcommitteeIndex, final Bytes32 beaconBlockRoot) {
493+
if (isSyncActive()) {
494+
return NodeSyncingException.failedFuture();
495+
}
493496
return SafeFuture.completedFuture(
494497
syncCommitteeMessagePool.createContribution(slot, beaconBlockRoot, subcommitteeIndex));
495498
}

Diff for: beacon/validator/src/test/java/tech/pegasys/teku/validator/coordinator/ValidatorApiHandlerTest.java

+12
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
import tech.pegasys.teku.spec.datastructures.operations.AttestationData;
102102
import tech.pegasys.teku.spec.datastructures.operations.SignedAggregateAndProof;
103103
import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof;
104+
import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeContribution;
104105
import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SyncCommitteeMessage;
105106
import tech.pegasys.teku.spec.datastructures.state.Checkpoint;
106107
import tech.pegasys.teku.spec.datastructures.state.CheckpointState;
@@ -696,6 +697,17 @@ public void createAggregate_shouldFailWhenNodeIsSyncing() {
696697
assertThatThrownBy(result::get).hasRootCauseInstanceOf(NodeSyncingException.class);
697698
}
698699

700+
@Test
701+
public void createSyncCommitteeContribution() {
702+
nodeIsSyncing();
703+
final SafeFuture<Optional<SyncCommitteeContribution>> result =
704+
validatorApiHandler.createSyncCommitteeContribution(
705+
ONE, 0, dataStructureUtil.randomBytes32());
706+
707+
assertThat(result).isCompletedExceptionally();
708+
assertThatThrownBy(result::get).hasRootCauseInstanceOf(NodeSyncingException.class);
709+
}
710+
699711
@Test
700712
public void createAggregate_shouldReturnAggregateFromAttestationPool() {
701713
final AttestationData attestationData = dataStructureUtil.randomAttestationData();

Diff for: build.gradle

+31-3
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,13 @@ allprojects {
297297

298298
def refTestVersion = 'v1.4.0' // Arbitrary change to refresh cache number: 1
299299
def blsRefTestVersion = 'v0.1.2'
300+
def slashingProtectionInterchangeRefTestVersion = 'v5.3.0'
300301
def refTestBaseUrl = 'https://github.com/ethereum/consensus-spec-tests/releases/download'
301302
def blsRefTestBaseUrl = 'https://github.com/ethereum/bls12-381-tests/releases/download'
303+
def slashingProtectionInterchangeRefTestBaseUrl = 'https://github.com/eth-clients/slashing-protection-interchange-tests/archive/refs/tags'
302304
def refTestDownloadDir = "${buildDir}/refTests/${refTestVersion}"
303305
def blsRefTestDownloadDir = "${buildDir}/blsRefTests/${blsRefTestVersion}"
306+
def slashingProtectionInterchangeRefTestDownloadDir = "${buildDir}/slashingProtectionInterchangeRefTests/${slashingProtectionInterchangeRefTestVersion}"
304307
def refTestExpandDir = "${project.rootDir}/eth-reference-tests/src/referenceTest/resources/consensus-spec-tests/"
305308

306309
task downloadEthRefTests(type: Download) {
@@ -321,7 +324,15 @@ task downloadBlsRefTests(type: Download) {
321324
overwrite false
322325
}
323326

324-
task downloadRefTests(dependsOn: [downloadEthRefTests, downloadBlsRefTests])
327+
task downloadSlashingProtectionInterchangeRefTests(type: Download) {
328+
src([
329+
"${slashingProtectionInterchangeRefTestBaseUrl}/${slashingProtectionInterchangeRefTestVersion}.tar.gz"
330+
])
331+
dest "${slashingProtectionInterchangeRefTestDownloadDir}/slashing-protection-interchange-tests.tar.gz"
332+
overwrite false
333+
}
334+
335+
task downloadRefTests(dependsOn: [downloadEthRefTests, downloadBlsRefTests, downloadSlashingProtectionInterchangeRefTests])
325336

326337
task cleanRefTestsGeneral(type: Delete) {
327338
delete "${refTestExpandDir}/tests/general"
@@ -359,8 +370,25 @@ task expandRefTestsBls(type: Copy, dependsOn: [cleanRefTestsBls, downloadBlsRefT
359370
into "${refTestExpandDir}/tests/bls"
360371
}
361372

362-
task expandRefTests(dependsOn: [expandRefTestsGeneral, expandRefTestsMainnet, expandRefTestsMinimal, expandRefTestsBls])
363-
task cleanRefTests(dependsOn: [cleanRefTestsGeneral, cleanRefTestsMainnet, cleanRefTestsMinimal, cleanRefTestsBls])
373+
task cleanRefTestsSlashingProtectionInterchange(type: Delete) {
374+
delete "${refTestExpandDir}/tests/slashing-protection-interchange"
375+
}
376+
377+
task expandRefTestsSlashingProtectionInterchange(type: Copy, dependsOn: [cleanRefTestsSlashingProtectionInterchange, downloadSlashingProtectionInterchangeRefTests]) {
378+
from {
379+
tarTree("${slashingProtectionInterchangeRefTestDownloadDir}/slashing-protection-interchange-tests.tar.gz").matching {
380+
include "**/tests/generated/*.json"
381+
// flatten
382+
eachFile { FileCopyDetails fcp ->
383+
fcp.path = fcp.name
384+
}
385+
}
386+
}
387+
into "${refTestExpandDir}/tests/slashing-protection-interchange"
388+
}
389+
390+
task expandRefTests(dependsOn: [expandRefTestsGeneral, expandRefTestsMainnet, expandRefTestsMinimal, expandRefTestsBls, expandRefTestsSlashingProtectionInterchange])
391+
task cleanRefTests(dependsOn: [cleanRefTestsGeneral, cleanRefTestsMainnet, cleanRefTestsMinimal, cleanRefTestsBls, cleanRefTestsSlashingProtectionInterchange])
364392

365393
task deploy() {}
366394

Diff for: data/dataexchange/src/test/java/tech/pegasys/teku/data/SlashingProtectionImporterTest.java

+30-3
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,31 @@ void shouldImportFileOverRepairedRecords(@TempDir Path tempDir) throws Exception
163163
repairedEpoch));
164164
}
165165

166+
@Test
167+
void shouldFailImportingIfValidatorExistingRecordHasDifferentGenesisValidatorsRoot(
168+
@TempDir Path tempDir) throws URISyntaxException, IOException {
169+
final SlashingProtectionImporter importer = new SlashingProtectionImporter(tempDir);
170+
171+
final File slashProtection = getResourceFile("format2_minimal.json");
172+
173+
importer.initialise(slashProtection);
174+
175+
Map<BLSPublicKey, String> errors = importer.updateLocalRecords(__ -> {});
176+
177+
assertThat(errors).isEmpty();
178+
179+
final File slashProtectionWithDifferentGvr =
180+
getResourceFile("format2_minimal_different_genesis_validators_root.json");
181+
182+
importer.initialise(slashProtectionWithDifferentGvr);
183+
184+
errors = importer.updateLocalRecords(__ -> {});
185+
186+
assertThat(errors)
187+
.hasSize(1)
188+
.containsEntry(publicKey, "Genesis validators root did not match what was expected.");
189+
}
190+
166191
private ValidatorSigningRecord loadSigningRecord(final File repairedRuleFile) throws IOException {
167192
return ValidatorSigningRecord.fromBytes(
168193
Bytes.wrap(Files.readAllBytes(repairedRuleFile.toPath())));
@@ -182,9 +207,11 @@ private File usingResourceFile(final String resourceFileName, final Path tempDir
182207
throws URISyntaxException, IOException {
183208
final Path tempFile = tempDir.resolve(pubkey + ".yml").toAbsolutePath();
184209
Files.copy(
185-
new File(Resources.getResource(resourceFileName).toURI()).toPath(),
186-
tempFile,
187-
StandardCopyOption.REPLACE_EXISTING);
210+
getResourceFile(resourceFileName).toPath(), tempFile, StandardCopyOption.REPLACE_EXISTING);
188211
return tempFile.toFile();
189212
}
213+
214+
private File getResourceFile(final String resourceFileName) throws URISyntaxException {
215+
return new File(Resources.getResource(resourceFileName).toURI());
216+
}
190217
}

Diff for: data/dataexchange/src/test/resources/format2_minimal.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
{
88
"pubkey": "0xb845089a1457f811bfc000588fbb4e713669be8ce060ea6be3c6ece09afc3794106c91ca73acda5e5457122d58723bed",
99
"signed_blocks": [
10-
{"slot": "81952"
10+
{
11+
"slot": "81952"
1112
}
1213
],
1314
"signed_attestations": [
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"metadata": {
3+
"interchange_format_version": "5",
4+
"genesis_validators_root": "0x0000000000000000000000000000000000000000000000000000000000123457"
5+
},
6+
"data": [
7+
{
8+
"pubkey": "0xb845089a1457f811bfc000588fbb4e713669be8ce060ea6be3c6ece09afc3794106c91ca73acda5e5457122d58723bed",
9+
"signed_blocks": [
10+
{
11+
"slot": "81952"
12+
}
13+
],
14+
"signed_attestations": [
15+
{
16+
"source_epoch": "2290",
17+
"target_epoch": "3007"
18+
}
19+
]
20+
}
21+
]
22+
}

Diff for: data/serializer/src/main/java/tech/pegasys/teku/api/schema/electra/PendingConsolidation.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public PendingConsolidation(
4747
spec.getSchemaDefinitions().toVersionElectra();
4848
if (schemaDefinitionsElectra.isEmpty()) {
4949
throw new IllegalArgumentException(
50-
"Could not create PendingBalanceDeposit for pre-electra spec");
50+
"Could not create PendingConsolidation for pre-electra spec");
5151
}
5252
return schemaDefinitionsElectra
5353
.get()

Diff for: data/serializer/src/main/java/tech/pegasys/teku/api/schema/electra/PendingPartialWithdrawal.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public PendingPartialWithdrawal(
5353
spec.getSchemaDefinitions().toVersionElectra();
5454
if (schemaDefinitionsElectra.isEmpty()) {
5555
throw new IllegalArgumentException(
56-
"Could not create PendingBalanceDeposit for pre-electra spec");
56+
"Could not create PendingPartialWithdrawal for pre-electra spec");
5757
}
5858
return schemaDefinitionsElectra
5959
.get()

Diff for: eth-reference-tests/build.gradle

+3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ dependencies {
1515
referenceTestImplementation project(':storage')
1616
referenceTestImplementation testFixtures(project(':storage'))
1717
referenceTestImplementation project(':infrastructure:async')
18+
referenceTestImplementation project(':infrastructure:io')
1819
referenceTestImplementation testFixtures(project(':infrastructure:async'))
1920
referenceTestImplementation testFixtures(project(':infrastructure:metrics'))
2021
referenceTestImplementation project(':infrastructure:time')
22+
referenceTestImplementation project(':data:dataexchange')
23+
referenceTestImplementation project(':data:serializer')
2124

2225
referenceTestImplementation 'org.hyperledger.besu:plugin-api'
2326
referenceTestImplementation 'com.fasterxml.jackson.core:jackson-databind'

Diff for: eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/Eth2ReferenceTestCase.java

+2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import tech.pegasys.teku.reference.phase0.rewards.RewardsTestExecutorPhase0;
3232
import tech.pegasys.teku.reference.phase0.sanity.SanityTests;
3333
import tech.pegasys.teku.reference.phase0.shuffling.ShufflingTestExecutor;
34+
import tech.pegasys.teku.reference.phase0.slashing_protection_interchange.SlashingProtectionInterchangeTestExecutor;
3435
import tech.pegasys.teku.reference.phase0.ssz_generic.SszGenericTests;
3536
import tech.pegasys.teku.reference.phase0.ssz_static.SszTestExecutor;
3637

@@ -48,6 +49,7 @@ public abstract class Eth2ReferenceTestCase {
4849
.putAll(SszGenericTests.SSZ_GENERIC_TEST_TYPES)
4950
.putAll(OperationsTestExecutor.OPERATIONS_TEST_TYPES)
5051
.putAll(SanityTests.SANITY_TEST_TYPES)
52+
.put("slashing-protection-interchange", new SlashingProtectionInterchangeTestExecutor())
5153
.put("light_client/single_merkle_proof", TestExecutor.IGNORE_TESTS)
5254
.put("light_client/sync", TestExecutor.IGNORE_TESTS)
5355
.put("light_client/update_ranking", TestExecutor.IGNORE_TESTS)

Diff for: eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/ManualReferenceTestRunner.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class ManualReferenceTestRunner extends Eth2ReferenceTestCase {
4242
*
4343
* <p>May be overridden by the ENV_TEST_TYPE environment variable.
4444
*/
45-
private static final String TEST_TYPE = "fork_choice";
45+
private static final String TEST_TYPE = "";
4646

4747
/**
4848
* Filter test to run to those from the specified spec. One of general, minimal or mainnet

Diff for: eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/TestDataUtils.java

+19-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020
import java.io.InputStream;
2121
import java.io.UncheckedIOException;
22+
import java.nio.charset.StandardCharsets;
2223
import java.nio.file.Files;
2324
import java.nio.file.Path;
2425
import java.util.function.Function;
@@ -29,18 +30,21 @@
2930
import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition;
3031
import tech.pegasys.teku.infrastructure.ssz.SszData;
3132
import tech.pegasys.teku.infrastructure.ssz.schema.SszSchema;
33+
import tech.pegasys.teku.provider.JsonProvider;
3234
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
3335

3436
public class TestDataUtils {
3537

3638
private static final YAMLFactory YAML_FACTORY;
39+
private static final JsonProvider JSON_PROVIDER;
3740

3841
static {
3942
final LoaderOptions loaderOptions = new LoaderOptions();
4043
// Set the code point limit to 100MB - context:
4144
// https://github.com/FasterXML/jackson-dataformats-text/tree/2.15/yaml#maximum-input-yaml-document-size-3-mb
4245
loaderOptions.setCodePointLimit(1024 * 1024 * 100);
4346
YAML_FACTORY = YAMLFactory.builder().loaderOptions(loaderOptions).build();
47+
JSON_PROVIDER = new JsonProvider();
4448
}
4549

4650
public static <T extends SszData> T loadSsz(
@@ -85,7 +89,7 @@ public static <T> T loadYaml(
8589
throws IOException {
8690
final Path path = testDefinition.getTestDirectory().resolve(fileName);
8791
try (final InputStream in = Files.newInputStream(path)) {
88-
return new ObjectMapper(YAML_FACTORY).readerFor(type).readValue(in);
92+
return new ObjectMapper(YAML_FACTORY).readValue(in, type);
8993
}
9094
}
9195

@@ -100,4 +104,18 @@ public static <T> T loadYaml(
100104
return type.deserialize(in);
101105
}
102106
}
107+
108+
public static <T> T loadJson(
109+
final TestDefinition testDefinition, final String fileName, final Class<T> type)
110+
throws IOException {
111+
final Path path = testDefinition.getTestDirectory().resolve(fileName);
112+
try (final InputStream in = Files.newInputStream(path)) {
113+
return JSON_PROVIDER.getObjectMapper().readValue(in, type);
114+
}
115+
}
116+
117+
public static <T> void writeJsonToFile(final T object, final Path file) throws IOException {
118+
final String json = JSON_PROVIDER.getObjectMapper().writeValueAsString(object);
119+
Files.writeString(file, json, StandardCharsets.UTF_8);
120+
}
103121
}

Diff for: eth-reference-tests/src/referenceTest/java/tech/pegasys/teku/reference/altair/fork/ForkUpgradeTestExecutor.java

+2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.altair.BeaconStateSchemaAltair;
2828
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.bellatrix.BeaconStateSchemaBellatrix;
2929
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.capella.BeaconStateSchemaCapella;
30+
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.deneb.BeaconStateSchemaDeneb;
3031
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.phase0.BeaconStateSchemaPhase0;
3132
import tech.pegasys.teku.spec.logic.common.forktransition.StateUpgrade;
3233

@@ -50,6 +51,7 @@ private void processUpgrade(final TestDefinition testDefinition, final SpecMiles
5051
case BELLATRIX -> BeaconStateSchemaAltair.create(spec.getConfig());
5152
case CAPELLA -> BeaconStateSchemaBellatrix.create(spec.getConfig());
5253
case DENEB -> BeaconStateSchemaCapella.create(spec.getConfig());
54+
case ELECTRA -> BeaconStateSchemaDeneb.create(spec.getConfig());
5355
default -> throw new IllegalStateException(
5456
"Unhandled fork upgrade for test "
5557
+ testDefinition.getDisplayName()

0 commit comments

Comments
 (0)