package hostexec import ( "context" "errors" "os" "github.com/carlosframework/platform/internal/rootparticipation" ) func (b *RootBroker) servingView(ctx context.Context, peer ControllerProcess, q ExecutionRequest, authority ExecutionAuthority) (ExecutionResponse, error) { if authority.Kind != "serving" || (authority.Installation == "" && !authority.ParticipationOnly) { return ExecutionResponse{}, ErrInactive } unlock, err := b.cfg.State.Lock(ctx, "transaction.lock") if err != nil { return ExecutionResponse{}, err } defer unlock() if _, err := b.cfg.State.Read("update.json"); !errors.Is(err, os.ErrNotExist) { return ExecutionResponse{}, ErrInactive } census, err := (rootparticipation.Ledger{State: b.cfg.State, Box: authority.Box, Enrollment: authority.Enrollment}).Census() if err != nil || census.Migration != authority.Migration { return ExecutionResponse{}, errors.Join(err, ErrState) } if _, err := ReadRoot(ctx, b.cfg.State, b.cfg.Clock, q, true); err != nil { return ExecutionResponse{}, err } fresh, err := b.cfg.Authority(ctx, q, peer) if err != nil || fresh != authority { return ExecutionResponse{}, errors.Join(err, ErrLost) } if err := b.cfg.Alive(ctx, peer); err != nil { return ExecutionResponse{}, err } b.mu.Lock() defer b.mu.Unlock() if b.closed || ctx.Err() != nil { return ExecutionResponse{}, ErrLost } return ExecutionResponse{Schema: 1, Host: q.Host, Incarnation: q.Incarnation, Stamp: q.Stamp, Session: q.Session, Op: q.Op, BootID: peer.KernelBootID, Status: "serving"}, nil }