mirror of https://github.com/hyperledger/besu
Collapse Transaction Validator (#1548)
Moves TransactionInvalidReason to top level so it can be accessed by privacy code while also allowing the TransactionValidator to be collapsed as it's only used on the permissionless side. Signed-off-by: Ratan Rai Sur <ratan.r.sur@gmail.com>pull/1560/head
parent
4ff73342b6
commit
9062140452
@ -1,93 +0,0 @@ |
||||
/* |
||||
* Copyright ConsenSys AG. |
||||
* |
||||
* 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.ethereum.mainnet; |
||||
|
||||
import org.hyperledger.besu.ethereum.core.Account; |
||||
import org.hyperledger.besu.ethereum.core.Transaction; |
||||
import org.hyperledger.besu.ethereum.core.TransactionFilter; |
||||
|
||||
import java.util.Optional; |
||||
|
||||
/** Validates transaction based on some criteria. */ |
||||
public interface TransactionValidator { |
||||
|
||||
/** |
||||
* Asserts whether a transaction is valid. |
||||
* |
||||
* @param transaction the transaction to validate |
||||
* @param baseFee optional baseFee |
||||
* @return An empty @{link Optional} if the transaction is considered valid; otherwise an @{code |
||||
* Optional} containing a {@link TransactionInvalidReason} that identifies why the transaction |
||||
* is invalid. |
||||
*/ |
||||
ValidationResult<TransactionInvalidReason> validate( |
||||
Transaction transaction, Optional<Long> baseFee); |
||||
|
||||
/** |
||||
* Asserts whether a transaction is valid for the sender accounts current state. |
||||
* |
||||
* <p>Note: {@code validate} should be called before getting the sender {@link Account} used in |
||||
* this method to ensure that a sender can be extracted from the {@link Transaction}. |
||||
* |
||||
* @param transaction the transaction to validateMessageFrame.State.COMPLETED_FAILED |
||||
* @param sender the sender account state to validate against |
||||
* @param allowFutureNonce if true, transactions with nonce equal or higher than the account nonce |
||||
* will be considered valid (used when received transactions in the transaction pool). If |
||||
* false, only a transaction with the nonce equals the account nonce will be considered valid |
||||
* (used when processing transactions). |
||||
* @return An empty @{link Optional} if the transaction is considered valid; otherwise an @{code |
||||
* Optional} containing a {@link TransactionInvalidReason} that identifies why the transaction |
||||
* is invalid. |
||||
*/ |
||||
default ValidationResult<TransactionInvalidReason> validateForSender( |
||||
final Transaction transaction, final Account sender, final boolean allowFutureNonce) { |
||||
final TransactionValidationParams validationParams = |
||||
new TransactionValidationParams.Builder().allowFutureNonce(allowFutureNonce).build(); |
||||
return validateForSender(transaction, sender, validationParams); |
||||
} |
||||
|
||||
ValidationResult<TransactionInvalidReason> validateForSender( |
||||
Transaction transaction, Account sender, TransactionValidationParams validationParams); |
||||
|
||||
void setTransactionFilter(TransactionFilter transactionFilter); |
||||
|
||||
enum TransactionInvalidReason { |
||||
WRONG_CHAIN_ID, |
||||
REPLAY_PROTECTED_SIGNATURES_NOT_SUPPORTED, |
||||
INVALID_SIGNATURE, |
||||
UPFRONT_COST_EXCEEDS_BALANCE, |
||||
NONCE_TOO_LOW, |
||||
INCORRECT_NONCE, |
||||
INTRINSIC_GAS_EXCEEDS_GAS_LIMIT, |
||||
EXCEEDS_BLOCK_GAS_LIMIT, |
||||
TX_SENDER_NOT_AUTHORIZED, |
||||
CHAIN_HEAD_WORLD_STATE_NOT_AVAILABLE, |
||||
EXCEEDS_PER_TRANSACTION_GAS_LIMIT, |
||||
INVALID_TRANSACTION_FORMAT, |
||||
TRANSACTION_PRICE_TOO_LOW, |
||||
TRANSACTION_ALREADY_KNOWN, |
||||
TRANSACTION_REPLACEMENT_UNDERPRICED, |
||||
// Private Transaction Invalid Reasons
|
||||
PRIVATE_TRANSACTION_FAILED, |
||||
PRIVATE_NONCE_TOO_LOW, |
||||
OFFCHAIN_PRIVACY_GROUP_DOES_NOT_EXIST, |
||||
INCORRECT_PRIVATE_NONCE, |
||||
GAS_PRICE_TOO_LOW, |
||||
TX_FEECAP_EXCEEDED, |
||||
PRIVATE_VALUE_NOT_ZERO, |
||||
PRIVATE_UNIMPLEMENTED_TRANSACTION_TYPE, |
||||
INTERNAL_ERROR; |
||||
} |
||||
} |
@ -0,0 +1,46 @@ |
||||
/* |
||||
* |
||||
* * Copyright ConsenSys AG. |
||||
* * |
||||
* * 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.ethereum.transaction; |
||||
|
||||
public enum TransactionInvalidReason { |
||||
WRONG_CHAIN_ID, |
||||
REPLAY_PROTECTED_SIGNATURES_NOT_SUPPORTED, |
||||
INVALID_SIGNATURE, |
||||
UPFRONT_COST_EXCEEDS_BALANCE, |
||||
NONCE_TOO_LOW, |
||||
INCORRECT_NONCE, |
||||
INTRINSIC_GAS_EXCEEDS_GAS_LIMIT, |
||||
EXCEEDS_BLOCK_GAS_LIMIT, |
||||
TX_SENDER_NOT_AUTHORIZED, |
||||
CHAIN_HEAD_WORLD_STATE_NOT_AVAILABLE, |
||||
EXCEEDS_PER_TRANSACTION_GAS_LIMIT, |
||||
INVALID_TRANSACTION_FORMAT, |
||||
TRANSACTION_PRICE_TOO_LOW, |
||||
TRANSACTION_ALREADY_KNOWN, |
||||
TRANSACTION_REPLACEMENT_UNDERPRICED, |
||||
// Private Transaction Invalid Reasons
|
||||
PRIVATE_TRANSACTION_FAILED, |
||||
PRIVATE_NONCE_TOO_LOW, |
||||
OFFCHAIN_PRIVACY_GROUP_DOES_NOT_EXIST, |
||||
INCORRECT_PRIVATE_NONCE, |
||||
GAS_PRICE_TOO_LOW, |
||||
TX_FEECAP_EXCEEDED, |
||||
PRIVATE_VALUE_NOT_ZERO, |
||||
PRIVATE_UNIMPLEMENTED_TRANSACTION_TYPE, |
||||
INTERNAL_ERROR; |
||||
} |
Loading…
Reference in new issue