Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor TransactionForRpc (Alternative) #7483

Open
wants to merge 180 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
180 commits
Select commit Hold shift + click to select a range
84178b8
Initial `RpcLegacyTransaction`
emlautarom1 Sep 4, 2024
a2739f4
Change field order
emlautarom1 Sep 5, 2024
af3b042
Support null as `ChainId` through `TransactionBuilder`
emlautarom1 Sep 5, 2024
ec1a21e
Initial `RpcAccessListTransaction`
emlautarom1 Sep 5, 2024
88dd0e3
Add `RandomSignature`s
emlautarom1 Sep 5, 2024
e9994ea
Use `TestItem` random `Signature`s
emlautarom1 Sep 5, 2024
1839a0d
Initial `RpcEIP1559Transaction`
emlautarom1 Sep 5, 2024
2833a9e
Rename `TestCaseSource`
emlautarom1 Sep 5, 2024
3caed48
Fix `DefaultChainId`
emlautarom1 Sep 5, 2024
67ec222
Guarantee Blob transaction invariants
emlautarom1 Sep 5, 2024
0f997c9
Initial `RpcBlobTransaction`
emlautarom1 Sep 5, 2024
5ae394a
Initial `IRpcTransaction`
emlautarom1 Sep 10, 2024
14d3cae
Initial `IRpcTransactionConverter`
emlautarom1 Sep 10, 2024
11c237e
Move `RpcXTransaction` to class hierarchy
emlautarom1 Sep 10, 2024
7580bc4
Merge `RPCXTransactionTests` into a single test
emlautarom1 Sep 10, 2024
b073e50
Rename test class
emlautarom1 Sep 11, 2024
a13fcc0
Initial `RpcOptimismTransaction`
emlautarom1 Sep 11, 2024
48326d5
Add `WithSourceHash` to builder
emlautarom1 Sep 11, 2024
16765be
Initial `RpcAccessList`
emlautarom1 Sep 11, 2024
f673490
Annotate converter instead of registering
emlautarom1 Sep 11, 2024
cdd4f23
Use annotation for `IRpcTransaction`
emlautarom1 Sep 11, 2024
a9f6277
Initial `RpcGenericTransaction`
emlautarom1 Sep 12, 2024
7db803b
Initial JSON deserialization code
emlautarom1 Sep 13, 2024
0fee0cf
Remove `TxReceipt` for now
emlautarom1 Sep 13, 2024
19686a1
Test for member equality in JSON (de)serialization
emlautarom1 Sep 13, 2024
38f2a1f
Introduce `ITransactionConverter<T>`
emlautarom1 Sep 13, 2024
4e040bf
Add `TODO`
emlautarom1 Sep 13, 2024
07690be
Update inline docs
emlautarom1 Sep 13, 2024
92394c1
Whitespace
emlautarom1 Sep 13, 2024
b7c42cf
Delete unused classes
emlautarom1 Sep 13, 2024
fe8e7e7
Define `RpcNethermindTransaction` as base class
emlautarom1 Sep 13, 2024
c76f72f
Inherit from `RpcNethermindTransaction`
emlautarom1 Sep 13, 2024
629dda7
Add `TransactionConverterExtraData`
emlautarom1 Sep 13, 2024
e3c884a
Add `ToTransaction`
emlautarom1 Sep 13, 2024
33213e5
Implement `ToTransaction`
emlautarom1 Sep 13, 2024
115dbfc
Update inline docs
emlautarom1 Sep 13, 2024
fb91767
Remove deprecated fields in Blob transactions
emlautarom1 Sep 13, 2024
90fe6fa
Retrofit `Data ~ Input` fix
emlautarom1 Sep 13, 2024
121e057
Move docs
emlautarom1 Sep 13, 2024
cbc3b7f
Initial `ToTransactionWithDefaults`
emlautarom1 Sep 16, 2024
3660df5
Change `ChainId` from UInt256 to ulong in JSON DTO
emlautarom1 Sep 16, 2024
5311804
Update inline TODOs
emlautarom1 Sep 16, 2024
f8c0495
Implement remaining `ToTransactionWithDefaults`
emlautarom1 Sep 16, 2024
dd43cf9
Add `From` field
emlautarom1 Sep 16, 2024
34de464
Add defaults test
emlautarom1 Sep 16, 2024
f8283e4
Add `EnsureDefaults`
emlautarom1 Sep 16, 2024
0b63ce6
Add test ignore
emlautarom1 Sep 16, 2024
eb98675
Forward `baseFee`
emlautarom1 Sep 16, 2024
11b1522
Use `RpcGenericTransaction` approach
emlautarom1 Sep 16, 2024
f4dd96b
Update flow docs
emlautarom1 Sep 16, 2024
8ee417e
Remove JSON constructor
emlautarom1 Sep 16, 2024
422460b
Add `IToTransaction<T>`
emlautarom1 Sep 16, 2024
416a21e
Add `RpcGenericTransaction`
emlautarom1 Sep 16, 2024
e2683f9
Implement `IToTransaction, IFromTransaction`
emlautarom1 Sep 16, 2024
1bb457d
Implement `ToTransactionWithDefaults`
emlautarom1 Sep 16, 2024
aaf6d53
Remove deleted files
emlautarom1 Sep 16, 2024
443115c
Implement `IToTransaction, IFromTransaction` for OP
emlautarom1 Sep 16, 2024
c431ad9
Add `EnsureDefaults`
emlautarom1 Sep 16, 2024
6cda988
Remove roundtrip tests
emlautarom1 Sep 16, 2024
e2e7691
Test for Nethermind fields
emlautarom1 Sep 16, 2024
5ad5049
Move files
emlautarom1 Sep 16, 2024
825d455
Proper inline docs
emlautarom1 Sep 16, 2024
5f3e553
Rename class
emlautarom1 Sep 16, 2024
79761d0
Fix import
emlautarom1 Sep 16, 2024
1ff3356
Simplify XML reference
emlautarom1 Sep 16, 2024
80264f4
Fix imports
emlautarom1 Sep 16, 2024
e07620d
Make fields `init` only
emlautarom1 Sep 16, 2024
70abd1b
Add transition `RpcGenericTransactionExtensions`
emlautarom1 Sep 16, 2024
aba2970
Preserve nullability
emlautarom1 Sep 16, 2024
70b175c
Simplify accessor
emlautarom1 Sep 16, 2024
93f94a9
Remove `chainId` from `ToTransactionWithDefaults`
emlautarom1 Sep 16, 2024
a9a06f4
Add more fallback methods durin dev
emlautarom1 Sep 16, 2024
4d88ba9
Remove `IRpcTransaction`
emlautarom1 Sep 16, 2024
e5d576d
Mimic `RpcNethermindTransaction.TransactionConverter`
emlautarom1 Sep 16, 2024
1d13861
Remove duplicated comment
emlautarom1 Sep 16, 2024
8a70ee5
Merge branch 'master' into refactor/individual-transaction-for-rpc
emlautarom1 Sep 16, 2024
04133ef
Fix whitespace
emlautarom1 Sep 16, 2024
4a07b2e
Merge branch 'master' into refactor/individual-transaction-for-rpc
emlautarom1 Sep 18, 2024
28e7173
Revert (again) to class hierarchy deserialization
emlautarom1 Sep 18, 2024
4f115eb
Reorder field initiatlization
emlautarom1 Sep 18, 2024
154512f
Add `From`
emlautarom1 Sep 18, 2024
d52c29a
Use `default`
emlautarom1 Sep 18, 2024
9d587ae
Add `ToTransaction`
emlautarom1 Sep 18, 2024
e51e23a
Assert subclass
emlautarom1 Sep 18, 2024
0df8888
Hide converter classes
emlautarom1 Sep 18, 2024
02e5765
Do not serialize `From` field
emlautarom1 Sep 18, 2024
ff726c8
Change `DefaultChainId` type
emlautarom1 Sep 18, 2024
865102a
Test for type constraint
emlautarom1 Sep 18, 2024
67895c2
Add `blobs`
emlautarom1 Sep 18, 2024
fce6373
Fix Tx Builder
emlautarom1 Sep 18, 2024
c804800
Add JSON constructors
emlautarom1 Sep 18, 2024
182ad70
Update licence year
emlautarom1 Sep 18, 2024
e52c79d
Update `RpcAccessList` tests
emlautarom1 Sep 19, 2024
aec8152
Add `EnsureDefaults`
emlautarom1 Sep 19, 2024
fcb1557
Implement abstract method in `RpcOptimismTransaction`
emlautarom1 Sep 19, 2024
fe90fcf
Add `Nonce` to Optimism
emlautarom1 Sep 19, 2024
a3b80d8
Make `Nonce` nullable
emlautarom1 Sep 19, 2024
8096c9e
Support nullable `StorageKeys`
emlautarom1 Sep 19, 2024
e30d035
Add nullability annotation
emlautarom1 Sep 19, 2024
19abbe0
Remove converter static field
emlautarom1 Sep 19, 2024
aea65b7
Add `Data` as an alias
emlautarom1 Sep 19, 2024
d153056
Add default JSON converters for RPC Transactions
emlautarom1 Sep 19, 2024
8a90075
Support deserializing string wrapped objects
emlautarom1 Sep 20, 2024
f44b4e4
Update main code
emlautarom1 Sep 20, 2024
9f10463
Delete Optimism RPC class
emlautarom1 Sep 20, 2024
cd5b22d
Make `TxType` to `virtual` to ensure invariants
emlautarom1 Sep 20, 2024
8420769
Include `TransactionConverterExtraData`
emlautarom1 Sep 20, 2024
7f72f37
Serialize `From`
emlautarom1 Sep 20, 2024
302a125
Update comparison to use JSON equality
emlautarom1 Sep 20, 2024
9eda9fd
Update comparison to use JSON equality
emlautarom1 Sep 20, 2024
6ee32a1
Use new types
emlautarom1 Sep 20, 2024
fe46fe2
Reintroduce TxType asserts
emlautarom1 Sep 20, 2024
78db619
Use Newtonsoft.JSON for tests
emlautarom1 Sep 20, 2024
4d4628e
Use class instead of record
emlautarom1 Sep 20, 2024
3e44de9
Use Newtonsoft.JSON for tests
emlautarom1 Sep 20, 2024
49521cb
Use Newtonsoft.JSON for tests
emlautarom1 Sep 23, 2024
78fd52f
Use new types
emlautarom1 Sep 23, 2024
8cd3505
Use new types
emlautarom1 Sep 23, 2024
0a6c06a
Update tests
emlautarom1 Sep 23, 2024
5db8814
Test for proper JSON equality
emlautarom1 Sep 23, 2024
cb1c471
Use new types
emlautarom1 Sep 23, 2024
9f4e404
Use new types
emlautarom1 Sep 23, 2024
ec83822
Use new types
emlautarom1 Sep 23, 2024
84022e1
Use new types
emlautarom1 Sep 23, 2024
ce86129
Use new types
emlautarom1 Sep 23, 2024
2ea0629
Reintroduce `UpdateTxType`
emlautarom1 Sep 23, 2024
0cda531
Use new types
emlautarom1 Sep 23, 2024
5ab8eb6
Update base class
emlautarom1 Sep 23, 2024
61bd483
Fix test
emlautarom1 Sep 23, 2024
ed8dc32
Rollback builder changes
emlautarom1 Sep 23, 2024
8d2eb6f
Use new types
emlautarom1 Sep 23, 2024
de52ef9
Rename RpcTransaction
emlautarom1 Sep 23, 2024
80ea178
Rename Optimism transaction
emlautarom1 Sep 23, 2024
5ad37bf
Rename struct
emlautarom1 Sep 23, 2024
0f0d03e
Remove traces from previous naming
emlautarom1 Sep 23, 2024
564ab95
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Sep 23, 2024
4035a07
Use correct code
emlautarom1 Sep 23, 2024
5145de9
Run dotnet format
emlautarom1 Sep 23, 2024
d710e79
Make types explicit
emlautarom1 Sep 23, 2024
b0e9075
Add `Nonce` to Optimism JSON serialization
emlautarom1 Sep 24, 2024
6144dab
1. Move more to generics
LukaszRozmej Sep 24, 2024
e2a9968
remove unneded method
LukaszRozmej Sep 24, 2024
6e801bc
fixes
LukaszRozmej Sep 24, 2024
51bc6bf
whitespace
LukaszRozmej Sep 24, 2024
93ca13b
Reduce code
emlautarom1 Sep 24, 2024
8ac7342
Cleanup docs, naming and nullability annotations
emlautarom1 Sep 24, 2024
bae6ecc
Merge remote-tracking branch 'origin/master' into refactor/transactio…
emlautarom1 Sep 25, 2024
d8a4465
Remove redundant default parameter
emlautarom1 Sep 25, 2024
b617ede
Separate `ITxTyped` from `IFromTransaction`
emlautarom1 Sep 25, 2024
4e90ed8
Inline private method
emlautarom1 Sep 25, 2024
7152b65
Rename tests
emlautarom1 Sep 25, 2024
86c5c77
Merge test suites
emlautarom1 Sep 25, 2024
fa24456
Reintroduce local method for consistency
emlautarom1 Sep 25, 2024
de871bf
Casing
emlautarom1 Sep 25, 2024
112a72c
Inline all JSON equality tests
emlautarom1 Sep 25, 2024
f841207
Move `ShouldSetBaseFee` to class method
emlautarom1 Sep 25, 2024
fa0b53e
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Sep 25, 2024
7c67ad6
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Sep 26, 2024
86d7ce3
Revert interface hierarchy
emlautarom1 Sep 27, 2024
58f2acc
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Sep 27, 2024
40c7ba2
Fix merge
emlautarom1 Sep 27, 2024
d0025fd
Pass `ChainId` to `FromTransaction`
emlautarom1 Sep 27, 2024
992e8e7
Pass `ChainId` to `TxPoolContent`
emlautarom1 Sep 27, 2024
1cb3e4f
Remove `DefaultChainId` hack
emlautarom1 Sep 27, 2024
ac903ad
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Sep 27, 2024
750ad0d
Remove defaulting mechanism for OP transactions
emlautarom1 Sep 30, 2024
f004f26
Reject malformed OP transactions
emlautarom1 Sep 30, 2024
ebb50d2
Initialize serializer once
emlautarom1 Sep 30, 2024
7738c0f
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Sep 30, 2024
7562257
Formatting
emlautarom1 Sep 30, 2024
0690958
Reintroduce laziness to `AccessListForRpc`
emlautarom1 Oct 1, 2024
b785352
Wrap up `Nonce` behavior in OP
emlautarom1 Oct 1, 2024
7c4a9ed
Fix Blob transaction code
emlautarom1 Oct 1, 2024
1c68869
Json Type parsing (#7538)
benaadams Oct 2, 2024
58396a8
Change private `TransactionType` to struct
emlautarom1 Oct 2, 2024
0ff03ac
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Oct 2, 2024
281f6af
Merge branch 'refactor/transaction-for-rpc-hierarchy' of https://gith…
emlautarom1 Oct 2, 2024
42c1b29
Avoid double serialization in tests
emlautarom1 Oct 3, 2024
5002733
Avoid double serialization in RPC tests (#7547)
emlautarom1 Oct 4, 2024
686269f
Merge branch 'master' into refactor/transaction-for-rpc-hierarchy
emlautarom1 Oct 4, 2024
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 @@ -80,21 +80,20 @@ internal static void RegisterTransactionType<T>() where T : TransactionForRpc, I

public override TransactionForRpc? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
using var document = JsonDocument.ParseValue(ref reader);

// TODO: For some reason we might get an object wrapped in a String
using JsonDocument jsonObject = document.RootElement.ValueKind == JsonValueKind.String
? JsonDocument.Parse(document.RootElement.GetString()!)
: document;

TxType discriminator = DefaultTxType;
if (jsonObject.RootElement.TryGetProperty("type", out JsonElement typeProperty))
if (reader.ValueIsEscaped)
{
discriminator = (TxType?)typeProperty.Deserialize(typeof(TxType), options) ?? DefaultTxType;
string escapedJson = JsonSerializer.Deserialize<string>(ref reader);
emlautarom1 marked this conversation as resolved.
Show resolved Hide resolved
return JsonSerializer.Deserialize<TransactionForRpc>(escapedJson, options);
}

// Copy reader so we can double parse to get type
Utf8JsonReader copyReader = reader;
TransactionType type = JsonSerializer.Deserialize<TransactionType>(ref copyReader, options);

TxType discriminator = (TxType)(type.Type ?? (ulong)DefaultTxType);
emlautarom1 marked this conversation as resolved.
Show resolved Hide resolved

return _types.TryGetByTxType(discriminator, out Type concreteTxType)
? (TransactionForRpc?)jsonObject.Deserialize(concreteTxType, options)
? (TransactionForRpc?)JsonSerializer.Deserialize(ref reader, concreteTxType, options)
: throw new JsonException("Unknown transaction type");
}

Expand All @@ -104,6 +103,12 @@ public override void Write(Utf8JsonWriter writer, TransactionForRpc value, JsonS
}
}

