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

Implement Gnosis beacon chain push withdrawals #5160

Merged
merged 58 commits into from
Apr 3, 2023
Merged
Show file tree
Hide file tree
Changes from 43 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
2080c2a
Add preliminary `WithdrawalProcessor` for Aura
rubo Jan 11, 2023
ac4f38e
Merge branch 'master' into feature/aura-withdrawals
rubo Jan 17, 2023
a35b5fc
Merge branch 'master' into feature/aura-withdrawals
rubo Jan 18, 2023
f473aca
Move `Nethermind.Merge.AuRa.Test` to `Tests`
rubo Jan 18, 2023
a27abbe
Implement withdrawal contract handling
rubo Jan 18, 2023
92c3198
Merge branch 'master' into feature/aura-withdrawals
rubo Jan 21, 2023
d7b23f6
Merge branch 'master' into feature/aura-withdrawals
rubo Jan 30, 2023
ce7d0a0
Revert withdrawals null check revision
rubo Jan 30, 2023
f512660
Introduce `NullWithdrawalProcessor` for pre-Merge Aura
rubo Jan 31, 2023
27970b4
Fix withdrawal array initialization
rubo Jan 31, 2023
b333924
Remove `WithdrawalContractTransition`
rubo Jan 31, 2023
bc324a0
Add withdrawals contract ABI
rubo Jan 31, 2023
c13709f
Fix formatting
rubo Jan 31, 2023
caf55e8
Merge branch 'master' into feature/aura-withdrawals
rubo Feb 6, 2023
71046ca
Move withdrawals to `Nethermind.Merge.AuRa`
rubo Feb 6, 2023
f38c4c1
Move withdrawal contract to `Netmermind.Merge.AuRa`
rubo Feb 6, 2023
3d28048
Merge branch 'master' into feature/aura-withdrawals
rubo Feb 14, 2023
7158bf8
Rename withdrawal contract method
rubo Feb 15, 2023
05bffa9
Add devnet configuration
rubo Feb 16, 2023
d5bf65e
Change validator address
rubo Feb 16, 2023
c80933e
Update chainspec
rubo Feb 17, 2023
e75806f
Merge branch 'master' into feature/aura-withdrawals
rubo Feb 21, 2023
e1e735f
Remove array pooling
rubo Feb 23, 2023
584378b
Update `executeSystemWithdrawals` signature
rubo Mar 1, 2023
1fb7a0f
Merge branch 'master' into feature/aura-withdrawals
rubo Mar 1, 2023
1a72078
Revise withdrawals contract address
rubo Mar 1, 2023
d70c230
Merge branch 'master' into feature/aura-withdrawals
rubo Mar 3, 2023
c7b201f
Merge branch 'master' into feature/aura-withdrawals
rubo Mar 6, 2023
c57de41
Merge branch 'master' into feature/aura-withdrawals
rubo Mar 7, 2023
3020507
Merge branch 'master' into feature/aura-withdrawals
rubo Mar 16, 2023
7fdfd07
Merge branch 'master' into feature/aura-withdrawals
rubo Mar 17, 2023
2797f8d
Refactor Engine API tests to support Aura
rubo Mar 21, 2023
00fd013
Merge branch 'master' into feature/aura-withdrawals
rubo Mar 21, 2023
9b87bde
Remove redundant comments
rubo Mar 21, 2023
d6273de
Remove Gnosis withdrawals devnet config
rubo Mar 21, 2023
9b56970
Rename `AuRaMergeEngineModuleTests`
rubo Mar 24, 2023
908c9ec
Add withdrawal processor tests
rubo Mar 24, 2023
7a29fce
Merge branch 'master' into feature/aura-withdrawals
rubo Mar 28, 2023
a1a82eb
Merge branch 'master' into feature/aura-withdrawals
rubo Mar 28, 2023
7464ff0
Revise tests
rubo Mar 28, 2023
0311b88
Revise withdrawal contract processing
rubo Mar 28, 2023
d6bf218
Remove devnet chain spec
rubo Mar 28, 2023
7cb0e9c
Revise withdrawal error handling
rubo Mar 29, 2023
296c1f1
add Can_load_chiado
MarekM25 Mar 30, 2023
5b8621e
Merge branch 'feature/aura-withdrawals' of https://github.com/netherm…
MarekM25 Mar 30, 2023
972f3c6
Remove redundant stuff
rubo Mar 30, 2023
8f475e2
Revise chain spec tests
rubo Mar 30, 2023
a3c1c63
Merge branch 'master' into feature/aura-withdrawals
rubo Mar 30, 2023
11bc42b
Remove outdated Chains folder
rubo Mar 30, 2023
211e443
Use `ArrayPoolList` for withdrawals (#5512)
LukaszRozmej Mar 30, 2023
682e434
Merge remote-tracking branch 'origin/feature/aura-withdrawals' into f…
rubo Mar 30, 2023
4bb5e4b
renamed WithdrawalProcessor -> ContractWithdrawalProcessor
MarekM25 Mar 31, 2023
594af29
Update withdrawal contract address
rubo Mar 31, 2023
8eb87ba
Rename `ContractWithdrawalProcessor` to `AuraWithdrawalProcessor`
rubo Mar 31, 2023
f190463
Merge branch 'master' into feature/aura-withdrawals
rubo Mar 31, 2023
52aa03a
Move to file scope namespaces
rubo Mar 31, 2023
2507ef5
Implement `IList` in `ArrayPoolList`
rubo Mar 31, 2023
ffc45f8
Implement `IList.Add` explicitly
rubo Apr 3, 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
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
using Nethermind.Consensus;
using Nethermind.Consensus.AuRa;
using Nethermind.Consensus.AuRa.Contracts;
using Nethermind.Consensus.AuRa.Withdrawals;
using Nethermind.Consensus.Processing;
using Nethermind.Consensus.Rewards;
using Nethermind.Consensus.Validators;
using Nethermind.Consensus.Withdrawals;
using Nethermind.Core;
using Nethermind.Logging;
using Nethermind.Trie.Pruning;
Expand Down Expand Up @@ -100,7 +100,7 @@ protected override BlockProcessor CreateBlockProcessor()
ReceiptStorage,
LimboLogs.Instance,
BlockTree,
new WithdrawalProcessor(State, LogManager),
NullWithdrawalProcessor.Instance,
null,
GasLimitCalculator as AuRaContractGasLimitOverride);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
using Nethermind.Consensus.AuRa;
using Nethermind.Consensus.AuRa.Contracts;
using Nethermind.Consensus.AuRa.Transactions;
using Nethermind.Consensus.AuRa.Withdrawals;
using Nethermind.Consensus.Processing;
using Nethermind.Consensus.Rewards;
using Nethermind.Consensus.Transactions;
using Nethermind.Consensus.Validators;
using Nethermind.Consensus.Withdrawals;
using Nethermind.Core;
using Nethermind.Core.Specs;
using Nethermind.Core.Test.Builders;
Expand Down Expand Up @@ -157,7 +157,7 @@ protected override BlockProcessor CreateBlockProcessor()
ReceiptStorage,
LimboLogs.Instance,
BlockTree,
new WithdrawalProcessor(State, LogManager));
NullWithdrawalProcessor.Instance);
}

