-
Notifications
You must be signed in to change notification settings - Fork 304
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Decoupling] Implement
BlockFactoryDeneb
(part 2) (#7161)
- Loading branch information
1 parent
021e33d
commit 87d7095
Showing
29 changed files
with
967 additions
and
397 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
...validator/src/main/java/tech/pegasys/teku/validator/coordinator/AbstractBlockFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright ConsenSys Software Inc., 2023 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.teku.validator.coordinator; | ||
|
||
import tech.pegasys.teku.infrastructure.async.SafeFuture; | ||
import tech.pegasys.teku.spec.Spec; | ||
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock; | ||
|
||
public abstract class AbstractBlockFactory implements BlockFactory { | ||
|
||
protected final Spec spec; | ||
protected final BlockOperationSelectorFactory operationSelector; | ||
|
||
protected AbstractBlockFactory( | ||
final Spec spec, final BlockOperationSelectorFactory operationSelector) { | ||
this.spec = spec; | ||
this.operationSelector = operationSelector; | ||
} | ||
|
||
@Override | ||
public SafeFuture<SignedBeaconBlock> unblindSignedBeaconBlockIfBlinded( | ||
final SignedBeaconBlock blindedSignedBeaconBlock) { | ||
if (blindedSignedBeaconBlock.isBlinded()) { | ||
return spec.unblindSignedBeaconBlock( | ||
blindedSignedBeaconBlock, operationSelector.createUnblinderSelector()); | ||
} | ||
return SafeFuture.completedFuture(blindedSignedBeaconBlock); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
...on/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactoryDeneb.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright ConsenSys Software Inc., 2023 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.teku.validator.coordinator; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import org.apache.tuweni.bytes.Bytes32; | ||
import tech.pegasys.teku.bls.BLSSignature; | ||
import tech.pegasys.teku.infrastructure.async.SafeFuture; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
import tech.pegasys.teku.spec.Spec; | ||
import tech.pegasys.teku.spec.SpecMilestone; | ||
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlindedBlobSidecar; | ||
import tech.pegasys.teku.spec.datastructures.blobs.versions.deneb.BlobSidecar; | ||
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock; | ||
import tech.pegasys.teku.spec.datastructures.blocks.BlockContainer; | ||
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.BlindedBlockContents; | ||
import tech.pegasys.teku.spec.datastructures.blocks.versions.deneb.BlockContents; | ||
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; | ||
import tech.pegasys.teku.spec.schemas.SchemaDefinitionsDeneb; | ||
|
||
public class BlockFactoryDeneb extends BlockFactoryPhase0 { | ||
|
||
private final SchemaDefinitionsDeneb schemaDefinitionsDeneb; | ||
|
||
public BlockFactoryDeneb(final Spec spec, final BlockOperationSelectorFactory operationSelector) { | ||
super(spec, operationSelector); | ||
this.schemaDefinitionsDeneb = | ||
SchemaDefinitionsDeneb.required( | ||
spec.forMilestone(SpecMilestone.DENEB).getSchemaDefinitions()); | ||
} | ||
|
||
@Override | ||
public SafeFuture<BlockContainer> createUnsignedBlock( | ||
final BeaconState blockSlotState, | ||
final UInt64 newSlot, | ||
final BLSSignature randaoReveal, | ||
final Optional<Bytes32> optionalGraffiti, | ||
final boolean blinded) { | ||
return super.createUnsignedBlock( | ||
blockSlotState, newSlot, randaoReveal, optionalGraffiti, blinded) | ||
.thenApply(BlockContainer::getBlock) | ||
.thenCompose( | ||
block -> { | ||
if (block.isBlinded()) { | ||
return operationSelector | ||
.createBlindedBlobSidecarsSelector() | ||
.apply(block) | ||
.thenApply( | ||
blindedBlobSidecars -> | ||
createBlindedBlockContents(block, blindedBlobSidecars)); | ||
} | ||
return operationSelector | ||
.createBlobSidecarsSelector() | ||
.apply(block) | ||
.thenApply(blobSidecars -> createBlockContents(block, blobSidecars)); | ||
}); | ||
} | ||
|
||
private BlockContents createBlockContents( | ||
final BeaconBlock block, final List<BlobSidecar> blobSidecars) { | ||
return schemaDefinitionsDeneb.getBlockContentsSchema().create(block, blobSidecars); | ||
} | ||
|
||
private BlindedBlockContents createBlindedBlockContents( | ||
final BeaconBlock block, final List<BlindedBlobSidecar> blindedBlobSidecars) { | ||
return schemaDefinitionsDeneb | ||
.getBlindedBlockContentsSchema() | ||
.create(block, blindedBlobSidecars); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...n/validator/src/main/java/tech/pegasys/teku/validator/coordinator/BlockFactoryPhase0.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright ConsenSys Software Inc., 2023 | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package tech.pegasys.teku.validator.coordinator; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
import java.util.Optional; | ||
import org.apache.tuweni.bytes.Bytes32; | ||
import tech.pegasys.teku.bls.BLSSignature; | ||
import tech.pegasys.teku.infrastructure.async.SafeFuture; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
import tech.pegasys.teku.spec.Spec; | ||
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockAndState; | ||
import tech.pegasys.teku.spec.datastructures.blocks.BlockContainer; | ||
import tech.pegasys.teku.spec.datastructures.state.beaconstate.BeaconState; | ||
|
||
public class BlockFactoryPhase0 extends AbstractBlockFactory { | ||
|
||
public BlockFactoryPhase0( | ||
final Spec spec, final BlockOperationSelectorFactory operationSelector) { | ||
super(spec, operationSelector); | ||
} | ||
|
||
@Override | ||
public SafeFuture<BlockContainer> createUnsignedBlock( | ||
final BeaconState blockSlotState, | ||
final UInt64 newSlot, | ||
final BLSSignature randaoReveal, | ||
final Optional<Bytes32> optionalGraffiti, | ||
final boolean blinded) { | ||
checkArgument( | ||
blockSlotState.getSlot().equals(newSlot), | ||
"Block slot state for slot %s but should be for slot %s", | ||
blockSlotState.getSlot(), | ||
newSlot); | ||
|
||
// Process empty slots up to the one before the new block slot | ||
final UInt64 slotBeforeBlock = newSlot.minus(UInt64.ONE); | ||
|
||
final Bytes32 parentRoot = spec.getBlockRootAtSlot(blockSlotState, slotBeforeBlock); | ||
|
||
return spec.createNewUnsignedBlock( | ||
newSlot, | ||
spec.getBeaconProposerIndex(blockSlotState, newSlot), | ||
blockSlotState, | ||
parentRoot, | ||
operationSelector.createSelector( | ||
parentRoot, blockSlotState, randaoReveal, optionalGraffiti), | ||
blinded) | ||
.thenApply(BeaconBlockAndState::getBlock); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.