Skip to content

Commit 3d975ef

Browse files
authored
Init beacon root precompile state for genesis (#5982)
1 parent 011687d commit 3d975ef

File tree

5 files changed

+12
-0
lines changed

5 files changed

+12
-0
lines changed

src/Nethermind/Nethermind.Blockchain/GenesisLoader.cs

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Nethermind.Evm.TransactionProcessing;
1616
using Nethermind.Specs.ChainSpecStyle;
1717
using Nethermind.State;
18+
using Nethermind.Consensus.BeaconBlockRoot;
1819

1920
namespace Nethermind.Blockchain
2021
{
@@ -24,6 +25,7 @@ public class GenesisLoader
2425
private readonly ISpecProvider _specProvider;
2526
private readonly IWorldState _stateProvider;
2627
private readonly ITransactionProcessor _transactionProcessor;
28+
private readonly BeaconBlockRootHandler _beaconBlockRootHandler;
2729

2830
public GenesisLoader(
2931
ChainSpec chainSpec,
@@ -35,6 +37,7 @@ public GenesisLoader(
3537
_specProvider = specProvider ?? throw new ArgumentNullException(nameof(specProvider));
3638
_stateProvider = stateProvider ?? throw new ArgumentNullException(nameof(stateProvider));
3739
_transactionProcessor = transactionProcessor ?? throw new ArgumentNullException(nameof(transactionProcessor));
40+
_beaconBlockRootHandler = new BeaconBlockRootHandler();
3841
}
3942

4043
public Block Load()
@@ -45,6 +48,8 @@ public Block Load()
4548
// we no longer need the allocations - 0.5MB RAM, 9000 objects for mainnet
4649
_chainSpec.Allocations = null;
4750

51+
_beaconBlockRootHandler?.HandleBeaconBlockRoot(genesis, _specProvider.GenesisSpec, _stateProvider);
52+
4853
_stateProvider.Commit(_specProvider.GenesisSpec, true);
4954

5055
_stateProvider.CommitTree(0);

src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpecLoader.cs

+6
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,12 @@ private static void LoadGenesis(ChainSpecJson chainSpecJson, ChainSpec chainSpec
389389
genesisHeader.ExcessBlobGas = chainSpecJson.Genesis.ExcessBlobGas;
390390
}
391391

392+
bool isEip4788Enabled = chainSpecJson.Params.Eip4788TransitionTimestamp != null && genesisHeader.Timestamp >= chainSpecJson.Params.Eip4788TransitionTimestamp;
393+
if (isEip4788Enabled)
394+
{
395+
genesisHeader.ParentBeaconBlockRoot = chainSpecJson.Genesis.ParentBeaconBlockRoot;
396+
}
397+
392398
genesisHeader.AuRaStep = step;
393399
genesisHeader.AuRaSignature = auRaSignature;
394400

src/Nethermind/Nethermind.Specs/ChainSpecStyle/Json/ChainSpecGenesisJson.cs

+1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ internal class ChainSpecGenesisJson
2525

2626
public ulong? BlobGasUsed { get; set; }
2727
public ulong? ExcessBlobGas { get; set; }
28+
public Keccak ParentBeaconBlockRoot { get; set; }
2829
}
2930
}

0 commit comments

Comments
 (0)