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

[WIP]Add Eip6110 implementation #6849

Draft
wants to merge 38 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
70a3e5c
+ Draft implementation of Eip6110
Demuirgos Feb 4, 2024
02974cc
Merge remote-tracking branch 'origin/master' into Feature/Eip/6110
Demuirgos Feb 4, 2024
c541cb1
fix merge issue
Demuirgos Feb 4, 2024
b9d03c4
- fix NullPtrException in BlockProcessing
Demuirgos Feb 5, 2024
dfc79d6
add missing fields to ChainSpecJson
Demuirgos Feb 5, 2024
45e0c44
- added new fields to Builder api
Demuirgos Feb 5, 2024
c336a0f
- revert ReleaseSpec creeping out
Demuirgos Feb 6, 2024
f3271b2
Ammended PayloadAttribute and ExecutionPayload with new Deposits field
Demuirgos Feb 7, 2024
81466dd
Merge remote-tracking branch 'origin/master' into Feature/Eip/6110
Demuirgos Feb 7, 2024
e5c7ed0
fix erroneous change
Demuirgos Feb 7, 2024
4e91720
merge master and resolve conflicts
Demuirgos Mar 21, 2024
7ee1fef
fix
MarekM25 Mar 27, 2024
d700629
Typo credentials
MarekM25 Mar 27, 2024
3d9ab43
cosmetic comment fix
MarekM25 Mar 27, 2024
758ffa5
more fixes
MarekM25 Mar 27, 2024
a518336
merge master, resolve errors, apply suggestions
Demuirgos Mar 27, 2024
130593c
Added roundtrip tests
Demuirgos Mar 28, 2024
1353354
Merge remote-tracking branch 'origin/master' into feature/eip/6110
Demuirgos Apr 1, 2024
852b4b7
add v4 capabilities
Demuirgos Apr 2, 2024
ec51f7f
add back executionParloadV3 params to executionParloadV4
Demuirgos Apr 3, 2024
04f881b
minor fixes
Demuirgos Apr 3, 2024
56559ba
Merge branch 'master' into feature/eip/6110
Demuirgos Apr 3, 2024
b0a809f
revert change
Demuirgos Apr 5, 2024
6ca067c
Merge remote-tracking branch 'origin/master' into feature/eip/6110
Demuirgos Apr 5, 2024
ef50e1e
Merge branch 'master' into feature/eip/6110
Demuirgos Apr 8, 2024
3ada282
add deposists in BlockForRPC
rjnrohit Apr 10, 2024
c9be5af
- minor chainspecloader fixes
Demuirgos Apr 10, 2024
9429e49
merge pulled commits
Demuirgos Apr 10, 2024
4018745
fix build issues
Demuirgos Apr 10, 2024
685617d
minor fix
Demuirgos Apr 14, 2024
e6f0e33
Merge branch 'master' into feature/eip/6110
Demuirgos Apr 15, 2024
4cc7255
Update BlockErrorMessages.cs
Demuirgos Apr 15, 2024
b020b87
Update BlockErrorMessages.cs
Demuirgos Apr 15, 2024
c7dcf00
Update BlockErrorMessages.cs
Demuirgos Apr 15, 2024
e30be14
Cosmetic cleanup
MarekM25 Apr 16, 2024
931d1dd
merge changes
Demuirgos Apr 17, 2024
a86ac19
Merge branch 'feature/eip/6110' of https://github.com/NethermindEth/n…
Demuirgos Apr 17, 2024
066af5a
rename EipPropertyName, fix BlockToBuild ctpr call
Demuirgos Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using Nethermind.Consensus.Processing;
using Nethermind.Consensus.Rewards;
using Nethermind.Consensus.Transactions;
using Nethermind.Consensus.Withdrawals;
using Nethermind.Consensus.Deposits;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;
Expand Down Expand Up @@ -160,6 +160,7 @@ void Process(AuRaBlockProcessor auRaBlockProcessor, int blockNumber, Hash256 sta
LimboLogs.Instance,
Substitute.For<IBlockTree>(),
new WithdrawalProcessor(stateProvider, LimboLogs.Instance),
new DepositsProcessor(LimboLogs.Instance),
null,
txFilter,
contractRewriter: contractRewriter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Nethermind.Consensus;
using Nethermind.Consensus.AuRa;
using Nethermind.Consensus.AuRa.Contracts;
using Nethermind.Consensus.AuRa.Deposits;
using Nethermind.Consensus.AuRa.Withdrawals;
using Nethermind.Consensus.Processing;
using Nethermind.Consensus.Rewards;
Expand Down Expand Up @@ -100,6 +101,7 @@ protected override BlockProcessor CreateBlockProcessor()
LimboLogs.Instance,
BlockTree,
NullWithdrawalProcessor.Instance,
NullDepositsProcessor.Instance,
null,
null,
GasLimitCalculator as AuRaContractGasLimitOverride);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Nethermind.AuRa.Test.Contract;
using Nethermind.Consensus.AuRa;
using Nethermind.Consensus.AuRa.Contracts;
using Nethermind.Consensus.AuRa.Deposits;
using Nethermind.Consensus.AuRa.Transactions;
using Nethermind.Consensus.AuRa.Withdrawals;
using Nethermind.Consensus.Processing;
Expand Down Expand Up @@ -156,6 +157,7 @@ protected override BlockProcessor CreateBlockProcessor()
LimboLogs.Instance,
BlockTree,
NullWithdrawalProcessor.Instance,
NullDepositsProcessor.Instance,
null
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
using Nethermind.TxPool;
using NSubstitute;
using NUnit.Framework;
using Nethermind.Consensus.AuRa.Deposits;

