Skip to content

Commit

Permalink
Direct fail create tx rather than throwing exceptions (#7436)
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams authored Sep 16, 2024
1 parent 6d5f7e7 commit f601699
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,7 @@ protected virtual void ExecuteEvmCall(

if (substate.ShouldRevert || substate.IsError)
{
if (Logger.IsTrace)
Logger.Trace("Restoring state from before transaction");
if (Logger.IsTrace) Logger.Trace("Restoring state from before transaction");
WorldState.Restore(snapshot);
}
else
Expand All @@ -539,12 +538,12 @@ protected virtual void ExecuteEvmCall(
long codeDepositGasCost = CodeDepositHandler.CalculateCost(substate.Output.Length, spec);
if (unspentGas < codeDepositGasCost && spec.ChargeForTopLevelCreate)
{
ThrowOutOfGasException();
goto Fail;
}

if (CodeDepositHandler.CodeIsInvalid(spec, substate.Output))
{
ThrowInvalidCodeException();
goto Fail;
}

if (unspentGas >= codeDepositGasCost)
Expand Down Expand Up @@ -572,13 +571,17 @@ protected virtual void ExecuteEvmCall(
}

spentGas = Refund(tx, header, spec, opts, substate, unspentGas, env.TxExecutionContext.GasPrice);
goto Complete;
}
catch (Exception ex) when (ex is EvmException or OverflowException) // TODO: OverflowException? still needed? hope not
{
if (Logger.IsTrace) Logger.Trace($"EVM EXCEPTION: {ex.GetType().Name}:{ex.Message}");
WorldState.Restore(snapshot);
}
Fail:
if (Logger.IsTrace) Logger.Trace("Restoring state from before transaction");
WorldState.Restore(snapshot);

Complete:
if (!opts.HasFlag(ExecutionOptions.NoValidation))
header.GasUsed += spentGas;
}
Expand Down Expand Up @@ -649,14 +652,6 @@ protected virtual long Refund(Transaction tx, BlockHeader header, IReleaseSpec s
[StackTraceHidden]
private static void ThrowInvalidDataException(string message) => throw new InvalidDataException(message);

[DoesNotReturn]
[StackTraceHidden]
private static void ThrowInvalidCodeException() => throw new InvalidCodeException();

[DoesNotReturn]
[StackTraceHidden]
private static void ThrowOutOfGasException() => throw new OutOfGasException();

[DoesNotReturn]
[StackTraceHidden]
private static void ThrowTransactionCollisionException() => throw new TransactionCollisionException();
Expand Down

0 comments on commit f601699

Please sign in to comment.