Skip to content

Commit

Permalink
feat: execute deposit tx
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkAfCod committed Jan 2, 2024
1 parent 79665fc commit 11acfde
Show file tree
Hide file tree
Showing 27 changed files with 721 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,8 @@ BesuControllerBuilder fromGenesisConfig(
builder = new QbftBesuControllerBuilder();
} else if (configOptions.isClique()) {
builder = new CliqueBesuControllerBuilder();
} else if (configOptions.isOptimism()) {
builder = new MainnetBesuControllerBuilder();
} else {
throw new IllegalArgumentException("Unknown consensus mechanism defined");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,20 +277,42 @@ default boolean isConsensusMigration() {
*/
OptionalLong getBedrockBlock();

/**
* Returns whether a fork scheduled at bedrock block number is active at the given head block
* number
*
* @return the boolean
*/
boolean isBedrockBlock(long headBlock);

/**
* Gets regolith time.
*
* @return the regolith time
*/
OptionalLong getRegolithTime();

/**
* Returns whether a fork scheduled at regolith timestamp is active at the given head timestamp.
*
* @return the boolean
*/
boolean isRegolith(long headTime);

/**
* Gets canyon time.
*
* @return the canyon time
*/
OptionalLong getCanyonTime();

/**
* Returns whether a fork scheduled at canyon timestamp is active at the given head timestamp.
*
* @return the boolean
*/
boolean isCanyon(long headTime);

/**
* Gets base fee per gas.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,17 +317,50 @@ public OptionalLong getExperimentalEipsTime() {

@Override
public OptionalLong getBedrockBlock() {
return getOptionalLong("bedrockBlock");
return getOptionalLong("bedrockblock");
}

@Override
public boolean isBedrockBlock(final long headBlock) {
OptionalLong bedrockBlock = getBedrockBlock();
if (!bedrockBlock.isPresent()) {
return false;
}
return bedrockBlock.getAsLong() <= headBlock;
}

@Override
public OptionalLong getRegolithTime() {
return getOptionalLong("regolithTime");
return getOptionalLong("regolithtime");
}

@Override
public boolean isRegolith(final long headTime) {
if (!isOptimism()) {
return false;
}
var regolithTime = getRegolithTime();
if (regolithTime.isPresent()) {
return regolithTime.getAsLong() <= headTime;
}
return false;
}

@Override
public OptionalLong getCanyonTime() {
return getOptionalLong("canyonTime");
return getOptionalLong("canyontime");
}

@Override
public boolean isCanyon(final long headTime) {
if (!isOptimism()) {
return false;
}
var canyonTime = getCanyonTime();
if (canyonTime.isPresent()) {
return canyonTime.getAsLong() <= headTime;
}
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,16 +260,31 @@ public OptionalLong getBedrockBlock() {
return bedrockBlock;
}

@Override
public boolean isBedrockBlock(final long headBlock) {
return false;
}

@Override
public OptionalLong getRegolithTime() {
return regolithTime;
}

@Override
public boolean isRegolith(final long headTime) {
return false;
}

@Override
public OptionalLong getCanyonTime() {
return canyonTime;
}

@Override
public boolean isCanyon(final long headTime) {
return false;
}

@Override
public Optional<Wei> getBaseFeePerGas() {
return baseFeePerGas;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright optimism-java.
*
* 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.
*
* SPDX-License-Identifier: Apache-2.0
*/
package org.hyperledger.besu.datatypes;

import org.apache.tuweni.bytes.Bytes;

/** Optimism roll up data records. */
public class RollupGasData {

private static final RollupGasData empty = new RollupGasData(0L, 0L);

private final long zeroes;

private final long ones;

RollupGasData(final long zeroes, final long ones) {
this.zeroes = zeroes;
this.ones = ones;
}

public long getZeroes() {
return zeroes;
}

public long getOnes() {
return ones;
}

public static RollupGasData fromPayload(final Bytes payload) {
if (payload == null) {
return empty;
}
final int length = payload.size();
int zeroes = 0;
int ones = 0;
for (int i = 0; i < length; i++) {
byte b = payload.get(i);
if (b == 0) {
zeroes++;
} else {
ones++;
}
}
return new RollupGasData(zeroes, ones);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ default Optional<? extends Quantity> getMaxFeePerBlobGas() {
*/
Optional<Boolean> getIsSystemTx();

/**
* Return the roll up gas data.
*
* @return roll up gas data
*/
RollupGasData getRollupGasData();

/**
* Return the address of the contract, if the transaction creates one
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.response.RpcErrorType;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.EngineUpdateForkchoiceResult;
import org.hyperledger.besu.ethereum.core.BlockHeader;
import org.hyperledger.besu.ethereum.core.Transaction;
import org.hyperledger.besu.ethereum.core.Withdrawal;
import org.hyperledger.besu.ethereum.core.encoding.EncodingContext;
import org.hyperledger.besu.ethereum.core.encoding.TransactionDecoder;
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule;
import org.hyperledger.besu.ethereum.mainnet.ScheduledProtocolSpec;
import org.hyperledger.besu.ethereum.mainnet.ValidationResult;
Expand Down Expand Up @@ -224,7 +225,11 @@ public JsonRpcResponse syncResponse(final JsonRpcRequestContext requestContext)
payloadAttributes.getTransactions() == null
? null
: payloadAttributes.getTransactions().stream()
.map(s -> Transaction.readFrom(Bytes.fromHexString(s)))
.map(Bytes::fromHexString)
.map(
in ->
TransactionDecoder.decodeOpaqueBytes(
in, EncodingContext.BLOCK_BODY))
.collect(toList())),
Optional.ofNullable(payloadAttributes.getGasLimit())));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public EnginePayloadAttributesParameter(
@JsonProperty("parentBeaconBlockRoot") final String parentBeaconBlockRoot,
@JsonProperty("noTxPool") final Boolean noTxPool,
@JsonProperty("transactions") final List<String> transactions,
@JsonProperty("gasLimit") final Long gasLimit) {
@JsonProperty("gasLimit") final UnsignedLongParameter gasLimit) {
this.timestamp = Long.decode(timestamp);
this.prevRandao = Bytes32.fromHexString(prevRandao);
this.suggestedFeeRecipient = Address.fromHexString(suggestedFeeRecipient);
Expand All @@ -55,7 +55,7 @@ public EnginePayloadAttributesParameter(
parentBeaconBlockRoot == null ? null : Bytes32.fromHexString(parentBeaconBlockRoot);
this.noTxPool = noTxPool;
this.transactions = transactions;
this.gasLimit = gasLimit;
this.gasLimit = gasLimit.getValue();
}

public Long getTimestamp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"cumulativeGasUsed",
"from",
"gasUsed",
"depositNonce",
"effectiveGasPrice",
"logs",
"logsBloom",
Expand All @@ -58,6 +59,7 @@ public abstract class TransactionReceiptResult {
private final String cumulativeGasUsed;
private final String from;
private final String gasUsed;
private final String depositNonce;
private final String effectiveGasPrice;
private final List<TransactionReceiptLogResult> logs;
private final String logsBloom;
Expand All @@ -83,6 +85,10 @@ protected TransactionReceiptResult(final TransactionReceiptWithMetadata receiptW
this.gasUsed = Quantity.create(receiptWithMetadata.getGasUsed());
this.blobGasUsed = receiptWithMetadata.getBlobGasUsed().map(Quantity::create).orElse(null);
this.blobGasPrice = receiptWithMetadata.getBlobGasPrice().map(Quantity::create).orElse(null);
this.depositNonce =
this.receipt.getDepositNonce().isPresent()
? Quantity.create(this.receipt.getDepositNonce().get())
: null;
this.effectiveGasPrice =
Quantity.create(txn.getEffectiveGasPrice(receiptWithMetadata.getBaseFee()));

Expand Down Expand Up @@ -146,6 +152,11 @@ public String getBlobGasPrice() {
return blobGasPrice;
}

@JsonGetter(value = "depositNonce")
public String getDepositNonce() {
return depositNonce;
}

@JsonGetter(value = "effectiveGasPrice")
public String getEffectiveGasPrice() {
return effectiveGasPrice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import org.hyperledger.besu.config.GenesisConfigOptions;
import org.hyperledger.besu.datatypes.Address;
import org.hyperledger.besu.datatypes.Wei;
import org.hyperledger.besu.ethereum.api.jsonrpc.internal.results.tracing.Trace;
Expand All @@ -35,6 +36,7 @@

import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -55,6 +57,7 @@ public class RewardTraceGeneratorTest {
@Mock private ProtocolSpec protocolSpec;
@Mock private MiningBeneficiaryCalculator miningBeneficiaryCalculator;
@Mock private MainnetTransactionProcessor transactionProcessor;
@Mock private GenesisConfigOptions genesisConfigOptions;

private final Address ommerBeneficiary =
Address.wrap(Bytes.fromHexString("0x095e7baea6a6c7c4c2dfeb977efac326af552d87"));
Expand Down Expand Up @@ -91,7 +94,8 @@ public void assertThatTraceGeneratorReturnValidRewardsForMainnetBlockProcessor()
blockReward,
BlockHeader::getCoinbase,
true,
protocolSchedule);
protocolSchedule,
Optional.of(genesisConfigOptions));
when(protocolSpec.getBlockProcessor()).thenReturn(blockProcessor);

final Stream<Trace> traceStream =
Expand Down
Loading

0 comments on commit 11acfde

Please sign in to comment.