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

Handling BlsToExecutionChange operations on reorgs #6809

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -42,6 +42,7 @@ public class OperationsReOrgManager implements ChainHeadChannel {
private final OperationPool<AttesterSlashing> attesterSlashingPool;
private final AttestationManager attestationManager;
private final AggregatingAttestationPool attestationPool;
private final BlsToExecutionOperationPool blsToExecutionOperationPool;
private final RecentChainData recentChainData;

public OperationsReOrgManager(
Expand All @@ -50,12 +51,14 @@ public OperationsReOrgManager(
final OperationPool<SignedVoluntaryExit> exitPool,
final AggregatingAttestationPool attestationPool,
final AttestationManager attestationManager,
final BlsToExecutionOperationPool blsToExecutionOperationPool,
final RecentChainData recentChainData) {
this.exitPool = exitPool;
this.proposerSlashingPool = proposerSlashingPool;
this.attesterSlashingPool = attesterSlashingPool;
this.attestationManager = attestationManager;
this.attestationPool = attestationPool;
this.blsToExecutionOperationPool = blsToExecutionOperationPool;
this.recentChainData = recentChainData;
}

Expand Down Expand Up @@ -101,6 +104,9 @@ private void processNonCanonicalBlockOperations(
proposerSlashingPool.addAll(blockBody.getProposerSlashings());
attesterSlashingPool.addAll(blockBody.getAttesterSlashings());
exitPool.addAll(blockBody.getVoluntaryExits());
blockBody
.getOptionalBlsToExecutionChanges()
.ifPresent(blsToExecutionOperationPool::addAll);

processNonCanonicalBlockAttestations(blockBody.getAttestations(), root);
},
Expand Down Expand Up @@ -160,6 +166,9 @@ private void processCanonicalBlockOperations(final Collection<Bytes32> canonical
exitPool.removeAll(blockBody.getVoluntaryExits());
attestationPool.onAttestationsIncludedInBlock(
block.getSlot(), blockBody.getAttestations());
blockBody
.getOptionalBlsToExecutionChanges()
.ifPresent(blsToExecutionOperationPool::removeAll);
},
() ->
LOG.debug(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

@SuppressWarnings("unchecked")
public class OperationsReOrgManagerTest {
private final Spec spec = TestSpecFactory.createDefault();
private final Spec spec = TestSpecFactory.createMinimalCapella();
private final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);

private final OperationPool<ProposerSlashing> proposerSlashingOperationPool =
Expand All @@ -59,6 +59,8 @@ public class OperationsReOrgManagerTest {
mock(SimpleOperationPool.class);
private final AggregatingAttestationPool attestationPool = mock(AggregatingAttestationPool.class);
private final AttestationManager attestationManager = mock(AttestationManager.class);
private final BlsToExecutionOperationPool blsToExecutionOperationPool =
mock(BlsToExecutionOperationPool.class);

private final RecentChainData recentChainData = mock(RecentChainData.class);

Expand All @@ -69,6 +71,7 @@ public class OperationsReOrgManagerTest {
exitOperationPool,
attestationPool,
attestationManager,
blsToExecutionOperationPool,
recentChainData);

@Test
Expand Down Expand Up @@ -127,10 +130,14 @@ void shouldRequeueAndRemoveOperations() {
verify(proposerSlashingOperationPool).addAll(fork1Block1.getBody().getProposerSlashings());
verify(attesterSlashingOperationPool).addAll(fork1Block1.getBody().getAttesterSlashings());
verify(exitOperationPool).addAll(fork1Block1.getBody().getVoluntaryExits());
verify(blsToExecutionOperationPool)
.addAll(fork1Block1.getBody().getOptionalBlsToExecutionChanges().orElseThrow());

verify(proposerSlashingOperationPool).addAll(fork1Block2.getBody().getProposerSlashings());
verify(attesterSlashingOperationPool).addAll(fork1Block2.getBody().getAttesterSlashings());
verify(exitOperationPool).addAll(fork1Block2.getBody().getVoluntaryExits());
verify(blsToExecutionOperationPool)
.addAll(fork1Block2.getBody().getOptionalBlsToExecutionChanges().orElseThrow());

ArgumentCaptor<ValidateableAttestation> argument =
ArgumentCaptor.forClass(ValidateableAttestation.class);
Expand All @@ -155,13 +162,17 @@ void shouldRequeueAndRemoveOperations() {
verify(attestationPool)
.onAttestationsIncludedInBlock(
fork2Block1.getSlot(), fork2Block1.getBody().getAttestations());
verify(blsToExecutionOperationPool)
.removeAll(fork2Block1.getBody().getOptionalBlsToExecutionChanges().orElseThrow());

verify(proposerSlashingOperationPool).removeAll(fork2Block2.getBody().getProposerSlashings());
verify(attesterSlashingOperationPool).removeAll(fork2Block2.getBody().getAttesterSlashings());
verify(exitOperationPool).removeAll(fork2Block2.getBody().getVoluntaryExits());
verify(attestationPool)
.onAttestationsIncludedInBlock(
fork2Block2.getSlot(), fork2Block2.getBody().getAttestations());
verify(blsToExecutionOperationPool)
.removeAll(fork2Block2.getBody().getOptionalBlsToExecutionChanges().orElseThrow());
}

@Test
Expand Down Expand Up @@ -206,17 +217,22 @@ void shouldOnlyRemoveOperations() {
verify(proposerSlashingOperationPool, never()).addAll(any());
verify(attesterSlashingOperationPool, never()).addAll(any());
verify(attestationManager, never()).onAttestation(any());
verify(blsToExecutionOperationPool, never()).addAll(any());

verify(proposerSlashingOperationPool).removeAll(block2.getBody().getProposerSlashings());
verify(attesterSlashingOperationPool).removeAll(block2.getBody().getAttesterSlashings());
verify(exitOperationPool).removeAll(block2.getBody().getVoluntaryExits());
verify(attestationPool)
.onAttestationsIncludedInBlock(block2.getSlot(), block2.getBody().getAttestations());
verify(blsToExecutionOperationPool)
.removeAll(block2.getBody().getOptionalBlsToExecutionChanges().orElseThrow());

verify(proposerSlashingOperationPool).removeAll(block1.getBody().getProposerSlashings());
verify(attesterSlashingOperationPool).removeAll(block1.getBody().getAttesterSlashings());
verify(exitOperationPool).removeAll(block1.getBody().getVoluntaryExits());
verify(attestationPool)
.onAttestationsIncludedInBlock(block1.getSlot(), block1.getBody().getAttestations());
verify(blsToExecutionOperationPool)
.removeAll(block1.getBody().getOptionalBlsToExecutionChanges().orElseThrow());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
import tech.pegasys.teku.spec.datastructures.interop.GenesisStateBuilder;
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
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.state.AnchorPoint;
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
Expand Down Expand Up @@ -219,7 +218,7 @@ public class BeaconChainController extends Service implements BeaconChainControl
protected volatile OperationPool<AttesterSlashing> attesterSlashingPool;
protected volatile OperationPool<ProposerSlashing> proposerSlashingPool;
protected volatile OperationPool<SignedVoluntaryExit> voluntaryExitPool;
protected volatile OperationPool<SignedBlsToExecutionChange> blsToExecutionChangePool;
protected volatile BlsToExecutionOperationPool blsToExecutionChangePool;
protected volatile SyncCommitteeContributionPool syncCommitteeContributionPool;
protected volatile SyncCommitteeMessagePool syncCommitteeMessagePool;
protected volatile WeakSubjectivityValidator weakSubjectivityValidator;
Expand Down Expand Up @@ -1041,6 +1040,7 @@ protected void initOperationsReOrgManager() {
voluntaryExitPool,
attestationPool,
attestationManager,
blsToExecutionChangePool,
recentChainData);
eventChannels.subscribe(ChainHeadChannel.class, operationsReOrgManager);
}
Expand Down