Skip to content

Commit

Permalink
Apply suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
smartprogrammer93 committed Aug 23, 2024
1 parent 7a82b36 commit 6e428f9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,51 @@
using Nethermind.Consensus.Processing;
using Nethermind.Core.Crypto;

namespace Nethermind.Merge.Plugin
{
public class AuRaMergeFinalizationManager : MergeFinalizationManager, IManualBlockFinalizationManager, IAuRaBlockFinalizationManager
{
private readonly IAuRaBlockFinalizationManager? _auRaBlockFinalizationManager;
namespace Nethermind.Merge.Plugin;

public AuRaMergeFinalizationManager(IManualBlockFinalizationManager manualBlockFinalizationManager, IBlockFinalizationManager? blockFinalizationManager, IPoSSwitcher poSSwitcher) : base(manualBlockFinalizationManager, blockFinalizationManager, poSSwitcher)
{
_auRaBlockFinalizationManager = blockFinalizationManager as IAuRaBlockFinalizationManager;
_auRaBlockFinalizationManager!.BlocksFinalized += OnBlockFinalized;
}

public long GetLastLevelFinalizedBy(Hash256 blockHash)
{
if (_auRaBlockFinalizationManager is not null)
{
return _auRaBlockFinalizationManager.GetLastLevelFinalizedBy(blockHash);
}
public class AuRaMergeFinalizationManager : MergeFinalizationManager, IAuRaBlockFinalizationManager
{
private readonly IAuRaBlockFinalizationManager _auRaBlockFinalizationManager;

throw new InvalidOperationException(
$"{nameof(GetLastLevelFinalizedBy)} called when empty {nameof(_auRaBlockFinalizationManager)} is null.");
}
public AuRaMergeFinalizationManager(IManualBlockFinalizationManager manualBlockFinalizationManager, IAuRaBlockFinalizationManager blockFinalizationManager, IPoSSwitcher poSSwitcher)
: base(manualBlockFinalizationManager, blockFinalizationManager, poSSwitcher)
{
_auRaBlockFinalizationManager = blockFinalizationManager;
_auRaBlockFinalizationManager.BlocksFinalized += OnBlockFinalized;
}

public long? GetFinalizationLevel(long level)
{
if (_auRaBlockFinalizationManager is not null)
{
return _auRaBlockFinalizationManager.GetFinalizationLevel(level);
}
public long GetLastLevelFinalizedBy(Hash256 blockHash)
{
return _auRaBlockFinalizationManager.GetLastLevelFinalizedBy(blockHash);
}

throw new InvalidOperationException(
$"{nameof(GetFinalizationLevel)} called when empty {nameof(_auRaBlockFinalizationManager)} is null.");
}
public long? GetFinalizationLevel(long level)
{
return _auRaBlockFinalizationManager.GetFinalizationLevel(level);
}

public void SetMainBlockProcessor(IBlockProcessor blockProcessor)
{
_auRaBlockFinalizationManager!.SetMainBlockProcessor(blockProcessor);
}
public void SetMainBlockProcessor(IBlockProcessor blockProcessor)
{
_auRaBlockFinalizationManager.SetMainBlockProcessor(blockProcessor);
}

public override long LastFinalizedBlockLevel
public override long LastFinalizedBlockLevel
{
get
{
get
{
if (IsPostMerge)
{
return _manualBlockFinalizationManager.LastFinalizedBlockLevel;
}
return _auRaBlockFinalizationManager!.LastFinalizedBlockLevel;
}
return IsPostMerge
? _manualBlockFinalizationManager.LastFinalizedBlockLevel
: _auRaBlockFinalizationManager.LastFinalizedBlockLevel;
}
}

public override void Dispose()
public override void Dispose()
{
if (IsPostMerge)
{
if (IsPostMerge)
{
_auRaBlockFinalizationManager!.Dispose();
}
base.Dispose();
_auRaBlockFinalizationManager.Dispose();
}

base.Dispose();
}

}
9 changes: 7 additions & 2 deletions src/Nethermind/Nethermind.Merge.AuRa/AuRaMergePlugin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-FileCopyrightText: 2022 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Threading.Tasks;
using Nethermind.Api;
using Nethermind.Api.Extensions;
Expand Down Expand Up @@ -48,7 +49,7 @@ originalFilter is MinGasPriceContractTxFilter ? originalFilter
public override IBlockProducer InitBlockProducer(IBlockProducerFactory consensusPlugin, ITxSource? txSource)
{
_api.BlockProducerEnvFactory = new AuRaMergeBlockProducerEnvFactory(
(AuRaNethermindApi)_api,
_auraApi!,
_api.WorldStateManager!,
_api.BlockTree!,
_api.SpecProvider!,
Expand All @@ -74,7 +75,11 @@ protected override PostMergeBlockProducerFactory CreateBlockProducerFactory()

protected override IBlockFinalizationManager InitializeMergeFinilizationManager()
{
return new AuRaMergeFinalizationManager(_blockFinalizationManager, _api.FinalizationManager, _poSSwitcher);
return new AuRaMergeFinalizationManager(_blockFinalizationManager,
_auraApi!.FinalizationManager ??
throw new ArgumentNullException(nameof(_auraApi.FinalizationManager),
"Cannot instantiate AuRaMergeFinalizationManager when AuRaFinalizationManager is null!"),
_poSSwitcher);
}

public bool ShouldRunSteps(INethermindApi api)
Expand Down

0 comments on commit 6e428f9

Please sign in to comment.