Skip to content

Commit

Permalink
Code Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Demuirgos committed Jun 13, 2023
1 parent 156dc91 commit 7c35693
Show file tree
Hide file tree
Showing 26 changed files with 56 additions and 140 deletions.
3 changes: 1 addition & 2 deletions src/Nethermind/Ethereum.Test.Base/BlockchainTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ protected async Task<EthereumTestResult> RunTest(BlockchainTest test, Stopwatch?
stateProvider,
receiptStorage,
NullWitnessCollector.Instance,
_logManager,
blockTree);
_logManager);

IBlockchainProcessor blockchainProcessor = new BlockchainProcessor(
blockTree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,7 @@ protected override BlockProcessor CreateBlockProcessor()
State,
ReceiptStorage,
NullWitnessCollector.Instance,
LogManager,
BlockTree);
LogManager);

var parser = new AbiDefinitionParser();
parser.RegisterAbiTypeFactory(new AbiTuple<UserOperationAbi>());
Expand Down
77 changes: 15 additions & 62 deletions src/Nethermind/Nethermind.Blockchain.Test/BlockProcessorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
using Nethermind.Consensus.Withdrawals;
using Nethermind.Core.Test.Blockchain;
using Nethermind.Evm.TransactionProcessing;
using Nethermind.Core.Specs;
using Nethermind.Db.Blooms;
using Nethermind.State.Repositories;

