-
Notifications
You must be signed in to change notification settings - Fork 459
/
OptimismPayloadPreparationService.cs
73 lines (66 loc) · 2.67 KB
/
OptimismPayloadPreparationService.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only
using System;
using Nethermind.Consensus.Producers;
using Nethermind.Core;
using Nethermind.Core.Specs;
using Nethermind.Core.Timers;
using Nethermind.Int256;
using Nethermind.Logging;
using Nethermind.Merge.Plugin.BlockProduction;
using Nethermind.Optimism.Rpc;
namespace Nethermind.Optimism;
public class OptimismPayloadPreparationService : PayloadPreparationService
{
private readonly ISpecProvider _specProvider;
private readonly ILogger _logger;
public OptimismPayloadPreparationService(
ISpecProvider specProvider,
PostMergeBlockProducer blockProducer,
IBlockImprovementContextFactory blockImprovementContextFactory,
ITimerFactory timerFactory,
ILogManager logManager,
TimeSpan timePerSlot,
int slotsPerOldPayloadCleanup = SlotsPerOldPayloadCleanup,
TimeSpan? improvementDelay = null,
TimeSpan? minTimeForProduction = null)
: base(
blockProducer,
blockImprovementContextFactory,
timerFactory,
logManager,
timePerSlot,
slotsPerOldPayloadCleanup,
improvementDelay,
minTimeForProduction)
{
_specProvider = specProvider;
_logger = logManager.GetClassLogger();
}
protected override void ImproveBlock(string payloadId, BlockHeader parentHeader,
PayloadAttributes payloadAttributes, Block currentBestBlock, DateTimeOffset startDateTime)
{
if (payloadAttributes is OptimismPayloadAttributes { NoTxPool: true })
{
if (_logger.IsDebug)
_logger.Debug("Skip block improvement because of NoTxPool payload attribute.");
// ignore TryAdd failure (it can only happen if payloadId is already in the dictionary)
_payloadStorage.TryAdd(payloadId,
new NoBlockImprovementContext(currentBestBlock, UInt256.Zero, startDateTime));
}
else
{
if (payloadAttributes is OptimismPayloadAttributes optimismPayload)
{
var spec = _specProvider.GetSpec(currentBestBlock.Header);
if (spec.IsOpHoloceneEnabled)
{
EIP1559Parameters eip1559Parameters = optimismPayload.DecodeEIP1559Parameters();
currentBestBlock.Header.ExtraData = new byte[EIP1559Parameters.ByteLength];
eip1559Parameters.WriteTo(currentBestBlock.Header.ExtraData);
}
}
base.ImproveBlock(payloadId, parentHeader, payloadAttributes, currentBestBlock, startDateTime);
}
}
}