Skip to content
Open
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
10 changes: 10 additions & 0 deletions prdoc/pr_12220.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: 'pallet-revive eth-rpc: make SubmittedTransaction::gas() return Option<U256>'
doc:
- audience: Node Dev
description: |-
closes #11889

Change `SubmittedTransaction::gas()` to return `Option<U256>` mirroring the underlying `GenericTransaction::gas` field, and skip the `wait_for_receipt` gas-limit assertion when no gas limit is set, removing the panic that occurred on legacy/incomplete payloads.
crates:
- name: pallet-revive-eth-rpc
bump: major
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised that this example code module is even public. @pgherveou do you know any reason?

4 changes: 2 additions & 2 deletions substrate/frame/revive/rpc/examples/deploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async fn main() -> anyhow::Result<()> {

println!("Receipt:");
println!("- Block number: {block_number}");
println!("- Gas estimated: {}", tx.gas());
println!("- Gas estimated: {:?}", tx.gas());
println!("- Gas used: {gas_used}");
println!("- Contract address: {contract_address:?}");
let balance = client.get_balance(contract_address, BlockTag::Latest.into()).await?;
Expand All @@ -76,7 +76,7 @@ async fn main() -> anyhow::Result<()> {
println!("Receipt:");
println!("- Block number: {block_number}");
println!("- Gas used: {gas_used}");
println!("- Gas estimated: {}", tx.gas());
println!("- Gas estimated: {:?}", tx.gas());
println!("- To: {to:?}");
Ok(())
}
23 changes: 14 additions & 9 deletions substrate/frame/revive/rpc/src/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ impl<Client: EthRpcClient + Sync + Send> SubmittedTransaction<Client> {
self.hash
}

/// The gas sent with the transaction.
pub fn gas(&self) -> U256 {
self.tx.gas.unwrap()
/// The gas limit sent with the transaction, if one was specified.
///
/// This mirrors [`GenericTransaction::gas`], which is optional for legacy/incomplete
/// payloads, so it can be `None`.
pub fn gas(&self) -> Option<U256> {
self.tx.gas
}

pub fn generic_transaction(&self) -> GenericTransaction {
Expand All @@ -79,12 +82,14 @@ impl<Client: EthRpcClient + Sync + Send> SubmittedTransaction<Client> {
pub async fn wait_for_receipt(&self) -> anyhow::Result<ReceiptInfo> {
let receipt = self.wait_for_receipt_any().await?;
if receipt.is_success() {
assert!(
self.gas() >= receipt.gas_used,
"Gas used {:?} should be less than or equal to gas limit {:?}",
receipt.gas_used,
self.gas()
);
if let Some(gas) = self.gas() {
assert!(
gas >= receipt.gas_used,
"Gas used {:?} should be less than or equal to gas limit {:?}",
receipt.gas_used,
gas
);
}
Ok(receipt)
} else {
anyhow::bail!("Transaction failed receipt: {receipt:?}")
Expand Down
Loading