namespace Nethermind.Blockchain.Test
{
Expand All @@ -41,24 +38,10 @@ public class BlockProcessorTests
[Test, Timeout(Timeout.MaxTestTime)]
public void Prepared_block_contains_author_field()
{
ISpecProvider specProvider = MainnetSpecProvider.Instance;
DbProvider dbProvider = new(DbModeHint.Mem);
dbProvider.RegisterDb(DbNames.BlockInfos, new MemDb());
dbProvider.RegisterDb(DbNames.Blocks, new MemDb());
dbProvider.RegisterDb(DbNames.Headers, new MemDb());
dbProvider.RegisterDb(DbNames.State, new MemDb());
dbProvider.RegisterDb(DbNames.Code, new MemDb());
dbProvider.RegisterDb(DbNames.Metadata, new MemDb());

TrieStore trieStore = new(dbProvider.GetDb<IDb>("stateDb"), LimboLogs.Instance);
IWorldState stateProvider = new WorldState(trieStore, dbProvider.GetDb<IDb>("codeDb"), LimboLogs.Instance);
BlockTree blockTree = new(
dbProvider,
new ChainLevelInfoRepository(dbProvider),
specProvider,
NullBloomStorage.Instance,
LimboLogs.Instance);

IDb stateDb = new MemDb();
IDb codeDb = new MemDb();
TrieStore trieStore = new(stateDb, LimboLogs.Instance);
IWorldState stateProvider = new WorldState(trieStore, codeDb, LimboLogs.Instance);
ITransactionProcessor transactionProcessor = Substitute.For<ITransactionProcessor>();
BlockProcessor processor = new(
RinkebySpecProvider.Instance,
Expand All @@ -68,8 +51,7 @@ public void Prepared_block_contains_author_field()
stateProvider,
NullReceiptStorage.Instance,
NullWitnessCollector.Instance,
LimboLogs.Instance,
blockTree);
LimboLogs.Instance);

BlockHeader header = Build.A.BlockHeader.WithAuthor(TestItem.AddressD).TestObject;
Block block = Build.A.Block.WithHeader(header).TestObject;
Expand All @@ -85,24 +67,11 @@ public void Prepared_block_contains_author_field()
[Test, Timeout(Timeout.MaxTestTime)]
public void Can_store_a_witness()
{
ISpecProvider specProvider = MainnetSpecProvider.Instance;
DbProvider dbProvider = new(DbModeHint.Mem);
dbProvider.RegisterDb(DbNames.BlockInfos, new MemDb());
dbProvider.RegisterDb(DbNames.Blocks, new MemDb());
dbProvider.RegisterDb(DbNames.Headers, new MemDb());
dbProvider.RegisterDb(DbNames.State, new MemDb());
dbProvider.RegisterDb(DbNames.Code, new MemDb());
dbProvider.RegisterDb(DbNames.Metadata, new MemDb());

TrieStore trieStore = new(dbProvider.GetDb<IDb>("stateDb"), LimboLogs.Instance);
BlockTree blockTree = new(
dbProvider,
new ChainLevelInfoRepository(dbProvider),
specProvider,
NullBloomStorage.Instance,
LimboLogs.Instance);
IDb stateDb = new MemDb();
IDb codeDb = new MemDb();
var trieStore = new TrieStore(stateDb, LimboLogs.Instance);

IWorldState stateProvider = new WorldState(trieStore, dbProvider.GetDb<IDb>("codeDb"), LimboLogs.Instance);
IWorldState stateProvider = new WorldState(trieStore, codeDb, LimboLogs.Instance);
ITransactionProcessor transactionProcessor = Substitute.For<ITransactionProcessor>();
IWitnessCollector witnessCollector = Substitute.For<IWitnessCollector>();
BlockProcessor processor = new(
Expand All @@ -113,8 +82,7 @@ public void Can_store_a_witness()
stateProvider,
NullReceiptStorage.Instance,
witnessCollector,
LimboLogs.Instance,
blockTree);
LimboLogs.Instance);

BlockHeader header = Build.A.BlockHeader.WithAuthor(TestItem.AddressD).TestObject;
Block block = Build.A.Block.WithHeader(header).TestObject;
Expand All @@ -130,24 +98,10 @@ public void Can_store_a_witness()
[Test, Timeout(Timeout.MaxTestTime)]
public void Recovers_state_on_cancel()
{
ISpecProvider specProvider = MainnetSpecProvider.Instance;
DbProvider dbProvider = new(DbModeHint.Mem);
dbProvider.RegisterDb(DbNames.BlockInfos, new MemDb());
dbProvider.RegisterDb(DbNames.Blocks, new MemDb());
dbProvider.RegisterDb(DbNames.Headers, new MemDb());
dbProvider.RegisterDb(DbNames.State, new MemDb());
dbProvider.RegisterDb(DbNames.Code, new MemDb());
dbProvider.RegisterDb(DbNames.Metadata, new MemDb());

TrieStore trieStore = new(dbProvider.GetDb<IDb>("stateDb"), LimboLogs.Instance);
IWorldState stateProvider = new WorldState(trieStore, dbProvider.GetDb<IDb>("codeDb"), LimboLogs.Instance);
BlockTree blockTree = new(
dbProvider,
new ChainLevelInfoRepository(dbProvider),
specProvider,
NullBloomStorage.Instance,
LimboLogs.Instance);

IDb stateDb = new MemDb();
IDb codeDb = new MemDb();
TrieStore trieStore = new(stateDb, LimboLogs.Instance);
IWorldState stateProvider = new WorldState(trieStore, codeDb, LimboLogs.Instance);
ITransactionProcessor transactionProcessor = Substitute.For<ITransactionProcessor>();
BlockProcessor processor = new(
RinkebySpecProvider.Instance,
Expand All @@ -157,8 +111,7 @@ public void Recovers_state_on_cancel()
stateProvider,
NullReceiptStorage.Instance,
NullWitnessCollector.Instance,
LimboLogs.Instance,
blockTree);
LimboLogs.Instance);

BlockHeader header = Build.A.BlockHeader.WithNumber(1).WithAuthor(TestItem.AddressD).TestObject;
Block block = Build.A.Block.WithTransactions(1, MuirGlacier.Instance).WithHeader(header).TestObject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void Test()
stateProvider,
NullReceiptStorage.Instance,
NullWitnessCollector.Instance,
LimboLogs.Instance, blockTree);
LimboLogs.Instance);
BlockchainProcessor blockchainProcessor = new(
blockTree,
blockProcessor,
Expand Down
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Blockchain.Test/ReorgTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void Setup()
stateProvider,
NullReceiptStorage.Instance,
new WitnessCollector(memDbProvider.StateDb, LimboLogs.Instance),
LimboLogs.Instance, _blockTree);
LimboLogs.Instance);
_blockchainProcessor = new BlockchainProcessor(
_blockTree,
blockProcessor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ public On CreateNode(PrivateKey privateKey, bool withGenesisAlreadyProcessed = f
stateProvider,
NullReceiptStorage.Instance,
NullWitnessCollector.Instance,
nodeLogManager,
_blockTrees[privateKey]);
nodeLogManager);

BlockchainProcessor processor = new(blockTree, blockProcessor, new AuthorRecoveryStep(snapshotManager), stateReader, nodeLogManager, BlockchainProcessor.Options.NoReceipts);
processor.Start();
Expand All @@ -152,8 +151,7 @@ public On CreateNode(PrivateKey privateKey, bool withGenesisAlreadyProcessed = f
minerStateProvider,
NullReceiptStorage.Instance,
NullWitnessCollector.Instance,
nodeLogManager,
_blockTrees[privateKey]);
nodeLogManager);

