Repository navigation
wasm: Route clock reads through a time module - #1122
benthecarman wants to merge 5 commits into
Conversation
|
I've assigned @tnull as a reviewer! |
fa1f806 to
e3dc550
Compare
| now, | ||
| FORWARDED_PAYMENT_AGGREGATION_BUCKET_SIZE_SECS, | ||
| ); | ||
| // Tokio deadlines must use the runtime clock, whose origin may differ from our provider. |
There was a problem hiding this comment.
Hmm, so this will panic if exercised in WASM?
There was a problem hiding this comment.
For now, will do tokio related stuff in the future
| pub mod probing; | ||
| mod runtime; | ||
| mod scoring; | ||
| pub mod time; |
There was a problem hiding this comment.
no longer with the builder change
|
|
||
| impl std::error::Error for TimeProviderAlreadyInitialized {} | ||
|
|
||
| static TIME_PROVIDER: OnceLock<Arc<dyn TimeProvider>> = OnceLock::new(); |
There was a problem hiding this comment.
Are we positive to make this a OnceLock? If we made it a 'regular' parameter to Node settable via the Builder, it could be useful, eg., for testing purposes to allow some nodes to experience clock drift etc?
There was a problem hiding this comment.
Changed it to be a part of the Builder but it goes into the OnceLock. If it's just a part of the Node it percolates everywhere and gets kinda ugly
| @@ -1 +1,14 @@ | |||
| msrv = "1.63.0" No newline at end of file | |||
| msrv = "1.63.0" | |||
There was a problem hiding this comment.
This is outdated. Mind updating in a commit since you're already here?
e3dc550 to
ada49f1
Compare
Keep node wall and monotonic clock reads behind one provider in the time module. Use native clocks by default and let embedding hosts supply one through the builder. The provider is process-wide and can't be replaced once in use, so monotonic measurements share one origin. Nodes can share a provider, but building with a different one fails. Drop chrono's clock feature, as UTC timestamps now come from the provider. Ban direct platform clock reads with clippy and run the check in a dedicated CI job across the native and UniFFI feature sets, so new code stays wasm32-safe while the rest of the port lands. AI assistance: Claude Opus 5.5 and OpenAI Codex. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Supply node time to BDK scans, liquidity, invoice timestamps, gossip snapshots, and UniFFI expiry checks through existing explicit-time APIs. Preserve freshness and expiry validation, and report a pre-epoch clock as an LSPS2 invoice creation error. Disable transaction-sync's optional timing logs, which duplicate the node's own sync duration logs, so it no longer reads the clock itself. Ban the dependency APIs that read the platform clock internally, so call sites keep using the explicit-time variants. AI assistance: Claude Opus 5.5 and OpenAI Codex. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LDK's std feature reads the system clock internally (channel manager, gossip, offers, payment retries, liquidity), which wasm32 can't do. Move it and liquidity's time feature behind a default ldk-std feature, so code can switch to LDK's explicit-time APIs when it is disabled. The chain sources and filesystem storage pull in LDK crates that require std, so they enable ldk-std. Native builds resolve the same LDK features as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
lightning-net-tokio enables LDK's default features, which turns std back on even when ldk-std is disabled. Move it behind a default net-tokio feature so builds without ldk-std are free of LDK's internal clock reads. Without net-tokio, a placeholder socket type stands in for the transport. It has no values, so no connection can be created with it: connecting to peers fails and listening addresses are rejected at build time. This leaves the seam for a wasm32 transport later. Restore the CI check that disabling default features leaves no LDK clock features enabled, and lint a build without net-tokio so the placeholder keeps compiling. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The crate's minimum supported Rust version is 1.85, but .clippy.toml still targeted 1.63, so clippy applied lint rules for the wrong toolchain. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ada49f1 to
41be68a
Compare
First step toward wasm32 support: stop reading the system clock directly, since
SystemTime::now()panics onwasm32-unknown-unknown.ldk_node::time. All clock reads go through it, and hosts without asystem clock can install a
TimeProvider.internally.
stdfeatures behind a defaultldk-stdfeature, andlightning-net-tokiobehind a defaultnet-tokiofeature. Both are temporaryscaffolding for the port.
std/timefeatures are off when default features are disabled.
Native behavior should be unchanged.