diff --git a/prdoc/pr_12220.prdoc b/prdoc/pr_12220.prdoc new file mode 100644 index 0000000000000..6442a6f63809d --- /dev/null +++ b/prdoc/pr_12220.prdoc @@ -0,0 +1,10 @@ +title: 'pallet-revive eth-rpc: make SubmittedTransaction::gas() return Option' +doc: +- audience: Node Dev + description: |- + closes #11889 + + Change `SubmittedTransaction::gas()` to return `Option` 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 diff --git a/substrate/frame/revive/rpc/examples/deploy.rs b/substrate/frame/revive/rpc/examples/deploy.rs index ac3a8ce07d7fb..2c835e3607a6c 100644 --- a/substrate/frame/revive/rpc/examples/deploy.rs +++ b/substrate/frame/revive/rpc/examples/deploy.rs @@ -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?; @@ -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(()) } diff --git a/substrate/frame/revive/rpc/src/example.rs b/substrate/frame/revive/rpc/src/example.rs index 1ae77e887ec4f..c4b6ee75c81e3 100644 --- a/substrate/frame/revive/rpc/src/example.rs +++ b/substrate/frame/revive/rpc/src/example.rs @@ -54,9 +54,12 @@ impl SubmittedTransaction { 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 { + self.tx.gas } pub fn generic_transaction(&self) -> GenericTransaction { @@ -79,12 +82,14 @@ impl SubmittedTransaction { pub async fn wait_for_receipt(&self) -> anyhow::Result { 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:?}")