Skip to content

Commit 7a4abc6

Browse files
Handling BlsToExecutionChange operations on reorgs (#6809)
1 parent 385eaa8 commit 7a4abc6

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

ethereum/statetransition/src/main/java/tech/pegasys/teku/statetransition/OperationsReOrgManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class OperationsReOrgManager implements ChainHeadChannel {
4242
private final OperationPool<AttesterSlashing> attesterSlashingPool;
4343
private final AttestationManager attestationManager;
4444
private final AggregatingAttestationPool attestationPool;
45+
private final BlsToExecutionOperationPool blsToExecutionOperationPool;
4546
private final RecentChainData recentChainData;
4647

4748
public OperationsReOrgManager(
@@ -50,12 +51,14 @@ public OperationsReOrgManager(
5051
final OperationPool<SignedVoluntaryExit> exitPool,
5152
final AggregatingAttestationPool attestationPool,
5253
final AttestationManager attestationManager,
54+
final BlsToExecutionOperationPool blsToExecutionOperationPool,
5355
final RecentChainData recentChainData) {
5456
this.exitPool = exitPool;
5557
this.proposerSlashingPool = proposerSlashingPool;
5658
this.attesterSlashingPool = attesterSlashingPool;
5759
this.attestationManager = attestationManager;
5860
this.attestationPool = attestationPool;
61+
this.blsToExecutionOperationPool = blsToExecutionOperationPool;
5962
this.recentChainData = recentChainData;
6063
}
6164

@@ -101,6 +104,9 @@ private void processNonCanonicalBlockOperations(
101104
proposerSlashingPool.addAll(blockBody.getProposerSlashings());
102105
attesterSlashingPool.addAll(blockBody.getAttesterSlashings());
103106
exitPool.addAll(blockBody.getVoluntaryExits());
107+
blockBody
108+
.getOptionalBlsToExecutionChanges()
109+
.ifPresent(blsToExecutionOperationPool::addAll);
104110

105111
processNonCanonicalBlockAttestations(blockBody.getAttestations(), root);
106112
},
@@ -160,6 +166,9 @@ private void processCanonicalBlockOperations(final Collection<Bytes32> canonical
160166
exitPool.removeAll(blockBody.getVoluntaryExits());
161167
attestationPool.onAttestationsIncludedInBlock(
162168
block.getSlot(), blockBody.getAttestations());
169+
blockBody
170+
.getOptionalBlsToExecutionChanges()
171+
.ifPresent(blsToExecutionOperationPool::removeAll);
163172
},
164173
() ->
165174
LOG.debug(

ethereum/statetransition/src/test/java/tech/pegasys/teku/statetransition/OperationsReOrgManagerTest.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848

4949
@SuppressWarnings("unchecked")
5050
public class OperationsReOrgManagerTest {
51-
private final Spec spec = TestSpecFactory.createDefault();
51+
private final Spec spec = TestSpecFactory.createMinimalCapella();
5252
private final DataStructureUtil dataStructureUtil = new DataStructureUtil(spec);
5353

5454
private final OperationPool<ProposerSlashing> proposerSlashingOperationPool =
@@ -59,6 +59,8 @@ public class OperationsReOrgManagerTest {
5959
mock(SimpleOperationPool.class);
6060
private final AggregatingAttestationPool attestationPool = mock(AggregatingAttestationPool.class);
6161
private final AttestationManager attestationManager = mock(AttestationManager.class);
62+
private final BlsToExecutionOperationPool blsToExecutionOperationPool =
63+
mock(BlsToExecutionOperationPool.class);
6264

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

@@ -69,6 +71,7 @@ public class OperationsReOrgManagerTest {
6971
exitOperationPool,
7072
attestationPool,
7173
attestationManager,
74+
blsToExecutionOperationPool,
7275
recentChainData);
7376

7477
@Test
@@ -127,10 +130,14 @@ void shouldRequeueAndRemoveOperations() {
127130
verify(proposerSlashingOperationPool).addAll(fork1Block1.getBody().getProposerSlashings());
128131
verify(attesterSlashingOperationPool).addAll(fork1Block1.getBody().getAttesterSlashings());
129132
verify(exitOperationPool).addAll(fork1Block1.getBody().getVoluntaryExits());
133+
verify(blsToExecutionOperationPool)
134+
.addAll(fork1Block1.getBody().getOptionalBlsToExecutionChanges().orElseThrow());
130135

131136
verify(proposerSlashingOperationPool).addAll(fork1Block2.getBody().getProposerSlashings());
132137
verify(attesterSlashingOperationPool).addAll(fork1Block2.getBody().getAttesterSlashings());
133138
verify(exitOperationPool).addAll(fork1Block2.getBody().getVoluntaryExits());
139+
verify(blsToExecutionOperationPool)
140+
.addAll(fork1Block2.getBody().getOptionalBlsToExecutionChanges().orElseThrow());
134141

135142
ArgumentCaptor<ValidateableAttestation> argument =
136143
ArgumentCaptor.forClass(ValidateableAttestation.class);
@@ -155,13 +162,17 @@ void shouldRequeueAndRemoveOperations() {
155162
verify(attestationPool)
156163
.onAttestationsIncludedInBlock(
157164
fork2Block1.getSlot(), fork2Block1.getBody().getAttestations());
165+
verify(blsToExecutionOperationPool)
166+
.removeAll(fork2Block1.getBody().getOptionalBlsToExecutionChanges().orElseThrow());
158167

159168
verify(proposerSlashingOperationPool).removeAll(fork2Block2.getBody().getProposerSlashings());
160169
verify(attesterSlashingOperationPool).removeAll(fork2Block2.getBody().getAttesterSlashings());
161170
verify(exitOperationPool).removeAll(fork2Block2.getBody().getVoluntaryExits());
162171
verify(attestationPool)
163172
.onAttestationsIncludedInBlock(
164173
fork2Block2.getSlot(), fork2Block2.getBody().getAttestations());
174+
verify(blsToExecutionOperationPool)
175+
.removeAll(fork2Block2.getBody().getOptionalBlsToExecutionChanges().orElseThrow());
165176
}
166177

167178
@Test
@@ -206,17 +217,22 @@ void shouldOnlyRemoveOperations() {
206217
verify(proposerSlashingOperationPool, never()).addAll(any());
207218
verify(attesterSlashingOperationPool, never()).addAll(any());
208219
verify(attestationManager, never()).onAttestation(any());
220+
verify(blsToExecutionOperationPool, never()).addAll(any());
209221

210222
verify(proposerSlashingOperationPool).removeAll(block2.getBody().getProposerSlashings());
211223
verify(attesterSlashingOperationPool).removeAll(block2.getBody().getAttesterSlashings());
212224
verify(exitOperationPool).removeAll(block2.getBody().getVoluntaryExits());
213225
verify(attestationPool)
214226
.onAttestationsIncludedInBlock(block2.getSlot(), block2.getBody().getAttestations());
227+
verify(blsToExecutionOperationPool)
228+
.removeAll(block2.getBody().getOptionalBlsToExecutionChanges().orElseThrow());
215229

216230
verify(proposerSlashingOperationPool).removeAll(block1.getBody().getProposerSlashings());
217231
verify(attesterSlashingOperationPool).removeAll(block1.getBody().getAttesterSlashings());
218232
verify(exitOperationPool).removeAll(block1.getBody().getVoluntaryExits());
219233
verify(attestationPool)
220234
.onAttestationsIncludedInBlock(block1.getSlot(), block1.getBody().getAttestations());
235+
verify(blsToExecutionOperationPool)
236+
.removeAll(block1.getBody().getOptionalBlsToExecutionChanges().orElseThrow());
221237
}
222238
}

services/beaconchain/src/main/java/tech/pegasys/teku/services/beaconchain/BeaconChainController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
import tech.pegasys.teku.spec.datastructures.interop.GenesisStateBuilder;
8888
import tech.pegasys.teku.spec.datastructures.operations.AttesterSlashing;
8989
import tech.pegasys.teku.spec.datastructures.operations.ProposerSlashing;
90-
import tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange;
9190
import tech.pegasys.teku.spec.datastructures.operations.SignedVoluntaryExit;
9291
import tech.pegasys.teku.spec.datastructures.state.AnchorPoint;
9392
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
@@ -219,7 +218,7 @@ public class BeaconChainController extends Service implements BeaconChainControl
219218
protected volatile OperationPool<AttesterSlashing> attesterSlashingPool;
220219
protected volatile OperationPool<ProposerSlashing> proposerSlashingPool;
221220
protected volatile OperationPool<SignedVoluntaryExit> voluntaryExitPool;
222-
protected volatile OperationPool<SignedBlsToExecutionChange> blsToExecutionChangePool;
221+
protected volatile BlsToExecutionOperationPool blsToExecutionChangePool;
223222
protected volatile SyncCommitteeContributionPool syncCommitteeContributionPool;
224223
protected volatile SyncCommitteeMessagePool syncCommitteeMessagePool;
225224
protected volatile WeakSubjectivityValidator weakSubjectivityValidator;
@@ -1041,6 +1040,7 @@ protected void initOperationsReOrgManager() {
10411040
voluntaryExitPool,
10421041
attestationPool,
10431042
attestationManager,
1043+
blsToExecutionChangePool,
10441044
recentChainData);
10451045
eventChannels.subscribe(ChainHeadChannel.class, operationsReOrgManager);
10461046
}

0 commit comments

Comments
 (0)