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

evm: Return effective gas price in eth_getTransaction #2496

Merged
merged 6 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 45 additions & 8 deletions lib/ain-grpc/src/rpc/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,15 @@ pub trait MetachainRPC {
fn get_transaction_by_block_hash_and_index(
&self,
hash: H256,
index: usize,
index: U256,
) -> RpcResult<Option<EthTransactionInfo>>;

/// Retrieves a specific transaction, identified by the block number and transaction index.
#[method(name = "getTransactionByBlockNumberAndIndex")]
fn get_transaction_by_block_number_and_index(
&self,
block_number: U256,
index: usize,
index: U256,
) -> RpcResult<Option<EthTransactionInfo>>;

/// Retrieves the list of pending transactions.
Expand Down Expand Up @@ -514,6 +514,7 @@ impl MetachainRPCServer for MetachainRPCModule {
transaction_info.block_number = Some(format_u256(receipt.block_number));
transaction_info.transaction_index =
Some(format_u256(U256::from(receipt.tx_index)));
transaction_info.gas_price = format_u256(receipt.effective_gas_price)
}

Ok(Some(transaction_info))
Expand All @@ -534,29 +535,65 @@ impl MetachainRPCServer for MetachainRPCModule {
fn get_transaction_by_block_hash_and_index(
&self,
hash: H256,
index: usize,
index: U256,
) -> RpcResult<Option<EthTransactionInfo>> {
self.handler
.storage
.get_transaction_by_block_hash_and_index(&hash, index)
.get_transaction_by_block_hash_and_index(&hash, index.as_usize())
.map_err(to_jsonrpsee_custom_error)?
.map_or(Ok(None), |tx| {
let transaction_info = tx.try_into().map_err(to_jsonrpsee_custom_error)?;
let tx_hash = &tx.hash();
let mut transaction_info: EthTransactionInfo =
tx.try_into().map_err(to_jsonrpsee_custom_error)?;

// TODO: Improve efficiency by indexing the block_hash, block_number, and transaction_index fields.
// Temporary workaround: Makes an additional call to get_receipt where these fields are available.
if let Some(receipt) = self
.handler
.storage
.get_receipt(tx_hash)
.map_err(to_jsonrpsee_custom_error)?
{
transaction_info.block_hash = Some(format_h256(receipt.block_hash));
transaction_info.block_number = Some(format_u256(receipt.block_number));
transaction_info.transaction_index =
Some(format_u256(U256::from(receipt.tx_index)));
transaction_info.gas_price = format_u256(receipt.effective_gas_price)
}

Ok(Some(transaction_info))
})
}

fn get_transaction_by_block_number_and_index(
&self,
number: U256,
index: usize,
index: U256,
) -> RpcResult<Option<EthTransactionInfo>> {
self.handler
.storage
.get_transaction_by_block_number_and_index(&number, index)
.get_transaction_by_block_number_and_index(&number, index.as_usize())
.map_err(to_jsonrpsee_custom_error)?
.map_or(Ok(None), |tx| {
let transaction_info = tx.try_into().map_err(to_jsonrpsee_custom_error)?;
let tx_hash = &tx.hash();
let mut transaction_info: EthTransactionInfo =
tx.try_into().map_err(to_jsonrpsee_custom_error)?;

// TODO: Improve efficiency by indexing the block_hash, block_number, and transaction_index fields.
// Temporary workaround: Makes an additional call to get_receipt where these fields are available.
if let Some(receipt) = self
.handler
.storage
.get_receipt(tx_hash)
.map_err(to_jsonrpsee_custom_error)?
{
transaction_info.block_hash = Some(format_h256(receipt.block_hash));
transaction_info.block_number = Some(format_u256(receipt.block_number));
transaction_info.transaction_index =
Some(format_u256(U256::from(receipt.tx_index)));
transaction_info.gas_price = format_u256(receipt.effective_gas_price)
}

Ok(Some(transaction_info))
})
}
Expand Down
1 change: 1 addition & 0 deletions lib/ain-grpc/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ impl EthTransactionInfo {
block_hash: Some(format_h256(block.header.hash())),
block_number: Some(format_u256(block.header.number)),
transaction_index: Some(format_u256(U256::from(index))),
gas_price: format_u256(signed_tx.effective_gas_price(block.header.base_fee)),
..EthTransactionInfo::from(signed_tx)
})
}
Expand Down