Skip to content

Commit

Permalink
allow future nonce during parallelization
Browse files Browse the repository at this point in the history
Signed-off-by: Karim Taam <[email protected]>
  • Loading branch information
matkt committed Jan 15, 2025
1 parent 103ad88 commit 3d9d9a2
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ protected TransactionProcessingResult getTransactionProcessingResult(
OperationTracer.NO_TRACING,
blockHashLookup,
true,
TransactionValidationParams.processingBlock(),
TransactionValidationParams.blockProcessing(),
privateMetadataUpdater,
blobGasPrice);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@
@Value.Style(allParameters = true)
public interface TransactionValidationParams {

TransactionValidationParams processingBlockParams =
TransactionValidationParams blockProcessingParams =
ImmutableTransactionValidationParams.of(false, false, false, true, false, false);

TransactionValidationParams parallelBlockProcessingParams =
ImmutableTransactionValidationParams.copyOf(blockProcessingParams)
.withIsAllowFutureNonce(true);

TransactionValidationParams transactionPoolParams =
ImmutableTransactionValidationParams.of(true, false, true, true, true, false);

Expand Down Expand Up @@ -76,8 +80,12 @@ static TransactionValidationParams transactionSimulatorAllowExceedingBalance() {
return transactionSimulatorAllowExceedingBalanceParams;
}

static TransactionValidationParams processingBlock() {
return processingBlockParams;
static TransactionValidationParams blockProcessing() {
return blockProcessingParams;
}

static TransactionValidationParams parallelBlockProcessing() {
return parallelBlockProcessingParams;
}

static TransactionValidationParams transactionPool() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void traceBeforeRewardTransaction(
},
blockHashLookup,
true,
TransactionValidationParams.processingBlock(),
TransactionValidationParams.parallelBlockProcessing(),
privateMetadataUpdater,
blobGasPrice);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public BlockProcessingResult processBlock(
miningBeneficiary,
blockHashLookup,
false,
TransactionValidationParams.processingBlock(),
TransactionValidationParams.blockProcessing(),
Wei.ZERO);
if (result.isInvalid()) {
return BlockProcessingResult.FAILED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public BlockProcessingResult processBlock(
miningBeneficiary,
blockHashLookup,
true,
TransactionValidationParams.processingBlock(),
TransactionValidationParams.blockProcessing(),
Wei.ZERO);
if (result.isInvalid()) {
return BlockProcessingResult.FAILED;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ ImmutableTransactionValidationParams buildTransactionValidationParams(

if (shouldValidate) {
return ImmutableTransactionValidationParams.builder()
.from(TransactionValidationParams.processingBlock())
.from(TransactionValidationParams.blockProcessing())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package org.hyperledger.besu.ethereum.mainnet;

import static org.assertj.core.api.Assertions.assertThat;
import static org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams.processingBlockParams;
import static org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams.blockProcessingParams;
import static org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams.transactionPoolParams;
import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.BLOB_GAS_PRICE_BELOW_CURRENT_BLOB_BASE_FEE;
import static org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason.GAS_PRICE_BELOW_CURRENT_BASE_FEE;
Expand Down Expand Up @@ -75,7 +75,7 @@ public class MainnetTransactionValidatorTest {
protected static final KeyPair senderKeys = SIGNATURE_ALGORITHM.get().generateKeyPair();

private static final TransactionValidationParams transactionValidationParams =
processingBlockParams;
blockProcessingParams;

@Mock protected GasCalculator gasCalculator;

Expand Down Expand Up @@ -169,7 +169,7 @@ public void shouldRejectTransactionWhenSenderAccountDoesNotExist() {
final TransactionValidator validator =
createTransactionValidator(
gasCalculator, GasLimitCalculator.constant(), false, Optional.of(BigInteger.ONE));
assertThat(validator.validateForSender(basicTransaction, null, processingBlockParams))
assertThat(validator.validateForSender(basicTransaction, null, blockProcessingParams))
.isEqualTo(ValidationResult.invalid(TransactionInvalidReason.UPFRONT_COST_EXCEEDS_BALANCE));
}

Expand All @@ -180,7 +180,7 @@ public void shouldRejectTransactionWhenTransactionNonceBelowAccountNonce() {
gasCalculator, GasLimitCalculator.constant(), false, Optional.of(BigInteger.ONE));

final Account account = accountWithNonce(basicTransaction.getNonce() + 1);
assertThat(validator.validateForSender(basicTransaction, account, processingBlockParams))
assertThat(validator.validateForSender(basicTransaction, account, blockProcessingParams))
.isEqualTo(ValidationResult.invalid(TransactionInvalidReason.NONCE_TOO_LOW));
}

Expand All @@ -192,7 +192,7 @@ public void shouldRejectTransactionWhenTransactionNonceBelowAccountNonce() {
gasCalculator, GasLimitCalculator.constant(), false, Optional.of(BigInteger.ONE));

final Account account = accountWithNonce(basicTransaction.getNonce() - 1);
assertThat(validator.validateForSender(basicTransaction, account, processingBlockParams))
assertThat(validator.validateForSender(basicTransaction, account, blockProcessingParams))
.isEqualTo(ValidationResult.invalid(TransactionInvalidReason.NONCE_TOO_HIGH));
}

Expand All @@ -218,7 +218,7 @@ public void shouldRejectTransactionWhenNonceExceedsMaximumAllowedNonce() {
new TransactionTestFixture().nonce(11).createTransaction(senderKeys);
final Account account = accountWithNonce(5);

assertThat(validator.validateForSender(transaction, account, processingBlockParams))
assertThat(validator.validateForSender(transaction, account, blockProcessingParams))
.isEqualTo(ValidationResult.invalid(TransactionInvalidReason.NONCE_TOO_HIGH));
}

Expand All @@ -235,7 +235,7 @@ public void transactionWithNullSenderCanBeValidIfGasPriceAndValueIsZero() {

assertThat(
validator.validateForSender(
builder.createTransaction(senderKeyPair), null, processingBlockParams))
builder.createTransaction(senderKeyPair), null, blockProcessingParams))
.isEqualTo(ValidationResult.valid());
}

Expand All @@ -251,7 +251,7 @@ public void shouldRejectTransactionIfAccountIsNotEOA() {
.thenReturn(Hash.fromHexStringLenient("0xdeadbeef"))
.getMock();

assertThat(validator.validateForSender(basicTransaction, invalidEOA, processingBlockParams))
assertThat(validator.validateForSender(basicTransaction, invalidEOA, blockProcessingParams))
.isEqualTo(ValidationResult.invalid(TransactionInvalidReason.TX_SENDER_NOT_AUTHORIZED));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public void transactionSimulator() {
}

@Test
public void processingBlock() {
final TransactionValidationParams params = TransactionValidationParams.processingBlock();
public void blockProcessing() {
final TransactionValidationParams params = TransactionValidationParams.blockProcessing();
assertThat(params.isAllowFutureNonce()).isFalse();
assertThat(params.checkOnchainPermissions()).isTrue();
assertThat(params.checkLocalPermissions()).isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void testRunTransaction() {
any(OperationTracer.class),
any(BlockHashLookup.class),
eq(true),
eq(TransactionValidationParams.processingBlock()),
eq(TransactionValidationParams.blockProcessing()),
eq(privateMetadataUpdater),
eq(blobGasPrice));

Expand Down Expand Up @@ -198,7 +198,7 @@ void testRunTransactionWithConflict() {
any(OperationTracer.class),
any(BlockHashLookup.class),
eq(true),
eq(TransactionValidationParams.processingBlock()),
eq(TransactionValidationParams.blockProcessing()),
eq(privateMetadataUpdater),
eq(blobGasPrice));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public void shouldApplyBlockHeaderOverridesCorrectly() {
public void testBuildTransactionValidationParams() {
var configWhenValidate =
ImmutableTransactionValidationParams.builder()
.from(TransactionValidationParams.processingBlock())
.from(TransactionValidationParams.blockProcessing())
.build();

ImmutableTransactionValidationParams params =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private void traceTestSpecs(final String test, final List<GeneralStateTestCaseEi
? Hash.ZERO
: Hash.hash(Bytes.wrap(Long.toString(blockNumber).getBytes(UTF_8))),
false,
TransactionValidationParams.processingBlock(),
TransactionValidationParams.blockProcessing(),
tracer,
blobGasPrice);
timer.stop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ static T8nResult runTest(
blockHeader.getCoinbase(),
blockHashLookup,
false,
TransactionValidationParams.processingBlock(),
TransactionValidationParams.blockProcessing(),
tracer,
blobGasPrice);
tracerManager.disposeTracer(tracer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void milestone(
final Transaction transaction = Transaction.readFrom(RLP.input(rlp));
final ValidationResult<TransactionInvalidReason> validation =
transactionValidator(milestone)
.validate(transaction, baseFee, Optional.empty(), TransactionValidationParams.processingBlock());
.validate(transaction, baseFee, Optional.empty(), TransactionValidationParams.blockProcessing());
if (!validation.isValid()) {
throw new RuntimeException(
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public static void executeTest(final GeneralStateTestCaseEipSpec spec) {
blockHeader.getCoinbase(),
protocolSpec.getBlockHashProcessor().createBlockHashLookup(blockchain, blockHeader),
false,
TransactionValidationParams.processingBlock(),
TransactionValidationParams.blockProcessing(),
blobGasPrice);
if (result.isInvalid()) {
assertThat(spec.getExpectException())
Expand Down

0 comments on commit 3d9d9a2

Please sign in to comment.