diff --git a/modules/mesh-grants/grants_test.go b/modules/mesh-grants/grants_test.go index 3b09d426..ce7f8560 100644 --- a/modules/mesh-grants/grants_test.go +++ b/modules/mesh-grants/grants_test.go @@ -1817,7 +1817,7 @@ func TestGrants(t *testing.T) { a, err := p.AssertOne("mod-x") am, _ := a.(map[string]any) as, _ := am["assertion"].(grants.Assertion) - if err != nil || as.Asserted || as.Says != grants.ShadowAsserts || len(as.Items) != 3 || am["asked"] == nil { + if err != nil || as.Asserted || as.Says != grants.ShadowAsserts || len(as.Items) != 4 || am["asked"] == nil { t.Fatalf("assert = %+v, %v", a, err) } for _, it := range as.Items { @@ -2162,7 +2162,7 @@ func TestGrants(t *testing.T) { return a } first := p.Compose() - if !slices.Equal(b.creates, []string{"LOG_mod-x_history", "THINGS"}) || len(first.Asserted) != 1 || + if !slices.Equal(b.creates, []string{"LOG_mod-x_history", "OBJ_mod-x_kept-objects", "THINGS"}) || len(first.Asserted) != 1 || !strings.HasPrefix(first.Asserted[0], "mod-x at ") || !slices.Contains(b.events, grants.EventAsserted) { t.Fatalf("the first pass created %v, said %v, events %v", b.creates, first.Asserted, b.events) } @@ -2185,7 +2185,7 @@ func TestGrants(t *testing.T) { } } } - if again := p.Compose(); len(again.Asserted) != 0 || len(b.creates) != 2 { + if again := p.Compose(); len(again.Asserted) != 0 || len(b.creates) != 3 { t.Errorf("a pass with everything held created again: %v, %v", again.Asserted, b.creates) } // THINGS deleted since: not made again at the same manifest, said; a hand assert (the tool, asking the process) @@ -2194,11 +2194,11 @@ func TestGrants(t *testing.T) { b.streams = slices.DeleteFunc(b.streams, func(s map[string]any) bool { return s["name"] == "THINGS" }) b.mu.Unlock() gone := p.Compose() - if len(b.creates) != 2 || !strings.Contains(strings.Join(gone.NotAsserted, " "), "THINGS: created at this manifest and gone since") { + if len(b.creates) != 3 || !strings.Contains(strings.Join(gone.NotAsserted, " "), "THINGS: created at this manifest and gone since") { t.Errorf("a stream gone since was made again by itself, or not said: %v, %v", b.creates, gone.NotAsserted) } tool := partOn(b) - if got, err := tool.AssertOne("mod-x"); err != nil || fmt.Sprint(got) == "" || len(b.creates) != 2 { + if got, err := tool.AssertOne("mod-x"); err != nil || fmt.Sprint(got) == "" || len(b.creates) != 3 { t.Fatalf("the tool = %v, %v, creates %v: it asks, and creates nothing itself", got, err, b.creates) } if hand := p.Compose(); len(hand.Asserted) != 1 || b.creates[len(b.creates)-1] != "THINGS" { diff --git a/modules/mesh-grants/internal/buscompose/busstate.go b/modules/mesh-grants/internal/buscompose/busstate.go index bcd14394..2007988c 100644 --- a/modules/mesh-grants/internal/buscompose/busstate.go +++ b/modules/mesh-grants/internal/buscompose/busstate.go @@ -67,6 +67,10 @@ func BusStateStreams(module string, e catalogue.BusStateEntry) []string { switch e.Storage { case catalogue.StorageKeyValue: out = []string{"KV_" + base} + // And a state's object store beside it, `-objects`, which the bus module makes with it (design 47 G §58). + if e.Template == catalogue.TemplateState { + out = append(out, "OBJ_"+module+"_"+catalogue.StateObjectsName(e.Name)) + } case catalogue.StorageObjectStore: out = []string{"OBJ_" + base} case catalogue.StorageLedger: diff --git a/modules/mesh-grants/internal/buscompose/state_objects_test.go b/modules/mesh-grants/internal/buscompose/state_objects_test.go index 4277f2c7..974fd962 100644 --- a/modules/mesh-grants/internal/buscompose/state_objects_test.go +++ b/modules/mesh-grants/internal/buscompose/state_objects_test.go @@ -1,6 +1,7 @@ package buscompose import ( + "slices" "testing" "git.novox.be/novox/mesh-sdk/go/catalogue" @@ -27,6 +28,22 @@ func TestStateObjectsAndSentStores(t *testing.T) { t.Errorf("another module may publish %s", subject) } } + // The bus module may make the store beside a state asked by the template state: it is among the streams it keeps. + if got := BusStateStreams("shop", catalogue.BusStateEntry{Name: "orders", Storage: catalogue.StorageKeyValue, Template: catalogue.TemplateState}); !slices.Contains(got, "OBJ_shop_orders-objects") { + t.Errorf("the bus module's streams of the state orders = %v, want its object store among them", got) + } + // A state of the field state has its store beside it too, its owner's (A-237: the indexer's and the assigner's inputs), as + // the grants part makes and grants a module's own object buckets. + stated, err := PermissionsFor(Principal{Kind: KindModule, Node: "novox", Module: "mesh-delivery-indexer", State: []string{"inputs"}, + Objects: []string{"mesh-delivery-indexer_inputs-objects"}}) + if err != nil { + t.Fatal(err) + } + for _, subject := range []string{"$JS.API.STREAM.INFO.OBJ_mesh-delivery-indexer_inputs-objects", "$O.mesh-delivery-indexer_inputs-objects.C.x"} { + if !MayPublish(stated, subject) { + t.Errorf("the indexer may not publish %s", subject) + } + } reader, err := PermissionsFor(Principal{Kind: KindModule, Node: "one", Module: "bank", ReadsObjects: []string{"shop_sent-objects"}}) if err != nil { t.Fatal(err) diff --git a/modules/mesh-grants/internal/grants/bindings.go b/modules/mesh-grants/internal/grants/bindings.go index e9256c4f..fd7fb757 100644 --- a/modules/mesh-grants/internal/grants/bindings.go +++ b/modules/mesh-grants/internal/grants/bindings.go @@ -262,6 +262,10 @@ func bindingStreams(b membership.BusBinding) []string { if b.ObjectStore != "" { out = append(out, "OBJ_"+b.ObjectStore) } + // A state's object store beside it (design 47 G §58). + if b.Objects != "" { + out = append(out, "OBJ_"+b.Objects) + } if b.History != "" { out = append(out, b.History, b.History+"_snapshot") } diff --git a/modules/mesh-grants/internal/grants/records.go b/modules/mesh-grants/internal/grants/records.go index cc706c50..5f9da5e3 100644 --- a/modules/mesh-grants/internal/grants/records.go +++ b/modules/mesh-grants/internal/grants/records.go @@ -465,15 +465,36 @@ func bucketsFor(m catalogue.Manifest, nodes []string) []buscompose.Bucket { return append(out, buscompose.EngineComposedBuckets(nodes)...) } -// objectsOf is a manifest's own object buckets (ADR 0592 §5). +// objectsOf is a manifest's own object buckets (ADR 0592 §5), and the object store beside each state it keeps in its `state`, +// `-objects`, its owner's alone (design 47 G §58, §607, A-237): a state asked in `requires` gets its store from the bus +// module (its binding's objects), a state of the field `state` from the grants part, as its other buckets. Its cap is the state's +// size, StateObjectsMiB when it names none. A state only read, or one whose store's name is one of the module's own object +// buckets, gets none. func objectsOf(m catalogue.Manifest) []buscompose.ObjectBucket { var out []buscompose.ObjectBucket + own := map[string]bool{} for _, o := range m.Objects { + own[o.Name] = true out = append(out, buscompose.ObjectBucket{Module: m.Module, Name: o.Name, MaxMiB: o.MaxMiB, Restricted: o.Grant != nil}) } + for _, s := range m.State { + name := catalogue.StateObjectsName(s.Name) + if s.ReadOnly || own[name] { + continue + } + size := s.MaxMiB + if size <= 0 { + size = StateObjectsMiB + } + out = append(out, buscompose.ObjectBucket{Module: m.Module, Name: name, MaxMiB: min(max(size, catalogue.ObjectsLeastMiB), catalogue.ObjectsMostMiB)}) + } return out } +// StateObjectsMiB is the cap of a state's object store when the state names no size: the bus module's for a state asked in +// `requires` (StateObjectsCapMiB there). +const StateObjectsMiB = 16 + // readsOfObjects takes out of a module's reads each that names another module's object bucket (ADR 0592 §9): read, by // its bus name, where the owner's trusted config value of the bucket's grant names the module on this node, and refused // otherwise, a bucket with no grant included (its owner alone reads it). Every other read stays as it was: a state's. diff --git a/modules/mesh-grants/internal/grants/sentobjects_test.go b/modules/mesh-grants/internal/grants/sentobjects_test.go index bfb9f365..59e97976 100644 --- a/modules/mesh-grants/internal/grants/sentobjects_test.go +++ b/modules/mesh-grants/internal/grants/sentobjects_test.go @@ -13,6 +13,14 @@ import ( // The sent stores a module reads follow the catalog graph (design 47 G §59, §124): the consumers of a module's events and the // callers a seat's verb admits, and no other module. func TestSentStoresRead(t *testing.T) { + // The store beside each state of the field state is the module's own object bucket (design 47 G §58, A-237); a state only + // read has none, a state's size is its store's. + objs := objectsOf(catalogue.Manifest{Module: "mesh-delivery-indexer", State: []catalogue.StateDeclaration{{Name: "inputs", History: 1}, + {Name: "versions", MaxMiB: 64}, {Name: "seen", ReadOnly: true}}}) + if len(objs) != 2 || objs[0].Bucket() != "mesh-delivery-indexer_inputs-objects" || objs[0].MaxMiB != StateObjectsMiB || + objs[1].Bucket() != "mesh-delivery-indexer_versions-objects" || objs[1].MaxMiB != 64 { + t.Errorf("the state's object stores = %+v", objs) + } holder := catalogue.Manifest{Module: "shop", Claims: []catalogue.Claim{{Name: "orders-seat"}}} all := map[string]catalogue.Manifest{"shop": holder, "bank": {Module: "bank"}, "plain": {Module: "plain"}} callers := map[string]map[string][]string{"orders-seat": {