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.
Merge pull request #8 from mehdi-aouadi/8026-1-containers
add electra attestation container
- Loading branch information
Showing
9 changed files
with
320 additions
and
3 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
32 changes: 32 additions & 0 deletions
32
.../src/main/java/tech/pegasys/teku/spec/datastructures/operations/AttestationContainer.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,32 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2024 | ||
* | ||
* 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.spec.datastructures.operations; | ||
|
||
import java.util.Collection; | ||
import org.apache.tuweni.bytes.Bytes32; | ||
import tech.pegasys.teku.bls.BLSSignature; | ||
import tech.pegasys.teku.infrastructure.ssz.SszContainer; | ||
import tech.pegasys.teku.infrastructure.ssz.SszData; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
import tech.pegasys.teku.spec.Spec; | ||
|
||
public interface AttestationContainer extends SszData, SszContainer { | ||
AttestationData getData(); | ||
|
||
BLSSignature getAggregateSignature(); | ||
|
||
UInt64 getEarliestSlotForForkChoiceProcessing(Spec spec); | ||
|
||
Collection<Bytes32> getDependentBlockRoots(); | ||
} |
25 changes: 25 additions & 0 deletions
25
...ain/java/tech/pegasys/teku/spec/datastructures/operations/AttestationContainerSchema.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,25 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2024 | ||
* | ||
* 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.spec.datastructures.operations; | ||
|
||
import tech.pegasys.teku.infrastructure.ssz.schema.SszContainerSchema; | ||
|
||
public interface AttestationContainerSchema<T extends AttestationContainer> | ||
extends SszContainerSchema<T> { | ||
|
||
@SuppressWarnings("unchecked") | ||
default AttestationContainerSchema<AttestationContainer> castTypeToAttestationContainer() { | ||
return (AttestationContainerSchema<AttestationContainer>) this; | ||
} | ||
} |
87 changes: 87 additions & 0 deletions
87
...tech/pegasys/teku/spec/datastructures/operations/versions/electra/AttestationElectra.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,87 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2024 | ||
* | ||
* 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.spec.datastructures.operations.versions.electra; | ||
|
||
import com.google.common.collect.Sets; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import org.apache.tuweni.bytes.Bytes32; | ||
import tech.pegasys.teku.bls.BLSSignature; | ||
import tech.pegasys.teku.infrastructure.ssz.SszList; | ||
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist; | ||
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector; | ||
import tech.pegasys.teku.infrastructure.ssz.containers.Container4; | ||
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
import tech.pegasys.teku.spec.Spec; | ||
import tech.pegasys.teku.spec.datastructures.operations.AttestationContainer; | ||
import tech.pegasys.teku.spec.datastructures.operations.AttestationData; | ||
import tech.pegasys.teku.spec.datastructures.type.SszSignature; | ||
|
||
public class AttestationElectra | ||
extends Container4< | ||
AttestationElectra, SszList<SszBitlist>, AttestationData, SszBitvector, SszSignature> | ||
implements AttestationContainer { | ||
|
||
public AttestationElectra(final AttestationElectraSchema type, final TreeNode backingNode) { | ||
super(type, backingNode); | ||
} | ||
|
||
public AttestationElectra( | ||
final AttestationElectraSchema schema, | ||
final SszList<SszBitlist> aggregationBits, | ||
final AttestationData data, | ||
final SszBitvector committeeBits, | ||
final BLSSignature signature) { | ||
super(schema, aggregationBits, data, committeeBits, new SszSignature(signature)); | ||
} | ||
|
||
@Override | ||
public AttestationElectraSchema getSchema() { | ||
return (AttestationElectraSchema) super.getSchema(); | ||
} | ||
|
||
public UInt64 getEarliestSlotForForkChoiceProcessing(final Spec spec) { | ||
return getData().getEarliestSlotForForkChoice(spec); | ||
} | ||
|
||
public Collection<Bytes32> getDependentBlockRoots() { | ||
return Sets.newHashSet(getData().getTarget().getRoot(), getData().getBeaconBlockRoot()); | ||
} | ||
|
||
public SszList<SszBitlist> getAggregationBits() { | ||
return getField0(); | ||
} | ||
|
||
public AttestationData getData() { | ||
return getField1(); | ||
} | ||
|
||
public SszBitvector getCommitteeBits() { | ||
return getField2(); | ||
} | ||
|
||
public BLSSignature getAggregateSignature() { | ||
return getField3().getSignature(); | ||
} | ||
|
||
public List<UInt64> getCommitteeIndices(AttestationElectra attestationElectra) { | ||
return attestationElectra | ||
.getCommitteeBits() | ||
.getAllSetBits() | ||
.intStream() | ||
.mapToObj(UInt64::valueOf) | ||
.toList(); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...egasys/teku/spec/datastructures/operations/versions/electra/AttestationElectraSchema.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,66 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2024 | ||
* | ||
* 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.spec.datastructures.operations.versions.electra; | ||
|
||
import tech.pegasys.teku.bls.BLSSignature; | ||
import tech.pegasys.teku.infrastructure.ssz.SszList; | ||
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitlist; | ||
import tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector; | ||
import tech.pegasys.teku.infrastructure.ssz.containers.ContainerSchema4; | ||
import tech.pegasys.teku.infrastructure.ssz.schema.SszListSchema; | ||
import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitlistSchema; | ||
import tech.pegasys.teku.infrastructure.ssz.schema.collections.SszBitvectorSchema; | ||
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; | ||
import tech.pegasys.teku.spec.config.SpecConfig; | ||
import tech.pegasys.teku.spec.datastructures.operations.AttestationContainerSchema; | ||
import tech.pegasys.teku.spec.datastructures.operations.AttestationData; | ||
import tech.pegasys.teku.spec.datastructures.type.SszSignature; | ||
import tech.pegasys.teku.spec.datastructures.type.SszSignatureSchema; | ||
|
||
public class AttestationElectraSchema | ||
extends ContainerSchema4< | ||
AttestationElectra, SszList<SszBitlist>, AttestationData, SszBitvector, SszSignature> | ||
implements AttestationContainerSchema<AttestationElectra> { | ||
|
||
public AttestationElectraSchema(final SpecConfig specConfig) { | ||
super( | ||
"Attestation", | ||
namedSchema( | ||
"aggregation_bits", | ||
SszListSchema.create( | ||
SszBitlistSchema.create(specConfig.getMaxValidatorsPerCommittee()), | ||
specConfig.getMaxCommitteesPerSlot())), | ||
namedSchema("data", AttestationData.SSZ_SCHEMA), | ||
namedSchema( | ||
"committee_bits", SszBitvectorSchema.create(specConfig.getMaxCommitteesPerSlot())), | ||
namedSchema("signature", SszSignatureSchema.INSTANCE)); | ||
} | ||
|
||
public SszListSchema<SszList<SszBitvector>, ?> getAggregationBitsSchema() { | ||
return (SszListSchema<SszList<SszBitvector>, ?>) getFieldSchema0(); | ||
} | ||
|
||
@Override | ||
public AttestationElectra createFromBackingNode(TreeNode node) { | ||
return new AttestationElectra(this, node); | ||
} | ||
|
||
public AttestationElectra create( | ||
final SszList<SszBitlist> aggregationBits, | ||
final AttestationData data, | ||
final SszBitvector committeeBits, | ||
final BLSSignature signature) { | ||
return new AttestationElectra(this, aggregationBits, data, committeeBits, signature); | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
.../teku/spec/datastructures/operations/versions/electra/AttestationElectraPropertyTest.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., 2024 | ||
* | ||
* 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.spec.datastructures.operations.versions.electra; | ||
|
||
import static tech.pegasys.teku.spec.propertytest.util.PropertyTestHelper.assertDeserializeMutatedThrowsExpected; | ||
import static tech.pegasys.teku.spec.propertytest.util.PropertyTestHelper.assertRoundTrip; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import net.jqwik.api.ForAll; | ||
import net.jqwik.api.Property; | ||
import tech.pegasys.teku.spec.propertytest.suppliers.operations.versions.electra.AttestationElectraSupplier; | ||
|
||
public class AttestationElectraPropertyTest { | ||
@Property | ||
void roundTrip( | ||
@ForAll(supplier = AttestationElectraSupplier.class) | ||
final AttestationElectra attestationElectra) | ||
throws JsonProcessingException { | ||
assertRoundTrip(attestationElectra); | ||
} | ||
|
||
@Property | ||
void deserializeMutated( | ||
@ForAll(supplier = AttestationElectraSupplier.class) | ||
final AttestationElectra attestationElectra, | ||
@ForAll final int seed) { | ||
assertDeserializeMutatedThrowsExpected(attestationElectra, seed); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...u/spec/propertytest/suppliers/operations/versions/electra/AttestationElectraSupplier.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,25 @@ | ||
/* | ||
* Copyright Consensys Software Inc., 2024 | ||
* | ||
* 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.spec.propertytest.suppliers.operations.versions.electra; | ||
|
||
import tech.pegasys.teku.spec.SpecMilestone; | ||
import tech.pegasys.teku.spec.datastructures.operations.versions.electra.AttestationElectra; | ||
import tech.pegasys.teku.spec.propertytest.suppliers.DataStructureUtilSupplier; | ||
import tech.pegasys.teku.spec.util.DataStructureUtil; | ||
|
||
public class AttestationElectraSupplier extends DataStructureUtilSupplier<AttestationElectra> { | ||
public AttestationElectraSupplier() { | ||
super(DataStructureUtil::randomAttestationElectra, SpecMilestone.ELECTRA); | ||
} | ||
} |
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