Skip to main content

write_trust

Function write_trust 

Source
pub fn write_trust(trust: &Value) -> Result<()>
Expand description

Atomic, lock-serialized write of the full trust store (#246).

The background daemon’s pull path pins peers (add_agent_card_pinwrite_trust) while a foreground wire add / accept / promote may write concurrently. The old raw fs::write was non-atomic AND lockless: two writers could interleave bytes into a torn, unparseable trust.json (the same failure class as relay.json Bug #3), breaking trust reads until hand-repaired. flock + tmp+rename, mirroring write_relay_state, so a concurrent reader always sees either the whole old or whole new file.

(Read-modify-write lost updates — two callers each read-then-write — are a separate, deeper concern that needs an update_trust-style locked transaction like update_relay_state; tracked under #246.)