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

Fix gas fees accounting in TransactionProcessor.Trace #5743

Merged

Conversation

deffrian
Copy link
Contributor

@deffrian deffrian commented May 31, 2023

Fixes Closes Resolves #
#5680

Changes

  • Now some of trace_* functions use Execute instead of trace.
  • Do not refund in noValidation mode

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

@deffrian deffrian linked an issue May 31, 2023 that may be closed by this pull request
@@ -241,7 +241,7 @@ public void Trace(Transaction transaction, BlockHeader block, ITxTracer txTracer
}
}

UInt256 senderReservedGasPayment = noValidation ? UInt256.Zero : (ulong)gasLimit * effectiveGasPrice;
UInt256 senderReservedGasPayment = (ulong)gasLimit * effectiveGasPrice;
Copy link
Member

Choose a reason for hiding this comment

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

Can you write an explanation for TransactionProcessor changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How it works right now:

  1. If noValidation subtract zero(senderReservedGasPayment) as gas fee
  2. Refund gas. So if noValidation we refund gas that we didn't take.

After the fix:

  1. If noValidation do not subtract gas fee at all
  2. Refund only if noValidation is false. This fixes mentioned above issue

Another issue:
Right now Trace function uses noValidation, so we don't charge gas from account during trace. And as we discussed this behavior shouldn't be changed.
When we execute trace_replayBlock or trace_replayTransaction not charging fees causes inconsistency between chain state and stat that we get in trace. So I changed these functions to use Execute instead of Trace.

Comment on lines +50 to +53
public void Trace(Block block, IBlockTracer tracer) => Process(block, tracer, _traceProcessor);

public void Execute(Block block, IBlockTracer tracer) => Process(block, tracer, _executeProcessor);

Copy link
Member

Choose a reason for hiding this comment

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

Why do we need separated processors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wrote under previous comment

@@ -118,7 +118,7 @@ protected TestAllTracerWithOutput Execute(long blockNumber, long gasLimit, byte[
protected (Block block, Transaction transaction) PrepareTx(
long blockNumber,
long gasLimit,
byte[] code,
byte[] code = null,
Copy link
Member

Choose a reason for hiding this comment

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

mark it nullable

Comment on lines +21 to +28
void Trace(Block block, IBlockTracer tracer);

/// <summary>
/// Allows to trace and verify arbitrary constructed block. Subtracts gas from sender account
/// </summary>
/// <param name="block">Block to trace.</param>
/// <param name="tracer">Trace to act on block processing events.</param>
void Execute(Block block, IBlockTracer tracer);
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a write-up (maybe in which JSON RPC uses which and why)

Nikita Mescheryakov added 2 commits June 8, 2023 19:38
@deffrian deffrian merged commit e4c949d into master Jun 9, 2023
@deffrian deffrian deleted the 5680-trace_replayblocktransactions-insufficient-funds branch June 9, 2023 12:05
@benaadams benaadams added the bug label Jun 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

trace_replayBlockTransactions insufficient funds for transfer
3 participants