Skip to content

Commit db6c97f

Browse files
changes
1 parent 52f7d5a commit db6c97f

File tree

3 files changed

+74
-10
lines changed

3 files changed

+74
-10
lines changed

ethereum/spec/src/main/java/tech/pegasys/teku/spec/logic/versions/gloas/execution/ExecutionPayloadProcessorGloas.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionRequestsDataCodec;
3838
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
3939
import tech.pegasys.teku.spec.datastructures.state.beaconstate.MutableBeaconState;
40-
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.gloas.BeaconStateGloas;
4140
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.gloas.MutableBeaconStateGloas;
4241
import tech.pegasys.teku.spec.datastructures.state.versions.gloas.BuilderPendingPayment;
4342
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment;
@@ -100,13 +99,9 @@ private boolean verifyExecutionPayloadEnvelopeSignature(
10099
final BLSPublicKey pubkey;
101100
if (builderIndex.equals(BUILDER_INDEX_SELF_BUILD)) {
102101
final UInt64 validatorIndex = preState.getLatestBlockHeader().getProposerIndex();
103-
pubkey = preState.getValidators().get(validatorIndex.intValue()).getPublicKey();
102+
pubkey = beaconStateAccessors.getValidatorPubKey(preState, validatorIndex).orElseThrow();
104103
} else {
105-
pubkey =
106-
BeaconStateGloas.required(preState)
107-
.getBuilders()
108-
.get(builderIndex.intValue())
109-
.getPublicKey();
104+
pubkey = beaconStateAccessors.getBuilderPubKey(preState, builderIndex).orElseThrow();
110105
}
111106
final Bytes32 domain =
112107
beaconStateAccessors.getDomain(

ethereum/spec/src/test/java/tech/pegasys/teku/spec/logic/versions/gloas/helpers/BeaconStateAccessorsGloasTest.java

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@
1717

1818
import java.util.Optional;
1919
import org.junit.jupiter.api.Test;
20+
import tech.pegasys.teku.bls.BLSPublicKey;
21+
import tech.pegasys.teku.infrastructure.ssz.SszList;
22+
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
2023
import tech.pegasys.teku.spec.Spec;
2124
import tech.pegasys.teku.spec.TestSpecFactory;
2225
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState;
26+
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconStateCache;
2327
import tech.pegasys.teku.spec.datastructures.state.beaconstate.versions.gloas.BeaconStateGloas;
2428
import tech.pegasys.teku.spec.datastructures.state.versions.gloas.Builder;
2529
import tech.pegasys.teku.spec.util.DataStructureUtil;
@@ -34,9 +38,10 @@ public class BeaconStateAccessorsGloasTest {
3438
@Test
3539
void getBuilderIndex_shouldReturnBuilderIndex() {
3640
final BeaconStateGloas state = BeaconStateGloas.required(dataStructureUtil.randomBeaconState());
37-
assertThat(state.getBuilders()).hasSizeGreaterThan(5);
38-
for (int i = 0; i < 5; i++) {
39-
final Builder builder = state.getBuilders().get(i);
41+
final SszList<Builder> builders = state.getBuilders();
42+
assertThat(builders).isNotEmpty();
43+
for (int i = 0; i < builders.size(); i++) {
44+
final Builder builder = builders.get(i);
4045
assertThat(beaconStateAccessors.getBuilderIndex(state, builder.getPublicKey())).contains(i);
4146
}
4247
}
@@ -48,4 +53,31 @@ public void getBuilderIndex_shouldReturnEmptyWhenBuilderNotFound() {
4853
beaconStateAccessors.getBuilderIndex(state, dataStructureUtil.randomPublicKey());
4954
assertThat(index).isEmpty();
5055
}
56+
57+
@Test
58+
public void getBuilderPubKey_shouldReturnBuilderPubKey() {
59+
final BeaconStateGloas state = BeaconStateGloas.required(dataStructureUtil.randomBeaconState());
60+
final SszList<Builder> builders = state.getBuilders();
61+
assertThat(builders).isNotEmpty();
62+
for (int i = 0; i < builders.size(); i++) {
63+
final Builder builder = builders.get(i);
64+
final UInt64 builderIndex = UInt64.valueOf(i);
65+
assertThat(beaconStateAccessors.getBuilderPubKey(state, builderIndex))
66+
.contains(builder.getPublicKey());
67+
// pubKey => builderIndex mapping is pre cached
68+
assertThat(
69+
BeaconStateCache.getTransitionCaches(state)
70+
.getBuildersPubKeys()
71+
.getCached(builderIndex))
72+
.isPresent();
73+
}
74+
}
75+
76+
@Test
77+
public void getBuilderPubKey_shouldReturnEmptyWhenBuilderNotExisting() {
78+
final BeaconState state = dataStructureUtil.randomBeaconState();
79+
final Optional<BLSPublicKey> index =
80+
beaconStateAccessors.getBuilderPubKey(state, UInt64.valueOf(999));
81+
assertThat(index).isEmpty();
82+
}
5183
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright Consensys Software Inc., 2026
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
14+
package tech.pegasys.teku.spec.logic.versions.gloas.helpers;
15+
16+
import static org.assertj.core.api.Assertions.assertThat;
17+
18+
import org.junit.jupiter.api.Test;
19+
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
20+
import tech.pegasys.teku.spec.Spec;
21+
import tech.pegasys.teku.spec.TestSpecFactory;
22+
23+
public class MiscHelpersGloasTest {
24+
25+
private final Spec spec = TestSpecFactory.createMinimalGloas();
26+
27+
private final MiscHelpersGloas miscHelpers =
28+
MiscHelpersGloas.required(spec.getGenesisSpec().miscHelpers());
29+
30+
@Test
31+
public void roundTrip_convertBetweenBuilderIndexAndValidatorIndex() {
32+
final UInt64 builderIndex = UInt64.valueOf(42);
33+
final UInt64 validatorIndex = miscHelpers.convertBuilderIndexToValidatorIndex(builderIndex);
34+
assertThat(miscHelpers.convertValidatorIndexToBuilderIndex(validatorIndex))
35+
.isEqualTo(builderIndex);
36+
}
37+
}

0 commit comments

Comments
 (0)