Write each node's declaration at the Version its engine reads
The composer is the node-engine's own build, so a newer composer could hand an older engine a field its strict decode refuses. The engine's record now states the declaration Version it reads, and the composer writes node X's declaration at the lower of its own Version and X's (1 when X states none), leaving out what that Version lacks: an engine reading 1 gets no drain-bound and runs on its own default. Builds: design 47 H2 §813 (12); H-A-416 (2), H-A-419; mesh-contracts feat/47-H2 e6ed560e (the record's declaration-reads)
This commit is contained in:
@@ -213,9 +213,11 @@ func compositions(in Input, node string, fps map[string]string, mode Mode, appli
|
||||
}
|
||||
// What the tool runner's process runs as, whose slice of each held module the composed process keeps (H-A-306).
|
||||
var runsRuntime map[string]string
|
||||
reads := 0
|
||||
for i := range reading.Nodes {
|
||||
if reading.Nodes[i].Name == node {
|
||||
runsRuntime = reading.Nodes[i].RunsRuntime
|
||||
reads = reading.Nodes[i].DeclarationReads
|
||||
}
|
||||
}
|
||||
var kept []json.RawMessage
|
||||
@@ -223,6 +225,10 @@ func compositions(in Input, node string, fps map[string]string, mode Mode, appli
|
||||
foldedPaths := map[string]bool{}
|
||||
left := map[string]bool{}
|
||||
for _, raw := range envelope.Resources {
|
||||
// Written at the lower of this composer's declaration Version and the one the node's engine reads (H-A-416 (2)).
|
||||
if raw, err = AtDeclarationVersion(raw, reads); err != nil {
|
||||
return nil, nil, nil, nil, err
|
||||
}
|
||||
var head struct {
|
||||
ID string `json:"id"`
|
||||
Module string `json:"module"`
|
||||
@@ -836,3 +842,34 @@ func carry(kept []json.RawMessage, foldedPaths map[string]bool, runs *engcomp.Co
|
||||
}
|
||||
return out, foldedPaths, nil
|
||||
}
|
||||
|
||||
// drainBoundVersion is the declaration Version a process's drain-bound came with (mesh-sdk declaration, H-A-388 (2)).
|
||||
const drainBoundVersion = 2
|
||||
|
||||
// DeclarationVersionFor is the declaration Version a node's declaration is written at: the lower of this composer's
|
||||
// own (declaration.Version) and the one its engine states it reads, 1 when it states none (design 47 H2 §813 (12),
|
||||
// H-A-416 (2), H-A-419).
|
||||
func DeclarationVersionFor(reads int) int {
|
||||
if reads < 1 {
|
||||
reads = 1
|
||||
}
|
||||
return min(reads, declaration.Version)
|
||||
}
|
||||
|
||||
// AtDeclarationVersion is a resource as a node whose engine reads Version reads (DeclarationVersionFor): the fields that
|
||||
// Version lacks left out, so an older engine never meets a field it refuses; a process's drain-bound then takes the
|
||||
// engine's own default (H-A-416 (2)).
|
||||
func AtDeclarationVersion(raw json.RawMessage, reads int) (json.RawMessage, error) {
|
||||
if DeclarationVersionFor(reads) >= drainBoundVersion {
|
||||
return raw, nil
|
||||
}
|
||||
var fields map[string]json.RawMessage
|
||||
if err := json.Unmarshal(raw, &fields); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if _, has := fields["drain-bound"]; !has {
|
||||
return raw, nil
|
||||
}
|
||||
delete(fields, "drain-bound")
|
||||
return json.Marshal(fields)
|
||||
}
|
||||
|
||||
@@ -241,6 +241,21 @@ func TestCompositionsAreTheDeclarationSplitByModule(t *testing.T) {
|
||||
env[catalogue.RuntimeToolModules], env[catalogue.RuntimeToolEnv], wantServed, words)
|
||||
}
|
||||
}
|
||||
// Design 47 H2 §813 (12), H-A-416 (2), H-A-419: a node's declaration is written at the lower of the composer's Version
|
||||
// and the one its engine states it reads: one stating 1, or none, gets Version 1 and no drain-bound; one stating 2
|
||||
// gets Version 2 with it.
|
||||
t.Run("a declaration is written at the Version the node's engine reads", func(t *testing.T) {
|
||||
process := json.RawMessage(`{"id":"node-tools.runtime","type":"process","drain-bound":30}`)
|
||||
for _, row := range []struct {
|
||||
reads, version int
|
||||
drain bool
|
||||
}{{0, 1, false}, {1, 1, false}, {2, 2, true}, {3, 2, true}} {
|
||||
got, err := AtDeclarationVersion(process, row.reads)
|
||||
if err != nil || DeclarationVersionFor(row.reads) != row.version || strings.Contains(string(got), "drain-bound") != row.drain {
|
||||
t.Errorf("an engine reading %d: Version %d, %s (%v)", row.reads, DeclarationVersionFor(row.reads), got, err)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// lead-47 2026-11-16: a held tool runner keeps the program it runs (Carried, runningProgram) after what the runtime serves
|
||||
|
||||
@@ -1260,6 +1260,7 @@ func nodeOf(rec nodeengine.NodeRecord, p meshmoduleassigner.Assignments) compose
|
||||
SealingKey: rec.SealingKey,
|
||||
OutwardLinks: rec.OutwardLinks, Networks: attachedOf(rec.Networks), NetworksSaid: rec.NetworksSaid,
|
||||
ServingKey: rec.ServingKey, Certificate: rec.Certificate, Contract: int(rec.Contract), Stated: rec.Contract > 0,
|
||||
DeclarationReads: int(rec.DeclarationReads),
|
||||
}
|
||||
placeNode(&n, p)
|
||||
if len(rec.Capabilities) > 0 {
|
||||
|
||||
@@ -247,6 +247,9 @@ type Node struct {
|
||||
// Contract is the contract of its node-engine's newest statement (inv.HealthOf); Stated is whether it ever stated one.
|
||||
Contract int
|
||||
Stated bool
|
||||
// DeclarationReads is the declaration Version its node-engine states it reads (nodeengine.NodeRecord.DeclarationReads,
|
||||
// design 47 H2 §813 (12), H-A-416 (2), H-A-419); 0 when it states none, read as 1.
|
||||
DeclarationReads int
|
||||
// InOwn is the modules it runs inside its own composition (`<node>.node`), not by a composition of their own, since
|
||||
// no fingerprint of the new form names them where it runs them (novox/hq issue 1126): Compositions folds their
|
||||
// resources into the node's own, as the controller's composed writer does, unless fps gives one of the new form.
|
||||
|
||||
@@ -19,6 +19,7 @@ import (
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/busretry"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"git.novox.be/novox/mesh-sdk/go/declaration"
|
||||
"github.com/nats-io/nats.go"
|
||||
)
|
||||
|
||||
@@ -372,7 +373,8 @@ func testTheNodeKeyCarriesTheNodesFacts(t *testing.T) {
|
||||
Certificate: "cert", Trusts: keys.Trusts, Capabilities: []string{"apt", "bus-state-calls", "ledger-calls", "systemd"}, OutwardLinks: []string{"eth0"}, NetworksSaid: true,
|
||||
Networks: []nodeengine.AttachedNetwork{{Link: "eth0", Network: "192.0.2.0/24"}}, Contract: NodeKeyContract,
|
||||
ManifestReads: statedReads(), // what it reads of a manifest: its contract's (ADR 0614 §4) and that it reads a want by version (H §772)
|
||||
RunnerCapabilities: []string{"bus-state-calls", "ledger-calls"}, RunnerFingerprint: "sha256:runner"}
|
||||
RunnerCapabilities: []string{"bus-state-calls", "ledger-calls"}, RunnerFingerprint: "sha256:runner",
|
||||
DeclarationReads: declaration.Version} // H-A-416 (2), H-A-419: the declaration Version this engine reads
|
||||
if !nodeengineclient.SameNodeRecord(*got.Record, wantRecord) {
|
||||
t.Errorf("record = %+v, want %+v", *got.Record, wantRecord)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"time"
|
||||
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"git.novox.be/novox/mesh-sdk/go/declaration"
|
||||
)
|
||||
|
||||
// The node's record (novox/hq ADR 0555 §3, issue 1126): what the machine observes of itself, written in its own have key
|
||||
@@ -154,5 +155,7 @@ func recordOf(node string, r Report, keys RecordKeys) *nodeengine.NodeRecord {
|
||||
if r.Health != nil {
|
||||
rec.Contract = int64(r.Health.Contract)
|
||||
}
|
||||
// The declaration Version this engine reads, by which a composer writes this node's declaration (H-A-416 (2), H-A-419).
|
||||
rec.DeclarationReads = declaration.Version
|
||||
return rec
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user