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

eip 7840 implementation #7964

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
7 changes: 7 additions & 0 deletions src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,13 @@ public interface IReleaseSpec : IEip1559Spec, IReceiptSpec
/// <remarks>Backward compatibility for early Kovan blocks.</remarks>
bool ValidateChainId => true;

/// <summary>
/// EIP-7780: Add blob schedule to EL config files
/// </summary>
bool IsEip7840Enabled { get; }
public ulong TargetBlobCount { get; set; }
public ulong MaxBlobCount { get; set; }

public ulong WithdrawalTimestamp { get; }

public ulong Eip4844TransitionTimestamp { get; }
Expand Down
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.Core/Specs/ReleaseSpecDecorator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public class ReleaseSpecDecorator(IReleaseSpec spec) : IReleaseSpec
public virtual bool IsEip4895Enabled => spec.IsEip4895Enabled;
public virtual bool IsEip4844Enabled => spec.IsEip4844Enabled;
public virtual bool IsEip4788Enabled => spec.IsEip4788Enabled;
public bool IsEip7840Enabled => spec.IsEip7840Enabled;
public ulong TargetBlobCount { get; set; }
public ulong MaxBlobCount { get; set; }
public virtual Address? Eip4788ContractAddress => spec.Eip4788ContractAddress;
public bool IsEip6110Enabled => spec.IsEip6110Enabled;
public Address DepositContractAddress => spec.DepositContractAddress;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,19 @@ private readonly record struct BlockFeeHistorySearchInfo(
BlockFeeHistorySearchInfo BlockFeeHistorySearchInfoFromBlock(Block b)
{
BlobGasCalculator.TryCalculateFeePerBlobGas(b.Header, out UInt256 feePerBlobGas);

IReleaseSpec spec = _specProvider.GetSpec(b.Header);
var maxBlobGasPerBlob = spec.IsEip7840Enabled
? spec.MaxBlobCount
: Eip4844Constants.MaxBlobGasPerBlock;

return new(
b.Number,
b.BaseFeePerGas,
BaseFeeCalculator.Calculate(b.Header, _specProvider.GetSpecFor1559(b.Number + 1)),
feePerBlobGas == UInt256.MaxValue ? UInt256.Zero : feePerBlobGas,
b.GasUsed / (double)b.GasLimit,
(b.BlobGasUsed ?? 0) / (double)Eip4844Constants.MaxBlobGasPerBlock,
(b.BlobGasUsed ?? 0) / (double)maxBlobGasPerBlob,
b.ParentHash,
b.GasUsed,
b.Transactions.Length,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,9 @@ public ulong Eip4844TransitionTimestamp
}
}

public bool IsEip7840Enabled => _spec.IsEip7840Enabled;
public ulong TargetBlobCount { get; set; }
public ulong MaxBlobCount { get; set; }
public bool IsEip1153Enabled => _spec.IsEip1153Enabled;
public bool IsEip3651Enabled => _spec.IsEip3651Enabled;
public bool IsEip3855Enabled => _spec.IsEip3855Enabled;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public class ChainParameters
public ulong? Eip7702TransitionTimestamp { get; set; }
public ulong? OpGraniteTransitionTimestamp { get; set; }
public ulong? OpHoloceneTransitionTimestamp { get; set; }
public ulong? Eip7840TransitionTimestamp { get; set; }

#region EIP-4844 parameters
/// <summary>
Expand Down
5 changes: 5 additions & 0 deletions src/Nethermind/Nethermind.Specs/ChainSpecStyle/ChainSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Nethermind.Config;
using Nethermind.Core;
using Nethermind.Int256;
using Nethermind.Specs.ChainSpecStyle.Json;

namespace Nethermind.Specs.ChainSpecStyle
{
Expand Down Expand Up @@ -77,5 +78,9 @@ public class ChainSpec
public ulong? ShanghaiTimestamp { get; set; }

public ulong? CancunTimestamp { get; set; }

public ulong? PragueTimestamp { get; set; }

public Dictionary<string, ChainSpecBlobCountJson> BlobSchedule { get; set; } = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using Nethermind.Core.Specs;
using Nethermind.Int256;
using Nethermind.Logging;
using Nethermind.Specs.ChainSpecStyle.Json;
using Nethermind.Specs.Forks;

namespace Nethermind.Specs.ChainSpecStyle
{
Expand Down Expand Up @@ -199,6 +201,8 @@ private ReleaseSpec CreateReleaseSpec(ChainSpec chainSpec, long releaseStartBloc
bool eip4844FeeCollector = releaseSpec.IsEip4844Enabled && (chainSpec.Parameters.Eip4844FeeCollectorTransitionTimestamp ?? long.MaxValue) <= releaseStartTimestamp;
releaseSpec.FeeCollector = (eip1559FeeCollector || eip4844FeeCollector) ? chainSpec.Parameters.FeeCollector : null;

releaseSpec.IsEip7840Enabled = (chainSpec.Parameters.Eip7840TransitionTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp;
SetMaxAndTargetBlobCount(chainSpec, releaseSpec, releaseStartTimestamp);
releaseSpec.Eip1559BaseFeeMinValue = releaseSpec.IsEip1559Enabled && (chainSpec.Parameters.Eip1559BaseFeeMinValueTransition ?? long.MaxValue) <= releaseStartBlock ? chainSpec.Parameters.Eip1559BaseFeeMinValue : null;
releaseSpec.ElasticityMultiplier = chainSpec.Parameters.Eip1559ElasticityMultiplier ?? Eip1559Constants.DefaultElasticityMultiplier;
releaseSpec.ForkBaseFee = chainSpec.Parameters.Eip1559BaseFeeInitialValue ?? Eip1559Constants.DefaultForkBaseFee;
Expand Down Expand Up @@ -245,6 +249,39 @@ private ReleaseSpec CreateReleaseSpec(ChainSpec chainSpec, long releaseStartBloc
return releaseSpec;
}

private void SetMaxAndTargetBlobCount(ChainSpec chainSpec, ReleaseSpec spec, ulong? releaseStartTimestamp = null)
{
if (!spec.IsEip7840Enabled) return;

(IReleaseSpec? fork, IReleaseSpec? previousFork) = GetCurrentAndPreviousFork(chainSpec, releaseStartTimestamp);
if (fork is null) return;

if (chainSpec.BlobSchedule.TryGetValue(fork.Name.ToLower(), out ChainSpecBlobCountJson blobCount) ||
chainSpec.BlobSchedule.TryGetValue(previousFork.Name.ToLower(), out blobCount))
{
spec.TargetBlobCount = blobCount.TargetBlobCount;
spec.MaxBlobCount = blobCount.MaxBlobCount;
}
else
{
spec.TargetBlobCount = 0;
spec.MaxBlobCount = 0;
}
}

private (IReleaseSpec?, IReleaseSpec?) GetCurrentAndPreviousFork(ChainSpec chainSpec, ulong? releaseStartTimestamp = null)
{
// TODO: add Osaka
if ((chainSpec.PragueTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp)
{
return (Prague.Instance, Cancun.Instance);
}

return (chainSpec.CancunTimestamp ?? ulong.MaxValue) <= releaseStartTimestamp
? (Cancun.Instance, Shanghai.Instance)
: (null, null);
}

public void UpdateMergeTransitionInfo(long? blockNumber, UInt256? terminalTotalDifficulty = null)
{
if (blockNumber is not null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ private ChainSpec InitChainSpecFrom(ChainSpecJson chainSpecJson)
chainSpec.ChainId = chainSpecJson.Params.ChainId ?? chainSpec.NetworkId;
chainSpec.Name = chainSpecJson.Name;
chainSpec.DataDir = chainSpecJson.DataDir;
chainSpec.BlobSchedule = chainSpecJson.BlobScheduleJson;
LoadGenesis(chainSpecJson, chainSpec);
LoadEngine(chainSpecJson, chainSpec);
LoadAllocations(chainSpecJson, chainSpec);
Expand Down Expand Up @@ -175,6 +176,7 @@ bool GetForInnerPathExistence(KeyValuePair<string, JsonElement> o) =>
MergeForkIdTransition = chainSpecJson.Params.MergeForkIdTransition,
TerminalTotalDifficulty = chainSpecJson.Params.TerminalTotalDifficulty,
TerminalPoWBlockNumber = chainSpecJson.Params.TerminalPoWBlockNumber,
Eip7840TransitionTimestamp = chainSpecJson.Params.Eip7840TransitionTimestamp,

OntakeTransition = chainSpecJson.Params.OntakeTransition,
};
Expand Down Expand Up @@ -224,6 +226,7 @@ chainSpec.Parameters.Eip1283DisableTransition is null
chainSpec.LondonBlockNumber = chainSpec.Parameters.Eip1559Transition;
chainSpec.ShanghaiTimestamp = chainSpec.Parameters.Eip3651TransitionTimestamp;
chainSpec.CancunTimestamp = chainSpec.Parameters.Eip4844TransitionTimestamp;
chainSpec.PragueTimestamp = chainSpec.Parameters.Eip7840TransitionTimestamp;

// TheMerge parameters
chainSpec.MergeForkIdBlockNumber = chainSpec.Parameters.MergeForkIdTransition;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

namespace Nethermind.Specs.ChainSpecStyle.Json;

public class ChainSpecBlobCountJson
{
public ulong TargetBlobCount { get; set; }
public ulong MaxBlobCount { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ internal class ChainSpecJson
public string[] Nodes { get; set; }
[JsonPropertyName("accounts")]
public Dictionary<string, AllocationJson> Accounts { get; set; }
public Dictionary<string, ChainSpecBlobCountJson> BlobScheduleJson { get; set; } = [];

internal class EngineJson
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,5 @@ internal class ChainSpecParamsJson
public ulong? Eip7702TransitionTimestamp { get; set; }
public ulong? OpGraniteTransitionTimestamp { get; set; }
public ulong? OpHoloceneTransitionTimestamp { get; set; }
public ulong? Eip7840TransitionTimestamp { get; set; }
}
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.Specs/ReleaseSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ public bool IsEip1559Enabled
public bool IsEip7002Enabled { get; set; }
public bool IsEip7251Enabled { get; set; }
public bool IsOntakeEnabled { get; set; }
public bool IsEip7840Enabled { get; set; }
public ulong TargetBlobCount { get; set; }
public ulong MaxBlobCount { get; set; }

private Address _eip7251ContractAddress;
public Address Eip7251ContractAddress
Expand Down
Loading