Skip to content

Commit

Permalink
fix: test case
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkAfCod committed Sep 29, 2024
1 parent cf77337 commit 710b25f
Show file tree
Hide file tree
Showing 25 changed files with 170 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -88,7 +89,7 @@ public static EthNetworkConfig getNetworkConfig(final NetworkName networkName) {
.orElse(Collections.emptyList());
return new EthNetworkConfig(
genesisConfigFile,
null,
new HashMap<>(),
networkName.getNetworkId(),
bootNodes,
genesisConfigOptions.getDiscoveryOptions().getDiscoveryDnsUrl().orElse(null));
Expand Down Expand Up @@ -119,7 +120,7 @@ public static class Builder {
private String dnsDiscoveryUrl;
private GenesisConfigFile genesisConfigFile;
private BigInteger networkId;
private final List<EnodeURL> bootNodes;
private List<EnodeURL> bootNodes;
private Map<String, String> genesisConfigOverrides;

/**
Expand All @@ -132,6 +133,7 @@ public Builder(final EthNetworkConfig ethNetworkConfig) {
this.networkId = ethNetworkConfig.networkId;
this.bootNodes = ethNetworkConfig.bootNodes;
this.dnsDiscoveryUrl = ethNetworkConfig.dnsDiscoveryUrl;
this.genesisConfigOverrides = ethNetworkConfig.genesisConfigOverrides;
}

/**
Expand Down Expand Up @@ -174,15 +176,7 @@ public Builder setNetworkId(final BigInteger networkId) {
* @return this builder
*/
public Builder setBootNodes(final List<EnodeURL> bootNodes) {
if (bootNodes == null) {
return this;
}
bootNodes.forEach(
bootNode -> {
if (!this.bootNodes.contains(bootNode)) {
this.bootNodes.add(bootNode);
}
});
this.bootNodes = bootNodes;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public void overrideDefaultValuesIfKeyIsPresentInConfigFile(final @TempDir File
GenesisConfigFile.fromConfig(encodeJsonGenesis(GENESIS_VALID_JSON)))
.setBootNodes(nodes)
.setDnsDiscoveryUrl(null)
.setGenesisConfigOverrides(new HashMap<>())
.build();
verify(mockControllerBuilder).dataDirectory(eq(dataFolder.toPath()));
verify(mockControllerBuilderFactory).fromEthNetworkConfig(eq(networkConfig), any());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ public void maxPrioritizedTxsPerTypeConfigFile() throws IOException {
@Test
public void maxPrioritizedTxsPerTypeWrongTxType() {
internalTestFailure(
"Invalid value for option '--tx-pool-max-prioritized-by-type' (MAP<TYPE,INTEGER>): expected one of [FRONTIER, ACCESS_LIST, EIP1559, BLOB, SET_CODE] (case-insensitive) but was 'WRONG_TYPE'",
"Invalid value for option '--tx-pool-max-prioritized-by-type' (MAP<TYPE,INTEGER>): expected one of [FRONTIER, ACCESS_LIST, EIP1559, BLOB, SET_CODE, OPTIMISM_DEPOSIT] (case-insensitive) but was 'WRONG_TYPE'",
"--tx-pool-max-prioritized-by-type",
"WRONG_TYPE=1");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -146,7 +145,7 @@ public void setUp() {
.when(
mockTransactionValidatorFactory
.get()
.validate(any(), anyLong(), any(Optional.class), any(Optional.class), any()))
.validate(any(), any(), any(Optional.class), any(Optional.class), any()))
.thenReturn(ValidationResult.valid());
lenient()
.when(mockTransactionValidatorFactory.get().validateForSender(any(), any(), any()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public EnginePayloadAttributesParameter(
parentBeaconBlockRoot == null ? null : Bytes32.fromHexString(parentBeaconBlockRoot);
this.noTxPool = noTxPool;
this.transactions = transactions;
this.gasLimit = gasLimit.getValue();
this.gasLimit = gasLimit == null ? null : gasLimit.getValue();
}

public Long getTimestamp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void shouldReturnValidWithoutFinalizedWithPayload() {
null,
null,
null,
new UnsignedLongParameter(0L));
null);
var mockPayloadId =
PayloadIdentifier.forPayloadParams(
mockHeader.getHash(),
Expand Down Expand Up @@ -512,7 +512,7 @@ public void shouldReturnInvalidIfWithdrawalsIsNotNull_WhenWithdrawalsProhibited(
null,
null,
null,
new UnsignedLongParameter(0L));
null);

var resp =
resp(
Expand Down Expand Up @@ -540,7 +540,7 @@ public void shouldReturnValidIfWithdrawalsIsNull_WhenWithdrawalsProhibited() {
null,
null,
null,
new UnsignedLongParameter(0L));
null);

var mockPayloadId =
PayloadIdentifier.forPayloadParams(
Expand Down Expand Up @@ -629,7 +629,7 @@ public void shouldReturnValidIfWithdrawalsIsNotNull_WhenWithdrawalsAllowed() {
null,
null,
null,
new UnsignedLongParameter(0L));
null);

final Optional<List<Withdrawal>> withdrawals =
Optional.of(
Expand Down Expand Up @@ -684,7 +684,7 @@ public void shouldReturnValidIfProtocolScheduleIsEmpty() {
null,
null,
null,
new UnsignedLongParameter(0L));
null);

var mockPayloadId =
PayloadIdentifier.forPayloadParams(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public void shouldReturnUnsupportedForkIfBlockTimestampIsAfterCancunMilestone()
Bytes32.fromHexStringLenient("0xDEADBEEF").toHexString(),
Address.ECREC.toString(),
null,
null,
false,
null,
null);

final JsonRpcResponse resp = resp(param, Optional.of(payloadParams));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,7 @@ public void serialize_WithdrawalsPresent() {

private EnginePayloadAttributesParameter parameterWithdrawalsOmitted() {
return new EnginePayloadAttributesParameter(
TIMESTAMP,
PREV_RANDAO,
SUGGESTED_FEE_RECIPIENT_ADDRESS,
null,
null,
null,
null,
new UnsignedLongParameter(0L));
TIMESTAMP, PREV_RANDAO, SUGGESTED_FEE_RECIPIENT_ADDRESS, null, null, null, null, null);
}

private EnginePayloadAttributesParameter parameterWithdrawalsPresent() {
Expand All @@ -118,7 +111,7 @@ private EnginePayloadAttributesParameter parameterWithdrawalsPresent() {
null,
null,
null,
new UnsignedLongParameter(0L));
null);
}

// TODO: add a parent beacon block root test here
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
import java.time.Clock;
import java.util.List;
import java.util.Optional;
import java.util.OptionalLong;

import com.google.common.base.Supplier;
import com.google.common.base.Suppliers;
Expand Down Expand Up @@ -499,6 +500,7 @@ static class AlwaysValidTransactionValidator implements TransactionValidator {
@Override
public ValidationResult<TransactionInvalidReason> validate(
final Transaction transaction,
final OptionalLong blockTimestamp,
final Optional<Wei> baseFee,
final Optional<Wei> blobBaseFee,
final TransactionValidationParams transactionValidationParams) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ public static TransactionReceipt readFrom(
return new TransactionReceipt(
transactionType,
stateRoot,
0,
-1,
cumulativeGas,
logs,
bloomFilter,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public class L1CostCalculator {
private static final UInt256 SIXTEEN = UInt256.valueOf(16L);

private static final BigInteger L1_COST_INTERCEPT = BigInteger.valueOf(-42_585_600L);
private static final UInt256 L1_COST_FAST_LZ_COEF = UInt256.valueOf(836_500L);
private static final BigInteger L1_COST_FAST_LZ_COEF = BigInteger.valueOf(836_500L);

private static final UInt256 MIN_TX_SIZE = UInt256.valueOf(100L);
private static final UInt256 MIN_TX_SIZE_SCALED =
UInt256.valueOf(1_000_000L).multiply(MIN_TX_SIZE);
private static final BigInteger MIN_TX_SIZE = BigInteger.valueOf(100L);
private static final BigInteger MIN_TX_SIZE_SCALED =
BigInteger.valueOf(1_000_000L).multiply(MIN_TX_SIZE);
private static final UInt256 ECOTONE_DIVISOR = UInt256.valueOf(1_000_000L * 16L);
private static final UInt256 FJORD_DIVISOR = UInt256.valueOf(1_000_000_000_000L);
private static final BigInteger FJORD_DIVISOR = BigInteger.valueOf(1_000_000_000_000L);

private static final int BASE_FEE_SCALAR_SLOT_OFFSET = 12;
// private static final int BLOB_BASE_FEE_SCALAR_SLOT_OFFSET = 8;
Expand Down Expand Up @@ -231,16 +231,15 @@ static Wei l1CostFjord(
var blobCostPerByte = l1BlobBaseFeeScalar.multiply(l1BlobBaseFee);
var l1FeeScaled = calldataCostPerByte.add(blobCostPerByte);

var fastLzSize = UInt256.valueOf(costData.getFastLzSize());
var estimatedSize =
UInt256.valueOf(
L1_COST_INTERCEPT.add(L1_COST_FAST_LZ_COEF.multiply(fastLzSize).toBigInteger()));
L1_COST_INTERCEPT.add(
L1_COST_FAST_LZ_COEF.multiply(BigInteger.valueOf(costData.getFastLzSize())));

if (estimatedSize.compareTo(MIN_TX_SIZE_SCALED) < 0) {
estimatedSize = MIN_TX_SIZE_SCALED;
}

var l1CostScaled = estimatedSize.multiply(l1FeeScaled);
var l1CostScaled = estimatedSize.multiply(l1FeeScaled.toBigInteger());
var l1Cost = l1CostScaled.divide(FJORD_DIVISOR);
return Wei.of(l1Cost);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,7 @@ static ProtocolSpecBuilder regolithDefinition(
(BaseFeeMarket) feeMarket))
.blockBodyValidatorBuilder(BaseFeeBlockBodyValidator::new)
.genesisConfigOptions(Optional.of(genesisConfigOptions))
.withdrawalsValidator(new WithdrawalsValidator.AllowedWithdrawals())
.name("Regolith");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import java.util.Deque;
import java.util.List;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.Set;

import com.google.common.collect.HashMultimap;
Expand Down Expand Up @@ -339,7 +340,7 @@ public TransactionProcessingResult processTransaction(
ValidationResult<TransactionInvalidReason> validationResult =
transactionValidator.validate(
transaction,
blockHeader.getTimestamp(),
OptionalLong.of(blockHeader.getTimestamp()),
blockHeader.getBaseFee(),
Optional.ofNullable(blobGasPrice),
transactionValidationParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import java.math.BigInteger;
import java.util.List;
import java.util.Optional;
import java.util.OptionalLong;
import java.util.Set;

import ethereum.ckzg4844.CKZG4844JNI;
Expand Down Expand Up @@ -105,7 +106,7 @@ public MainnetTransactionValidator(
@Override
public ValidationResult<TransactionInvalidReason> validate(
final Transaction transaction,
final long blockTimestamp,
final OptionalLong blockTimestamp,
final Optional<Wei> baseFee,
final Optional<Wei> blobFee,
final TransactionValidationParams transactionValidationParams) {
Expand Down Expand Up @@ -144,7 +145,7 @@ public ValidationResult<TransactionInvalidReason> validate(
if (transaction.getType().equals(TransactionType.OPTIMISM_DEPOSIT)) {
// genesisOptions.orElseThrow();
if (transaction.getIsSystemTx().orElse(false)) {
if (genesisOptions.get().isRegolith(blockTimestamp)) {
if (genesisOptions.get().isRegolith(blockTimestamp.orElse(0L))) {
return ValidationResult.invalid(
TransactionInvalidReason.SYSTEM_TX_NOT_SUPPORT,
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.hyperledger.besu.evm.account.Account;

import java.util.Optional;
import java.util.OptionalLong;

/**
* Validates a transaction based on Frontier protocol runtime requirements.
Expand All @@ -42,7 +43,7 @@ public PermissionTransactionValidator(
@Override
public ValidationResult<TransactionInvalidReason> validate(
final Transaction transaction,
final long blockTimestamp,
final OptionalLong blockTimestamp,
final Optional<Wei> baseFee,
final Optional<Wei> blobBaseFee,
final TransactionValidationParams transactionValidationParams) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.hyperledger.besu.evm.account.Account;

import java.util.Optional;
import java.util.OptionalLong;

public interface TransactionValidator {

Expand All @@ -34,7 +35,7 @@ public interface TransactionValidator {
*/
ValidationResult<TransactionInvalidReason> validate(
Transaction transaction,
final long blockTimestamp,
OptionalLong blockTimestamp,
Optional<Wei> baseFee,
Optional<Wei> blobBaseFee,
TransactionValidationParams transactionValidationParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ProhibitedWithdrawals implements WithdrawalsValidator {

@Override
public boolean validateWithdrawals(final Optional<List<Withdrawal>> withdrawals) {
final boolean isValid = withdrawals.isEmpty() || withdrawals.get().isEmpty();
final boolean isValid = withdrawals.isEmpty();
if (!isValid) {
LOG.warn(
"withdrawals must be null when Withdrawals are prohibited but were: {}", withdrawals);
Expand Down
Loading

0 comments on commit 710b25f

Please sign in to comment.