private class TransactionType
{
// Hex value
public ulong? Type { get; set; }
}

internal class TransactionConverter
{
private delegate TransactionForRpc FromTransactionFunc(Transaction tx, TransactionConverterExtraData extraData);
Expand Down
28 changes: 14 additions & 14 deletions src/Nethermind/Nethermind.JsonRpc.Test/JsonRpcSocketsClientTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ static async Task<int> CountNumberOfMessages(Socket socket, CancellationToken to
byte[] buffer = new byte[10];
while (true)
{
ReceiveResult? result = await stream.ReceiveAsync(buffer);
ReceiveResult? result = await stream.ReceiveAsync(buffer).ConfigureAwait(false);
if (result?.EndOfMessage == true)
{
messages++;
Expand Down Expand Up @@ -108,7 +108,7 @@ static async Task<int> CountNumberOfMessages(Socket socket, CancellationToken to
Task<int> sendMessages = Task.Run(async () =>
{
using Socket socket = new(ipEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
await socket.ConnectAsync(ipEndPoint);
await socket.ConnectAsync(ipEndPoint).ConfigureAwait(false);

using IpcSocketMessageStream stream = new(socket);
using JsonRpcSocketsClient<IpcSocketMessageStream> client = new(
Expand All @@ -124,17 +124,17 @@ static async Task<int> CountNumberOfMessages(Socket socket, CancellationToken to
for (int i = 0; i < messageCount; i++)
{
using JsonRpcResult result = JsonRpcResult.Single(RandomSuccessResponse(1_000, () => disposeCount++), default);
await client.SendJsonRpcResult(result);
await Task.Delay(10);
await client.SendJsonRpcResult(result).ConfigureAwait(false);
await Task.Delay(1).ConfigureAwait(false);
}

disposeCount.Should().Be(messageCount);
await cts.CancelAsync();
await cts.CancelAsync().ConfigureAwait(false);

return messageCount;
});

await Task.WhenAll(sendMessages, receiveMessages);
await Task.WhenAll(sendMessages, receiveMessages).ConfigureAwait(false);
int sent = sendMessages.Result;
int received = receiveMessages.Result;

Expand All @@ -158,7 +158,7 @@ async Task<int> ReadMessages(Socket socket, IList<byte[]> receivedMessages, Canc
byte[] buffer = new byte[bufferSize];
while (true)
{
ReceiveResult? result = await stream.ReceiveAsync(buffer);
ReceiveResult? result = await stream.ReceiveAsync(buffer).ConfigureAwait(false);
if (result is not null)
{
msg.AddRange(buffer.Take(result.Read));
Expand Down Expand Up @@ -190,14 +190,14 @@ async Task<int> ReadMessages(Socket socket, IList<byte[]> receivedMessages, Canc

Task<int> receiveMessages = OneShotServer(
ipEndPoint,
async socket => await ReadMessages(socket, receivedMessages, cts.Token)
async socket => await ReadMessages(socket, receivedMessages, cts.Token).ConfigureAwait(false)
);

Task<int> sendMessages = Task.Run(async () =>
{
int messageCount = 0;
using Socket socket = new(ipEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
await socket.ConnectAsync(ipEndPoint);
await socket.ConnectAsync(ipEndPoint).ConfigureAwait(false);

using IpcSocketMessageStream stream = new(socket);
using JsonRpcSocketsClient<IpcSocketMessageStream> client = new(
Expand All @@ -216,20 +216,20 @@ async Task<int> ReadMessages(Socket socket, IList<byte[]> receivedMessages, Canc
messageCount++;
var msg = Enumerable.Range(11, i).Select(x => (byte)x).ToArray();
sentMessages.Add(msg);
await stream.WriteAsync(msg);
await stream.WriteEndOfMessageAsync();
await stream.WriteAsync(msg).ConfigureAwait(false);
await stream.WriteEndOfMessageAsync().ConfigureAwait(false);
if (i % 10 == 0)
{
await Task.Delay(10);
await Task.Delay(1).ConfigureAwait(false);
}
}
stream.Close();
await cts.CancelAsync();
await cts.CancelAsync().ConfigureAwait(false);

return messageCount;
});

await Task.WhenAll(sendMessages, receiveMessages);
await Task.WhenAll(sendMessages, receiveMessages).ConfigureAwait(false);
int sent = sendMessages.Result;
int received = receiveMessages.Result;

Expand Down
8 changes: 4 additions & 4 deletions src/Nethermind/Nethermind.JsonRpc.Test/RpcTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ public static async Task<string> TestSerializedRequest<T>(T module, string metho
JsonRpcContext context = module is IContextAwareRpcModule { Context: not null } contextAwareModule ?
contextAwareModule.Context :
new JsonRpcContext(RpcEndpoint.Http);
using JsonRpcResponse response = await service.SendRequestAsync(request, context);
using JsonRpcResponse response = await service.SendRequestAsync(request, context).ConfigureAwait(false);

EthereumJsonSerializer serializer = new();

Stream stream = new MemoryStream();
long size = await serializer.SerializeAsync(stream, response);
long size = await serializer.SerializeAsync(stream, response).ConfigureAwait(false);

// for coverage (and to prove that it does not throw
Stream indentedStream = new MemoryStream();
await serializer.SerializeAsync(indentedStream, response, true);
await serializer.SerializeAsync(indentedStream, response, true).ConfigureAwait(false);

stream.Seek(0, SeekOrigin.Begin);
string serialized = await new StreamReader(stream).ReadToEndAsync();
string serialized = await new StreamReader(stream).ReadToEndAsync().ConfigureAwait(false);

size.Should().Be(serialized.Length);

Expand Down