Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

139 changes: 112 additions & 27 deletions docs/src/reference/signer-state.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ channel, which destinations the on-chain wallet may send to, and which
invoices and preimages it has seen. This knowledge is the _signer
state_.

Greenlight signers are stateless by design. They do not own durable
storage for the signer state, which is what allows a signer to run on
a phone, in a short-lived process, or on several devices at once.
Instead, the Greenlight node stores the signer state and attaches it to
every request it sends to the signer.
Greenlight signers do not keep a durable copy of the full signer state,
which is what allows a signer to run on a phone, in a short-lived process,
or on several devices at once. Instead, the Greenlight node stores the
signer state and attaches it to every request it sends to the signer.
A signer can keep a small amount of metadata in device-local storage,
independently of the node.

This creates a tension with the [security model](security.md): the
signer protects funds against an attacker with access to the node
Expand All @@ -27,11 +28,15 @@ The signer state is a key-value map. Every entry consists of:

| Field | Description |
|-------|-------------|
| `key` | The entry name, prefixed by its class: `nodes/`, `nodestates/`, `channels/`, `allowlists/`, `trackers/`, `peers/` |
| `key` | The entry name, prefixed by its class: `nodes/`, `nodestates/`, `channels/`, `allowlists/`, `trackers/` |
| `version` | A counter that increases with every change to this key |
| `value` | The serialized VLS object |
| `signature` | The signer's signature over the key, version and value |

The node also sends `peers/` entries as address hints for channel backup
recovery. These are untrusted metadata. The signer keeps valid hints for
backups and excludes them from state signatures.

Deleting a key leaves a _tombstone_ behind: the entry is kept with the
highest possible version and an empty value, so that an older value of
the key cannot be merged back in.
Expand All @@ -45,16 +50,22 @@ exchanging only what changed:
carries a full snapshot of the state.
2. Every following request carries only the entries that changed
since the node last sent state to that signer.
3. The signer merges incoming entries into its in-memory copy. New
keys are added, higher versions replace lower ones, lower versions
are ignored.
4. The signer processes the request and returns the entries it
changed, signed.
3. The signer merges incoming entries into a scratch copy of its state.
New keys are added, higher versions replace lower ones, lower
versions are ignored.
4. The signer authorizes and processes the request against that copy.
Only after processing and state signing succeed does it commit the
copy and return the signed changes. A rejected request leaves the
live state unchanged, including changes made while processing it.
5. The node merges and persists the returned entries _before_ it
hands the signer's response on. If the entries cannot be stored,
the response is dropped, so the node never acts on a signature whose
state was lost.

Builds with the `permissive` feature report authorization failures but
continue processing them. Requests that return an error still leave the
live state unchanged.

The node pipelines requests, so several can be in flight at once, each
carrying the state as it was when the request was sent. The signer
handles them one after the other, and its in-memory state is always at
Expand Down Expand Up @@ -96,18 +107,12 @@ _state signature mode_:
| Mode | Missing signature | Invalid signature | Intended use |
|------|-------------------|-------------------|--------------|
| `off` | Accepted | Accepted | Development and tests only |
| `soft` | Accepted, and signed on the way out | Refused | Migrating nodes whose state predates state signatures |
| `hard` | Refused | Refused | Production, once all state is signed |
| `soft` | Accepted for one successfully processed snapshot, and signed on the way out | Refused | One-time migration of nodes whose state predates state signatures |
| `hard` | Refused | Refused | Production (default) |

`soft` is the current default. In `soft` mode a signer signs unsigned
entries it receives, which gradually migrates nodes created before
state signing existed. Only `hard` mode guarantees that every entry the
signer acts on was written by a signer of this node.

!!! note "Planned default"
The default will move from `soft` to `hard` once the fleet's state
is fully signed. Applications embedding the signer should plan for
running in `hard` mode.
`hard` is the default. A signer never automatically falls back to
`soft` when it encounters unsigned state. Only `hard` mode guarantees
that every entry the signer acts on was written by a signer of this node.

The mode is part of the signer configuration:

Expand All @@ -133,6 +138,86 @@ The mode is part of the signer configuration:
glcli signer run --state-signature-mode hard
```

#### One-time migration

An application can explicitly select `soft` to migrate a legacy node.
One successfully processed state snapshot can run in Soft mode. Missing
signatures in that snapshot are accepted and repaired; invalid signatures
are refused. After a successful migration, all subsequent requests use Hard, including after
reconnecting. Clones of the signer share this transition.

Soft mode requires a persistent `DeviceStorage` supplied through
`SignerConfig::device_storage`. The signer saves a migration marker,
scoped by node ID and network, after processing and signing succeed but
**before** committing state or returning signatures. If that marker is
already present, requesting Soft starts the
signer in Hard with a warning. Applications can keep the same configuration
across restarts without reopening the migration. A successfully processed
empty snapshot also consumes the allowance.

`DeviceStorage` provides fallible `load` and `save` operations over opaque
bytes; writes must replace values atomically and durably. Each purpose has
its own key and encoding.
Storage errors prevent the migration from publishing state or signatures.
If writing the marker fails, the current signer switches to Hard because
the failed write may still have persisted the marker.

The optional `file-storage` feature provides `FileDeviceStorage` for Rust.
Python and gl-sdk accept a persistent directory in the application's data
directory; `glcli` uses `<data-dir>/device-state`.

=== "glcli"

```bash
glcli signer run --state-signature-mode soft
```

=== "Python"

```python
signer = glclient.Signer(
seed, network, creds,
state_signature_mode="soft",
device_storage_path="/path/to/app/device-state",
)
```

=== "gl-sdk (Python)"

```python
migration = glsdk.SignerConfig(
state_signature_mode=glsdk.StateSignatureMode.SOFT,
device_storage_path="/path/to/app/device-state",
)
config = glsdk.Config().with_signer_config(migration)
node = glsdk.NodeBuilder(config).connect(credentials, mnemonic)
```

Standalone signers use `Signer.new_with_config(mnemonic, migration)`
or `Signer.new_from_seed_with_config(seed, migration)`. Authenticating
a signer preserves its migration configuration and storage.

After a successful migration, reusing the Soft configuration logs a
warning and uses Hard mode. The Rust, Python and SDK constructors use
Hard by default; Hard does not require a device store.

The migration deliberately trusts the unsigned snapshot it migrates. If the
process crashes or the connection drops after saving the marker but
before the node persists the repaired state, the allowance stays
consumed. Restarting with Soft uses Hard; it does not retry the migration.
Contact Greenlight support for explicit recovery if the node still has
unsigned state.
Deleting device storage or restoring an older copy can reset this local
guard. That limitation is accepted for now.

!!! note "Multi-device limitation"
The current solution does not coordinate migration across devices.
Each device has its own marker, so consuming the Soft allowance on one
device does not prevent another device from running Soft for the same
node. We plan to address this with an external watermarking service
that is not controlled by Blockstream. That service is outside the
scope of the current implementation.

#### Operator-assisted override

For manual recovery, a signer can be started with an override that
Expand Down Expand Up @@ -198,14 +283,14 @@ persistent storage, not secret storage.

#### Storing the anchor

`gl-client` itself does not access the filesystem, so that the signer
can also run in environments without one, such as a hardware security
module. It defines a storage interface for the anchor instead, and the
higher-level libraries provide implementations:
The core signer operates through a storage interface, so it can also run
in environments without a filesystem, such as a hardware security module.
The optional `file-storage` feature supplies a file backend shared by the
higher-level libraries:

| Library | Anchor storage |
|---------|----------------|
| `gl-client` (Rust) | Storage interface only; bring your own implementation |
| `gl-client` (Rust) | Storage interface, with an optional file backend |
| `gl-sdk` | File-backed, configured with a path in the application's data directory |
| `gl-client-py`, `glcli` | File-backed, configured with a path |
| `gl-testing` | In memory |
Expand Down
1 change: 1 addition & 0 deletions libs/gl-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

### Changed

- `signer run` defaults to `hard` state signature mode. Explicit `soft` mode allows one successful migration per device and node, then uses Hard on subsequent requests and restarts.
- `fundchannel` now creates private channels by default

## [0.1.2] - 2026-01-16
Expand Down
2 changes: 1 addition & 1 deletion libs/gl-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ clap = { version = "4.5", features = ["derive"] }
dirs = "6.0"
env_logger = "0.11"
futures = "0.3"
gl-client = { version = "0.7", path = "../gl-client", features = ["backup"] }
gl-client = { version = "0.7", path = "../gl-client", features = ["backup", "file-storage"] }
hex = "0.4"
serde = { version = "1", features = ["derive"] }
serde_json = "1"
Expand Down
26 changes: 19 additions & 7 deletions libs/gl-cli/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ use crate::util;
use clap::{Subcommand, ValueEnum};
use core::fmt::Debug;
use gl_client::signer::{
CLNBackup, CLNBackupOptions, FeeBudgetLimits, RecoverableChannel, Signer, SignerBackupConfig,
SignerBackupSnapshot, SignerBackupStrategy, SignerConfig, StateSignatureMode,
StateSignatureOverrideConfig,
CLNBackup, CLNBackupOptions, DeviceStorage, FeeBudgetLimits, FileDeviceStorage, RecoverableChannel,
Signer, SignerBackupConfig, SignerBackupSnapshot, SignerBackupStrategy, SignerConfig,
StateSignatureMode, StateSignatureOverrideConfig,
};
use lightning_signer::bitcoin::Network;
use serde::Serialize;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use tokio::{join, signal};
use util::{CREDENTIALS_FILE_NAME, SEED_FILE_NAME};

Expand All @@ -28,7 +29,7 @@ pub enum StateSignatureModeArg {

impl Default for StateSignatureModeArg {
fn default() -> Self {
Self::Soft
Self::Hard
}
}

Expand Down Expand Up @@ -75,7 +76,8 @@ impl Default for BackupConvertFormat {
pub enum Command {
/// Starts a signer that connects to greenlight
Run {
#[arg(long, value_enum, default_value_t = StateSignatureModeArg::Soft)]
/// Signature checks; soft migrates one state snapshot per device.
#[arg(long, value_enum, default_value_t = StateSignatureModeArg::Hard)]
state_signature_mode: StateSignatureModeArg,
#[arg(long = "state-override")]
state_override: Option<String>,
Expand Down Expand Up @@ -385,6 +387,15 @@ async fn run_handler<P: AsRef<Path>>(
}
});
let backup = backup_config_from_args(backup_path, backup_strategy, backup_periodic_updates)?;
let device_storage: Option<Arc<dyn DeviceStorage>> = match state_signature_mode {
StateSignatureModeArg::Soft => Some(Arc::new(
FileDeviceStorage::new(
config.data_dir.as_ref().join("device-state"),
)
.map_err(|e| Error::custom(format!("Failed to open device state storage: {e:#}")))?,
)),
_ => None,
};

let signer = Signer::new_with_config(
seed,
Expand All @@ -393,6 +404,7 @@ async fn run_handler<P: AsRef<Path>>(
SignerConfig {
state_signature_mode: state_signature_mode.into(),
state_signature_override,
device_storage,
backup,
fee_budget_limits,
},
Expand Down Expand Up @@ -497,7 +509,7 @@ mod tests {
}

#[test]
fn run_mode_defaults_to_soft() {
fn run_mode_defaults_to_hard() {
let cli = TestCli::parse_from(["test", "run"]);
match cli.cmd {
Command::Run {
Expand All @@ -509,7 +521,7 @@ mod tests {
backup_periodic_updates,
..
} => {
assert_eq!(state_signature_mode, StateSignatureModeArg::Soft);
assert_eq!(state_signature_mode, StateSignatureModeArg::Hard);
assert!(state_override.is_none());
assert!(state_override_note.is_none());
assert!(backup_path.is_none());
Expand Down
4 changes: 4 additions & 0 deletions libs/gl-client-py/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

### Added

- Optional `state_signature_mode` and `device_storage_path` keyword arguments for `Signer`, allowing explicit one-time Soft migration with persistent storage. Existing constructors continue to use Hard by default.

## [0.4.0] - 2026-10-12

### Changed
Expand Down
1 change: 1 addition & 0 deletions libs/gl-client-py/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ bytes = "1.6"
env_logger = { workspace = true }
gl-client = { path = "../gl-client", default-features = false, features = [
"export",
"file-storage",
] }
hex = "*"
log = "*"
Expand Down
24 changes: 22 additions & 2 deletions libs/gl-client-py/glclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,28 @@ def _convert(cls: Type[E], res: Iterable[Any]) -> E:


class Signer(object):
def __init__(self, secret: bytes, network: str, creds: Credentials):
self.inner = native.Signer(secret, network, creds)
"""Signer using Hard state verification by default.

Explicit Soft mode migrates legacy state once using the persistent
directory supplied by ``device_storage_path``.
"""

def __init__(
self,
secret: bytes,
network: str,
creds: Credentials,
*,
state_signature_mode: str = "hard",
device_storage_path: Optional[str] = None,
):
self.inner = native.Signer(
secret,
network,
creds,
state_signature_mode=state_signature_mode,
device_storage_path=device_storage_path,
)
self.creds = creds
self.handle: Optional[native.SignerHandle] = None

Expand Down
10 changes: 9 additions & 1 deletion libs/gl-client-py/glclient/glclient.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,15 @@ class SignerHandle:
def shutdown(self) -> None: ...

class Signer:
def __init__(self, secret: bytes, network: str, creds: Credentials): ...
def __init__(
self,
secret: bytes,
network: str,
creds: Credentials,
*,
state_signature_mode: str = "hard",
device_storage_path: Optional[str] = None,
): ...
def sign_challenge(self, challenge: bytes) -> bytes: ...
def run_in_thread(self) -> SignerHandle: ...
def run_in_foreground(self) -> None: ...
Expand Down
Loading
Loading