33
33
import org .apache .tuweni .units .bigints .UInt256 ;
34
34
import org .junit .jupiter .api .AfterAll ;
35
35
import org .junit .jupiter .api .BeforeAll ;
36
+ import tech .pegasys .teku .bls .BLSPublicKey ;
36
37
import tech .pegasys .teku .bls .BLSSignature ;
37
38
import tech .pegasys .teku .bls .BLSSignatureVerifier ;
38
39
import tech .pegasys .teku .ethereum .performance .trackers .BlockProductionPerformance ;
53
54
import tech .pegasys .teku .spec .datastructures .blocks .blockbody .versions .altair .SyncAggregate ;
54
55
import tech .pegasys .teku .spec .datastructures .blocks .blockbody .versions .bellatrix .BeaconBlockBodyBellatrix ;
55
56
import tech .pegasys .teku .spec .datastructures .blocks .blockbody .versions .bellatrix .BlindedBeaconBlockBodyBellatrix ;
57
+ import tech .pegasys .teku .spec .datastructures .builder .BuilderBid ;
56
58
import tech .pegasys .teku .spec .datastructures .builder .BuilderPayload ;
57
59
import tech .pegasys .teku .spec .datastructures .execution .BlobsBundle ;
60
+ import tech .pegasys .teku .spec .datastructures .execution .BuilderBidOrFallbackData ;
61
+ import tech .pegasys .teku .spec .datastructures .execution .BuilderPayloadOrFallbackData ;
58
62
import tech .pegasys .teku .spec .datastructures .execution .ExecutionPayload ;
59
63
import tech .pegasys .teku .spec .datastructures .execution .ExecutionPayloadHeader ;
60
64
import tech .pegasys .teku .spec .datastructures .execution .ExecutionPayloadResult ;
61
- import tech .pegasys .teku .spec .datastructures .execution .HeaderWithFallbackData ;
65
+ import tech .pegasys .teku .spec .datastructures .execution .GetPayloadResponse ;
62
66
import tech .pegasys .teku .spec .datastructures .metadata .BlockContainerAndMetaData ;
63
67
import tech .pegasys .teku .spec .datastructures .operations .Attestation ;
64
68
import tech .pegasys .teku .spec .datastructures .operations .AttesterSlashing ;
@@ -197,8 +201,6 @@ protected BlockContainerAndMetaData assertBlockCreated(
197
201
SafeFuture .completedFuture (
198
202
Optional .of (dataStructureUtil .randomPayloadExecutionContext (false ))));
199
203
200
- setupExecutionLayerBlockAndBlobsProduction ();
201
-
202
204
final BLSSignature randaoReveal = dataStructureUtil .randomSignature ();
203
205
final Bytes32 bestBlockRoot = recentChainData .getBestBlockRoot ().orElseThrow ();
204
206
final BeaconState blockSlotState =
@@ -209,24 +211,25 @@ protected BlockContainerAndMetaData assertBlockCreated(
209
211
210
212
when (syncCommitteeContributionPool .createSyncAggregateForBlock (newSlot , bestBlockRoot ))
211
213
.thenAnswer (invocation -> createEmptySyncAggregate (spec ));
212
- executionPayloadBuilder .accept (blockSlotState );
213
214
214
215
final UInt256 blockExecutionValue ;
215
216
final UInt64 blockProposerRewards ;
216
217
217
218
if (milestone .isGreaterThanOrEqualTo (SpecMilestone .BELLATRIX )) {
218
219
blockExecutionValue = dataStructureUtil .randomUInt256 ();
219
220
blockProposerRewards = dataStructureUtil .randomUInt64 ();
220
-
221
- // inject values into slot caches
221
+ // increase block proposer rewards to test the consensus block value
222
222
final SlotCaches slotCaches = BeaconStateCache .getSlotCaches (blockSlotState );
223
- slotCaches .setBlockExecutionValue (blockExecutionValue );
224
223
slotCaches .increaseBlockProposerRewards (blockProposerRewards );
225
224
} else {
226
225
blockExecutionValue = UInt256 .ZERO ;
227
226
blockProposerRewards = UInt64 .ZERO ;
228
227
}
229
228
229
+ setupExecutionLayerBlockAndBlobsProduction (spec , blockExecutionValue );
230
+
231
+ executionPayloadBuilder .accept (blockSlotState );
232
+
230
233
final BlockContainerAndMetaData blockContainerAndMetaData =
231
234
safeJoin (
232
235
blockFactory .createUnsignedBlock (
@@ -291,7 +294,8 @@ protected SignedBeaconBlock assertBlockUnblinded(
291
294
292
295
// no need to prepare blobs bundle when only testing block unblinding
293
296
when (executionLayer .getUnblindedPayload (blindedBlock , BlockPublishingPerformance .NOOP ))
294
- .thenReturn (SafeFuture .completedFuture (executionPayload ));
297
+ .thenReturn (
298
+ SafeFuture .completedFuture (BuilderPayloadOrFallbackData .create (executionPayload )));
295
299
296
300
final SignedBeaconBlock unblindedBlock =
297
301
blockFactory
@@ -365,7 +369,7 @@ protected BlockAndBlobSidecars createBlockAndBlobSidecars(
365
369
366
370
// simulate caching of the builder payload
367
371
when (executionLayer .getCachedUnblindedPayload (signedBlockContainer .getSlot ()))
368
- .thenReturn (builderPayload );
372
+ .thenReturn (builderPayload . map ( BuilderPayloadOrFallbackData :: create ) );
369
373
370
374
final List <BlobSidecar > blobSidecars =
371
375
blockFactory .createBlobSidecars (signedBlockContainer , BlockPublishingPerformance .NOOP );
@@ -446,63 +450,42 @@ protected BuilderPayload prepareBuilderPayload(final Spec spec, final int blobsC
446
450
return builderPayload ;
447
451
}
448
452
449
- private void setupExecutionLayerBlockAndBlobsProduction () {
450
- // pre Deneb
453
+ private void setupExecutionLayerBlockAndBlobsProduction (final Spec spec , final UInt256 value ) {
454
+ // non-blinded
451
455
when (executionLayer .initiateBlockProduction (any (), any (), eq (false ), any (), any ()))
452
456
.thenAnswer (
453
457
args -> {
454
458
final ExecutionPayloadResult executionPayloadResult =
455
- new ExecutionPayloadResult (
459
+ ExecutionPayloadResult . createForLocalFlow (
456
460
args .getArgument (0 ),
457
- Optional .of (SafeFuture .completedFuture (executionPayload )),
458
- Optional .empty (),
459
- Optional .empty (),
460
- Optional .empty ());
461
+ SafeFuture .completedFuture (
462
+ blobsBundle
463
+ .map (
464
+ bundle ->
465
+ new GetPayloadResponse (
466
+ executionPayload , value , bundle , false ))
467
+ .orElseGet (() -> new GetPayloadResponse (executionPayload , value ))));
461
468
cachedExecutionPayloadResult = executionPayloadResult ;
462
469
return executionPayloadResult ;
463
470
});
471
+ // blinded
464
472
when (executionLayer .initiateBlockProduction (any (), any (), eq (true ), any (), any ()))
465
473
.thenAnswer (
466
474
args -> {
475
+ final BuilderBid builderBid =
476
+ SchemaDefinitionsBellatrix .required (spec .getGenesisSchemaDefinitions ())
477
+ .getBuilderBidSchema ()
478
+ .createBuilderBid (
479
+ builder -> {
480
+ builder .header (executionPayloadHeader );
481
+ builderBlobKzgCommitments .ifPresent (builder ::blobKzgCommitments );
482
+ builder .value (value );
483
+ builder .publicKey (BLSPublicKey .empty ());
484
+ });
467
485
final ExecutionPayloadResult executionPayloadResult =
468
- new ExecutionPayloadResult (
469
- args .getArgument (0 ),
470
- Optional .empty (),
471
- Optional .empty (),
472
- Optional .of (
473
- SafeFuture .completedFuture (
474
- HeaderWithFallbackData .create (executionPayloadHeader ))),
475
- Optional .empty ());
476
- cachedExecutionPayloadResult = executionPayloadResult ;
477
- return executionPayloadResult ;
478
- });
479
- // post Deneb
480
- when (executionLayer .initiateBlockAndBlobsProduction (any (), any (), eq (false ), any (), any ()))
481
- .thenAnswer (
482
- args -> {
483
- final ExecutionPayloadResult executionPayloadResult =
484
- new ExecutionPayloadResult (
485
- args .getArgument (0 ),
486
- Optional .of (SafeFuture .completedFuture (executionPayload )),
487
- Optional .of (SafeFuture .completedFuture (blobsBundle )),
488
- Optional .empty (),
489
- Optional .empty ());
490
- cachedExecutionPayloadResult = executionPayloadResult ;
491
- return executionPayloadResult ;
492
- });
493
- when (executionLayer .initiateBlockAndBlobsProduction (any (), any (), eq (true ), any (), any ()))
494
- .thenAnswer (
495
- args -> {
496
- final ExecutionPayloadResult executionPayloadResult =
497
- new ExecutionPayloadResult (
486
+ ExecutionPayloadResult .createForBuilderFlow (
498
487
args .getArgument (0 ),
499
- Optional .empty (),
500
- Optional .empty (),
501
- Optional .of (
502
- SafeFuture .completedFuture (
503
- HeaderWithFallbackData .create (
504
- executionPayloadHeader , builderBlobKzgCommitments ))),
505
- Optional .empty ());
488
+ SafeFuture .completedFuture (BuilderBidOrFallbackData .create (builderBid )));
506
489
cachedExecutionPayloadResult = executionPayloadResult ;
507
490
return executionPayloadResult ;
508
491
});
0 commit comments