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

feat(rpc): initial RPC server/client implementation #59

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

ultd
Copy link
Contributor

@ultd ultd commented Dec 18, 2023

  • Initial RPC server
  • Processor implements GossipService dependent methods
  • Result returns a way to free allocated memory
  • Initial RPC client
  • Server returns correct headers, including CORS and serving Option requests
  • Client allows for multiple transports
  • Create JSON serialization/deserialization framework that replicates serde's behavior

To test out RPC server run it via:

zig build run -- validator --entrypoint 34.83.231.102:8001 \
    --entrypoint 145.40.67.83:8001 \
    --entrypoint 147.75.38.117:8001 \
    --entrypoint 145.40.93.177:8001 \
    --entrypoint 86.109.15.59:8001

@ultd ultd changed the title Initial RPC server implementation Initial RPC server/client implementation Dec 18, 2023
@ultd ultd marked this pull request as draft January 19, 2024 04:01
@ultd ultd marked this pull request as ready for review March 15, 2024 15:55
@0xNineteen 0xNineteen self-requested a review March 19, 2024 13:39
var arena = allocator.create(std.heap.ArenaAllocator) catch {
return .{ .ClientError = .OutOfMemory };
};
arena.* = std.heap.ArenaAllocator.init(allocator);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems like this leaks on success?

feeCalculator: FeeCalculator,
};

pub const FeeCalculator = struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something to note - seems like a lot of these structs also exist in the accounts-db branch but with snake_case field names

var table: *const GossipTable = table_rlock.get();

var contact_infos = table.getAllContactInfos() catch return .{ .Err = t.Error.Internal };
var rpc_contact_infos = std.ArrayList(t.RpcContactInfo).initCapacity(allocator, contact_infos.items.len) catch return .{ .Err = t.Error.Internal };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will all rpc methods need to return this Internal Error? - catch statements might be excessive on more complex rpc calls


inline fn methodCall(allocator: std.mem.Allocator, processor: *RpcRequestProcessor, request: *t.JsonRpcRequest, response: *httpz.Response) !void {
inline for (@typeInfo(t.RpcServiceImpl(RpcRequestProcessor, t.Result)).Struct.fields) |field| {
if (strEquals(request.method, field.name)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this fcn is only used once, might as well just have it as std.mem.eql

request.id,
response,
t.jrpc_error_code_invalid_params,
std.fmt.allocPrint(allocator, "Invalid params, expected type: array, got: {s} ", .{@tagName(request.params)}) catch unreachable,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this fcn is already anyerror we should probably keep this as a try since the alloc can fail?


args[0] = processor;
args[1] = allocator;
inline for (std.meta.fields(Args)[2..], 2.., 0..) |field, argIndex, valueIndex| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these vars should be snake_case

try response.write();
}

inline fn methodCall(allocator: std.mem.Allocator, processor: *RpcRequestProcessor, request: *t.JsonRpcRequest, response: *httpz.Response) !void {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason why this is a seperate fcn?

return std.mem.eql(u8, value, other);
}

pub fn RpcFunc(comptime func: anytype) type {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe rename to RpcFnCaller?

@ultd ultd changed the title Initial RPC server/client implementation feat(rpc): initial RPC server/client implementation Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

None yet

2 participants