Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NO MERGE] Verkle trees #7890

Draft
wants to merge 21 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
In the middle of moving Verkle Trees to Electra which is pre-Deneb
zilm13 committed Jan 21, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 2780b8fdf1e865acf9d7a563dc15b910192e3eca
Original file line number Diff line number Diff line change
@@ -36,6 +36,11 @@
import tech.pegasys.teku.api.schema.deneb.BeaconStateDeneb;
import tech.pegasys.teku.api.schema.deneb.BlindedBeaconBlockBodyDeneb;
import tech.pegasys.teku.api.schema.deneb.BlindedBlockDeneb;
import tech.pegasys.teku.api.schema.electra.BeaconBlockBodyElectra;
import tech.pegasys.teku.api.schema.electra.BeaconBlockElectra;
import tech.pegasys.teku.api.schema.electra.BeaconStateElectra;
import tech.pegasys.teku.api.schema.electra.BlindedBeaconBlockBodyElectra;
import tech.pegasys.teku.api.schema.electra.BlindedBlockElectra;
import tech.pegasys.teku.api.schema.phase0.BeaconBlockPhase0;
import tech.pegasys.teku.api.schema.phase0.BeaconStatePhase0;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
@@ -111,6 +116,13 @@ public BeaconBlock getBlindedBlock(
block.getParentRoot(),
block.getStateRoot(),
getBlindedBlockBodyCapella(block.getBody()));
case ELECTRA:
return new BlindedBlockElectra(
block.getSlot(),
block.getProposerIndex(),
block.getParentRoot(),
block.getStateRoot(),
getBlindedBlockBodyElectra(block.getBody()));
case DENEB:
return new BlindedBlockDeneb(
block.getSlot(),
@@ -155,6 +167,13 @@ public BeaconBlock getBeaconBlock(
block.getParentRoot(),
block.getStateRoot(),
getBeaconBlockBodyCapella(block.getBody()));
case ELECTRA:
return new BeaconBlockElectra(
block.getSlot(),
block.getProposerIndex(),
block.getParentRoot(),
block.getStateRoot(),
getBeaconBlockBodyElectra(block.getBody()));
case DENEB:
return new BeaconBlockDeneb(
block.getSlot(),
@@ -188,6 +207,13 @@ private BeaconBlockBodyCapella getBeaconBlockBodyCapella(
.BeaconBlockBodyCapella.required(body));
}

private BeaconBlockBodyElectra getBeaconBlockBodyElectra(
final tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody body) {
return new BeaconBlockBodyElectra(
tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.electra
.BeaconBlockBodyElectra.required(body));
}

private BeaconBlockBodyDeneb getBeaconBlockBodyDeneb(
final tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody body) {
return new BeaconBlockBodyDeneb(
@@ -209,6 +235,13 @@ private BlindedBeaconBlockBodyCapella getBlindedBlockBodyCapella(
.BlindedBeaconBlockBodyCapella.required(body));
}

private BlindedBeaconBlockBodyElectra getBlindedBlockBodyElectra(
final tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody body) {
return new BlindedBeaconBlockBodyElectra(
tech.pegasys.teku.spec.datastructures.blocks.blockbody.versions.electra
.BlindedBeaconBlockBodyElectra.required(body));
}

private BlindedBeaconBlockBodyDeneb getBlindedBlockBodyDeneb(
final tech.pegasys.teku.spec.datastructures.blocks.blockbody.BeaconBlockBody body) {
return new BlindedBeaconBlockBodyDeneb(
@@ -228,6 +261,8 @@ public BeaconState getBeaconState(
return new BeaconStateBellatrix(state);
case CAPELLA:
return new BeaconStateCapella(state);
case ELECTRA:
return new BeaconStateElectra(state);
case DENEB:
return new BeaconStateDeneb(state);
default:
Original file line number Diff line number Diff line change
@@ -37,6 +37,8 @@
import tech.pegasys.teku.api.schema.capella.SignedBlindedBeaconBlockCapella;
import tech.pegasys.teku.api.schema.deneb.SignedBeaconBlockDeneb;
import tech.pegasys.teku.api.schema.deneb.SignedBlindedBeaconBlockDeneb;
import tech.pegasys.teku.api.schema.electra.SignedBeaconBlockElectra;
import tech.pegasys.teku.api.schema.electra.SignedBlindedBeaconBlockElectra;
import tech.pegasys.teku.api.schema.phase0.SignedBeaconBlockPhase0;
import tech.pegasys.teku.bls.BLSSignature;
import tech.pegasys.teku.infrastructure.async.SafeFuture;
@@ -279,6 +281,9 @@ public SignedBeaconBlock parseBlock(final JsonProvider jsonProvider, final Strin
case CAPELLA:
signedBeaconBlock = mapper.treeToValue(jsonNode, SignedBeaconBlockCapella.class);
break;
case ELECTRA:
signedBeaconBlock = mapper.treeToValue(jsonNode, SignedBeaconBlockElectra.class);
break;
case DENEB:
signedBeaconBlock = mapper.treeToValue(jsonNode, SignedBeaconBlockDeneb.class);
break;
@@ -308,6 +313,9 @@ public SignedBeaconBlock parseBlindedBlock(
case CAPELLA:
signedBlindedBlock = mapper.treeToValue(jsonNode, SignedBlindedBeaconBlockCapella.class);
break;
case ELECTRA:
signedBlindedBlock = mapper.treeToValue(jsonNode, SignedBlindedBeaconBlockElectra.class);
break;
case DENEB:
signedBlindedBlock = mapper.treeToValue(jsonNode, SignedBlindedBeaconBlockDeneb.class);
break;
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import tech.pegasys.teku.api.schema.bellatrix.ExecutionPayloadBellatrix;
import tech.pegasys.teku.api.schema.capella.ExecutionPayloadCapella;
import tech.pegasys.teku.api.schema.deneb.ExecutionPayloadDeneb;
import tech.pegasys.teku.api.schema.electra.ExecutionPayloadElectra;

public interface ExecutionPayload {

@@ -28,6 +29,10 @@ default Optional<ExecutionPayloadCapella> toVersionCapella() {
return Optional.empty();
}

default Optional<ExecutionPayloadElectra> toVersionElectra() {
return Optional.empty();
}

default Optional<ExecutionPayloadDeneb> toVersionDeneb() {
return Optional.empty();
}
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import tech.pegasys.teku.api.schema.bellatrix.ExecutionPayloadHeaderBellatrix;
import tech.pegasys.teku.api.schema.capella.ExecutionPayloadHeaderCapella;
import tech.pegasys.teku.api.schema.deneb.ExecutionPayloadHeaderDeneb;
import tech.pegasys.teku.api.schema.electra.ExecutionPayloadHeaderElectra;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeaderSchema;

public interface ExecutionPayloadHeader {
@@ -31,6 +32,10 @@ default Optional<ExecutionPayloadHeaderCapella> toVersionCapella() {
return Optional.empty();
}

default Optional<ExecutionPayloadHeaderElectra> toVersionElectra() {
return Optional.empty();
}

default Optional<ExecutionPayloadHeaderDeneb> toVersionDeneb() {
return Optional.empty();
}
Original file line number Diff line number Diff line change
@@ -21,12 +21,15 @@ public enum Version {
altair,
bellatrix,
capella,
electra,
deneb;

public static Version fromMilestone(final SpecMilestone milestone) {
switch (milestone) {
case DENEB:
return deneb;
case ELECTRA:
return electra;
case CAPELLA:
return capella;
case BELLATRIX:
Original file line number Diff line number Diff line change
@@ -179,9 +179,7 @@ protected static void applyCapellaFields(
.baseFeePerGas(instance.latestExecutionPayloadHeader.baseFeePerGas)
.blockHash(instance.latestExecutionPayloadHeader.blockHash)
.transactionsRoot(instance.latestExecutionPayloadHeader.transactionsRoot)
.withdrawalsRoot(() -> instance.latestExecutionPayloadHeader.withdrawalsRoot)
// TODO Verkle trees
.executionWitnessRoot(() -> Bytes32.ZERO)));
.withdrawalsRoot(() -> instance.latestExecutionPayloadHeader.withdrawalsRoot)));

state.setNextWithdrawalIndex(instance.nextWithdrawalIndex);
state.setNextWithdrawalValidatorIndex(instance.nextWithdrawalValidatorIndex);
Original file line number Diff line number Diff line change
@@ -22,15 +22,15 @@
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
import tech.pegasys.teku.api.schema.ExecutionPayload;
import tech.pegasys.teku.api.schema.capella.ExecutionPayloadCapella;
import tech.pegasys.teku.api.schema.capella.Withdrawal;
import tech.pegasys.teku.api.schema.electra.ExecutionPayloadElectra;
import tech.pegasys.teku.infrastructure.bytes.Bytes20;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadBuilder;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadSchema;

public class ExecutionPayloadDeneb extends ExecutionPayloadCapella implements ExecutionPayload {
public class ExecutionPayloadDeneb extends ExecutionPayloadElectra {

@JsonProperty("blob_gas_used")
public final UInt64 blobGasUsed;
@@ -55,6 +55,7 @@ public ExecutionPayloadDeneb(
@JsonProperty("block_hash") final Bytes32 blockHash,
@JsonProperty("transactions") final List<Bytes> transactions,
@JsonProperty("withdrawals") final List<Withdrawal> withdrawals,
@JsonProperty("execution_witness") final Bytes executionWitness,
@JsonProperty("blob_gas_used") final UInt64 blobGasUsed,
@JsonProperty("excess_blob_gas") final UInt64 excessBlobGas) {
super(
@@ -72,13 +73,13 @@ public ExecutionPayloadDeneb(
baseFeePerGas,
blockHash,
transactions,
withdrawals);
withdrawals,
executionWitness);
this.blobGasUsed = blobGasUsed;
this.excessBlobGas = excessBlobGas;
}

public ExecutionPayloadDeneb(
final tech.pegasys.teku.spec.datastructures.execution.ExecutionPayload executionPayload) {
public ExecutionPayloadDeneb(final ExecutionPayload executionPayload) {
super(executionPayload);
this.blobGasUsed = executionPayload.toVersionDeneb().orElseThrow().getBlobGasUsed();
this.excessBlobGas = executionPayload.toVersionDeneb().orElseThrow().getExcessBlobGas();
@@ -137,6 +138,7 @@ public String toString() {
.add("blockHash", blockHash)
.add("transactions", transactions)
.add("withdrawals", withdrawals)
.add("executionWitness", executionWitness)
.add("blobGasUsed", blobGasUsed)
.add("excessBlobGas", excessBlobGas)
.toString();
Original file line number Diff line number Diff line change
@@ -21,13 +21,14 @@
import org.apache.tuweni.bytes.Bytes;
import org.apache.tuweni.bytes.Bytes32;
import org.apache.tuweni.units.bigints.UInt256;
import tech.pegasys.teku.api.schema.capella.ExecutionPayloadHeaderCapella;
import tech.pegasys.teku.infrastructure.bytes.Bytes20;
import tech.pegasys.teku.infrastructure.unsigned.UInt64;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeader;
import tech.pegasys.teku.spec.datastructures.execution.ExecutionPayloadHeaderSchema;
import tech.pegasys.teku.spec.datastructures.execution.versions.electra.ExecutionPayloadHeaderElectra;

public class ExecutionPayloadHeaderDeneb extends ExecutionPayloadHeaderCapella {
public class ExecutionPayloadHeaderDeneb
extends tech.pegasys.teku.api.schema.electra.ExecutionPayloadHeaderElectra {

@JsonProperty("blob_gas_used")
public final UInt64 blobGasUsed;
@@ -52,6 +53,7 @@ public ExecutionPayloadHeaderDeneb(
@JsonProperty("block_hash") final Bytes32 blockHash,
@JsonProperty("transactions_root") final Bytes32 transactionsRoot,
@JsonProperty("withdrawals_root") final Bytes32 withdrawalsRoot,
@JsonProperty("execution_witness_root") final Bytes32 executionWitnessRoot,
@JsonProperty("blob_gas_used") final UInt64 blobGasUsed,
@JsonProperty("excess_blob_gas") final UInt64 excessBlobGas) {
super(
@@ -69,7 +71,8 @@ public ExecutionPayloadHeaderDeneb(
baseFeePerGas,
blockHash,
transactionsRoot,
withdrawalsRoot);
withdrawalsRoot,
executionWitnessRoot);
this.blobGasUsed = blobGasUsed;
this.excessBlobGas = excessBlobGas;
}
@@ -90,7 +93,11 @@ public ExecutionPayloadHeaderDeneb(final ExecutionPayloadHeader executionPayload
executionPayloadHeader.getBaseFeePerGas(),
executionPayloadHeader.getBlockHash(),
executionPayloadHeader.getTransactionsRoot(),
executionPayloadHeader.getOptionalWithdrawalsRoot().orElseThrow());
executionPayloadHeader.getOptionalWithdrawalsRoot().orElseThrow(),
executionPayloadHeader
.toVersionElectra()
.map(ExecutionPayloadHeaderElectra::getExecutionWitnessRoot)
.orElse(null));
this.blobGasUsed = executionPayloadHeader.toVersionDeneb().orElseThrow().getBlobGasUsed();
this.excessBlobGas = executionPayloadHeader.toVersionDeneb().orElseThrow().getExcessBlobGas();
}
@@ -116,8 +123,7 @@ public ExecutionPayloadHeader asInternalExecutionPayloadHeader(
.blockHash(blockHash)
.transactionsRoot(transactionsRoot)
.withdrawalsRoot(() -> withdrawalsRoot)
// TODO Verkle trees
.executionWitnessRoot(() -> Bytes32.ZERO)
.executionWitnessRoot(() -> executionWitnessRoot)
.blobGasUsed(() -> blobGasUsed)
.excessBlobGas(() -> excessBlobGas));
}
@@ -166,6 +172,7 @@ public String toString() {
.add("blockHash", blockHash)
.add("transactionsRoot", transactionsRoot)
.add("withdrawalsRoot", withdrawalsRoot)
.add("executionWitnessRoot", executionWitnessRoot)
.add("blobGasUsed", blobGasUsed)
.add("excessBlobGas", excessBlobGas)
.toString();
Loading