Skip to content

Commit

Permalink
feat:blockv3 support
Browse files Browse the repository at this point in the history
Signed-off-by: Chen Kai <281165273grape@gmail.com>
  • Loading branch information
GrapeBaBa committed Feb 20, 2024
1 parent f2ced42 commit 6d591e1
Show file tree
Hide file tree
Showing 14 changed files with 1,066 additions and 640 deletions.
2 changes: 1 addition & 1 deletion hildr-node/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ dependencies {
implementation("com.squareup.okhttp3:okhttp:5.0.0-alpha.2")
implementation("com.squareup.okhttp3:logging-interceptor:5.0.0-alpha.2")

implementation('org.web3j:core:4.10.3') {
implementation('org.web3j:core:4.11.0') {
exclude group: 'org.bouncycastle', module: 'bcprov-jdk15on'
exclude group: 'com.squareup.okhttp3', module: 'okhttp'
exclude group: 'com.squareup.okhttp3', module: 'logging-interceptor'
Expand Down
193 changes: 113 additions & 80 deletions hildr-node/src/main/java/io/optimism/engine/ExecutionPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,23 @@
/**
* The type ExecutionPayload.
*
* @param parentHash A 32 byte hash of the parent payload.
* @param feeRecipient A 20 byte hash (aka Address) for the feeRecipient field of the new payload.
* @param stateRoot A 32 byte state root hash.
* @param receiptsRoot A 32 byte receipt root hash.
* @param logsBloom A 32 byte logs bloom filter.
* @param prevRandao A 32 byte beacon chain randomness value.
* @param blockNumber A 64-bit number for the current block index.
* @param gasLimit A 64-bit value for the gas limit.
* @param gasUsed A 64-bit value for the gas used.
* @param timestamp A 64-bit value for the timestamp field of the new payload.
* @param extraData 0 to 32 byte value for extra data.
* @param parentHash A 32 byte hash of the parent payload.
* @param feeRecipient A 20 byte hash (aka Address) for the feeRecipient field of the new payload.
* @param stateRoot A 32 byte state root hash.
* @param receiptsRoot A 32 byte receipt root hash.
* @param logsBloom A 32 byte logs bloom filter.
* @param prevRandao A 32 byte beacon chain randomness value.
* @param blockNumber A 64-bit number for the current block index.
* @param gasLimit A 64-bit value for the gas limit.
* @param gasUsed A 64-bit value for the gas used.
* @param timestamp A 64-bit value for the timestamp field of the new payload.
* @param extraData 0 to 32 byte value for extra data.
* @param baseFeePerGas 256 bits for the base fee per gas.
* @param blockHash The 32 byte block hash.
* @param transactions An array of transaction objects where each object is a byte list.
* @param withdrawals An array of withdrawal objects where each object is a byte list.
* @param blockHash The 32 byte block hash.
* @param transactions An array of transaction objects where each object is a byte list.
* @param withdrawals An array of withdrawal objects where each object is a byte list.
* @param blobGasUsed The gas used by the blob.
* @param excessBlobGas The excess gas used by the blob.
* @author grapebaba
* @since 0.1.0
*/
Expand All @@ -45,27 +47,31 @@ public record ExecutionPayload(
String extraData,
BigInteger baseFeePerGas,
String blockHash,
List<String> transactions,
List<EthBlock.Withdrawal> withdrawals,
List<String> transactions) {
BigInteger blobGasUsed,
BigInteger excessBlobGas) {

/**
* The type Execution payload res.
*
* @param parentHash A 32 byte hash of the parent payload.
* @param feeRecipient A 20 byte hash (aka Address) for the feeRecipient field of the new payload.
* @param stateRoot A 32 byte state root hash.
* @param receiptsRoot A 32 byte receipt root hash.
* @param logsBloom A 32 byte logs bloom filter.
* @param prevRandao A 32 byte beacon chain randomness value.
* @param blockNumber A 64-bit number for the current block index.
* @param gasLimit A 64-bit value for the gas limit.
* @param gasUsed A 64-bit value for the gas used.
* @param timestamp A 64-bit value for the timestamp field of the new payload.
* @param extraData 0 to 32 byte value for extra data.
* @param parentHash A 32 byte hash of the parent payload.
* @param feeRecipient A 20 byte hash (aka Address) for the feeRecipient field of the new payload.
* @param stateRoot A 32 byte state root hash.
* @param receiptsRoot A 32 byte receipt root hash.
* @param logsBloom A 32 byte logs bloom filter.
* @param prevRandao A 32 byte beacon chain randomness value.
* @param blockNumber A 64-bit number for the current block index.
* @param gasLimit A 64-bit value for the gas limit.
* @param gasUsed A 64-bit value for the gas used.
* @param timestamp A 64-bit value for the timestamp field of the new payload.
* @param extraData 0 to 32 byte value for extra data.
* @param baseFeePerGas 256 bits for the base fee per gas.
* @param blockHash The 32 byte block hash.
* @param withdrawals An array of withdrawal objects where each object is a byte list.
* @param transactions An array of transaction objects where each object is a byte list.
* @param blockHash The 32 byte block hash.
* @param withdrawals An array of withdrawal objects where each object is a byte list.
* @param transactions An array of transaction objects where each object is a byte list.
* @param blobGasUsed The gas used by the blob.
* @param excessBlobGas The excess gas used by the blob.
*/
public record ExecutionPayloadRes(
String parentHash,
Expand All @@ -81,8 +87,10 @@ public record ExecutionPayloadRes(
String extraData,
String baseFeePerGas,
String blockHash,
List<String> transactions,
List<EthBlock.Withdrawal> withdrawals,
List<String> transactions) {
String blobGasUsed,
String excessBlobGas) {

/**
* To execution payload execution payload.
Expand All @@ -104,8 +112,10 @@ public ExecutionPayload toExecutionPayload() {
extraData,
Numeric.decodeQuantity(baseFeePerGas),
blockHash,
transactions,
withdrawals,
transactions);
StringUtils.isEmpty(blobGasUsed) ? null : Numeric.decodeQuantity(blobGasUsed),
StringUtils.isEmpty(excessBlobGas) ? null : Numeric.decodeQuantity(excessBlobGas));
}
}

Expand Down Expand Up @@ -134,8 +144,11 @@ public static ExecutionPayload from(EthBlock.Block block) {
block.getExtraData(),
block.getBaseFeePerGas(),
block.getHash(),
encodedTxs,
block.getWithdrawals(),
encodedTxs);
// TODO:
null,
null);
}

/**
Expand All @@ -159,30 +172,34 @@ public static ExecutionPayload from(ExecutionPayloadSSZ payload) {
Numeric.toHexString(payload.extraData().toArray()),
payload.baseFeePerGas().toBigInteger(),
Numeric.toHexString(payload.blockHash().toArray()),
payload.withdrawals(),
payload.transactions().stream()
.map(bytes -> Numeric.toHexString(bytes.toArray()))
.collect(Collectors.toList()));
.collect(Collectors.toList()),
payload.withdrawals(),
payload.blobGasUsed() == null ? null : BigInteger.valueOf(payload.blobGasUsed()),
payload.excessBlobGas() == null ? null : BigInteger.valueOf(payload.excessBlobGas()));
}

/**
* The type Execution payload req.
*
* @param parentHash A 32 byte hash of the parent payload.
* @param feeRecipient A 20 byte hash (aka Address) for the feeRecipient field of the new payload.
* @param stateRoot A 32 byte state root hash.
* @param receiptsRoot A 32 byte receipt root hash.
* @param logsBloom A 32 byte logs bloom filter.
* @param prevRandao A 32 byte beacon chain randomness value.
* @param blockNumber A 64-bit number for the current block index.
* @param gasLimit A 64-bit value for the gas limit.
* @param gasUsed A 64-bit value for the gas used.
* @param timestamp A 64-bit value for the timestamp field of the new payload.
* @param extraData 0 to 32 byte value for extra data.
* @param parentHash A 32 byte hash of the parent payload.
* @param feeRecipient A 20 byte hash (aka Address) for the feeRecipient field of the new payload.
* @param stateRoot A 32 byte state root hash.
* @param receiptsRoot A 32 byte receipt root hash.
* @param logsBloom A 32 byte logs bloom filter.
* @param prevRandao A 32 byte beacon chain randomness value.
* @param blockNumber A 64-bit number for the current block index.
* @param gasLimit A 64-bit value for the gas limit.
* @param gasUsed A 64-bit value for the gas used.
* @param timestamp A 64-bit value for the timestamp field of the new payload.
* @param extraData 0 to 32 byte value for extra data.
* @param baseFeePerGas 256 bits for the base fee per gas.
* @param blockHash The 32 byte block hash.
* @param withdrawals The withdrawals list.
* @param transactions An array of transaction objects where each object is a byte list.
* @param blockHash The 32 byte block hash.
* @param withdrawals The withdrawals list.
* @param transactions An array of transaction objects where each object is a byte list.
* @param blobGasUsed The gas used by the blob.
* @param excessBlobGas The excess gas used by the blob.
*/
public record ExecutionPayloadReq(
String parentHash,
Expand All @@ -198,8 +215,10 @@ public record ExecutionPayloadReq(
String extraData,
String baseFeePerGas,
String blockHash,
List<String> transactions,
List<EthBlock.Withdrawal> withdrawals,
List<String> transactions) {}
String blobGasUsed,
String excessBlobGas) {}

/**
* To req execution payload req.
Expand All @@ -221,8 +240,10 @@ public ExecutionPayloadReq toReq() {
extraData,
Numeric.toHexStringWithPrefix(baseFeePerGas),
blockHash,
transactions,
withdrawals,
transactions);
blobGasUsed == null ? null : Numeric.toHexStringWithPrefix(blobGasUsed),
excessBlobGas == null ? null : Numeric.toHexStringWithPrefix(excessBlobGas));
}

/**
Expand All @@ -231,23 +252,23 @@ public ExecutionPayloadReq toReq() {
* <p>L2 extended payload attributes for Optimism. For more details, visit the [Optimism specs](<a
* href="https://github.com/ethereum-optimism/optimism/blob/develop/specs/exec-engine.md#extended-payloadattributesv1">...</a>).
*
* @param timestamp 64 bit value for the timestamp field of the new payload.
* @param prevRandao 32 byte value for the prevRandao field of the new payload.
* @param timestamp 64 bit value for the timestamp field of the new payload.
* @param prevRandao 32 byte value for the prevRandao field of the new payload.
* @param suggestedFeeRecipient 20 bytes suggested value for the feeRecipient field of the new
* payload.
* @param transactions List of transactions to be included in the new payload.
* @param withdrawals List of withdrawals to be included in the new payload.
* @param noTxPool Boolean value indicating whether the payload should be built without including
* transactions from the txpool.
* @param gasLimit 64 bit value for the gasLimit field of the new payload.The gasLimit is optional
* w.r.t. compatibility with L1, but required when used as rollup.This field overrides the gas
* limit used during block-building.If not specified as rollup, a STATUS_INVALID is returned.
* @param epoch The batch epoch number from derivation. This value is not expected by the engine
* is skipped during serialization and deserialization.
* @param l1InclusionBlock The L1 block number when this batch was first fully derived. This value
* is not expected by the engine and is skipped during serialization and deserialization.
* @param seqNumber The L2 sequence number of the block. This value is not expected by the engine
* and is skipped during serialization and deserialization.
* payload.
* @param transactions List of transactions to be included in the new payload.
* @param withdrawals List of withdrawals to be included in the new payload.
* @param noTxPool Boolean value indicating whether the payload should be built without including
* transactions from the txpool.
* @param gasLimit 64 bit value for the gasLimit field of the new payload.The gasLimit is optional
* w.r.t. compatibility with L1, but required when used as rollup.This field overrides the gas
* limit used during block-building.If not specified as rollup, a STATUS_INVALID is returned.
* @param epoch The batch epoch number from derivation. This value is not expected by the engine
* is skipped during serialization and deserialization.
* @param l1InclusionBlock The L1 block number when this batch was first fully derived. This value
* is not expected by the engine and is skipped during serialization and deserialization.
* @param seqNumber The L2 sequence number of the block. This value is not expected by the engine
* and is skipped during serialization and deserialization.
* @author zhouop0
* @since 0.1.0
*/
Expand All @@ -266,22 +287,22 @@ public record PayloadAttributes(
/**
* The type Epoch req.
*
* @param number the number
* @param hash the hash
* @param number the number
* @param hash the hash
* @param timestamp the timestamp
*/
public record EpochReq(String number, String hash, String timestamp) {}

/**
* The type Payload attributes req.
*
* @param timestamp the timestamp
* @param prevRandao the prev randao
* @param timestamp the timestamp
* @param prevRandao the prev randao
* @param suggestedFeeRecipient the suggested fee recipient
* @param transactions the transactions
* @param withdrawals the withdrawals
* @param noTxPool the no tx pool
* @param gasLimit the gas limit
* @param transactions the transactions
* @param withdrawals the withdrawals
* @param noTxPool the no tx pool
* @param gasLimit the gas limit
*/
public record PayloadAttributesReq(
String timestamp,
Expand Down Expand Up @@ -316,15 +337,25 @@ public PayloadAttributesReq toReq() {
* @since 0.1.0
*/
public enum Status {
/** Valid status. */
/**
* Valid status.
*/
VALID,
/** Invalid status. */
/**
* Invalid status.
*/
INVALID,
/** Syncing status. */
/**
* Syncing status.
*/
SYNCING,
/** Accepted status. */
/**
* Accepted status.
*/
ACCEPTED,
/** Invalid block hash status. */
/**
* Invalid block hash status.
*/
INVALID_BLOCK_HASH,
}

Expand All @@ -345,7 +376,9 @@ public static class PayloadStatus {
private String latestValidHash;
private String validationError;

/** PayloadStatus constructor. */
/**
* PayloadStatus constructor.
*/
public PayloadStatus() {}

/**
Expand Down
Loading

0 comments on commit 6d591e1

Please sign in to comment.