From 11a3f0b732767dc15590f1c3fe4517670a18b57f Mon Sep 17 00:00:00 2001 From: Nikita Mescheryakov Date: Tue, 10 Dec 2024 15:26:44 +0300 Subject: [PATCH] Fix op-mainnet snapshot (#7881) --- .../InitializeBlockchainOptimism.cs | 3 ++ .../OptimismLegacyTxDecoder.cs | 39 +++++++++++++++++++ .../Nethermind.Optimism/OptimismPlugin.cs | 3 ++ .../TxDecoders/LegacyTxDecoder.cs | 2 +- 4 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 src/Nethermind/Nethermind.Optimism/OptimismLegacyTxDecoder.cs diff --git a/src/Nethermind/Nethermind.Optimism/InitializeBlockchainOptimism.cs b/src/Nethermind/Nethermind.Optimism/InitializeBlockchainOptimism.cs index e1c185d2aea..1036e22ba9e 100644 --- a/src/Nethermind/Nethermind.Optimism/InitializeBlockchainOptimism.cs +++ b/src/Nethermind/Nethermind.Optimism/InitializeBlockchainOptimism.cs @@ -14,9 +14,11 @@ using Nethermind.Core; using Nethermind.Evm; using Nethermind.Evm.TransactionProcessing; +using Nethermind.Facade.Eth.RpcTransaction; using Nethermind.Init.Steps; using Nethermind.Merge.Plugin.InvalidChainTracker; using Nethermind.Optimism.Rpc; +using Nethermind.Serialization.Rlp.TxDecoders; using Nethermind.TxPool; namespace Nethermind.Optimism; @@ -36,6 +38,7 @@ protected override async Task InitBlockchain() await base.InitBlockchain(); api.RegisterTxType(new OptimismTxDecoder(), Always.Valid); + api.RegisterTxType(new OptimismLegacyTxDecoder(), new OptimismLegacyTxValidator()); } protected override ITransactionProcessor CreateTransactionProcessor(CodeInfoRepository codeInfoRepository, VirtualMachine virtualMachine) diff --git a/src/Nethermind/Nethermind.Optimism/OptimismLegacyTxDecoder.cs b/src/Nethermind/Nethermind.Optimism/OptimismLegacyTxDecoder.cs new file mode 100644 index 00000000000..eb85cd9e22e --- /dev/null +++ b/src/Nethermind/Nethermind.Optimism/OptimismLegacyTxDecoder.cs @@ -0,0 +1,39 @@ +// SPDX-FileCopyrightText: 2024 Demerzel Solutions Limited +// SPDX-License-Identifier: LGPL-3.0-only + +using System; +using Nethermind.Core; +using Nethermind.Core.Crypto; +using Nethermind.Core.Specs; +using Nethermind.Serialization.Rlp; +using Nethermind.Serialization.Rlp.TxDecoders; +using Nethermind.TxPool; + +namespace Nethermind.Optimism; + +public class OptimismLegacyTxDecoder : LegacyTxDecoder +{ + protected override Signature? DecodeSignature(ulong v, ReadOnlySpan rBytes, ReadOnlySpan sBytes, Signature? fallbackSignature = null, + RlpBehaviors rlpBehaviors = RlpBehaviors.None) + { + if (v == 0 && rBytes.IsEmpty && sBytes.IsEmpty) + { + return null; + } + return base.DecodeSignature(v, rBytes, sBytes, fallbackSignature, rlpBehaviors); + } +} + +public class OptimismLegacyTxValidator : ITxValidator +{ + public ValidationResult IsWellFormed(Transaction transaction, IReleaseSpec releaseSpec) + { + // In op bedrock eip1559 activated with bedrock + if (releaseSpec.IsEip1559Enabled) + { + return transaction.Signature is null ? new ValidationResult("Empty signature") : ValidationResult.Success; + } + + return ValidationResult.Success; + } +} diff --git a/src/Nethermind/Nethermind.Optimism/OptimismPlugin.cs b/src/Nethermind/Nethermind.Optimism/OptimismPlugin.cs index 277aadbbd25..a294cbe1c01 100644 --- a/src/Nethermind/Nethermind.Optimism/OptimismPlugin.cs +++ b/src/Nethermind/Nethermind.Optimism/OptimismPlugin.cs @@ -24,12 +24,14 @@ using Nethermind.Consensus.Rewards; using Nethermind.Consensus.Validators; using Nethermind.Core; +using Nethermind.Facade.Eth.RpcTransaction; using Nethermind.Merge.Plugin.Synchronization; using Nethermind.HealthChecks; using Nethermind.Serialization.Json; using Nethermind.Specs.ChainSpecStyle; using Nethermind.Serialization.Rlp; using Nethermind.Optimism.Rpc; +using Nethermind.Serialization.Rlp.TxDecoders; using Nethermind.Synchronization; namespace Nethermind.Optimism; @@ -84,6 +86,7 @@ public void InitTxTypesAndRlpDecoders(INethermindApi api) if (ShouldRunSteps(api)) { api.RegisterTxType(new OptimismTxDecoder(), Always.Valid); + api.RegisterTxType(new OptimismLegacyTxDecoder(), new OptimismLegacyTxValidator()); Rlp.RegisterDecoders(typeof(OptimismReceiptMessageDecoder).Assembly, true); } } diff --git a/src/Nethermind/Nethermind.Serialization.Rlp/TxDecoders/LegacyTxDecoder.cs b/src/Nethermind/Nethermind.Serialization.Rlp/TxDecoders/LegacyTxDecoder.cs index 3937f0c0ae2..99aba5bf70d 100644 --- a/src/Nethermind/Nethermind.Serialization.Rlp/TxDecoders/LegacyTxDecoder.cs +++ b/src/Nethermind/Nethermind.Serialization.Rlp/TxDecoders/LegacyTxDecoder.cs @@ -7,7 +7,7 @@ namespace Nethermind.Serialization.Rlp.TxDecoders; -public sealed class LegacyTxDecoder(Func? transactionFactory = null) : BaseTxDecoder(TxType.Legacy, transactionFactory) where T : Transaction, new() +public class LegacyTxDecoder(Func? transactionFactory = null) : BaseTxDecoder(TxType.Legacy, transactionFactory) where T : Transaction, new() { private static bool IncludeSigChainIdHack(bool isEip155Enabled, ulong chainId) => isEip155Enabled && chainId != 0;