expiry_height (VTXO lifetime explains the mechanics). Users should never have to think about the deadline.
Let the background daemon run maintenance
Bark’s background daemon runs wallet maintenance with no call from your wallet app. While it runs, it:- Syncs the on-chain wallet and every pending board, payment, and round. A sync runs every 60 seconds by default (
daemon_sync_interval_secs) and on every new block. - Joins the next round whenever a VTXO is due for a refresh, then completes the refresh once the round transaction confirms.
- Scans for forced exits on every sync pass and progresses emergency exits (forced exits covers the response).
- Bark SDK: The library starts the daemon when your app opens the wallet (
runDaemonin the open arguments,run_daemonin Rust, on by default). In Go, setRunDaemon: trueexplicitly, since an unsetboolfield isfalse. The daemon runs for as long as your app holds the open wallet. In a browser, that is for as long as the tab stays open. - Barkd:
barkdstarts the daemon and runs it for as long as the process lives. Runbarkdunder a service manager, such as systemd, so it starts again after a crash or a reboot. - iOS and Android: iOS and Android suspend your app in the background. Use delegated refreshes, which the Ark server carries through the round without your app online. Run
maintenanceDelegated()on background wakes and foreground opens (background refresh covers the setup). - Bark CLI: No daemon runs between
barkcommands. For a wallet that maintains itself, run Barkd. To stay on the CLI, schedule the maintenance pass.
The background daemon stops when your process doesNeither Barkd nor an SDK app can run maintenance while its process is stopped. A reboot without a service manager, a suspended mobile app, or a closed browser tab all pause maintenance until the process starts again.
Run maintenance at least daily
Without a daemon, your wallet app runs the maintenance pass itself. Runbark maintain on the CLI. In an SDK app that opens the wallet with runDaemon: false, call maintenance() (Wallet::maintenance() in Rust). A pass syncs the wallet, progresses pending rounds, and refreshes the VTXOs that are due.
A maintenance pass refreshes any VTXO within vtxo_refresh_expiry_threshold blocks of its expiry, 144 blocks (about 24 hours) by default on mainnet. A daily pass is therefore the floor, not a guarantee. A VTXO that enters the window just after one pass reaches its expiry around the next one. Its refresh then still waits for a round. Running every 6 or 12 hours leaves margin for downtime, missed passes, and fast block stretches.
With one pass a day, a VTXO that enters the refresh window just after a pass is reached by the next pass only at its expiry, while a pass every 6 hours reaches it with 108 blocks left
- Bark SDK
- Bark CLI
With
runDaemon: false, run maintenance() when the app starts or comes to the foreground, and every 6 to 12 hours. On iOS and Android, run maintenanceDelegated() instead (background refresh covers the pass). While hasPendingExits() returns true, run progressExits() every few minutes (exit handling covers what that needs).Tune the refresh policy
How early to refresh is a policy your app exposes to users, not a protocol constant. Refreshing early improves security sooner and raises operating costs. Refreshing late saves fees. Ark payments explains the trade-off. Liquidity explains what each refresh costs. One setting sets the window:vtxo_refresh_expiry_threshold in config.toml for the CLI and Barkd (configuration reference), or the same field in the SDK’s Config (vtxoRefreshExpiryThreshold in TypeScript):
bark refresh --threshold-blocks <n> or --threshold-hours <n> overrides the window. Refresh options lists the other selections. A maintenance refresh can include more VTXOs than the one that triggered it and charge a fee (show refresh fees covers what to display).
Stay online through round participation
Refreshes settle in rounds, which are interactive. Bark submits the inputs and co-signs the new transaction tree while the round runs. It signs the forfeits once the round transaction confirms. Keep the process alive from submission until the round ends. Have it running again after the round transaction confirms and before the old VTXOs expire.- An interrupted participation starts over: Bark drops an interactive participation that stalls. It refreshes the same VTXOs in a later round.
- Pending participations are listable:
bark round list,GET /api/v1/wallet/rounds, and the SDK’spendingRoundStates()show each one with itsstate. - Mobile suspends apps mid-round: Submit a delegated refresh so the round completes without your app staying online. An interactive refresh first waits for the next round to start, up to an hour on Second’s Ark server. Background refresh covers the mobile setup.
Expose the next refresh deadline
Expose the deadline instead of guessing at it:- Bark SDK
- Bark CLI
- Barkd
- Next required refresh:
getNextRequiredRefreshBlockheight(get_next_required_refresh_blockheightin Rust) returns the height at which the next refresh becomes required, the first expiry minus the threshold. - First expiry:
getFirstExpiringVtxoBlockheight(get_first_expiring_vtxo_blockheightin Rust) returns that first expiry itself. - With a round pending: Also take the lowest
expiryHeightamong the VTXOs thatpendingRoundInputVtxos()returns (background refresh covers the call). - Pushed events:
notifications().nextNotification()(Wallet::subscribe_notifications()in Rust) streams movement events as they happen. Rereadhistory()when aChannelLaggingevent arrives. Read the two heights above on your own schedule, for example each time the app comes to the foreground.
Plan around platform limits
- Background execution is best effort: Mobile operating systems throttle background work. No scheduler API guarantees that your pass runs at the requested time. Run the pass on foreground opens as well. Give users who stop getting wakes a way back. Background refresh covers how to wake a mobile app and catch devices that stop waking.
- A browser wallet app runs only while its tab is open: The daemon resumes maintenance when the user opens the app. Warn users who return after a long absence to keep the tab open until the refresh completes.
- A missed refresh still leaves room: Expiry is the deadline, not your schedule. A VTXO that missed a refresh window remains yours to refresh until its
expiry_heightpasses. Expired VTXOs covers what happens after that.
How Bark Wallet does it
How Bark Wallet does it
- Two versions, two paths: In the installed version (Umbrel, Start9, or self-hosted), a
barkddaemon runs alongside the app. It refreshes VTXOs and progresses exits whether or not a browser tab is open. In the web version (WASM), the wallet runs in the browser. The app submits its own refreshes as delegated participations. A worker loop that syncs every 20 seconds while a tab is open completes them, on the next open if the tab closed first. - The policy as two settings: Bark Wallet turns the policy into two settings, Auto-refresh threshold and Refresh on receive. While the dashboard is open, it refreshes every spendable VTXO inside the chosen threshold that is not already in a round, at most once a minute for the same set. In the installed version the
barkddaemon applies its ownvtxo_refresh_expiry_thresholdto its background refreshes. - Options priced by the server: The threshold options come from the server’s refresh fee table, each labeled with its time and price and capped at half the VTXO lifetime. Until the user selects one, the app uses the first option, “1 day before expiry · free” on Second’s Ark server.
- The deadline shown as a round: The dashboard shows a “Next round” countdown computed from the server’s round schedule. The user cannot select a VTXO already committed to a round in the VTXOs table. In the web version, “Refresh all” leaves it out. “Refresh all” is disabled only while its own request runs or when no other VTXO is left to refresh.