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.
Add DAS Ssz data structures and config constants (#12)
* Add KZG prefixes to all struct in the 'kzg' package to avoid further ambiguity * Add DAS Ssz data structures and config constants
- Loading branch information
1 parent
008ab85
commit 220d422
Showing
23 changed files
with
525 additions
and
56 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
33 changes: 33 additions & 0 deletions
33
...spec/src/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/electra/Cell.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,33 @@ | ||
/* | ||
* 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.spec.datastructures.blobs.versions.electra; | ||
|
||
import org.apache.tuweni.bytes.Bytes; | ||
import tech.pegasys.teku.infrastructure.ssz.collections.impl.SszByteVectorImpl; | ||
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; | ||
|
||
public class Cell extends SszByteVectorImpl { | ||
|
||
Cell(final CellSchema schema, final TreeNode backingNode) { | ||
super(schema, backingNode); | ||
} | ||
|
||
Cell(final CellSchema cellSchema, final Bytes bytes) { | ||
super(cellSchema, bytes); | ||
} | ||
|
||
public String toBriefString() { | ||
return getBytes().slice(0, 7).toUnprefixedHexString(); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...rc/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/electra/CellSchema.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,23 @@ | ||
package tech.pegasys.teku.spec.datastructures.blobs.versions.electra; | ||
|
||
import org.apache.tuweni.bytes.Bytes; | ||
import tech.pegasys.teku.infrastructure.ssz.schema.collections.impl.SszByteVectorSchemaImpl; | ||
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; | ||
import tech.pegasys.teku.spec.config.SpecConfigDeneb; | ||
import tech.pegasys.teku.spec.config.SpecConfigElectra; | ||
|
||
public class CellSchema extends SszByteVectorSchemaImpl<Cell> { | ||
|
||
public CellSchema(final SpecConfigElectra specConfig) { | ||
super(SpecConfigDeneb.BYTES_PER_FIELD_ELEMENT.longValue() * specConfig.getFieldElementsPerCell().longValue()); | ||
} | ||
|
||
public Cell create(final Bytes bytes) { | ||
return new Cell(this, bytes); | ||
} | ||
|
||
@Override | ||
public Cell createFromBackingNode(TreeNode node) { | ||
return new Cell(this, node); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...rc/main/java/tech/pegasys/teku/spec/datastructures/blobs/versions/electra/DataColumn.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,29 @@ | ||
/* | ||
* 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.spec.datastructures.blobs.versions.electra; | ||
|
||
import tech.pegasys.teku.infrastructure.ssz.SszList; | ||
import tech.pegasys.teku.infrastructure.ssz.impl.SszListImpl; | ||
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; | ||
|
||
public class DataColumn extends SszListImpl<Cell> implements SszList<Cell> { | ||
|
||
DataColumn(DataColumnSchema schema, TreeNode node) { | ||
super(schema, node); | ||
} | ||
|
||
public String toBriefString() { | ||
return isEmpty() ? "" : get(0).toBriefString(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...n/java/tech/pegasys/teku/spec/datastructures/blobs/versions/electra/DataColumnSchema.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,18 @@ | ||
package tech.pegasys.teku.spec.datastructures.blobs.versions.electra; | ||
|
||
import tech.pegasys.teku.infrastructure.ssz.schema.impl.AbstractSszListSchema; | ||
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; | ||
import tech.pegasys.teku.spec.config.SpecConfigElectra; | ||
|
||
public class DataColumnSchema | ||
extends AbstractSszListSchema<Cell, DataColumn> { | ||
|
||
public DataColumnSchema(final SpecConfigElectra specConfig) { | ||
super(new CellSchema(specConfig), specConfig.getMaxBlobCommitmentsPerBlock()); | ||
} | ||
|
||
@Override | ||
public DataColumn createFromBackingNode(TreeNode node) { | ||
return new DataColumn(this, node); | ||
} | ||
} |
131 changes: 131 additions & 0 deletions
131
.../java/tech/pegasys/teku/spec/datastructures/blobs/versions/electra/DataColumnSidecar.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,131 @@ | ||
/* | ||
* 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.spec.datastructures.blobs.versions.electra; | ||
|
||
import org.apache.tuweni.bytes.Bytes32; | ||
import tech.pegasys.teku.infrastructure.logging.LogFormatter; | ||
import tech.pegasys.teku.infrastructure.ssz.SszList; | ||
import tech.pegasys.teku.infrastructure.ssz.collections.SszBytes32Vector; | ||
import tech.pegasys.teku.infrastructure.ssz.containers.Container6; | ||
import tech.pegasys.teku.infrastructure.ssz.primitive.SszUInt64; | ||
import tech.pegasys.teku.infrastructure.ssz.tree.TreeNode; | ||
import tech.pegasys.teku.infrastructure.unsigned.UInt64; | ||
import tech.pegasys.teku.kzg.KZGProof; | ||
import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader; | ||
import tech.pegasys.teku.spec.datastructures.blocks.SlotAndBlockRoot; | ||
import tech.pegasys.teku.spec.datastructures.type.SszKZGCommitment; | ||
import tech.pegasys.teku.spec.datastructures.type.SszKZGProof; | ||
|
||
public class DataColumnSidecar | ||
extends Container6< | ||
DataColumnSidecar, | ||
SszUInt64, | ||
DataColumn, | ||
SszList<SszKZGCommitment>, | ||
SszList<SszKZGProof>, | ||
SignedBeaconBlockHeader, | ||
SszBytes32Vector> { | ||
|
||
DataColumnSidecar(final DataColumnSidecarSchema dataColumnSidecarSchema, final TreeNode backingTreeNode) { | ||
super(dataColumnSidecarSchema, backingTreeNode); | ||
} | ||
|
||
// public DataColumnSidecar( | ||
// final DataColumnSidecarSchema schema, | ||
// final UInt64 index, | ||
// final Blob blob, | ||
// final SszKZGCommitment sszKzgCommitment, | ||
// final SszKZGProof sszKzgProof, | ||
// final SignedBeaconBlockHeader signedBeaconBlockHeader, | ||
// final List<Bytes32> kzgCommitmentInclusionProof) { | ||
// super( | ||
// schema, | ||
// SszUInt64.of(index), | ||
// schema.getDataColumnSszSchema().create(blob.getBytes()), | ||
// sszKzgCommitment, | ||
// sszKzgProof, | ||
// signedBeaconBlockHeader, | ||
// schema | ||
// .getKzgCommitmentInclusionProofSchema() | ||
// .createFromElements(kzgCommitmentInclusionProof.stream().map(SszBytes32::of).toList())); | ||
// } | ||
// | ||
// public DataColumnSidecar( | ||
// final DataColumnSidecarSchema schema, | ||
// final UInt64 index, | ||
// final Blob blob, | ||
// final KZGCommitment kzgCommitment, | ||
// final KZGProof kzgProof, | ||
// final SignedBeaconBlockHeader signedBeaconBlockHeader, | ||
// final List<Bytes32> kzgCommitmentInclusionProof) { | ||
// this( | ||
// schema, | ||
// index, | ||
// blob, | ||
// new SszKZGCommitment(kzgCommitment), | ||
// new SszKZGProof(kzgProof), | ||
// signedBeaconBlockHeader, | ||
// kzgCommitmentInclusionProof); | ||
// } | ||
|
||
public UInt64 getIndex() { | ||
return getField0().get(); | ||
} | ||
|
||
public DataColumn getDataColumn() { | ||
return getField1(); | ||
} | ||
|
||
public SszList<SszKZGCommitment> getSszKZGCommitments() { | ||
return getField2(); | ||
} | ||
|
||
public SszList<SszKZGProof> getSszKZGProofs() { | ||
return getField3(); | ||
} | ||
|
||
public SignedBeaconBlockHeader getSignedBeaconBlockHeader() { | ||
return getField4(); | ||
} | ||
|
||
public SszBytes32Vector getKzgCommitmentInclusionProof() { | ||
return getField5(); | ||
} | ||
|
||
public UInt64 getSlot() { | ||
return getSignedBeaconBlockHeader().getMessage().getSlot(); | ||
} | ||
|
||
public Bytes32 getBlockBodyRoot() { | ||
return getSignedBeaconBlockHeader().getMessage().getBodyRoot(); | ||
} | ||
|
||
public Bytes32 getBlockRoot() { | ||
return getSignedBeaconBlockHeader().getMessage().getRoot(); | ||
} | ||
|
||
public SlotAndBlockRoot getSlotAndBlockRoot() { | ||
return new SlotAndBlockRoot(getSlot(), getBlockRoot()); | ||
} | ||
|
||
public String toLogString() { | ||
return LogFormatter.formatBlobSidecar( | ||
getSlot(), | ||
getBlockRoot(), | ||
getIndex(), | ||
getDataColumn().toBriefString(), | ||
"" + getSszKZGCommitments().size(), | ||
"" + getSszKZGProofs().size()); | ||
} | ||
} |
Oops, something went wrong.