-
Notifications
You must be signed in to change notification settings - Fork 459
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
Support for state override parameter in some RPC methods #7362
Changes from all commits
8c5f8ee
5343927
d97caa4
264056f
3c19b09
aeaf7f0
c8fa006
37eb5e3
9a7094d
94c2618
eb3700a
58886b6
76eea55
1dee3c0
363fdc9
51d6aa6
3e5f964
4de78ab
3e1d83a
18825c8
d900a5a
95fb2ed
b4df9a7
8cbbe33
e078fcf
8930eba
4f9383d
5bf6c58
bd28e70
a1bd302
f8d8137
15f0e39
f05b7d2
cc3cb4c
82d7345
df1e146
e35f7e4
c902a07
d4f75c5
8b2bb68
606b569
3c3f6b0
dc9de8e
eba8bf0
4ee4658
9c0244b
023ab9c
d01cf9c
e15e625
4596308
acefb56
b0ce7d4
531cbe8
5758a4f
34b27a3
fe60977
c82c8f3
3e683cf
1651413
e935178
a54ac71
78c379f
e0563c3
4c39610
b70931b
fd5efaa
d7a8e8c
0650883
2754255
63f0c9f
4e307c7
2a2e66d
a5385c6
5072a6f
086e5b5
54b3e89
bdf2c84
aba3e6b
b6b656a
e872c4e
5d37f8b
4d82942
92644b5
2fa1c8e
92809ff
8c8a6a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Nethermind.Blockchain; | ||
using Nethermind.Core; | ||
using Nethermind.Core.Crypto; | ||
using Nethermind.Core.Specs; | ||
using Nethermind.Evm; | ||
using Nethermind.Evm.TransactionProcessing; | ||
using Nethermind.Logging; | ||
using Nethermind.State; | ||
|
||
namespace Nethermind.Consensus.Processing; | ||
|
||
public class OverridableTxProcessingEnv : ReadOnlyTxProcessingEnvBase, IOverridableTxProcessorSource | ||
{ | ||
private readonly Lazy<ITransactionProcessor> _transactionProcessorLazy; | ||
|
||
protected new OverridableWorldState StateProvider { get; } | ||
protected OverridableWorldStateManager WorldStateManager { get; } | ||
protected OverridableCodeInfoRepository CodeInfoRepository { get; } | ||
protected IVirtualMachine Machine { get; } | ||
protected ITransactionProcessor TransactionProcessor => _transactionProcessorLazy.Value; | ||
|
||
public OverridableTxProcessingEnv( | ||
OverridableWorldStateManager worldStateManager, | ||
IReadOnlyBlockTree readOnlyBlockTree, | ||
ISpecProvider specProvider, | ||
ILogManager? logManager, | ||
IWorldState? worldStateToWarmUp = null | ||
) : base(worldStateManager, readOnlyBlockTree, specProvider, logManager, worldStateToWarmUp) | ||
{ | ||
WorldStateManager = worldStateManager; | ||
StateProvider = (OverridableWorldState)base.StateProvider; | ||
CodeInfoRepository = new(new CodeInfoRepository((worldStateToWarmUp as IPreBlockCaches)?.Caches.PrecompileCache)); | ||
Machine = new VirtualMachine(BlockhashProvider, specProvider, CodeInfoRepository, logManager); | ||
_transactionProcessorLazy = new(CreateTransactionProcessor); | ||
} | ||
|
||
protected virtual ITransactionProcessor CreateTransactionProcessor() => | ||
new TransactionProcessor(SpecProvider, StateProvider, Machine, CodeInfoRepository, LogManager); | ||
|
||
IOverridableTxProcessingScope IOverridableTxProcessorSource.Build(Hash256 stateRoot) => Build(stateRoot); | ||
|
||
public OverridableTxProcessingScope Build(Hash256 stateRoot) | ||
{ | ||
Hash256 originalStateRoot = StateProvider.StateRoot; | ||
StateProvider.StateRoot = stateRoot; | ||
return new(CodeInfoRepository, TransactionProcessor, StateProvider, originalStateRoot); | ||
} | ||
|
||
IOverridableTxProcessingScope IOverridableTxProcessorSource.BuildAndOverride(BlockHeader header, Dictionary<Address, AccountOverride>? stateOverride) | ||
{ | ||
OverridableTxProcessingScope scope = Build(header.StateRoot ?? throw new ArgumentException($"Block {header.Hash} state root is null", nameof(header))); | ||
if (stateOverride != null) | ||
{ | ||
scope.WorldState.ApplyStateOverrides(scope.CodeInfoRepository, stateOverride, SpecProvider.GetSpec(header), header.Number); | ||
header.StateRoot = scope.WorldState.StateRoot; | ||
} | ||
return scope; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Core.Crypto; | ||
using Nethermind.Evm; | ||
using Nethermind.Evm.TransactionProcessing; | ||
using Nethermind.State; | ||
|
||
namespace Nethermind.Consensus.Processing; | ||
|
||
public class OverridableTxProcessingScope( | ||
IOverridableCodeInfoRepository codeInfoRepository, | ||
ITransactionProcessor transactionProcessor, | ||
OverridableWorldState worldState, | ||
Hash256 originalStateRoot | ||
) : IOverridableTxProcessingScope | ||
{ | ||
public IOverridableCodeInfoRepository CodeInfoRepository => codeInfoRepository; | ||
public ITransactionProcessor TransactionProcessor => transactionProcessor; | ||
public IWorldState WorldState => worldState; | ||
|
||
public void Dispose() | ||
{ | ||
worldState.StateRoot = originalStateRoot; | ||
worldState.Reset(); | ||
worldState.ResetOverrides(); | ||
codeInfoRepository.ResetOverrides(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Core; | ||
using Nethermind.Core.Specs; | ||
using Nethermind.Evm.CodeAnalysis; | ||
using Nethermind.State; | ||
|
||
namespace Nethermind.Evm; | ||
|
||
public interface IOverridableCodeInfoRepository : ICodeInfoRepository | ||
{ | ||
void SetCodeOverwrite(IWorldState worldState, IReleaseSpec vmSpec, Address key, CodeInfo value, Address? redirectAddress = null); | ||
public void ResetOverrides(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,17 +7,16 @@ | |
using Nethermind.Core.Extensions; | ||
using Nethermind.Core.Specs; | ||
using Nethermind.Evm.CodeAnalysis; | ||
using Nethermind.Facade.Proxy.Models; | ||
using Nethermind.Int256; | ||
using Nethermind.State; | ||
|
||
namespace Nethermind.Facade; | ||
namespace Nethermind.Evm; | ||
|
||
public static class StateOverridesExtensions | ||
{ | ||
public static void ApplyStateOverrides( | ||
this IWorldState state, | ||
OverridableCodeInfoRepository overridableCodeInfoRepository, | ||
IOverridableCodeInfoRepository overridableCodeInfoRepository, | ||
Dictionary<Address, AccountOverride>? overrides, | ||
IReleaseSpec spec, | ||
long blockNumber) | ||
|
@@ -69,13 +68,15 @@ void ApplyState(Dictionary<UInt256, Hash256> diff) | |
|
||
private static void UpdateCode( | ||
this IWorldState stateProvider, | ||
OverridableCodeInfoRepository overridableCodeInfoRepository, | ||
IOverridableCodeInfoRepository overridableCodeInfoRepository, | ||
IReleaseSpec currentSpec, | ||
AccountOverride accountOverride, | ||
Address address) | ||
{ | ||
if (accountOverride.Code is not null) | ||
{ | ||
stateProvider.InsertCode(address, accountOverride.Code, currentSpec); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is needed to prevent an There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @OlegJakushkin maybe this solves some issues on StateRoot in eth_simulate? |
||
|
||
overridableCodeInfoRepository.SetCodeOverwrite( | ||
stateProvider, | ||
currentSpec, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
namespace Nethermind.Evm.TransactionProcessing; | ||
|
||
public interface IOverridableTxProcessingScope : IReadOnlyTxProcessingScope | ||
{ | ||
IOverridableCodeInfoRepository CodeInfoRepository { get; } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't
Execute
be alwaysTrace
And
Trace
be alwaysTraceTransaction
And we don't need the parameters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When created in
TraceModuleFactory
,traceOptions
should beProcessingOptions.TraceTransactions
, so we don't rollback to previous block on some methods. ForProofRpcModule
/ProofModuleFactory
I decided to leave it as is for now - defaultProcessingOptions.Trace
.executeOptions
parameter was added just for the symmetry.