Skip to content

Commit

Permalink
some refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Dec 20, 2023
1 parent 706daca commit e6396f8
Showing 1 changed file with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,23 +219,9 @@ public SafeFuture<Optional<PayloadBuildingAttributes>> calculatePayloadBuildingA
calculatePayloadBuildingAttributes(
currentHeadBlockRoot, blockSlot, epoch, maybeState, mandatory);
payloadBuildingAttributes.ifPresent(
payloadAttributes -> {
// TODO: not sure about this
final UInt64 parentExecutionBlockNumber =
maybeState
.flatMap(BeaconState::toVersionBellatrix)
.map(BeaconStateBellatrix::getLatestExecutionPayloadHeader)
.map(ExecutionPayloadSummary::getBlockNumber)
.orElse(UInt64.ZERO);
final Bytes32 parentExecutionBlockHash =
forkChoiceUpdateData.getForkChoiceState().getHeadExecutionBlockHash();
newBlockBuildingSubscribers.forEach(
subscriber ->
subscriber.onNewBlockBuilding(
parentExecutionBlockNumber,
parentExecutionBlockHash,
payloadAttributes));
});
payloadAttributes ->
notifyNewBlockBuildingSubscribers(
maybeState, forkChoiceUpdateData, payloadAttributes));
return payloadBuildingAttributes;
},
eventThread);
Expand Down Expand Up @@ -278,6 +264,25 @@ private Optional<PayloadBuildingAttributes> calculatePayloadBuildingAttributes(
currentHeadBlockRoot));
}

private void notifyNewBlockBuildingSubscribers(
final Optional<BeaconState> maybeState,
final ForkChoiceUpdateData forkChoiceUpdateData,
final PayloadBuildingAttributes payloadAttributes) {
// TODO: more clean to get from ForkChoiceUpdateData but not available yet
final UInt64 parentExecutionBlockNumber =
maybeState
.flatMap(BeaconState::toVersionBellatrix)
.map(BeaconStateBellatrix::getLatestExecutionPayloadHeader)
.map(ExecutionPayloadSummary::getBlockNumber)
.orElse(UInt64.ZERO);
final Bytes32 parentExecutionBlockHash =
forkChoiceUpdateData.getForkChoiceState().getHeadExecutionBlockHash();
newBlockBuildingSubscribers.forEach(
subscriber ->
subscriber.onNewBlockBuilding(
parentExecutionBlockNumber, parentExecutionBlockHash, payloadAttributes));
}

// this function MUST return a fee recipient.
private Eth1Address getFeeRecipient(
final PreparedProposerInfo preparedProposerInfo, final UInt64 blockSlot) {
Expand Down

0 comments on commit e6396f8

Please sign in to comment.