Skip to content
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

Fix eth RPC call context and fix gas estimate pipeline #2633

Merged
merged 16 commits into from
Oct 31, 2023
48 changes: 36 additions & 12 deletions lib/ain-grpc/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,57 @@ use ain_evm::EVMError;
use jsonrpsee::core::Error;

pub enum RPCError {
EvmCall(EVMError),
AccountError,
BlockNotFound,
Error(Box<dyn std::error::Error>),
EvmError(EVMError),
FromBlockGreaterThanToBlock,
GasCapTooLow(u64),
InsufficientFunds,
ValueOverflow,
InvalidBlockInput,
InvalidDataInput,
InvalidLogFilter,
InvalidGasPrice,
InvalidTransactionMessage,
InvalidTransactionType,
InvalidDataInput,
NonceCacheError,
StateRootNotFound,
TxExecutionFailed,
GasCapTooLow(u64),
ValueOverflow,
}

impl From<RPCError> for Error {
fn from(e: RPCError) -> Self {
match e {
RPCError::EvmCall(e) => Error::Custom(format!("error calling EVM : {e:?}")),
RPCError::AccountError => to_custom_err("error getting account"),
RPCError::BlockNotFound => to_custom_err("block not found"),
sieniven marked this conversation as resolved.
Show resolved Hide resolved
RPCError::Error(e) => Error::Custom(format!("{e:?}")),
RPCError::EvmError(e) => Error::Custom(format!("error calling EVM : {e:?}")),
RPCError::FromBlockGreaterThanToBlock => {
to_custom_err("fromBlock is greater than toBlock")
}
RPCError::GasCapTooLow(cap) => {
Error::Custom(format!("gas required exceeds allowance {:#?}", cap))
}
RPCError::InsufficientFunds => to_custom_err("insufficient funds for transfer"),
RPCError::ValueOverflow => to_custom_err("value overflow"),
RPCError::InvalidGasPrice => {
to_custom_err("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
RPCError::InvalidBlockInput => {
to_custom_err("both blockHash and fromBlock/toBlock specified")
}
RPCError::InvalidTransactionType => to_custom_err("invalid transaction type specified"),
RPCError::InvalidDataInput => {
to_custom_err("data and input fields are mutually exclusive")
}
RPCError::TxExecutionFailed => to_custom_err("transaction execution failed"),
RPCError::GasCapTooLow(cap) => {
Error::Custom(format!("gas required exceeds allowance {:#?}", cap))
RPCError::InvalidGasPrice => {
to_custom_err("both gasPrice and (maxFeePerGas or maxPriorityFeePerGas) specified")
}
RPCError::InvalidLogFilter => to_custom_err("invalid log filter"),
RPCError::InvalidTransactionMessage => {
to_custom_err("invalid transaction message parameters")
}
RPCError::InvalidTransactionType => to_custom_err("invalid transaction type specified"),
RPCError::NonceCacheError => to_custom_err("could not cache account nonce"),
RPCError::StateRootNotFound => to_custom_err("state root not found"),
RPCError::TxExecutionFailed => to_custom_err("transaction execution failed"),
RPCError::ValueOverflow => to_custom_err("value overflow"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ain-grpc/src/rpc/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl MetachainDebugRPCServer for MetachainDebugRPCModule {
access_list: call.access_list.unwrap_or_default(),
block_number,
})
.map_err(RPCError::EvmCall)?;
.map_err(RPCError::EvmError)?;

let used_gas = U256::from(used_gas);
let gas_fee = used_gas
Expand Down
Loading