-
Notifications
You must be signed in to change notification settings - Fork 429
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
base: master
Are you sure you want to change the base?
Changes from 35 commits
70a3e5c
02974cc
c541cb1
b9d03c4
dfc79d6
45e0c44
c336a0f
f3271b2
81466dd
e5c7ed0
4e91720
7ee1fef
d700629
3d9ab43
758ffa5
a518336
130593c
1353354
852b4b7
ec51f7f
04f881b
56559ba
b0a809f
6ca067c
ef50e1e
3ada282
c9be5af
9429e49
4018745
685617d
e6f0e33
4cc7255
b020b87
c7dcf00
e30be14
931d1dd
a86ac19
066af5a
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,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 |
---|---|---|
@@ -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) | ||
{ | ||
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)); | ||
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. 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) | ||
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. Cosmetic a bit, but worth considering: Withdrawals only calculates root during the block production while exits and deposits always calculate the root. |
||
{ | ||
block.Header.DepositsRoot = deposits.IsNullOrEmpty() | ||
? Keccak.EmptyTreeHash | ||
: new DepositTrie(deposits.ToArray()!).RootHash; | ||
} | ||
} |
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); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -116,4 +117,7 @@ public static string InvalidTxInBlock(int i) => | |
|
||
public const string NegativeGasUsed = | ||
"NegativeGasUsed: Cannot be negative."; | ||
public static string MissingDeposits => "MissingDeposits: Deposits cannot be null in block when EIP-6110 activated."; | ||
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. Why do we have such messages for deposits in BlockErrorMessages but we don't for withdrawals and 7002? 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. 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 |
---|---|---|
|
@@ -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) | ||
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. @Demuirgos @rjnrohit check this line carefully: 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 | ||
|
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.
Consider moving
IReleaseSpec
to ctor instead, or alternatively remove it and make the if check before consumers callProcessDeposits
.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.
I think it is not possible, you could pass specProvider only. To me this is okay