BlockchainProcessor minerProcessor = new(blockTree, minerBlockProcessor, new AuthorRecoveryStep(snapshotManager), stateReader, nodeLogManager, BlockchainProcessor.Options.NoReceipts);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public AuRaBlockProcessor(
receiptStorage,
NullWitnessCollector.Instance,
logManager,
blockTree,
withdrawalProcessor)
{
_specProvider = specProvider;
Expand Down
1 change: 0 additions & 1 deletion src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public Task<IBlockProducer> InitBlockProducer(IBlockProductionTrigger? blockProd
NullReceiptStorage.Instance,
NullWitnessCollector.Instance,
getFromApi.LogManager,
getFromApi.BlockTree!,
new BlockProductionWithdrawalProcessor(new WithdrawalProcessor(producerEnv.StateProvider, getFromApi.LogManager)));

IBlockchainProcessor producerChainProcessor = new BlockchainProcessor(
Expand Down
3 changes: 1 addition & 2 deletions src/Nethermind/Nethermind.Consensus.Ethash/NethDevPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public Task<IBlockProducer> InitBlockProducer(IBlockProductionTrigger? blockProd
producerEnv.StateProvider,
NullReceiptStorage.Instance,
NullWitnessCollector.Instance,
getFromApi.LogManager,
getFromApi.BlockTree);
getFromApi.LogManager);

IBlockchainProcessor producerChainProcessor = new BlockchainProcessor(
readOnlyBlockTree,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ProjectReference Include="..\Nethermind.Crypto\Nethermind.Crypto.csproj" />
<ProjectReference Include="..\Nethermind.Evm\Nethermind.Evm.csproj" />
<ProjectReference Include="..\Nethermind.TxPool\Nethermind.TxPool.csproj" />
<ProjectReference Include="..\Nethermind.Serialization.Rlp\Nethermind.Serialization.Rlp.csproj" />

</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Nethermind.Core.Crypto;
using Nethermind.Core.Specs;
using Nethermind.Crypto;
using Nethermind.Evm.Precompiles.Statefull;
using Nethermind.Evm.Tracing;
using Nethermind.Int256;
using Nethermind.Logging;
Expand All @@ -34,13 +35,9 @@ public partial class BlockProcessor : IBlockProcessor
private readonly IBlockValidator _blockValidator;
private readonly IRewardCalculator _rewardCalculator;
private readonly IBlockProcessor.IBlockTransactionsExecutor _blockTransactionsExecutor;
private readonly IBlockTree _blockTree;

private const int MaxUncommittedBlocks = 64;

public static readonly Address HISTORY_STORAGE_ADDRESS = Address.FromNumber(UInt256.MaxValue - 2);
public static readonly UInt256 SLOTS_PER_HISTORICAL_ROOT = (UInt256)8192;

/// <summary>
/// We use a single receipt tracer for all blocks. Internally receipt tracer forwards most of the calls
/// to any block-specific tracers.
Expand All @@ -56,7 +53,6 @@ public BlockProcessor(
IReceiptStorage? receiptStorage,
IWitnessCollector? witnessCollector,
ILogManager? logManager,
IBlockTree? blockTree,
IWithdrawalProcessor? withdrawalProcessor = null)
{
_logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
Expand All @@ -68,7 +64,6 @@ public BlockProcessor(
_withdrawalProcessor = withdrawalProcessor ?? new WithdrawalProcessor(stateProvider, logManager);
_rewardCalculator = rewardCalculator ?? throw new ArgumentNullException(nameof(rewardCalculator));
_blockTransactionsExecutor = blockTransactionsExecutor ?? throw new ArgumentNullException(nameof(blockTransactionsExecutor));
_blockTree = blockTree ?? throw new ArgumentNullException(nameof(blockTree));

_receiptsTracer = new BlockReceiptsTracer();
}
Expand Down Expand Up @@ -228,7 +223,7 @@ protected virtual TxReceipt[] ProcessBlock(

if (spec.BeaconStateRootAvailable)
{
StorageCell storageCell = new(HISTORY_STORAGE_ADDRESS, new UInt256(block.Header.BeaconStateRoot.Bytes));
StorageCell storageCell = new(BeaconStateRootPrecompile.Address, new UInt256(block.Header.BeaconStateRoot.Bytes));
_stateProvider.Set(storageCell, ((UInt256)block.Timestamp).ToBigEndian());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ public ReadOnlyChainProcessingEnv(
StateProvider,
receiptStorage,
NullWitnessCollector.Instance,
logManager,
blocktree);
logManager);

_blockProcessingQueue = new BlockchainProcessor(_txEnv.BlockTree, BlockProcessor, recoveryStep, _txEnv.StateReader, logManager, BlockchainProcessor.Options.NoReceipts);
BlockProcessingQueue = _blockProcessingQueue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ protected virtual BlockProcessor CreateBlockProcessor(ReadOnlyTxProcessingEnv re
receiptStorage,
NullWitnessCollector.Instance,
logManager,
_blockTree,
new BlockProductionWithdrawalProcessor(new WithdrawalProcessor(readOnlyTxProcessingEnv.StateProvider, logManager)));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ protected virtual IBlockProcessor CreateBlockProcessor() =>
State,
ReceiptStorage,
NullWitnessCollector.Instance,
LogManager,
BlockTree);
LogManager);

public async Task WaitForNewHead()
{
Expand Down
23 changes: 0 additions & 23 deletions src/Nethermind/Nethermind.Core/RlpShape.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,11 @@ public void Debugger_stops_at_correct_breakpoint_depth(string bytecodeHex)
{
if (tracer.CanReadState)
{
if(tracer.CurrentState.Env.CallDepth == TARGET_OPCODE_PTR_BREAK_POINT.depth && tracer.CurrentState.ProgramCounter == TARGET_OPCODE_PTR_BREAK_POINT.pc)
if (tracer.CurrentState.Env.CallDepth == TARGET_OPCODE_PTR_BREAK_POINT.depth && tracer.CurrentState.ProgramCounter == TARGET_OPCODE_PTR_BREAK_POINT.pc)
{
stoppedAtCorrectBreakpoint = true;
} else
}
else
{
stoppedAtCorrectBreakpoint = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public static class AddressExtensions

public static bool IsPrecompile(this Address address, IReleaseSpec releaseSpec)
{
if(address == BeaconStateRootPrecompile.Address)
if (address == BeaconStateRootPrecompile.Address)
{
return releaseSpec.BeaconStateRootAvailable;
}
Expand Down Expand Up @@ -47,7 +47,7 @@ public static bool IsPrecompile(this Address address, IReleaseSpec releaseSpec)
17 => releaseSpec.Bls381Enabled,
18 => releaseSpec.Bls381Enabled,
20 => releaseSpec.IsEip4844Enabled,

_ => false
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
using Nethermind.State;

namespace Nethermind.Evm.Precompiles.Statefull;
internal class BeaconStateRootPrecompile : IPrecompile
public class BeaconStateRootPrecompile : IPrecompile
{
private readonly IWorldState _state;
public static Address Address { get; } = Address.FromNumber(UInt256.MaxValue - 2);
public static Address Address { get; } = Address.FromNumber(0x0B);

private BeaconStateRootPrecompile(IWorldState state)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Nethermind/Nethermind.Init/Steps/InitializeBlockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -353,8 +353,7 @@ protected virtual BlockProcessor CreateBlockProcessor()
_api.WorldState,
_api.ReceiptStorage,
_api.WitnessCollector,
_api.LogManager,
_api.BlockTree);
_api.LogManager);
}

// TODO: remove from here - move to consensus?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ TransactionProcessor transactionProcessor

IBlockProcessor.IBlockTransactionsExecutor transactionsExecutor = new BlockProcessor.BlockValidationTransactionsExecutor(transactionProcessor, stateProvider);
BlockProcessor blockProcessor = new(specProvider, Always.Valid, new RewardCalculator(specProvider), transactionsExecutor,
stateProvider, NullReceiptStorage.Instance, NullWitnessCollector.Instance, LimboLogs.Instance, blockTree);
stateProvider, NullReceiptStorage.Instance, NullWitnessCollector.Instance, LimboLogs.Instance);

EthereumEcdsa ecdsa = new(specProvider.ChainId, LimboLogs.Instance);
BlockchainProcessor blockchainProcessor = new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ public void Setup()
stateProvider,
NullReceiptStorage.Instance,
NullWitnessCollector.Instance,
LimboLogs.Instance,
_blockTree);
LimboLogs.Instance);

RecoverSignatures txRecovery = new(new EthereumEcdsa(TestBlockchainIds.ChainId, LimboLogs.Instance), NullTxPool.Instance, specProvider, LimboLogs.Instance);
_processor = new BlockchainProcessor(_blockTree, blockProcessor, txRecovery, stateReader, LimboLogs.Instance, BlockchainProcessor.Options.NoReceipts);
Expand Down
Loading

0 comments on commit 7c35693

Please sign in to comment.