Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

namespace Nethermind.Consensus.AuRa.Validators
{
internal class PendingValidatorsDecoder : IRlpObjectDecoder<PendingValidators>, IRlpStreamDecoder<PendingValidators>
internal sealed class PendingValidatorsDecoder : RlpStreamDecoder<PendingValidators>, IRlpObjectDecoder<PendingValidators>
{
public PendingValidators Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
protected override PendingValidators DecodeInternal(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
if (rlpStream.IsNextItemNull())
{
Expand Down Expand Up @@ -54,7 +54,7 @@ public Rlp Encode(PendingValidators item, RlpBehaviors rlpBehaviors = RlpBehavio
return new Rlp(rlpStream.Data.ToArray());
}

public void Encode(RlpStream rlpStream, PendingValidators item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
public override void Encode(RlpStream rlpStream, PendingValidators item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
(int contentLength, int addressesLength) = GetContentLength(item, rlpBehaviors);
rlpStream.StartSequence(contentLength);
Expand All @@ -68,7 +68,7 @@ public void Encode(RlpStream rlpStream, PendingValidators item, RlpBehaviors rlp
rlpStream.Encode(item.AreFinalized);
}

public int GetLength(PendingValidators item, RlpBehaviors rlpBehaviors) =>
public override int GetLength(PendingValidators item, RlpBehaviors rlpBehaviors) =>
item is null ? 1 : Rlp.LengthOfSequence(GetContentLength(item, rlpBehaviors).Total);

private static (int Total, int Addresses) GetContentLength(PendingValidators item, RlpBehaviors rlpBehaviors)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

namespace Nethermind.Consensus.AuRa.Validators
{
internal class ValidatorInfoDecoder : IRlpStreamDecoder<ValidatorInfo>, IRlpObjectDecoder<ValidatorInfo>
internal sealed class ValidatorInfoDecoder : RlpStreamDecoder<ValidatorInfo>, IRlpObjectDecoder<ValidatorInfo>
{
public ValidatorInfo? Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
protected override ValidatorInfo? DecodeInternal(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
if (rlpStream.IsNextItemNull())
{
Expand Down Expand Up @@ -49,7 +49,7 @@ public Rlp Encode(ValidatorInfo? item, RlpBehaviors rlpBehaviors = RlpBehaviors.
return new Rlp(rlpStream.Data.ToArray());
}

public void Encode(RlpStream stream, ValidatorInfo? item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
public override void Encode(RlpStream stream, ValidatorInfo? item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
if (item is null)
{
Expand All @@ -68,7 +68,7 @@ public void Encode(RlpStream stream, ValidatorInfo? item, RlpBehaviors rlpBehavi
}
}

public int GetLength(ValidatorInfo? item, RlpBehaviors rlpBehaviors) => item is null ? 1 : Rlp.LengthOfSequence(GetContentLength(item, rlpBehaviors).Total);
public override int GetLength(ValidatorInfo? item, RlpBehaviors rlpBehaviors) => item is null ? 1 : Rlp.LengthOfSequence(GetContentLength(item, rlpBehaviors).Total);

private static (int Total, int Validators) GetContentLength(ValidatorInfo item, RlpBehaviors rlpBehaviors)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Nethermind/Nethermind.Consensus.Clique/SnapshotDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@

namespace Nethermind.Consensus.Clique
{
internal class SnapshotDecoder : IRlpStreamDecoder<Snapshot>
internal sealed class SnapshotDecoder : RlpStreamDecoder<Snapshot>
{
public Snapshot Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
protected override Snapshot DecodeInternal(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
rlpStream.ReadSequenceLength();

Expand All @@ -30,7 +30,7 @@ public Snapshot Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehav
return snapshot;
}

public void Encode(RlpStream stream, Snapshot item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
public override void Encode(RlpStream stream, Snapshot item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
(int contentLength, int signersLength, int votesLength, int tallyLength) =
GetContentLength(item, rlpBehaviors);
Expand All @@ -43,7 +43,7 @@ public void Encode(RlpStream stream, Snapshot item, RlpBehaviors rlpBehaviors =

}

public int GetLength(Snapshot item, RlpBehaviors rlpBehaviors)
public override int GetLength(Snapshot item, RlpBehaviors rlpBehaviors)
{
(int contentLength, int _, int _, int _) = GetContentLength(item, rlpBehaviors);
return Rlp.LengthOfSequence(contentLength);
Expand Down
8 changes: 4 additions & 4 deletions src/Nethermind/Nethermind.Network/NetworkNodeDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace Nethermind.Network
{
public class NetworkNodeDecoder : IRlpStreamDecoder<NetworkNode>, IRlpObjectDecoder<NetworkNode>
public sealed class NetworkNodeDecoder : RlpStreamDecoder<NetworkNode>, IRlpObjectDecoder<NetworkNode>
{
private static readonly RlpLimit RlpLimit = RlpLimit.For<NetworkNode>((int)1.KiB(), nameof(NetworkNode.HostIp));

Expand All @@ -19,7 +19,7 @@ static NetworkNodeDecoder()
Rlp.RegisterDecoder(typeof(NetworkNode), new NetworkNodeDecoder());
}

public NetworkNode Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
protected override NetworkNode DecodeInternal(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
rlpStream.ReadSequenceLength();

Expand All @@ -41,7 +41,7 @@ public NetworkNode Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBe
return networkNode;
}

public void Encode(RlpStream stream, NetworkNode item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
public override void Encode(RlpStream stream, NetworkNode item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
int contentLength = GetContentLength(item, rlpBehaviors);
stream.StartSequence(contentLength);
Expand Down Expand Up @@ -70,7 +70,7 @@ public void Encode(MemoryStream stream, NetworkNode item, RlpBehaviors rlpBehavi
throw new NotImplementedException();
}

public int GetLength(NetworkNode item, RlpBehaviors rlpBehaviors)
public override int GetLength(NetworkNode item, RlpBehaviors rlpBehaviors)
{
return Rlp.LengthOfSequence(GetContentLength(item, rlpBehaviors));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
namespace Nethermind.Optimism;

[Rlp.Decoder(RlpDecoderKey.Trie)]
public class OptimismReceiptTrieDecoder() : OptimismReceiptMessageDecoder(true);
public sealed class OptimismReceiptTrieDecoder() : OptimismReceiptMessageDecoder(true);

[Rlp.Decoder]
public class OptimismReceiptMessageDecoder(bool isEncodedForTrie = false, bool skipStateAndStatus = false) : IRlpStreamDecoder<TxReceipt>
public class OptimismReceiptMessageDecoder(bool isEncodedForTrie = false, bool skipStateAndStatus = false) : RlpStreamDecoder<TxReceipt>
{
private readonly bool _skipStateAndStatus = skipStateAndStatus;
public OptimismTxReceipt Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
protected override OptimismTxReceipt DecodeInternal(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
OptimismTxReceipt txReceipt = new();
if (!rlpStream.IsSequenceNext())
Expand Down Expand Up @@ -126,7 +126,7 @@ public static int GetLogsLength(TxReceipt item)
/// <summary>
/// https://eips.ethereum.org/EIPS/eip-2718
/// </summary>
public int GetLength(TxReceipt item, RlpBehaviors rlpBehaviors)
public override int GetLength(TxReceipt item, RlpBehaviors rlpBehaviors)
{
(int total, _) = GetContentLength(item, rlpBehaviors);
int receiptPayloadLength = Rlp.LengthOfSequence(total);
Expand All @@ -140,7 +140,7 @@ public int GetLength(TxReceipt item, RlpBehaviors rlpBehaviors)
return result;
}

public void Encode(RlpStream rlpStream, TxReceipt item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
public override void Encode(RlpStream rlpStream, TxReceipt item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
if (item is null)
{
Expand Down Expand Up @@ -189,11 +189,6 @@ public void Encode(RlpStream rlpStream, TxReceipt item, RlpBehaviors rlpBehavior
}
}
}

TxReceipt IRlpStreamDecoder<TxReceipt>.Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors)
{
return Decode(rlpStream, rlpBehaviors);
}
}

internal static class TxReceiptExt
Expand Down
10 changes: 5 additions & 5 deletions src/Nethermind/Nethermind.Serialization.Rlp/AccountDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Nethermind.Serialization.Rlp
{
public class AccountDecoder : IRlpObjectDecoder<Account?>, IRlpStreamDecoder<Account?>, IRlpValueDecoder<Account?>
public sealed class AccountDecoder : RlpValueDecoder<Account?>, IRlpObjectDecoder<Account?>
{
private readonly bool _slimFormat;

Expand Down Expand Up @@ -54,7 +54,7 @@ public Hash256 DecodeStorageRootOnly(ref Rlp.ValueDecoderContext context)
return storageRoot;
}

public Account? Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
protected override Account? DecodeInternal(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
int length = rlpStream.ReadSequenceLength();
if (length == 1)
Expand All @@ -74,7 +74,7 @@ public Hash256 DecodeStorageRootOnly(ref Rlp.ValueDecoderContext context)
return new(nonce, balance, storageRoot, codeHash);
}

public void Encode(RlpStream stream, Account? item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
public override void Encode(RlpStream stream, Account? item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
if (item is null)
{
Expand Down Expand Up @@ -144,7 +144,7 @@ public int GetLength(Account[] accounts)
return length;
}

public int GetLength(Account? item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
public override int GetLength(Account? item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
if (item is null)
{
Expand Down Expand Up @@ -234,7 +234,7 @@ private Hash256 DecodeCodeHash(RlpStream rlpStream)
return codeHash;
}

public Account? Decode(ref Rlp.ValueDecoderContext decoderContext, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
protected override Account? DecodeInternal(ref Rlp.ValueDecoderContext decoderContext, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
int length = decoderContext.ReadSequenceLength();
if (length == 1)
Expand Down
48 changes: 24 additions & 24 deletions src/Nethermind/Nethermind.Serialization.Rlp/BasicStreamDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,109 +6,109 @@ namespace Nethermind.Serialization.Rlp;
// If any of these is triggered in prod, then something went wrong, coz these are fairly slow path. These are only
// useful for easy tests.

public class ByteStreamDecoder : IRlpStreamDecoder<byte>
public sealed class ByteStreamDecoder : RlpStreamDecoder<byte>
{
public int GetLength(byte item, RlpBehaviors rlpBehaviors)
public override int GetLength(byte item, RlpBehaviors rlpBehaviors)
{
return Rlp.LengthOf(item);
}

public byte Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
protected override byte DecodeInternal(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
return rlpStream.DecodeByte();
}

public void Encode(RlpStream stream, byte item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
public override void Encode(RlpStream stream, byte item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
stream.Encode(item);
}
}

public class ShortStreamDecoder : IRlpStreamDecoder<short>
public sealed class ShortStreamDecoder : RlpStreamDecoder<short>
{
public int GetLength(short item, RlpBehaviors rlpBehaviors)
public override int GetLength(short item, RlpBehaviors rlpBehaviors)
{
return Rlp.LengthOf(item);
}

public short Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
protected override short DecodeInternal(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
return (short)rlpStream.DecodeLong();
}

public void Encode(RlpStream stream, short item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
public override void Encode(RlpStream stream, short item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
stream.Encode(item);
}
}

public class UShortStreamDecoder : IRlpStreamDecoder<ushort>
public sealed class UShortStreamDecoder : RlpStreamDecoder<ushort>
{
public int GetLength(ushort item, RlpBehaviors rlpBehaviors)
public override int GetLength(ushort item, RlpBehaviors rlpBehaviors)
{
return Rlp.LengthOf((long)item);
}

public ushort Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
protected override ushort DecodeInternal(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
return (ushort)rlpStream.DecodeLong();
}

public void Encode(RlpStream stream, ushort item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
public override void Encode(RlpStream stream, ushort item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
stream.Encode(item);
}
}

public class IntStreamDecoder : IRlpStreamDecoder<int>
public sealed class IntStreamDecoder : RlpStreamDecoder<int>
{
public int GetLength(int item, RlpBehaviors rlpBehaviors)
public override int GetLength(int item, RlpBehaviors rlpBehaviors)
{
return Rlp.LengthOf(item);
}

public int Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
protected override int DecodeInternal(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
return rlpStream.DecodeInt();
}

public void Encode(RlpStream stream, int item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
public override void Encode(RlpStream stream, int item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
stream.Encode(item);
}
}

public class UIntStreamDecoder : IRlpStreamDecoder<uint>
public sealed class UIntStreamDecoder : RlpStreamDecoder<uint>
{
public int GetLength(uint item, RlpBehaviors rlpBehaviors)
public override int GetLength(uint item, RlpBehaviors rlpBehaviors)
{
return Rlp.LengthOf((long)item);
}

public uint Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
protected override uint DecodeInternal(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
return rlpStream.DecodeUInt();
}

public void Encode(RlpStream stream, uint item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
public override void Encode(RlpStream stream, uint item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
stream.Encode(item);
}
}

public class ULongStreamDecoder : IRlpStreamDecoder<ulong>
public sealed class ULongStreamDecoder : RlpStreamDecoder<ulong>
{
public int GetLength(ulong item, RlpBehaviors rlpBehaviors)
public override int GetLength(ulong item, RlpBehaviors rlpBehaviors)
{
return Rlp.LengthOf(item);
}

public ulong Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
protected override ulong DecodeInternal(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
return rlpStream.DecodeUInt();
}

public void Encode(RlpStream stream, ulong item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
public override void Encode(RlpStream stream, ulong item, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
stream.Encode(item);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Nethermind/Nethermind.Serialization.Rlp/BlockBodyDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

namespace Nethermind.Serialization.Rlp;

public class BlockBodyDecoder : IRlpValueDecoder<BlockBody>, IRlpStreamDecoder<BlockBody>
public sealed class BlockBodyDecoder : RlpValueDecoder<BlockBody>
{
private readonly TxDecoder _txDecoder = TxDecoder.Instance;
private readonly IHeaderDecoder _headerDecoder;
Expand All @@ -21,7 +21,7 @@ public BlockBodyDecoder(IHeaderDecoder headerDecoder = null)
_headerDecoder = headerDecoder ?? new HeaderDecoder();
}

public int GetLength(BlockBody item, RlpBehaviors rlpBehaviors)
public override int GetLength(BlockBody item, RlpBehaviors rlpBehaviors)
{
return Rlp.LengthOfSequence(GetBodyLength(item));
}
Expand Down Expand Up @@ -80,7 +80,7 @@ private int GetWithdrawalsLength(Withdrawal[] withdrawals)
return sum;
}

public BlockBody? Decode(ref Rlp.ValueDecoderContext ctx, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
protected override BlockBody? DecodeInternal(ref Rlp.ValueDecoderContext ctx, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
int sequenceLength = ctx.ReadSequenceLength();
int startingPosition = ctx.Position;
Expand All @@ -106,7 +106,7 @@ private int GetWithdrawalsLength(Withdrawal[] withdrawals)
return new BlockBody(transactions, uncles, withdrawals);
}

public BlockBody Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
protected override BlockBody DecodeInternal(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
Span<byte> span = rlpStream.PeekNextItem();
Rlp.ValueDecoderContext ctx = new Rlp.ValueDecoderContext(span);
Expand All @@ -116,7 +116,7 @@ public BlockBody Decode(RlpStream rlpStream, RlpBehaviors rlpBehaviors = RlpBeha
return response;
}

public void Encode(RlpStream stream, BlockBody body, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
public override void Encode(RlpStream stream, BlockBody body, RlpBehaviors rlpBehaviors = RlpBehaviors.None)
{
stream.StartSequence(GetBodyLength(body));
stream.StartSequence(GetTxLength(body.Transactions));
Expand Down
Loading
Loading