protected override Task AddBlocksOnStart() => Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
using Nethermind.Consensus.AuRa;
using Nethermind.Consensus.AuRa.Contracts;
using Nethermind.Consensus.AuRa.Transactions;
using Nethermind.Consensus.AuRa.Withdrawals;
using Nethermind.Consensus.Processing;
using Nethermind.Consensus.Rewards;
using Nethermind.Consensus.Validators;
using Nethermind.Consensus.Withdrawals;
using Nethermind.Core;
using Nethermind.Core.Caching;
using Nethermind.Core.Crypto;
Expand Down Expand Up @@ -300,7 +300,7 @@ protected override BlockProcessor CreateBlockProcessor()
ReceiptStorage,
LimboLogs.Instance,
BlockTree,
new WithdrawalProcessor(State, LogManager),
NullWithdrawalProcessor.Instance,
PermissionBasedTxFilter);
}

Expand Down
18 changes: 7 additions & 11 deletions src/Nethermind/Nethermind.Blockchain/InvalidBlockException.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

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

namespace Nethermind.Blockchain
namespace Nethermind.Blockchain;

public class InvalidBlockException : BlockchainException
{
public class InvalidBlockException : BlockchainException
{
public Block InvalidBlock { get; }
public InvalidBlockException(Block block, Exception? innerException = null)
: base($"Invalid block: {block}", innerException) => InvalidBlock = block;

public InvalidBlockException(Block invalidBlock)
: base($"Invalid block: {invalidBlock}")
{
InvalidBlock = invalidBlock;
}
}
public Block InvalidBlock { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
using Nethermind.Consensus.AuRa.Services;
using Nethermind.Consensus.AuRa.Transactions;
using Nethermind.Consensus.AuRa.Validators;
using Nethermind.Consensus.AuRa.Withdrawals;
using Nethermind.Consensus.Comparers;
using Nethermind.Consensus.Processing;
using Nethermind.Consensus.Transactions;
using Nethermind.Consensus.Validators;
using Nethermind.Consensus.Withdrawals;
using Nethermind.Core;
using Nethermind.Evm.TransactionProcessing;
using Nethermind.Init.Steps;
Expand Down Expand Up @@ -86,8 +86,9 @@ protected override BlockProcessor CreateBlockProcessor()
return processor;
}

protected virtual BlockProcessor NewBlockProcessor(AuRaNethermindApi api, ITxFilter txFilter, ContractRewriter contractRewriter) =>
new AuRaBlockProcessor(
protected virtual BlockProcessor NewBlockProcessor(AuRaNethermindApi api, ITxFilter txFilter, ContractRewriter contractRewriter)
rubo marked this conversation as resolved.
Show resolved Hide resolved
{
return new AuRaBlockProcessor(
_api.SpecProvider,
_api.BlockValidator,
_api.RewardCalculatorSource.Get(_api.TransactionProcessor),
Expand All @@ -97,11 +98,12 @@ protected virtual BlockProcessor NewBlockProcessor(AuRaNethermindApi api, ITxFil
_api.ReceiptStorage,
_api.LogManager,
_api.BlockTree,
new WithdrawalProcessor(_api.StateProvider, _api.LogManager),
NullWithdrawalProcessor.Instance,
txFilter,
GetGasLimitCalculator(),
contractRewriter
);
}

protected ReadOnlyTxProcessingEnv CreateReadOnlyTransactionProcessorSource() =>
new ReadOnlyTxProcessingEnv(_api.DbProvider, _api.ReadOnlyTrieStore, _api.BlockTree, _api.SpecProvider, _api.LogManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
using Nethermind.Consensus.AuRa.Contracts.DataStore;
using Nethermind.Consensus.AuRa.Transactions;
using Nethermind.Consensus.AuRa.Validators;
using Nethermind.Consensus.AuRa.Withdrawals;
using Nethermind.Consensus.Processing;
using Nethermind.Consensus.Producers;
using Nethermind.Consensus.Transactions;
using Nethermind.Consensus.Withdrawals;
using Nethermind.Core;
using Nethermind.Core.Specs;
using Nethermind.Crypto;
Expand Down Expand Up @@ -159,7 +159,7 @@ private BlockProcessor CreateBlockProcessor(ReadOnlyTxProcessingEnv changeableTx
_api.ReceiptStorage,
_api.LogManager,
changeableTxProcessingEnv.BlockTree,
new WithdrawalProcessor(_api.StateProvider!, _api.LogManager),
NullWithdrawalProcessor.Instance,
auRaTxFilter,
CreateGasLimitCalculator(constantContractTxProcessingEnv) as AuRaContractGasLimitOverride,
contractRewriter)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

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

namespace Nethermind.Consensus.AuRa.Withdrawals;
public class NullWithdrawalProcessor : IWithdrawalProcessor
{
public void ProcessWithdrawals(Block block, IReleaseSpec spec) { }

public static IWithdrawalProcessor Instance { get; } = new NullWithdrawalProcessor();
}
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ the previous head state.*/

return processedBlocks;
}
catch (Exception ex) // try to restore for all cost
catch (Exception ex) // try to restore at all cost
{
_logger.Trace($"Encountered exception {ex} while processing blocks.");
RestoreBranch(previousBranchStateRoot);
Expand Down
16 changes: 8 additions & 8 deletions src/Nethermind/Nethermind.Core/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ namespace Nethermind.Core;
[DebuggerDisplay("{Hash} ({Number})")]
public class Block
{
public Block(BlockHeader blockHeader, BlockBody body)
public Block(BlockHeader header, BlockBody body)
{
Header = blockHeader;
Body = body;
Header = header ?? throw new ArgumentNullException(nameof(header));
Body = body ?? throw new ArgumentNullException(nameof(body));
LukaszRozmej marked this conversation as resolved.
Show resolved Hide resolved
}

public Block(
BlockHeader blockHeader,
BlockHeader header,
IEnumerable<Transaction> transactions,
IEnumerable<BlockHeader> uncles,
IEnumerable<Withdrawal>? withdrawals = null)
{
Header = blockHeader;
Header = header ?? throw new ArgumentNullException(nameof(header));
Body = new(transactions.ToArray(), uncles.ToArray(), withdrawals?.ToArray());
}

public Block(BlockHeader blockHeader) : this(
blockHeader,
new(null, null, blockHeader.WithdrawalsRoot is null ? null : Array.Empty<Withdrawal>())
public Block(BlockHeader header) : this(
header,
new(null, null, header.WithdrawalsRoot is null ? null : Array.Empty<Withdrawal>())
)
{ }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@
using Nethermind.Core.Specs;
using Nethermind.Core.Timers;
using Nethermind.Facade.Eth;
using Nethermind.Int256;
using Nethermind.Logging;
using Nethermind.Merge.Plugin;
using Nethermind.Merge.Plugin.BlockProduction;
using Nethermind.Merge.Plugin.Handlers;
using Nethermind.Merge.Plugin.Test;
using Nethermind.Serialization.Json;
using Nethermind.Specs;
using Nethermind.Specs.ChainSpecStyle;
using NSubstitute;
using NUnit.Framework;

namespace Nethermind.Merge.AuRa.Test;

[TestFixture]
public class AuRaMergeEngineModuleTests : EngineModuleTests
{
protected override MergeTestBlockchain CreateBaseBlockChain(
Expand All @@ -40,46 +42,73 @@ protected override MergeTestBlockchain CreateBaseBlockChain(

protected override Keccak ExpectedBlockHash => new("0x990d377b67dbffee4a60db6f189ae479ffb406e8abea16af55e0469b8524cf46");

[TestCase(true)]
[TestCase(false)]
public override async Task executePayloadV1_accepts_already_known_block(bool throttleBlockProcessor)
{
await base.executePayloadV1_accepts_already_known_block(throttleBlockProcessor);
}

// Override below tests for now, it fails when asserting the blockHash of produced block equals a hardcoded precomputed one.
// This happens because for this AuRa chain the blockHash includes AuRa specific fields, hence the hash for genesis is different
// causing all subsequent blocks to have a different blockHash.
// You can verify this by removing `SealEngineType = Nethermind.Core.SealEngineType.AuRa;` from the constructor of
// the test class above and rerunning the tests.
[TestCaseSource(nameof(GetWithdrawalValidationValues))]
public override async Task newPayloadV2_should_validate_withdrawals((
IReleaseSpec Spec,
public override Task forkchoiceUpdatedV2_should_validate_withdrawals((IReleaseSpec Spec,
string ErrorMessage,
IEnumerable<Withdrawal>? Withdrawals,
string BlockHash
) input)
=> base.forkchoiceUpdatedV2_should_validate_withdrawals(input);

[Ignore("engine_newPayloadV2 fails")]
[TestCase(
"0xe168b70ac8a6f7d90734010030801fbb2dcce03a657155c4024b36ba8d1e3926",
"0x3e604e45a9a74b66a7e03f828cc2597f0cb5f5e7dc50c9211be3a62fbcd6396d",
"0xdbd87b98a6be7d4e3f11ff8500c38a0736d9a5e7a47b5cb25628d37187a98cb9",
"0x78ecfec08729d895")]
public override Task Should_process_block_as_expected_V2(string latestValidHash, string blockHash, string stateRoot, string payloadId)
=> base.Should_process_block_as_expected_V2(latestValidHash, blockHash, stateRoot, payloadId);

[TestCase(
"0xe4333fcde906675e50500bf53a6c73bc51b2517509bc3cff2d24d0de9b8dd23e",
"0xe168b70ac8a6f7d90734010030801fbb2dcce03a657155c4024b36ba8d1e3926",
"0x78ecfec08729d895")]
public override Task processing_block_should_serialize_valid_responses(string blockHash, string latestValidHash, string payloadId)
=> base.processing_block_should_serialize_valid_responses(blockHash, latestValidHash, payloadId);

[Test]
[TestCase(
"0xa66ec67b117f57388da53271f00c22a68e6c297b564f67c5904e6f2662881875",
"0xe168b70ac8a6f7d90734010030801fbb2dcce03a657155c4024b36ba8d1e3926"
)]
[Parallelizable(ParallelScope.None)]
public override Task forkchoiceUpdatedV1_should_communicate_with_boost_relay_through_http(string blockHash, string parentHash)
=> base.forkchoiceUpdatedV1_should_communicate_with_boost_relay_through_http(blockHash, parentHash);

[Ignore("engine_newPayloadV2 fails")]
public override Task Can_apply_withdrawals_correctly((Withdrawal[][] Withdrawals, (Address Account, UInt256 BalanceIncrease)[] ExpectedAccountIncrease) input)
{
await Task.CompletedTask;
return base.Can_apply_withdrawals_correctly(input);
}

[Test]
public override async Task Should_process_block_as_expected_V2()
[Ignore("engine_newPayloadV2 fails")]
public override Task Empty_block_is_valid_with_withdrawals_V2()
{
await Task.CompletedTask;
return base.Empty_block_is_valid_with_withdrawals_V2();
}

[Test]
public override async Task processing_block_should_serialize_valid_responses()
[Ignore("engine_newPayloadV2 fails")]
public override Task Should_handle_withdrawals_transition_when_Shanghai_fork_activated()
{
await Task.CompletedTask;
return base.Should_handle_withdrawals_transition_when_Shanghai_fork_activated();
}

[Test]
public override async Task forkchoiceUpdatedV1_should_communicate_with_boost_relay_through_http()
[Ignore("engine_newPayloadV2 fails")]
public override Task getPayloadBodiesByHashV1_should_return_payload_bodies_in_order_of_request_block_hashes_and_null_for_unknown_hashes(IList<Withdrawal> withdrawals)
{
// NOTE: This is the blockhash AuRa produces `0xb337e096b1540ade48f63104b653691af54bb87feb0944d7ec597baeb04f7e1b`
await Task.CompletedTask;
return base.getPayloadBodiesByHashV1_should_return_payload_bodies_in_order_of_request_block_hashes_and_null_for_unknown_hashes(withdrawals);
}

[Ignore("engine_newPayloadV2 fails")]
public override Task getPayloadBodiesByRangeV1_should_return_canonical(IList<Withdrawal> withdrawals)
{
return base.getPayloadBodiesByRangeV1_should_return_canonical(withdrawals);
}

[Ignore("engine_newPayloadV2 fails")]
public override Task getPayloadBodiesByRangeV1_should_return_payload_bodies_in_order_of_request_range_and_null_for_unknown_indexes(IList<Withdrawal> withdrawals)
{
return base.getPayloadBodiesByRangeV1_should_return_payload_bodies_in_order_of_request_range_and_null_for_unknown_indexes(withdrawals);
}

class MergeAuRaTestBlockchain : MergeTestBlockchain
Copy link
Contributor

@MarekM25 MarekM25 Mar 28, 2023

Choose a reason for hiding this comment

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

MergeAuRaTestBlockchain resolves internally the Ethereum mainnet withdrawal processor (https://github.com/NethermindEth/nethermind/blob/master/src/Nethermind/Nethermind.Consensus/Withdrawals/WithdrawalProcessor.cs) instead of Aura version of withdrawal processor. It will be easily checked by debugging tests, for example Nethermind.Merge.AuRa.Test.newPayloadV2_should_validate_withdrawals

Copy link
Contributor

Choose a reason for hiding this comment

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

This point is even more important because of the current state of hive tests for withdrawals.

Expand All @@ -105,7 +134,29 @@ protected override IBlockProducer CreateTestBlockProducer(TxPoolTxSource txPoolT
LogManager,
targetAdjustedGasLimitCalculator);

BlockProducerEnvFactory blockProducerEnvFactory = new(
AuRaMergeBlockProducerEnvFactory blockProducerEnvFactory = new(
new()
{
BlockTree = BlockTree,
ChainSpec = new ChainSpec
{
AuRa = new()
{
WithdrawalContractAddress = new("0xbabe2bed00000000000000000000000000000003")
},
Parameters = new()
},
DbProvider = DbProvider,
ConfigProvider = new ConfigProvider(),
EthereumJsonSerializer = new EthereumJsonSerializer(),
LogManager = LogManager,
ReadOnlyTrieStore = ReadOnlyTrieStore,
SpecProvider = SpecProvider,
TransactionComparerProvider = TransactionComparerProvider,
TxPool = TxPool
},
new AuRaConfig(),
new DisposableStack(),
DbProvider,
BlockTree,
ReadOnlyTrieStore,
Expand Down Expand Up @@ -155,7 +206,6 @@ protected override IBlockProducer CreateTestBlockProducer(TxPoolTxSource txPoolT

return new MergeBlockProducer(preMergeBlockProducer, postMergeBlockProducer, PoSSwitcher);
}

}
}

Loading