Skip to content

Commit

Permalink
Fix op-mainnet snapshot (#7881)
Browse files Browse the repository at this point in the history
  • Loading branch information
deffrian authored and kamilchodola committed Dec 10, 2024
1 parent becc381 commit 11a3f0b
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,6 +38,7 @@ protected override async Task InitBlockchain()
await base.InitBlockchain();

api.RegisterTxType<OptimismTransactionForRpc>(new OptimismTxDecoder<Transaction>(), Always.Valid);
api.RegisterTxType<LegacyTransactionForRpc>(new OptimismLegacyTxDecoder(), new OptimismLegacyTxValidator());
}

protected override ITransactionProcessor CreateTransactionProcessor(CodeInfoRepository codeInfoRepository, VirtualMachine virtualMachine)
Expand Down
39 changes: 39 additions & 0 deletions src/Nethermind/Nethermind.Optimism/OptimismLegacyTxDecoder.cs
Original file line number Diff line number Diff line change
@@ -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<Transaction>
{
protected override Signature? DecodeSignature(ulong v, ReadOnlySpan<byte> rBytes, ReadOnlySpan<byte> 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;
}
}
3 changes: 3 additions & 0 deletions src/Nethermind/Nethermind.Optimism/OptimismPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,6 +86,7 @@ public void InitTxTypesAndRlpDecoders(INethermindApi api)
if (ShouldRunSteps(api))
{
api.RegisterTxType<OptimismTransactionForRpc>(new OptimismTxDecoder<Transaction>(), Always.Valid);
api.RegisterTxType<LegacyTransactionForRpc>(new OptimismLegacyTxDecoder(), new OptimismLegacyTxValidator());
Rlp.RegisterDecoders(typeof(OptimismReceiptMessageDecoder).Assembly, true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Nethermind.Serialization.Rlp.TxDecoders;

public sealed class LegacyTxDecoder<T>(Func<T>? transactionFactory = null) : BaseTxDecoder<T>(TxType.Legacy, transactionFactory) where T : Transaction, new()
public class LegacyTxDecoder<T>(Func<T>? transactionFactory = null) : BaseTxDecoder<T>(TxType.Legacy, transactionFactory) where T : Transaction, new()
{
private static bool IncludeSigChainIdHack(bool isEip155Enabled, ulong chainId) => isEip155Enabled && chainId != 0;

Expand Down

0 comments on commit 11a3f0b

Please sign in to comment.