42 lines
1.6 KiB
Go
42 lines
1.6 KiB
Go
package main
|
|
|
|
// The controller's lease as the vault reads it (novox/hq ADR 0561 §3): handed away only to a holder that is no
|
|
// controller, and not for a controller's value, a key deleted or expired, or one that cannot be read. It turns retirement
|
|
// (retire.go) and rotation (rotation.go), never minting: the vault mints every wanted account it holds no value for,
|
|
// whoever holds the lease (mint.go, issue 774). No clock and no setting turns it. A key's age passing is heard by no
|
|
// watch, so the lease is read afresh before a retirement or a rotation (LeaseRead).
|
|
|
|
import "git.novox.be/novox/mesh-sdk/go/buscompose"
|
|
|
|
// LeaseHeard is the watch of the controller's lease: it records whether it is handed away, and says when that turned.
|
|
func (v *Vault) LeaseHeard(raw []byte, found bool, readErr error) {
|
|
if !v.setLease(raw, found, readErr) {
|
|
return
|
|
}
|
|
on, why := v.leaseHanded()
|
|
v.log("the controller's lease is %s: %s", map[bool]string{true: "HANDED AWAY", false: "not handed away"}[on], why)
|
|
}
|
|
|
|
// setLease records what the lease says, and answers whether minting turned on or off by it.
|
|
func (v *Vault) setLease(raw []byte, found bool, readErr error) bool {
|
|
on, why := buscompose.LeaseHandedAway(raw, found, readErr)
|
|
m := &v.minting
|
|
m.mu.Lock()
|
|
defer m.mu.Unlock()
|
|
flipped := on != m.on || m.why == ""
|
|
if flipped {
|
|
m.since = v.Now().UTC()
|
|
}
|
|
m.on, m.why = on, why
|
|
return flipped
|
|
}
|
|
|
|
// leaseAfresh reads the lease again before a retirement or a rotation, where the vault can: a key that expired since is heard by no watch.
|
|
func (v *Vault) leaseAfresh() {
|
|
if v.LeaseRead == nil {
|
|
return
|
|
}
|
|
raw, found, err := v.LeaseRead()
|
|
v.setLease(raw, found, err)
|
|
}
|