forked from Consensys/teku
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
try another approach for blind/unblind
- Loading branch information
1 parent
1afa6e1
commit 21b2421
Showing
22 changed files
with
853 additions
and
57 deletions.
There are no files selected for viewing
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
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
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
143 changes: 143 additions & 0 deletions
143
...zer/src/main/java/tech/pegasys/teku/api/schema/eip7732/BlindedBeaconBlockBodyEip7732.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,143 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2022 | ||
* | ||
* 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.api.schema.eip7732; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import java.util.List; | ||
import org.apache.tuweni.bytes.Bytes32; | ||
import tech.pegasys.teku.api.schema.Attestation; | ||
import tech.pegasys.teku.api.schema.AttesterSlashing; | ||
import tech.pegasys.teku.api.schema.BLSSignature; | ||
import tech.pegasys.teku.api.schema.Deposit; | ||
import tech.pegasys.teku.api.schema.Eth1Data; | ||
import tech.pegasys.teku.api.schema.ProposerSlashing; | ||
import tech.pegasys.teku.api.schema.SignedVoluntaryExit; | ||
import tech.pegasys.teku.api.schema.altair.BeaconBlockBodyAltair; | ||
import tech.pegasys.teku.api.schema.altair.SyncAggregate; | ||
import tech.pegasys.teku.api.schema.capella.SignedBlsToExecutionChange; | ||
import tech.pegasys.teku.infrastructure.async.SafeFuture; | ||
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema; | ||
import tech.pegasys.teku.spec.SpecVersion; | ||
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody; | ||
import tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.eip7732.BeaconBlockBodySchemaEip7732; | ||
|
||
public class BlindedBeaconBlockBodyEip7732 extends BeaconBlockBodyAltair { | ||
|
||
@JsonProperty("bls_to_execution_changes") | ||
public final List<SignedBlsToExecutionChange> blsToExecutionChanges; | ||
|
||
@JsonProperty("signed_execution_payload_header") | ||
public final SignedExecutionPayloadHeader signedExecutionPayloadHeader; | ||
|
||
@JsonProperty("payload_attestations") | ||
public final List<PayloadAttestation> payloadAttestations; | ||
|
||
@JsonCreator | ||
public BlindedBeaconBlockBodyEip7732( | ||
@JsonProperty("randao_reveal") final BLSSignature randaoReveal, | ||
@JsonProperty("eth1_data") final Eth1Data eth1Data, | ||
@JsonProperty("graffiti") final Bytes32 graffiti, | ||
@JsonProperty("proposer_slashings") final List<ProposerSlashing> proposerSlashings, | ||
@JsonProperty("attester_slashings") final List<AttesterSlashing> attesterSlashings, | ||
@JsonProperty("attestations") final List<Attestation> attestations, | ||
@JsonProperty("deposits") final List<Deposit> deposits, | ||
@JsonProperty("voluntary_exits") final List<SignedVoluntaryExit> voluntaryExits, | ||
@JsonProperty("sync_aggregate") final SyncAggregate syncAggregate, | ||
@JsonProperty("bls_to_execution_changes") | ||
final List<SignedBlsToExecutionChange> blsToExecutionChanges, | ||
@JsonProperty("signed_execution_payload_header") | ||
final SignedExecutionPayloadHeader signedExecutionPayloadHeader, | ||
@JsonProperty("payload_attestations") final List<PayloadAttestation> payloadAttestations) { | ||
super( | ||
randaoReveal, | ||
eth1Data, | ||
graffiti, | ||
proposerSlashings, | ||
attesterSlashings, | ||
attestations, | ||
deposits, | ||
voluntaryExits, | ||
syncAggregate); | ||
checkNotNull(blsToExecutionChanges, "BlsToExecutionChanges is required for Eip7732 blocks"); | ||
this.blsToExecutionChanges = blsToExecutionChanges; | ||
checkNotNull( | ||
signedExecutionPayloadHeader, | ||
"SignedExecutionPayloadHeader is required for Eip7732 blocks"); | ||
this.signedExecutionPayloadHeader = signedExecutionPayloadHeader; | ||
checkNotNull(payloadAttestations, "PayloadAttestations is required for Eip7732 blocks"); | ||
this.payloadAttestations = payloadAttestations; | ||
} | ||
|
||
public BlindedBeaconBlockBodyEip7732( | ||
final tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.eip7732 | ||
.BlindedBeaconBlockBodyEip7732 | ||
message) { | ||
super(message); | ||
checkNotNull( | ||
message.getBlsToExecutionChanges(), | ||
"BlsToExecutionChanges are required for Eip7732 blocks"); | ||
this.blsToExecutionChanges = | ||
message.getBlsToExecutionChanges().stream().map(SignedBlsToExecutionChange::new).toList(); | ||
checkNotNull( | ||
message.getSignedExecutionPayloadHeader(), | ||
"SignedExecutionPayloadHeader are required for Eip7732 blocks"); | ||
this.signedExecutionPayloadHeader = | ||
new SignedExecutionPayloadHeader(message.getSignedExecutionPayloadHeader()); | ||
checkNotNull( | ||
message.getPayloadAttestations(), "PayloadAttestations are required for Eip7732 blocks"); | ||
this.payloadAttestations = | ||
message.getPayloadAttestations().stream().map(PayloadAttestation::new).toList(); | ||
} | ||
|
||
@Override | ||
public BeaconBlockBodySchemaEip7732<?> getBeaconBlockBodySchema(final SpecVersion spec) { | ||
return (BeaconBlockBodySchemaEip7732<?>) | ||
spec.getSchemaDefinitions().getBlindedBeaconBlockBodySchema(); | ||
} | ||
|
||
@Override | ||
public boolean isBlinded() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public BeaconBlockBody asInternalBeaconBlockBody(final SpecVersion spec) { | ||
final SszListSchema< | ||
tech.pegasys.teku.spec.datastructures.operations.SignedBlsToExecutionChange, ?> | ||
blsToExecutionChangesSchema = | ||
getBeaconBlockBodySchema(spec).getBlsToExecutionChangesSchema(); | ||
return super.asInternalBeaconBlockBody( | ||
spec, | ||
builder -> { | ||
builder.blsToExecutionChanges( | ||
this.blsToExecutionChanges.stream() | ||
.map(b -> b.asInternalSignedBlsToExecutionChange(spec)) | ||
.collect(blsToExecutionChangesSchema.collector())); | ||
builder.signedExecutionPayloadHeader( | ||
signedExecutionPayloadHeader.asInternalSignedExecutionPayloadHeader(spec)); | ||
final SszListSchema< | ||
tech.pegasys.teku.spec.datastructures.operations.PayloadAttestation, ?> | ||
payloadAttestationsSchema = | ||
getBeaconBlockBodySchema(spec).getPayloadAttestationsSchema(); | ||
builder.payloadAttestations( | ||
this.payloadAttestations.stream() | ||
.map(pa -> pa.asInternalPayloadAttestation(spec)) | ||
.collect(payloadAttestationsSchema.collector())); | ||
return SafeFuture.COMPLETE; | ||
}); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
data/serializer/src/main/java/tech/pegasys/teku/api/schema/eip7732/BlindedBlockEip7732.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,70 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2022 | ||
* | ||
* 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.api.schema.eip7732; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import org.apache.tuweni.bytes.Bytes32; | ||
import tech.pegasys.teku.api.schema.altair.BeaconBlockAltair; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
import tech.pegasys.teku.spec.Spec; | ||
import tech.pegasys.teku.spec.SpecVersion; | ||
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlock; | ||
import tech.pegasys.teku.spec.datastructures.blocks.BeaconBlockSchema; | ||
|
||
public class BlindedBlockEip7732 extends BeaconBlockAltair { | ||
|
||
public BlindedBlockEip7732(final BeaconBlock message) { | ||
super( | ||
message.getSlot(), | ||
message.getProposerIndex(), | ||
message.getParentRoot(), | ||
message.getStateRoot(), | ||
new BlindedBeaconBlockBodyEip7732( | ||
message.getBody().toBlindedVersionEip7732().orElseThrow())); | ||
} | ||
|
||
@Override | ||
public BeaconBlockSchema getBeaconBlockSchema(final SpecVersion spec) { | ||
return spec.getSchemaDefinitions().getBlindedBeaconBlockSchema(); | ||
} | ||
|
||
@Override | ||
public BeaconBlock asInternalBeaconBlock(final Spec spec) { | ||
final SpecVersion specVersion = spec.atSlot(slot); | ||
return getBeaconBlockSchema(specVersion) | ||
.create( | ||
slot, | ||
proposer_index, | ||
parent_root, | ||
state_root, | ||
body.asInternalBeaconBlockBody(specVersion)); | ||
} | ||
|
||
@JsonProperty("body") | ||
@Override | ||
public BlindedBeaconBlockBodyEip7732 getBody() { | ||
return (BlindedBeaconBlockBodyEip7732) body; | ||
} | ||
|
||
@JsonCreator | ||
public BlindedBlockEip7732( | ||
@JsonProperty("slot") final UInt64 slot, | ||
@JsonProperty("proposer_index") final UInt64 proposerIndex, | ||
@JsonProperty("parent_root") final Bytes32 parentRoot, | ||
@JsonProperty("state_root") final Bytes32 stateRoot, | ||
@JsonProperty("body") final BlindedBeaconBlockBodyEip7732 body) { | ||
super(slot, proposerIndex, parentRoot, stateRoot, body); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...r/src/main/java/tech/pegasys/teku/api/schema/eip7732/SignedBlindedBeaconBlockEip7732.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,47 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2022 | ||
* | ||
* 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.api.schema.eip7732; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import tech.pegasys.teku.api.schema.BLSSignature; | ||
import tech.pegasys.teku.api.schema.SignedBeaconBlock; | ||
import tech.pegasys.teku.api.schema.interfaces.SignedBlock; | ||
|
||
public class SignedBlindedBeaconBlockEip7732 extends SignedBeaconBlock implements SignedBlock { | ||
private final BlindedBlockEip7732 message; | ||
|
||
public SignedBlindedBeaconBlockEip7732( | ||
final tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlock internalBlock) { | ||
super(internalBlock); | ||
checkArgument( | ||
internalBlock.getMessage().getBody().isBlinded(), "requires a signed blinded beacon block"); | ||
this.message = new BlindedBlockEip7732(internalBlock.getMessage()); | ||
} | ||
|
||
@Override | ||
public BlindedBlockEip7732 getMessage() { | ||
return message; | ||
} | ||
|
||
@JsonCreator | ||
public SignedBlindedBeaconBlockEip7732( | ||
@JsonProperty("message") final BlindedBlockEip7732 message, | ||
@JsonProperty("signature") final BLSSignature signature) { | ||
super(message, signature); | ||
this.message = message; | ||
} | ||
} |
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
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
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.