Skip to content

Remove use of blockchain processor in RPC#9021

Merged
asdacap merged 3 commits into
masterfrom
cleanup/remove-use-of-branchprocessor-in-rpc
Aug 11, 2025
Merged

Remove use of blockchain processor in RPC#9021
asdacap merged 3 commits into
masterfrom
cleanup/remove-use-of-branchprocessor-in-rpc

Conversation

@asdacap

@asdacap asdacap commented Jul 21, 2025

Copy link
Copy Markdown
Contributor
  • Required Fix/some simulate call #8989
  • RPC modules which uses IOverridableEnv have a well defined world scope that it execute within.
  • Problem is, it then call IBlockchainProcessor, which then call IBranchProcessor, which then re-set the state, making it an unclear responsibility who is suppose to handle the state.
  • This PR try to address it by finding the remaining caller of IBlockchainProcessor that already have IOverridableScope to call a new class BlockchainProcessorFacade which try to call IBlockProcessor directly without re-setting the state.
  • Note, this PR try to keep existing behaviour, no matter how weird.

Types of changes

What types of changes does your code introduce?

  • Refactoring

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Notes on testing

  • Mainnet can sync as always.
  • I don't know I'll find a hive test somewhere.

@asdacap asdacap force-pushed the feature/separate-branch-and-block-processor branch from e8b5c4e to c2e847b Compare July 23, 2025 12:26
@asdacap asdacap force-pushed the cleanup/remove-use-of-branchprocessor-in-rpc branch from 59803a0 to 8694204 Compare July 23, 2025 12:26
@asdacap asdacap mentioned this pull request Jul 23, 2025
8 tasks
@benaadams benaadams requested a review from Copilot July 26, 2025 13:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the blockchain processing architecture to remove the use of IBlockchainProcessor in RPC modules that already have well-defined world scopes via IOverridableEnv. The refactoring introduces a new BlockchainProcessorFacade class that calls IBlockProcessor directly without resetting state, addressing unclear responsibility for state management between components.

Key changes include:

  • Introducing BlockchainProcessorFacade to replace IBlockchainProcessor in RPC contexts
  • Updating trace execution to use parent block headers for proper state management
  • Refactoring simulation logic to improve gas handling and transaction processing
  • Updating test expectations to reflect the behavioral changes

Reviewed Changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
TraceRpcModule.cs Updates trace methods to use parent block headers and new ExecuteBlock signature
BlockchainProcessorFacade.cs New facade class that wraps IBlockProcessor without state management
SimulateBridgeHelper.cs Major refactoring of simulation logic for better gas cap handling and state management
SimulateTxMutatorTracer.cs Updates transaction hash handling to use transaction object instead of hash
GethStyleTracer.cs Updates to use parent block headers for proper state context

