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

Verkle/testnets #50

Open
wants to merge 24 commits into
base: verkle/base
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
f773da6
Add equality comparer to journal set
tanishqjasoria Aug 16, 2023
4fe22e7
add more bytes comparision
tanishqjasoria Aug 16, 2023
7aafe75
add int to little endian
tanishqjasoria Aug 16, 2023
91d4cc8
add verkle tree eip in prague hardfork (#4975)
tanishqjasoria Dec 7, 2022
300e8d6
Add verkle package
tanishqjasoria Aug 16, 2023
b50b8c1
add core verkle structure
tanishqjasoria Aug 16, 2023
3f8d085
Add verkle tree structures
tanishqjasoria Aug 16, 2023
120a49d
use is fully synced from trie store
tanishqjasoria Aug 16, 2023
fed6efe
Add verkle gas cost
tanishqjasoria Aug 16, 2023
cd1acd0
Add contructs to charge for verkle evm costs
tanishqjasoria Aug 16, 2023
344a19a
storage cell value 32 bytes verkle
tanishqjasoria Aug 18, 2023
0b58fd2
Add new witness access and gas cost changes
tanishqjasoria Aug 18, 2023
95ce978
add processing changes and blockchain intialization
tanishqjasoria Aug 21, 2023
c6a1fa1
Add stateless processing capacbility merge plugin
tanishqjasoria Aug 21, 2023
7369604
add testnet configs
tanishqjasoria Aug 21, 2023
23bc1f0
use ISyncTrieStore
tanishqjasoria Aug 21, 2023
245d142
fix account creation
tanishqjasoria Aug 22, 2023
2b58cb0
fix some init steps
tanishqjasoria Aug 22, 2023
6265e9c
revert timeout change
tanishqjasoria Aug 23, 2023
3b5ea04
add serilizers json
tanishqjasoria Aug 23, 2023
7d1b096
fix account creation
tanishqjasoria Aug 25, 2023
da22e82
add logs and remove gas benficiary
tanishqjasoria Aug 25, 2023
78281c7
fix push32
tanishqjasoria Aug 25, 2023
9a546e9
Add new execution tracer
tanishqjasoria Aug 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
886 changes: 886 additions & 0 deletions src/Nethermind/Chains/beverly-hills.json

Large diffs are not rendered by default.

103 changes: 103 additions & 0 deletions src/Nethermind/Chains/kaustinen.json

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/Nethermind/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
<PackageVersion Include="Nethermind.DotNetty.Transport" Version="1.0.1" />
<PackageVersion Include="Nethermind.Gmp" Version="1.0.1" />
<PackageVersion Include="Nethermind.Numerics.Int256" Version="1.1.0" />
<PackageVersion Include="Nethermind.Verkle" Version="0.1.3-alpha" />
<PackageVersion Include="Newtonsoft.Json" Version="13.0.3" />
<PackageVersion Include="Nito.Collections.Deque" Version="1.1.1" />
<PackageVersion Include="NLog" Version="5.2.2" />
Expand Down Expand Up @@ -82,4 +83,4 @@
<PackageVersion Include="Websocket.Client" Version="4.6.1" />
<PackageVersion Include="YamlDotNet" Version="13.1.1" />
</ItemGroup>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public AABlockProducerTransactionsExecutor(
public override TxReceipt[] ProcessTransactions(
Block block,
ProcessingOptions processingOptions,
BlockReceiptsTracer receiptsTracer,
BlockExecutionTracer receiptsTracer,
IReleaseSpec spec)
{
IEnumerable<Transaction> transactions = GetTransactions(block);
Expand Down Expand Up @@ -81,7 +81,7 @@ private BlockProcessor.TxAction ProcessAccountAbstractionTransaction(
Block block,
Transaction currentTx,
int index,
BlockReceiptsTracer receiptsTracer,
BlockExecutionTracer receiptsTracer,
ProcessingOptions processingOptions,
LinkedHashSet<Transaction> transactionsInBlock)
{
Expand Down
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.Api/IApiWithBlockchain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Nethermind.State;
using Nethermind.Trie.Pruning;
using Nethermind.TxPool;
using Nethermind.Verkle.Tree;

namespace Nethermind.Api
{
Expand All @@ -43,6 +44,8 @@ public interface IApiWithBlockchain : IApiWithStores, IBlockchainBridgeFactory
IUnclesValidator? UnclesValidator { get; set; }
IHeaderValidator? HeaderValidator { get; set; }
IManualBlockProductionTrigger ManualBlockProductionTrigger { get; }
VerkleStateStore? VerkleTrieStore { get; set; }
ReadOnlyVerkleStateStore? ReadOnlyVerkleTrieStore { get; set; }
IReadOnlyTrieStore? ReadOnlyTrieStore { get; set; }
IRewardCalculatorSource? RewardCalculatorSource { get; set; }
/// <summary>
Expand Down
21 changes: 14 additions & 7 deletions src/Nethermind/Nethermind.Api/NethermindApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
using Nethermind.Sockets;
using Nethermind.Synchronization.SnapSync;
using Nethermind.Synchronization.Blocks;
using Nethermind.Verkle;
using Nethermind.Verkle.Tree;

namespace Nethermind.Api
{
Expand All @@ -77,13 +79,15 @@ public IBlockchainBridge CreateBlockchainBridge()
ReadOnlyBlockTree readOnlyTree = BlockTree!.AsReadOnly();
LazyInitializer.EnsureInitialized(ref _readOnlyDbProvider, () => new ReadOnlyDbProvider(DbProvider, false));

// TODO: reuse the same trie cache here
ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv = new(
_readOnlyDbProvider,
ReadOnlyTrieStore,
readOnlyTree,
SpecProvider,
LogManager);
ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv = SpecProvider!.GenesisSpec.IsVerkleTreeEipEnabled switch
{
true =>
// TODO: reuse the same trie cache here
new ReadOnlyTxProcessingEnv(_readOnlyDbProvider, ReadOnlyVerkleTrieStore, readOnlyTree, SpecProvider, LogManager),
false =>
// TODO: reuse the same trie cache here
new ReadOnlyTxProcessingEnv(_readOnlyDbProvider, ReadOnlyTrieStore, readOnlyTree, SpecProvider, LogManager)
};

IMiningConfig miningConfig = ConfigProvider.GetConfig<IMiningConfig>();
IBlocksConfig blocksConfig = ConfigProvider.GetConfig<IBlocksConfig>();
Expand Down Expand Up @@ -134,6 +138,9 @@ public IBlockchainBridge CreateBlockchainBridge()
public IManualBlockProductionTrigger ManualBlockProductionTrigger { get; set; } =
new BuildBlocksWhenRequested();

public VerkleStateStore? VerkleTrieStore { get; set; }
public ReadOnlyVerkleStateStore? ReadOnlyVerkleTrieStore { get; set; }

public IIPResolver? IpResolver { get; set; }
public IJsonSerializer EthereumJsonSerializer { get; set; }
public IKeyStore? KeyStore { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ public enum BlockTreeSuggestOptions
/// Force not to set as main block
/// </summary>
ForceDontSetAsMain = 8,

/// <summary>
/// If block should be processed without global state
/// </summary>
ShouldProcessStateless = 16,
}

public static class BlockTreeSuggestOptionsExtensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ namespace Nethermind.Blockchain
/// </summary>
public class TrieStoreBoundaryWatcher : IDisposable
{
private readonly ITrieStore _trieStore;
private readonly IStoreWithReorgBoundary _trieStore;
private readonly IBlockTree _blockTree;
private readonly ILogger _logger;

public TrieStoreBoundaryWatcher(ITrieStore trieStore, IBlockTree blockTree, ILogManager logManager)
public TrieStoreBoundaryWatcher(IStoreWithReorgBoundary trieStore, IBlockTree blockTree, ILogManager logManager)
{
_trieStore = trieStore;
_blockTree = blockTree;
Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Config/BlocksConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class BlocksConfig : IBlocksConfig
public bool RandomizedBlocks { get; set; }

public ulong SecondsPerSlot { get; set; } = 12;
public bool StatelessProcessing { get; set; } = false;


public string ExtraData
Expand Down
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.Config/IBlocksConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ public interface IBlocksConfig : IConfig
[ConfigItem(Description = "Seconds per slot.", DefaultValue = "12")]
ulong SecondsPerSlot { get; set; }

[ConfigItem(Description = "Should process block stateless if possible.", DefaultValue = "false")]
bool StatelessProcessing { get; set; }

byte[] GetExtraDataBytes();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ namespace Nethermind.Consensus.AuRa
{
public class AuRaBlockProcessor : BlockProcessor
{
private readonly ISpecProvider _specProvider;
private readonly IBlockTree _blockTree;
private readonly AuRaContractGasLimitOverride? _gasLimitOverride;
private readonly ContractRewriter? _contractRewriter;
Expand Down Expand Up @@ -57,7 +56,6 @@ public AuRaBlockProcessor(
logManager,
withdrawalProcessor)
{
_specProvider = specProvider;
_blockTree = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
_logger = logManager?.GetClassLogger<AuRaBlockProcessor>() ?? throw new ArgumentNullException(nameof(logManager));
_txFilter = txFilter ?? NullTxFilter.Instance;
Expand Down
9 changes: 3 additions & 6 deletions src/Nethermind/Nethermind.Consensus.Ethash/NethDevPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,9 @@ public Task<IBlockProducer> InitBlockProducer(IBlockProductionTrigger? blockProd
if (logger.IsInfo) logger.Info("Starting Neth Dev block producer & sealer");


ReadOnlyTxProcessingEnv producerEnv = new(
readOnlyDbProvider,
getFromApi.ReadOnlyTrieStore,
readOnlyBlockTree,
getFromApi.SpecProvider,
getFromApi.LogManager);
ReadOnlyTxProcessingEnv producerEnv = _nethermindApi.SpecProvider!.GenesisSpec.IsVerkleTreeEipEnabled
? new ReadOnlyTxProcessingEnv(readOnlyDbProvider, getFromApi.ReadOnlyVerkleTrieStore, readOnlyBlockTree, getFromApi.SpecProvider, getFromApi.LogManager)
: new ReadOnlyTxProcessingEnv(readOnlyDbProvider, getFromApi.ReadOnlyTrieStore, readOnlyBlockTree, getFromApi.SpecProvider, getFromApi.LogManager);

BlockProcessor producerProcessor = new(
getFromApi!.SpecProvider,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ internal static class BlockExtensions
{
public static Block CreateCopy(this Block block, BlockHeader header) =>
block is BlockToProduce blockToProduce
? new BlockToProduce(header, blockToProduce.Transactions, blockToProduce.Uncles, blockToProduce.Withdrawals)
: new Block(header, block.Transactions, block.Uncles, block.Withdrawals);
? new BlockToProduce(header, blockToProduce.Transactions, blockToProduce.Uncles, blockToProduce.Withdrawals, blockToProduce.ExecutionWitness)
: new Block(header, block.Transactions, block.Uncles, block.Withdrawals, block.ExecutionWitness);

public static IEnumerable<Transaction> GetTransactions(this Block block) =>
block is BlockToProduce blockToProduce
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class BlockProductionTransactionsExecutor : IBlockProductionTransactionsE
private readonly IWorldState _stateProvider;
private readonly BlockProductionTransactionPicker _blockProductionTransactionPicker;
private readonly ILogger _logger;
private readonly ILogManager _logManager;

public BlockProductionTransactionsExecutor(
ReadOnlyTxProcessingEnv readOnlyTxProcessingEnv,
Expand All @@ -46,6 +47,20 @@ public BlockProductionTransactionsExecutor(
_stateProvider = stateProvider;
_blockProductionTransactionPicker = new BlockProductionTransactionPicker(specProvider);
_logger = logManager.GetClassLogger();
_logManager = logManager;
}

private BlockProductionTransactionsExecutor(
ITransactionProcessorAdapter transactionProcessor,
IWorldState stateProvider,
BlockProductionTransactionPicker blockProductionTransactionPicker,
ILogManager logManager)
{
_transactionProcessor = transactionProcessor;
_stateProvider = stateProvider;
_blockProductionTransactionPicker = blockProductionTransactionPicker;
_logger = logManager.GetClassLogger();
_logManager = logManager;
}

protected EventHandler<TxProcessedEventArgs>? _transactionProcessed;
Expand All @@ -55,13 +70,19 @@ event EventHandler<TxProcessedEventArgs>? IBlockProcessor.IBlockTransactionsExec
remove => _transactionProcessed -= value;
}

public IBlockProcessor.IBlockTransactionsExecutor WithNewStateProvider(IWorldState worldState)
{
return new BlockProductionTransactionsExecutor(_transactionProcessor, worldState,
_blockProductionTransactionPicker, _logManager);
}

event EventHandler<AddingTxEventArgs>? IBlockProductionTransactionsExecutor.AddingTransaction
{
add => _blockProductionTransactionPicker.AddingTransaction += value;
remove => _blockProductionTransactionPicker.AddingTransaction -= value;
}

public virtual TxReceipt[] ProcessTransactions(Block block, ProcessingOptions processingOptions, BlockReceiptsTracer receiptsTracer, IReleaseSpec spec)
public virtual TxReceipt[] ProcessTransactions(Block block, ProcessingOptions processingOptions, BlockExecutionTracer receiptsTracer, IReleaseSpec spec)
{
IEnumerable<Transaction> transactions = GetTransactions(block);

Expand All @@ -83,7 +104,7 @@ protected TxAction ProcessTransaction(
Block block,
Transaction currentTx,
int index,
BlockReceiptsTracer receiptsTracer,
BlockExecutionTracer receiptsTracer,
ProcessingOptions processingOptions,
LinkedHashSet<Transaction> transactionsInBlock,
bool addToBlock = true)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Linq;
using Nethermind.Core;
using Nethermind.Core.Specs;
using Nethermind.Crypto;
using Nethermind.Evm.Tracing;
using Nethermind.Evm.TransactionProcessing;
using Nethermind.Logging;
using Nethermind.State;

namespace Nethermind.Consensus.Processing;

public partial class BlockProcessor
{
public class BlockStatelessValidationTransactionsExecutor : IBlockProcessor.IBlockTransactionsExecutor
{
private ITransactionProcessorAdapter _transactionProcessor;
private IWorldState? _stateProvider;

public BlockStatelessValidationTransactionsExecutor(ITransactionProcessor transactionProcessor)
: this(new ExecuteTransactionProcessorAdapter(transactionProcessor))
{
}

public BlockStatelessValidationTransactionsExecutor(ITransactionProcessorAdapter transactionProcessor)
{
_transactionProcessor = transactionProcessor;
_stateProvider = null;
}

public BlockStatelessValidationTransactionsExecutor(ITransactionProcessor transactionProcessor, IWorldState worldState)
: this(new ExecuteTransactionProcessorAdapter(transactionProcessor), worldState)
{
}

public BlockStatelessValidationTransactionsExecutor(ITransactionProcessorAdapter transactionProcessor, IWorldState worldState)
{
_transactionProcessor = transactionProcessor;
_stateProvider = worldState;
}

public event EventHandler<TxProcessedEventArgs>? TransactionProcessed;

public IBlockProcessor.IBlockTransactionsExecutor WithNewStateProvider(IWorldState worldState)
{
_transactionProcessor = _transactionProcessor.WithNewStateProvider(worldState);
return new BlockStatelessValidationTransactionsExecutor(_transactionProcessor, worldState);
}

public TxReceipt[] ProcessTransactions(Block block, ProcessingOptions processingOptions, BlockExecutionTracer receiptsTracer, IReleaseSpec spec)
{
// var ecdsa = new EthereumEcdsa(69420, LimboLogs.Instance);
if (!block.IsGenesis)
{

for (int i = 0; i < block.Transactions.Length; i++)
{
Transaction currentTx = block.Transactions[i];
// currentTx.SenderAddress = ecdsa.RecoverAddress(currentTx);
ProcessTransaction(block, currentTx, i, receiptsTracer, _stateProvider, processingOptions);
}
_stateProvider.Commit(spec);
_stateProvider.RecalculateStateRoot();
}
return receiptsTracer.TxReceipts.ToArray();
}

private void ProcessTransaction(Block block, Transaction currentTx, int index, BlockExecutionTracer receiptsTracer, IWorldState worldState, ProcessingOptions processingOptions)
{
_transactionProcessor.ProcessTransaction(block, currentTx, receiptsTracer, processingOptions, worldState);
TransactionProcessed?.Invoke(this, new TxProcessedEventArgs(index, currentTx, receiptsTracer.TxReceipts[index]));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,13 @@ public BlockValidationTransactionsExecutor(ITransactionProcessorAdapter transact
}

public event EventHandler<TxProcessedEventArgs>? TransactionProcessed;
public IBlockProcessor.IBlockTransactionsExecutor WithNewStateProvider(IWorldState worldState)
{
return new BlockValidationTransactionsExecutor(_transactionProcessor, worldState);
}

public TxReceipt[] ProcessTransactions(Block block, ProcessingOptions processingOptions, BlockReceiptsTracer receiptsTracer, IReleaseSpec spec)
public TxReceipt[] ProcessTransactions(Block block, ProcessingOptions processingOptions, BlockExecutionTracer receiptsTracer, IReleaseSpec spec)
{
Evm.Metrics.ResetBlockStats();
for (int i = 0; i < block.Transactions.Length; i++)
{
Transaction currentTx = block.Transactions[i];
Expand All @@ -42,7 +45,7 @@ public TxReceipt[] ProcessTransactions(Block block, ProcessingOptions processing
return receiptsTracer.TxReceipts.ToArray();
}

private void ProcessTransaction(Block block, Transaction currentTx, int index, BlockReceiptsTracer receiptsTracer, ProcessingOptions processingOptions)
private void ProcessTransaction(Block block, Transaction currentTx, int index, BlockExecutionTracer receiptsTracer, ProcessingOptions processingOptions)
{
_transactionProcessor.ProcessTransaction(block, currentTx, receiptsTracer, processingOptions, _stateProvider);
TransactionProcessed?.Invoke(this, new TxProcessedEventArgs(index, currentTx, receiptsTracer.TxReceipts[index]));
Expand Down
Loading