diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/main.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/main.go index 2f6b37b66..1dce628c6 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/main.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/main.go @@ -16,6 +16,8 @@ import ( "sync" "time" + ownmanifest "mesh-delivery-gate" + "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" stdio "git.novox.be/novox/mesh-sdk/go" ) @@ -64,6 +66,11 @@ func main() { h.Records = &Records{Ledger: sdkLedger{}, Now: h.Now, Say: stdio.SeatPublish, Logf: logf, TooLarge: h.recordTooLarge, Class: seatCatalog{ask: stdio.Ask}.Class} h.Records.Changed = h.recordChanged + var daysErr error + if h.Records.KeepingDays, h.Records.EndedDays, daysErr = ownmanifest.RecordsDays(); daysErr != nil { + logf("%v", daysErr) + os.Exit(1) + } h.Forge = seatGit{ask: stdio.Ask} h.Catalog = seatCatalog{ask: stdio.Ask} h.Consumer = &StepConsumer{Records: h.Records, Families: stepFamilies, Now: h.Now, Logf: logf, Taken: h.TakenIn, diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/record.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/record.go index ffda8c243..56c1aab04 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/record.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/record.go @@ -266,6 +266,9 @@ type RecordLedger interface { Apply(instance, operation string, body any) (uint64, error) // Get is the instance's state and the sequence of its last operation; a nil state when it has none. Get(instance string) (json.RawMessage, uint64, error) + // Expires is when the bus ends the instance's state key, as `get` reads it from the bus (its time and the lifetime it + // carries); nil while the instance has not ended (design 47 H2 H-A-689 (2)). + Expires(instance string) (*time.Time, error) // Remove removes a record with its operations and its snapshot through the tool runner's ledger removal. Remove(instance string) error // Query is the instances a declared index names under key (`>` for the rest). @@ -344,6 +347,19 @@ func (sdkLedger) Watch(instances string, handle func(string, json.RawMessage) er return stdio.WatchLedger(RecordsLedger, instances, func(c buscalls.InstanceChange) error { return handle(c.Instance, c.State) }) } +// Expires is the `expires` the tool runner's `get` answers for the instance. +func (sdkLedger) Expires(instance string) (*time.Time, error) { + out, err := ledgerCall(buscalls.LedgerGet, buscalls.InstanceRequest{Ledger: RecordsLedger, Instance: instance}) + if err != nil { + return nil, err + } + var got buscalls.InstanceState + if err := json.Unmarshal(out, &got); err != nil { + return nil, fmt.Errorf("the ledger's state of %s is not readable: %w", instance, err) + } + return got.Expires, nil +} + func (sdkLedger) Get(instance string) (json.RawMessage, uint64, error) { out, err := ledgerCall(buscalls.LedgerGet, buscalls.InstanceRequest{Ledger: RecordsLedger, Instance: instance}) if err != nil { @@ -377,6 +393,9 @@ type Records struct { // TooLarge raises (raised) or clears record-too-large for an entry of the record named by its head's instance, the // finding's subject (§809; H-A-460); an empty instance clears every one held of the record (its end). nil raises none. TooLarge func(record, instance string, bytes int, raised bool) + // KeepingDays and EndedDays are the ledger's `max-age-days` and `ended-days` its manifest gives, said by the read tools + // (design 47 H2 H-A-634 (7)); zero says none. + KeepingDays, EndedDays int // held are the records kept, by instance: the current states of a watch of the ledger's `record/>` at the first read, // then as the gate writes them (the gate is their one writer); a key the watch hands gone is dropped, and remembered in diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/record_test.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/record_test.go index 969f71897..22aa011d7 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/record_test.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/record_test.go @@ -12,6 +12,8 @@ import ( "testing" "time" + ownmanifest "mesh-delivery-gate" + "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" "git.novox.be/novox/mesh-contracts/health-and-repair/go/seats/meshconditions" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshdelivery" @@ -222,6 +224,25 @@ func (f *ledgerFake) Query(index, key string) ([]string, error) { return out, nil } +// Expires is the end of the instance plus the manifest's ended-days, as `get` answers it; nil while it has no end. +func (f *ledgerFake) Expires(instance string) (*time.Time, error) { + if f.failOn == "expires" { + return nil, errors.New("the ledger is away") + } + var st struct { + Ended *RecordEnded `json:"ended"` + } + if raw := f.states[instance]; raw != nil { + _ = json.Unmarshal(raw, &st) + } + if st.Ended == nil { + return nil, nil + } + _, days, _ := ownmanifest.RecordsDays() + at := st.Ended.At.AddDate(0, 0, days) + return &at, nil +} + func (f *ledgerFake) Get(instance string) (json.RawMessage, uint64, error) { s := f.states[instance] if s == nil || string(s) == "null" { @@ -970,6 +991,106 @@ func TestTheRecordsToolsReadThemAndEndOneByHand(t *testing.T) { t.Fatalf("with none open: %+v %v, log %d", again, err, len(log.took)) } }) + // H-A-634 (7), H-A-689 (2): gate_records_expiring names what the bus ends when, read from the bus, and no open record. + t.Run("gate_records_expiring names an ended record's expires thirty days after its end, and no open record", func(t *testing.T) { + rs, r, _ := setup(t) + rs.EndedDays, rs.KeepingDays = 30, 90 + if err := rs.SetMover(r, "mesh-x", "src2:f1", "main.47", "0.1.0"); err != nil { + t.Fatal(err) + } + open, _, err := rs.Open(opening("main", 48, map[string]string{"novox/app@222222222222": strings.Repeat("2", 40)})) + if err != nil { + t.Fatal(err) + } + if err := rs.End(r, "done", "jochen@shanks"); err != nil { + t.Fatal(err) + } + got, err := rs.Expiring(0, "") + lines, _ := got["records"].([]expiringLine) + want := at.AddDate(0, 0, 30).UTC().Format(time.RFC3339) + if err != nil || len(lines) != 1 || lines[0].Instance != r.Instance || lines[0].Expires != want || got["open"] != 1 || + lines[0].Movers != (counts{Counted: 1, Indexed: 1}) || got["capped"] != false { + t.Fatalf("%+v %v", got, err) + } + for _, l := range lines { + if l.Instance == open.Instance { + t.Fatal("an open record is named") + } + } + if short, _ := rs.Expiring(1, ""); short["total"] != 0 { + t.Fatalf("within one day: %+v", short) + } + if _, err := rs.Expiring(3651, ""); err == nil { + t.Fatal("within 3651 days was taken") + } + if _, err := rs.Expiring(0, "not-a-cursor"); err == nil { + t.Fatal("a cursor this tool never answered was taken") + } + if lines, _ := rs.Lines(); lines["soonest-expires"] != want || lines["ended-days"] != 30 || lines["keeping-days"] != 90 { + t.Fatalf("gate_records says %v, %v, %v", lines["soonest-expires"], lines["ended-days"], lines["keeping-days"]) + } + rs.Ledger.(*ledgerFake).failOn = "expires" + if got, _ := rs.Expiring(0, ""); got["unread"] == nil { + t.Fatalf("an expires that could not be read is not said: %+v", got) + } + }) + // H-A-634 (7): gate_records_follow_ends gives an ended record's movers and acts its end and takes it from an open one's, once + // the hand-act log took it. + t.Run("gate_records_follow_ends gives an ended record's entries its end and takes it from an open record's", func(t *testing.T) { + rs, r, _ := setup(t) + if err := rs.SetMover(r, "mesh-x", "src2:f1", "main.47", "0.1.0"); err != nil { + t.Fatal(err) + } + if err := rs.Act(r, RecordAct{ID: "a1", Act: "merge", Repository: "novox/app", Number: 1, At: at}); err != nil { + t.Fatal(err) + } + open, _, err := rs.Open(opening("main", 48, map[string]string{"novox/app@222222222222": strings.Repeat("2", 40)})) + if err != nil { + t.Fatal(err) + } + if err := rs.SetMover(open, "mesh-y", "src2:f2", "main.48", "0.1.0"); err != nil { + t.Fatal(err) + } + if err := rs.End(r, "done", "jochen@shanks"); err != nil { + t.Fatal(err) + } + l := rs.Ledger.(*ledgerFake) + moverX, _ := MoverInstance(r.Milestone, "mesh-x") + actA, _ := ActInstance(r.Milestone, "a1") + moverY, _ := MoverInstance(open.Milestone, "mesh-y") + // The earlier gate left the entries as the end found them: the ended record's with none, the open one's with an end. + for inst, ended := range map[string]any{moverX: nil, actA: nil, moverY: RecordEnded{At: at, Why: "stale"}} { + if _, err := l.Apply(inst, OpEnd, map[string]any{"ended": ended}); err != nil { + t.Fatal(err) + } + } + log := &handActsFake{refuse: errors.New("no responders")} + if _, err := rs.FollowEnds("", log); err == nil { + t.Fatal("followed with no reason") + } + if _, err := rs.FollowEnds("the indexes were rebuilt", log); err == nil || len(l.history) == 0 || strings.HasSuffix(l.history[len(l.history)-1], moverX+" end") { + t.Fatalf("followed though the hand-act log refused it: %v", err) + } + endedOf := func(inst string) any { + var st map[string]any + _ = json.Unmarshal(l.states[inst], &st) + return st["ended"] + } + if endedOf(moverX) != nil || endedOf(moverY) == nil { + t.Fatal("an entry was written while no hand act was recorded") + } + log.refuse = nil + got, err := rs.FollowEnds("the indexes were rebuilt", log) + if err != nil || got["written"] != 3 || len(log.took) != 1 { + t.Fatalf("%+v %v (log %+v)", got, err, log.took) + } + if endedOf(moverX) == nil || endedOf(actA) == nil || endedOf(moverY) != nil { + t.Fatalf("the ends: %v %v %v", endedOf(moverX), endedOf(actA), endedOf(moverY)) + } + if again, err := rs.FollowEnds("again", log); err != nil || again["written"] != 0 { + t.Fatalf("a second pass wrote: %+v %v", again, err) + } + }) t.Run("gate_record_repair asks the owners for the outcomes an entry lacks, applies what they answer, and ends the record", func(t *testing.T) { rs, r, said := setup(t) owners := &ownersFake{wanted: "src2:f1", fp: "src2:f1", phase: "running"} diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/recordends.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/recordends.go new file mode 100644 index 000000000..a8defac04 --- /dev/null +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/recordends.go @@ -0,0 +1,295 @@ +package main + +// What the ledger's lifetimes make of the records, read and mended by hand (design 47 H2 H-A-634 (7), H-A-689): when an ended +// record's key goes (gate_records_expiring) and the end each of its movers and acts holds (gate_records_follow_ends), found +// through the ledger's indexes `movers` and `acts`. + +import ( + "encoding/base64" + "encoding/json" + "errors" + "fmt" + "sort" + "strconv" + "strings" + "time" + + "git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient" + "git.novox.be/novox/mesh-sdk/go/views" +) + +// expiry is one ended record with the time the bus ends its key. +type expiry struct { + r *Record + expires time.Time +} + +// expiries are the ended records of list whose key the bus ends, each with its `expires` as the ledger's `get` reads it from the +// bus, the soonest first; a record whose `expires` cannot be read is named in unread with the error. +func (rs *Records) expiries(list []*Record) (out []expiry, unread []string) { + for _, r := range list { + if r.Ended == nil { + continue + } + at, err := rs.Ledger.Expires(r.Instance) + if err != nil { + unread = append(unread, r.Instance+": "+err.Error()) + continue + } + if at == nil { + continue + } + out = append(out, expiry{r: r, expires: at.UTC()}) + } + sort.SliceStable(out, func(i, j int) bool { + if !out[i].expires.Equal(out[j].expires) { + return out[i].expires.Before(out[j].expires) + } + return out[i].r.Instance < out[j].r.Instance + }) + return out, unread +} + +// expiringLine is one ended record as gate_records_expiring lists it: its movers and acts as the head counts them and as the +// ledger's indexes name them. +type expiringLine struct { + Instance string `json:"instance"` + Opened string `json:"opened"` + Ended string `json:"ended"` + Expires string `json:"expires"` + Movers counts `json:"movers"` + Acts counts `json:"acts"` +} + +type counts struct { + Counted int `json:"counted"` + Indexed int `json:"indexed"` +} + +// MaxWithinDays is the most days gate_records_expiring looks ahead. +const MaxWithinDays = 3650 + +// Expiring reads what goes when, removing nothing: every ended record whose key expires within `within` days (the ledger's +// ended-days when 0), the soonest first, and how many open records are kept whatever their age, at most views.PageBytes a page +// with capped, total and the cursor (design 47 H2 §811, H-A-634 (7), H-A-689 (2)). +func (rs *Records) Expiring(within int, next string) (map[string]any, error) { + if within == 0 { + within = rs.EndedDays + } + if within < 1 || within > MaxWithinDays { + return nil, fmt.Errorf("within is a number of days from 1 to %d", MaxWithinDays) + } + list, err := rs.Kept() + if err != nil { + return nil, err + } + open := 0 + for _, r := range list { + if r.Ended == nil { + open++ + } + } + until := rs.now().Add(time.Duration(within) * 24 * time.Hour) + var all []expiry + got, unread := rs.expiries(list) + for _, e := range got { + if !e.expires.After(until) { + all = append(all, e) + } + } + page, size, capped, cursor := []expiringLine{}, 0, false, "" + for _, e := range all { + if next != "" { + at, err := beforeExpiry(e, next) + if err != nil { + return nil, err + } + if at { + continue + } + } + line, err := rs.expiringLine(e) + if err != nil { + return nil, err + } + raw, _ := json.Marshal(line) + if size+len(raw) > views.PageBytes && len(page) > 0 { + capped = true + break + } + size += len(raw) + page, cursor = append(page, line), expiryCursor(e) + } + out := map[string]any{"within-days": within, "ended-days": rs.EndedDays, "records": page, "total": len(all), "open": open, + "capped": capped} + if capped { + out["next"] = cursor + } else { + out["next"] = "" + } + if len(unread) > 0 { + out["unread"] = unread + } + return out, nil +} + +func (rs *Records) expiringLine(e expiry) (expiringLine, error) { + ms, err := rs.Ledger.Query(MoversIndex, moversKey(e.r.Milestone)) + if err != nil { + return expiringLine{}, fmt.Errorf("the movers of the record %s cannot be read: %w", e.r.Instance, err) + } + as, err := rs.Ledger.Query(ActsIndex, moversKey(e.r.Milestone)) + if err != nil { + return expiringLine{}, fmt.Errorf("the acts of the record %s cannot be read: %w", e.r.Instance, err) + } + return expiringLine{Instance: e.r.Instance, Opened: timeText(&e.r.Opened), Ended: timeText(&e.r.Ended.At), + Expires: timeText(&e.expires), Movers: counts{Counted: e.r.MoverCount, Indexed: len(ms)}, + Acts: counts{Counted: len(e.r.Acts), Indexed: len(as)}}, nil +} + +// expiryCursor is the opaque cursor of a page of gate_records_expiring: the place of the last record it answered. +func expiryCursor(e expiry) string { + return base64.RawURLEncoding.EncodeToString([]byte(fmt.Sprintf("%d|%s", e.expires.UnixNano(), e.r.Instance))) +} + +// beforeExpiry is whether e comes at or before the place the cursor names. +func beforeExpiry(e expiry, cursor string) (bool, error) { + raw, err := base64.RawURLEncoding.DecodeString(cursor) + at, inst, ok := strings.Cut(string(raw), "|") + n, perr := strconv.ParseInt(at, 10, 64) + if err != nil || !ok || perr != nil { + return false, fmt.Errorf("gate_records_expiring: %q is no cursor this tool answered", cursor) + } + if e.expires.UnixNano() != n { + return e.expires.UnixNano() < n, nil + } + return e.r.Instance <= inst, nil +} + +// soonest is the earliest `expires` among the ended records, "" when none ends or none could be read. +func (rs *Records) soonest(list []*Record) string { + got, _ := rs.expiries(list) + if len(got) == 0 { + return "" + } + return timeText(&got[0].expires) +} + +// sameEnded is whether two ends are one: the time, the reason, who and the nodes away. +func sameEnded(a, b *RecordEnded) bool { + if a == nil || b == nil { + return a == nil && b == nil + } + if !a.At.Equal(b.At) || a.Why != b.Why || a.By != b.By || len(a.Away) != len(b.Away) { + return false + } + for i := range a.Away { + if a.Away[i].Node != b.Away[i].Node || !a.Away[i].Since.Equal(b.Away[i].Since) { + return false + } + } + return true +} + +// followRecord gives every mover and act of the record, found through the indexes `movers` and `acts`, the record's end where +// they hold another, and takes it from those of an open record, by their `end` (H-A-634 (2), (7)): the instances it wrote. It +// stops at the first write that fails, naming it. +func (rs *Records) followRecord(r *Record) ([]string, error) { + var written []string + for _, index := range []string{MoversIndex, ActsIndex} { + insts, err := rs.Ledger.Query(index, moversKey(r.Milestone)) + if err != nil { + return written, fmt.Errorf("the %s of the record %s cannot be read: %w", index, r.Instance, err) + } + sort.Strings(insts) + for _, inst := range insts { + raw, _, err := rs.Ledger.Get(inst) + if err != nil { + return written, err + } + if raw == nil { + continue + } + var m Mover + var a RecordAct + var held, state any + var heldEnded *RecordEnded + if index == MoversIndex { + if err := json.Unmarshal(raw, &m); err != nil { + return written, fmt.Errorf("the mover %s is not readable: %w", inst, err) + } + heldEnded = m.Ended + m.Ended = copyEnded(r.Ended) + held, state = m.Ended, m + } else { + if err := json.Unmarshal(raw, &a); err != nil { + return written, fmt.Errorf("the act %s is not readable: %w", inst, err) + } + heldEnded = a.Ended + a.Ended = copyEnded(r.Ended) + held, state = a.Ended, a + } + if sameEnded(heldEnded, r.Ended) { + continue + } + var value any + if r.Ended != nil { + value = *held.(*RecordEnded) + } + if _, err := rs.write(r, inst, OpEnd, map[string]any{"ended": value}, state); err != nil { + return written, fmt.Errorf("the end of %s is not written: %w", inst, err) + } + written = append(written, inst) + } + } + return written, nil +} + +// FollowEnds does by hand the pass the gate makes at its start: every record's movers and acts take the record's end, or none +// while it is open, read through the indexes. Recorded first in the hand-act log of the seat mesh-hand-acts: nothing is written +// when the log did not take it. It answers each record and the instances it wrote; a record whose pass failed is named with +// the error and the rest go on. +func (rs *Records) FollowEnds(why string, acts handActs) (map[string]any, error) { + if strings.TrimSpace(why) == "" { + return nil, errors.New("say why the ends are followed by hand, such as the indexes were rebuilt") + } + if acts == nil { + return nil, errors.New("the hand-act log cannot be reached here, so nothing was written") + } + list, err := rs.Kept() + if err != nil { + return nil, err + } + if _, err := acts.Record(meshhandactsclient.Request{What: "gave the movers and acts of every delivery record its end by hand", + Why: why, Cause: "gate_records_follow_ends", Verb: "follow-ends"}); err != nil { + return nil, fmt.Errorf("the hand act was not recorded through mesh-hand-acts, so nothing was written: %w", err) + } + type line struct { + Record string `json:"record"` + Ended bool `json:"ended"` + Written []string `json:"written"` + Failed string `json:"failed,omitempty"` + } + lines, total, failed := []line{}, 0, 0 + for _, r := range list { + w, err := rs.followRecord(r) + if len(w) == 0 && err == nil { + continue + } + l := line{Record: r.Instance, Ended: r.Ended != nil, Written: w} + if l.Written == nil { + l.Written = []string{} + } + if err != nil { + l.Failed = err.Error() + failed++ + } + total += len(w) + lines = append(lines, l) + } + out := map[string]any{"records": lines, "read": len(list), "written": total, "failed": failed} + if failed > 0 { + return out, fmt.Errorf("the ends of %d records were not followed in full", failed) + } + return out, nil +} diff --git a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/recordtools.go b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/recordtools.go index 31f294c02..9568424aa 100644 --- a/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/recordtools.go +++ b/modules/mesh-delivery-gate/cmd/mesh-delivery-gate/recordtools.go @@ -102,8 +102,8 @@ func (rs *Records) Lines() (map[string]any, error) { } lines = append(lines, l) } - return map[string]any{"records": lines, "open": open, "kept": len(lines), - "fill": rs.fillLine()}, nil + return map[string]any{"records": lines, "open": open, "kept": len(lines), "ended-days": rs.EndedDays, + "keeping-days": rs.KeepingDays, "soonest-expires": rs.soonest(list), "fill": rs.fillLine()}, nil } // EndByHand ends one open record by hand, with the reason, recorded in the hand-act log first: nothing is ended when the @@ -216,6 +216,35 @@ func recordTools(h *Holder, acts handActs) []stdio.Tool { } return h.Records.Lines() }}, + {Name: "gate_records_expiring", + Description: "What the ledger's lifetimes take, removing nothing (design 47 H2 H-A-634 (7)): every ended delivery record whose " + + "key the bus ends within within days (1 to 3650, default the ledger's ended-days), the soonest first, with its key, " + + "when it opened and ended, its expires as the bus holds it, and its movers and acts as the head counts them and as the " + + "indexes name them; and how many open records are kept, whatever their age. At most 768 KB a page, with capped, total " + + "and the next page's cursor.", + Input: map[string]any{"type": "object", "properties": map[string]any{ + "within": map[string]any{"type": "integer", "description": "days from now, 1 to 3650; the ledger's ended-days when absent"}, + "next": str("the cursor the previous page answered")}}, + Run: func(a map[string]any) (any, error) { + if h.Records == nil { + return none() + } + within, _ := a["within"].(float64) + return h.Records.Expiring(int(within), strArg(a, "next")) + }}, + {Name: "gate_records_follow_ends", + Description: "Do by hand the pass the gate makes at its start (design 47 H2 H-A-634 (7)): give every mover and act of an ended " + + "delivery record that record's end where they hold another, and take it from those of an open record, found through " + + "the ledger's indexes movers and acts; answers each record and the instances it wrote. Recorded in the hand-act log " + + "of the seat mesh-hand-acts first.", + Input: map[string]any{"type": "object", "properties": map[string]any{ + "why": str("why the ends are followed by hand, in plain words")}, "required": []string{"why"}}, + Run: func(a map[string]any) (any, error) { + if h.Records == nil { + return none() + } + return h.Records.FollowEnds(strArg(a, "why"), acts) + }}, {Name: "gate_consumer", Description: "The delivery record's consumer of the step events: per family the events applied and refused " + "since the gate started, the last applied, and why the last was refused.", diff --git a/modules/mesh-delivery-gate/manifest.go b/modules/mesh-delivery-gate/manifest.go index a6214ed30..a20fab017 100644 --- a/modules/mesh-delivery-gate/manifest.go +++ b/modules/mesh-delivery-gate/manifest.go @@ -21,3 +21,26 @@ func Consumes() ([]string, error) { } return m.Consumes, nil } + +// RecordsDays are the days the manifest's ledger `records` keeps its history (`max-age-days`) and an ended instance's state +// (`ended-days`), as its `configuration` says them (design 47 H2 H-A-634 (7)); the gate's read tools say them beside the records. +func RecordsDays() (keeping, ended int, err error) { + var m struct { + Requires []struct { + Name string `json:"name"` + Configuration map[string]any `json:"configuration"` + } `json:"requires"` + } + if err := json.Unmarshal(manifest, &m); err != nil { + return 0, 0, fmt.Errorf("the gate's own manifest is not readable: %w", err) + } + for _, r := range m.Requires { + if r.Name != "records" { + continue + } + k, _ := r.Configuration["max-age-days"].(float64) + e, _ := r.Configuration["ended-days"].(float64) + return int(k), int(e), nil + } + return 0, 0, fmt.Errorf("the gate's own manifest asks for no ledger records") +} diff --git a/modules/mesh-delivery-gate/module.json b/modules/mesh-delivery-gate/module.json index 3784c9e0c..82a713dcb 100644 --- a/modules/mesh-delivery-gate/module.json +++ b/modules/mesh-delivery-gate/module.json @@ -490,6 +490,8 @@ "gate_record_end", "gate_record_repair", "gate_records", + "gate_records_expiring", + "gate_records_follow_ends", "gate_source", "gate_source_again", "gate_source_seed",