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

Xdai/minimal base fee #3576

Merged
merged 8 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion src/Nethermind/Nethermind.Core.Test/BlockHeaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,14 @@ public void Eip_1559_CalculateBaseFee_should_returns_zero_when_eip1559_not_enabl
[TestCase(500, 0, 0, 200)]
[TestCase(21, 23, 23, 21)]
[TestCase(21, 23, 61, 300)]
public void Eip_1559_CalculateBaseFee(long gasTarget, long baseFee, long expectedBaseFee, long gasUsed)
[TestCase(500, 0, 10, 200, 10)]
[TestCase(100, 100, 88, 0, 80)]
[TestCase(100, 100, 110, 0, 110)]
public void Eip_1559_CalculateBaseFee(long gasTarget, long baseFee, long expectedBaseFee, long gasUsed, long? minimalBaseFee = null)
{
IReleaseSpec releaseSpec = Substitute.For<IReleaseSpec>();
releaseSpec.IsEip1559Enabled.Returns(true);
releaseSpec.Eip1559BaseFeeMinValue.Returns((UInt256?)minimalBaseFee);

BlockHeader blockHeader = Build.A.BlockHeader.TestObject;
blockHeader.Number = 2001;
Expand Down
6 changes: 6 additions & 0 deletions src/Nethermind/Nethermind.Core/BaseFeeCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.
//

using System;
using Nethermind.Core.Specs;
using Nethermind.Int256;

Expand Down Expand Up @@ -59,6 +60,11 @@ public static UInt256 Calculate(BlockHeader parent, IReleaseSpec spec)
{
expectedBaseFee = Eip1559Constants.ForkBaseFee;
}

if (spec.Eip1559BaseFeeMinValue.HasValue)
{
expectedBaseFee = UInt256.Max(expectedBaseFee, spec.Eip1559BaseFeeMinValue.Value);
}
}

return expectedBaseFee;
Expand Down
2 changes: 2 additions & 0 deletions src/Nethermind/Nethermind.Core/Specs/IReleaseSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -330,5 +330,7 @@ public interface IReleaseSpec
public bool BaseFeeEnabled => IsEip3198Enabled;

public Address? Eip1559FeeCollector => null;

public UInt256? Eip1559BaseFeeMinValue => null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using FluentAssertions;
using Nethermind.Core;
using Nethermind.Core.Specs;
using Nethermind.Int256;
using Nethermind.Serialization.Json;
using Nethermind.Specs.ChainSpecStyle;
using Nethermind.Specs.Forks;
Expand Down Expand Up @@ -398,6 +399,8 @@ public void Eip_transitions_loaded_correctly()
Eip1559Transition = 15590L,
Eip1559FeeCollectorTransition = 15591L,
Eip1559FeeCollector = Address.SystemUser,
Eip1559BaseFeeMinValueTransition = 15592L,
Eip1559BaseFeeMinValue = UInt256.UInt128MaxValue,
Eip3198Transition = 31980L,
Eip3529Transition = 35290L,
Eip3541Transition = 35410L,
Expand Down Expand Up @@ -455,6 +458,7 @@ void TestTransitions(long blockNumber, Action<ReleaseSpec> changes)
TestTransitions(13440L, r => { r.IsEip1344Enabled = true; });
TestTransitions(15590L, r => { r.IsEip1559Enabled = true; });
TestTransitions(15591L, r => { r.Eip1559FeeCollector = Address.SystemUser; });
TestTransitions(15592L, r => { r.Eip1559BaseFeeMinValue = UInt256.UInt128MaxValue; });
TestTransitions(18840L, r => { r.IsEip1884Enabled = true; });
TestTransitions(20280L, r => { r.IsEip2028Enabled = true; });
TestTransitions(22000L, r => { r.IsEip2200Enabled = true; });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ public class ChainParameters
/// <summary>
/// Optional, address where burnt EIP-1559 fees will go
/// </summary>
public Address Eip1559FeeCollector { get; set; }
public Address Eip1559FeeCollector { get; set; }

/// <summary>
/// Block from which EIP1559 base fee cannot drop below <see cref="Eip1559BaseFeeMinValue"/>
/// </summary>
public long? Eip1559BaseFeeMinValueTransition { get; set; }

/// <summary>
/// Optional, minimal value of EIP1559 base fee
/// </summary>
public UInt256? Eip1559BaseFeeMinValue { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ private void BuildTransitions()
releaseSpec.IsEip3675Enabled = (_chainSpec.Parameters.Eip3675Transition ?? long.MaxValue) <= releaseStartBlock;
releaseSpec.ValidateChainId = (_chainSpec.Parameters.ValidateChainIdTransition ?? 0) <= releaseStartBlock;
releaseSpec.ValidateReceipts = ((_chainSpec.Parameters.ValidateReceiptsTransition > 0) ? Math.Max(_chainSpec.Parameters.ValidateReceiptsTransition ?? 0, _chainSpec.Parameters.Eip658Transition ?? 0) : 0) <= releaseStartBlock;
releaseSpec.Eip1559FeeCollector = releaseSpec.IsEip1559Enabled && (_chainSpec.Parameters.Eip1559FeeCollectorTransition ?? long.MaxValue) <= releaseStartBlock ? _chainSpec.Parameters.Eip1559FeeCollector : null;
releaseSpec.Eip1559FeeCollector = releaseSpec.IsEip1559Enabled && (_chainSpec.Parameters.Eip1559FeeCollectorTransition ?? long.MaxValue) <= releaseStartBlock ? _chainSpec.Parameters.Eip1559FeeCollector : null;
releaseSpec.Eip1559BaseFeeMinValue = releaseSpec.IsEip1559Enabled && (_chainSpec.Parameters.Eip1559BaseFeeMinValueTransition ?? long.MaxValue) <= releaseStartBlock ? _chainSpec.Parameters.Eip1559BaseFeeMinValue : null;

if (_chainSpec.Ethash != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,9 @@ private void LoadParameters(ChainSpecJson chainSpecJson, ChainSpec chainSpec)
Eip1559BaseFeeMaxChangeDenominator = chainSpecJson.Params.Eip1559BaseFeeMaxChangeDenominator ??
Eip1559Constants.BaseFeeMaxChangeDenominator,
Eip1559FeeCollector = chainSpecJson.Params.Eip1559FeeCollector,
Eip1559FeeCollectorTransition = chainSpecJson.Params.Eip1559FeeCollectorTransition

Eip1559FeeCollectorTransition = chainSpecJson.Params.Eip1559FeeCollectorTransition,
Eip1559BaseFeeMinValueTransition = chainSpecJson.Params.Eip1559BaseFeeMinValueTransition,
Eip1559BaseFeeMinValue = chainSpecJson.Params.Eip1559BaseFeeMinValue,
};

chainSpec.Parameters.Eip152Transition ??= GetTransitionForExpectedPricing("blake2_f", "price.blake2_f.gas_per_round", 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,9 @@ internal class ChainSpecParamsJson
public long? Eip1559FeeCollectorTransition { get; set; }

public Address Eip1559FeeCollector { get; set; }

public long? Eip1559BaseFeeMinValueTransition { get; set; }

public UInt256? Eip1559BaseFeeMinValue { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/Nethermind/Nethermind.Specs/ReleaseSpec.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class ReleaseSpec : IReleaseSpec
public bool ValidateChainId { get; set; }
public bool ValidateReceipts { get; set; }
public long Eip1559TransitionBlock { get; set; }

public Address Eip1559FeeCollector { get; set; }
public UInt256? Eip1559BaseFeeMinValue { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/int256