Skip to content

Workers

The gateway uses background tasks so admission does not need to hold an HTTP request open while witnesses are contacted. Work is represented in SQLite and can be reclaimed after a process restart or an expired lease.

Attestation reconciler

The reconciler repeatedly asks storage for one due pending or retryable job. A claim contains an opaque random 32-byte lease token, an expiry, and the saved receipt record. The default lease is 30 seconds; witness requests default to a 10-second timeout and the idle loop sleeps for one second.

pending/retryable
        |
        | claim if due and lease absent/expired
        v
 +----------------+
 | leased attempt |
 +-------+--------+
         |
   +-----+----------------------+
   |                            |
 threshold reached       timeout / too few signatures
   |                            |
   v                            v
 final verify              retryable + backoff
   |                            |
   v                            +----> later claim
 confirmed

The worker fans out to witnesses in parallel. It stops collecting once the threshold is reached and cancels outstanding requests. Every accepted response must match the expected witness ID, be unique, and verify under the configured public key. The final Ed25519 multisignature is verified again before completion.

Completion checks the lease token, expiry, hash, timestamp, network ID, and sequence. A stale worker therefore cannot replace a result completed by a later worker. Signature rows are replaced atomically with the verified result.

Transient failures to collect enough signatures use exponential retry scheduling capped at 300 seconds. Configuration invariant failures, such as an invalid key or duplicate configured signer key, are terminal failures rather than endless retries.

The reservation timestamp is immutable: retries sign the tuple captured when the job was reserved; they do not refresh its timestamp. The required WITNESS_JOB_SIGNING_WINDOW_SECS defines the exclusive deadline. Once it is reached, storage marks the job failed with the stable signing_deadline_exceeded error rather than creating a new timestamp. That failed job remains the saved job for its hash: a duplicate submission returns the same failed job and cannot create a replacement tuple.

WITNESS_ATTESTATION_WORKERS runs a bounded pool (default four, maximum 64), while WITNESS_MAX_ACTIVE_JOBS bounds new pending/retryable reservations (default 1000). Duplicate hashes continue to return their existing tuple.

On gateway shutdown, active signing attempts are cancelled rather than drained. Their leases expire normally, allowing a surviving or restarted worker to reclaim the jobs.

Batch manager

The batch manager periodically selects confirmed, unbatched attestations in deterministic (sequence, hash) order. It does not use a timestamp watermark, so a job that confirms after a long retry remains eligible. It stores the batch and its Merkle membership transactionally.

The batch manager runs every WITNESS_BATCH_PERIOD_SECS seconds (default 60; 0 disables it), and runs once immediately at startup. Each tick closes a batch if there are eligible attestations, then makes sure the latest signed checkpoint covers the whole log. If the log has grown past the latest checkpoint, or none exists, the gateway signs a new note. It calls each signer's POST /add-checkpoint with that note and a consistency proof from the last checkpoint size the gateway knows; if the signer reports a different last-signed size (HTTP 409), the gateway rebuilds the proof from that size and retries once. Signers refuse (HTTP 422) any checkpoint that does not extend the one they last signed. The gateway verifies returned signatures and publishes only if enough signers signed. It includes valid external witness signatures it received. See C2SP checkpoints. If signing fails, the batch remains stored and the next tick retries, even when no new attestations arrive.