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

Added SingleAttestationEvent #8873

Merged
merged 7 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,14 @@ protected void onSyncCommitteeContribution(
}

protected void onNewAttestation(final ValidatableAttestation attestation) {
final AttestationEvent attestationEvent = new AttestationEvent(attestation.getAttestation());
notifySubscribersOfEvent(EventType.attestation, attestationEvent);
if (!attestation.getAttestation().isSingleAttestation()) {
final AttestationEvent attestationEvent = new AttestationEvent(attestation.getAttestation());
notifySubscribersOfEvent(EventType.attestation, attestationEvent);
} else {
final SingleAttestationEvent attestationEvent =
new SingleAttestationEvent(attestation.getAttestation().toSingleAttestationRequired());
notifySubscribersOfEvent(EventType.single_attestation, attestationEvent);
}
}

protected void onNewBlock(final SignedBeaconBlock block, final boolean executionOptimistic) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Consensys Software Inc., 2024
*
* 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.beaconrestapi.handlers.v1.events;

import tech.pegasys.teku.spec.datastructures.operations.SingleAttestation;

public class SingleAttestationEvent extends Event<SingleAttestation> {
SingleAttestationEvent(final SingleAttestation attestation) {
super(
attestation.toSingleAttestationRequired().getSchema().getJsonTypeDefinition(), attestation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange;
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
import tech.pegasys.teku.spec.datastructures.operations.SingleAttestation;
import tech.pegasys.teku.spec.datastructures.operations.versions.altair.SignedContributionAndProof;
import tech.pegasys.teku.spec.datastructures.state.Checkpoint;
import tech.pegasys.teku.spec.executionlayer.ForkChoiceState;
Expand All @@ -65,7 +66,7 @@
import tech.pegasys.teku.storage.api.ReorgContext;

public class EventSubscriptionManagerTest {
private final Spec spec = TestSpecFactory.createMinimalDeneb();
private final Spec spec = TestSpecFactory.createMinimalElectra();
private final SpecConfig specConfig = spec.getGenesisSpecConfig();
private final DataStructureUtil data = new DataStructureUtil(spec);
protected final NodeDataProvider nodeDataProvider = mock(NodeDataProvider.class);
Expand Down Expand Up @@ -107,6 +108,7 @@ public class EventSubscriptionManagerTest {
SignedBeaconBlock.create(data.randomSignedBeaconBlock(0));
private final BlobSidecar sampleBlobSidecar = data.randomBlobSidecar();
private final Attestation sampleAttestation = data.randomAttestation(0);
private final SingleAttestation singleAttestation = data.randomSingleAttestation();

private final AttesterSlashing sampleAttesterSlashing =
spec.getGenesisSchemaDefinitions()
Expand All @@ -123,7 +125,7 @@ public class EventSubscriptionManagerTest {
data.randomPayloadBuildingAttributes(true);
final PayloadAttributesData samplePayloadAttributesData =
new PayloadAttributesData(
SpecMilestone.DENEB,
SpecMilestone.ELECTRA,
new Data(
samplePayloadAttributes.getProposalSlot(),
samplePayloadAttributes.getParentBeaconBlockRoot(),
Expand Down Expand Up @@ -299,6 +301,15 @@ void shouldPropagateAttestation() throws IOException {
checkEvent("attestation", new AttestationEvent(sampleAttestation));
}

@Test
void shouldPropagateSingleAttestation() throws IOException {
when(req.getQueryString()).thenReturn("&topics=single_attestation");
manager.registerClient(client1);

triggerSingleAttestationEvent();
checkEvent("single_attestation", new SingleAttestationEvent(singleAttestation));
}

@Test
void shouldPropagateAttesterSlashing() throws IOException {
when(req.getQueryString()).thenReturn("&topics=attester_slashing");
Expand Down Expand Up @@ -438,6 +449,11 @@ private void triggerAttestationEvent() {
asyncRunner.executeQueuedActions();
}

private void triggerSingleAttestationEvent() {
manager.onNewAttestation(ValidatableAttestation.from(spec, singleAttestation));
asyncRunner.executeQueuedActions();
}

private void triggerAttesterSlashingEvent() {
manager.onNewAttesterSlashing(sampleAttesterSlashing, InternalValidationResult.ACCEPT, false);
asyncRunner.executeQueuedActions();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public enum EventType {
attester_slashing,
proposer_slashing,
payload_attributes,
block_gossip;
block_gossip,
single_attestation;

public static List<EventType> getTopics(final List<String> topics) {
return topics.stream().map(EventType::valueOf).toList();
Expand Down
Loading