Search in sources :

Example 1 with TransactionValidationParams

use of org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams in project besu by hyperledger.

the class GoQuorumBlockProcessor method validateTransaction.

private ValidationResult<TransactionInvalidReason> validateTransaction(final BlockHeader blockHeader, final Transaction transaction, final WorldUpdater publicWorldStateUpdater) {
    final MainnetTransactionValidator transactionValidator = transactionProcessor.getTransactionValidator();
    final TransactionValidationParams transactionValidationParams = TransactionValidationParams.processingBlock();
    ValidationResult<TransactionInvalidReason> validationResult = transactionValidator.validate(transaction, blockHeader.getBaseFee(), transactionValidationParams);
    if (!validationResult.isValid()) {
        LOG.warn("Invalid transaction: {}. Block {} Transaction {}", validationResult.getErrorMessage(), blockHeader.getHash().toHexString(), transaction.getHash().toHexString());
        return validationResult;
    }
    final Address senderAddress = transaction.getSender();
    final EvmAccount sender = publicWorldStateUpdater.getOrCreate(senderAddress);
    validationResult = transactionValidator.validateForSender(transaction, sender, transactionValidationParams);
    if (!validationResult.isValid()) {
        LOG.warn("Invalid transaction: {}. Block {} Transaction {}", validationResult.getErrorMessage(), blockHeader.getHash().toHexString(), transaction.getHash().toHexString());
        return validationResult;
    }
    return ValidationResult.valid();
}
Also used : EvmAccount(org.hyperledger.besu.evm.account.EvmAccount) Address(org.hyperledger.besu.datatypes.Address) TransactionInvalidReason(org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason) MainnetTransactionValidator(org.hyperledger.besu.ethereum.mainnet.MainnetTransactionValidator) TransactionValidationParams(org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams)

Example 2 with TransactionValidationParams

use of org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams in project besu by hyperledger.

the class BlockTransactionSelector method validateTransaction.

private ValidationResult<TransactionInvalidReason> validateTransaction(final ProcessableBlockHeader blockHeader, final Transaction transaction, final WorldUpdater publicWorldStateUpdater) {
    final TransactionValidationParams transactionValidationParams = TransactionValidationParams.processingBlock();
    final MainnetTransactionValidator transactionValidator = transactionProcessor.getTransactionValidator();
    ValidationResult<TransactionInvalidReason> validationResult = transactionValidator.validate(transaction, blockHeader.getBaseFee(), transactionValidationParams);
    if (!validationResult.isValid()) {
        return validationResult;
    }
    final Address senderAddress = transaction.getSender();
    final EvmAccount sender = publicWorldStateUpdater.getOrCreate(senderAddress);
    validationResult = transactionValidator.validateForSender(transaction, sender, transactionValidationParams);
    return validationResult;
}
Also used : EvmAccount(org.hyperledger.besu.evm.account.EvmAccount) Address(org.hyperledger.besu.datatypes.Address) TransactionInvalidReason(org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason) MainnetTransactionValidator(org.hyperledger.besu.ethereum.mainnet.MainnetTransactionValidator) TransactionValidationParams(org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams)

Example 3 with TransactionValidationParams

use of org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams in project besu by hyperledger.

the class EthCallTest method internalAutoSelectIsAllowedExeecdBalance.

private void internalAutoSelectIsAllowedExeecdBalance(final JsonCallParameter callParameter, final Optional<Wei> baseFee, final boolean isAllowedExeedingBalance) {
    final JsonRpcRequestContext request = ethCallRequest(callParameter, "latest");
    BlockHeader blockHeader = mock(BlockHeader.class);
    when(blockHeader.getBaseFee()).thenReturn(baseFee);
    when(blockchainQueries.getBlockchain()).thenReturn(blockchain);
    when(blockchainQueries.getBlockchain().getChainHead()).thenReturn(chainHead);
    when(blockchainQueries.getBlockchain().getChainHead().getHash()).thenReturn(Hash.ZERO);
    when(blockchainQueries.getBlockHeaderByHash(Hash.ZERO)).thenReturn(Optional.of(blockHeader));
    method.response(request);
    TransactionValidationParams transactionValidationParams = ImmutableTransactionValidationParams.builder().from(TransactionValidationParams.transactionSimulator()).isAllowExceedingBalance(isAllowedExeedingBalance).build();
    verify(transactionSimulator).process(any(), eq(transactionValidationParams), any(), any());
}
Also used : JsonRpcRequestContext(org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext) BlockHeader(org.hyperledger.besu.ethereum.core.BlockHeader) TransactionValidationParams(org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams) ImmutableTransactionValidationParams(org.hyperledger.besu.ethereum.mainnet.ImmutableTransactionValidationParams)

Example 4 with TransactionValidationParams

use of org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams in project besu by hyperledger.

the class TransactionPoolTest method shouldCallValidatorWithExpectedValidationParameters.

@Test
public void shouldCallValidatorWithExpectedValidationParameters() {
    final ArgumentCaptor<TransactionValidationParams> txValidationParamCaptor = ArgumentCaptor.forClass(TransactionValidationParams.class);
    when(transactionValidator.validate(eq(transaction1), any(Optional.class), any())).thenReturn(valid());
    when(transactionValidator.validateForSender(any(), any(), txValidationParamCaptor.capture())).thenReturn(valid());
    final TransactionValidationParams expectedValidationParams = TransactionValidationParams.transactionPool();
    transactionPool.addLocalTransaction(transaction1);
    assertThat(txValidationParamCaptor.getValue()).usingRecursiveComparison().isEqualTo(expectedValidationParams);
}
Also used : Optional(java.util.Optional) TransactionValidationParams(org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams) Test(org.junit.Test)

Aggregations

TransactionValidationParams (org.hyperledger.besu.ethereum.mainnet.TransactionValidationParams)4 Address (org.hyperledger.besu.datatypes.Address)2 MainnetTransactionValidator (org.hyperledger.besu.ethereum.mainnet.MainnetTransactionValidator)2 TransactionInvalidReason (org.hyperledger.besu.ethereum.transaction.TransactionInvalidReason)2 EvmAccount (org.hyperledger.besu.evm.account.EvmAccount)2 Optional (java.util.Optional)1 JsonRpcRequestContext (org.hyperledger.besu.ethereum.api.jsonrpc.internal.JsonRpcRequestContext)1 BlockHeader (org.hyperledger.besu.ethereum.core.BlockHeader)1 ImmutableTransactionValidationParams (org.hyperledger.besu.ethereum.mainnet.ImmutableTransactionValidationParams)1 Test (org.junit.Test)1