Skip to content

EventQueue: load the persisted queue at start - #116

Open
hash-money wants to merge 1 commit into
lightningdevkit:masterfrom
emergent-money:fix/event-queue-load
Open

hash-money wants to merge 1 commit into
lightningdevkit:masterfrom
emergent-money:fix/event-queue-load

Conversation

@hash-money

Copy link
Copy Markdown
Contributor

EventQueue::new always starts with an empty VecDeque, while every push and every event_handled persist the queue under orange_events (EVENT_QUEUE_PERSISTENCE_KEY). The key is written and never read, so any event still unhandled when the process exits is lost on the next run. ldk-node reads its own queue back at build time (io::utils::read_event_queue; in builder.rs NotFound is a fresh queue and any other error is BuildError::ReadFailed).

This mirrors that: new becomes async and fallible, reads the key, starts empty on NotFound, and fails the build (InitFailure::IoError) on any other read error or on a queue that does not decode. The reader is the counterpart of EventQueueSerWrapper (a u16 count, then the events), as in ldk-node. A store that errors on read now fails Wallet::new here rather than at ldk-node's build_with_store of the same store a few lines later (BuildError::ReadFailed), so nothing that built before fails now.

Delivery becomes at-least-once across a restart, since an LDK event is persisted here before it is acknowledged to ldk-node. That is the delivery consumers of ldk-node's own queue already get: it is reloaded at build time and an event stays at its front until event_handled; the new doc on EventQueue::new says so.

Seen in the field: after restarting a wallet whose consumer had stalled (#115), the only event that came back was the one ldk-node replayed from its own queue; nothing from this queue did.

Tests: unhandled_events_survive_a_restart (fails on master: the reloaded queue is empty), an_undecodable_stored_queue_fails_the_build and an_unreadable_store_fails_the_build.

Checked: cargo fmt --check, the clippy line from ci/check-lint.sh, RUSTDOCFLAGS=-D warnings cargo doc --no-deps, cargo test -p orange-sdk --lib, cargo check --features _test-utils --tests. The _test-utils integration suite needs bitcoind/electrs and was not run here.

Touches the same file as #115 and conflicts with it textually (the constructor's return, the test module, the file tail); neither depends on the other, so whichever lands second gets rebased. Until this lands we carry it on the same fork pin as #115.

`EventQueue::new` always began with an empty `VecDeque`, while every push
and every `event_handled` persisted the queue under `orange_events`. The
key was written and never read, so events still unhandled when the process
exited were lost on the next run. ldk-node reads its own queue back at
build time (`io::utils::read_event_queue`); mirror that: `new` reads the
key, starts empty on `NotFound`, and fails the build on any other read
error or on a queue that does not decode, as ldk-node does.

The restart test fails on the previous code (the reloaded queue is empty).

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.

1 participant