Skip to content

Commit

Permalink
Merge pull request #1465 from oasisprotocol/kostko/fix/subcall-gas-ev…
Browse files Browse the repository at this point in the history
…ents

runtime-sdk: Do not emit gas used events for subcalls
  • Loading branch information
kostko committed Aug 28, 2023
2 parents d63fe96 + e42ec8a commit eb97a81
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
11 changes: 11 additions & 0 deletions runtime-sdk/modules/evm/src/precompile/subcall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,17 @@ mod test {
assert_eq!(event.from, Address::from_eth(contract_address.as_ref()));
assert_eq!(event.to, keys::alice::address());
assert_eq!(event.amount, BaseUnits::new(1_000, Denomination::NATIVE));

// Make sure only one gas used event was emitted (e.g. subcall should not emit its own gas
// used events).
#[derive(Debug, Default, cbor::Decode)]
struct GasUsedEvent {
amount: u64,
}

let events: Vec<GasUsedEvent> = cbor::from_slice(&tags[1].value).unwrap();
assert_eq!(events.len(), 1); // Just one gas used event.
assert_eq!(events[0].amount, 25742);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions runtime-sdk/src/modules/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,8 @@ impl<Cfg: Config> module::TransactionHandler for Module<Cfg> {
ctx: &mut C,
result: module::CallResult,
) -> Result<module::CallResult, Error> {
// Emit gas used event.
if Cfg::EMIT_GAS_USED_EVENTS {
// Emit gas used event (if this is not an internally generated call).
if Cfg::EMIT_GAS_USED_EVENTS && !ctx.is_internal() {
let used_gas = Self::used_tx_gas(ctx);
ctx.emit_unconditional_event(Event::GasUsed { amount: used_gas });
}
Expand Down

0 comments on commit eb97a81

Please sign in to comment.