From c0d80fc8ccd648089a04ad36e571c332d5bd23b9 Mon Sep 17 00:00:00 2001 From: Alexey Osipov Date: Fri, 27 Dec 2024 19:49:29 +0300 Subject: [PATCH] Cancel merge changes --- .../IBlockImprovementContextFactory.cs | 2 - .../Nethermind.Core.Test/Crypto/BlsTests.cs | 71 ------------------- .../Collections/ArrayPoolList.cs | 8 +-- .../Extensions/EnumerableExtensions.cs | 3 - .../MergePlugin.BlockProducer.cs | 2 +- .../OptimismPayloadPreparationService.cs | 1 - .../ShutterApiSimulator.cs | 63 +++++++++------- 7 files changed, 44 insertions(+), 106 deletions(-) delete mode 100644 src/Nethermind/Nethermind.Core.Test/Crypto/BlsTests.cs diff --git a/src/Nethermind/Nethermind.Consensus/Producers/IBlockImprovementContextFactory.cs b/src/Nethermind/Nethermind.Consensus/Producers/IBlockImprovementContextFactory.cs index 70a1f4812781..daba38c45d77 100644 --- a/src/Nethermind/Nethermind.Consensus/Producers/IBlockImprovementContextFactory.cs +++ b/src/Nethermind/Nethermind.Consensus/Producers/IBlockImprovementContextFactory.cs @@ -13,6 +13,4 @@ IBlockImprovementContext StartBlockImprovementContext( BlockHeader parentHeader, PayloadAttributes payloadAttributes, DateTimeOffset startDateTime); - - bool KeepImproving { get => true; } } diff --git a/src/Nethermind/Nethermind.Core.Test/Crypto/BlsTests.cs b/src/Nethermind/Nethermind.Core.Test/Crypto/BlsTests.cs deleted file mode 100644 index 4d86a7dfd51b..000000000000 --- a/src/Nethermind/Nethermind.Core.Test/Crypto/BlsTests.cs +++ /dev/null @@ -1,71 +0,0 @@ -// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited -// SPDX-License-Identifier: LGPL-3.0-only - -using FluentAssertions; -using Nethermind.Crypto; -using NUnit.Framework; - -namespace Nethermind.Core.Test.Crypto; - -using G1 = Bls.P1; -using G2 = Bls.P2; -using GT = Bls.PT; - -[TestFixture] -public class BlsTests -{ - private static readonly BlsSigner.PrivateKey _sk = new() - { - Bytes = [0x2c, 0xd4, 0xba, 0x40, 0x6b, 0x52, 0x24, 0x59, 0xd5, 0x7a, 0x0b, 0xed, 0x51, 0xa3, 0x97, 0x43, 0x5c, 0x0b, 0xb1, 0x1d, 0xd5, 0xf3, 0xca, 0x11, 0x52, 0xb3, 0x69, 0x4b, 0xb9, 0x1d, 0x7c, 0x22] - }; - private static readonly byte[] _msgBytes = [0x3e, 0x00, 0xef, 0x2f, 0x89, 0x5f, 0x40, 0xd6, 0x7f, 0x5b, 0xb8, 0xe8, 0x1f, 0x09, 0xa5, 0xa1, 0x2c, 0x84, 0x0e, 0xc3, 0xce, 0x9a, 0x7f, 0x3b, 0x18, 0x1b, 0xe1, 0x88, 0xef, 0x71, 0x1a, 0x1e]; - - [Test] - public void Calculate_signature() - { - byte[] expected = [0xa5, 0xa0, 0x0d, 0xe9, 0x9d, 0x8f, 0xee, 0x7e, 0x28, 0x81, 0x1b, 0x2c, 0x08, 0xe0, 0xa7, 0xfc, 0x00, 0xa1, 0x10, 0x0c, 0x3d, 0x0f, 0x80, 0x51, 0x9d, 0x43, 0x24, 0x67, 0x1c, 0x29, 0x36, 0xb1, 0xe5, 0xa5, 0x87, 0x7d, 0x46, 0x7a, 0x6d, 0xc6, 0xf5, 0x92, 0xb2, 0x40, 0x7b, 0xcb, 0x12, 0x61, 0x0c, 0x18, 0x8a, 0x6c, 0xdf, 0x57, 0xd1, 0x77, 0x92, 0x00, 0x0f, 0xf7, 0x56, 0xf8, 0x0e, 0xbe, 0xd8, 0x00, 0x88, 0xab, 0x22, 0x9a, 0xa7, 0xe2, 0xc3, 0x24, 0x09, 0xec, 0xfe, 0x5a, 0x8d, 0x44, 0x73, 0xe9, 0x12, 0xfa, 0x19, 0x9e, 0xee, 0xa1, 0x8f, 0x3c, 0x79, 0x8d, 0xc5, 0x28, 0x64, 0x7d]; - BlsSigner.Signature s = BlsSigner.Sign(_sk, _msgBytes); - s.Bytes.Should().Equal(expected); - } - - [Test] - public void Verify_signature() - { - BlsSigner.Signature s = BlsSigner.Sign(_sk, _msgBytes); - Assert.That(BlsSigner.Verify(BlsSigner.GetPublicKey(_sk), s, _msgBytes)); - } - - [Test] - public void Rejects_bad_signature() - { - BlsSigner.Signature s = BlsSigner.Sign(_sk, _msgBytes); - s.Bytes[34] += 1; - Assert.That(!BlsSigner.Verify(BlsSigner.GetPublicKey(_sk), s, _msgBytes)); - } - - [Test] - public void Public_key_from_private_key() - { - byte[] expected = [0x95, 0x39, 0x27, 0x35, 0x0c, 0x35, 0x31, 0xb0, 0xbc, 0x58, 0x64, 0xcd, 0x9c, 0x5f, 0xe1, 0x34, 0x74, 0xca, 0x0c, 0x9b, 0x59, 0x99, 0x51, 0xa7, 0x76, 0xc4, 0xb9, 0x8d, 0xf6, 0x6a, 0x0e, 0x62, 0x07, 0xa8, 0x5c, 0x7f, 0x7a, 0x85, 0x1a, 0x0c, 0x02, 0x2a, 0x87, 0xc0, 0x29, 0xc3, 0x65, 0x61]; - Assert.That(BlsSigner.GetPublicKey(_sk).Bytes, Is.EqualTo(expected)); - } - - [Test] - public void PairingTest1() - { - // e((12+34)*56*g1, 78*g2) == e(78*g1, 12*56*g2) * e(78*g1, 34*56*g2) - GT q1 = new(G1.generator().mult((12 + 34) * 56), G2.generator().mult(78)); - GT q2 = new(G1.generator().mult(78), G2.generator().mult(12 * 56)); - GT q3 = new(G1.generator().mult(78), G2.generator().mult(34 * 56)); - q2.mul(q3); - Assert.That(GT.finalverify(q1, q2)); - } - - [Test] - public void PairingTest2() - { - GT q1 = new(G1.generator().mult(2), G2.generator()); - GT q2 = new(G1.generator(), G2.generator().mult(2)); - Assert.That(GT.finalverify(q1, q2)); - } -} diff --git a/src/Nethermind/Nethermind.Core/Collections/ArrayPoolList.cs b/src/Nethermind/Nethermind.Core/Collections/ArrayPoolList.cs index 920be389d861..7b734e34236f 100644 --- a/src/Nethermind/Nethermind.Core/Collections/ArrayPoolList.cs +++ b/src/Nethermind/Nethermind.Core/Collections/ArrayPoolList.cs @@ -381,10 +381,10 @@ public void Dispose() ~ArrayPoolList() { - // if (_capacity != 0 && !_disposed) - // { - // throw new InvalidOperationException($"{nameof(ArrayPoolList)} hasn't been disposed. Created {_creationStackTrace}"); - // } + if (_capacity != 0 && !_disposed) + { + throw new InvalidOperationException($"{nameof(ArrayPoolList)} hasn't been disposed. Created {_creationStackTrace}"); + } } #endif diff --git a/src/Nethermind/Nethermind.Core/Extensions/EnumerableExtensions.cs b/src/Nethermind/Nethermind.Core/Extensions/EnumerableExtensions.cs index eb121e6eba94..216af63604b4 100644 --- a/src/Nethermind/Nethermind.Core/Extensions/EnumerableExtensions.cs +++ b/src/Nethermind/Nethermind.Core/Extensions/EnumerableExtensions.cs @@ -13,9 +13,6 @@ public static class EnumerableExtensions public static ISet AsSet(this IEnumerable enumerable) => enumerable as ISet ?? enumerable.ToHashSet(); - public static IEnumerable<(T item, int index)> WithIndex(this IEnumerable self) => - self.Select((item, index) => (item, index)); - public static ArrayPoolList ToPooledList(this IEnumerable enumerable, int count) => new(count, enumerable); public static ArrayPoolList ToPooledList(this IReadOnlyCollection collection) => new(collection.Count, collection); diff --git a/src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.BlockProducer.cs b/src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.BlockProducer.cs index 9b26330c4346..d17d39b5599a 100644 --- a/src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.BlockProducer.cs +++ b/src/Nethermind/Nethermind.Merge.Plugin/MergePlugin.BlockProducer.cs @@ -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) diff --git a/src/Nethermind/Nethermind.Optimism/OptimismPayloadPreparationService.cs b/src/Nethermind/Nethermind.Optimism/OptimismPayloadPreparationService.cs index 9a4d85daa8c6..7cdb39780b96 100644 --- a/src/Nethermind/Nethermind.Optimism/OptimismPayloadPreparationService.cs +++ b/src/Nethermind/Nethermind.Optimism/OptimismPayloadPreparationService.cs @@ -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; diff --git a/src/Nethermind/Nethermind.Shutter.Test/ShutterApiSimulator.cs b/src/Nethermind/Nethermind.Shutter.Test/ShutterApiSimulator.cs index 08a634da3682..d2377ef466e8 100644 --- a/src/Nethermind/Nethermind.Shutter.Test/ShutterApiSimulator.cs +++ b/src/Nethermind/Nethermind.Shutter.Test/ShutterApiSimulator.cs @@ -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; @@ -21,9 +19,7 @@ using Nethermind.Shutter.Config; using Nethermind.State; using NSubstitute; - namespace Nethermind.Shutter.Test; - public class ShutterApiSimulator( ShutterEventSimulator eventSimulator, IAbiEncoder abiEncoder, @@ -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 events, Dto.DecryptionKeys keys) AdvanceSlot(int eventCount, int? keyCount = null) { + (List 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++) { @@ -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(); + } protected override IShutterEon InitEon() { IShutterEon eon = Substitute.For(); + eon.GetCurrentEonInfo().Returns(_ => eventSimulator.GetCurrentEonInfo()); + eon.When(x => x.Update(Arg.Any())).Do((_) => EonUpdateCalled++); return eon; }