Skip to content

Commit

Permalink
Cancel merge changes
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 committed Dec 27, 2024
1 parent 634f960 commit c0d80fc
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,4 @@ IBlockImprovementContext StartBlockImprovementContext(
BlockHeader parentHeader,
PayloadAttributes payloadAttributes,
DateTimeOffset startDateTime);

bool KeepImproving { get => true; }
}
71 changes: 0 additions & 71 deletions src/Nethermind/Nethermind.Core.Test/Crypto/BlsTests.cs

This file was deleted.

8 changes: 4 additions & 4 deletions src/Nethermind/Nethermind.Core/Collections/ArrayPoolList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,10 @@ public void Dispose()

~ArrayPoolList()
{
// if (_capacity != 0 && !_disposed)
// {
// throw new InvalidOperationException($"{nameof(ArrayPoolList<T>)} hasn't been disposed. Created {_creationStackTrace}");
// }
if (_capacity != 0 && !_disposed)
{
throw new InvalidOperationException($"{nameof(ArrayPoolList<T>)} hasn't been disposed. Created {_creationStackTrace}");
}
}
#endif

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ public static class EnumerableExtensions
public static ISet<T> AsSet<T>(this IEnumerable<T> enumerable) =>
enumerable as ISet<T> ?? enumerable.ToHashSet();

public static IEnumerable<(T item, int index)> WithIndex<T>(this IEnumerable<T> self) =>
self.Select((item, index) => (item, index));

public static ArrayPoolList<T> ToPooledList<T>(this IEnumerable<T> enumerable, int count) => new(count, enumerable);
public static ArrayPoolList<T> ToPooledList<T>(this IReadOnlyCollection<T> collection) => new(collection.Count, collection);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public virtual IBlockProducer InitBlockProducer(IBlockProducerFactory baseBlockP
if (_api.SealValidator is null) throw new ArgumentNullException(nameof(_api.SealValidator));
if (_api.BlockProducerEnvFactory is null) throw new ArgumentNullException(nameof(_api.BlockProducerEnvFactory));

_logger.Info("Starting Merge block producer & sealer");
if (_logger.IsInfo) _logger.Info("Starting Merge block producer & sealer");

IBlockProducer? blockProducer = _mergeBlockProductionPolicy.ShouldInitPreMergeBlockProduction()
? baseBlockProducerFactory.InitBlockProducer(txSource)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using Nethermind.Consensus;
using Nethermind.Consensus.Producers;
using Nethermind.Core;
using Nethermind.Core.Specs;
Expand Down
63 changes: 39 additions & 24 deletions src/Nethermind/Nethermind.Shutter.Test/ShutterApiSimulator.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited
// SPDX-License-Identifier: LGPL-3.0-only

using System;
using System.Collections.Generic;
using System.IO.Abstractions;
Expand All @@ -21,9 +19,7 @@
using Nethermind.Shutter.Config;
using Nethermind.State;
using NSubstitute;

namespace Nethermind.Shutter.Test;

public class ShutterApiSimulator(
ShutterEventSimulator eventSimulator,
IAbiEncoder abiEncoder,
Expand All @@ -38,47 +34,41 @@ public class ShutterApiSimulator(
IFileSystem fileSystem,
IKeyStoreConfig keyStoreConfig,
IShutterConfig cfg,
ShutterValidatorsInfo validatorsInfo,
Random rnd
) : ShutterApi(abiEncoder, blockTree, ecdsa, logFinder, receiptStorage,
logManager, specProvider, timestamper, worldStateManager, fileSystem,
keyStoreConfig, cfg, validatorsInfo, ShutterTestsCommon.SlotLength, IPAddress.None)
{
public int EonUpdateCalled = 0;
public int KeysValidated = 0;
public ShutterTransactions? LoadedTransactions;

private readonly Random _rnd = rnd;
private readonly IReceiptStorage _receiptStorage = receiptStorage;
private ShutterEventSimulator? _eventSimulator;

public void SetEventSimulator(ShutterEventSimulator eventSimulator)
{
_eventSimulator = eventSimulator;
}

public (List<ShutterEventSimulator.Event> events, Dto.DecryptionKeys keys) AdvanceSlot(int eventCount, int? keyCount = null)
{
(List<ShutterEventSimulator.Event> events, Dto.DecryptionKeys keys) x = eventSimulator.AdvanceSlot(eventCount, keyCount);
LogEntry[] logs = x.events.Select(e => e.LogEntry).ToArray();
InsertShutterReceipts(_readOnlyBlockTree.Head ?? Build.A.Block.TestObject, logs);
TriggerKeysReceived(x.keys);
return x;
}

public void TriggerKeysValidated(IShutterKeyValidator.ValidatedKeyArgs keys)
{
KeysValidated?.Invoke(this, keys);
}

public void TriggerKeysReceived(Dto.DecryptionKeys keys)
{
KeysReceived?.Invoke(this, keys);
}

public void TriggerNewHeadBlock(BlockEventArgs e)
=> _blockTree.NewHeadBlock += Raise.EventWith(this, e);

public void TriggerKeysReceived(Dto.DecryptionKeys keys)
=> _ = OnKeysReceived(keys);

public void NextEon()
=> eventSimulator.NextEon();

public void InsertShutterReceipts(Block block, in LogEntry[] logs)
{
var receipts = new TxReceipt[logs.Length];
block.Header.Bloom = new(logs);

// one log per receipt
for (int i = 0; i < logs.Length; i++)
{
Expand All @@ -93,19 +83,44 @@ public void InsertShutterReceipts(Block block, in LogEntry[] logs)
}

_receiptStorage.Insert(block, receipts);
TxLoader.LoadFromReceipts(block, receipts, eventSimulator.GetCurrentEonInfo().Eon);
}

protected override async Task OnKeysReceived(Dto.DecryptionKeys decryptionKeys)
{
IShutterKeyValidator.ValidatedKeys? keys = KeyValidator.ValidateKeys(decryptionKeys);

if (keys is null)
{
return;
}

KeysValidated++;
Metrics.ShutterTxPointer = keys.Value.TxPointer;

// wait for latest block before loading transactions
Block? head = (await BlockHandler.WaitForBlockInSlot(keys.Value.Slot - 1, new())) ?? _readOnlyBlockTree.Head;
BlockHeader? header = head?.Header;
BlockHeader parentHeader = header is not null
? _readOnlyBlockTree.FindParentHeader(header, BlockTreeLookupOptions.None)!
: _readOnlyBlockTree.FindLatestHeader()!;

// store transactions to check in tests
LoadedTransactions = TxSource.LoadTransactions(head, parentHeader, keys.Value);
}

// fake out key validator
// protected override void RegisterOnKeysValidated()
// {

// fake out P2P module
protected override void InitP2P(IPAddress _)
{
P2P = Substitute.For<IShutterP2P>();
}

protected override IShutterEon InitEon()
{
IShutterEon eon = Substitute.For<IShutterEon>();
eon.GetCurrentEonInfo().Returns(_ => eventSimulator.GetCurrentEonInfo());
eon.When(x => x.Update(Arg.Any<BlockHeader>())).Do((_) => EonUpdateCalled++);
return eon;
}

Expand Down

0 comments on commit c0d80fc

Please sign in to comment.