Skip to content

Commit

Permalink
Merge branch 'master' into merge_beacon_apis
Browse files Browse the repository at this point in the history
  • Loading branch information
tbenr authored Nov 4, 2021
2 parents c868851 + 2ff9474 commit 8c79eac
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ static BeaconBlockBodySchemaMergeImpl create(final SpecConfigMerge specConfig) {
BlockBodyFields.SYNC_AGGREGATE.name(),
SyncAggregateSchema.create(specConfig.getSyncCommitteeSize())),
namedSchema(
BlockBodyFields.EXECUTION_PAYLOAD.name(), ExecutionPayloadSchema.create(specConfig)));
BlockBodyFields.EXECUTION_PAYLOAD.name(), new ExecutionPayloadSchema(specConfig)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,7 @@ public class ExecutionPayloadSchema
SszBytes32,
SszList<Transaction>> {

private final TransactionSchema transactionSchema;

private ExecutionPayloadSchema(
final SpecConfigMerge specConfig, final TransactionSchema transactionSchema) {
public ExecutionPayloadSchema(final SpecConfigMerge specConfig) {
super(
"ExecutionPayload",
namedSchema("parent_hash", SszPrimitiveSchemas.BYTES32_SCHEMA),
Expand All @@ -72,13 +69,8 @@ private ExecutionPayloadSchema(
namedSchema("block_hash", SszPrimitiveSchemas.BYTES32_SCHEMA),
namedSchema(
"transactions",
SszListSchema.create(transactionSchema, specConfig.getMaxTransactionsPerPayload())));
this.transactionSchema = transactionSchema;
}

public static ExecutionPayloadSchema create(final SpecConfigMerge specConfig) {
final TransactionSchema transactionSchema = new TransactionSchema(specConfig);
return new ExecutionPayloadSchema(specConfig, transactionSchema);
SszListSchema.create(
new TransactionSchema(specConfig), specConfig.getMaxTransactionsPerPayload())));
}

public ExecutionPayload create(
Expand Down Expand Up @@ -112,11 +104,15 @@ public ExecutionPayload create(
SszUInt256.of(baseFeePerGas),
SszBytes32.of(blockHash),
transactions.stream()
.map(txBytes -> transactionSchema.getOpaqueTransactionSchema().fromBytes(txBytes))
.map(transactionSchema::createOpaque)
.map(getTransactionSchema()::fromBytes)
.collect(getTransactionsSchema().collector()));
}

@SuppressWarnings("unchecked")
private TransactionSchema getTransactionSchema() {
return (TransactionSchema) getTransactionsSchema().getElementSchema();
}

@SuppressWarnings("unchecked")
public SszListSchema<Transaction, ?> getTransactionsSchema() {
return (SszListSchema<Transaction, ?>) getFieldSchema13();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,12 @@

package tech.pegasys.teku.spec.datastructures.execution;

import static com.google.common.base.Preconditions.checkState;

import tech.pegasys.teku.ssz.collections.SszByteList;
import tech.pegasys.teku.ssz.impl.SszUnionImpl;
import tech.pegasys.teku.ssz.collections.impl.SszByteListImpl;
import tech.pegasys.teku.ssz.tree.TreeNode;

public class Transaction extends SszUnionImpl {
public static final int OPAQUE_TRANSACTION_SELECTOR = 0;
public class Transaction extends SszByteListImpl {

Transaction(TransactionSchema schema, TreeNode backingNode) {
super(schema, backingNode);
}

public SszByteList getOpaqueTransaction() {
checkState(getSelector() == OPAQUE_TRANSACTION_SELECTOR);
return (SszByteList) getValue();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,14 @@

package tech.pegasys.teku.spec.datastructures.execution;

import java.util.List;
import tech.pegasys.teku.spec.config.SpecConfigMerge;
import tech.pegasys.teku.ssz.collections.SszByteList;
import tech.pegasys.teku.ssz.schema.collections.SszByteListSchema;
import tech.pegasys.teku.ssz.schema.impl.SszUnionSchemaImpl;
import tech.pegasys.teku.ssz.schema.collections.impl.SszByteListSchemaImpl;
import tech.pegasys.teku.ssz.tree.TreeNode;

public class TransactionSchema extends SszUnionSchemaImpl<Transaction> {
public class TransactionSchema extends SszByteListSchemaImpl<Transaction> {

public TransactionSchema(final SpecConfigMerge specConfig) {
super(List.of(SszByteListSchema.create(specConfig.getMaxBytesPerTransaction())));
}

public Transaction createOpaque(SszByteList bytes) {
return createFromValue(Transaction.OPAQUE_TRANSACTION_SELECTOR, bytes);
}

@SuppressWarnings("unchecked")
public SszByteListSchema<?> getOpaqueTransactionSchema() {
return (SszByteListSchema<?>) getChildSchema(Transaction.OPAQUE_TRANSACTION_SELECTOR);
super(specConfig.getMaxBytesPerTransaction());
}

@Override
Expand Down

0 comments on commit 8c79eac

Please sign in to comment.