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

Add Api impl for ListForwardedPayments. #32

Merged
merged 5 commits into from
Dec 13, 2024

Conversation

G8XSU
Copy link
Contributor

@G8XSU G8XSU commented Dec 7, 2024

Based on #35

@G8XSU G8XSU requested a review from jkczyz December 7, 2024 00:04
outbound_amount_forwarded_msat.unwrap_or(0), total_fee_earned_msat.unwrap_or(0), prev_channel_id, next_channel_id
);

let forwarded_payment = forwarded_payment_to_proto(payment_forwarded_event);
Copy link

Choose a reason for hiding this comment

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

Do we need to use the proto version here? Seems it would better not to to the translation and allocate a vec.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Main reason for doing this is so that this data is easily accessible outside of LDK if need be.
We have APIs that are protobuf-defined, and eventually, we will have events that are protobuf-defined, along with some data that makes sense to be easily accessible outside of LDK in protobuf format. (However, this doesn't apply to all types of data that we store.)

For example, when a user has a Postgres backend for storage with read replicas, it might make sense for them to query data directly from the database-read-replica using a simple utility for batch queries and analytics.
This becomes even more important as LDK-server itself isn't horizontally scalable, and users might want to offload simple but large read queries to another system.

Comment on lines 43 to 53
pub(crate) struct Context {
pub(crate) node: Arc<Node>,
}
Copy link

Choose a reason for hiding this comment

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

Could you remind me why PaginatedKvStore can't be in NodeService? Is it just to save passing two parameters to the relevant handlers? If this is only need for one handler, then I'm not sure if we should bother adding the wrapper.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is to avoid passing two parameters; otherwise, every time there is a new parameter, we need a signature change for all handlers.
Currently, the way the code is structured, we have some common handler code in handle_request, and it is enforcing every handler to have the same signature.

I believe it is okay to have the same signature for every handler and only have these common context members exposed to them; some future additions could include logger, metrics etc.

Copy link

Choose a reason for hiding this comment

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

Right, that makes sense. Alternatively, you could have everything take Arc<NodeService> instead. Though we may need a wrapper on that to implement Service<Request<Incoming>> since we can't implement that trait on Arc<NodeService> directly. Then you could remove the Arc from Node and have the event handler access it through an Arc. I'm more inclined towards that than introducing a Context wrapper, unless I'm missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if i completely understand this approach but it seems very complicated.
Why not go with something simpler such as service-context? what is the advantage of the other approach over it?

Currently, the whole reason for NodeService to exist is to implement Service<Request<Incoming>>, which in turn calls api-handlers. Giving api-handlers access to nodeService seems like a circular dependency.

Copy link

Choose a reason for hiding this comment

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

Hmm... seems less complicated if we don't add another struct. I don't see it as a circular dependency. The only reason why these functions aren't methods on NodeService is to get around the fact that Service uses Future instead of being an async trait. Using Arc<NodeService> is just like a &self parameter that works with async.

The wrapper is only needed because both Service and Arc don't belong to this crate, so we need another type to implement Service on. But that is only needed locally.

Copy link
Contributor Author

@G8XSU G8XSU Dec 13, 2024

Choose a reason for hiding this comment

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

I agree with that, we can create context inside call method.
Will use call instead of handle_request so that we don't need a signature change (for new context members) for all these methods : https://github.com/lightningdevkit/ldk-server/blob/main/ldk-server/src/service.rs#L53-L76

Copy link

Choose a reason for hiding this comment

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

Right, inside call is accurate. I misspoke earlier.

Copy link

@jkczyz jkczyz Dec 13, 2024

Choose a reason for hiding this comment

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

Err... actually you need to create Context in handle_request to pass it to call, IIUC, since you need both the Arc<Node> and Arc<PaginatedKVStore> from NodeService to create Context.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Checkout current diff with the Context being created in call

Copy link

Choose a reason for hiding this comment

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

Yeah, that looks good. Seems I was just mixing up the names for some reason. 😛

@G8XSU G8XSU force-pushed the forwarded-payments branch from 5ef7584 to 15964ea Compare December 11, 2024 23:44
@G8XSU G8XSU marked this pull request as ready for review December 11, 2024 23:44
ldk-server/src/api/onchain_send.rs Show resolved Hide resolved
ldk-server-protos/src/proto/types.proto Outdated Show resolved Hide resolved
ldk-server-protos/src/proto/types.proto Outdated Show resolved Hide resolved
ldk-server/src/main.rs Outdated Show resolved Hide resolved
ldk-server/src/main.rs Outdated Show resolved Hide resolved
ldk-server/src/main.rs Outdated Show resolved Hide resolved
ldk-server/src/util/proto_adapter.rs Outdated Show resolved Hide resolved
@G8XSU G8XSU requested review from jkczyz and tnull December 12, 2024 22:55
@G8XSU G8XSU mentioned this pull request Dec 12, 2024
9 tasks
Copy link
Collaborator

@tnull tnull left a comment

Choose a reason for hiding this comment

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

LGTM from my side I think, mod pending discussions.

ldk-server/src/api/list_forwarded_payments.rs Show resolved Hide resolved
@G8XSU G8XSU force-pushed the forwarded-payments branch from 5f6c91f to f73a54c Compare December 13, 2024 21:46
@G8XSU
Copy link
Contributor Author

G8XSU commented Dec 13, 2024

Squashed current fixups since it would have been difficult to do context refactoring.

@G8XSU G8XSU requested a review from jkczyz December 13, 2024 22:03
Copy link

@jkczyz jkczyz left a comment

Choose a reason for hiding this comment

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

LGTM. Please squash

@G8XSU G8XSU force-pushed the forwarded-payments branch from ad9f221 to 5f34539 Compare December 13, 2024 22:13
@G8XSU
Copy link
Contributor Author

G8XSU commented Dec 13, 2024

Squashed fixups !

@G8XSU G8XSU merged commit f28b20d into lightningdevkit:main Dec 13, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants