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

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

Lines changed: 3 additions & 0 deletions
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
}

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

Lines changed: 12 additions & 0 deletions
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();

build.gradle

Lines changed: 31 additions & 3 deletions
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

data/dataexchange/src/test/java/tech/pegasys/teku/data/SlashingProtectionImporterTest.java

Lines changed: 30 additions & 3 deletions
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
}

data/dataexchange/src/test/resources/format2_minimal.json

Lines changed: 2 additions & 1 deletion
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": [
Lines changed: 22 additions & 0 deletions
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+
}

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

Lines changed: 1 addition & 1 deletion
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()

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

Lines changed: 1 addition & 1 deletion
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()

eth-reference-tests/build.gradle

Lines changed: 3 additions & 0 deletions
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'

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

Lines changed: 2 additions & 0 deletions
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)

0 commit comments

Comments
 (0)