Files
cdk/Cargo.toml
C cdd59359b9 Introduce a generic pubsub mod in cdk-common (#1098)
* pubsub: consolidate into Spec, adopt Arc<SubscriptionId>, and wire through  wallet/mint/WS/FFI

Refactor the pub/sub engine to a single Spec trait, move Event alongside it,
and propagate Arc-backed subscription IDs across the stack. This simplifies
generics, clarifies responsibilities, and preserves coalescing +
latest-on-subscribe semantics.

-   **Single source of truth:** `Spec` owns `Topic`, `Event`, `SubscriptionId`,
    `Context`, new_instance, and fetch_events.
-   **Lean & explicit API:** Remove Topic trait split;
    `Subscriber::send(Event)` carries sub-ID internally.
-   **Performance/ergonomics:** `Arc<SubscriptionId>` avoids heavy clones and
    makes channel/task hops trivial.

-   Introduce `pub_sub/typ.rs` with:
    -   trait `Spec`
    -   trait `Event` colocated with Spec.
-   Remove `pub_sub/event.rs` fold `Event` into `typ.rs`.
-   Make `Pubsub<S>` generic over `Spec` and store `Arc<S>`.
-   The subscriber holds `Arc<SubscriptionId>` and deduplicates the latest
    entry per subscription.
-   SubscriptionRequest: rename SubscriptionName → SubscriptionId; return
    `Arc<...>` from `subscription_name()`.
-   Remote consumer (Transport) now parameterized by `Spec`; control types
    updated:
    -   `StreamCtrl<S>`, `SubscribeMessage<S>`, internal caches keyed by
        `S::Topic`.
-   Mint/wallet:
    -   Mint: `MintPubSubSpec` (Context = `DynMintDatabase`),
        `PubSubManager(Pubsub<MintPubSubSpec>)`.
    -   Wallet: lightweight MintSubTopics Spec with `Context = ()`.
-   IDs go Arc end-to-end:
    -   cdk-axum WS maps `HashMap<Arc<SubId>, JoinHandle<()>>`, publisher sends
        `(Arc<SubId>, NotificationPayload)`.
    -   `subscription::{Params, WalletParams}` now use `Arc<...>`.
    -   cdk-ffi conversions & wallet glue updated.
    -   Integration tests updated for new types.

-   Coalescing unchanged: multiple local subs to the same topic are combined
    into a single remote sub.
-   Backfill via `Spec::fetch_events(topics, Subscriber)`; Subscriber enforces
    latest-only dedupe per subscription.

**Result:** a slimmer, more maintainable pub/sub core that’s easier to embed
across mint, wallet, transports, and FFI without sacrificing performance or
semantics.


---------

Co-authored-by: thesimplekid <tsk@thesimplekid.com>
2025-10-08 09:33:45 +01:00

141 lines
5.1 KiB
TOML

[workspace]
members = [
"crates/*",
]
resolver = "2"
[workspace.lints.rust]
unsafe_code = "forbid"
unreachable_pub = "warn"
missing_debug_implementations = "warn"
[workspace.lints.clippy]
pedantic = "warn"
unwrap_used = "warn"
clone_on_ref_ptr = "warn"
missing_errors_doc = "warn"
missing_panics_doc = "warn"
missing_safety_doc = "warn"
nursery = "warn"
redundant_else = "warn"
redundant_closure_for_method_calls = "warn"
unneeded_field_pattern = "warn"
use_debug = "warn"
large_enum_variant = "warn"
[workspace.lints.rustdoc]
missing_docs = "warn"
bare_urls = "warn"
[workspace.package]
edition = "2021"
rust-version = "1.85.0"
license = "MIT"
homepage = "https://github.com/cashubtc/cdk"
repository = "https://github.com/cashubtc/cdk.git"
version = "0.13.0"
readme = "README.md"
[workspace.dependencies]
anyhow = "1"
async-trait = "0.1"
axum = { version = "0.8.1", features = ["ws"] }
bitcoin = { version = "0.32.2", features = ["base64", "serde", "rand", "rand-std"] }
bip39 = { version = "2.0", features = ["rand"] }
jsonwebtoken = "9.2.0"
cashu = { path = "./crates/cashu", version = "=0.13.0" }
cdk = { path = "./crates/cdk", default-features = false, version = "=0.13.0" }
cdk-common = { path = "./crates/cdk-common", default-features = false, version = "=0.13.0" }
cdk-axum = { path = "./crates/cdk-axum", default-features = false, version = "=0.13.0" }
cdk-cln = { path = "./crates/cdk-cln", version = "=0.13.0" }
cdk-lnbits = { path = "./crates/cdk-lnbits", version = "=0.13.0" }
cdk-lnd = { path = "./crates/cdk-lnd", version = "=0.13.0" }
cdk-ldk-node = { path = "./crates/cdk-ldk-node", version = "=0.13.0" }
cdk-fake-wallet = { path = "./crates/cdk-fake-wallet", version = "=0.13.0" }
cdk-ffi = { path = "./crates/cdk-ffi", version = "=0.13.0" }
cdk-payment-processor = { path = "./crates/cdk-payment-processor", default-features = true, version = "=0.13.0" }
cdk-mint-rpc = { path = "./crates/cdk-mint-rpc", version = "=0.13.0" }
cdk-redb = { path = "./crates/cdk-redb", default-features = true, version = "=0.13.0" }
cdk-sql-common = { path = "./crates/cdk-sql-common", default-features = true, version = "=0.13.0" }
cdk-sqlite = { path = "./crates/cdk-sqlite", default-features = true, version = "=0.13.0" }
cdk-postgres = { path = "./crates/cdk-postgres", default-features = true, version = "=0.13.0" }
cdk-signatory = { path = "./crates/cdk-signatory", version = "=0.13.0", default-features = false }
cdk-mintd = { path = "./crates/cdk-mintd", version = "=0.13.0", default-features = false }
cdk-prometheus = { path = "./crates/cdk-prometheus", version = "=0.13.0", default-features = false }
clap = { version = "4.5.31", features = ["derive"] }
ciborium = { version = "0.2.2", default-features = false, features = ["std"] }
cbor-diag = "0.1.12"
config = { version = "0.15.11", features = ["toml"] }
futures = { version = "0.3.28", default-features = false, features = ["async-await"] }
lightning-invoice = { version = "0.33.0", features = ["serde", "std"] }
lightning = { version = "0.1.2", default-features = false, features = ["std"]}
ldk-node = "0.6.2"
serde = { version = "1", features = ["derive", "rc"] }
serde_json = "1"
thiserror = { version = "2" }
tokio = { version = "1", default-features = false, features = ["rt", "macros", "test-util", "sync"] }
tokio-util = { version = "0.7.11", default-features = false }
tower = "0.5.2"
tower-http = { version = "0.6.1", features = ["compression-full", "decompression-full", "cors", "trace", "fs"] }
tokio-tungstenite = { version = "0.26.0", default-features = false }
tokio-stream = "0.1.15"
tracing = { version = "0.1", default-features = false, features = ["attributes", "log"] }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tracing-appender = "0.2"
url = "2.3"
uuid = { version = "1.17", features = ["v4", "serde"] }
utoipa = { version = "5.3.1", features = [
"preserve_order",
"preserve_path_order",
]}
serde_with = "3"
reqwest = { version = "0.12", default-features = false, features = [
"json",
"rustls-tls",
"rustls-tls-native-roots",
"socks",
"zstd",
"brotli",
"gzip",
"deflate",
]}
once_cell = "1.20.2"
web-time = "1.1.0"
rand = "0.9.1"
regex = "1"
home = "0.5.5"
tonic = { version = "0.13.1", features = ["tls-ring", "codegen", "prost", "transport"], default-features = false }
prost = "0.13.1"
tonic-build = "0.13.1"
strum = "0.27.1"
strum_macros = "0.27.1"
rustls = { version = "0.23.27", default-features = false, features = ["ring"] }
prometheus = { version = "0.13.4", features = ["process"], default-features = false }
[workspace.metadata]
authors = ["CDK Developers"]
description = "Cashu Development Kit"
readme = "README.md"
repository = "https://github.com/cashubtc/cdk"
license-file = "LICENSE"
keywords = ["bitcoin", "e-cash", "cashu"]
[profile.ci]
inherits = "dev"
incremental = false
lto = "off"
[profile.release-smaller]
inherits = "release"
opt-level = 'z' # Optimize for size.
lto = true # Enable Link Time Optimization
codegen-units = 1 # Reduce number of codegen units to increase optimizations.
panic = "abort" # Abort on panic
strip = "debuginfo" # Partially strip symbols from binary
[workspace.metadata.crane]
name = "cdk-workspace"