nodeengineclient: a composition names the digests of the templates archives it was rendered from (A-481, A-481a)

Builds: design 47 G A-481, A-481a
This commit is contained in:
2026-11-17 23:42:11 +01:00
parent ba11b5e9e3
commit 36e78f5ff0
5 changed files with 30 additions and 4 deletions
+15 -3
View File
@@ -49,6 +49,9 @@ type Composition struct {
Own seat.NodeOwn
Plan json.RawMessage
Refused string
// Templates are the digests ("sha256:<hex>"), sorted, of the templates archives the module's files were rendered from
// (design 47 G A-481, A-481a); part of the digest as the resources are.
Templates []string
}
type adoptionWire struct {
@@ -139,6 +142,7 @@ type composedWire struct {
Own *ownWire `json:"own,omitempty"`
Plan json.RawMessage `json:"plan,omitempty"`
Refused string `json:"refused,omitempty"`
Templates []string `json:"templates,omitempty"`
// Signature is read and dropped: a composition is unsigned (ADR 0593 §6), and a value the ended controller signed
// still decodes. Nothing writes it.
Signature json.RawMessage `json:"signature,omitempty"`
@@ -183,9 +187,17 @@ func (c Composition) check() error {
return fmt.Errorf("node-engine: the composition of %s carries the node's own parts, which only <node>.node carries", c.Module)
}
}
if c.Refused != "" && (len(c.Resources) > 0 || len(c.Filled) > 0 || c.Data || len(c.Plan) > 0) {
if c.Refused != "" && (len(c.Resources) > 0 || len(c.Filled) > 0 || c.Data || len(c.Plan) > 0 || len(c.Templates) > 0) {
return fmt.Errorf("node-engine: the composition of %s on %s is refused and holds resources, filled files, data or a plan", c.Module, c.Node)
}
for i, d := range c.Templates {
if hex, ok := strings.CutPrefix(d, "sha256:"); !ok || !keys.IsHex64(hex) {
return fmt.Errorf("node-engine: the templates digest %q of %s is not sha256: and 64 lowercase hex digits", d, c.Module)
}
if i > 0 && c.Templates[i-1] >= d {
return fmt.Errorf("node-engine: the templates digests of %s are not sorted and distinct", c.Module)
}
}
seen := map[string]bool{}
files := map[string][]*declaration.File{}
for _, raw := range c.Resources {
@@ -245,7 +257,7 @@ func (c Composition) wire() (composedWire, error) {
return composedWire{}, err
}
w := composedWire{V: keys.Version, Node: c.Node, Module: c.Module, FP: c.FP, Data: c.Data, Filled: c.Filled,
Refused: c.Refused, Resources: make([]json.RawMessage, len(c.Resources))}
Refused: c.Refused, Templates: c.Templates, Resources: make([]json.RawMessage, len(c.Resources))}
for i, r := range c.Resources {
canon, err := canonicalJSON(r)
if err != nil {
@@ -290,7 +302,7 @@ func DecodeComposition(data []byte) (Composition, error) {
return Composition{}, fmt.Errorf("node-engine: a composition does not fit its shape: %w", err)
}
c := Composition{V: w.V, Node: w.Node, Module: w.Module, FP: w.FP, Data: w.Data, Resources: w.Resources,
Filled: w.Filled, Plan: w.Plan, Refused: w.Refused}
Filled: w.Filled, Plan: w.Plan, Refused: w.Refused, Templates: w.Templates}
if w.Own != nil {
c.Own = ownFromWire(*w.Own)
}