Skip to main content
The Ark server can sweep a VTXO after its 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).
How the daemon starts depends on the surface:
  • Bark SDK: The library starts the daemon when your app opens the wallet (runDaemon in the open arguments, run_daemon in Rust, on by default). In Go, set RunDaemon: true explicitly, since an unset bool field is false. 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: barkd starts the daemon and runs it for as long as the process lives. Run barkd under 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 bark commands. 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. Run bark 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.
Diagram comparing one maintenance pass a day with a pass every 6 hours over the last 144 blocks before Alice's VTXO expiresDiagram comparing one maintenance pass a day with a pass every 6 hours over the last 144 blocks before Alice's VTXO expires

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

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):
On mainnet, set the threshold below half the Ark server’s VTXO lifetime, or Bark refuses to connect to that server. For a single run, 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’s pendingRoundStates() show each one with its state.
  • 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:
  • Next required refresh: getNextRequiredRefreshBlockheight (get_next_required_refresh_blockheight in Rust) returns the height at which the next refresh becomes required, the first expiry minus the threshold.
  • First expiry: getFirstExpiringVtxoBlockheight (get_first_expiring_vtxo_blockheight in Rust) returns that first expiry itself.
  • With a round pending: Also take the lowest expiryHeight among the VTXOs that pendingRoundInputVtxos() returns (background refresh covers the call).
  • Pushed events: notifications().nextNotification() (Wallet::subscribe_notifications() in Rust) streams movement events as they happen. Reread history() when a ChannelLagging event arrives. Read the two heights above on your own schedule, for example each time the app comes to the foreground.
Expired VTXOs covers how to turn these heights into user-facing state.

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_height passes. Expired VTXOs covers what happens after that.
  • Two versions, two paths: In the installed version (Umbrel, Start9, or self-hosted), a barkd daemon 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 barkd daemon applies its own vtxo_refresh_expiry_threshold to 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.