-
Notifications
You must be signed in to change notification settings - Fork 18
Introduce EventPublisher trait. #51
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
672379c
Refactor persistance related IO to separate module.
G8XSU 3fe2b1d
Add basic structure for defining different events.
G8XSU 9741cba
Introduce EventPublisher trait.
G8XSU bc97890
Add NoopEventPublisher, which will be used as default impl.
G8XSU 5ffb7d8
Start publishing events using EventPublisher.
G8XSU File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/// EventEnvelope wraps different event types in a single message to be used by EventPublisher. | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct EventEnvelope { | ||
#[prost(oneof = "event_envelope::Event", tags = "2")] | ||
pub event: ::core::option::Option<event_envelope::Event>, | ||
} | ||
/// Nested message and enum types in `EventEnvelope`. | ||
pub mod event_envelope { | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Oneof)] | ||
pub enum Event { | ||
#[prost(message, tag = "2")] | ||
PaymentForwarded(super::PaymentForwarded), | ||
} | ||
} | ||
/// PaymentForwarded indicates a payment was forwarded through the node. | ||
#[allow(clippy::derive_partial_eq_without_eq)] | ||
#[derive(Clone, PartialEq, ::prost::Message)] | ||
pub struct PaymentForwarded { | ||
#[prost(message, optional, tag = "1")] | ||
pub forwarded_payment: ::core::option::Option<super::types::ForwardedPayment>, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod api; | ||
pub mod error; | ||
pub mod events; | ||
pub mod types; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
syntax = "proto3"; | ||
import "types.proto"; | ||
package events; | ||
|
||
// EventEnvelope wraps different event types in a single message to be used by EventPublisher. | ||
message EventEnvelope { | ||
oneof event { | ||
PaymentForwarded payment_forwarded = 2; | ||
} | ||
} | ||
|
||
// PaymentForwarded indicates a payment was forwarded through the node. | ||
message PaymentForwarded { | ||
types.ForwardedPayment forwarded_payment = 1; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
use crate::api::error::LdkServerError; | ||
use async_trait::async_trait; | ||
use ldk_server_protos::events::EventEnvelope; | ||
|
||
/// A trait for publishing events or notifications from the LDK Server. | ||
/// | ||
/// Implementors of this trait define how events are sent to various messaging | ||
/// systems. It provides a consistent, asynchronous interface for event publishing, while allowing | ||
/// each implementation to manage its own initialization and configuration, typically sourced from | ||
/// the `ldk-server.config` file. A no-op implementation is included by default, | ||
/// with specific implementations enabled via feature flags. | ||
/// | ||
/// Events are represented as [`EventEnvelope`] messages, which are Protocol Buffers | ||
/// ([protobuf](https://protobuf.dev/)) objects defined in [`ldk_server_protos::events`]. | ||
/// These events are serialized to bytes by the publisher before transmission, and consumers can | ||
/// deserialize them using the protobuf definitions. | ||
/// | ||
/// The underlying messaging system is expected to support durably buffered events, | ||
/// enabling easy decoupling between the LDK Server and event consumers. | ||
#[async_trait] | ||
pub trait EventPublisher { | ||
/// Publishes an event to the underlying messaging system. | ||
/// | ||
/// # Arguments | ||
/// * `event` - The event message to publish, provided as an [`EventEnvelope`] | ||
/// defined in [`ldk_server_protos::events`]. Implementors must serialize | ||
/// the whole [`EventEnvelope`] to bytes before publishing. | ||
/// | ||
/// In order to ensure no events are lost, implementors of this trait must publish events | ||
/// durably to underlying messaging system. An event is considered published when | ||
/// [`EventPublisher::publish`] returns `Ok(())`, thus implementors MUST durably persist/publish events *before* | ||
/// returning `Ok(())`. | ||
/// | ||
/// # Errors | ||
/// May return an [`LdkServerErrorCode::InternalServerError`] if the event cannot be published, | ||
/// such as due to network failures, misconfiguration, or transport-specific issues. | ||
/// If event publishing fails, the LDK Server will retry publishing the event indefinitely, which | ||
/// may degrade performance until the underlying messaging system is operational again. | ||
G8XSU marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// | ||
/// [`LdkServerErrorCode::InternalServerError`]: crate::api::error::LdkServerErrorCode | ||
async fn publish(&self, event: EventEnvelope) -> Result<(), LdkServerError>; | ||
} | ||
|
||
pub(crate) struct NoopEventPublisher; | ||
|
||
#[async_trait] | ||
impl EventPublisher for NoopEventPublisher { | ||
/// Publishes an event to a no-op sink, effectively discarding it. | ||
/// | ||
/// This implementation does nothing and always returns `Ok(())`, serving as a | ||
/// default when no messaging system is configured. | ||
async fn publish(&self, _event: EventEnvelope) -> Result<(), LdkServerError> { | ||
Ok(()) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub(crate) mod event_publisher; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,3 @@ | ||
pub(crate) mod paginated_kv_store; | ||
pub(crate) mod sqlite_store; | ||
pub(crate) mod events; | ||
pub(crate) mod persist; | ||
pub(crate) mod utils; | ||
|
||
/// The forwarded payments will be persisted under this prefix. | ||
pub(crate) const FORWARDED_PAYMENTS_PERSISTENCE_PRIMARY_NAMESPACE: &str = "forwarded_payments"; | ||
pub(crate) const FORWARDED_PAYMENTS_PERSISTENCE_SECONDARY_NAMESPACE: &str = ""; | ||
|
||
/// The payments will be persisted under this prefix. | ||
pub(crate) const PAYMENTS_PERSISTENCE_PRIMARY_NAMESPACE: &str = "payments"; | ||
pub(crate) const PAYMENTS_PERSISTENCE_SECONDARY_NAMESPACE: &str = ""; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
pub(crate) mod paginated_kv_store; | ||
pub(crate) mod sqlite_store; | ||
|
||
/// The forwarded payments will be persisted under this prefix. | ||
pub(crate) const FORWARDED_PAYMENTS_PERSISTENCE_PRIMARY_NAMESPACE: &str = "forwarded_payments"; | ||
pub(crate) const FORWARDED_PAYMENTS_PERSISTENCE_SECONDARY_NAMESPACE: &str = ""; | ||
|
||
/// The payments will be persisted under this prefix. | ||
pub(crate) const PAYMENTS_PERSISTENCE_PRIMARY_NAMESPACE: &str = "payments"; | ||
pub(crate) const PAYMENTS_PERSISTENCE_SECONDARY_NAMESPACE: &str = ""; |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
ldk-server/src/io/sqlite_store/mod.rs → ...server/src/io/persist/sqlite_store/mod.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.