namespace Nethermind.AuRa.Test.Transactions;

Expand Down Expand Up @@ -297,6 +298,7 @@ protected override BlockProcessor CreateBlockProcessor()
LimboLogs.Instance,
BlockTree,
NullWithdrawalProcessor.Instance,
NullDepositsProcessor.Instance,
null,
PermissionBasedTxFilter);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using Nethermind.Consensus.Rewards;
using Nethermind.Consensus.Transactions;
using Nethermind.Consensus.Validators;
using Nethermind.Consensus.Withdrawals;
using Nethermind.Consensus.Deposits;
using Nethermind.Core;
using Nethermind.Core.Specs;
using Nethermind.Crypto;
Expand Down Expand Up @@ -40,6 +40,7 @@ public class AuRaBlockProcessor : BlockProcessor
ILogManager logManager,
IBlockTree blockTree,
IWithdrawalProcessor withdrawalProcessor,
IDepositsProcessor depositsProcessor,
IAuRaValidator? auRaValidator,
ITxFilter? txFilter = null,
AuRaContractGasLimitOverride? gasLimitOverride = null,
Expand All @@ -53,7 +54,8 @@ public class AuRaBlockProcessor : BlockProcessor
receiptStorage,
NullWitnessCollector.Instance,
logManager,
withdrawalProcessor)
withdrawalProcessor,
depositsProcessor)
{
_specProvider = specProvider;
_blockTree = blockTree ?? throw new ArgumentNullException(nameof(blockTree));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Consensus.Deposits;
using Nethermind.Core;
using Nethermind.Core.Specs;
using System.Collections.Generic;

namespace Nethermind.Consensus.AuRa.Deposits;

public class NullDepositsProcessor : IDepositsProcessor
{
public void ProcessDeposits(Block block, TxReceipt[] receipts, IReleaseSpec spec)
{
}
public static IDepositsProcessor Instance { get; } = new NullDepositsProcessor();
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Nethermind.Consensus.AuRa.Config;
using Nethermind.Consensus.AuRa.Contracts;
using Nethermind.Consensus.AuRa.Contracts.DataStore;
using Nethermind.Consensus.AuRa.Deposits;
using Nethermind.Consensus.AuRa.Rewards;
using Nethermind.Consensus.AuRa.Services;
using Nethermind.Consensus.AuRa.Transactions;
Expand Down Expand Up @@ -109,6 +110,7 @@ protected virtual AuRaBlockProcessor NewAuraBlockProcessor(ITxFilter txFilter)
_api.LogManager,
_api.BlockTree!,
NullWithdrawalProcessor.Instance,
NullDepositsProcessor.Instance,
CreateAuRaValidator(),
txFilter,
GetGasLimitCalculator(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Nethermind.Consensus.AuRa.Config;
using Nethermind.Consensus.AuRa.Contracts;
using Nethermind.Consensus.AuRa.Contracts.DataStore;
using Nethermind.Consensus.AuRa.Deposits;
using Nethermind.Consensus.AuRa.Transactions;
using Nethermind.Consensus.AuRa.Validators;
using Nethermind.Consensus.AuRa.Withdrawals;
Expand Down Expand Up @@ -157,6 +158,7 @@ private BlockProcessor CreateBlockProcessor(ReadOnlyTxProcessingEnv changeableTx
_api.LogManager,
changeableTxProcessingEnv.BlockTree,
NullWithdrawalProcessor.Instance,
NullDepositsProcessor.Instance,
_validator,
auRaTxFilter,
CreateGasLimitCalculator(_api) as AuRaContractGasLimitOverride,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Consensus.Withdrawals;
using Nethermind.Consensus.Deposits;
using Nethermind.Core;
using Nethermind.Core.Specs;

Expand Down
5 changes: 3 additions & 2 deletions src/Nethermind/Nethermind.Consensus.Clique/CliquePlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
using Nethermind.Consensus.Producers;
using Nethermind.Consensus.Rewards;
using Nethermind.Consensus.Transactions;
using Nethermind.Consensus.Withdrawals;
using Nethermind.Consensus.Deposits;
using Nethermind.Core.Attributes;
using Nethermind.Db;
using Nethermind.JsonRpc.Modules;
Expand Down Expand Up @@ -108,7 +108,8 @@ public Task<IBlockProducer> InitBlockProducer(IBlockProductionTrigger? blockProd
NullReceiptStorage.Instance,
NullWitnessCollector.Instance,
getFromApi.LogManager,
new BlockProductionWithdrawalProcessor(new WithdrawalProcessor(producerEnv.StateProvider, getFromApi.LogManager)));
new BlockProductionWithdrawalProcessor(new WithdrawalProcessor(producerEnv.StateProvider, getFromApi.LogManager)),
new DepositsProcessor(getFromApi.LogManager));

IBlockchainProcessor producerChainProcessor = new BlockchainProcessor(
readOnlyBlockTree,
Expand Down
58 changes: 58 additions & 0 deletions src/Nethermind/Nethermind.Consensus/Deposits/DepositsProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.IdentityModel.Tokens;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.Specs;
using Nethermind.Logging;
using Nethermind.Serialization.Rlp;
using Nethermind.State;
using Nethermind.State.Proofs;

namespace Nethermind.Consensus.Deposits;

public class DepositsProcessor : IDepositsProcessor
{
private readonly ILogger _logger;

public DepositsProcessor(ILogManager logManager)
{
ArgumentNullException.ThrowIfNull(logManager);

_logger = logManager.GetClassLogger();
}

public void ProcessDeposits(Block block, TxReceipt[] receipts, IReleaseSpec spec)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider moving IReleaseSpec to ctor instead, or alternatively remove it and make the if check before consumers call ProcessDeposits.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is not possible, you could pass specProvider only. To me this is okay

{
if (!spec.IsEip6110Enabled)
return;


List<Deposit> depositList = [];
for (int i = 0; i < block.Transactions.Length; i++)
{
foreach (var log in receipts[i].Logs)
{
if (log.LoggersAddress == spec.Eip6110ContractAddress)
{
var depositDecoder = new DepositDecoder();
Deposit? deposit = depositDecoder.Decode(new RlpStream(log.Data));
Copy link
Contributor

Choose a reason for hiding this comment

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

Open question, probably to other teams as well: is it possible to get incorrect data here?

depositList.Add(deposit);
}
}
}

CalculateDepositsRoot(block, depositList, spec);
}

private void CalculateDepositsRoot(Block block, IEnumerable<Deposit> deposits, IReleaseSpec spec)
Copy link
Contributor

Choose a reason for hiding this comment

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

Cosmetic a bit, but worth considering: Withdrawals only calculates root during the block production while exits and deposits always calculate the root.
cc: @rjnrohit @Demuirgos

{
block.Header.DepositsRoot = deposits.IsNullOrEmpty()
? Keccak.EmptyTreeHash
: new DepositTrie(deposits.ToArray()!).RootHash;
}
}
14 changes: 14 additions & 0 deletions src/Nethermind/Nethermind.Consensus/Deposits/IDepositsProcessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core;
using Nethermind.Core.Specs;
using Nethermind.Serialization.Rlp;
using System.Collections.Generic;

namespace Nethermind.Consensus.Deposits;

public interface IDepositsProcessor
{
void ProcessDeposits(Block block, TxReceipt[] receipts, IReleaseSpec spec);
}
1 change: 1 addition & 0 deletions src/Nethermind/Nethermind.Consensus/EngineApiVersions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public static class EngineApiVersions
public const int Paris = 1;
public const int Shanghai = 2;
public const int Cancun = 3;
public const int Prague = 4;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: LGPL-3.0-only

using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Crypto;

namespace Nethermind.Consensus.Messages;
Expand Down Expand Up @@ -116,4 +117,7 @@ public static class BlockErrorMessages

public const string NegativeGasUsed =
"NegativeGasUsed: Cannot be negative.";
public static string MissingDeposits => "MissingDeposits: Deposits cannot be null in block when EIP-6110 activated.";
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have such messages for deposits in BlockErrorMessages but we don't for withdrawals and 7002?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we have MissingWithdrawals Error, I am not sure abt Eip7002 tho

public static string DepositsNotEnabled => "DepositsNotEnabled: Deposits must be null in block when EIP-6110 not activated.";
public static string InvalidDepositsRoot(Hash256 expected, Hash256 actual) => $"InvalidDepositsRoot: Deposits root hash mismatch in block: expected {expected}, got {actual}";
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ 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)
Copy link
Contributor

Choose a reason for hiding this comment

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

@Demuirgos @rjnrohit check this line carefully:
? new BlockToProduce(header, blockToProduce.Transactions, blockToProduce.Uncles, blockToProduce.Withdrawals)

analyze all usages of BlockToProduce constructor

: new Block(header, block.Transactions, block.Uncles, block.Withdrawals);
: new Block(header, block.Transactions, block.Uncles, block.Withdrawals, block.Deposits);

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 @@ -11,7 +11,7 @@
using Nethermind.Consensus.BeaconBlockRoot;
using Nethermind.Consensus.Rewards;
using Nethermind.Consensus.Validators;
using Nethermind.Consensus.Withdrawals;
using Nethermind.Consensus.Deposits;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.Specs;
Expand Down Expand Up @@ -39,7 +39,7 @@ public partial class BlockProcessor : IBlockProcessor
private readonly IBlockValidator _blockValidator;
private readonly IRewardCalculator _rewardCalculator;
private readonly IBlockProcessor.IBlockTransactionsExecutor _blockTransactionsExecutor;

private readonly IDepositsProcessor _depositsProcessor;
private const int MaxUncommittedBlocks = 64;

/// <summary>
Expand All @@ -58,6 +58,7 @@ public partial class BlockProcessor : IBlockProcessor
IWitnessCollector? witnessCollector,
ILogManager? logManager,
IWithdrawalProcessor? withdrawalProcessor = null,
IDepositsProcessor? depositsProcessor = null,
IReceiptsRootCalculator? receiptsRootCalculator = null)
{
_logger = logManager?.GetClassLogger() ?? throw new ArgumentNullException(nameof(logManager));
Expand All @@ -70,6 +71,7 @@ public partial class BlockProcessor : IBlockProcessor
_rewardCalculator = rewardCalculator ?? throw new ArgumentNullException(nameof(rewardCalculator));
_blockTransactionsExecutor = blockTransactionsExecutor ?? throw new ArgumentNullException(nameof(blockTransactionsExecutor));
_receiptsRootCalculator = receiptsRootCalculator ?? ReceiptsRootCalculator.Instance;
_depositsProcessor = depositsProcessor ?? new DepositsProcessor(logManager);
_beaconBlockRootHandler = new BeaconBlockRootHandler();

ReceiptsTracer = new BlockReceiptsTracer();
Expand Down Expand Up @@ -248,6 +250,7 @@ private void ValidateProcessedBlock(Block suggestedBlock, ProcessingOptions opti
block.Header.ReceiptsRoot = _receiptsRootCalculator.GetReceiptsRoot(receipts, spec, block.ReceiptsRoot);
ApplyMinerRewards(block, blockTracer, spec);
_withdrawalProcessor.ProcessWithdrawals(block, spec);
_depositsProcessor.ProcessDeposits(block, receipts, spec);
ReceiptsTracer.EndBlockTrace();

_stateProvider.Commit(spec);
Expand Down Expand Up @@ -299,6 +302,7 @@ private Block PrepareBlockForProcessing(Block suggestedBlock)
ReceiptsRoot = bh.ReceiptsRoot,
BaseFeePerGas = bh.BaseFeePerGas,
WithdrawalsRoot = bh.WithdrawalsRoot,
DepositsRoot = bh.DepositsRoot,
IsPostMerge = bh.IsPostMerge,
ParentBeaconBlockRoot = bh.ParentBeaconBlockRoot,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using Nethermind.Consensus.Rewards;
using Nethermind.Consensus.Transactions;
using Nethermind.Consensus.Validators;
using Nethermind.Consensus.Withdrawals;
using Nethermind.Consensus.Deposits;
using Nethermind.Core.Specs;
using Nethermind.Logging;
using Nethermind.State;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ public new IEnumerable<Transaction> Transactions
BlockHeader blockHeader,
IEnumerable<Transaction> transactions,
IEnumerable<BlockHeader> uncles,
IEnumerable<Withdrawal>? withdrawals = null)
: base(blockHeader, Array.Empty<Transaction>(), uncles, withdrawals)
IEnumerable<Withdrawal>? withdrawals = null,
IEnumerable<Deposit>? deposits = null)
: base(blockHeader, Array.Empty<Transaction>(), uncles, withdrawals, deposits)
{
Transactions = transactions;
}
Expand Down