Comment on lines 33 to 34
{
Scope<T> BuildAndOverride(BlockHeader? header);

Copilot AI Jul 26, 2025

Copy link

Choose a reason for hiding this comment

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

The parameter name 'header' should be nullable-aware since the signature change makes it optional. Consider updating the parameter documentation or validation to clarify when null headers are acceptable.

Suggested change
{
Scope<T> BuildAndOverride(BlockHeader? header);
{
/// <summary>
/// Builds and overrides the environment with the specified block header and state overrides.
/// </summary>
/// <param name="header">
/// The block header to use for the override. If <c>null</c>, the method will use a default or fallback behavior.
/// </param>
/// <param name="stateOverride">
/// A dictionary of state overrides to apply. Can be <c>null</c> if no state overrides are needed.
/// </param>
/// <returns>A scope containing the overridden environment and the specified component.</returns>
Scope<T> BuildAndOverride(BlockHeader? header);
/// <summary>
/// Builds and overrides the environment with the specified block header and state overrides.
/// </summary>
/// <param name="header">
/// The block header to use for the override. If <c>null</c>, the method will use a default or fallback behavior.
/// </param>
/// <param name="stateOverride">
/// A dictionary of state overrides to apply. Can be <c>null</c> if no state overrides are needed.
/// </param>
/// <returns>A scope containing the overridden environment and the specified component.</returns>

Copilot uses AI. Check for mistakes.
Comment on lines +320 to +325
if (!stateReader.HasStateForBlock(parentSearch.Object))
{
return GetStateFailureResult<IEnumerable<ParityTxTraceFromStore>>(block.Header);
return GetStateFailureResult<IEnumerable<ParityTxTraceFromStore>>(parentSearch.Object);
}

IReadOnlyCollection<ParityLikeTxTrace> txTrace = ExecuteBlock(block, new(txHash, ParityTraceTypes.Trace));
IReadOnlyCollection<ParityLikeTxTrace> txTrace = ExecuteBlock(parentSearch.Object!, block, new(txHash, ParityTraceTypes.Trace));

Copilot AI Jul 26, 2025

Copy link

Choose a reason for hiding this comment

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

Using null-forgiving operator (!) on parentSearch.Object is unsafe. The previous error check only validates parentSearch.IsError, but doesn't guarantee the Object is non-null.

Copilot uses AI. Check for mistakes.
Transaction tx = callTransactionModel.ToTransaction();

// The RPC set SystemUser as default, but we want to set it to zero to follow hive test.
if (tx.SenderAddress == Address.SystemUser) tx.SenderAddress = Address.Zero;

Copilot AI Jul 26, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] This hardcoded address override with a comment referencing 'hive test' suggests implementation-specific behavior. Consider using a configuration flag or making this behavior more explicit.

Copilot uses AI. Check for mistakes.
ulong txIndex)
{
_txHash = txHash;
// Note: Tx hash will be mutated as tx is modified while processing block

Copilot AI Jul 26, 2025

Copy link

Choose a reason for hiding this comment

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

The comment indicates transaction hash mutation during block processing, but this could lead to inconsistent state. Consider documenting why this mutation is necessary and when it occurs.

Suggested change
// Note: Tx hash will be mutated as tx is modified while processing block
// Note: Tx hash will be mutated as tx is modified while processing block.
// This mutation is necessary because the transaction object is reused and modified
// during the simulation process to reflect changes in state. The hash is recalculated
// to ensure consistency with the modified transaction data. This approach avoids
// creating multiple copies of the transaction object, which could be inefficient.
// However, care must be taken to ensure that the mutation does not lead to
// inconsistencies or unexpected behavior in other parts of the system. The mutation
// is controlled and occurs only during the simulation process, where the transaction
// object is not shared with other components.

Copilot uses AI. Check for mistakes.

// For some reason, the logs from geth when processing the block is missing but not in the output from tracer.
// this cause the receipt root to be different than us. So we simulate it here.
txReceipt.Logs = [];

Copilot AI Jul 26, 2025

Copy link

Choose a reason for hiding this comment

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

Clearing receipt logs with a comment about geth compatibility seems like a workaround. This could cause issues with log-dependent functionality and should be documented more thoroughly or made configurable.

Copilot uses AI. Check for mistakes.
IEnumerable<Address> senders = blockStateCall.Calls?.Select(static details => details.Transaction.SenderAddress) ?? [];
IEnumerable<Address> targets = blockStateCall.Calls?.Select(static details => details.Transaction.To!) ?? [];
foreach (Address address in senders.Union(targets).Where(static t => t is not null))
{

Copilot AI Jul 26, 2025

Copy link

Choose a reason for hiding this comment

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

The change from nonce 1 to 0 appears intentional but lacks documentation. Consider adding a comment explaining why nonce 0 is now used instead of 1.

Suggested change
{
{
// Using nonce 0 for account creation to ensure a clean state for simulation purposes.
// This is intentional and aligns with the requirements of the simulation framework.

Copilot uses AI. Check for mistakes.
@asdacap asdacap force-pushed the feature/separate-branch-and-block-processor branch from c2e847b to 9295fce Compare July 27, 2025 01:30
Base automatically changed from feature/separate-branch-and-block-processor to master July 29, 2025 07:18
@asdacap asdacap force-pushed the cleanup/remove-use-of-branchprocessor-in-rpc branch from 8694204 to 91e14bd Compare August 1, 2025 12:07
Comment thread src/Nethermind/Nethermind.JsonRpc/Modules/Trace/TraceRpcModule.cs
@asdacap asdacap merged commit 037fe3c into master Aug 11, 2025
77 checks passed
@asdacap asdacap deleted the cleanup/remove-use-of-branchprocessor-in-rpc branch August 11, 2025 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants