-
Notifications
You must be signed in to change notification settings - Fork 58
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
add block limit #2
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ | |
import org.hyperledger.besu.ethereum.core.TransactionReceipt; | ||
import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactions; | ||
import org.hyperledger.besu.ethereum.eth.transactions.PendingTransactions.TransactionSelectionResult; | ||
import org.hyperledger.besu.ethereum.linea.LineaParameters; | ||
import org.hyperledger.besu.ethereum.mainnet.AbstractBlockProcessor; | ||
import org.hyperledger.besu.ethereum.mainnet.MainnetTransactionProcessor; | ||
import org.hyperledger.besu.ethereum.mainnet.MainnetTransactionValidator; | ||
|
@@ -45,7 +46,9 @@ | |
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Objects; | ||
import java.util.Optional; | ||
import java.util.concurrent.CancellationException; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
|
||
|
@@ -75,6 +78,12 @@ | |
* not cleared between executions of buildTransactionListForBlock(). | ||
*/ | ||
public class BlockTransactionSelector { | ||
|
||
private final int blockMaxCalldataSize; | ||
private final Function<Transaction, Optional<TransactionSelectionResult>> | ||
lineaMaxCalldataSizeEnforcer; | ||
private int blockCalldataSum; | ||
|
||
public static class TransactionValidationResult { | ||
private final Transaction transaction; | ||
private final ValidationResult<TransactionInvalidReason> validationResult; | ||
|
@@ -240,7 +249,8 @@ public BlockTransactionSelector( | |
final Wei dataGasPrice, | ||
final FeeMarket feeMarket, | ||
final GasCalculator gasCalculator, | ||
final GasLimitCalculator gasLimitCalculator) { | ||
final GasLimitCalculator gasLimitCalculator, | ||
final LineaParameters lineaParameters) { | ||
this.transactionProcessor = transactionProcessor; | ||
this.blockchain = blockchain; | ||
this.worldState = worldState; | ||
|
@@ -255,6 +265,13 @@ public BlockTransactionSelector( | |
this.feeMarket = feeMarket; | ||
this.gasCalculator = gasCalculator; | ||
this.gasLimitCalculator = gasLimitCalculator; | ||
if (lineaParameters.maybeBlockCalldataMaxSize().isPresent()) { | ||
blockMaxCalldataSize = lineaParameters.maybeBlockCalldataMaxSize().getAsInt(); | ||
lineaMaxCalldataSizeEnforcer = (t) -> maxCalldataEnforcer(t); | ||
} else { | ||
blockMaxCalldataSize = 0; | ||
lineaMaxCalldataSizeEnforcer = (t) -> Optional.empty(); | ||
} | ||
} | ||
|
||
/* | ||
|
@@ -304,6 +321,12 @@ private TransactionSelectionResult evaluateTransaction( | |
throw new CancellationException("Cancelled during transaction selection."); | ||
} | ||
|
||
final Optional<TransactionSelectionResult> maybeResult = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems this could simplified to be a |
||
lineaMaxCalldataSizeEnforcer.apply(transaction); | ||
if (maybeResult.isPresent()) { | ||
return maybeResult.get(); | ||
} | ||
|
||
if (transactionTooLargeForBlock(transaction)) { | ||
LOG.atTrace() | ||
.setMessage("Transaction {} too large to select for block creation") | ||
|
@@ -534,4 +557,13 @@ private boolean blockOccupancyAboveThreshold() { | |
occupancyRatio); | ||
return occupancyRatio >= minBlockOccupancyRatio; | ||
} | ||
|
||
private Optional<TransactionSelectionResult> maxCalldataEnforcer(final Transaction transaction) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it seems this could simplified to just return a boolean |
||
this.blockCalldataSum += transaction.getPayload().size(); | ||
if (blockCalldataSum > blockMaxCalldataSize) { | ||
return Optional.of(TransactionSelectionResult.COMPLETE_OPERATION); | ||
} else { | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
import java.util.Set; | ||
|
||
public class LineaProtocolSpecs { | ||
public static final int DEFAULT_BLOCK_MAX_CALLDATA_SIZE = 1000000; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be private |
||
private static final int LINEA_MAX_TX_CALLDATA_SIZE = | ||
10000; // fake value replace with the actual one when known | ||
|
||
|
@@ -52,6 +53,7 @@ static ProtocolSpecBuilder lineaDefinition( | |
TransactionType.EIP1559), | ||
quorumCompatibilityMode, | ||
txCalldataMaxSize)) | ||
.lineaParameters(lineaParameters) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should not pass |
||
.name("Linea"); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import org.hyperledger.besu.ethereum.chain.BadBlockManager; | ||
import org.hyperledger.besu.ethereum.core.BlockHeaderFunctions; | ||
import org.hyperledger.besu.ethereum.core.BlockImporter; | ||
import org.hyperledger.besu.ethereum.linea.LineaParameters; | ||
import org.hyperledger.besu.ethereum.mainnet.feemarket.FeeMarket; | ||
import org.hyperledger.besu.ethereum.privacy.PrivateTransactionProcessor; | ||
import org.hyperledger.besu.evm.EVM; | ||
|
@@ -81,6 +82,8 @@ public class ProtocolSpec { | |
private final DepositsValidator depositsValidator; | ||
|
||
private final boolean isPoS; | ||
private final LineaParameters lineaParameters; | ||
|
||
/** | ||
* Creates a new protocol specification instance. | ||
* | ||
|
@@ -111,6 +114,7 @@ public class ProtocolSpec { | |
* @param withdrawalsProcessor the Withdrawals processor to use | ||
* @param depositsValidator the withdrawals validator to use | ||
* @param isPoS indicates whether the current spec is PoS | ||
* @param lineaParameters linea parameters | ||
*/ | ||
public ProtocolSpec( | ||
final String name, | ||
|
@@ -139,7 +143,8 @@ public ProtocolSpec( | |
final WithdrawalsValidator withdrawalsValidator, | ||
final Optional<WithdrawalsProcessor> withdrawalsProcessor, | ||
final DepositsValidator depositsValidator, | ||
final boolean isPoS) { | ||
final boolean isPoS, | ||
final LineaParameters lineaParameters) { | ||
this.name = name; | ||
this.evm = evm; | ||
this.transactionValidator = transactionValidator; | ||
|
@@ -167,6 +172,7 @@ public ProtocolSpec( | |
this.withdrawalsProcessor = withdrawalsProcessor; | ||
this.depositsValidator = depositsValidator; | ||
this.isPoS = isPoS; | ||
this.lineaParameters = lineaParameters; | ||
} | ||
|
||
/** | ||
|
@@ -387,4 +393,8 @@ public DepositsValidator getDepositsValidator() { | |
public boolean isPoS() { | ||
return isPoS; | ||
} | ||
|
||
public LineaParameters getLineaParameters() { | ||
return lineaParameters; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. as described before, we can replace this with |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adapt the description to block max calldata size