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 56 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
3 changes: 2 additions & 1 deletion src/Nethermind/Chains/chiado.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"validators": {
"multi": {
"0": {
"list": ["0x14747a698Ec1227e6753026C08B29b4d5D3bC484"]
"list": [ "0x14747a698Ec1227e6753026C08B29b4d5D3bC484" ]
},
"67334": {
"list": [
Expand All @@ -30,6 +30,7 @@
"randomnessContractAddress": {
"0": "0x3000000000000000000000000000000000000001"
},
"withdrawalContractAddress": "0xb97036A26259B7147018913bD58a774cf91acf25",
"twoThirdsMajorityTransition": 0,
"posdaoTransition": 0,
"blockGasLimitContractTransitions": {
Expand Down
1 change: 1 addition & 0 deletions src/Nethermind/Chains/gnosis.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"randomnessContractAddress": {
"9186425": "0x5870b0527DeDB1cFBD9534343Feda1a41Ce47766"
},
"withdrawalContractAddress": "0x0B98057eA310F4d31F2a452B414647007d1645d9",
"posdaoTransition": 9186425,
"rewriteBytecode": {
"21735000": {
Expand Down
1,168 changes: 589 additions & 579 deletions src/Nethermind/Nethermind.Abi.Test/AbiTests.cs

Large diffs are not rendered by default.

74 changes: 42 additions & 32 deletions src/Nethermind/Nethermind.Abi/AbiArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,66 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using Nethermind.Core.Extensions;
using Nethermind.Int256;

namespace Nethermind.Abi
namespace Nethermind.Abi;

public class AbiArray : AbiType
{
public class AbiArray : AbiType
public AbiType ElementType { get; }

public AbiArray(AbiType elementType)
{
public AbiType ElementType { get; }
ElementType = elementType;
Name = $"{ElementType}[]";
CSharpType = ElementType.CSharpType.MakeArrayType();
}

public AbiArray(AbiType elementType)
{
ElementType = elementType;
Name = $"{ElementType}[]";
CSharpType = ElementType.CSharpType.MakeArrayType();
}
public override bool IsDynamic => true;

public override bool IsDynamic => true;
public override string Name { get; }

public override string Name { get; }
public override Type CSharpType { get; }

public override Type CSharpType { get; }
public override (object, int) Decode(byte[] data, int position, bool packed)
{
UInt256 length;
(length, position) = UInt256.DecodeUInt(data, position, packed);
return DecodeSequence(ElementType.CSharpType, (int)length, ElementTypes, data, packed, position);
}

public override (object, int) Decode(byte[] data, int position, bool packed)
public override byte[] Encode(object? arg, bool packed)
{
int length;
byte[][] encodedItems;
switch (arg)
{
UInt256 length;
(length, position) = UInt256.DecodeUInt(data, position, packed);
return DecodeSequence(ElementType.CSharpType, (int)length, ElementTypes, data, packed, position);
case Array array:
length = array.Length;
encodedItems = EncodeSequence(length, ElementTypes, array.Cast<object?>(), packed, 1);
break;
case IList list:
length = list.Count;
encodedItems = EncodeSequence(length, ElementTypes, list.Cast<object?>(), packed, 1);
break;
default:
throw new AbiException(AbiEncodingExceptionMessage);
}

public override byte[] Encode(object? arg, bool packed)
{
if (arg is Array input)
{
byte[][] encodedItems = EncodeSequence(input.Length, ElementTypes, input.Cast<object?>(), packed, 1);
encodedItems[0] = UInt256.Encode((BigInteger)input.Length, packed);
return Bytes.Concat(encodedItems);
}

throw new AbiException(AbiEncodingExceptionMessage);
}
encodedItems[0] = UInt256.Encode((BigInteger)length, packed);
return Bytes.Concat(encodedItems);
}

private IEnumerable<AbiType> ElementTypes
private IEnumerable<AbiType> ElementTypes
{
get
{
get
{
yield return ElementType;
}
yield return ElementType;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,113 +9,112 @@
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;
using NUnit.Framework;

namespace Nethermind.AuRa.Test.Contract
namespace Nethermind.AuRa.Test.Contract;

public class AuRaContractGasLimitOverrideTests
{
public class AuRaContractGasLimitOverrideTests
private const int CorrectHeadGasLimit = 100000000;

// TestContract:
// pragma solidity ^0.5.0;
// contract TestValidatorSet {
// function blockGasLimit() public view returns(uint256) {
// return 100000000;
// }
// }
[Test]
public async Task can_read_block_gas_limit_from_contract()
{
private const int CorrectHeadGasLimit = 100000000;
using TestGasLimitContractBlockchain chain = await TestContractBlockchain.ForTest<TestGasLimitContractBlockchain, AuRaContractGasLimitOverrideTests>();
long gasLimit = chain.GasLimitCalculator.GetGasLimit(chain.BlockTree.Head.Header);
gasLimit.Should().Be(CorrectHeadGasLimit);
}

// TestContract:
// pragma solidity ^0.5.0;
// contract TestValidatorSet {
// function blockGasLimit() public view returns(uint256) {
// return 100000000;
// }
// }
[Test]
public async Task can_read_block_gas_limit_from_contract()
{
using TestGasLimitContractBlockchain chain = await TestContractBlockchain.ForTest<TestGasLimitContractBlockchain, AuRaContractGasLimitOverrideTests>();
long gasLimit = chain.GasLimitCalculator.GetGasLimit(chain.BlockTree.Head.Header);
gasLimit.Should().Be(CorrectHeadGasLimit);
}
[Test]
public async Task caches_read_block_gas_limit()
{
using TestGasLimitContractBlockchain chain = await TestContractBlockchain.ForTest<TestGasLimitContractBlockchain, AuRaContractGasLimitOverrideTests>();
chain.GasLimitCalculator.GetGasLimit(chain.BlockTree.Head.Header);
long? gasLimit = chain.GasLimitOverrideCache.GasLimitCache.Get(chain.BlockTree.Head.Hash);
gasLimit.Should().Be(CorrectHeadGasLimit);
}

[Test]
public async Task caches_read_block_gas_limit()
{
using TestGasLimitContractBlockchain chain = await TestContractBlockchain.ForTest<TestGasLimitContractBlockchain, AuRaContractGasLimitOverrideTests>();
chain.GasLimitCalculator.GetGasLimit(chain.BlockTree.Head.Header);
long? gasLimit = chain.GasLimitOverrideCache.GasLimitCache.Get(chain.BlockTree.Head.Hash);
gasLimit.Should().Be(CorrectHeadGasLimit);
}
[Test]
public async Task can_validate_gas_limit_correct()
{
using TestGasLimitContractBlockchain chain = await TestContractBlockchain.ForTest<TestGasLimitContractBlockchain, AuRaContractGasLimitOverrideTests>();
bool isValid = ((AuRaContractGasLimitOverride)chain.GasLimitCalculator).IsGasLimitValid(chain.BlockTree.Head.Header, CorrectHeadGasLimit, out _);
isValid.Should().BeTrue();
}

[Test]
public async Task can_validate_gas_limit_correct()
{
using TestGasLimitContractBlockchain chain = await TestContractBlockchain.ForTest<TestGasLimitContractBlockchain, AuRaContractGasLimitOverrideTests>();
bool isValid = ((AuRaContractGasLimitOverride)chain.GasLimitCalculator).IsGasLimitValid(chain.BlockTree.Head.Header, CorrectHeadGasLimit, out _);
isValid.Should().BeTrue();
}
[Test]
public async Task can_validate_gas_limit_incorrect()
{
using TestGasLimitContractBlockchain chain = await TestContractBlockchain.ForTest<TestGasLimitContractBlockchain, AuRaContractGasLimitOverrideTests>();
bool isValid = ((AuRaContractGasLimitOverride)chain.GasLimitCalculator).IsGasLimitValid(chain.BlockTree.Head.Header, 100000001, out long? expectedGasLimit);
isValid.Should().BeFalse();
expectedGasLimit.Should().Be(CorrectHeadGasLimit);
}

[Test]
public async Task can_validate_gas_limit_incorrect()
{
using TestGasLimitContractBlockchain chain = await TestContractBlockchain.ForTest<TestGasLimitContractBlockchain, AuRaContractGasLimitOverrideTests>();
bool isValid = ((AuRaContractGasLimitOverride)chain.GasLimitCalculator).IsGasLimitValid(chain.BlockTree.Head.Header, 100000001, out long? expectedGasLimit);
isValid.Should().BeFalse();
expectedGasLimit.Should().Be(CorrectHeadGasLimit);
}
[Test]
public async Task skip_validate_gas_limit_before_enabled()
{
using TestGasLimitContractBlockchainLateBlockGasLimit chain = await TestContractBlockchain.ForTest<TestGasLimitContractBlockchainLateBlockGasLimit, AuRaContractGasLimitOverrideTests>();
bool isValid = ((AuRaContractGasLimitOverride)chain.GasLimitCalculator).IsGasLimitValid(chain.BlockTree.Genesis, 100000001, out _);
isValid.Should().BeTrue();
}

[Test]
public async Task skip_validate_gas_limit_before_enabled()
{
using TestGasLimitContractBlockchainLateBlockGasLimit chain = await TestContractBlockchain.ForTest<TestGasLimitContractBlockchainLateBlockGasLimit, AuRaContractGasLimitOverrideTests>();
bool isValid = ((AuRaContractGasLimitOverride)chain.GasLimitCalculator).IsGasLimitValid(chain.BlockTree.Genesis, 100000001, out _);
isValid.Should().BeTrue();
}
public class TestGasLimitContractBlockchain : TestContractBlockchain
{
public IGasLimitCalculator GasLimitCalculator { get; private set; }
public AuRaContractGasLimitOverride.Cache GasLimitOverrideCache { get; private set; }

public class TestGasLimitContractBlockchain : TestContractBlockchain
protected override BlockProcessor CreateBlockProcessor()
{
public IGasLimitCalculator GasLimitCalculator { get; private set; }
public AuRaContractGasLimitOverride.Cache GasLimitOverrideCache { get; private set; }

protected override BlockProcessor CreateBlockProcessor()
{
KeyValuePair<long, Address> blockGasLimitContractTransition = ChainSpec.AuRa.BlockGasLimitContractTransitions.First();
BlockGasLimitContract gasLimitContract = new(AbiEncoder.Instance, blockGasLimitContractTransition.Value, blockGasLimitContractTransition.Key,
new ReadOnlyTxProcessingEnv(
DbProvider,
new TrieStore(DbProvider.StateDb, LimboLogs.Instance).AsReadOnly(),
BlockTree, SpecProvider, LimboLogs.Instance));

GasLimitOverrideCache = new AuRaContractGasLimitOverride.Cache();
GasLimitCalculator = new AuRaContractGasLimitOverride(new[] { gasLimitContract }, GasLimitOverrideCache, false, new FollowOtherMiners(SpecProvider), LimboLogs.Instance);
KeyValuePair<long, Address> blockGasLimitContractTransition = ChainSpec.AuRa.BlockGasLimitContractTransitions.First();
BlockGasLimitContract gasLimitContract = new(AbiEncoder.Instance, blockGasLimitContractTransition.Value, blockGasLimitContractTransition.Key,
new ReadOnlyTxProcessingEnv(
DbProvider,
new TrieStore(DbProvider.StateDb, LimboLogs.Instance).AsReadOnly(),
BlockTree, SpecProvider, LimboLogs.Instance));

return new AuRaBlockProcessor(
SpecProvider,
Always.Valid,
new RewardCalculator(SpecProvider),
new BlockProcessor.BlockValidationTransactionsExecutor(TxProcessor, State),
State,
Storage,
ReceiptStorage,
LimboLogs.Instance,
BlockTree,
new WithdrawalProcessor(State, LogManager),
null,
GasLimitCalculator as AuRaContractGasLimitOverride);
}
GasLimitOverrideCache = new AuRaContractGasLimitOverride.Cache();
GasLimitCalculator = new AuRaContractGasLimitOverride(new[] { gasLimitContract }, GasLimitOverrideCache, false, new FollowOtherMiners(SpecProvider), LimboLogs.Instance);

protected override Task AddBlocksOnStart() => Task.CompletedTask;
return new AuRaBlockProcessor(
SpecProvider,
Always.Valid,
new RewardCalculator(SpecProvider),
new BlockProcessor.BlockValidationTransactionsExecutor(TxProcessor, State),
State,
Storage,
ReceiptStorage,
LimboLogs.Instance,
BlockTree,
NullWithdrawalProcessor.Instance,
null,
GasLimitCalculator as AuRaContractGasLimitOverride);
}

public class TestGasLimitContractBlockchainLateBlockGasLimit : TestGasLimitContractBlockchain
protected override Task AddBlocksOnStart() => Task.CompletedTask;
}

public class TestGasLimitContractBlockchainLateBlockGasLimit : TestGasLimitContractBlockchain
{
protected override BlockProcessor CreateBlockProcessor()
{
protected override BlockProcessor CreateBlockProcessor()
{
KeyValuePair<long, Address> blockGasLimitContractTransition = ChainSpec.AuRa.BlockGasLimitContractTransitions.First();
ChainSpec.AuRa.BlockGasLimitContractTransitions = new Dictionary<long, Address>() { { 10, blockGasLimitContractTransition.Value } };
return base.CreateBlockProcessor();
}
KeyValuePair<long, Address> blockGasLimitContractTransition = ChainSpec.AuRa.BlockGasLimitContractTransitions.First();
ChainSpec.AuRa.BlockGasLimitContractTransitions = new Dictionary<long, Address>() { { 10, blockGasLimitContractTransition.Value } };
return base.CreateBlockProcessor();
}
}
}
Loading