-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into refactor/tx-validator
# Conflicts: # src/Nethermind/Nethermind.Optimism/InitializeBlockchainOptimism.cs
- Loading branch information
Showing
98 changed files
with
641 additions
and
629 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 34 additions & 29 deletions
63
src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/BeaconBlockRootHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,44 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Core.Specs; | ||
using System; | ||
using Nethermind.Core; | ||
using Nethermind.Core.Eip2930; | ||
using Nethermind.Core.Specs; | ||
using Nethermind.Crypto; | ||
using Nethermind.Evm.Tracing; | ||
using Nethermind.Evm.TransactionProcessing; | ||
using Nethermind.Int256; | ||
using Nethermind.State; | ||
using Nethermind.Core.Crypto; | ||
using Nethermind.Core.Extensions; | ||
|
||
namespace Nethermind.Consensus.BeaconBlockRoot; | ||
|
||
public class BeaconBlockRootHandler : IBeaconBlockRootHandler | ||
namespace Nethermind.Blockchain.BeaconBlockRoot; | ||
public class BeaconBlockRootHandler(ITransactionProcessor processor) : IBeaconBlockRootHandler | ||
{ | ||
public void ApplyContractStateChanges(Block block, IReleaseSpec spec, IWorldState stateProvider) | ||
{ | ||
if (!spec.IsBeaconBlockRootAvailable || | ||
block.IsGenesis || | ||
block.Header.ParentBeaconBlockRoot is null) | ||
return; | ||
|
||
Address eip4788Account = spec.Eip4788ContractAddress ?? Eip4788Constants.BeaconRootsAddress; | ||
private const long GasLimit = 30_000_000L; | ||
|
||
if (!stateProvider.AccountExists(eip4788Account)) | ||
return; | ||
|
||
UInt256 timestamp = (UInt256)block.Timestamp; | ||
Hash256 parentBeaconBlockRoot = block.ParentBeaconBlockRoot; | ||
|
||
UInt256.Mod(timestamp, Eip4788Constants.HistoryBufferLength, out UInt256 timestampReduced); | ||
UInt256 rootIndex = timestampReduced + Eip4788Constants.HistoryBufferLength; | ||
|
||
StorageCell tsStorageCell = new(eip4788Account, timestampReduced); | ||
StorageCell brStorageCell = new(eip4788Account, rootIndex); | ||
|
||
stateProvider.Set(tsStorageCell, Bytes.WithoutLeadingZeros(timestamp.ToBigEndian()).ToArray()); | ||
stateProvider.Set(brStorageCell, Bytes.WithoutLeadingZeros(parentBeaconBlockRoot.Bytes).ToArray()); | ||
public void StoreBeaconRoot(Block block, IReleaseSpec spec) | ||
{ | ||
BlockHeader? header = block.Header; | ||
var canInsertBeaconRoot = spec.IsBeaconBlockRootAvailable | ||
&& !header.IsGenesis | ||
&& header.ParentBeaconBlockRoot is not null; | ||
|
||
if (canInsertBeaconRoot) | ||
{ | ||
Address beaconRootsAddress = spec.Eip4788ContractAddress ?? Eip4788Constants.BeaconRootsAddress; | ||
Transaction transaction = new() | ||
{ | ||
Value = UInt256.Zero, | ||
Data = header.ParentBeaconBlockRoot.Bytes.ToArray(), | ||
To = beaconRootsAddress, | ||
SenderAddress = Address.SystemUser, | ||
GasLimit = GasLimit, | ||
GasPrice = UInt256.Zero, | ||
AccessList = new AccessList.Builder().AddAddress(beaconRootsAddress).Build() | ||
}; | ||
|
||
transaction.Hash = transaction.CalculateHash(); | ||
|
||
processor.Execute(transaction, header, NullTxTracer.Instance); | ||
} | ||
} | ||
} |
7 changes: 3 additions & 4 deletions
7
src/Nethermind/Nethermind.Blockchain/BeaconBlockRoot/IBeaconBlockRootHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Core.Specs; | ||
using Nethermind.Core; | ||
using Nethermind.State; | ||
using Nethermind.Core.Specs; | ||
|
||
namespace Nethermind.Consensus.BeaconBlockRoot; | ||
namespace Nethermind.Blockchain.BeaconBlockRoot; | ||
public interface IBeaconBlockRootHandler | ||
{ | ||
void ApplyContractStateChanges(Block block, IReleaseSpec spec, IWorldState state); | ||
void StoreBeaconRoot(Block block, IReleaseSpec spec); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.